diff --git a/schema.graphql b/schema.graphql index 9f31e76..af17bf4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -333,6 +333,7 @@ type Transaction @entity { type APRInTime @entity { id: ID! createdAtTimestamp: BigInt! + block: BigInt! spotPrice: BigInt! ibtRate: BigInt! diff --git a/src/entities/APRInTime.ts b/src/entities/APRInTime.ts index 8d0c557..4859955 100644 --- a/src/entities/APRInTime.ts +++ b/src/entities/APRInTime.ts @@ -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 diff --git a/src/entities/Pool.ts b/src/entities/Pool.ts index 7f93b88..43fd251 100644 --- a/src/entities/Pool.ts +++ b/src/entities/Pool.ts @@ -22,6 +22,7 @@ class PoolDetails { ptAddress: Address factoryAddress: Address timestamp: BigInt + blockNumber: BigInt logIndex: BigInt transactionHash: Bytes } @@ -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() diff --git a/src/mappings/amm.ts b/src/mappings/amm.ts index 751133b..75f2020 100644 --- a/src/mappings/amm.ts +++ b/src/mappings/amm.ts @@ -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 ) } } @@ -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 ) } } @@ -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 ) } } diff --git a/src/mappings/futures.ts b/src/mappings/futures.ts index f8b0ec4..bebfd47 100644 --- a/src/mappings/futures.ts +++ b/src/mappings/futures.ts @@ -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, }) } diff --git a/src/utils/calculateAPR.ts b/src/utils/calculateAPR.ts index 261ba23..0e1bc51 100644 --- a/src/utils/calculateAPR.ts +++ b/src/utils/calculateAPR.ts @@ -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)