Skip to content

Commit

Permalink
Add totalBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jun 10, 2024
1 parent 0cce348 commit c46f59e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ type ClassicPosition @entity {
vaultBalance: BigInt!
"The amount of vault shares the investor holds in a boost"
boostBalance: BigInt!
"Total amount of vault shares the investor holds. Should always equal vaultBalance + boostBalance. This is mostly used for filtering."
totalBalance: BigInt!

"All investor position interactions"
interactions: [ClassicPositionInteraction!]! @derivedFrom(field: "investorPosition")
Expand Down Expand Up @@ -330,6 +332,8 @@ type ClassicPositionInteraction @entity(immutable: true) {
vaultBalance: BigInt!
"The amount of vault shares the investor holds in a boost at the time of the interaction"
boostBalance: BigInt!
"Total amount of vault shares the investor holds. Should always equal vaultBalance + boostBalance. This is mostly used for filtering."
totalBalance: BigInt!

"Amount of vault shares change in the interaction"
vaultBalanceDelta: BigInt!
Expand Down Expand Up @@ -642,6 +646,8 @@ type ClmPosition @entity {
managerBalance: BigInt!
"Amount of reward pool shares the investor holds"
rewardPoolBalance: BigInt!
"Total amount of CLM shares the investor holds. Should always equal to managerBalance + rewardPoolBalance. This is mostly used for filtering."
totalBalance: BigInt!

"All investor position interactions"
interactions: [ClmPositionInteraction!]! @derivedFrom(field: "investorPosition")
Expand Down Expand Up @@ -686,6 +692,8 @@ type ClmPositionInteraction @entity(immutable: true) {
managerBalance: BigInt!
"The amount of reward pool shares the investor holds at the time of the interaction"
rewardPoolBalance: BigInt!
"Total amount of CLM shares the investor holds. Should always equal to managerBalance + rewardPoolBalance. This is mostly used for filtering."
totalBalance: BigInt!
"The amount of first underlying tokens the investor is entitled to at the time of the interaction"
underlyingBalance0: BigInt!
"The amount of second underlying tokens the investor is entitled to at the time of the interaction"
Expand Down
1 change: 1 addition & 0 deletions src/classic/entity/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getClassicPosition(classic: Classic, investor: Investor): Classi
position.createdWith = ADDRESS_ZERO
position.vaultBalance = ZERO_BI
position.boostBalance = ZERO_BI
position.totalBalance = ZERO_BI
}
return position
}
Expand Down
2 changes: 2 additions & 0 deletions src/classic/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function updateUserPosition(
}
position.vaultBalance = position.vaultBalance.plus(vaultBalanceDelta)
position.boostBalance = position.boostBalance.plus(boostBalanceDelta)
position.totalBalance = position.vaultBalance.plus(position.boostBalance)
position.save()

///////
Expand Down Expand Up @@ -94,6 +95,7 @@ function updateUserPosition(
}
interaction.vaultBalance = position.vaultBalance
interaction.boostBalance = position.boostBalance
interaction.totalBalance = position.totalBalance
interaction.vaultBalanceDelta = vaultBalanceDelta
interaction.boostBalanceDelta = boostBalanceDelta

Expand Down
1 change: 1 addition & 0 deletions src/clm/entity/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getClmPosition(clm: CLM, investor: Investor): ClmPosition {
position.createdWith = ADDRESS_ZERO
position.managerBalance = ZERO_BI
position.rewardPoolBalance = ZERO_BI
position.totalBalance = ZERO_BI
}
return position
}
Expand Down
2 changes: 2 additions & 0 deletions src/clm/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function updateUserPosition(
}
position.managerBalance = position.managerBalance.plus(managerBalanceDelta)
position.rewardPoolBalance = position.rewardPoolBalance.plus(rewardPoolBalanceDelta)
position.totalBalance = position.managerBalance.plus(position.rewardPoolBalance)
position.save()

///////
Expand Down Expand Up @@ -143,6 +144,7 @@ function updateUserPosition(
}
interaction.managerBalance = position.managerBalance
interaction.rewardPoolBalance = position.rewardPoolBalance
interaction.totalBalance = position.totalBalance
interaction.managerBalanceDelta = managerBalanceDelta
interaction.rewardPoolBalanceDelta = rewardPoolBalanceDelta

Expand Down

0 comments on commit c46f59e

Please sign in to comment.