Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
fix: init tranche currency details on tranche creation
Browse files Browse the repository at this point in the history
  • Loading branch information
filo87 committed Jan 29, 2024
1 parent 2b38e69 commit e0a4f21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/mappings/handlers/evmHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function _handleEvmDeployTranche(event: DeployTrancheLog): Promise<void> {
const investmentManager = InvestmentManagerAbi__factory.connect(investmentManagerAddress, ethApi)
const userEscrowAddress = await investmentManager.userEscrow()

await currency.initEvmDetails(tokenAddress, escrowAddress, userEscrowAddress, tranche.poolId, tranche.trancheId)
await currency.initTrancheDetails(tranche.poolId, tranche.trancheId, tokenAddress, escrowAddress, userEscrowAddress)
await currency.save()

await createTrancheTrackerDatasource({ address: tokenAddress })
Expand Down
13 changes: 12 additions & 1 deletion src/mappings/handlers/poolsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ async function _handlePoolCreated(event: SubstrateEvent<PoolCreatedEvent>): Prom
await tranche.init(index, trancheData[tranche.trancheId].data)
await tranche.updateSupply()
await tranche.save()

const currency = await CurrencyService.getOrInit(blockchain.id, 'Tranche', pool.id, tranche.trancheId)
await currency.initTrancheDetails(pool.id, tranche.trancheId)
await currency.save()
}

// Initialise Epoch
Expand All @@ -65,8 +69,11 @@ async function _handlePoolUpdated(event: SubstrateEvent<PoolUpdatedEvent>): Prom
const [poolId] = event.event.data
logger.info(`Pool ${poolId.toString()} updated on block ${event.block.block.header.number}`)

const chainId = await getNodeChainId()
const blockchain = await BlockchainService.getOrInit(chainId)

const pool = await PoolService.getById(poolId.toString())
if (pool === undefined) throw missingPool
if (!pool) throw missingPool

await pool.initData()
await pool.save()
Expand All @@ -88,6 +95,10 @@ async function _handlePoolUpdated(event: SubstrateEvent<PoolUpdatedEvent>): Prom
await trancheService.updateSupply()
await trancheService.updateDebt(tranche.data.debt.toBigInt())
await trancheService.save()

const currency = await CurrencyService.getOrInit(blockchain.id, 'Tranche', pool.id, trancheService.trancheId)
await currency.initTrancheDetails(pool.id, trancheService.trancheId)
await currency.save()
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/mappings/services/currencyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export class CurrencyService extends Currency {
return currency as CurrencyService
}

public initEvmDetails(
tokenAddress: string,
escrowAddress: string,
userEscrowAddress: string,
public initTrancheDetails(
poolId: string,
trancheId: string
trancheId: string,
evmTokenAddress?: string,
evmEscrowAddress?: string,
evmUserEscrowAddress?: string
) {
this.tokenAddress = tokenAddress
this.escrowAddress = escrowAddress
this.userEscrowAddress = userEscrowAddress
this.poolId = poolId
this.trancheId = `${poolId}-${trancheId}`
this.tokenAddress = evmTokenAddress
this.escrowAddress = evmEscrowAddress
this.userEscrowAddress = evmUserEscrowAddress
}
}

Expand Down

0 comments on commit e0a4f21

Please sign in to comment.