diff --git a/src/abi/ramses-v2/RamsesV2Pool.abi.json b/src/abi/ramses-v2/RamsesV2Pool.abi.json index 1dc342a1c..b5516c8d7 100644 --- a/src/abi/ramses-v2/RamsesV2Pool.abi.json +++ b/src/abi/ramses-v2/RamsesV2Pool.abi.json @@ -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": [ diff --git a/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts b/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts index 63f978d38..10d4bf4c2 100644 --- a/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +++ b/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts @@ -1,5 +1,5 @@ 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'; @@ -7,11 +7,60 @@ 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> { const callData = this._getStateRequestCallData(); diff --git a/src/dex/uniswap-v3/types.ts b/src/dex/uniswap-v3/types.ts index 4d29b5099..967675843 100644 --- a/src/dex/uniswap-v3/types.ts +++ b/src/dex/uniswap-v3/types.ts @@ -61,6 +61,7 @@ export type UniswapV3Data = { tokenIn: Address; tokenOut: Address; fee: NumberAsString; + currentFee?: NumberAsString; }[]; isApproved?: boolean; }; diff --git a/src/dex/uniswap-v3/uniswap-v3.ts b/src/dex/uniswap-v3/uniswap-v3.ts index 37e66e455..8a6229fb7 100644 --- a/src/dex/uniswap-v3/uniswap-v3.ts +++ b/src/dex/uniswap-v3/uniswap-v3.ts @@ -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, @@ -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, }, ], },