Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lockedAmount to veDelegation #672

Merged
merged 14 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ type VeDelegation @entity {
receiver: VeOCEAN!
tokenId: BigInt!
amount: BigDecimal!
lockedAmount: BigDecimal!
timeLeft: Int!
cancelTime: BigInt!
expireTime: BigInt!
updates: [VeDelegationUpdate!] @derivedFrom(field: "veDelegation")
Expand Down Expand Up @@ -609,4 +611,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 @@ -136,6 +136,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