Rollback to the approach for veDelegation like it is in main.

This commit is contained in:
Maria Carmina 2023-04-26 17:34:15 +03:00
parent c1e2d28738
commit 20abe8dd65
3 changed files with 27 additions and 47 deletions

View File

@ -126,36 +126,24 @@ export function writeveAllocationUpdate(
return allocationUpdate
}
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
}
}
return null
}
export function getveDelegation(id: string): VeDelegation {
let veDelegation = VeDelegation.load(id)
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()
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 veDelegation
}
export function getDeposit(id: string): VeDeposit {
let deposit = VeDeposit.load(id)
if (deposit === null) {

View File

@ -5,11 +5,7 @@ import {
ExtendBoost,
TransferBoost
} from '../@types/veDelegation/veDelegation'
import {
createDefaultVeDelegation,
getveDelegation,
getveOCEAN
} from './utils/veUtils'
import { getveDelegation, getveOCEAN } from './utils/veUtils'
export function handleDelegation(event: DelegateBoost): void {
const _delegator = event.params._delegator.toHex()
@ -20,12 +16,9 @@ export function handleDelegation(event: DelegateBoost): void {
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(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
veDelegation.delegator = _delegator
getveOCEAN(_receiver)
veDelegation.receiver = _receiver
@ -49,7 +42,9 @@ export function handleExtendBoost(event: ExtendBoost): void {
const _expireTime = event.params._expire_time
const eventIndex: number = event.logIndex.toI32()
const tx = event.transaction.hash.toHex()
const veDelegation = getveDelegation(tx, _tokenId.toHex(), eventIndex)
const veDelegation = getveDelegation(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
if (!veDelegation) return
veDelegation.delegator = _delegator
@ -79,14 +74,9 @@ export function handleBurnBoost(event: BurnBoost): void {
// delete
const eventIndex: number = event.logIndex.toI32()
const tx = event.transaction.hash.toHex()
const veDelegation = getveDelegation(tx, _tokenId.toHex(), eventIndex)
if (!veDelegation) return
// {
// veDelegation = createDefaultVeDelegation(
// `${tx}-${_tokenId.toHex()}-${eventIndex}`
// )
// }
const veDelegation = getveDelegation(
`${tx}-${_tokenId.toHex()}-${eventIndex}`
)
veDelegation.amount = BigInt.zero()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()

View File

@ -40,6 +40,8 @@ describe('Ending tests', () => {
assert(result.data._meta.hasIndexingErrors == false)
})
it('Make sure that graph has synced to last block', async () => {
console.log('meta.block: ', result.data._meta.block.number)
console.log('lastblock: ', lastblock)
assert(result.data._meta.block.number >= lastblock)
})
})