Skip to content

Commit

Permalink
Fix genesis vault apy before pool migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi committed Jul 23, 2024
1 parent a6ca862 commit b2b0a4e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v3-subgraph",
"version": "2.0.2",
"version": "2.0.3",
"description": "Subgraph for the StakeWise Protocol",
"repository": "https://github.com/stakewise/v3-subgraph",
"license": "AGPL-3.0-only",
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ export function getPoolStateUpdate(
penaltyAssets = ethereum.decode('uint256', resultValue[2].returnData)!.toBigInt()
principalAssets = ethereum.decode('uint256', resultValue[3].returnData)!.toBigInt()
}
const newRate = BigInt.fromString(WAD)
.times(rewardAssets.plus(principalAssets).minus(penaltyAssets))
.div(principalAssets)
let newRate = BigInt.fromString(WAD)
if (principalAssets.gt(BigInt.fromI32(0))) {
newRate = newRate.times(rewardAssets.plus(principalAssets).minus(penaltyAssets)).div(principalAssets)
}

return [newRate, rewardAssets, principalAssets, penaltyAssets]
}
Expand Down
6 changes: 5 additions & 1 deletion src/mappings/depositDataRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export function handleDepositDataRootUpdated(event: DepositDataRootUpdated): voi
const depositDataRoot = event.params.depositDataRoot

// Vault must exist at the time of the event
const vault = Vault.load(vaultAddress) as Vault
const vault = Vault.load(vaultAddress)
if (vault === null) {
log.error('[DepositDataRegistry] DepositDataRootUpdated vault={} not found', [vaultAddress])
return
}
vault.depositDataRoot = depositDataRoot
// Update deprecated validators root
vault.validatorsRoot = depositDataRoot
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ export function updateRewards(
slashedMevReward = slashedMevReward.plus(vault.lockedExecutionReward.minus(lockedMevReward))
}

updateVaultApy(vault, vault.rewardsTimestamp, updateTimestamp, newRate.minus(vault.rate))
if (!vault.isGenesis || v2Pool.migrated) {
updateVaultApy(vault, vault.rewardsTimestamp, updateTimestamp, newRate.minus(vault.rate))
}

vaultsStat.totalAssets = vaultsStat.totalAssets.minus(vault.totalAssets).plus(newTotalAssets)
vault.totalAssets = newTotalAssets
Expand Down

0 comments on commit b2b0a4e

Please sign in to comment.