Resolve conflicts.

This commit is contained in:
Maria Carmina 2023-04-28 15:31:01 +03:00
commit 3308497677
9 changed files with 215 additions and 57 deletions

View File

@ -4,12 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### [v3.0.6](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.5...v3.0.6)
- proper veDelegation [`#663`](https://github.com/oceanprotocol/ocean-subgraph/pull/663)
#### [v3.0.5](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.4...v3.0.5)
> 26 April 2023
- add events handlers [`#662`](https://github.com/oceanprotocol/ocean-subgraph/pull/662)
- Bump prettier from 2.8.7 to 2.8.8 [`#660`](https://github.com/oceanprotocol/ocean-subgraph/pull/660)
- Bump vm2 from 3.9.16 to 3.9.17 [`#659`](https://github.com/oceanprotocol/ocean-subgraph/pull/659)
- Add missing veDelegation.save() [`#658`](https://github.com/oceanprotocol/ocean-subgraph/pull/658)
- Release 3.0.5 [`68944f0`](https://github.com/oceanprotocol/ocean-subgraph/commit/68944f02a545ea9c06881dcd8883f7dcecd72063)
#### [v3.0.4](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.3...v3.0.4)

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "ocean-subgraph",
"version": "3.0.5",
"version": "3.0.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ocean-subgraph",
"version": "3.0.5",
"version": "3.0.6",
"license": "Apache-2.0",
"dependencies": {
"@oceanprotocol/contracts": "^1.1.12",

View File

@ -1,6 +1,6 @@
{
"name": "ocean-subgraph",
"version": "3.0.5",
"version": "3.0.6",
"scripts": {
"start": "",
"quickstart:development": "node ./scripts/generatenetworkssubgraphs.js development && npm run codegen && npm run create:local && npm run deploy:local",

View File

@ -475,7 +475,7 @@ type VeAllocationUpdate @entity {
}
type VeDelegation @entity {
"{tx}-{tokenId}-{eventIndex}"
"id = VeDelegation contract + tokenId"
id: ID!
delegator: VeOCEAN!
receiver: VeOCEAN!
@ -483,12 +483,27 @@ type VeDelegation @entity {
amount: BigInt!
cancelTime: BigInt!
expireTime: BigInt!
updates: [VeDelegationUpdate!] @derivedFrom(field: "veDelegation")
}
type VeDelegationUpdate @entity {
"id = {tx}-{eventIndex}"
id: ID!
block: Int!
timestamp: Int!
tx: String!
eventIndex: Int!
sender: String!
amount: BigInt!
cancelTime: BigInt!
expireTime: BigInt!
"type: CREATE_BOOST = 0, EXTEND_BOOST = 1, BURN_BOOST = 2"
type:Int!
veDelegation:VeDelegation!
}
type VeOCEAN @entity {
"id = {user address}"
id: ID!

View File

@ -13,7 +13,7 @@ export function getGlobalStats(): GlobalStatistic {
let globalStats = GlobalStatistic.load(GLOBAL_ID)
if (!globalStats) {
globalStats = new GlobalStatistic(GLOBAL_ID)
globalStats.version = '3.0.5'
globalStats.version = '3.0.6'
globalStats.orderCount = 0
globalStats.fixedCount = 0
globalStats.datatokenCount = 0

View File

@ -125,7 +125,11 @@ export function writeveAllocationUpdate(
return allocationUpdate
}
export function getveDelegation(id: string): VeDelegation {
export function getveDelegation(
contract: Address,
eventid: string
): VeDelegation {
const id = contract.toHex() + '-' + eventid
let veDelegation = VeDelegation.load(id)
if (veDelegation === null) {
@ -136,10 +140,6 @@ export function getveDelegation(id: string): VeDelegation {
veDelegation.amount = BigInt.zero()
veDelegation.receiver = ''
veDelegation.delegator = ''
veDelegation.block = 0
veDelegation.timestamp = 0
veDelegation.tx = ''
veDelegation.eventIndex = 0
veDelegation.save()
}
return veDelegation

View File

@ -1,4 +1,5 @@
import { BigInt } from '@graphprotocol/graph-ts'
import { VeDelegationUpdate } from '../@types/schema'
import {
BurnBoost,
DelegateBoost,
@ -14,22 +15,33 @@ export function handleDelegation(event: DelegateBoost): void {
const _amount = event.params._amount
const _cancelTime = event.params._cancel_time
const _expireTime = event.params._expire_time
const tx = event.transaction.hash.toHex()
const veDelegation = getveDelegation(
`${tx}-${_tokenId.toHex()}-${event.logIndex.toString()}`
)
veDelegation.delegator = _delegator
// create veOcean if does not exists
getveOCEAN(_receiver)
getveOCEAN(_delegator)
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
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()
const veDelegationUpdate = new VeDelegationUpdate(
event.transaction.hash.toHex() + '-' + event.logIndex.toString()
)
veDelegationUpdate.type = 0
veDelegationUpdate.veDelegation = veDelegation.id
veDelegationUpdate.block = event.block.number.toI32()
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
veDelegationUpdate.tx = event.transaction.hash.toHex()
veDelegationUpdate.eventIndex = event.logIndex.toI32()
veDelegationUpdate.amount = _amount
veDelegationUpdate.cancelTime = _cancelTime
veDelegationUpdate.expireTime = _expireTime
veDelegationUpdate.sender = event.transaction.from.toHex()
veDelegationUpdate.save()
}
export function handleExtendBoost(event: ExtendBoost): void {
@ -39,22 +51,34 @@ export function handleExtendBoost(event: ExtendBoost): void {
const _amount = event.params._amount
const _cancelTime = event.params._cancel_time
const _expireTime = event.params._expire_time
const tx = event.transaction.hash.toHex()
const veDelegation = getveDelegation(
`${tx}-${_tokenId.toHex()}-${event.logIndex.toString()}`
)
if (!veDelegation) return
// create veOcean if does not exists
getveOCEAN(_receiver)
getveOCEAN(_delegator)
// it's possible to not have veDelegation object, because we missed handleDelegation
// that should not happend, but we create the object anyway
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
veDelegation.delegator = _delegator
veDelegation.receiver = _receiver
veDelegation.tokenId = _tokenId
veDelegation.amount = _amount
veDelegation.cancelTime = _cancelTime
veDelegation.expireTime = _expireTime
veDelegation.timestamp = event.block.timestamp.toI32()
veDelegation.tx = event.transaction.hash.toHex()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()
const veDelegationUpdate = new VeDelegationUpdate(
event.transaction.hash.toHex() + '-' + event.logIndex.toString()
)
veDelegationUpdate.veDelegation = veDelegation.id
veDelegationUpdate.type = 1
veDelegationUpdate.block = event.block.number.toI32()
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
veDelegationUpdate.tx = event.transaction.hash.toHex()
veDelegationUpdate.eventIndex = event.logIndex.toI32()
veDelegationUpdate.amount = _amount
veDelegationUpdate.cancelTime = _cancelTime
veDelegationUpdate.expireTime = _expireTime
veDelegationUpdate.sender = event.transaction.from.toHex()
veDelegationUpdate.save()
}
export function handleTransferBoost(event: TransferBoost): void {
@ -70,11 +94,23 @@ export function handleBurnBoost(event: BurnBoost): void {
const _tokenId = event.params._token_id
// delete
const tx = event.transaction.hash.toHex()
const veDelegation = getveDelegation(
`${tx}-${_tokenId.toHex()}-${event.logIndex.toString()}`
)
const veDelegation = getveDelegation(event.address, _tokenId.toHex())
veDelegation.amount = BigInt.zero()
veDelegation.eventIndex = event.logIndex.toI32()
veDelegation.save()
const veDelegationUpdate = new VeDelegationUpdate(
event.transaction.hash.toHex() + '-' + event.logIndex.toString()
)
veDelegationUpdate.veDelegation = veDelegation.id
veDelegationUpdate.type = 2
veDelegationUpdate.block = event.block.number.toI32()
veDelegationUpdate.timestamp = event.block.timestamp.toI32()
veDelegationUpdate.tx = event.transaction.hash.toHex()
veDelegationUpdate.eventIndex = event.logIndex.toI32()
veDelegationUpdate.amount = veDelegation.amount
veDelegationUpdate.cancelTime = veDelegation.cancelTime
veDelegationUpdate.expireTime = veDelegation.expireTime
veDelegationUpdate.sender = event.transaction.from.toHex()
veDelegationUpdate.save()
}

View File

@ -69,7 +69,7 @@
- event: ExtendBoost(indexed address,indexed address,indexed uint256,uint256,uint256,uint256)
handler: handleExtendBoost
- event: BurnBoost(indexed address,indexed address,indexed uint256)
handler: handleTransferBoost
handler: handleBurnBoost
- name: veFeeDistributor
kind: ethereum/contract

View File

@ -663,14 +663,15 @@ describe('veOcean tests', async () => {
await veOcean.increaseUnlockTime(Alice, extLockTime)
const estGas = await calculateEstimatedGas(
const initalBoostExpiry = extLockTime - 100000
let estGas = await calculateEstimatedGas(
Alice,
delegateContract.methods.create_boost,
Alice,
Bob,
10000,
5000,
0,
extLockTime,
initalBoostExpiry,
0
)
@ -682,48 +683,147 @@ describe('veOcean tests', async () => {
delegateContract.methods.create_boost,
Alice,
Bob,
10000,
5000,
0,
extLockTime,
initalBoostExpiry,
0
)
assert(tx3, 'Transaction failed')
assert(tx3.events.DelegateBoost, 'No Delegate boost event')
const tokenId = tx3.events.DelegateBoost.returnValues._token_id
await evmIncreaseTime(60)
// extend boost
estGas = await calculateEstimatedGas(
Alice,
delegateContract.methods.extend_boost,
tokenId,
10000,
extLockTime,
0
)
sleep(4000)
const tx4 = await sendTx(
Alice,
estGas,
web3,
1,
delegateContract.methods.extend_boost,
tokenId,
10000,
extLockTime,
0
)
assert(tx4, 'Transaction failed')
assert(tx4.events.ExtendBoost, 'No ExtendBoost event')
await evmIncreaseTime(60)
// burn it
estGas = await calculateEstimatedGas(
Alice,
delegateContract.methods.cancel_boost,
tokenId
)
const tx5 = await sendTx(
Alice,
estGas,
web3,
1,
delegateContract.methods.cancel_boost,
tokenId
)
assert(tx5, 'Transaction failed')
assert(tx5.events.BurnBoost, 'No BurnBoost event')
await sleep(3000)
const delegateQuery = {
query: `query {
veDelegations{
id,
query: `query{
veDelegations(where:{delegator:"${Alice.toLowerCase()}"}){
id
delegator {
id
},
receiver {
}
receiver{
id
},
tokenId,
amount,
cancelTime,
expireTime,
eventIndex
}
amount
tokenId
cancelTime
expireTime
updates(orderBy:timestamp orderDirection:asc){
id
block
timestamp
tx
eventIndex
sender
amount
cancelTime
expireTime
type
}
}
}`
}`
}
const delegateResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(delegateQuery)
})
const json = await delegateResponse.json()
assert(json?.data?.veDelegations, 'No veDelegations')
const resp = await delegateResponse.json()
const delegations = resp.data.veDelegations
assert(delegations.length > 0, 'No veDelegations')
assert(
json?.data?.veDelegations.eventIndex !== null,
'Invalid eventIndex for veDelegation'
delegations[0].tokenId.toLowerCase() ==
tx3.events.DelegateBoost.returnValues._token_id.toLowerCase(),
'Invalid tokenID'
)
assert(delegations[0].amount == '0', 'Invalid amount, should be 0')
assert(delegations[0].updates.length > 0, 'No updates')
// check updates. first is create boost
assert(
delegations[0].updates[0].type == 0,
'Invalid type. should be createBoost'
)
assert(
json?.data?.veDelegations.id !== null,
'Invalid eventIndex for veDelegation'
delegations[0].updates[0].cancelTime ==
tx3.events.DelegateBoost.returnValues._cancel_time,
'Invalid cancelTime'
)
assert(
delegations[0].updates[0].expireTime ==
tx3.events.DelegateBoost.returnValues._expire_time,
'Invalid expireTime'
)
assert(
delegations[0].updates[0].amount ==
tx3.events.DelegateBoost.returnValues._amount,
'Invalid amount'
)
// check extend boos update
assert(
delegations[0].updates[1].type == 1,
'Invalid type. should be extend Boost'
)
assert(
delegations[0].updates[1].cancelTime ==
tx4.events.ExtendBoost.returnValues._cancel_time,
'Invalid cancelTime for extend boost'
)
assert(
delegations[0].updates[1].expireTime ==
tx4.events.ExtendBoost.returnValues._expire_time,
'Invalid expireTime for extend boost'
)
assert(
delegations[0].updates[1].amount ==
tx4.events.ExtendBoost.returnValues._amount,
'Invalid amount for extend boost'
)
// check burn
assert(delegations[0].updates[2].type == 2, 'Invalid type. should be burn')
})
})