Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch amount from wei to numeric #666

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/utils/veUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 13 additions & 6 deletions src/mappings/veDelegation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BigInt } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { VeDelegationUpdate } from '../@types/schema'
import {
BurnBoost,
DelegateBoost,
ExtendBoost,
TransferBoost
} from '../@types/veDelegation/veDelegation'
import { weiToDecimal } from './utils/generic'
import { getveDelegation, getveOCEAN } from './utils/veUtils'

export function handleDelegation(event: DelegateBoost): void {
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/integration/VeOcean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand All @@ -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'
)
Expand Down