@paraswap/dex-lib 4.1.10 → 4.1.11-erc-4626.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +53 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/build/abi/ERC4626.json +757 -0
- package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
- package/build/abi/inception/inception-ratio-feed.json +329 -0
- package/build/abi/inception/inception-vault.json +991 -0
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
- package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
- package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
- package/build/dex/aave-v1/aave-v1.d.ts +2 -1
- package/build/dex/aave-v1/aave-v1.js +23 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/tokens-avalanche.json +44 -0
- package/build/dex/aave-v2/tokens-mainnet.json +188 -0
- package/build/dex/aave-v2/tokens-polygon.json +44 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
- package/build/dex/balancer-v3/gyroECLPPool.d.ts +11 -0
- package/build/dex/balancer-v3/gyroECLPPool.js +6 -0
- package/build/dex/balancer-v3/gyroECLPPool.js.map +1 -0
- package/build/dex/balancer-v3/utils.d.ts +2 -0
- package/build/dex/balancer-v3/utils.js +11 -0
- package/build/dex/balancer-v3/utils.js.map +1 -0
- package/build/dex/erc4626/config.d.ts +3 -0
- package/build/dex/erc4626/config.js +42 -0
- package/build/dex/erc4626/config.js.map +1 -0
- package/build/dex/erc4626/constants.d.ts +3 -0
- package/build/dex/erc4626/constants.js +7 -0
- package/build/dex/erc4626/constants.js.map +1 -0
- package/build/dex/erc4626/erc-4626-pool.d.ts +24 -0
- package/build/dex/erc4626/erc-4626-pool.js +92 -0
- package/build/dex/erc4626/erc-4626-pool.js.map +1 -0
- package/build/dex/erc4626/erc4626.d.ts +46 -0
- package/build/dex/erc4626/erc4626.js +247 -0
- package/build/dex/erc4626/erc4626.js.map +1 -0
- package/build/dex/erc4626/scripts/validate-state.d.ts +0 -0
- package/build/dex/erc4626/scripts/validate-state.js +146 -0
- package/build/dex/erc4626/scripts/validate-state.js.map +1 -0
- package/build/dex/erc4626/types.d.ts +18 -0
- package/build/dex/erc4626/types.js +11 -0
- package/build/dex/erc4626/types.js.map +1 -0
- package/build/dex/inception/config.d.ts +4 -0
- package/build/dex/inception/config.js +109 -0
- package/build/dex/inception/config.js.map +1 -0
- package/build/dex/inception/inception-event-pool.d.ts +16 -0
- package/build/dex/inception/inception-event-pool.js +49 -0
- package/build/dex/inception/inception-event-pool.js.map +1 -0
- package/build/dex/inception/inception.d.ts +43 -0
- package/build/dex/inception/inception.js +180 -0
- package/build/dex/inception/inception.js.map +1 -0
- package/build/dex/inception/tokens.d.ts +9 -0
- package/build/dex/inception/tokens.js +28 -0
- package/build/dex/inception/tokens.js.map +1 -0
- package/build/dex/inception/types.d.ts +22 -0
- package/build/dex/{m-token → inception}/types.js.map +1 -1
- package/build/dex/inception/utils.d.ts +7 -0
- package/build/dex/inception/utils.js +58 -0
- package/build/dex/inception/utils.js.map +1 -0
- package/build/dex/index.js +2 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/jarvis.d.ts +2 -1
- package/build/dex/jarvis.js +58 -0
- package/build/dex/jarvis.js.map +1 -1
- package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
- package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
- package/build/dex/maker-psm/scripts/validate-state.js +185 -0
- package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
- package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
- package/build/dex/platypus/platypus.d.ts +2 -1
- package/build/dex/platypus/platypus.js +45 -0
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
- package/build/dex/stable-pool.js +1 -8
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
- package/build/dex/swaap-v1/swaap-v1.js +14 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
- package/build/dex/uniswap-v4/config.js +0 -43
- package/build/dex/uniswap-v4/config.js.map +1 -1
- package/build/dex/uniswap-v4/encoder.js +2 -12
- package/build/dex/uniswap-v4/encoder.js.map +1 -1
- package/build/dex/uniswap-v4/types.d.ts +2 -36
- package/build/dex/uniswap-v4/uniswap-v4.d.ts +6 -6
- package/build/dex/uniswap-v4/uniswap-v4.js +47 -29
- package/build/dex/uniswap-v4/uniswap-v4.js.map +1 -1
- package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
- package/build/dex/usual/usual-m-smart-m.js +50 -0
- package/build/dex/usual/usual-m-smart-m.js.map +1 -0
- package/build/dex/usual-m-smart-m/config.d.ts +3 -0
- package/build/dex/usual-m-smart-m/config.js +13 -0
- package/build/dex/usual-m-smart-m/config.js.map +1 -0
- package/build/dex/usual-m-smart-m/types.d.ts +7 -0
- package/build/dex/usual-m-smart-m/types.js +3 -0
- package/build/dex/usual-m-smart-m/types.js.map +1 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
- package/build/dex/{m-token → usual-m-usd0}/config.d.ts +2 -2
- package/build/dex/usual-m-usd0/config.js +14 -0
- package/build/dex/usual-m-usd0/config.js.map +1 -0
- package/build/dex/usual-m-usd0/types.d.ts +8 -0
- package/build/dex/usual-m-usd0/types.js +3 -0
- package/build/dex/usual-m-usd0/types.js.map +1 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
- package/build/dex/zerox/index.d.ts +4 -26
- package/build/dex/zerox/index.js +50 -42
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex/zerox/types.d.ts +29 -0
- package/build/dex/zerox/types.js +8 -1
- package/build/dex/zerox/types.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/erc4626/config.ts +41 -0
- package/src/dex/{wusdm → erc4626}/constants.ts +2 -0
- package/src/dex/{wusdm/wusdm-pool.ts → erc4626/erc-4626-pool.ts} +38 -15
- package/src/dex/erc4626/erc4626-event.test.ts +134 -0
- package/src/dex/{wusdm/wusdm-integration.test.ts → erc4626/erc4626-integration.test.ts} +3 -3
- package/src/dex/{wusdm/wusdm.ts → erc4626/erc4626.ts} +69 -64
- package/src/dex/erc4626/old-events.test.ts +249 -0
- package/src/dex/erc4626/scripts/validate-state.ts +168 -0
- package/src/dex/{wusdm → erc4626}/types.ts +6 -6
- package/src/dex/index.ts +2 -2
- package/tests/constants-e2e.ts +1 -1
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/build/abi/integral/factory.json +0 -333
- package/build/abi/integral/oracle.json +0 -501
- package/build/abi/uniswap-v4/pool-manager.abi.json +0 -1366
- package/build/abi/uniswap-v4/state-view.abi.json +0 -365
- package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
- package/build/dex/integral/config.d.ts +0 -4
- package/build/dex/integral/config.js +0 -20
- package/build/dex/integral/config.js.map +0 -1
- package/build/dex/integral/context.d.ts +0 -40
- package/build/dex/integral/context.js +0 -158
- package/build/dex/integral/context.js.map +0 -1
- package/build/dex/integral/integral-factory.d.ts +0 -24
- package/build/dex/integral/integral-factory.js +0 -95
- package/build/dex/integral/integral-factory.js.map +0 -1
- package/build/dex/integral/integral-pool.d.ts +0 -50
- package/build/dex/integral/integral-pool.js +0 -149
- package/build/dex/integral/integral-pool.js.map +0 -1
- package/build/dex/integral/integral-pricing.d.ts +0 -18
- package/build/dex/integral/integral-pricing.js +0 -114
- package/build/dex/integral/integral-pricing.js.map +0 -1
- package/build/dex/integral/integral-relayer.d.ts +0 -42
- package/build/dex/integral/integral-relayer.js +0 -192
- package/build/dex/integral/integral-relayer.js.map +0 -1
- package/build/dex/integral/integral-token.d.ts +0 -27
- package/build/dex/integral/integral-token.js +0 -59
- package/build/dex/integral/integral-token.js.map +0 -1
- package/build/dex/integral/integral.d.ts +0 -41
- package/build/dex/integral/integral.js +0 -376
- package/build/dex/integral/integral.js.map +0 -1
- package/build/dex/integral/types.d.ts +0 -85
- package/build/dex/integral/types.js +0 -9
- package/build/dex/integral/types.js.map +0 -1
- package/build/dex/integral/utils-e2e.d.ts +0 -9
- package/build/dex/integral/utils-e2e.js +0 -131
- package/build/dex/integral/utils-e2e.js.map +0 -1
- package/build/dex/integral/utils.d.ts +0 -17
- package/build/dex/integral/utils.js +0 -94
- package/build/dex/integral/utils.js.map +0 -1
- package/build/dex/m-token/config.js +0 -19
- package/build/dex/m-token/config.js.map +0 -1
- package/build/dex/m-token/m-token.d.ts +0 -29
- package/build/dex/m-token/m-token.js +0 -145
- package/build/dex/m-token/m-token.js.map +0 -1
- package/build/dex/m-token/m-wrapped-m.d.ts +0 -17
- package/build/dex/m-token/m-wrapped-m.js +0 -50
- package/build/dex/m-token/m-wrapped-m.js.map +0 -1
- package/build/dex/m-token/types.d.ts +0 -12
- package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
- package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
- package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
- package/build/dex/uniswap-v4/constants.d.ts +0 -7
- package/build/dex/uniswap-v4/constants.js +0 -18
- package/build/dex/uniswap-v4/constants.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/BitMath.d.ts +0 -4
- package/build/dex/uniswap-v4/contract-math/BitMath.js +0 -93
- package/build/dex/uniswap-v4/contract-math/BitMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.d.ts +0 -3
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.js +0 -8
- package/build/dex/uniswap-v4/contract-math/FixedPoint128.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.d.ts +0 -4
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.js +0 -9
- package/build/dex/uniswap-v4/contract-math/FixedPoint96.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/FullMath.d.ts +0 -4
- package/build/dex/uniswap-v4/contract-math/FullMath.js +0 -19
- package/build/dex/uniswap-v4/contract-math/FullMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.d.ts +0 -3
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.js +0 -22
- package/build/dex/uniswap-v4/contract-math/LiquidityMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.d.ts +0 -10
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.js +0 -91
- package/build/dex/uniswap-v4/contract-math/SqrtPriceMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/SwapMath.d.ts +0 -8
- package/build/dex/uniswap-v4/contract-math/SwapMath.js +0 -70
- package/build/dex/uniswap-v4/contract-math/SwapMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/TickBitMap.d.ts +0 -7
- package/build/dex/uniswap-v4/contract-math/TickBitMap.js +0 -86
- package/build/dex/uniswap-v4/contract-math/TickBitMap.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/TickMath.d.ts +0 -8
- package/build/dex/uniswap-v4/contract-math/TickMath.js +0 -162
- package/build/dex/uniswap-v4/contract-math/TickMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.d.ts +0 -3
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.js +0 -10
- package/build/dex/uniswap-v4/contract-math/UnsafeMath.js.map +0 -1
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.d.ts +0 -8
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.js +0 -12
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-math.js.map +0 -1
- package/build/dex/uniswap-v4/subgraph.d.ts +0 -5
- package/build/dex/uniswap-v4/subgraph.js +0 -80
- package/build/dex/uniswap-v4/subgraph.js.map +0 -1
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.d.ts +0 -30
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js +0 -139
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js.map +0 -1
- package/build/dex/uniswap-v4/utils.d.ts +0 -2
- package/build/dex/uniswap-v4/utils.js +0 -15
- package/build/dex/uniswap-v4/utils.js.map +0 -1
- package/src/dex/wusdm/config.ts +0 -43
- package/src/dex/wusdm/wusdm-event.test.ts +0 -104
- /package/build/dex/{m-token → inception}/types.js +0 -0
- /package/src/abi/{wUSDM.json → ERC4626.json} +0 -0
- /package/src/dex/{wusdm/wusdm-e2e.test.ts → erc4626/erc4626-e2e.test.ts} +0 -0
- /package/src/dex/{wusdm/wusdm-gas-estimation.test.ts → erc4626/erc4626-gas-estimation.test.ts} +0 -0
|
@@ -14,58 +14,65 @@ import {
|
|
|
14
14
|
import { SwapSide, Network } from '../../constants';
|
|
15
15
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
16
16
|
import { getDexKeysWithNetwork } from '../../utils';
|
|
17
|
-
import { IDex, Context } from '
|
|
17
|
+
import { IDex, Context } from '../idex';
|
|
18
18
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
ERC4626Data,
|
|
21
|
+
ERC4626Functions,
|
|
22
|
+
ERC4626Params,
|
|
23
|
+
ERC4626PoolState,
|
|
24
24
|
} from './types';
|
|
25
25
|
import { SimpleExchange } from '../simple-exchange';
|
|
26
|
-
import {
|
|
27
|
-
import { Utils } from '../../utils';
|
|
26
|
+
import { ERC4626Config } from './config';
|
|
28
27
|
import { BI_POWS } from '../../bigint-constants';
|
|
29
|
-
import {
|
|
28
|
+
import { ERC4626EventPool } from './erc-4626-pool';
|
|
30
29
|
import { Interface } from '@ethersproject/abi';
|
|
31
|
-
import
|
|
32
|
-
import
|
|
30
|
+
import ERC4626_ABI from '../../abi/ERC4626.json';
|
|
31
|
+
import ERC20ABI from '../../abi/erc20.json';
|
|
32
|
+
import { DEPOSIT_TOPIC, TRANSFER_TOPIC, WITHDRAW_TOPIC } from './constants';
|
|
33
33
|
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
34
34
|
|
|
35
|
-
export class
|
|
35
|
+
export class ERC4626
|
|
36
36
|
extends SimpleExchange
|
|
37
|
-
implements IDex<
|
|
37
|
+
implements IDex<ERC4626Data, ERC4626Params>
|
|
38
38
|
{
|
|
39
39
|
readonly hasConstantPriceLargeAmounts = true;
|
|
40
40
|
readonly isFeeOnTransferSupported = false;
|
|
41
41
|
readonly needWrapNative: boolean = true;
|
|
42
42
|
|
|
43
43
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
44
|
-
getDexKeysWithNetwork(
|
|
44
|
+
getDexKeysWithNetwork(ERC4626Config);
|
|
45
45
|
|
|
46
|
-
public readonly eventPool:
|
|
46
|
+
public readonly eventPool: ERC4626EventPool;
|
|
47
47
|
logger: Logger;
|
|
48
48
|
|
|
49
49
|
constructor(
|
|
50
50
|
readonly network: Network,
|
|
51
51
|
readonly dexKey: string,
|
|
52
52
|
readonly dexHelper: IDexHelper,
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
53
|
+
readonly vault: string = ERC4626Config[dexKey][network].vault,
|
|
54
|
+
readonly asset: string = ERC4626Config[dexKey][network].asset,
|
|
55
|
+
readonly erc4626Interface: Interface = new Interface([
|
|
56
|
+
// Vault abi
|
|
57
|
+
...ERC4626_ABI,
|
|
58
|
+
// asset abi (specifically to handle Transfer to vault event)
|
|
59
|
+
...ERC20ABI,
|
|
60
|
+
]),
|
|
56
61
|
) {
|
|
57
62
|
super(dexHelper, dexKey);
|
|
58
63
|
this.logger = dexHelper.getLogger(dexKey);
|
|
59
|
-
this.eventPool = new
|
|
64
|
+
this.eventPool = new ERC4626EventPool(
|
|
60
65
|
this.dexKey,
|
|
61
66
|
this.network,
|
|
62
|
-
`${this.
|
|
67
|
+
`${this.vault}_${this.asset}`,
|
|
63
68
|
dexHelper,
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
69
|
+
this.vault,
|
|
70
|
+
this.asset,
|
|
71
|
+
this.erc4626Interface,
|
|
66
72
|
this.logger,
|
|
67
73
|
DEPOSIT_TOPIC,
|
|
68
74
|
WITHDRAW_TOPIC,
|
|
75
|
+
TRANSFER_TOPIC,
|
|
69
76
|
);
|
|
70
77
|
}
|
|
71
78
|
|
|
@@ -75,8 +82,8 @@ export class WUSDM
|
|
|
75
82
|
|
|
76
83
|
isAppropriatePair(srcToken: Token, destToken: Token): boolean {
|
|
77
84
|
return (
|
|
78
|
-
(this.
|
|
79
|
-
(this.
|
|
85
|
+
(this.isAsset(srcToken.address) && this.isVault(destToken.address)) ||
|
|
86
|
+
(this.isVault(srcToken.address) && this.isAsset(destToken.address))
|
|
80
87
|
);
|
|
81
88
|
}
|
|
82
89
|
|
|
@@ -94,23 +101,23 @@ export class WUSDM
|
|
|
94
101
|
const _destToken = this.dexHelper.config.wrapETH(destToken);
|
|
95
102
|
|
|
96
103
|
return this.isAppropriatePair(_srcToken, _destToken)
|
|
97
|
-
? [`${this.dexKey}_${this.
|
|
104
|
+
? [`${this.dexKey}_${this.vault}`]
|
|
98
105
|
: [];
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
return this.
|
|
108
|
+
isAsset(tokenAddress: Address) {
|
|
109
|
+
return this.asset.toLowerCase() === tokenAddress.toLowerCase();
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
return this.
|
|
112
|
+
isVault(tokenAddress: Address) {
|
|
113
|
+
return this.vault.toLowerCase() === tokenAddress.toLowerCase();
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
isWrap(srcToken: Token, destToken: Token, side: SwapSide) {
|
|
110
117
|
if (side === SwapSide.SELL) {
|
|
111
|
-
return this.
|
|
118
|
+
return this.isAsset(srcToken.address) && this.isVault(destToken.address);
|
|
112
119
|
}
|
|
113
|
-
return this.
|
|
120
|
+
return this.isVault(srcToken.address) && this.isAsset(destToken.address);
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
// Returns pool prices for amounts.
|
|
@@ -124,7 +131,7 @@ export class WUSDM
|
|
|
124
131
|
side: SwapSide,
|
|
125
132
|
blockNumber: number,
|
|
126
133
|
limitPools?: string[],
|
|
127
|
-
): Promise<null | ExchangePrices<
|
|
134
|
+
): Promise<null | ExchangePrices<ERC4626Data>> {
|
|
128
135
|
const _srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
129
136
|
const _destToken = this.dexHelper.config.wrapETH(destToken);
|
|
130
137
|
|
|
@@ -132,7 +139,7 @@ export class WUSDM
|
|
|
132
139
|
const state = this.eventPool.getState(blockNumber);
|
|
133
140
|
if (!state) return null;
|
|
134
141
|
|
|
135
|
-
const isSrcAsset = this.
|
|
142
|
+
const isSrcAsset = this.isAsset(_srcToken.address);
|
|
136
143
|
|
|
137
144
|
const isWrap = this.isWrap(_srcToken, _destToken, side);
|
|
138
145
|
|
|
@@ -156,15 +163,15 @@ export class WUSDM
|
|
|
156
163
|
unit: BI_POWS[18],
|
|
157
164
|
prices: amounts.map(amount => calcFunction(amount, state)),
|
|
158
165
|
gasCost: isWrap ? 60000 : 70000,
|
|
159
|
-
data: { exchange: `${this.
|
|
160
|
-
poolAddresses: [this.
|
|
166
|
+
data: { exchange: `${this.vault}` },
|
|
167
|
+
poolAddresses: [this.vault],
|
|
161
168
|
exchange: this.dexKey,
|
|
162
169
|
},
|
|
163
170
|
];
|
|
164
171
|
}
|
|
165
172
|
|
|
166
173
|
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
167
|
-
getCalldataGasCost(poolPrices: PoolPrices<
|
|
174
|
+
getCalldataGasCost(poolPrices: PoolPrices<ERC4626Data>): number | number[] {
|
|
168
175
|
// TODO: update if there is any payload in getAdapterParam
|
|
169
176
|
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
170
177
|
}
|
|
@@ -173,18 +180,16 @@ export class WUSDM
|
|
|
173
180
|
tokenAddress: Address,
|
|
174
181
|
limit: number,
|
|
175
182
|
): Promise<PoolLiquidity[]> {
|
|
176
|
-
if (!this.
|
|
183
|
+
if (!this.isAsset(tokenAddress) && !this.isVault(tokenAddress)) return [];
|
|
177
184
|
|
|
178
185
|
return [
|
|
179
186
|
{
|
|
180
187
|
exchange: this.dexKey,
|
|
181
|
-
address: this.
|
|
188
|
+
address: this.vault,
|
|
182
189
|
connectorTokens: [
|
|
183
190
|
{
|
|
184
191
|
decimals: 18,
|
|
185
|
-
address: this.
|
|
186
|
-
? this.wUSDMAddress
|
|
187
|
-
: this.USDMAddress,
|
|
192
|
+
address: this.isAsset(tokenAddress) ? this.vault : this.asset,
|
|
188
193
|
},
|
|
189
194
|
],
|
|
190
195
|
liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
|
|
@@ -197,21 +202,21 @@ export class WUSDM
|
|
|
197
202
|
destToken: string,
|
|
198
203
|
srcAmount: string,
|
|
199
204
|
destAmount: string,
|
|
200
|
-
data:
|
|
205
|
+
data: ERC4626Data,
|
|
201
206
|
side: SwapSide,
|
|
202
207
|
): Promise<SimpleExchangeParam> {
|
|
203
208
|
const isSell = side === SwapSide.SELL;
|
|
204
209
|
const { exchange } = data;
|
|
205
210
|
|
|
206
211
|
let swapData: string;
|
|
207
|
-
if (this.
|
|
208
|
-
swapData = this.
|
|
209
|
-
isSell ?
|
|
212
|
+
if (this.isAsset(srcToken)) {
|
|
213
|
+
swapData = this.erc4626Interface.encodeFunctionData(
|
|
214
|
+
isSell ? ERC4626Functions.deposit : ERC4626Functions.mint,
|
|
210
215
|
[isSell ? srcAmount : destAmount, this.augustusAddress],
|
|
211
216
|
);
|
|
212
217
|
} else {
|
|
213
|
-
swapData = this.
|
|
214
|
-
isSell ?
|
|
218
|
+
swapData = this.erc4626Interface.encodeFunctionData(
|
|
219
|
+
isSell ? ERC4626Functions.redeem : ERC4626Functions.withdraw,
|
|
215
220
|
[
|
|
216
221
|
isSell ? srcAmount : destAmount,
|
|
217
222
|
this.augustusAddress,
|
|
@@ -230,7 +235,7 @@ export class WUSDM
|
|
|
230
235
|
undefined,
|
|
231
236
|
undefined,
|
|
232
237
|
undefined,
|
|
233
|
-
isSell && this.
|
|
238
|
+
isSell && this.isAsset(destToken),
|
|
234
239
|
);
|
|
235
240
|
}
|
|
236
241
|
|
|
@@ -240,7 +245,7 @@ export class WUSDM
|
|
|
240
245
|
srcAmount: NumberAsString,
|
|
241
246
|
destAmount: NumberAsString,
|
|
242
247
|
recipient: Address,
|
|
243
|
-
data:
|
|
248
|
+
data: ERC4626Data,
|
|
244
249
|
side: SwapSide,
|
|
245
250
|
_: Context,
|
|
246
251
|
executorAddress: Address,
|
|
@@ -249,14 +254,14 @@ export class WUSDM
|
|
|
249
254
|
const { exchange } = data;
|
|
250
255
|
|
|
251
256
|
let swapData: string;
|
|
252
|
-
if (this.
|
|
253
|
-
swapData = this.
|
|
254
|
-
isSell ?
|
|
257
|
+
if (this.isAsset(srcToken)) {
|
|
258
|
+
swapData = this.erc4626Interface.encodeFunctionData(
|
|
259
|
+
isSell ? ERC4626Functions.deposit : ERC4626Functions.mint,
|
|
255
260
|
[isSell ? srcAmount : destAmount, recipient],
|
|
256
261
|
);
|
|
257
262
|
} else {
|
|
258
|
-
swapData = this.
|
|
259
|
-
isSell ?
|
|
263
|
+
swapData = this.erc4626Interface.encodeFunctionData(
|
|
264
|
+
isSell ? ERC4626Functions.redeem : ERC4626Functions.withdraw,
|
|
260
265
|
[isSell ? srcAmount : destAmount, recipient, executorAddress],
|
|
261
266
|
);
|
|
262
267
|
}
|
|
@@ -268,13 +273,13 @@ export class WUSDM
|
|
|
268
273
|
targetExchange: exchange,
|
|
269
274
|
returnAmountPos: isSell
|
|
270
275
|
? extractReturnAmountPosition(
|
|
271
|
-
this.
|
|
272
|
-
this.
|
|
273
|
-
?
|
|
274
|
-
:
|
|
276
|
+
this.erc4626Interface,
|
|
277
|
+
this.isAsset(srcToken)
|
|
278
|
+
? ERC4626Functions.deposit
|
|
279
|
+
: ERC4626Functions.redeem,
|
|
275
280
|
)
|
|
276
281
|
: undefined,
|
|
277
|
-
skipApproval: this.
|
|
282
|
+
skipApproval: this.isAsset(destToken),
|
|
278
283
|
};
|
|
279
284
|
}
|
|
280
285
|
|
|
@@ -287,7 +292,7 @@ export class WUSDM
|
|
|
287
292
|
destToken: string,
|
|
288
293
|
srcAmount: string,
|
|
289
294
|
destAmount: string,
|
|
290
|
-
data:
|
|
295
|
+
data: ERC4626Data,
|
|
291
296
|
side: SwapSide,
|
|
292
297
|
): AdapterExchangeParam {
|
|
293
298
|
const { exchange } = data;
|
|
@@ -299,7 +304,7 @@ export class WUSDM
|
|
|
299
304
|
},
|
|
300
305
|
},
|
|
301
306
|
{
|
|
302
|
-
toStaked: this.
|
|
307
|
+
toStaked: this.isAsset(srcToken),
|
|
303
308
|
},
|
|
304
309
|
);
|
|
305
310
|
|
|
@@ -310,19 +315,19 @@ export class WUSDM
|
|
|
310
315
|
};
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
previewRedeem(shares: bigint, state:
|
|
318
|
+
previewRedeem(shares: bigint, state: ERC4626PoolState) {
|
|
314
319
|
return (shares * state.totalAssets) / state.totalShares;
|
|
315
320
|
}
|
|
316
321
|
|
|
317
|
-
previewMint(shares: bigint, state:
|
|
322
|
+
previewMint(shares: bigint, state: ERC4626PoolState) {
|
|
318
323
|
return (shares * state.totalAssets) / state.totalShares;
|
|
319
324
|
}
|
|
320
325
|
|
|
321
|
-
previewWithdraw(assets: bigint, state:
|
|
326
|
+
previewWithdraw(assets: bigint, state: ERC4626PoolState) {
|
|
322
327
|
return (assets * state.totalShares) / state.totalAssets;
|
|
323
328
|
}
|
|
324
329
|
|
|
325
|
-
previewDeposit(assets: bigint, state:
|
|
330
|
+
previewDeposit(assets: bigint, state: ERC4626PoolState) {
|
|
326
331
|
return (assets * state.totalShares) / state.totalAssets;
|
|
327
332
|
}
|
|
328
333
|
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { WusdmEventPool } from './wusdm-pool';
|
|
6
|
+
import { WUSDMConfig } from './config';
|
|
7
|
+
import { Network } from '../../constants';
|
|
8
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
9
|
+
import wUSDM_ABI from '../../abi/wUSDM.json';
|
|
10
|
+
import { DEPOSIT_TOPIC, WITHDRAW_TOPIC } from './constants';
|
|
11
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
12
|
+
import { WusdmPoolState } from './types';
|
|
13
|
+
import { Log, Provider } from '@ethersproject/providers';
|
|
14
|
+
|
|
15
|
+
import { Interface } from '@ethersproject/abi';
|
|
16
|
+
import _ from 'lodash';
|
|
17
|
+
import { uint256 } from '../../utils';
|
|
18
|
+
|
|
19
|
+
jest.setTimeout(1000 * 1000);
|
|
20
|
+
const networks = [
|
|
21
|
+
Network.MAINNET,
|
|
22
|
+
Network.ARBITRUM,
|
|
23
|
+
Network.BASE,
|
|
24
|
+
Network.POLYGON,
|
|
25
|
+
Network.OPTIMISM,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
async function fetchPoolState(
|
|
29
|
+
wusdmPool: WusdmEventPool,
|
|
30
|
+
blockNumber: number,
|
|
31
|
+
): Promise<WusdmPoolState> {
|
|
32
|
+
const eventState = wusdmPool.getState(blockNumber);
|
|
33
|
+
if (eventState) return eventState;
|
|
34
|
+
const onChainState = await wusdmPool.generateState(blockNumber);
|
|
35
|
+
wusdmPool.setState(onChainState, blockNumber);
|
|
36
|
+
return onChainState;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('Wusdm', function () {
|
|
40
|
+
const dexKey = 'Wusdm';
|
|
41
|
+
const multichainBlockNumbers: {
|
|
42
|
+
[network: string]: { [eventName: string]: number[] };
|
|
43
|
+
} = {
|
|
44
|
+
[Network.MAINNET]: {
|
|
45
|
+
deposit: [20808811, 20692902, 20685702],
|
|
46
|
+
withdraw: [20873278, 20869272, 20862960],
|
|
47
|
+
},
|
|
48
|
+
[Network.ARBITRUM]: {
|
|
49
|
+
deposit: [259463653, 259456755, 259448821],
|
|
50
|
+
withdraw: [259421319, 259420791, 259419437],
|
|
51
|
+
},
|
|
52
|
+
[Network.BASE]: {
|
|
53
|
+
deposit: [20521934, 20460747, 20436449],
|
|
54
|
+
withdraw: [20492729, 20409282, 20274826],
|
|
55
|
+
},
|
|
56
|
+
[Network.POLYGON]: {
|
|
57
|
+
deposit: [62509681, 62359608, 62160587],
|
|
58
|
+
withdraw: [62505429, 62381506, 62125779],
|
|
59
|
+
},
|
|
60
|
+
[Network.OPTIMISM]: {
|
|
61
|
+
deposit: [126118678, 126116167, 126110439],
|
|
62
|
+
withdraw: [126113314, 126108196, 126107784],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
networks.forEach(network => {
|
|
67
|
+
describe(`${network}`, function () {
|
|
68
|
+
const wUSDMAddress = WUSDMConfig['wUSDM'][network].wUSDMAddress;
|
|
69
|
+
const wUSDMIface = new Interface(wUSDM_ABI);
|
|
70
|
+
|
|
71
|
+
const blockNumbers = multichainBlockNumbers[network];
|
|
72
|
+
|
|
73
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
74
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
75
|
+
it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
|
|
76
|
+
const dexHelper = new DummyDexHelper(network);
|
|
77
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
78
|
+
|
|
79
|
+
const wusdmPool = new WusdmEventPool(
|
|
80
|
+
dexKey,
|
|
81
|
+
network,
|
|
82
|
+
`wusdm-pool`,
|
|
83
|
+
dexHelper,
|
|
84
|
+
wUSDMAddress,
|
|
85
|
+
wUSDMIface,
|
|
86
|
+
logger,
|
|
87
|
+
DEPOSIT_TOPIC,
|
|
88
|
+
WITHDRAW_TOPIC,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await wusdmPool.initialize(blockNumber);
|
|
92
|
+
|
|
93
|
+
await testEventSubscriber(
|
|
94
|
+
wusdmPool,
|
|
95
|
+
wusdmPool.addressesSubscribed,
|
|
96
|
+
(_blockNumber: number) => fetchPoolState(wusdmPool, _blockNumber),
|
|
97
|
+
blockNumber,
|
|
98
|
+
`${dexKey}_${wUSDMAddress}`,
|
|
99
|
+
dexHelper.provider,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
async function getEventLogsByBlockNumbers(
|
|
109
|
+
provider: Provider,
|
|
110
|
+
blockNumber: number,
|
|
111
|
+
amountOfBlocksBeforeAndAfter: number,
|
|
112
|
+
address: string,
|
|
113
|
+
topics0: string[],
|
|
114
|
+
): Promise<number[]> {
|
|
115
|
+
const events: Log[] = [];
|
|
116
|
+
const batchSize = 50;
|
|
117
|
+
const from = Math.max(0, blockNumber - amountOfBlocksBeforeAndAfter);
|
|
118
|
+
const to = blockNumber + amountOfBlocksBeforeAndAfter;
|
|
119
|
+
|
|
120
|
+
for (let i = from; i <= to; i += batchSize) {
|
|
121
|
+
const batch = _.range(i, Math.min(i + batchSize, to + 1));
|
|
122
|
+
const batchPromises = batch.map(async blockNumber => {
|
|
123
|
+
const block = await provider.getBlockWithTransactions(blockNumber);
|
|
124
|
+
for (const tx of block.transactions) {
|
|
125
|
+
const receipt = await provider.getTransactionReceipt(tx.hash);
|
|
126
|
+
for (const log of receipt.logs) {
|
|
127
|
+
if (
|
|
128
|
+
log.address.toLowerCase() === address.toLowerCase() &&
|
|
129
|
+
topics0.includes(log.topics[0])
|
|
130
|
+
) {
|
|
131
|
+
events.push(log);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
await Promise.all(batchPromises);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return new Array(
|
|
141
|
+
...new Set(
|
|
142
|
+
events
|
|
143
|
+
.sort((a, b) => a.blockNumber - b.blockNumber)
|
|
144
|
+
.map(log => log.blockNumber),
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
describe.only('sDAI', function () {
|
|
150
|
+
const dexKey = 'sDAI';
|
|
151
|
+
// 38964246:withdraw
|
|
152
|
+
// 38964302:withdraw
|
|
153
|
+
const network = Network.GNOSIS;
|
|
154
|
+
const brokenBlockNumber = 38964315;
|
|
155
|
+
const blockNumbers: Record<string, number[]> = {
|
|
156
|
+
deposit: [38964247, 38964249, 38964253, 38964263, 38964303, 38964311],
|
|
157
|
+
withdraw: [
|
|
158
|
+
38964221, 38964225, 38964230, 38964233, 38964236, 38964238, 38964246,
|
|
159
|
+
38964277, 38964278, 38964279, 38964289, 38964294, 38964302,
|
|
160
|
+
],
|
|
161
|
+
// withdraw: [38964246],
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// const withdrawTopic =
|
|
165
|
+
// '0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7';
|
|
166
|
+
// const address = '0xaf204776c7245bF4147c2612BF6e5972Ee483701';
|
|
167
|
+
|
|
168
|
+
// it('test', async function () {
|
|
169
|
+
|
|
170
|
+
// const withdrawBlockNumbers: number[] = [];
|
|
171
|
+
// for (let i = brokenBlockNumber - 100; i <= brokenBlockNumber; i++) {
|
|
172
|
+
// console.log('Checking block', i);
|
|
173
|
+
// const logs = await getEventLogsByBlockNumber(
|
|
174
|
+
// dexHelper.provider,
|
|
175
|
+
// i,
|
|
176
|
+
// address,
|
|
177
|
+
// withdrawTopic,
|
|
178
|
+
// );
|
|
179
|
+
// if (logs.length > 0) {
|
|
180
|
+
// withdrawBlockNumbers.push(i);
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
|
|
184
|
+
// console.log('depositBlockNumbers', withdrawBlockNumbers);
|
|
185
|
+
// });
|
|
186
|
+
|
|
187
|
+
const wUSDMAddress = WUSDMConfig[dexKey][network].wUSDMAddress;
|
|
188
|
+
const wUSDMIface = new Interface(wUSDM_ABI);
|
|
189
|
+
|
|
190
|
+
const events = [];
|
|
191
|
+
|
|
192
|
+
describe('test', function () {
|
|
193
|
+
// const blockNumberWithEvents = await getEventLogsByBlockNumbers(
|
|
194
|
+
// new DummyDexHelper(network).provider,
|
|
195
|
+
// brokenBlockNumber,
|
|
196
|
+
// 10,
|
|
197
|
+
// '0xaf204776c7245bF4147c2612BF6e5972Ee483701',
|
|
198
|
+
// [WITHDRAW_TOPIC, DEPOSIT_TOPIC],
|
|
199
|
+
// );
|
|
200
|
+
|
|
201
|
+
// const blockNumberWithEvents = [
|
|
202
|
+
// 38964215, 38964218, 38964219, 38964221, 38964222, 38964224, 38964225,
|
|
203
|
+
// 38964230, 38964233, 38964236, 38964238, 38964243, 38964244, 38964245,
|
|
204
|
+
// 38964246, 38964247, 38964249, 38964253, 38964263, 38964277, 38964278,
|
|
205
|
+
// 38964279, 38964289, 38964294, 38964302, 38964303, 38964309, 38964311,
|
|
206
|
+
// 38964314, 38964317, 38964318, 38964319, 38964320, 38964321, 38964322,
|
|
207
|
+
// 38964327, 38964329, 38964330, 38964332, 38964335, 38964339, 38964341,
|
|
208
|
+
// 38964343, 38964344, 38964349, 38964352, 38964356, 38964357, 38964362,
|
|
209
|
+
// 38964364, 38964369, 38964373, 38964378, 38964379, 38964381, 38964384,
|
|
210
|
+
// 38964386, 38964388, 38964389, 38964391, 38964393, 38964398, 38964401,
|
|
211
|
+
// 38964403, 38964404, 38964406, 38964407, 38964410, 38964412, 38964413,
|
|
212
|
+
// 38964414,
|
|
213
|
+
// ];
|
|
214
|
+
|
|
215
|
+
const blockNumberWithEvents = [38964251, 38964252, 38964253, 38964254];
|
|
216
|
+
|
|
217
|
+
console.log('blockNumberWithEvents', blockNumberWithEvents);
|
|
218
|
+
|
|
219
|
+
blockNumberWithEvents.forEach(blockNumber => {
|
|
220
|
+
it(`Should return the correct state after the ${blockNumber}`, async function () {
|
|
221
|
+
const dexHelper = new DummyDexHelper(network);
|
|
222
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
223
|
+
|
|
224
|
+
const wusdmPool = new WusdmEventPool(
|
|
225
|
+
dexKey,
|
|
226
|
+
network,
|
|
227
|
+
`wusdm-pool`,
|
|
228
|
+
dexHelper,
|
|
229
|
+
wUSDMAddress,
|
|
230
|
+
wUSDMIface,
|
|
231
|
+
logger,
|
|
232
|
+
DEPOSIT_TOPIC,
|
|
233
|
+
WITHDRAW_TOPIC,
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
await wusdmPool.initialize(blockNumber - 1);
|
|
237
|
+
|
|
238
|
+
await testEventSubscriber(
|
|
239
|
+
wusdmPool,
|
|
240
|
+
wusdmPool.addressesSubscribed,
|
|
241
|
+
(_blockNumber: number) => fetchPoolState(wusdmPool, _blockNumber),
|
|
242
|
+
blockNumber,
|
|
243
|
+
`${dexKey}_${wUSDMAddress}`,
|
|
244
|
+
dexHelper.provider,
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|