Skip to content

Commit

Permalink
Merge pull request paraswap#796 from paraswap/fix/BACK-1716
Browse files Browse the repository at this point in the history
fix(BACK-1716): remove redundant state pooling for `WooFiV2`
  • Loading branch information
0xNazarii authored Sep 27, 2024
2 parents c6817a2 + 2f22472 commit 003ffca
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "3.8.38",
"version": "3.8.39",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
85 changes: 58 additions & 27 deletions src/dex/woo-fi-v2/woo-fi-v2-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export class WooFiV2PollingPool extends StatefulRpcPoller<
poolIdentifier: string,
dexHelper: IDexHelper,
protected config: DexParams,
// It already includes quoteToken
protected tokens: Token[],
protected baseTokens: Token[],
) {
const callbacks = pollingManagerCbExtractor(
StatePollingManager.getInstance(dexHelper),
Expand All @@ -50,51 +49,83 @@ export class WooFiV2PollingPool extends StatefulRpcPoller<
decodeFunction: uint256ToBigInt,
},
] as MultiCallParams<MulticallResultOutputs>[]
).concat(
this.tokens
.map(t => [
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('tokenInfos', [t.address]),
decodeFunction: tokenInfoDecoder,
},
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('decimalInfo', [
t.address,
]),
decodeFunction: decimalInfoDecoder,
},
{
target: this.config.wooOracleV2Address,
callData: ifaces.oracleV2.encodeFunctionData('state', [t.address]),
decodeFunction: stateDecoder,
},
])
.flat(),
);
)
.concat([
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('tokenInfos', [
this.config.quoteToken.address,
]),
decodeFunction: tokenInfoDecoder,
},
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('decimalInfo', [
this.config.quoteToken.address,
]),
decodeFunction: decimalInfoDecoder,
},
])
.concat(
this.baseTokens
.map(t => [
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('tokenInfos', [
t.address,
]),
decodeFunction: tokenInfoDecoder,
},
{
target: this.config.wooPPV2Address,
callData: ifaces.PPV2.encodeFunctionData('decimalInfo', [
t.address,
]),
decodeFunction: decimalInfoDecoder,
},
{
target: this.config.wooOracleV2Address,
callData: ifaces.oracleV2.encodeFunctionData('state', [
t.address,
]),
decodeFunction: stateDecoder,
},
])
.flat(),
);
}

protected _parseStateFromMultiResults(
multiOutputs: MulticallResultOutputs[],
): PoolState {
const [isPaused, oracleTimestamp, ...remained] = multiOutputs as [
const [
isPaused,
oracleTimestamp,
quoteTokenInfo,
quoteTokenDecimals,
...remained
] = multiOutputs as [
boolean,
bigint,
TokenInfo,
DecimalInfo,
...MulticallResultOutputs[],
];

const tokenInfos: Record<string, TokenInfo> = {};
const decimals: Record<string, DecimalInfo> = {};
const tokenStates: Record<string, TokenState> = {};

tokenInfos[this.config.quoteToken.address] = quoteTokenInfo;
decimals[this.config.quoteToken.address] = quoteTokenDecimals;

_.chunk(remained, 3).forEach((chunk, i) => {
const [tokenInfo, decimalInfo, tokenState] = chunk as [
TokenInfo,
DecimalInfo,
TokenState,
];
const token = this.tokens[i];
const token = this.baseTokens[i];

tokenInfos[token.address] = tokenInfo;
decimals[token.address] = decimalInfo;
Expand Down
3 changes: 1 addition & 2 deletions src/dex/woo-fi-v2/woo-fi-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { ethers } from 'ethers';
import { addressDecode } from '../../lib/decoders';
import { ifaces } from './utils';
import { StatePollingManager } from '../../lib/stateful-rpc-poller/state-polling-manager';
import { solidityPack } from 'ethers/lib/utils';
import { extractReturnAmountPosition } from '../../executor/utils';

export class WooFiV2 extends SimpleExchange implements IDex<WooFiV2Data> {
Expand Down Expand Up @@ -521,7 +520,7 @@ export class WooFiV2 extends SimpleExchange implements IDex<WooFiV2Data> {
this.getIdentifier(),
this.dexHelper,
this.config,
Object.values(this.tokenByAddress),
this.baseTokens,
);

this.pollingManager.initializeAllPendingPools();
Expand Down

0 comments on commit 003ffca

Please sign in to comment.