@paraswap/dex-lib 2.50.5 → 2.50.6-sdai
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/build/abi/maker-psm/pot.json +322 -0
- package/build/abi/{angle/stagToken.json → sdai/SavingsDai.abi.json} +177 -263
- package/build/config.js +2 -1
- package/build/config.js.map +1 -1
- package/build/dex/curve-v1-factory/config.js +11 -128
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +0 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.js +17 -29
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +0 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +1 -4
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +0 -10
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +0 -40
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +0 -24
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +0 -53
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.d.ts +0 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.js +1 -5
- package/build/dex/curve-v1-factory/price-handlers/functions/utils.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/types.d.ts +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +2 -3
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +6 -38
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +2 -11
- package/build/dex/curve-v1-factory/types.js +0 -3
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/hashflow/constants.d.ts +0 -27
- package/build/dex/hashflow/constants.js +1 -29
- package/build/dex/hashflow/constants.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +2 -3
- package/build/dex/hashflow/hashflow.js +12 -69
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/types.d.ts +0 -11
- package/build/dex/hashflow/types.js +0 -9
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/index.d.ts +2 -2
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/config.js +0 -15
- package/build/dex/pancakeswap-v3/config.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/sdai/config.d.ts +11 -0
- package/build/dex/sdai/config.js +24 -0
- package/build/dex/sdai/config.js.map +1 -0
- package/build/dex/sdai/constants.d.ts +2 -0
- package/build/dex/sdai/constants.js +6 -0
- package/build/dex/sdai/constants.js.map +1 -0
- package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
- package/build/dex/sdai/scripts/validate-state.js +102 -0
- package/build/dex/sdai/scripts/validate-state.js.map +1 -0
- package/build/dex/sdai/sdai-pool.d.ts +16 -0
- package/build/dex/sdai/sdai-pool.js +85 -0
- package/build/dex/sdai/sdai-pool.js.map +1 -0
- package/build/dex/sdai/sdai.d.ts +51 -0
- package/build/dex/sdai/sdai.js +172 -0
- package/build/dex/sdai/sdai.js.map +1 -0
- package/build/dex/sdai/types.d.ts +21 -0
- package/build/dex/sdai/types.js +11 -0
- package/build/dex/sdai/types.js.map +1 -0
- package/build/dex/sdai/utils.d.ts +4 -0
- package/build/dex/sdai/utils.js +39 -0
- package/build/dex/sdai/utils.js.map +1 -0
- package/build/dex/woo-fi-v2/config.js +4 -4
- package/package.json +1 -1
- package/src/abi/maker-psm/pot.json +322 -0
- package/src/abi/sdai/SavingsDai.abi.json +877 -0
- package/src/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
- package/src/config.ts +2 -1
- package/src/dex/curve-v1-factory/config.ts +11 -128
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +1 -123
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +0 -392
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +39 -61
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +0 -1
- package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +2 -6
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +0 -11
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +1 -59
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +0 -51
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +1 -68
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +0 -2
- package/src/dex/curve-v1-factory/price-handlers/functions/utils.ts +0 -4
- package/src/dex/curve-v1-factory/price-handlers/types.ts +1 -8
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +18 -71
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +0 -1
- package/src/dex/curve-v1-factory/types.ts +1 -12
- package/src/dex/hashflow/constants.ts +0 -32
- package/src/dex/hashflow/hashflow.ts +19 -121
- package/src/dex/hashflow/types.ts +2 -20
- package/src/dex/idex.ts +1 -1
- package/src/dex/index.ts +4 -2
- package/src/dex/pancakeswap-v3/config.ts +0 -16
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1 -3
- package/src/dex/sdai/config.ts +28 -0
- package/src/dex/sdai/constants.ts +2 -0
- package/src/dex/sdai/scripts/validate-state.ts +144 -0
- package/src/dex/sdai/sdai-e2e.test.ts +96 -0
- package/src/dex/sdai/sdai-events.test.ts +105 -0
- package/src/dex/sdai/sdai-integration.test.ts +148 -0
- package/src/dex/sdai/sdai-pool.ts +113 -0
- package/src/dex/sdai/sdai.ts +233 -0
- package/src/dex/sdai/types.ts +23 -0
- package/src/dex/sdai/utils.ts +48 -0
- package/src/dex/woo-fi-v2/config.ts +4 -4
- package/tests/constants-e2e.ts +3 -38
- package/tests/utils-e2e.ts +0 -1
- package/build/abi/Redstone.json +0 -739
- package/build/abi/angle-transmuter/MorphoOracle.json +0 -193
- package/build/abi/angle-transmuter/MorphoVault.json +0 -2506
- package/build/abi/angle-transmuter/Pyth.json +0 -1534
- package/build/abi/angle-transmuter/Transmuter.json +0 -1711
- package/build/abi/pharaoh/PharaohPool.abi.json +0 -1582
- package/build/abi/smardex/smardex-factory.json +0 -185
- package/build/abi/smardex/smardex-pool.json +0 -578
- package/build/abi/smardex/smardex-router.json +0 -648
- package/build/abi/trader-joe-v2_1/FactoryABI.json +0 -1208
- package/build/abi/trader-joe-v2_1/PairABI.json +0 -1493
- package/build/abi/trader-joe-v2_1/RouterABI.json +0 -1489
- package/build/abi/trader-joe-v2_1/StateMulticall.json +0 -193
- package/build/abi/wombat/pool.json +0 -1289
- package/build/dex/aave-v2/tokens-avalanche.json +0 -44
- package/build/dex/aave-v2/tokens-mainnet.json +0 -188
- package/build/dex/aave-v2/tokens-polygon.json +0 -44
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.d.ts +0 -55
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js +0 -183
- package/build/dex/angle-staked-stable/angle-staked-stable-pool.js.map +0 -1
- package/build/dex/angle-staked-stable/angle-staked-stable.d.ts +0 -50
- package/build/dex/angle-staked-stable/angle-staked-stable.js +0 -228
- package/build/dex/angle-staked-stable/angle-staked-stable.js.map +0 -1
- package/build/dex/angle-staked-stable/config.d.ts +0 -4
- package/build/dex/angle-staked-stable/config.js +0 -139
- package/build/dex/angle-staked-stable/config.js.map +0 -1
- package/build/dex/angle-staked-stable/types.d.ts +0 -15
- package/build/dex/angle-staked-stable/types.js +0 -3
- package/build/dex/angle-staked-stable/types.js.map +0 -1
- package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +0 -61
- package/build/dex/angle-transmuter/angle-transmuter-pool.js +0 -415
- package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +0 -1
- package/build/dex/angle-transmuter/angle-transmuter.d.ts +0 -59
- package/build/dex/angle-transmuter/angle-transmuter.js +0 -262
- package/build/dex/angle-transmuter/angle-transmuter.js.map +0 -1
- package/build/dex/angle-transmuter/backedOracle.d.ts +0 -19
- package/build/dex/angle-transmuter/backedOracle.js +0 -56
- package/build/dex/angle-transmuter/backedOracle.js.map +0 -1
- package/build/dex/angle-transmuter/config.d.ts +0 -4
- package/build/dex/angle-transmuter/config.js +0 -30
- package/build/dex/angle-transmuter/config.js.map +0 -1
- package/build/dex/angle-transmuter/constants.d.ts +0 -77
- package/build/dex/angle-transmuter/constants.js +0 -94
- package/build/dex/angle-transmuter/constants.js.map +0 -1
- package/build/dex/angle-transmuter/morphoOracle.d.ts +0 -42
- package/build/dex/angle-transmuter/morphoOracle.js +0 -179
- package/build/dex/angle-transmuter/morphoOracle.js.map +0 -1
- package/build/dex/angle-transmuter/morphoVault.d.ts +0 -19
- package/build/dex/angle-transmuter/morphoVault.js +0 -78
- package/build/dex/angle-transmuter/morphoVault.js.map +0 -1
- package/build/dex/angle-transmuter/pyth.d.ts +0 -19
- package/build/dex/angle-transmuter/pyth.js +0 -70
- package/build/dex/angle-transmuter/pyth.js.map +0 -1
- package/build/dex/angle-transmuter/redstone.d.ts +0 -20
- package/build/dex/angle-transmuter/redstone.js +0 -73
- package/build/dex/angle-transmuter/redstone.js.map +0 -1
- package/build/dex/angle-transmuter/transmuter.d.ts +0 -52
- package/build/dex/angle-transmuter/transmuter.js +0 -374
- package/build/dex/angle-transmuter/transmuter.js.map +0 -1
- package/build/dex/angle-transmuter/types.d.ts +0 -188
- package/build/dex/angle-transmuter/types.js +0 -33
- package/build/dex/angle-transmuter/types.js.map +0 -1
- package/build/dex/angle-transmuter/utils.d.ts +0 -9
- package/build/dex/angle-transmuter/utils.js +0 -252
- package/build/dex/angle-transmuter/utils.js.map +0 -1
- package/build/dex/smardex/subgraph-queries.d.ts +0 -1
- package/build/dex/smardex/subgraph-queries.js +0 -17
- package/build/dex/smardex/subgraph-queries.js.map +0 -1
- package/build/dex/smardex/usd-reserves.d.ts +0 -23
- package/build/dex/smardex/usd-reserves.js +0 -86
- package/build/dex/smardex/usd-reserves.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/config.d.ts +0 -4
- package/build/dex/trader-joe-v2-1-2/config.js +0 -47
- package/build/dex/trader-joe-v2-1-2/config.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/constants.d.ts +0 -20
- package/build/dex/trader-joe-v2-1-2/constants.js +0 -22
- package/build/dex/trader-joe-v2-1-2/constants.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/math/index.d.ts +0 -37
- package/build/dex/trader-joe-v2-1-2/math/index.js +0 -291
- package/build/dex/trader-joe-v2-1-2/math/index.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +0 -60
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +0 -248
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +0 -53
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +0 -307
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +0 -1
- package/build/dex/trader-joe-v2-1-2/types.d.ts +0 -82
- package/build/dex/trader-joe-v2-1-2/types.js +0 -9
- package/build/dex/trader-joe-v2-1-2/types.js.map +0 -1
- package/build/dex/trader-joe-v2_1/config.d.ts +0 -4
- package/build/dex/trader-joe-v2_1/config.js +0 -47
- package/build/dex/trader-joe-v2_1/config.js.map +0 -1
- package/build/dex/trader-joe-v2_1/constants.d.ts +0 -20
- package/build/dex/trader-joe-v2_1/constants.js +0 -22
- package/build/dex/trader-joe-v2_1/constants.js.map +0 -1
- package/build/dex/trader-joe-v2_1/math/index.d.ts +0 -37
- package/build/dex/trader-joe-v2_1/math/index.js +0 -291
- package/build/dex/trader-joe-v2_1/math/index.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +0 -384
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.d.ts +0 -60
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js +0 -247
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js.map +0 -1
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.d.ts +0 -53
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js +0 -307
- package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js.map +0 -1
- package/build/dex/trader-joe-v2_1/types.d.ts +0 -82
- package/build/dex/trader-joe-v2_1/types.js +0 -9
- package/build/dex/trader-joe-v2_1/types.js.map +0 -1
- package/build/dex/wombat/wombat-pool-poller.d.ts +0 -22
- package/build/dex/wombat/wombat-pool-poller.js +0 -164
- package/build/dex/wombat/wombat-pool-poller.js.map +0 -1
- package/build/dex-helper/Cache.d.ts +0 -31
- package/build/dex-helper/Cache.js +0 -106
- package/build/dex-helper/Cache.js.map +0 -1
- package/build/dex-helper/RedisBatcher.d.ts +0 -20
- package/build/dex-helper/RedisBatcher.js +0 -75
- package/build/dex-helper/RedisBatcher.js.map +0 -1
- package/build/dex-helper/RedisWrapper.d.ts +0 -37
- package/build/dex-helper/RedisWrapper.js +0 -165
- package/build/dex-helper/RedisWrapper.js.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { SDaiEventPool } from './sdai-pool';
|
|
5
|
+
import { SDaiConfig } from './config';
|
|
6
|
+
import { Network } from '../../constants';
|
|
7
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
8
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
9
|
+
import { SDaiPoolState } from './types';
|
|
10
|
+
|
|
11
|
+
import PotAbi from '../../abi/maker-psm/pot.json';
|
|
12
|
+
import { Interface } from '@ethersproject/abi';
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
README
|
|
17
|
+
======
|
|
18
|
+
|
|
19
|
+
This test script adds unit tests for SDai event based
|
|
20
|
+
system. This is done by fetching the state on-chain before the
|
|
21
|
+
event block, manually pushing the block logs to the event-subscriber,
|
|
22
|
+
comparing the local state with on-chain state.
|
|
23
|
+
|
|
24
|
+
Most of the logic for testing is abstracted by `testEventSubscriber`.
|
|
25
|
+
You need to do two things to make the tests work:
|
|
26
|
+
|
|
27
|
+
1. Fetch the block numbers where certain events were released. You
|
|
28
|
+
can modify the `./scripts/fetch-event-blocknumber.ts` to get the
|
|
29
|
+
block numbers for different events. Make sure to get sufficient
|
|
30
|
+
number of blockNumbers to cover all possible cases for the event
|
|
31
|
+
mutations.
|
|
32
|
+
|
|
33
|
+
2. Complete the implementation for fetchPoolState function. The
|
|
34
|
+
function should fetch the on-chain state of the event subscriber
|
|
35
|
+
using just the blocknumber.
|
|
36
|
+
|
|
37
|
+
The template tests only include the test for a single event
|
|
38
|
+
subscriber. There can be cases where multiple event subscribers
|
|
39
|
+
exist for a single DEX. In such cases additional tests should be
|
|
40
|
+
added.
|
|
41
|
+
|
|
42
|
+
You can run this individual test script by running:
|
|
43
|
+
`npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
|
|
44
|
+
|
|
45
|
+
(This comment should be removed from the final implementation)
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
jest.setTimeout(50 * 1000);
|
|
49
|
+
const dexKey = 'SDai';
|
|
50
|
+
const network = Network.MAINNET;
|
|
51
|
+
|
|
52
|
+
async function fetchPoolState(
|
|
53
|
+
sdaiPool: SDaiEventPool,
|
|
54
|
+
blockNumber: number,
|
|
55
|
+
): Promise<SDaiPoolState> {
|
|
56
|
+
return sdaiPool.generateState(blockNumber);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('SDai Event', function () {
|
|
60
|
+
const blockNumbers: { [eventName: string]: number[] } = {
|
|
61
|
+
drip: [19827559, 19827524, 19827163, 19827124, 19827000, 19826892],
|
|
62
|
+
// TODO: no matching logs, you have to manually call "file"
|
|
63
|
+
// from "0xbe8e3e3618f7474f8cb1d074a26affef007e98fb" address
|
|
64
|
+
// https://etherscan.io/advanced-filter?fadd=0x197e90f9fad81970ba7976f33cbd77088e5d7cf7&tadd=0x197e90f9fad81970ba7976f33cbd77088e5d7cf7&mtd=0x29ae8114%7eFile
|
|
65
|
+
// file: [19831086]
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const addresses: { [contract: string]: string } = {
|
|
69
|
+
potAddress: SDaiConfig[dexKey][network].potAddress,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
describe('SDaiPool', function () {
|
|
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 sdaiPool = new SDaiEventPool(
|
|
80
|
+
dexKey,
|
|
81
|
+
dexHelper,
|
|
82
|
+
addresses.potAddress,
|
|
83
|
+
new Interface(PotAbi),
|
|
84
|
+
logger,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
await sdaiPool.initialize(blockNumber);
|
|
88
|
+
|
|
89
|
+
await testEventSubscriber(
|
|
90
|
+
sdaiPool,
|
|
91
|
+
sdaiPool.addressesSubscribed,
|
|
92
|
+
(_blockNumber: number) => fetchPoolState(sdaiPool, _blockNumber),
|
|
93
|
+
blockNumber,
|
|
94
|
+
`${dexKey}_${sdaiPool}`,
|
|
95
|
+
dexHelper.provider,
|
|
96
|
+
(state, expected) => {
|
|
97
|
+
// TODO:
|
|
98
|
+
expect(_.omit(state, ['chi'])).toEqual(_.omit(expected, ['chi']));
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
5
|
+
import { Network, SwapSide } from '../../constants';
|
|
6
|
+
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
7
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
8
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
+
import { SDai } from './sdai';
|
|
10
|
+
|
|
11
|
+
const network = Network.MAINNET;
|
|
12
|
+
|
|
13
|
+
const SDaiSymbol = 'sDAI';
|
|
14
|
+
const SDaiToken = Tokens[network][SDaiSymbol];
|
|
15
|
+
|
|
16
|
+
const DaiSymbol = 'DAI';
|
|
17
|
+
const DaiToken = Tokens[network][DaiSymbol];
|
|
18
|
+
|
|
19
|
+
const amounts = [0n, BI_POWS[18], 2000000000000000000n];
|
|
20
|
+
|
|
21
|
+
const dexKey = 'SDai';
|
|
22
|
+
const dexHelper = new DummyDexHelper(network);
|
|
23
|
+
let blocknumber: number;
|
|
24
|
+
let sdai: SDai;
|
|
25
|
+
|
|
26
|
+
describe('SDai', function () {
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
29
|
+
sdai = new SDai(network, dexKey, dexHelper);
|
|
30
|
+
if (sdai.initializePricing) {
|
|
31
|
+
await sdai.initializePricing(blocknumber);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('getPoolIdentifiers and getPricesVolume DAI -> sDAI SELL', async function () {
|
|
36
|
+
const pools = await sdai.getPoolIdentifiers(
|
|
37
|
+
DaiToken,
|
|
38
|
+
SDaiToken,
|
|
39
|
+
SwapSide.SELL,
|
|
40
|
+
blocknumber,
|
|
41
|
+
);
|
|
42
|
+
console.log(`${DaiSymbol} <> ${SDaiSymbol} Pool Identifiers: `, pools);
|
|
43
|
+
|
|
44
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
45
|
+
|
|
46
|
+
const poolPrices = await sdai.getPricesVolume(
|
|
47
|
+
DaiToken,
|
|
48
|
+
SDaiToken,
|
|
49
|
+
amounts,
|
|
50
|
+
SwapSide.SELL,
|
|
51
|
+
blocknumber,
|
|
52
|
+
pools,
|
|
53
|
+
);
|
|
54
|
+
console.log(`${DaiSymbol} <> ${SDaiSymbol} Pool Prices: `, poolPrices);
|
|
55
|
+
|
|
56
|
+
expect(poolPrices).not.toBeNull();
|
|
57
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('getPoolIdentifiers and getPricesVolume sDAI -> DAI SELL', async function () {
|
|
61
|
+
const pools = await sdai.getPoolIdentifiers(
|
|
62
|
+
SDaiToken,
|
|
63
|
+
DaiToken,
|
|
64
|
+
SwapSide.SELL,
|
|
65
|
+
blocknumber,
|
|
66
|
+
);
|
|
67
|
+
console.log(`${SDaiSymbol} <> ${DaiSymbol} Pool Identifiers: `, pools);
|
|
68
|
+
|
|
69
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
70
|
+
|
|
71
|
+
const poolPrices = await sdai.getPricesVolume(
|
|
72
|
+
SDaiToken,
|
|
73
|
+
DaiToken,
|
|
74
|
+
amounts,
|
|
75
|
+
SwapSide.SELL,
|
|
76
|
+
blocknumber,
|
|
77
|
+
pools,
|
|
78
|
+
);
|
|
79
|
+
console.log(`${SDaiSymbol} <> ${DaiSymbol} Pool Prices: `, poolPrices);
|
|
80
|
+
|
|
81
|
+
expect(poolPrices).not.toBeNull();
|
|
82
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('getPoolIdentifiers and getPricesVolume DAI -> sDAI BUY', async function () {
|
|
86
|
+
const pools = await sdai.getPoolIdentifiers(
|
|
87
|
+
DaiToken,
|
|
88
|
+
SDaiToken,
|
|
89
|
+
SwapSide.BUY,
|
|
90
|
+
blocknumber,
|
|
91
|
+
);
|
|
92
|
+
console.log(`${DaiSymbol} <> ${SDaiSymbol} Pool Identifiers: `, pools);
|
|
93
|
+
|
|
94
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
95
|
+
|
|
96
|
+
const poolPrices = await sdai.getPricesVolume(
|
|
97
|
+
DaiToken,
|
|
98
|
+
SDaiToken,
|
|
99
|
+
amounts,
|
|
100
|
+
SwapSide.BUY,
|
|
101
|
+
blocknumber,
|
|
102
|
+
pools,
|
|
103
|
+
);
|
|
104
|
+
console.log(`${DaiSymbol} <> ${SDaiSymbol} Pool Prices: `, poolPrices);
|
|
105
|
+
|
|
106
|
+
expect(poolPrices).not.toBeNull();
|
|
107
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.BUY, dexKey);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('getPoolIdentifiers and getPricesVolume sDAI -> DAI BUY', async function () {
|
|
111
|
+
const pools = await sdai.getPoolIdentifiers(
|
|
112
|
+
SDaiToken,
|
|
113
|
+
DaiToken,
|
|
114
|
+
SwapSide.BUY,
|
|
115
|
+
blocknumber,
|
|
116
|
+
);
|
|
117
|
+
console.log(`${SDaiSymbol} <> ${DaiSymbol} Pool Identifiers: `, pools);
|
|
118
|
+
|
|
119
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
120
|
+
|
|
121
|
+
const poolPrices = await sdai.getPricesVolume(
|
|
122
|
+
SDaiToken,
|
|
123
|
+
DaiToken,
|
|
124
|
+
amounts,
|
|
125
|
+
SwapSide.BUY,
|
|
126
|
+
blocknumber,
|
|
127
|
+
pools,
|
|
128
|
+
);
|
|
129
|
+
console.log(`${SDaiSymbol} <> ${DaiSymbol} Pool Prices: `, poolPrices);
|
|
130
|
+
|
|
131
|
+
expect(poolPrices).not.toBeNull();
|
|
132
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.BUY, dexKey);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('Dai getTopPoolsForToken', async function () {
|
|
136
|
+
const poolLiquidity = await sdai.getTopPoolsForToken(DaiToken.address, 10);
|
|
137
|
+
console.log(`${DaiSymbol} Top Pools:`, poolLiquidity);
|
|
138
|
+
|
|
139
|
+
checkPoolsLiquidity(poolLiquidity, DaiToken.address, dexKey);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('SDai getTopPoolsForToken', async function () {
|
|
143
|
+
const poolLiquidity = await sdai.getTopPoolsForToken(SDaiToken.address, 10);
|
|
144
|
+
console.log(`${SDaiSymbol} Top Pools:`, poolLiquidity);
|
|
145
|
+
|
|
146
|
+
checkPoolsLiquidity(poolLiquidity, SDaiToken.address, dexKey);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
2
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
3
|
+
import { Interface } from '@ethersproject/abi';
|
|
4
|
+
|
|
5
|
+
import type { IDexHelper } from '../../dex-helper';
|
|
6
|
+
import type { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
7
|
+
import type { Address, BlockHeader, Log, Logger } from '../../types';
|
|
8
|
+
import type { SDaiPoolState } from './types';
|
|
9
|
+
import { getOnChainState } from './utils';
|
|
10
|
+
|
|
11
|
+
const RAY = BI_POWS[27];
|
|
12
|
+
const ZERO = BigInt(0);
|
|
13
|
+
const TWO = BigInt(2);
|
|
14
|
+
const HALF = RAY / TWO;
|
|
15
|
+
|
|
16
|
+
// function file(bytes32,uint256)
|
|
17
|
+
const FILE_TOPICHASH = `0x29ae811400000000000000000000000000000000000000000000000000000000`;
|
|
18
|
+
// function drip()
|
|
19
|
+
const DRIP_TOPICHASH = `0x9f678cca00000000000000000000000000000000000000000000000000000000`;
|
|
20
|
+
// function cage()
|
|
21
|
+
const CAGE_TOPICHASH = `0x6924500900000000000000000000000000000000000000000000000000000000`;
|
|
22
|
+
// bytes32 repr of "dsr" string
|
|
23
|
+
const DSR_TOPIC = `0x6473720000000000000000000000000000000000000000000000000000000000`;
|
|
24
|
+
|
|
25
|
+
const rpow = (x: bigint, n: bigint): bigint => {
|
|
26
|
+
if (!x && !n) return RAY;
|
|
27
|
+
if (!x) return ZERO;
|
|
28
|
+
|
|
29
|
+
let z = n % TWO > ZERO ? x : RAY;
|
|
30
|
+
|
|
31
|
+
for (n = n / TWO; n; n /= TWO) {
|
|
32
|
+
x = (x * x + HALF) / RAY;
|
|
33
|
+
if (n % TWO > ZERO) {
|
|
34
|
+
z = (z * x + HALF) / RAY;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return z;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const calcChi = (state: SDaiPoolState, currentTimestamp?: number) => {
|
|
42
|
+
currentTimestamp ||= Math.floor(Date.now() / 1000);
|
|
43
|
+
if (!state.live) return RAY;
|
|
44
|
+
|
|
45
|
+
const { dsr: dsr_, chi: chi_, rho: rho_ } = state;
|
|
46
|
+
const now = BigInt(currentTimestamp);
|
|
47
|
+
const rho = BigInt(rho_);
|
|
48
|
+
const dsr = BigInt(dsr_);
|
|
49
|
+
const chi = BigInt(chi_);
|
|
50
|
+
|
|
51
|
+
return now > rho ? (rpow(dsr, now - rho) * chi) / RAY : chi;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export class SDaiEventPool extends StatefulEventSubscriber<SDaiPoolState> {
|
|
55
|
+
constructor(
|
|
56
|
+
parentName: string,
|
|
57
|
+
protected dexHelper: IDexHelper,
|
|
58
|
+
private potAddress: Address,
|
|
59
|
+
private potInterface: Interface,
|
|
60
|
+
logger: Logger,
|
|
61
|
+
) {
|
|
62
|
+
super(parentName, 'sdai', dexHelper, logger);
|
|
63
|
+
this.addressesSubscribed = [potAddress];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected processLog(
|
|
67
|
+
state: DeepReadonly<SDaiPoolState>,
|
|
68
|
+
log: Readonly<Log>,
|
|
69
|
+
blockHeader: Readonly<BlockHeader>,
|
|
70
|
+
): AsyncOrSync<DeepReadonly<SDaiPoolState> | null> {
|
|
71
|
+
if (log.topics[0] === FILE_TOPICHASH && log.topics[2] === DSR_TOPIC) {
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
dsr: BigInt(log.topics[3]).toString(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (log.topics[0] === DRIP_TOPICHASH) {
|
|
79
|
+
return {
|
|
80
|
+
...state,
|
|
81
|
+
rho: blockHeader.timestamp.toString(),
|
|
82
|
+
chi: calcChi(state, +blockHeader.timestamp).toString(),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async generateState(
|
|
90
|
+
blockNumber: number | 'latest' = 'latest',
|
|
91
|
+
): Promise<DeepReadonly<SDaiPoolState>> {
|
|
92
|
+
return getOnChainState(
|
|
93
|
+
this.dexHelper.multiContract,
|
|
94
|
+
this.potAddress,
|
|
95
|
+
this.potInterface,
|
|
96
|
+
blockNumber,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
convertToSDai(daiAmount: bigint, blockNumber: number): bigint {
|
|
101
|
+
const state = this.getState(blockNumber);
|
|
102
|
+
if (!state) throw new Error(`SDai state at ${blockNumber} does not exists`);
|
|
103
|
+
|
|
104
|
+
return (daiAmount * RAY) / calcChi(state);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
convertToDai(sdaiAmount: bigint, blockNumber: number): bigint {
|
|
108
|
+
const state = this.getState(blockNumber);
|
|
109
|
+
if (!state) throw new Error(`SDai state at ${blockNumber} does not exists`);
|
|
110
|
+
|
|
111
|
+
return (sdaiAmount * calcChi(state)) / RAY;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
2
|
+
import { IDex } from '../idex';
|
|
3
|
+
import { SDaiParams, SDaiData, SDaiFunctions } from './types';
|
|
4
|
+
import { Network, SwapSide } from '../../constants';
|
|
5
|
+
import { getDexKeysWithNetwork } from '../../utils';
|
|
6
|
+
import { Adapters, SDaiConfig } from './config';
|
|
7
|
+
import {
|
|
8
|
+
AdapterExchangeParam,
|
|
9
|
+
Address,
|
|
10
|
+
ExchangePrices,
|
|
11
|
+
Logger,
|
|
12
|
+
PoolLiquidity,
|
|
13
|
+
PoolPrices,
|
|
14
|
+
SimpleExchangeParam,
|
|
15
|
+
Token,
|
|
16
|
+
} from '../../types';
|
|
17
|
+
import { IDexHelper } from '../../dex-helper';
|
|
18
|
+
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
19
|
+
import PotAbi from '../../abi/maker-psm/pot.json';
|
|
20
|
+
import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
|
|
21
|
+
import { Interface } from 'ethers/lib/utils';
|
|
22
|
+
import { SDaiEventPool } from './sdai-pool';
|
|
23
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
24
|
+
import { SDAI_DEPOSIT_GAS_COST, SDAI_REDEEM_GAS_COST } from './constants';
|
|
25
|
+
|
|
26
|
+
export class SDai extends SimpleExchange implements IDex<SDaiData, SDaiParams> {
|
|
27
|
+
readonly hasConstantPriceLargeAmounts = true;
|
|
28
|
+
readonly isFeeOnTransferSupported = false;
|
|
29
|
+
|
|
30
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
31
|
+
getDexKeysWithNetwork(SDaiConfig);
|
|
32
|
+
|
|
33
|
+
public readonly eventPool: SDaiEventPool;
|
|
34
|
+
logger: Logger;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
protected network: Network,
|
|
38
|
+
dexKey: string,
|
|
39
|
+
protected dexHelper: IDexHelper,
|
|
40
|
+
|
|
41
|
+
readonly daiAddress: string = SDaiConfig[dexKey][network].daiAddress,
|
|
42
|
+
readonly sdaiAddress: string = SDaiConfig[dexKey][network].sdaiAddress,
|
|
43
|
+
readonly potAddress: string = SDaiConfig[dexKey][network].potAddress,
|
|
44
|
+
|
|
45
|
+
protected adapters = Adapters[network] || {},
|
|
46
|
+
protected sdaiInterface = new Interface(SavingsDaiAbi),
|
|
47
|
+
protected potInterface = new Interface(PotAbi),
|
|
48
|
+
) {
|
|
49
|
+
super(dexHelper, dexKey);
|
|
50
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
51
|
+
this.eventPool = new SDaiEventPool(
|
|
52
|
+
this.dexKey,
|
|
53
|
+
dexHelper,
|
|
54
|
+
this.potAddress,
|
|
55
|
+
this.potInterface,
|
|
56
|
+
this.logger,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
61
|
+
return this.adapters[side] || null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
isSDai(tokenAddress: Address) {
|
|
65
|
+
return this.sdaiAddress.toLowerCase() === tokenAddress.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isDai(tokenAddress: Address) {
|
|
69
|
+
return this.daiAddress.toLowerCase() === tokenAddress.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isAppropriatePair(srcToken: Token, destToken: Token) {
|
|
73
|
+
return (
|
|
74
|
+
(this.isDai(srcToken.address) && this.isSDai(destToken.address)) ||
|
|
75
|
+
(this.isDai(destToken.address) && this.isSDai(srcToken.address))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async initializePricing(blockNumber: number) {
|
|
80
|
+
await this.eventPool.initialize(blockNumber);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getPoolIdentifiers(
|
|
84
|
+
srcToken: Token,
|
|
85
|
+
destToken: Token,
|
|
86
|
+
side: SwapSide,
|
|
87
|
+
blockNumber: number,
|
|
88
|
+
): Promise<string[]> {
|
|
89
|
+
return this.isAppropriatePair(srcToken, destToken)
|
|
90
|
+
? [`${this.dexKey}_${this.sdaiAddress}`]
|
|
91
|
+
: [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async getPricesVolume(
|
|
95
|
+
srcToken: Token,
|
|
96
|
+
destToken: Token,
|
|
97
|
+
amounts: bigint[],
|
|
98
|
+
side: SwapSide,
|
|
99
|
+
blockNumber: number,
|
|
100
|
+
limitPools?: string[],
|
|
101
|
+
): Promise<null | ExchangePrices<SDaiData>> {
|
|
102
|
+
if (!this.isAppropriatePair(srcToken, destToken)) return null;
|
|
103
|
+
if (!this.eventPool.getState(blockNumber)) return null;
|
|
104
|
+
|
|
105
|
+
if (side === SwapSide.SELL) {
|
|
106
|
+
const calcSellFn = (blockNumber: number, amountIn: bigint) =>
|
|
107
|
+
this.isDai(srcToken.address)
|
|
108
|
+
? this.eventPool.convertToSDai(amountIn, blockNumber)
|
|
109
|
+
: this.eventPool.convertToDai(amountIn, blockNumber);
|
|
110
|
+
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
prices: amounts.map(amount => calcSellFn(blockNumber, amount)),
|
|
114
|
+
unit: calcSellFn(blockNumber, BI_POWS[18]),
|
|
115
|
+
gasCost: SDAI_DEPOSIT_GAS_COST,
|
|
116
|
+
exchange: this.dexKey,
|
|
117
|
+
data: { exchange: `${this.sdaiAddress}` },
|
|
118
|
+
poolAddresses: [`${this.sdaiAddress}`],
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
} else {
|
|
122
|
+
const calcBuyFn = (blockNumber: number, amountIn: bigint) =>
|
|
123
|
+
this.isDai(srcToken.address)
|
|
124
|
+
? this.eventPool.convertToDai(amountIn, blockNumber)
|
|
125
|
+
: this.eventPool.convertToSDai(amountIn, blockNumber);
|
|
126
|
+
|
|
127
|
+
return [
|
|
128
|
+
{
|
|
129
|
+
prices: amounts.map(amount => calcBuyFn(blockNumber, amount)),
|
|
130
|
+
unit: calcBuyFn(blockNumber, BI_POWS[18]),
|
|
131
|
+
gasCost: SDAI_REDEEM_GAS_COST,
|
|
132
|
+
exchange: this.dexKey,
|
|
133
|
+
data: { exchange: `${this.sdaiAddress}` },
|
|
134
|
+
poolAddresses: [`${this.sdaiAddress}`],
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
141
|
+
getCalldataGasCost(poolPrices: PoolPrices<SDaiData>): number | number[] {
|
|
142
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async getTopPoolsForToken(
|
|
146
|
+
tokenAddress: Address,
|
|
147
|
+
limit: number,
|
|
148
|
+
): Promise<PoolLiquidity[]> {
|
|
149
|
+
if (!this.isDai(tokenAddress) && !this.isSDai(tokenAddress)) return [];
|
|
150
|
+
|
|
151
|
+
return [
|
|
152
|
+
{
|
|
153
|
+
exchange: this.dexKey,
|
|
154
|
+
address: this.sdaiAddress,
|
|
155
|
+
connectorTokens: [
|
|
156
|
+
{
|
|
157
|
+
decimals: 18,
|
|
158
|
+
address: this.isDai(tokenAddress)
|
|
159
|
+
? this.sdaiAddress
|
|
160
|
+
: this.daiAddress,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async getSimpleParam(
|
|
169
|
+
srcToken: string,
|
|
170
|
+
destToken: string,
|
|
171
|
+
srcAmount: string,
|
|
172
|
+
destAmount: string,
|
|
173
|
+
data: SDaiData,
|
|
174
|
+
side: SwapSide,
|
|
175
|
+
): Promise<SimpleExchangeParam> {
|
|
176
|
+
const isSell = side === SwapSide.SELL;
|
|
177
|
+
const { exchange } = data;
|
|
178
|
+
|
|
179
|
+
let swapData: string;
|
|
180
|
+
if (this.isDai(srcToken)) {
|
|
181
|
+
swapData = this.sdaiInterface.encodeFunctionData(
|
|
182
|
+
isSell ? SDaiFunctions.deposit : SDaiFunctions.mint,
|
|
183
|
+
[isSell ? srcAmount : destAmount, this.augustusAddress],
|
|
184
|
+
);
|
|
185
|
+
} else {
|
|
186
|
+
swapData = this.sdaiInterface.encodeFunctionData(
|
|
187
|
+
isSell ? SDaiFunctions.redeem : SDaiFunctions.withdraw,
|
|
188
|
+
[
|
|
189
|
+
isSell ? srcAmount : destAmount,
|
|
190
|
+
this.augustusAddress,
|
|
191
|
+
this.augustusAddress,
|
|
192
|
+
],
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
197
|
+
srcToken,
|
|
198
|
+
srcAmount,
|
|
199
|
+
destToken,
|
|
200
|
+
destAmount,
|
|
201
|
+
swapData,
|
|
202
|
+
exchange,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
getAdapterParam(
|
|
207
|
+
srcToken: string,
|
|
208
|
+
destToken: string,
|
|
209
|
+
srcAmount: string,
|
|
210
|
+
destAmount: string,
|
|
211
|
+
data: SDaiData,
|
|
212
|
+
side: SwapSide,
|
|
213
|
+
): AdapterExchangeParam {
|
|
214
|
+
const { exchange } = data;
|
|
215
|
+
|
|
216
|
+
const payload = this.abiCoder.encodeParameter(
|
|
217
|
+
{
|
|
218
|
+
ParentStruct: {
|
|
219
|
+
toStaked: 'bool',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
toStaked: this.isDai(srcToken),
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
targetExchange: exchange,
|
|
229
|
+
payload,
|
|
230
|
+
networkFee: '0',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
|
|
3
|
+
export type SDaiData = { exchange: Address };
|
|
4
|
+
|
|
5
|
+
export type SDaiParams = {
|
|
6
|
+
sdaiAddress: Address;
|
|
7
|
+
daiAddress: Address;
|
|
8
|
+
potAddress: Address;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export enum SDaiFunctions {
|
|
12
|
+
deposit = 'deposit',
|
|
13
|
+
redeem = 'redeem',
|
|
14
|
+
withdraw = 'withdraw',
|
|
15
|
+
mint = 'mint',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SDaiPoolState = {
|
|
19
|
+
rho: string;
|
|
20
|
+
chi: string;
|
|
21
|
+
dsr: string;
|
|
22
|
+
live: boolean;
|
|
23
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Contract } from 'web3-eth-contract';
|
|
2
|
+
import { SDaiPoolState } from './types';
|
|
3
|
+
import { Interface, AbiCoder } from '@ethersproject/abi';
|
|
4
|
+
import { currentBigIntTimestampInS } from '../../utils';
|
|
5
|
+
|
|
6
|
+
const coder = new AbiCoder();
|
|
7
|
+
|
|
8
|
+
// - `dsr`: the Dai Savings Rate
|
|
9
|
+
// - `chi`: the Rate Accumulator
|
|
10
|
+
// - `rho`: time of last drip
|
|
11
|
+
export async function getOnChainState(
|
|
12
|
+
multiContract: Contract,
|
|
13
|
+
potAddress: string,
|
|
14
|
+
potInterface: Interface,
|
|
15
|
+
blockNumber: number | 'latest',
|
|
16
|
+
): Promise<SDaiPoolState> {
|
|
17
|
+
const data: { returnData: any[] } = await multiContract.methods
|
|
18
|
+
.aggregate([
|
|
19
|
+
{
|
|
20
|
+
target: potAddress,
|
|
21
|
+
callData: potInterface.encodeFunctionData('dsr', []),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
target: potAddress,
|
|
25
|
+
callData: potInterface.encodeFunctionData('chi', []),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
target: potAddress,
|
|
29
|
+
callData: potInterface.encodeFunctionData('rho', []),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
target: potAddress,
|
|
33
|
+
callData: potInterface.encodeFunctionData('live', []),
|
|
34
|
+
},
|
|
35
|
+
])
|
|
36
|
+
.call({}, blockNumber);
|
|
37
|
+
|
|
38
|
+
const [dsr, chi, rho, live] = data.returnData.map(item =>
|
|
39
|
+
coder.decode(['uint256'], item)[0].toString(),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
live: !!live,
|
|
44
|
+
dsr,
|
|
45
|
+
chi,
|
|
46
|
+
rho,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -15,8 +15,8 @@ export const WooFiV2Config: DexConfigMap<DexParams> = {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
[Network.BSC]: {
|
|
18
|
-
wooPPV2Address: '
|
|
19
|
-
wooOracleV2Address: '
|
|
18
|
+
wooPPV2Address: '0x59dE3B49314Bf5067719364A2Cb43e8525ab93FA',
|
|
19
|
+
wooOracleV2Address: '0x72dc7fa5eeb901a34173C874A7333c8d1b34bca9',
|
|
20
20
|
integrationHelperAddress: '0xAA9c15cd603428cA8ddD45e933F8EfE3Afbcc173',
|
|
21
21
|
// USDT
|
|
22
22
|
quoteToken: {
|
|
@@ -55,8 +55,8 @@ export const WooFiV2Config: DexConfigMap<DexParams> = {
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
[Network.AVALANCHE]: {
|
|
58
|
-
wooPPV2Address: '
|
|
59
|
-
wooOracleV2Address: '
|
|
58
|
+
wooPPV2Address: '0x3b3E4b4741e91aF52d0e9ad8660573E951c88524',
|
|
59
|
+
wooOracleV2Address: '0xc13843aE0D2C5ca9E0EfB93a78828446D8173d19',
|
|
60
60
|
integrationHelperAddress: '0x020630613E296c3E9b06186f630D1bF97A2B6Ad1',
|
|
61
61
|
// USDC
|
|
62
62
|
quoteToken: {
|