diff --git a/src/dex-helper/dummy-dex-helper.ts b/src/dex-helper/dummy-dex-helper.ts index da726e1ad..250dc55f7 100644 --- a/src/dex-helper/dummy-dex-helper.ts +++ b/src/dex-helper/dummy-dex-helper.ts @@ -250,8 +250,8 @@ export class DummyDexHelper implements IDexHelper { network: number, dexKeys: string, methodSelector: string, - payload: any[], - ) => Promise; + payload: unknown[], + ) => Promise; constructor(network: number, rpcUrl?: string) { this.config = new ConfigHelper(false, generateConfig(network), 'is'); @@ -292,7 +292,7 @@ export class DummyDexHelper implements IDexHelper { network: number, dexKey: string, methodSelector: string, - payload: any[], + payload: unknown[], ) => { return null; }; diff --git a/src/dex-helper/idex-helper.ts b/src/dex-helper/idex-helper.ts index 835662dac..eb47347be 100644 --- a/src/dex-helper/idex-helper.ts +++ b/src/dex-helper/idex-helper.ts @@ -25,8 +25,8 @@ export interface IDexHelper { network: number, dexKey: string, methodSelector: string, - // For POC it is ok to have any - payload: any[], - ) => Promise; + payload: unknown[], + // For POC it is ok to have this unknown + ) => Promise; getTokenUSDPrice: (token: Token, amount: bigint) => Promise; } diff --git a/src/dex/algebra/algebra.ts b/src/dex/algebra/algebra.ts index e4c370870..41f40ef6b 100644 --- a/src/dex/algebra/algebra.ts +++ b/src/dex/algebra/algebra.ts @@ -527,20 +527,20 @@ export class Algebra extends SimpleExchange implements IDex { const balanceDestToken = _destAddress === pool.token0 ? state.balance0 : state.balance1; - const outputFunc = this.getOutputs; - const unitResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, [unitAmount], zeroForOne, side, balanceDestToken], - )) as ReturnType; - - const pricesResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, _amounts, zeroForOne, side, balanceDestToken], - )) as ReturnType; + const unitResult = await this._getOutputs( + state, + [unitAmount], + zeroForOne, + side, + balanceDestToken, + ); + const pricesResult = await this._getOutputs( + state, + _amounts, + zeroForOne, + side, + balanceDestToken, + ); if (!unitResult || !pricesResult) { this.logger.debug('Prices or unit is not calculated'); @@ -800,20 +800,20 @@ export class Algebra extends SimpleExchange implements IDex { return newConfig; } - getOutputs( + private async _getOutputs( state: DeepReadonly, amounts: bigint[], zeroForOne: boolean, side: SwapSide, destTokenBalance: bigint, - ): OutputResult | null { + ): Promise { try { - const outputsResult = AlgebraMath.queryOutputs( - state, - amounts, - zeroForOne, - side, - ); + const outputsResult = (await this.dexHelper.executeOnWorkerPool( + this.network, + this.dexKey, + 'queryOutputs', + [state, amounts, zeroForOne, side], + )) as ReturnType; if (side === SwapSide.SELL) { if (outputsResult.outputs[0] > destTokenBalance) { diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3.ts b/src/dex/pancakeswap-v3/pancakeswap-v3.ts index 217fef353..2559c2b27 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3.ts @@ -112,7 +112,7 @@ export class PancakeswapV3 // To receive revert reasons this.dexHelper.web3Provider.eth.handleRevert = false; - // Normalise once all config addresses and use across all scenarios + // Normalize once all config addresses and use across all scenarios this.config = this._toLowerForAllConfigAddresses(); this.notExistingPoolSetKey = @@ -253,7 +253,7 @@ export class PancakeswapV3 e, ); } else { - // on unkown error mark as failed and increase retryCount for retry init strategy + // on unknown error mark as failed and increase retryCount for retry init strategy // note: state would be null by default which allows to fallback this.logger.warn( `${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool.initRetryAttemptCount}`, @@ -608,19 +608,21 @@ export class PancakeswapV3 const balanceDestToken = _destAddress === pool.token0 ? state.balance0 : state.balance1; - const unitResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, [unitAmount], zeroForOne, side, balanceDestToken], - )) as ReturnType; - - const pricesResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, _amounts, zeroForOne, side, balanceDestToken], - )) as ReturnType; + const unitResult = await this._getOutputs( + state, + [unitAmount], + zeroForOne, + side, + balanceDestToken, + ); + const pricesResult = await this._getOutputs( + state, + _amounts, + zeroForOne, + side, + balanceDestToken, + ); + if (!pricesResult) { this.logger.debug('Prices or unit is not calculated'); return null; @@ -909,20 +911,20 @@ export class PancakeswapV3 return newConfig; } - getOutputs( + private async _getOutputs( state: DeepReadonly, amounts: bigint[], zeroForOne: boolean, side: SwapSide, destTokenBalance: bigint, - ): OutputResult | null { + ): Promise { try { - const outputsResult = pancakeswapV3Math.queryOutputs( - state, - amounts, - zeroForOne, - side, - ); + const outputsResult = (await this.dexHelper.executeOnWorkerPool( + this.network, + this.dexKey, + 'queryOutputs', + [state, amounts, zeroForOne, side], + )) as ReturnType; if (side === SwapSide.SELL) { if (outputsResult.outputs[0] > destTokenBalance) { diff --git a/src/dex/uniswap-v3/uniswap-v3.ts b/src/dex/uniswap-v3/uniswap-v3.ts index 530d2b4ce..d6c87441d 100644 --- a/src/dex/uniswap-v3/uniswap-v3.ts +++ b/src/dex/uniswap-v3/uniswap-v3.ts @@ -641,19 +641,20 @@ export class UniswapV3 const balanceDestToken = _destAddress === pool.token0 ? state.balance0 : state.balance1; - const unitResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, [unitAmount], zeroForOne, side, balanceDestToken], - )) as ReturnType; - - const pricesResult = (await this.dexHelper.executeOnWorkerPool( - this.network, - this.dexKey, - 'getOutputs', - [state, _amounts, zeroForOne, side, balanceDestToken], - )) as ReturnType; + const unitResult = await this._getOutputs( + state, + [unitAmount], + zeroForOne, + side, + balanceDestToken, + ); + const pricesResult = await this._getOutputs( + state, + _amounts, + zeroForOne, + side, + balanceDestToken, + ); if (!unitResult || !pricesResult) { this.logger.debug('Prices or unit is not calculated'); @@ -1070,20 +1071,20 @@ export class UniswapV3 return newConfig; } - getOutputs( + private async _getOutputs( state: DeepReadonly, amounts: bigint[], zeroForOne: boolean, side: SwapSide, destTokenBalance: bigint, - ): OutputResult | null { + ): Promise { try { - const outputsResult = uniswapV3Math.queryOutputs( - state, - amounts, - zeroForOne, - side, - ); + const outputsResult = (await this.dexHelper.executeOnWorkerPool( + this.network, + this.dexKey, + 'queryOutputs', + [state, amounts, zeroForOne, side], + )) as ReturnType; if (side === SwapSide.SELL) { if (outputsResult.outputs[0] > destTokenBalance) {