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

Commit

Permalink
103 totalinvested and totalredeemed are missing in poolsnapshot (#107)
Browse files Browse the repository at this point in the history
* fix: add missing properties to snapshot

* deploy: update node and query versions

* fix: pool investment and redemptions totals
  • Loading branch information
filo87 authored Oct 10, 2022
1 parent 7f6dabf commit abe2f7f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ jobs:
--projectName="$SUBQL_PROJ_NAME" \
--ipfsCID="$IPFSCID" \
--type=primary \
--indexerVersion="v1.9.2" \
--queryVersion="v1.4.0"
--indexerVersion="v1.10.2" \
--queryVersion="v1.6.0"
4 changes: 3 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Pool @entity {
type PoolState @entity {
id: ID! #poolId
type: String! @index

#States
netAssetValue: BigInt!
totalReserve: BigInt!
Expand Down Expand Up @@ -74,6 +75,8 @@ type PoolSnapshot @entity {
# Aggregated transaction data over the last period
totalBorrowed_: BigInt
totalRepaid_: BigInt
totalInvested_: BigInt
totalRedeemed_: BigInt
totalNumberOfLoans_: BigInt

# Cumulated transaction data since pool creation
Expand Down Expand Up @@ -161,7 +164,6 @@ type Epoch @entity {
totalRepaid: BigInt!
totalInvested: BigInt!
totalRedeemed: BigInt!
totalRedeemedCurrency: BigInt!

epochStates: [EpochState] @derivedFrom(field: "epoch")

Expand Down
2 changes: 1 addition & 1 deletion src/mappings/handlers/loansHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function _handleLoanClosed(event: SubstrateEvent<LoanCreatedClosedEvent>)
await loan.close()
await loan.save()

const bt = await BorrowerTransactionService.repaid({
const bt = await BorrowerTransactionService.closed({
poolId: poolId.toString(),
loanId: loanId.toString(),
address: account.account.id,
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/handlers/poolsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ async function _handleEpochExecuted(event: SubstrateEvent<EpochEvent>): Promise<
await epoch.save()

await poolService.executeEpoch(epochId.toNumber())
await poolService.increaseTotalInvested(epoch.epoch.totalInvested)
await poolService.increaseTotalRedeemed(epoch.epoch.totalRedeemed)
await poolService.save()

// Compute and save aggregated order fulfillment
Expand All @@ -123,7 +125,7 @@ async function _handleEpochExecuted(event: SubstrateEvent<EpochEvent>): Promise<
await tranche.updateSupply()
await tranche.updatePrice(epochState.price)
await tranche.updateFulfilledInvestOrders(epochState.fulfilledInvestOrders)
await tranche.updateFulfilledRedeemOrders(epochState.fulfilledRedeemOrders)
await tranche.updateFulfilledRedeemOrders(epochState.fulfilledRedeemOrders, digits)
await tranche.save()

// Carry over aggregated unfulfilled orders to next epoch
Expand Down
4 changes: 1 addition & 3 deletions src/mappings/services/epochService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class EpochService {
epoch.totalRepaid = BigInt(0)
epoch.totalInvested = BigInt(0)
epoch.totalRedeemed = BigInt(0)
epoch.totalRedeemedCurrency = BigInt(0)

const epochStates: EpochState[] = []
for (const trancheId of trancheIds) {
Expand Down Expand Up @@ -85,8 +84,7 @@ export class EpochService {
)

this.epoch.totalInvested += epochState.fulfilledInvestOrders
this.epoch.totalRedeemed += epochState.fulfilledRedeemOrders
this.epoch.totalRedeemedCurrency += epochState.fulfilledRedeemOrdersCurrency
this.epoch.totalRedeemed += epochState.fulfilledRedeemOrdersCurrency
}
return this
}
Expand Down
8 changes: 8 additions & 0 deletions src/mappings/services/poolService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ export class PoolService {
this.poolState.totalEverNumberOfLoans = this.poolState.totalEverNumberOfLoans + BigInt(1)
}

public increaseTotalInvested = (currencyAmount: bigint) => {
this.poolState.totalInvested_ += currencyAmount
}

public increaseTotalRedeemed = (currencyAmount: bigint) => {
this.poolState.totalRedeemed_ += currencyAmount
}

public closeEpoch = (epochId: number) => {
this.pool.lastEpochClosed = epochId
this.pool.currentEpoch = epochId + 1
Expand Down
6 changes: 5 additions & 1 deletion src/mappings/services/trancheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ export class TrancheService {
return this
}

public updateFulfilledRedeemOrders = (amount: bigint) => {
public updateFulfilledRedeemOrders = (amount: bigint, digits: number) => {
this.trancheState.fulfilledRedeemOrders_ = this.trancheState.fulfilledRedeemOrders_ + amount
this.trancheState.fulfilledRedeemOrdersCurrency_ = this.computeCurrencyAmount(
this.trancheState.fulfilledRedeemOrders_,
digits
)
return this
}

Expand Down

0 comments on commit abe2f7f

Please sign in to comment.