File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
packages/hyperdrive-js-core/src/hyperdrive/base Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import {
2121import { HyperdriveSdkError } from "src/errors/HyperdriveSdkError" ;
2222import { getBlockFromReadOptions } from "src/evm-client/utils/getBlockFromReadOptions" ;
2323import { getBlockOrThrow } from "src/evm-client/utils/getBlockOrThrow" ;
24- import { fixed , ln } from "src/fixed-point" ;
24+ import { fixed } from "src/fixed-point" ;
2525import { HyperdriveAbi , hyperdriveAbi } from "src/hyperdrive/base/abi" ;
2626import { MAX_ITERATIONS , NULL_BYTES } from "src/hyperdrive/constants" ;
2727import { calculateAprFromPrice } from "src/hyperdrive/utils/calculateAprFromPrice" ;
@@ -2023,7 +2023,7 @@ export class ReadHyperdrive extends ReadModel {
20232023 * p_1 = to lpSharePrice
20242024 * t = term length in fractions of a year
20252025 *
2026- * r = ln (p_1 / p_0) / t
2026+ * r = (p_1 / p_0) ^ (1 / t) - 1
20272027 */
20282028function calculateLpApy ( {
20292029 startingLpSharePrice,
@@ -2036,5 +2036,8 @@ function calculateLpApy({
20362036} ) : number {
20372037 const priceRatio = fixed ( endingLpSharePrice ) . div ( startingLpSharePrice ) ;
20382038 const yearFraction = fixed ( timeFrame ) . div ( SECONDS_PER_YEAR ) ;
2039- return ln ( priceRatio ) . div ( yearFraction ) . toNumber ( ) ;
2039+ return priceRatio
2040+ . pow ( fixed ( 1e18 ) . div ( yearFraction ) )
2041+ . sub ( fixed ( 1e18 ) )
2042+ . toNumber ( ) ;
20402043}
You can’t perform that action at this time.
0 commit comments