Skip to content

Commit

Permalink
Removing amountFraction and adding timestamp (#647)
Browse files Browse the repository at this point in the history
* Removing amountFraction

* Adding block timestamp

* initiating veDelegation timestamp

* add tx as well

---------

Co-authored-by: alexcos20 <[email protected]>
  • Loading branch information
jamiehewitt15 and alexcos20 authored Apr 6, 2023
1 parent 0cf40d4 commit 420a229
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,11 @@ type VeDelegation @entity {
receiver: VeOCEAN!
tokenId: BigInt!
amount: BigInt!
amountFraction: BigDecimal!
cancelTime: BigInt!
expireTime: BigInt!
block: Int!
timestamp: Int!
tx: String!
}

type VeOCEAN @entity {
Expand Down
3 changes: 2 additions & 1 deletion src/mappings/utils/veUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ export function getveDelegation(id: string): VeDelegation {
veDelegation.cancelTime = BigInt.zero()
veDelegation.expireTime = BigInt.zero()
veDelegation.tokenId = BigInt.zero()
veDelegation.amountFraction = BigDecimal.zero()
veDelegation.amount = BigInt.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.block = 0
veDelegation.timestamp = 0
veDelegation.tx = ''
veDelegation.save()
}
return veDelegation
Expand Down
20 changes: 5 additions & 15 deletions src/mappings/veDelegation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { BigInt } from '@graphprotocol/graph-ts'
import {
BurnBoost,
DelegateBoost,
ExtendBoost,
TransferBoost
} from '../@types/veDelegation/veDelegation'
import { getveDelegation, getveOCEAN } from './utils/veUtils'
import { weiToDecimal } from './utils/generic'

export function handleDelegation(event: DelegateBoost): void {
const _delegator = event.params._delegator.toHex()
Expand All @@ -19,18 +18,14 @@ export function handleDelegation(event: DelegateBoost): void {
const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.delegator = _delegator
getveOCEAN(_receiver)
const delegatorVeOcean = getveOCEAN(_delegator)
if (_amount && delegatorVeOcean.lockedAmount) {
veDelegation.amountFraction = _amount.divDecimal(
delegatorVeOcean.lockedAmount
)
}
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.block = event.block.number.toI32()
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.save()
}

Expand All @@ -43,18 +38,14 @@ export function handleExtendBoost(event: ExtendBoost): void {
const _expireTime = event.params._expire_time

const veDelegation = getveDelegation(_tokenId.toHex())
const delegatorVeOcean = getveOCEAN(_delegator)
if (_amount && delegatorVeOcean.lockedAmount) {
veDelegation.amountFraction = weiToDecimal(_amount.toBigDecimal(), 18).div(
delegatorVeOcean.lockedAmount
)
}
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.save()
}

Expand All @@ -72,6 +63,5 @@ export function handleBurnBoost(event: BurnBoost): void {

// delete
const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.amountFraction = BigDecimal.zero()
veDelegation.amount = BigInt.zero()
}
1 change: 0 additions & 1 deletion test/integration/VeOcean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ describe('veOcean tests', async () => {
},
tokenId,
amount,
amountFraction,
cancelTime,
expireTime
}
Expand Down

0 comments on commit 420a229

Please sign in to comment.