diff --git a/schema.graphql b/schema.graphql index c66b140..cf8a365 100644 --- a/schema.graphql +++ b/schema.graphql @@ -410,6 +410,8 @@ type TrancheBalance @entity { pool: Pool! @index tranche: Tranche! @index + initialisedAt: Date! + pendingInvestCurrency: BigInt! claimableTrancheTokens: BigInt! diff --git a/src/mappings/handlers/evmHandlers.ts b/src/mappings/handlers/evmHandlers.ts index 349bcf0..be718b1 100644 --- a/src/mappings/handlers/evmHandlers.ts +++ b/src/mappings/handlers/evmHandlers.ts @@ -119,7 +119,12 @@ async function _handleEvmTransfer(event: TransferLog): Promise { const investLpCollect = InvestorTransactionService.collectLpInvestOrder({ ...orderData, address: toAccount.id }) await investLpCollect.save() - const trancheBalance = await TrancheBalanceService.getOrInit(toAccount.id, orderData.poolId, orderData.trancheId) + const trancheBalance = await TrancheBalanceService.getOrInit( + toAccount.id, + orderData.poolId, + orderData.trancheId, + timestamp + ) await trancheBalance.investCollect(orderData.amount) await trancheBalance.save() } diff --git a/src/mappings/handlers/investmentsHandlers.ts b/src/mappings/handlers/investmentsHandlers.ts index f479726..a344a2d 100644 --- a/src/mappings/handlers/investmentsHandlers.ts +++ b/src/mappings/handlers/investmentsHandlers.ts @@ -67,7 +67,12 @@ async function _handleInvestOrderUpdated(event: SubstrateEvent 0) { const it = InvestorTransactionService.collectInvestOrder(orderData) @@ -227,7 +242,12 @@ async function _handleRedeemOrdersCollected(event: SubstrateEvent 0) { const it = InvestorTransactionService.collectRedeemOrder(orderData) diff --git a/src/mappings/handlers/poolsHandlers.ts b/src/mappings/handlers/poolsHandlers.ts index 9f3c88c..043cae5 100644 --- a/src/mappings/handlers/poolsHandlers.ts +++ b/src/mappings/handlers/poolsHandlers.ts @@ -231,7 +231,8 @@ async function _handleEpochExecuted(event: SubstrateEvent BigInt(0) && epochState.investFulfillmentPercentage > BigInt(0)) { diff --git a/src/mappings/services/trancheBalanceService.ts b/src/mappings/services/trancheBalanceService.ts index d3c6e96..ac183b6 100644 --- a/src/mappings/services/trancheBalanceService.ts +++ b/src/mappings/services/trancheBalanceService.ts @@ -1,13 +1,14 @@ import { TrancheBalance } from '../../types/models/TrancheBalance' export class TrancheBalanceService extends TrancheBalance { - static init(address: string, poolId: string, trancheId: string) { + static init(address: string, poolId: string, trancheId: string, timestamp: Date) { logger.info(`Initialising new TrancheBalance: ${address}-${poolId}-${trancheId}`) const trancheBalance = new this( `${address}-${poolId}-${trancheId}`, address, poolId, `${poolId}-${trancheId}`, + timestamp, BigInt(0), BigInt(0), BigInt(0), @@ -24,10 +25,10 @@ export class TrancheBalanceService extends TrancheBalance { return trancheBalance as TrancheBalanceService } - static getOrInit = async (address: string, poolId: string, trancheId: string) => { + static getOrInit = async (address: string, poolId: string, trancheId: string, timestamp: Date) => { let trancheBalance = await this.getById(address, poolId, trancheId) if (trancheBalance === undefined) { - trancheBalance = this.init(address, poolId, trancheId) + trancheBalance = this.init(address, poolId, trancheId, timestamp) await trancheBalance.save() } return trancheBalance