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! receiver: VeOCEAN!
tokenId: BigInt! tokenId: BigInt!
amount: BigInt! amount: BigInt!
amountFraction: BigDecimal!
cancelTime: BigInt! cancelTime: BigInt!
expireTime: BigInt! expireTime: BigInt!
block: Int! block: Int!
timestamp: Int!
tx: String!
} }
type VeOCEAN @entity { type VeOCEAN @entity {

View File

@ -129,11 +129,12 @@ export function getveDelegation(id: string): VeDelegation {
veDelegation.cancelTime = BigInt.zero() veDelegation.cancelTime = BigInt.zero()
veDelegation.expireTime = BigInt.zero() veDelegation.expireTime = BigInt.zero()
veDelegation.tokenId = BigInt.zero() veDelegation.tokenId = BigInt.zero()
veDelegation.amountFraction = BigDecimal.zero()
veDelegation.amount = BigInt.zero() veDelegation.amount = BigInt.zero()
veDelegation.receiver = '' veDelegation.receiver = ''
veDelegation.delegator = '' veDelegation.delegator = ''
veDelegation.block = 0 veDelegation.block = 0
veDelegation.timestamp = 0
veDelegation.tx = ''
veDelegation.save() veDelegation.save()
} }
return veDelegation return veDelegation

View File

@ -1,4 +1,4 @@
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { BigInt } from '@graphprotocol/graph-ts'
import { import {
BurnBoost, BurnBoost,
DelegateBoost, DelegateBoost,
@ -6,7 +6,6 @@ import {
TransferBoost TransferBoost
} from '../@types/veDelegation/veDelegation' } from '../@types/veDelegation/veDelegation'
import { getveDelegation, getveOCEAN } from './utils/veUtils' import { getveDelegation, getveOCEAN } from './utils/veUtils'
import { weiToDecimal } from './utils/generic'
export function handleDelegation(event: DelegateBoost): void { export function handleDelegation(event: DelegateBoost): void {
const _delegator = event.params._delegator.toHex() const _delegator = event.params._delegator.toHex()
@ -19,18 +18,14 @@ export function handleDelegation(event: DelegateBoost): void {
const veDelegation = getveDelegation(_tokenId.toHex()) const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.delegator = _delegator veDelegation.delegator = _delegator
getveOCEAN(_receiver) getveOCEAN(_receiver)
const delegatorVeOcean = getveOCEAN(_delegator)
if (_amount && delegatorVeOcean.lockedAmount) {
veDelegation.amountFraction = _amount.divDecimal(
delegatorVeOcean.lockedAmount
)
}
veDelegation.receiver = _receiver veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId veDelegation.tokenId = _tokenId
veDelegation.amount = _amount veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime veDelegation.expireTime = _expireTime
veDelegation.block = event.block.number.toI32() veDelegation.block = event.block.number.toI32()
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.save() veDelegation.save()
} }
@ -43,18 +38,14 @@ export function handleExtendBoost(event: ExtendBoost): void {
const _expireTime = event.params._expire_time const _expireTime = event.params._expire_time
const veDelegation = getveDelegation(_tokenId.toHex()) 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.delegator = _delegator
veDelegation.receiver = _receiver veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId veDelegation.tokenId = _tokenId
veDelegation.amount = _amount veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime veDelegation.expireTime = _expireTime
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.save() veDelegation.save()
} }
@ -72,6 +63,5 @@ export function handleBurnBoost(event: BurnBoost): void {
// delete // delete
const veDelegation = getveDelegation(_tokenId.toHex()) const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.amountFraction = BigDecimal.zero()
veDelegation.amount = BigInt.zero() veDelegation.amount = BigInt.zero()
} }

View File

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