Skip to content

Commit 5b2ccbc

Browse files
authored
switch amount from wei to numeric (#666)
1 parent 9fd0553 commit 5b2ccbc

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

schema.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ type VeDelegation @entity {
467467
delegator: VeOCEAN!
468468
receiver: VeOCEAN!
469469
tokenId: BigInt!
470-
amount: BigInt!
470+
amount: BigDecimal!
471471
cancelTime: BigInt!
472472
expireTime: BigInt!
473473
updates: [VeDelegationUpdate!] @derivedFrom(field: "veDelegation")
@@ -481,7 +481,7 @@ type VeDelegationUpdate @entity {
481481
timestamp: Int!
482482
tx: String!
483483
sender: String!
484-
amount: BigInt!
484+
amount: BigDecimal!
485485
cancelTime: BigInt!
486486
expireTime: BigInt!
487487
"type: CREATE_BOOST = 0, EXTEND_BOOST = 1, BURN_BOOST = 2"

src/mappings/utils/veUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function getveDelegation(
133133
veDelegation.cancelTime = BigInt.zero()
134134
veDelegation.expireTime = BigInt.zero()
135135
veDelegation.tokenId = BigInt.zero()
136-
veDelegation.amount = BigInt.zero()
136+
veDelegation.amount = BigDecimal.zero()
137137
veDelegation.receiver = ''
138138
veDelegation.delegator = ''
139139
veDelegation.save()

src/mappings/veDelegation.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { BigInt } from '@graphprotocol/graph-ts'
1+
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
22
import { VeDelegationUpdate } from '../@types/schema'
33
import {
44
BurnBoost,
55
DelegateBoost,
66
ExtendBoost,
77
TransferBoost
88
} from '../@types/veDelegation/veDelegation'
9+
import { weiToDecimal } from './utils/generic'
910
import { getveDelegation, getveOCEAN } from './utils/veUtils'
1011

1112
export function handleDelegation(event: DelegateBoost): void {
@@ -23,7 +24,10 @@ export function handleDelegation(event: DelegateBoost): void {
2324
veDelegation.delegator = _delegator
2425
veDelegation.receiver = _receiver
2526
veDelegation.tokenId = _tokenId
26-
veDelegation.amount = _amount
27+
veDelegation.amount = weiToDecimal(
28+
_amount.toBigDecimal(),
29+
BigInt.fromI32(18).toI32()
30+
)
2731
veDelegation.cancelTime = _cancelTime
2832
veDelegation.expireTime = _expireTime
2933
veDelegation.save()
@@ -36,7 +40,7 @@ export function handleDelegation(event: DelegateBoost): void {
3640
veDelegationUpdate.block = event.block.number.toI32()
3741
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
3842
veDelegationUpdate.tx = event.transaction.hash.toHex()
39-
veDelegationUpdate.amount = _amount
43+
veDelegationUpdate.amount = veDelegation.amount
4044
veDelegationUpdate.cancelTime = _cancelTime
4145
veDelegationUpdate.expireTime = _expireTime
4246
veDelegationUpdate.sender = event.transaction.from.toHex()
@@ -59,7 +63,10 @@ export function handleExtendBoost(event: ExtendBoost): void {
5963
veDelegation.delegator = _delegator
6064
veDelegation.receiver = _receiver
6165
veDelegation.tokenId = _tokenId
62-
veDelegation.amount = _amount
66+
veDelegation.amount = weiToDecimal(
67+
_amount.toBigDecimal(),
68+
BigInt.fromI32(18).toI32()
69+
)
6370
veDelegation.cancelTime = _cancelTime
6471
veDelegation.expireTime = _expireTime
6572
veDelegation.save()
@@ -72,7 +79,7 @@ export function handleExtendBoost(event: ExtendBoost): void {
7279
veDelegationUpdate.block = event.block.number.toI32()
7380
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
7481
veDelegationUpdate.tx = event.transaction.hash.toHex()
75-
veDelegationUpdate.amount = _amount
82+
veDelegationUpdate.amount = veDelegation.amount
7683
veDelegationUpdate.cancelTime = _cancelTime
7784
veDelegationUpdate.expireTime = _expireTime
7885
veDelegationUpdate.sender = event.transaction.from.toHex()
@@ -93,7 +100,7 @@ export function handleBurnBoost(event: BurnBoost): void {
93100

94101
// delete
95102
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
96-
veDelegation.amount = BigInt.zero()
103+
veDelegation.amount = BigDecimal.zero()
97104
veDelegation.save()
98105

99106
const veDelegationUpdate = new VeDelegationUpdate(

test/integration/VeOcean.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ describe('veOcean tests', async () => {
790790
'Invalid expireTime'
791791
)
792792
assert(
793-
delegations[0].updates[0].amount ==
793+
web3.utils.toWei(delegations[0].updates[0].amount) ==
794794
tx3.events.DelegateBoost.returnValues._amount,
795795
'Invalid amount'
796796
)
@@ -810,7 +810,7 @@ describe('veOcean tests', async () => {
810810
'Invalid expireTime for extend boost'
811811
)
812812
assert(
813-
delegations[0].updates[1].amount ==
813+
web3.utils.toWei(delegations[0].updates[1].amount) ==
814814
tx4.events.ExtendBoost.returnValues._amount,
815815
'Invalid amount for extend boost'
816816
)

0 commit comments

Comments
 (0)