Skip to content

Commit

Permalink
listen to FeeAdjustment event
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 7, 2023
1 parent 3373047 commit d989a3d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/abi/ramses-v2/RamsesV2Pool.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint24",
"name": "oldFee",
"type": "uint24"
},
{
"indexed": false,
"internalType": "uint24",
"name": "newFee",
"type": "uint24"
}
],
"name": "FeeAdjustment",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
51 changes: 50 additions & 1 deletion src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
import { UniswapV3EventPool } from '../../uniswap-v3-pool';
import { DecodedStateMultiCallResultWithRelativeBitmaps, PoolState } from '../../types';
import { DecodedStateMultiCallResultWithRelativeBitmaps, DecodeStateMultiCallFunc, PoolState } from '../../types';
import { assert } from 'ts-essentials';
import { _reduceTickBitmap, _reduceTicks } from '../../contract-math/utils';
import { bigIntify } from '../../../../utils';
import { TickBitMap } from '../../contract-math/TickBitMap';
import { uint24ToBigInt } from '../../../../lib/decoders';
import { Interface } from 'ethers/lib/utils';
import RamsesV2PoolABI from '../../../../abi/ramses-v2/RamsesV2Pool.abi.json';
import { IDexHelper } from '../../../../dex-helper';
import { Contract } from 'web3-eth-contract';
import { Address, Logger } from '../../../../types';

export class RamsesV2EventPool extends UniswapV3EventPool {

public readonly poolIface = new Interface(RamsesV2PoolABI);

constructor(
readonly dexHelper: IDexHelper,
parentName: string,
readonly stateMultiContract: Contract,
readonly decodeStateMultiCallResultWithRelativeBitmaps:
| DecodeStateMultiCallFunc
| undefined,
readonly erc20Interface: Interface,
protected readonly factoryAddress: Address,
public feeCode: bigint,
token0: Address,
token1: Address,
logger: Logger,
mapKey: string = '',
readonly poolInitCodeHash: string,
) {
super(
dexHelper,
parentName,
stateMultiContract,
decodeStateMultiCallResultWithRelativeBitmaps,
erc20Interface,
factoryAddress,
feeCode,
token0,
token1,
logger,
mapKey,
poolInitCodeHash,
);

this.handlers['FeeAdjustment'] = this.handleFeeAdjustmentEvent.bind(this);
}

handleFeeAdjustmentEvent(
event: any,
pool: PoolState,
): PoolState {
const newFee = bigIntify(event.args.newFee);

pool.fee = newFee;
this.currentFeeCodeAsString = newFee.toString();

return pool;
}

async generateState(blockNumber: number): Promise<Readonly<PoolState>> {
const callData = this._getStateRequestCallData();

Expand Down
1 change: 1 addition & 0 deletions src/dex/uniswap-v3/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type UniswapV3Data = {
tokenIn: Address;
tokenOut: Address;
fee: NumberAsString;
currentFee?: NumberAsString;
}[];
isApproved?: boolean;
};
Expand Down
6 changes: 4 additions & 2 deletions src/dex/uniswap-v3/uniswap-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ export class UniswapV3
{
tokenIn: from.address,
tokenOut: to.address,
fee: pool.currentFeeCodeAsString ? pool.currentFeeCodeAsString : pool.feeCodeAsString,
fee: pool.feeCodeAsString,
currentFee: pool.currentFeeCodeAsString,
},
],
exchange: pool.poolAddress,
Expand Down Expand Up @@ -734,7 +735,8 @@ export class UniswapV3
{
tokenIn: _srcAddress,
tokenOut: _destAddress,
fee: pool.currentFeeCodeAsString ? pool.currentFeeCodeAsString : pool.feeCode.toString(),
fee: pool.feeCode.toString(),
currentFee: pool.currentFeeCodeAsString,
},
],
},
Expand Down

0 comments on commit d989a3d

Please sign in to comment.