Skip to content

Commit

Permalink
solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 16, 2024
2 parents 05e4d54 + 96309a7 commit 8f78c4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 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": "4.0.3-Cables.1",
"version": "4.0.3",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
57 changes: 9 additions & 48 deletions src/dex/algebra/algebra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ const ALGEBRA_TICK_BASE_OVERHEAD = 75_000;
const ALGEBRA_POOL_SEARCH_OVERHEAD = 10_000;
const ALGEBRA_QUOTE_GASLIMIT = 2_000_000;

const MAX_STALE_STATE_BLOCK_AGE = {
[Network.ZKEVM]: 150, // approximately 3min
};

type IAlgebraEventPool =
| AlgebraEventPoolV1_1
| AlgebraEventPoolV1_9
Expand Down Expand Up @@ -240,20 +236,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {

if (pool) {
if (!pool.initFailed) {
if (this.network !== Network.ZKEVM) return pool;

if (
pool.getStaleState() === null ||
(pool.getState(blockNumber) === null &&
blockNumber - pool.getStateBlockNumber() >
MAX_STALE_STATE_BLOCK_AGE[this.network])
) {
/* reload state, on zkEVM this would most likely timeout during request life
* but would allow to rely on staleState for couple of min for next requests
*/
await pool.initialize(blockNumber, { forceRegenerate: true });
}

return pool;
} else {
// if init failed then prefer to early return pool with empty state to fallback to rpc call
Expand Down Expand Up @@ -615,37 +597,16 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
let state = pool.getState(blockNumber);

if (state === null) {
if (this.network === Network.ZKEVM) {
if (pool.initFailed) return null;

if (
blockNumber - pool.getStateBlockNumber() <=
MAX_STALE_STATE_BLOCK_AGE[this.network]
) {
this.logger.warn(
`${_srcAddress}_${_destAddress}_${pool.name}_${
pool.poolAddress
} state fallback to latest early enough state. Current blockNumber=${blockNumber}, stateBlockNumber=${pool.getStateBlockNumber()}`,
);
state = pool.getStaleState();
} else {
this.logger.warn(
`${_srcAddress}_${_destAddress}_${pool.name}_${pool.poolAddress} state is unhealthy, cannot compute price (no fallback on this chain)`,
);
return null; // never fallback as takes more time
}
} else {
const rpcPrice = await this.getPricingFromRpc(
_srcToken,
_destToken,
amounts,
side,
pool,
transferFees,
);
const rpcPrice = await this.getPricingFromRpc(
_srcToken,
_destToken,
amounts,
side,
pool,
transferFees,
);

return rpcPrice;
}
return rpcPrice;
}

if (!state) return null;
Expand Down

0 comments on commit 8f78c4e

Please sign in to comment.