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 9a7bf1a..5c40c3e 100644 --- a/src/mappings/handlers/evmHandlers.ts +++ b/src/mappings/handlers/evmHandlers.ts @@ -9,13 +9,10 @@ import { InvestorTransactionData, InvestorTransactionService } from '../services import { CurrencyService } from '../services/currencyService' import { BlockchainService } from '../services/blockchainService' import { CurrencyBalanceService } from '../services/currencyBalanceService' -import type { Provider } from '@ethersproject/providers' import { TrancheBalanceService } from '../services/trancheBalanceService' import { escrows } from '../../config' import { InvestorPositionService } from '../services/investorPositionService' import { getPeriodStart } from '../../helpers/timekeeperService' - -const _ethApi = api as Provider //const networkPromise = typeof ethApi.getNetwork === 'function' ? ethApi.getNetwork() : null export const handleEvmDeployTranche = errorHandler(_handleEvmDeployTranche) @@ -122,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 7e1a37b..66d6e27 100644 --- a/src/mappings/handlers/investmentsHandlers.ts +++ b/src/mappings/handlers/investmentsHandlers.ts @@ -74,7 +74,12 @@ async function _handleInvestOrderUpdated(event: SubstrateEvent 0) { const it = InvestorTransactionService.collectInvestOrder(orderData) @@ -248,7 +263,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 3ea49ce..9024f4a 100644 --- a/src/mappings/handlers/poolsHandlers.ts +++ b/src/mappings/handlers/poolsHandlers.ts @@ -240,7 +240,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 9cc45fb..5249fad 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 | undefined } - static getOrInit = async (address: string, poolId: string, trancheId: string) => { + static async getOrInit(address: string, poolId: string, trancheId: string, timestamp: Date) { let trancheBalance = await this.getById(address, poolId, trancheId) if (!trancheBalance) { - trancheBalance = this.init(address, poolId, trancheId) + trancheBalance = this.init(address, poolId, trancheId, timestamp) await trancheBalance.save() } return trancheBalance as TrancheBalanceService