Changed IDs for VeDelegation and VeAllocationUpdate.

This commit is contained in:
Maria Carmina 2023-04-25 15:41:13 +03:00
parent 402acc58b9
commit 7c717392bc
5 changed files with 91 additions and 28 deletions

View File

@ -76,6 +76,7 @@ jobs:
npm run test-fixed
npm run test-dispenser
npm run test-nft
npm run test-ve
env:
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
BARGE_FOLDER: /home/runner/.ocean/

View File

@ -461,7 +461,7 @@ enum veAllocationUpdateType {
}
type VeAllocationUpdate @entity {
"{tx}-{VeAllocation id}"
"{tx}-{VeAllocation id}-{eventIndex}"
id: ID!
veAllocation: VeAllocation!
@ -475,7 +475,7 @@ type VeAllocationUpdate @entity {
}
type VeDelegation @entity {
"id = tokenId"
"{tx}-{tokenId}-{eventIndex}"
id: ID!
delegator: VeOCEAN!
receiver: VeOCEAN!
@ -486,6 +486,7 @@ type VeDelegation @entity {
block: Int!
timestamp: Int!
tx: String!
eventIndex: Int!
}
type VeOCEAN @entity {

View File

@ -106,10 +106,11 @@ export function writeveAllocationUpdate(
allocationType: string,
amount: BigDecimal
): VeAllocationUpdate {
const tx = event.transaction.hash.toHex()
let allocationUpdate = VeAllocationUpdate.load(tx + '-' + veAllocationId)
const eventIndex: number = event.logIndex.toI32()
const id = `${event.transaction.hash.toHex()}-${veAllocationId}-${eventIndex}`
let allocationUpdate = VeAllocationUpdate.load(id)
if (allocationUpdate === null) {
allocationUpdate = new VeAllocationUpdate(tx + '-' + veAllocationId)
allocationUpdate = new VeAllocationUpdate(id)
allocationUpdate.veAllocation = veAllocationId
allocationUpdate.type = allocationType
allocationUpdate.allocatedTotal = amount
@ -125,22 +126,47 @@ export function writeveAllocationUpdate(
return allocationUpdate
}
export function getveDelegation(id: string): VeDelegation {
let veDelegation = VeDelegation.load(id)
if (veDelegation === null) {
veDelegation = new VeDelegation(id)
veDelegation.cancelTime = BigInt.zero()
veDelegation.expireTime = BigInt.zero()
veDelegation.tokenId = BigInt.zero()
veDelegation.amount = BigInt.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.block = 0
veDelegation.timestamp = 0
veDelegation.tx = ''
veDelegation.save()
export function getveDelegation(
transactionHash: string,
tokenId: string,
eventIndex: number
): VeDelegation | null {
for (let i = eventIndex; i >= 0; i--) {
const id = `${transactionHash}-${tokenId}-${i}`
const veDelegation = VeDelegation.load(id)
if (veDelegation) {
return veDelegation
}
}
// if (veDelegation === null) {
// veDelegation = new VeDelegation(id)
// veDelegation.cancelTime = BigInt.zero()
// veDelegation.expireTime = BigInt.zero()
// veDelegation.tokenId = BigInt.zero()
// veDelegation.amount = BigInt.zero()
// veDelegation.receiver = ''
// veDelegation.delegator = ''
// veDelegation.block = 0
// veDelegation.timestamp = 0
// veDelegation.tx = ''
// veDelegation.save()
// }
return null
}
export function createDefaultVeDelegation(id: string): VeDelegation {
const veDelegation = new VeDelegation(id)
veDelegation.cancelTime = BigInt.zero()
veDelegation.expireTime = BigInt.zero()
veDelegation.tokenId = BigInt.zero()
veDelegation.amount = BigInt.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.block = 0
veDelegation.timestamp = 0
veDelegation.tx = ''
veDelegation.save()
return veDelegation
}

View File

@ -5,7 +5,11 @@ import {
ExtendBoost,
TransferBoost
} from '../@types/veDelegation/veDelegation'
import { getveDelegation, getveOCEAN } from './utils/veUtils'
import {
createDefaultVeDelegation,
getveDelegation,
getveOCEAN
} from './utils/veUtils'
export function handleDelegation(event: DelegateBoost): void {
const _delegator = event.params._delegator.toHex()
@ -14,8 +18,14 @@ export function handleDelegation(event: DelegateBoost): void {
const _amount = event.params._amount
const _cancelTime = event.params._cancel_time
const _expireTime = event.params._expire_time
const veDelegation = getveDelegation(_tokenId.toHex())
const eventIndex: number = event.logIndex.toI32()
const tx = event.transaction.hash.toHex()
let veDelegation = getveDelegation(tx, _tokenId.toHex(), eventIndex)
if (!veDelegation) {
veDelegation = createDefaultVeDelegation(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
}
veDelegation.delegator = _delegator
getveOCEAN(_receiver)
veDelegation.receiver = _receiver
@ -26,6 +36,7 @@ export function handleDelegation(event: DelegateBoost): void {
veDelegation.block = event.block.number.toI32()
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()
}
@ -36,8 +47,15 @@ export function handleExtendBoost(event: ExtendBoost): void {
const _amount = event.params._amount
const _cancelTime = event.params._cancel_time
const _expireTime = event.params._expire_time
const eventIndex: number = event.logIndex.toI32()
const tx = event.transaction.hash.toHex()
let veDelegation = getveDelegation(tx, _tokenId.toHex(), eventIndex)
if (!veDelegation) {
veDelegation = createDefaultVeDelegation(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
}
const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
@ -46,6 +64,7 @@ export function handleExtendBoost(event: ExtendBoost): void {
veDelegation.expireTime = _expireTime
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()
}
@ -62,7 +81,15 @@ export function handleBurnBoost(event: BurnBoost): void {
const _tokenId = event.params._token_id
// delete
const veDelegation = getveDelegation(_tokenId.toHex())
const eventIndex: number = event.logIndex.toI32()
const tx = event.transaction.hash.toHex()
let veDelegation = getveDelegation(tx, _tokenId.toHex(), eventIndex)
if (!veDelegation) {
veDelegation = createDefaultVeDelegation(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
}
veDelegation.amount = BigInt.zero()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()
}

View File

@ -706,7 +706,8 @@ describe('veOcean tests', async () => {
tokenId,
amount,
cancelTime,
expireTime
expireTime,
eventIndex
}
}`
}
@ -716,8 +717,15 @@ describe('veOcean tests', async () => {
body: JSON.stringify(delegateQuery)
})
const json = await delegateResponse.json()
console.log('json', json)
console.log('json?.data?.veDelegations', json?.data?.veDelegations)
console.log('json: ', json)
assert(json?.data?.veDelegations, 'No veDelegations')
assert(
json?.data?.veDelegations.eventIndex !== null,
'Invalid eventIndex for veDelegation'
)
assert(
json?.data?.veDelegations.id !== null,
'Invalid eventIndex for veDelegation'
)
})
})