Skip to content

Commit

Permalink
Get tradingFeePPM from carbonController
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipenunes committed Jul 5, 2023
1 parent e3c46a5 commit 1a9e556
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/dex/carbon/carbon-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EncodedStrategy, EncodedOrder } from './sdk/';
import { ChainCache } from './sdk/chain-cache';
import { BigNumber } from './sdk/utils';
import { toPairKey } from './sdk/chain-cache/utils';
import { Contract } from 'web3-eth-contract';

export class CarbonEventPool extends StatefulEventSubscriber<PoolState> {
handlers: {
Expand All @@ -27,6 +28,8 @@ export class CarbonEventPool extends StatefulEventSubscriber<PoolState> {

addressesSubscribed: string[];

carbonController: Contract;

public readonly carbonIface = new Interface(CarbonControllerABI);

constructor(
Expand All @@ -48,6 +51,11 @@ export class CarbonEventPool extends StatefulEventSubscriber<PoolState> {
CarbonConfig[parentName][network].carbonController,
];

this.carbonController = new this.dexHelper.web3Provider.eth.Contract(
CarbonControllerABI as any,
CarbonConfig[parentName][network].carbonController,
);

// Add handlers
this.handlers['StrategyCreated'] = this.handleStrategyChanges.bind(this);
this.handlers['StrategyUpdated'] = this.handleStrategyChanges.bind(this);
Expand Down Expand Up @@ -180,30 +188,11 @@ export class CarbonEventPool extends StatefulEventSubscriber<PoolState> {
newCache.addPair(pair.token0, pair.token1, pair.strategies, true);
});

// Get TradingFeePPM
const tradingFeeQuery: string = `
query ($block_number: Int) {
tradingFeePPMUpdateds(block: {number: $block_number}, first:1, orderBy: createdAtTimestamp, orderDirection: desc) {
newFeePPM
}
}
`;

const feeData = await this._querySubgraph(
tradingFeeQuery,
{
block_number: blockNumber,
},
CarbonConfig[this.parentName][this.network].subgraphURL,
);

if (!(feeData && feeData.tradingFeePPMUpdateds)) {
this.logger.error(
`Error_${this.parentName}_Subgraph: couldn't fetch the trading fee from the subgraph`,
);
}
newCache.tradingFeePPM = await this.carbonController.methods
.tradingFeePPM()
.call();

newCache.tradingFeePPM = feeData.tradingFeePPMUpdateds[0].newFeePPM;
this.logger.info(`Read tradingFeePPM: ${newCache.tradingFeePPM}`);

const newState: PoolState = {
sdkCache: newCache,
Expand Down

0 comments on commit 1a9e556

Please sign in to comment.