Skip to content

Commit

Permalink
fix: APR block number (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler authored May 2, 2024
1 parent 545aacc commit f38048e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ type Transaction @entity {
type APRInTime @entity {
id: ID!
createdAtTimestamp: BigInt!
block: BigInt!

spotPrice: BigInt!
ibtRate: BigInt!
Expand Down
4 changes: 3 additions & 1 deletion src/entities/APRInTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { UNIT_BI, ZERO_BD } from "../constants"

export function createAPRInTimeForPool(
poolAddress: Address,
timestamp: BigInt
timestamp: BigInt,
blockNumber: BigInt
): APRInTime {
let aprInTime = new APRInTime(
`${poolAddress.toHex()}-${timestamp.toString()}`
)

aprInTime.createdAtTimestamp = timestamp
aprInTime.block = blockNumber
aprInTime.pool = poolAddress.toHex()

aprInTime.spotPrice = UNIT_BI
Expand Down
4 changes: 3 additions & 1 deletion src/entities/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PoolDetails {
ptAddress: Address
factoryAddress: Address
timestamp: BigInt
blockNumber: BigInt
logIndex: BigInt
transactionHash: Bytes
}
Expand Down Expand Up @@ -103,7 +104,8 @@ export function createPool(params: PoolDetails): Pool {
if (pool.futureVault) {
let poolAPR = createAPRInTimeForPool(
params.poolAddress,
params.timestamp
params.timestamp,
params.blockNumber
)

poolAPR.save()
Expand Down
9 changes: 6 additions & 3 deletions src/mappings/amm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export function handleAddLiquidity(event: AddLiquidity): void {
updatePoolAPR(
event.address,
Address.fromString(pool.futureVault!),
event.block.timestamp
event.block.timestamp,
event.block.number
)
}
}
Expand Down Expand Up @@ -449,7 +450,8 @@ export function handleTokenExchange(event: TokenExchange): void {
updatePoolAPR(
event.address,
Address.fromString(pool.futureVault!),
event.block.timestamp
event.block.timestamp,
event.block.number
)
}
}
Expand Down Expand Up @@ -607,7 +609,8 @@ export function handleRemoveLiquidityOne(event: RemoveLiquidityOne): void {
updatePoolAPR(
event.address,
Address.fromString(pool.futureVault!),
event.block.timestamp
event.block.timestamp,
event.block.number
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mappings/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export function handleCurvePoolDeployed(event: CurvePoolDeployed): void {
timestamp: event.block.timestamp,
logIndex: event.logIndex,
transactionHash: event.transaction.hash,
blockNumber: event.block.number,
})
}

Expand Down
9 changes: 7 additions & 2 deletions src/utils/calculateAPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import { RAYS_PRECISION, toPrecision } from "./toPrecision"
export function updatePoolAPR(
poolAddress: Address,
principalToken: Address,
currentTimestamp: BigInt
currentTimestamp: BigInt,
blockNumber: BigInt
): void {
let poolAPR = createAPRInTimeForPool(poolAddress, currentTimestamp)
let poolAPR = createAPRInTimeForPool(
poolAddress,
currentTimestamp,
blockNumber
)

let underlyingAddress = getUnderlying(principalToken)
let ibtAddress = getIBT(principalToken)
Expand Down

0 comments on commit f38048e

Please sign in to comment.