Removing amountFraction and adding timestamp (#647)

* Removing amountFraction

* Adding block timestamp

* initiating veDelegation timestamp

* add tx as well

---------

Co-authored-by: alexcos20 <alex.coseru@gmail.com>
This commit is contained in:
Jamie Hewitt 2023-04-06 11:13:22 +03:00 committed by GitHub
parent 0cf40d40ce
commit 420a229a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 18 deletions

View File

@ -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 {

View File

@ -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

View File

@ -1,4 +1,4 @@
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { BigInt } from '@graphprotocol/graph-ts'
import {
BurnBoost,
DelegateBoost,
@ -6,7 +6,6 @@ import {
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()
@ -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()
}
@ -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()
}
@ -72,6 +63,5 @@ export function handleBurnBoost(event: BurnBoost): void {
// delete
const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.amountFraction = BigDecimal.zero()
veDelegation.amount = BigInt.zero()
}

View File

@ -656,7 +656,6 @@ describe('veOcean tests', async () => {
},
tokenId,
amount,
amountFraction,
cancelTime,
expireTime
}