Merge branch 'main' into store-event-index

This commit is contained in:
Maria Carmina 2023-04-24 15:00:50 +03:00
commit 0b377b8e02
8 changed files with 99 additions and 19 deletions

View File

@ -4,12 +4,23 @@ 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.4](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.3...v3.0.4)
- add more veOcean stats [`#655`](https://github.com/oceanprotocol/ocean-subgraph/pull/655)
- Bump vm2 from 3.9.15 to 3.9.16 [`#653`](https://github.com/oceanprotocol/ocean-subgraph/pull/653)
- Bump typescript from 5.0.3 to 5.0.4 [`#652`](https://github.com/oceanprotocol/ocean-subgraph/pull/652)
- Bump vm2 from 3.9.11 to 3.9.15 [`#649`](https://github.com/oceanprotocol/ocean-subgraph/pull/649)
- Bump release-it from 15.10.0 to 15.10.1 [`#651`](https://github.com/oceanprotocol/ocean-subgraph/pull/651)
#### [v3.0.3](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.2...v3.0.3)
> 6 April 2023
- Removing amountFraction and adding timestamp [`#647`](https://github.com/oceanprotocol/ocean-subgraph/pull/647)
- Fixing decimals issue [`#644`](https://github.com/oceanprotocol/ocean-subgraph/pull/644)
- Bump typescript from 5.0.2 to 5.0.3 [`#641`](https://github.com/oceanprotocol/ocean-subgraph/pull/641)
- Bump release-it from 15.9.3 to 15.10.0 [`#640`](https://github.com/oceanprotocol/ocean-subgraph/pull/640)
- Release 3.0.3 [`d888d7d`](https://github.com/oceanprotocol/ocean-subgraph/commit/d888d7d2566c5fa0fe21903bd16d0b5329815526)
#### [v3.0.2](https://github.com/oceanprotocol/ocean-subgraph/compare/v3.0.1...v3.0.2)

30
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "ocean-subgraph",
"version": "3.0.3",
"version": "3.0.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ocean-subgraph",
"version": "3.0.3",
"version": "3.0.4",
"license": "Apache-2.0",
"dependencies": {
"@oceanprotocol/contracts": "^1.1.12",
@ -34,7 +34,7 @@
"eslint-plugin-standard": "^5.0.0",
"mocha": "^10.2.0",
"mock-local-storage": "^1.1.23",
"prettier": "^2.8.7",
"prettier": "^2.8.8",
"release-it": "^15.10.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
@ -10537,9 +10537,9 @@
}
},
"node_modules/prettier": {
"version": "2.8.7",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
@ -13788,9 +13788,9 @@
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"node_modules/vm2": {
"version": "3.9.15",
"resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.15.tgz",
"integrity": "sha512-XqNqknHGw2avJo13gbIwLNZUumvrSHc9mLqoadFZTpo3KaNEJoe1I0lqTFhRXmXD7WkLyG01aaraXdXT0pa4ag==",
"version": "3.9.17",
"resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.17.tgz",
"integrity": "sha512-AqwtCnZ/ERcX+AVj9vUsphY56YANXxRuqMb7GsDtAr0m0PcQX3u0Aj3KWiXM0YAHy7i6JEeHrwOnwXbGYgRpAw==",
"dev": true,
"dependencies": {
"acorn": "^8.7.0",
@ -22765,9 +22765,9 @@
"dev": true
},
"prettier": {
"version": "2.8.7",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true
},
"prettier-linter-helpers": {
@ -25213,9 +25213,9 @@
}
},
"vm2": {
"version": "3.9.15",
"resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.15.tgz",
"integrity": "sha512-XqNqknHGw2avJo13gbIwLNZUumvrSHc9mLqoadFZTpo3KaNEJoe1I0lqTFhRXmXD7WkLyG01aaraXdXT0pa4ag==",
"version": "3.9.17",
"resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.17.tgz",
"integrity": "sha512-AqwtCnZ/ERcX+AVj9vUsphY56YANXxRuqMb7GsDtAr0m0PcQX3u0Aj3KWiXM0YAHy7i6JEeHrwOnwXbGYgRpAw==",
"dev": true,
"requires": {
"acorn": "^8.7.0",

View File

@ -1,6 +1,6 @@
{
"name": "ocean-subgraph",
"version": "3.0.3",
"version": "3.0.4",
"scripts": {
"start": "",
"quickstart:development": "node ./scripts/generatenetworkssubgraphs.js development && npm run codegen && npm run create:local && npm run deploy:local",
@ -63,7 +63,7 @@
"eslint-plugin-standard": "^5.0.0",
"mocha": "^10.2.0",
"mock-local-storage": "^1.1.23",
"prettier": "^2.8.7",
"prettier": "^2.8.8",
"release-it": "^15.10.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",

View File

@ -346,6 +346,9 @@ type GlobalStatistic @entity {
"number of dispensers created"
dispenserCount: Int!
"total ocean locked in veOcean"
totalOceanLocked:BigDecimal!
"current version"
version: String
}
@ -518,6 +521,7 @@ type VeDeposit @entity {
tx: String!
eventIndex: Int!
veOcean: VeOCEAN!
totalOceanLocked:BigDecimal!
}

View File

@ -13,12 +13,13 @@ export function getGlobalStats(): GlobalStatistic {
let globalStats = GlobalStatistic.load(GLOBAL_ID)
if (!globalStats) {
globalStats = new GlobalStatistic(GLOBAL_ID)
globalStats.version = '3.0.3'
globalStats.version = '3.0.4'
globalStats.orderCount = 0
globalStats.fixedCount = 0
globalStats.datatokenCount = 0
globalStats.dispenserCount = 0
globalStats.nftCount = 0
globalStats.totalOceanLocked = BigDecimal.zero()
globalStats.save()
}
return globalStats
@ -33,6 +34,11 @@ export function getOPC(): OPC {
return globalStats
}
export function getTotalOceanLocked(): BigDecimal {
const globalStats = getGlobalStats()
return globalStats.totalOceanLocked
}
export function getTemplates(): Template {
let templates = Template.load(GLOBAL_ID)
if (!templates) {
@ -42,6 +48,12 @@ export function getTemplates(): Template {
return templates
}
export function updateTotalOceanLocked(amount: BigDecimal): void {
const globalStats = getGlobalStats()
globalStats.totalOceanLocked = amount
globalStats.save()
}
export function addOrder(): void {
const globalStats = getGlobalStats()
globalStats.orderCount = globalStats.orderCount + 1

View File

@ -64,4 +64,5 @@ export function handleBurnBoost(event: BurnBoost): void {
// delete
const veDelegation = getveDelegation(_tokenId.toHex())
veDelegation.amount = BigInt.zero()
veDelegation.save()
}

View File

@ -2,6 +2,10 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { Deposit, Supply, Withdraw } from '../@types/veOCEAN/veOCEAN'
import { weiToDecimal } from './utils/generic'
import { getDeposit, getveOCEAN } from './utils/veUtils'
import {
getTotalOceanLocked,
updateTotalOceanLocked
} from './utils/globalUtils'
export function handleDeposit(event: Deposit): void {
const provider = event.params.provider
@ -9,7 +13,7 @@ export function handleDeposit(event: Deposit): void {
const locktime = event.params.locktime
const type = event.params.type
const ts = event.params.ts
const totalOceanLocked = getTotalOceanLocked()
const veOCEAN = getveOCEAN(provider.toHex())
// Create new Deposit entity
const deposit = getDeposit(
@ -29,6 +33,10 @@ export function handleDeposit(event: Deposit): void {
deposit.eventIndex = event.logIndex.toI32()
deposit.sender = event.transaction.from.toHex()
deposit.veOcean = veOCEAN.id
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value)
updateTotalOceanLocked(deposit.totalOceanLocked)
deposit.save()
// --------------------------------------------
@ -40,6 +48,7 @@ export function handleDeposit(event: Deposit): void {
}
export function handleSupply(event: Supply): void {}
export function handleWithdraw(event: Withdraw): void {
const totalOceanLocked = getTotalOceanLocked()
const provider = event.params.provider
const value = event.params.value
const ts = event.params.ts
@ -63,6 +72,8 @@ export function handleWithdraw(event: Withdraw): void {
deposit.eventIndex = event.logIndex.toI32()
deposit.sender = event.transaction.from.toHex()
deposit.veOcean = veOCEAN.id
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value) // it's already negated above
updateTotalOceanLocked(deposit.totalOceanLocked)
deposit.save()
// --------------------------------------------

View File

@ -70,6 +70,23 @@ function evmIncreaseTime(seconds) {
})
}
async function getTotalLockedOcean() {
const initialQuery = {
query: `query{
globalStatistics{
totalOceanLocked
}
}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(initialQuery)
})
const data = (await initialResponse.json()).data.globalStatistics
if (data.length == 0) return 0
return data[0].totalOceanLocked
}
const minAbi = [
{
constant: false,
@ -144,6 +161,7 @@ describe('veOcean tests', async () => {
it('Alice should lock 100 Ocean', async () => {
// since we can only lock once, we test if tx fails or not
// so if there is already a lock, skip it
const totalOceanLockedBefore = await getTotalLockedOcean()
let currentBalance = await veOcean.getLockedAmount(Alice)
let currentLock = await veOcean.lockEnd(Alice)
const amount = '100'
@ -172,6 +190,19 @@ describe('veOcean tests', async () => {
currentBalance = await veOcean.getLockedAmount(Alice)
currentLock = await veOcean.lockEnd(Alice)
await sleep(2000)
const totalOceanLockedAfter = await getTotalLockedOcean()
assert(
parseFloat(totalOceanLockedAfter) > parseFloat(totalOceanLockedBefore),
'After (' +
totalOceanLockedAfter +
') shold be higher then ' +
totalOceanLockedBefore
)
assert(
parseFloat(totalOceanLockedAfter) ==
parseFloat(totalOceanLockedBefore + amount),
'Invalid totalOceanLockedAfter (' + totalOceanLockedAfter + ')'
)
const initialQuery = {
query: `query {
veOCEANs(id:"${Alice.toLowerCase()}"){
@ -558,7 +589,17 @@ describe('veOcean tests', async () => {
})
it('Alice should withdraw locked tokens', async () => {
await evmIncreaseTime(60 * 60 * 24 * 7)
const totalOceanLockedBefore = await getTotalLockedOcean()
await veOcean.withdraw(Alice)
await sleep(2000)
const totalOceanLockedAfter = await getTotalLockedOcean()
assert(
parseFloat(totalOceanLockedAfter) < parseFloat(totalOceanLockedBefore),
'After (' +
totalOceanLockedAfter +
') shold be lower then ' +
totalOceanLockedBefore
)
})
it('Alice should lock 100 Ocean and Delegate them to Bob', async () => {