Skip to content

Commit

Permalink
Add lockedAmount to veDelegation (#672)
Browse files Browse the repository at this point in the history
* Add lockedAmount to veDelegation

* Fix typo

* Fixes

* Add lockedAmountinVe

* Replace lockedAmountinVe with timeLeft

* Use event.params.ts

* Fixes

* Fix

* Delete maxtime

* Fix

* Fix and rename

* Revert "Fix and rename"

This reverts commit 70846ea.

* fix

* fix

---------

Co-authored-by: alexcos20 <alex.coseru@gmail.com>
  • Loading branch information
trizin and alexcos20 authored May 13, 2023
1 parent e1df119 commit 2ca1280
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ type VeDelegation @entity {
receiver: VeOCEAN!
tokenId: BigInt!
amount: BigDecimal!
lockedAmount: BigDecimal!
timeLeftUnlock: Int!
cancelTime: BigInt!
expireTime: BigInt!
updates: [VeDelegationUpdate!] @derivedFrom(field: "veDelegation")
Expand Down Expand Up @@ -628,4 +630,3 @@ type NftTransferHistory @entity {
timestamp: Int!
block: Int!
}

2 changes: 2 additions & 0 deletions src/mappings/utils/veUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export function getveDelegation(
veDelegation.amount = BigDecimal.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.lockedAmount = BigDecimal.zero()
veDelegation.timeLeftUnlock = 0
veDelegation.save()
}
return veDelegation
Expand Down
7 changes: 5 additions & 2 deletions src/mappings/veDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ export function handleDelegation(event: DelegateBoost): void {
const _expireTime = event.params._expire_time
// create veOcean if does not exists
getveOCEAN(_receiver)
getveOCEAN(_delegator)

const delegator = getveOCEAN(_delegator)
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
const ts = event.block.timestamp.toI32()

veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = weiToDecimal(
_amount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
veDelegation.lockedAmount = delegator.lockedAmount
veDelegation.timeLeftUnlock = delegator.unlockTime.toI32() - ts
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.save()
Expand Down

0 comments on commit 2ca1280

Please sign in to comment.