switch amount from wei to numeric (#666)

This commit is contained in:
Alex Coseru 2023-04-28 17:37:02 +03:00 committed by GitHub
parent 9fd0553337
commit 5b2ccbc276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View File

@ -467,7 +467,7 @@ type VeDelegation @entity {
delegator: VeOCEAN!
receiver: VeOCEAN!
tokenId: BigInt!
amount: BigInt!
amount: BigDecimal!
cancelTime: BigInt!
expireTime: BigInt!
updates: [VeDelegationUpdate!] @derivedFrom(field: "veDelegation")
@ -481,7 +481,7 @@ type VeDelegationUpdate @entity {
timestamp: Int!
tx: String!
sender: String!
amount: BigInt!
amount: BigDecimal!
cancelTime: BigInt!
expireTime: BigInt!
"type: CREATE_BOOST = 0, EXTEND_BOOST = 1, BURN_BOOST = 2"

View File

@ -133,7 +133,7 @@ export function getveDelegation(
veDelegation.cancelTime = BigInt.zero()
veDelegation.expireTime = BigInt.zero()
veDelegation.tokenId = BigInt.zero()
veDelegation.amount = BigInt.zero()
veDelegation.amount = BigDecimal.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.save()

View File

@ -1,4 +1,4 @@
import { BigInt } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { VeDelegationUpdate } from '../@types/schema'
import {
BurnBoost,
@ -6,6 +6,7 @@ import {
ExtendBoost,
TransferBoost
} from '../@types/veDelegation/veDelegation'
import { weiToDecimal } from './utils/generic'
import { getveDelegation, getveOCEAN } from './utils/veUtils'
export function handleDelegation(event: DelegateBoost): void {
@ -23,7 +24,10 @@ export function handleDelegation(event: DelegateBoost): void {
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.amount = weiToDecimal(
_amount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.save()
@ -36,7 +40,7 @@ export function handleDelegation(event: DelegateBoost): void {
veDelegationUpdate.block = event.block.number.toI32()
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
veDelegationUpdate.tx = event.transaction.hash.toHex()
veDelegationUpdate.amount = _amount
veDelegationUpdate.amount = veDelegation.amount
veDelegationUpdate.cancelTime = _cancelTime
veDelegationUpdate.expireTime = _expireTime
veDelegationUpdate.sender = event.transaction.from.toHex()
@ -59,7 +63,10 @@ export function handleExtendBoost(event: ExtendBoost): void {
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.amount = weiToDecimal(
_amount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.save()
@ -72,7 +79,7 @@ export function handleExtendBoost(event: ExtendBoost): void {
veDelegationUpdate.block = event.block.number.toI32()
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
veDelegationUpdate.tx = event.transaction.hash.toHex()
veDelegationUpdate.amount = _amount
veDelegationUpdate.amount = veDelegation.amount
veDelegationUpdate.cancelTime = _cancelTime
veDelegationUpdate.expireTime = _expireTime
veDelegationUpdate.sender = event.transaction.from.toHex()
@ -93,7 +100,7 @@ export function handleBurnBoost(event: BurnBoost): void {
// delete
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
veDelegation.amount = BigInt.zero()
veDelegation.amount = BigDecimal.zero()
veDelegation.save()
const veDelegationUpdate = new VeDelegationUpdate(

View File

@ -790,7 +790,7 @@ describe('veOcean tests', async () => {
'Invalid expireTime'
)
assert(
delegations[0].updates[0].amount ==
web3.utils.toWei(delegations[0].updates[0].amount) ==
tx3.events.DelegateBoost.returnValues._amount,
'Invalid amount'
)
@ -810,7 +810,7 @@ describe('veOcean tests', async () => {
'Invalid expireTime for extend boost'
)
assert(
delegations[0].updates[1].amount ==
web3.utils.toWei(delegations[0].updates[1].amount) ==
tx4.events.ExtendBoost.returnValues._amount,
'Invalid amount for extend boost'
)