|
1 |
| -import { NewPool } from '../@types/FactoryRouter/FactoryRouter' |
| 1 | +import { |
| 2 | + NewPool, |
| 3 | + TokenAdded, |
| 4 | + OPCFeeChanged, |
| 5 | + FactoryRouter |
| 6 | +} from '../@types/FactoryRouter/FactoryRouter' |
| 7 | +import { BigInt } from '@graphprotocol/graph-ts' |
2 | 8 | import { Pool } from '../@types/schema'
|
3 | 9 | import { BPool } from '../@types/templates'
|
4 |
| -import { addPool } from './utils/globalUtils' |
| 10 | +import { addPool, getOPC } from './utils/globalUtils' |
| 11 | +import { weiToDecimal } from './utils/generic' |
5 | 12 |
|
6 | 13 | export function handleNewPool(event: NewPool): void {
|
7 | 14 | BPool.create(event.params.poolAddress)
|
8 | 15 | const pool = new Pool(event.params.poolAddress.toHexString())
|
9 | 16 | pool.save()
|
10 | 17 | addPool()
|
11 | 18 | }
|
| 19 | + |
| 20 | +export function handleOPCFeeChanged(event: OPCFeeChanged): void { |
| 21 | + const opc = getOPC() |
| 22 | + const decimals = BigInt.fromI32(18).toI32() |
| 23 | + opc.swapOceanFee = weiToDecimal( |
| 24 | + event.params.newSwapOceanFee.toBigDecimal(), |
| 25 | + decimals |
| 26 | + ) |
| 27 | + opc.swapNonOceanFee = weiToDecimal( |
| 28 | + event.params.newSwapNonOceanFee.toBigDecimal(), |
| 29 | + decimals |
| 30 | + ) |
| 31 | + opc.consumeFee = weiToDecimal( |
| 32 | + event.params.newConsumeFee.toBigDecimal(), |
| 33 | + decimals |
| 34 | + ) |
| 35 | + opc.providerFee = weiToDecimal( |
| 36 | + event.params.newProviderFee.toBigDecimal(), |
| 37 | + decimals |
| 38 | + ) |
| 39 | + opc.save() |
| 40 | +} |
| 41 | + |
| 42 | +export function handleTokenAdded(event: TokenAdded): void { |
| 43 | + const contract = FactoryRouter.bind(event.address) |
| 44 | + const oceanFees = contract.try_getOPCFees() |
| 45 | + if (oceanFees.reverted) return |
| 46 | + |
| 47 | + const opc = getOPC() |
| 48 | + const decimals = BigInt.fromI32(18).toI32() |
| 49 | + opc.swapOceanFee = weiToDecimal( |
| 50 | + oceanFees.value.value0.toBigDecimal(), |
| 51 | + decimals |
| 52 | + ) |
| 53 | + opc.swapNonOceanFee = weiToDecimal( |
| 54 | + oceanFees.value.value1.toBigDecimal(), |
| 55 | + decimals |
| 56 | + ) |
| 57 | + |
| 58 | + const newConsumeFee = contract.try_getOPCConsumeFee() |
| 59 | + if (newConsumeFee.reverted) return |
| 60 | + |
| 61 | + const newProviderFee = contract.try_getOPCProviderFee() |
| 62 | + if (newProviderFee.reverted) return |
| 63 | + opc.consumeFee = weiToDecimal(newConsumeFee.value.toBigDecimal(), decimals) |
| 64 | + opc.providerFee = weiToDecimal(newProviderFee.value.toBigDecimal(), decimals) |
| 65 | + opc.save() |
| 66 | +} |
0 commit comments