Skip to content

Commit

Permalink
fix: set flexible allowed state delay time
Browse files Browse the repository at this point in the history
  • Loading branch information
Verisana committed Dec 1, 2022
1 parent de1a221 commit 0378266
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dex/curve-v1-factory/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const STATE_UPDATE_RETRY_PERIOD_MS = 1000;

export const LIQUIDITY_UPDATE_PERIOD_MS = 2 * 60 * 1000;

export const MAX_ALLOWED_STATE_DELAY_MS = 15 * 1000;
export const MAX_ALLOWED_STATE_DELAY_FACTOR = 2;

export const POOL_EXCHANGE_GAS_COST = 200 * 1000;

Expand Down
3 changes: 3 additions & 0 deletions src/dex/curve-v1-factory/curve-v1-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class CurveV1Factory
this.cacheStateKey,
customPool.name,
customPool.address,
this.config.stateUpdatePeriodMs,
poolIdentifier,
poolConstants,
poolContextConstants,
Expand All @@ -244,6 +245,7 @@ export class CurveV1Factory
this.cacheStateKey,
customPool.name,
customPool.address,
this.config.stateUpdatePeriodMs,
poolIdentifier,
poolConstants,
poolContextConstants,
Expand Down Expand Up @@ -530,6 +532,7 @@ export class CurveV1Factory
factoryImplementationFromConfig.name,
implementationAddress.toLowerCase(),
poolAddresses[i],
this.config.stateUpdatePeriodMs,
factoryAddress,
poolIdentifier,
poolConstants,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
cacheStateKey: string,
readonly implementationName: ImplementationNames,
readonly address: Address,
stateUpdatePeriodMs: number,
readonly poolIdentifier: string,
readonly poolConstants: PoolConstants,
readonly poolContextConstants: PoolContextConstants,
Expand All @@ -118,6 +119,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
cacheStateKey,
implementationName,
address,
stateUpdatePeriodMs,
poolIdentifier,
poolConstants,
address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class FactoryStateHandler extends PoolPollingBase {
readonly implementationName: FactoryImplementationNames,
implementationAddress: Address,
readonly address: Address,
stateUpdatePeriodMs: number,
readonly factoryAddress: Address,
readonly poolIdentifier: string,
readonly poolConstants: PoolConstants,
Expand All @@ -42,6 +43,7 @@ export class FactoryStateHandler extends PoolPollingBase {
cacheStateKey,
implementationName,
implementationAddress,
stateUpdatePeriodMs,
poolIdentifier,
poolConstants,
address,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Web3EthAbi, { AbiCoder } from 'web3-eth-abi';
import { Logger } from 'log4js';
import { MultiCallParams } from '../../../lib/multi-wrapper';
import { MAX_ALLOWED_STATE_DELAY_MS, MIN_LIQUIDITY_IN_USD } from '../constants';
import {
MAX_ALLOWED_STATE_DELAY_FACTOR,
MIN_LIQUIDITY_IN_USD,
} from '../constants';
import { CurveV1FactoryData, PoolConstants, PoolState } from '../types';
import { Address } from 'paraswap-core';

Expand Down Expand Up @@ -36,6 +39,7 @@ export abstract class PoolPollingBase {
readonly cacheStateKey: string,
readonly implementationName: string,
readonly implementationAddress: Address,
readonly stateUpdatePeriodMs: number,
readonly poolIdentifier: string,
readonly poolConstants: PoolConstants,
readonly address: Address,
Expand Down Expand Up @@ -79,7 +83,8 @@ export abstract class PoolPollingBase {
isStateUpToDate(state: PoolState | null): boolean {
return (
state !== null &&
Date.now() - state.updatedAtMs < MAX_ALLOWED_STATE_DELAY_MS
Date.now() - state.updatedAtMs <
this.stateUpdatePeriodMs * MAX_ALLOWED_STATE_DELAY_FACTOR
);
}

Expand Down

0 comments on commit 0378266

Please sign in to comment.