2022-02-18 16:38:51 +01:00
|
|
|
import {
|
|
|
|
NewPool,
|
|
|
|
TokenAdded,
|
|
|
|
OPCFeeChanged,
|
|
|
|
FactoryRouter
|
|
|
|
} from '../@types/FactoryRouter/FactoryRouter'
|
|
|
|
import { BigInt } from '@graphprotocol/graph-ts'
|
2022-01-14 15:51:23 +01:00
|
|
|
import { Pool } from '../@types/schema'
|
|
|
|
import { BPool } from '../@types/templates'
|
2022-02-18 16:38:51 +01:00
|
|
|
import { addPool, getOPC } from './utils/globalUtils'
|
|
|
|
import { weiToDecimal } from './utils/generic'
|
2022-01-14 15:51:23 +01:00
|
|
|
|
|
|
|
export function handleNewPool(event: NewPool): void {
|
|
|
|
BPool.create(event.params.poolAddress)
|
|
|
|
const pool = new Pool(event.params.poolAddress.toHexString())
|
|
|
|
pool.save()
|
2022-02-15 17:13:55 +01:00
|
|
|
addPool()
|
2022-01-14 15:51:23 +01:00
|
|
|
}
|
2022-02-18 16:38:51 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|