mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
parent
81b43ecc20
commit
b376cb3942
@ -338,6 +338,9 @@ type GlobalStatistic @entity {
|
|||||||
"number of dispensers created"
|
"number of dispensers created"
|
||||||
dispenserCount: Int!
|
dispenserCount: Int!
|
||||||
|
|
||||||
|
"total ocean locked in veOcean"
|
||||||
|
totalOceanLocked:BigDecimal!
|
||||||
|
|
||||||
"current version"
|
"current version"
|
||||||
version: String
|
version: String
|
||||||
}
|
}
|
||||||
@ -504,6 +507,7 @@ type VeDeposit @entity {
|
|||||||
block: Int!
|
block: Int!
|
||||||
tx: String!
|
tx: String!
|
||||||
veOcean: VeOCEAN!
|
veOcean: VeOCEAN!
|
||||||
|
totalOceanLocked:BigDecimal!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ export function getGlobalStats(): GlobalStatistic {
|
|||||||
globalStats.datatokenCount = 0
|
globalStats.datatokenCount = 0
|
||||||
globalStats.dispenserCount = 0
|
globalStats.dispenserCount = 0
|
||||||
globalStats.nftCount = 0
|
globalStats.nftCount = 0
|
||||||
|
globalStats.totalOceanLocked = BigDecimal.zero()
|
||||||
globalStats.save()
|
globalStats.save()
|
||||||
}
|
}
|
||||||
return globalStats
|
return globalStats
|
||||||
@ -33,6 +34,11 @@ export function getOPC(): OPC {
|
|||||||
return globalStats
|
return globalStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTotalOceanLocked(): BigDecimal {
|
||||||
|
const globalStats = getGlobalStats()
|
||||||
|
return globalStats.totalOceanLocked
|
||||||
|
}
|
||||||
|
|
||||||
export function getTemplates(): Template {
|
export function getTemplates(): Template {
|
||||||
let templates = Template.load(GLOBAL_ID)
|
let templates = Template.load(GLOBAL_ID)
|
||||||
if (!templates) {
|
if (!templates) {
|
||||||
@ -42,6 +48,12 @@ export function getTemplates(): Template {
|
|||||||
return templates
|
return templates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateTotalOceanLocked(amount: BigDecimal): void {
|
||||||
|
const globalStats = getGlobalStats()
|
||||||
|
globalStats.totalOceanLocked = amount
|
||||||
|
globalStats.save()
|
||||||
|
}
|
||||||
|
|
||||||
export function addOrder(): void {
|
export function addOrder(): void {
|
||||||
const globalStats = getGlobalStats()
|
const globalStats = getGlobalStats()
|
||||||
globalStats.orderCount = globalStats.orderCount + 1
|
globalStats.orderCount = globalStats.orderCount + 1
|
||||||
|
@ -2,6 +2,10 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
|
|||||||
import { Deposit, Supply, Withdraw } from '../@types/veOCEAN/veOCEAN'
|
import { Deposit, Supply, Withdraw } from '../@types/veOCEAN/veOCEAN'
|
||||||
import { weiToDecimal } from './utils/generic'
|
import { weiToDecimal } from './utils/generic'
|
||||||
import { getDeposit, getveOCEAN } from './utils/veUtils'
|
import { getDeposit, getveOCEAN } from './utils/veUtils'
|
||||||
|
import {
|
||||||
|
getTotalOceanLocked,
|
||||||
|
updateTotalOceanLocked
|
||||||
|
} from './utils/globalUtils'
|
||||||
|
|
||||||
export function handleDeposit(event: Deposit): void {
|
export function handleDeposit(event: Deposit): void {
|
||||||
const provider = event.params.provider
|
const provider = event.params.provider
|
||||||
@ -9,7 +13,7 @@ export function handleDeposit(event: Deposit): void {
|
|||||||
const locktime = event.params.locktime
|
const locktime = event.params.locktime
|
||||||
const type = event.params.type
|
const type = event.params.type
|
||||||
const ts = event.params.ts
|
const ts = event.params.ts
|
||||||
|
const totalOceanLocked = getTotalOceanLocked()
|
||||||
const veOCEAN = getveOCEAN(provider.toHex())
|
const veOCEAN = getveOCEAN(provider.toHex())
|
||||||
// Create new Deposit entity
|
// Create new Deposit entity
|
||||||
const deposit = getDeposit(
|
const deposit = getDeposit(
|
||||||
@ -28,6 +32,10 @@ export function handleDeposit(event: Deposit): void {
|
|||||||
deposit.tx = event.transaction.hash.toHex()
|
deposit.tx = event.transaction.hash.toHex()
|
||||||
deposit.sender = event.transaction.from.toHex()
|
deposit.sender = event.transaction.from.toHex()
|
||||||
deposit.veOcean = veOCEAN.id
|
deposit.veOcean = veOCEAN.id
|
||||||
|
|
||||||
|
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value)
|
||||||
|
updateTotalOceanLocked(deposit.totalOceanLocked)
|
||||||
|
|
||||||
deposit.save()
|
deposit.save()
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
|
||||||
@ -39,6 +47,7 @@ export function handleDeposit(event: Deposit): void {
|
|||||||
}
|
}
|
||||||
export function handleSupply(event: Supply): void {}
|
export function handleSupply(event: Supply): void {}
|
||||||
export function handleWithdraw(event: Withdraw): void {
|
export function handleWithdraw(event: Withdraw): void {
|
||||||
|
const totalOceanLocked = getTotalOceanLocked()
|
||||||
const provider = event.params.provider
|
const provider = event.params.provider
|
||||||
const value = event.params.value
|
const value = event.params.value
|
||||||
const ts = event.params.ts
|
const ts = event.params.ts
|
||||||
@ -61,6 +70,8 @@ export function handleWithdraw(event: Withdraw): void {
|
|||||||
deposit.tx = event.transaction.hash.toHex()
|
deposit.tx = event.transaction.hash.toHex()
|
||||||
deposit.sender = event.transaction.from.toHex()
|
deposit.sender = event.transaction.from.toHex()
|
||||||
deposit.veOcean = veOCEAN.id
|
deposit.veOcean = veOCEAN.id
|
||||||
|
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value) // it's already negated above
|
||||||
|
updateTotalOceanLocked(deposit.totalOceanLocked)
|
||||||
deposit.save()
|
deposit.save()
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
|
||||||
|
@ -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 = [
|
const minAbi = [
|
||||||
{
|
{
|
||||||
constant: false,
|
constant: false,
|
||||||
@ -144,6 +161,7 @@ describe('veOcean tests', async () => {
|
|||||||
it('Alice should lock 100 Ocean', async () => {
|
it('Alice should lock 100 Ocean', async () => {
|
||||||
// since we can only lock once, we test if tx fails or not
|
// since we can only lock once, we test if tx fails or not
|
||||||
// so if there is already a lock, skip it
|
// so if there is already a lock, skip it
|
||||||
|
const totalOceanLockedBefore = await getTotalLockedOcean()
|
||||||
let currentBalance = await veOcean.getLockedAmount(Alice)
|
let currentBalance = await veOcean.getLockedAmount(Alice)
|
||||||
let currentLock = await veOcean.lockEnd(Alice)
|
let currentLock = await veOcean.lockEnd(Alice)
|
||||||
const amount = '100'
|
const amount = '100'
|
||||||
@ -172,6 +190,19 @@ describe('veOcean tests', async () => {
|
|||||||
currentBalance = await veOcean.getLockedAmount(Alice)
|
currentBalance = await veOcean.getLockedAmount(Alice)
|
||||||
currentLock = await veOcean.lockEnd(Alice)
|
currentLock = await veOcean.lockEnd(Alice)
|
||||||
await sleep(2000)
|
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 = {
|
const initialQuery = {
|
||||||
query: `query {
|
query: `query {
|
||||||
veOCEANs(id:"${Alice.toLowerCase()}"){
|
veOCEANs(id:"${Alice.toLowerCase()}"){
|
||||||
@ -550,7 +581,17 @@ describe('veOcean tests', async () => {
|
|||||||
})
|
})
|
||||||
it('Alice should withdraw locked tokens', async () => {
|
it('Alice should withdraw locked tokens', async () => {
|
||||||
await evmIncreaseTime(60 * 60 * 24 * 7)
|
await evmIncreaseTime(60 * 60 * 24 * 7)
|
||||||
|
const totalOceanLockedBefore = await getTotalLockedOcean()
|
||||||
await veOcean.withdraw(Alice)
|
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 () => {
|
it('Alice should lock 100 Ocean and Delegate them to Bob', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user