mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
parent
772b723d8a
commit
cb16470c9a
@ -470,6 +470,17 @@ type GlobalStatistic @entity {
|
|||||||
dispenserCount: Int!
|
dispenserCount: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OPC @entity {
|
||||||
|
id: ID!
|
||||||
|
"fee in percent for swaps involving OPC approved tokens"
|
||||||
|
swapOceanFee: BigDecimal
|
||||||
|
"fee in percent for swaps involving non OPC approved tokens"
|
||||||
|
swapNonOceanFee: BigDecimal
|
||||||
|
"fee in percent taken by OPC from consumeFees"
|
||||||
|
consumeFee: BigDecimal
|
||||||
|
"fee in percent taken by OPC from providerFees"
|
||||||
|
providerFee: BigDecimal
|
||||||
|
}
|
||||||
|
|
||||||
enum NftUpdateType {
|
enum NftUpdateType {
|
||||||
METADATA_CREATED,
|
METADATA_CREATED,
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
import { NewPool } from '../@types/FactoryRouter/FactoryRouter'
|
import {
|
||||||
|
NewPool,
|
||||||
|
TokenAdded,
|
||||||
|
OPCFeeChanged,
|
||||||
|
FactoryRouter
|
||||||
|
} from '../@types/FactoryRouter/FactoryRouter'
|
||||||
|
import { BigInt } from '@graphprotocol/graph-ts'
|
||||||
import { Pool } from '../@types/schema'
|
import { Pool } from '../@types/schema'
|
||||||
import { BPool } from '../@types/templates'
|
import { BPool } from '../@types/templates'
|
||||||
import { addPool } from './utils/globalUtils'
|
import { addPool, getOPC } from './utils/globalUtils'
|
||||||
|
import { weiToDecimal } from './utils/generic'
|
||||||
|
|
||||||
export function handleNewPool(event: NewPool): void {
|
export function handleNewPool(event: NewPool): void {
|
||||||
BPool.create(event.params.poolAddress)
|
BPool.create(event.params.poolAddress)
|
||||||
@ -9,3 +16,51 @@ export function handleNewPool(event: NewPool): void {
|
|||||||
pool.save()
|
pool.save()
|
||||||
addPool()
|
addPool()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handleOPCFeeChanged(event: OPCFeeChanged): void {
|
||||||
|
const opc = getOPC()
|
||||||
|
const decimals = BigInt.fromI32(18).toI32()
|
||||||
|
opc.swapOceanFee = weiToDecimal(
|
||||||
|
event.params.newSwapOceanFee.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
opc.swapNonOceanFee = weiToDecimal(
|
||||||
|
event.params.newSwapNonOceanFee.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
opc.consumeFee = weiToDecimal(
|
||||||
|
event.params.newConsumeFee.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
opc.providerFee = weiToDecimal(
|
||||||
|
event.params.newProviderFee.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
opc.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleTokenAdded(event: TokenAdded): void {
|
||||||
|
const contract = FactoryRouter.bind(event.address)
|
||||||
|
const oceanFees = contract.try_getOPCFees()
|
||||||
|
if (oceanFees.reverted) return
|
||||||
|
|
||||||
|
const opc = getOPC()
|
||||||
|
const decimals = BigInt.fromI32(18).toI32()
|
||||||
|
opc.swapOceanFee = weiToDecimal(
|
||||||
|
oceanFees.value.value0.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
opc.swapNonOceanFee = weiToDecimal(
|
||||||
|
oceanFees.value.value1.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
|
||||||
|
const newConsumeFee = contract.try_getOPCConsumeFee()
|
||||||
|
if (newConsumeFee.reverted) return
|
||||||
|
|
||||||
|
const newProviderFee = contract.try_getOPCProviderFee()
|
||||||
|
if (newProviderFee.reverted) return
|
||||||
|
opc.consumeFee = weiToDecimal(newConsumeFee.value.toBigDecimal(), decimals)
|
||||||
|
opc.providerFee = weiToDecimal(newProviderFee.value.toBigDecimal(), decimals)
|
||||||
|
opc.save()
|
||||||
|
}
|
||||||
|
@ -3,7 +3,8 @@ import {
|
|||||||
GlobalStatistic,
|
GlobalStatistic,
|
||||||
GlobalTotalFixedSwapPair,
|
GlobalTotalFixedSwapPair,
|
||||||
GlobalTotalLiquidityPair,
|
GlobalTotalLiquidityPair,
|
||||||
GlobalTotalPoolSwapPair
|
GlobalTotalPoolSwapPair,
|
||||||
|
OPC
|
||||||
} from '../../@types/schema'
|
} from '../../@types/schema'
|
||||||
|
|
||||||
const GLOBAL_ID = '1'
|
const GLOBAL_ID = '1'
|
||||||
@ -16,6 +17,16 @@ export function getGlobalStats(): GlobalStatistic {
|
|||||||
}
|
}
|
||||||
return globalStats
|
return globalStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getOPC(): OPC {
|
||||||
|
let globalStats = OPC.load(GLOBAL_ID)
|
||||||
|
if (!globalStats) {
|
||||||
|
globalStats = new OPC(GLOBAL_ID)
|
||||||
|
globalStats.save()
|
||||||
|
}
|
||||||
|
return globalStats
|
||||||
|
}
|
||||||
|
|
||||||
export function addOrder(): void {
|
export function addOrder(): void {
|
||||||
const globalStats = getGlobalStats()
|
const globalStats = getGlobalStats()
|
||||||
globalStats.orderCount = globalStats.orderCount + 1
|
globalStats.orderCount = globalStats.orderCount + 1
|
||||||
|
@ -119,6 +119,11 @@ dataSources:
|
|||||||
eventHandlers:
|
eventHandlers:
|
||||||
- event: NewPool(indexed address,bool)
|
- event: NewPool(indexed address,bool)
|
||||||
handler: handleNewPool
|
handler: handleNewPool
|
||||||
|
- event: TokenAdded(indexed address,indexed address)
|
||||||
|
handler: handleTokenAdded
|
||||||
|
- event: OPCFeeChanged(indexed address,uint256,uint256,uint256,uint256)
|
||||||
|
handler: handleOPCFeeChanged
|
||||||
|
|
||||||
|
|
||||||
templates:
|
templates:
|
||||||
- name: ERC20Template
|
- name: ERC20Template
|
||||||
|
Loading…
Reference in New Issue
Block a user