Skip to content

Commit

Permalink
Merge pull request #8 from Tenderize/nv/fix-netdeposits
Browse files Browse the repository at this point in the history
fix: netdeposits calculation
  • Loading branch information
kyriediculous authored Jun 7, 2024
2 parents ac3ec2b + bc49269 commit 20160b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/subgraph/src/mappings/tenderizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export function handleUnlock(event: EmitUnlock): void {
let stake = Stake.load(event.params.receiver.toHex().concat('-').concat(event.address.toHex()))
if (stake == null) return
stake.shares = stake.shares.minus(shares)
let bal = stake.shares.times(tenderizer.tvl).div(tenderizer.shares)
let amount = convertToDecimal(event.params.assets)
if (bal.minus(stake.netDeposits).lt(amount)) {
// if rewards less than amount, set net deposits
// to balance minus what wasnt subtracted from the rewards
stake.netDeposits = bal.minus(amount.minus(stake.netDeposits))
} else {
// withdrawn rewards, do nothing
}
stake.netDeposits = stake.netDeposits.minus(convertToDecimal(event.params.assets))
stake.save()

Expand Down

0 comments on commit 20160b6

Please sign in to comment.