@paraswap/dex-lib 3.11.8-stader.3 → 3.11.8
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/balancer-v3/batch-router.json +989 -0
- package/build/abi/balancer-v3/router.json +1792 -0
- package/build/abi/balancer-v3/vault-extension.json +2834 -0
- package/build/abi/{cables/CablesMainnetRFQ.json → inception/inception-ineth-pool.json} +489 -510
- package/build/abi/inception/inception-ratio-feed.json +329 -0
- package/build/abi/inception/inception-vault.json +991 -0
- package/build/abi/permit2.json +581 -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/usual-m-usd0/usualCollateralDao.abi.json +681 -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-pool.d.ts +80 -0
- package/build/dex/balancer-v3/balancer-v3-pool.js +461 -0
- package/build/dex/balancer-v3/balancer-v3-pool.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/balancer-v3.d.ts +57 -0
- package/build/dex/balancer-v3/balancer-v3.js +383 -0
- package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
- package/build/dex/balancer-v3/config.d.ts +8 -0
- package/build/dex/balancer-v3/config.js +24 -0
- package/build/dex/balancer-v3/config.js.map +1 -0
- package/build/dex/balancer-v3/getGasCost.d.ts +2 -0
- package/build/dex/balancer-v3/getGasCost.js +41 -0
- package/build/dex/balancer-v3/getGasCost.js.map +1 -0
- package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
- package/build/dex/balancer-v3/getOnChainState.js +164 -0
- package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
- package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
- package/build/dex/balancer-v3/getPoolsApi.js +81 -0
- package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
- package/build/dex/balancer-v3/getTopPoolsApi.d.ts +13 -0
- package/build/dex/balancer-v3/getTopPoolsApi.js +62 -0
- package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
- package/build/dex/balancer-v3/optimizer.d.ts +2 -0
- package/build/dex/{trader-joe-v2.1 → balancer-v3}/optimizer.js +17 -16
- package/build/dex/balancer-v3/optimizer.js.map +1 -0
- package/build/dex/balancer-v3/stablePool.d.ts +7 -0
- package/build/dex/balancer-v3/stablePool.js +73 -0
- package/build/dex/balancer-v3/stablePool.js.map +1 -0
- package/build/dex/balancer-v3/types.d.ts +62 -0
- package/build/dex/balancer-v3/types.js +3 -0
- package/build/dex/balancer-v3/types.js.map +1 -0
- package/build/dex/balancer-v3/weightedPool.d.ts +1 -0
- package/build/dex/balancer-v3/weightedPool.js +6 -0
- package/build/dex/balancer-v3/weightedPool.js.map +1 -0
- package/build/dex/bebop/constants.d.ts +1 -1
- package/build/dex/bebop/constants.js +1 -1
- 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/inception/types.js +3 -0
- package/build/dex/inception/types.js.map +1 -0
- 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 +0 -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/pancakeswap-v3/pancakeswap-v3-pool.d.ts +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +20 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +4 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- 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-pool.d.ts +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +20 -0
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- 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-v3/uniswap-v3.js +5 -0
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/usual/types.d.ts +13 -0
- package/build/dex/usual/types.js +3 -0
- package/build/dex/usual/types.js.map +1 -0
- package/build/dex/usual/usual-bond.d.ts +18 -0
- package/build/dex/usual/usual-bond.js +52 -0
- package/build/dex/usual/usual-bond.js.map +1 -0
- 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/usual-m-usd0.d.ts +17 -0
- package/build/dex/usual/usual-m-usd0.js +51 -0
- package/build/dex/usual/usual-m-usd0.js.map +1 -0
- package/build/dex/usual/usual.d.ts +27 -0
- package/build/dex/usual/usual.js +125 -0
- package/build/dex/usual/usual.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/{stader → usual-m-usd0}/config.d.ts +1 -1
- 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/balancer-v3/balancer-v3-sepolia-pools.ts +404 -0
- package/src/dex/bebop/constants.ts +1 -1
- package/src/dex/index.ts +0 -2
- package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +30 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +10 -0
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +30 -0
- package/src/dex/uniswap-v3/uniswap-v3.ts +11 -0
- package/tests/constants-e2e.ts +0 -5
- 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/SSPM.json +0 -829
- package/build/abi/StaderOracle.json +0 -2170
- package/build/abi/integral/factory.json +0 -333
- package/build/abi/integral/oracle.json +0 -501
- package/build/abi/integral/pool.json +0 -1041
- package/build/dex/cables/cables.d.ts +0 -59
- package/build/dex/cables/cables.js +0 -614
- package/build/dex/cables/cables.js.map +0 -1
- package/build/dex/cables/config.d.ts +0 -4
- package/build/dex/cables/config.js +0 -15
- package/build/dex/cables/config.js.map +0 -1
- package/build/dex/cables/constants.d.ts +0 -20
- package/build/dex/cables/constants.js +0 -24
- package/build/dex/cables/constants.js.map +0 -1
- package/build/dex/cables/rate-fetcher.d.ts +0 -34
- package/build/dex/cables/rate-fetcher.js +0 -106
- package/build/dex/cables/rate-fetcher.js.map +0 -1
- package/build/dex/cables/types.d.ts +0 -113
- package/build/dex/cables/types.js +0 -19
- package/build/dex/cables/types.js.map +0 -1
- package/build/dex/cables/validators.d.ts +0 -5
- package/build/dex/cables/validators.js +0 -49
- package/build/dex/cables/validators.js.map +0 -1
- 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/stader/config.js +0 -14
- package/build/dex/stader/config.js.map +0 -1
- package/build/dex/stader/stader-pool.d.ts +0 -18
- package/build/dex/stader/stader-pool.js +0 -47
- package/build/dex/stader/stader-pool.js.map +0 -1
- package/build/dex/stader/stader.d.ts +0 -42
- package/build/dex/stader/stader.js +0 -141
- package/build/dex/stader/stader.js.map +0 -1
- package/build/dex/stader/types.d.ts +0 -13
- package/build/dex/stader/types.js +0 -8
- package/build/dex/stader/types.js.map +0 -1
- package/build/dex/stader/utils.d.ts +0 -4
- package/build/dex/stader/utils.js +0 -24
- package/build/dex/stader/utils.js.map +0 -1
- package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
- package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
- package/src/abi/SSPM.json +0 -829
- package/src/abi/StaderOracle.json +0 -2170
- package/src/dex/stader/config.ts +0 -13
- package/src/dex/stader/stader-e2e.test.ts +0 -74
- package/src/dex/stader/stader-events.test.ts +0 -64
- package/src/dex/stader/stader-integration.test.ts +0 -210
- package/src/dex/stader/stader-pool.ts +0 -68
- package/src/dex/stader/stader.ts +0 -208
- package/src/dex/stader/types.ts +0 -16
- package/src/dex/stader/utils.ts +0 -34
package/src/dex/stader/config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DexParams } from './types';
|
|
2
|
-
import { DexConfigMap } from '../../types';
|
|
3
|
-
import { Network, SwapSide } from '../../constants';
|
|
4
|
-
|
|
5
|
-
export const StaderConfig: DexConfigMap<DexParams> = {
|
|
6
|
-
Stader: {
|
|
7
|
-
[Network.MAINNET]: {
|
|
8
|
-
ETHx: '0xA35b1B31Ce002FBF2058D22F30f95D405200A15b',
|
|
9
|
-
SSPM: '0xcf5EA1b38380f6aF39068375516Daf40Ed70D299',
|
|
10
|
-
StaderOracle: '0xF64bAe65f6f2a5277571143A24FaaFDFC0C2a737',
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
-
import { Tokens, Holders } from '../../../tests/constants-e2e';
|
|
6
|
-
import { ContractMethod, Network, SwapSide } from '../../constants';
|
|
7
|
-
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
8
|
-
import { generateConfig } from '../../config';
|
|
9
|
-
|
|
10
|
-
describe('ETHx', () => {
|
|
11
|
-
const network = Network.MAINNET;
|
|
12
|
-
const tokens = Tokens[network];
|
|
13
|
-
const holders = Holders[network];
|
|
14
|
-
const provider = new StaticJsonRpcProvider(
|
|
15
|
-
generateConfig(network).privateHttpProvider,
|
|
16
|
-
network,
|
|
17
|
-
);
|
|
18
|
-
const dexKey = 'Stader';
|
|
19
|
-
|
|
20
|
-
const sideToContractMethods = new Map([
|
|
21
|
-
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
|
|
25
|
-
[
|
|
26
|
-
{
|
|
27
|
-
name: 'ETH',
|
|
28
|
-
sellAmount: '1000000000000000000',
|
|
29
|
-
buyAmount: '1000000000000000000',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'ETHx',
|
|
33
|
-
sellAmount: '1000000000000000000',
|
|
34
|
-
buyAmount: '1000000000000000000',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
{
|
|
39
|
-
name: 'WETH',
|
|
40
|
-
sellAmount: '1000000000000000000',
|
|
41
|
-
buyAmount: '1000000000000000000',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'ETHx',
|
|
45
|
-
sellAmount: '1000000000000000000',
|
|
46
|
-
buyAmount: '1000000000000000000',
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
sideToContractMethods.forEach((contractMethods, side) =>
|
|
52
|
-
describe(`${side}`, () => {
|
|
53
|
-
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
54
|
-
pairs.forEach(pair => {
|
|
55
|
-
describe(`${contractMethod}`, () => {
|
|
56
|
-
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
57
|
-
await testE2E(
|
|
58
|
-
tokens[pair[0].name],
|
|
59
|
-
tokens[pair[1].name],
|
|
60
|
-
holders[pair[0].name],
|
|
61
|
-
side === SwapSide.SELL ? pair[0].sellAmount : pair[0].buyAmount,
|
|
62
|
-
side,
|
|
63
|
-
dexKey,
|
|
64
|
-
contractMethod,
|
|
65
|
-
network,
|
|
66
|
-
provider,
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { ETHxEventPool } from './stader-pool';
|
|
6
|
-
import { Network } from '../../constants';
|
|
7
|
-
import { DummyDexHelper } from '../../dex-helper/index';
|
|
8
|
-
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
9
|
-
import { ETHxPoolState } from './types';
|
|
10
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
11
|
-
import { StaderConfig } from './config';
|
|
12
|
-
import StadeOracleAbi from '../../abi/StaderOracle.json';
|
|
13
|
-
|
|
14
|
-
jest.setTimeout(50 * 1000);
|
|
15
|
-
|
|
16
|
-
async function fetchETHxPoolState(
|
|
17
|
-
staderPools: ETHxEventPool,
|
|
18
|
-
blockNumber: number,
|
|
19
|
-
): Promise<ETHxPoolState> {
|
|
20
|
-
return staderPools.generateState(blockNumber);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('Stader EventPool Mainnet', function () {
|
|
24
|
-
const dexKey = 'Stader';
|
|
25
|
-
const network = Network.MAINNET;
|
|
26
|
-
const dexHelper = new DummyDexHelper(network);
|
|
27
|
-
const logger = dexHelper.getLogger(dexKey);
|
|
28
|
-
let staderPool: ETHxEventPool;
|
|
29
|
-
|
|
30
|
-
const blockNumbers: { [eventName: string]: number[] } = {
|
|
31
|
-
ExchangeRateUpdated: [
|
|
32
|
-
21341230, 21334070, 21326910, 21319802, 21312600, 21305433, 21291465,
|
|
33
|
-
21276861,
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
beforeEach(async () => {
|
|
38
|
-
staderPool = new ETHxEventPool(
|
|
39
|
-
dexKey,
|
|
40
|
-
dexHelper,
|
|
41
|
-
StaderConfig[dexKey][network].StaderOracle.toLowerCase(),
|
|
42
|
-
new Interface(StadeOracleAbi as JsonFragment[]),
|
|
43
|
-
logger,
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
Object.keys(blockNumbers).forEach((event: string) => {
|
|
48
|
-
blockNumbers[event].forEach((blockNumber: number) => {
|
|
49
|
-
it(`State after ${blockNumber}`, async function () {
|
|
50
|
-
await testEventSubscriber(
|
|
51
|
-
staderPool,
|
|
52
|
-
staderPool.addressesSubscribed,
|
|
53
|
-
(_blockNumber: number) =>
|
|
54
|
-
fetchETHxPoolState(staderPool, _blockNumber),
|
|
55
|
-
blockNumber,
|
|
56
|
-
`${dexKey}_${StaderConfig[dexKey][
|
|
57
|
-
network
|
|
58
|
-
].StaderOracle.toLowerCase()}`,
|
|
59
|
-
dexHelper.provider,
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { DummyDexHelper } from '../../dex-helper/index';
|
|
6
|
-
import { Network, SwapSide } from '../../constants';
|
|
7
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
8
|
-
import { Stader } from './stader';
|
|
9
|
-
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
10
|
-
import { Tokens } from '../../../tests/constants-e2e';
|
|
11
|
-
import { Interface, Result } from '@ethersproject/abi';
|
|
12
|
-
import SSPMABI from '../../abi/SSPM.json';
|
|
13
|
-
|
|
14
|
-
function getReaderCalldata(
|
|
15
|
-
exchangeAddress: string,
|
|
16
|
-
readerIface: Interface,
|
|
17
|
-
poolAddress: string,
|
|
18
|
-
amounts: bigint[],
|
|
19
|
-
funcName: string,
|
|
20
|
-
) {
|
|
21
|
-
return amounts.map(amount => ({
|
|
22
|
-
target: exchangeAddress,
|
|
23
|
-
callData: readerIface.encodeFunctionData(funcName, [amount]),
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function decodeReaderResult(
|
|
28
|
-
results: Result,
|
|
29
|
-
readerIface: Interface,
|
|
30
|
-
funcName: string,
|
|
31
|
-
) {
|
|
32
|
-
return results.map(result => {
|
|
33
|
-
return BigInt(result);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function checkOnChainPricing(
|
|
38
|
-
stader: Stader,
|
|
39
|
-
funcName: string,
|
|
40
|
-
poolAddress: string,
|
|
41
|
-
blockNumber: number,
|
|
42
|
-
prices: bigint[],
|
|
43
|
-
amounts: bigint[],
|
|
44
|
-
dexHelper: DummyDexHelper,
|
|
45
|
-
srcToken: string,
|
|
46
|
-
) {
|
|
47
|
-
const readerIface = new Interface(SSPMABI);
|
|
48
|
-
const SSPMAddress = stader.SSPM_Address;
|
|
49
|
-
|
|
50
|
-
const readerCallData = getReaderCalldata(
|
|
51
|
-
SSPMAddress,
|
|
52
|
-
readerIface,
|
|
53
|
-
poolAddress,
|
|
54
|
-
amounts.slice(1),
|
|
55
|
-
funcName,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const readerResult = (
|
|
59
|
-
await dexHelper.multiContract.methods
|
|
60
|
-
.aggregate(readerCallData)
|
|
61
|
-
.call({}, blockNumber)
|
|
62
|
-
).returnData;
|
|
63
|
-
|
|
64
|
-
const expectedPrices = [0n].concat(
|
|
65
|
-
decodeReaderResult(readerResult, readerIface, funcName),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(prices).toEqual(expectedPrices);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe('Stader', function () {
|
|
72
|
-
const dexKey = 'Stader';
|
|
73
|
-
let blockNumber: number;
|
|
74
|
-
let stader: Stader;
|
|
75
|
-
|
|
76
|
-
describe('Mainnet', () => {
|
|
77
|
-
const network = Network.MAINNET;
|
|
78
|
-
const dexHelper = new DummyDexHelper(network);
|
|
79
|
-
|
|
80
|
-
const tokens = Tokens[network];
|
|
81
|
-
|
|
82
|
-
beforeAll(async () => {
|
|
83
|
-
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
84
|
-
stader = new Stader(network, dexKey, dexHelper);
|
|
85
|
-
if (stader.initializePricing) {
|
|
86
|
-
await stader.initializePricing(blockNumber);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('getPoolIdentifiers and getPricesVolume ETH -> ETHx SELL', async () => {
|
|
91
|
-
const srcTokenSymbol = 'ETH';
|
|
92
|
-
const destTokenSymbol = 'ETHx';
|
|
93
|
-
|
|
94
|
-
const amountsForSell = [
|
|
95
|
-
0n,
|
|
96
|
-
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
97
|
-
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
98
|
-
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
99
|
-
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
100
|
-
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
101
|
-
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
102
|
-
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
103
|
-
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
104
|
-
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
105
|
-
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
const pools = await stader.getPoolIdentifiers(
|
|
109
|
-
tokens[srcTokenSymbol],
|
|
110
|
-
tokens[destTokenSymbol],
|
|
111
|
-
SwapSide.SELL,
|
|
112
|
-
blockNumber,
|
|
113
|
-
);
|
|
114
|
-
console.log(
|
|
115
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
|
|
116
|
-
pools,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
120
|
-
|
|
121
|
-
const poolPrices = await stader.getPricesVolume(
|
|
122
|
-
tokens[srcTokenSymbol],
|
|
123
|
-
tokens[destTokenSymbol],
|
|
124
|
-
amountsForSell,
|
|
125
|
-
SwapSide.SELL,
|
|
126
|
-
blockNumber,
|
|
127
|
-
pools,
|
|
128
|
-
);
|
|
129
|
-
console.log(
|
|
130
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
|
|
131
|
-
poolPrices,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
expect(poolPrices).not.toBeNull();
|
|
135
|
-
checkPoolPrices(poolPrices!, amountsForSell, SwapSide.SELL, dexKey);
|
|
136
|
-
|
|
137
|
-
// Check if onchain pricing equals to calculated ones
|
|
138
|
-
await checkOnChainPricing(
|
|
139
|
-
stader,
|
|
140
|
-
'previewDeposit',
|
|
141
|
-
poolPrices![0].poolAddresses![0],
|
|
142
|
-
blockNumber,
|
|
143
|
-
poolPrices![0].prices,
|
|
144
|
-
amountsForSell,
|
|
145
|
-
dexHelper,
|
|
146
|
-
tokens[srcTokenSymbol].address,
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('getPoolIdentifiers and getPricesVolume WETH -> ETHx SELL', async () => {
|
|
151
|
-
const srcTokenSymbol = 'WETH';
|
|
152
|
-
const destTokenSymbol = 'ETHx';
|
|
153
|
-
|
|
154
|
-
const amountsForSell = [
|
|
155
|
-
0n,
|
|
156
|
-
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
157
|
-
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
158
|
-
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
159
|
-
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
160
|
-
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
161
|
-
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
162
|
-
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
163
|
-
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
164
|
-
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
165
|
-
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
166
|
-
];
|
|
167
|
-
|
|
168
|
-
const pools = await stader.getPoolIdentifiers(
|
|
169
|
-
tokens[srcTokenSymbol],
|
|
170
|
-
tokens[destTokenSymbol],
|
|
171
|
-
SwapSide.SELL,
|
|
172
|
-
blockNumber,
|
|
173
|
-
);
|
|
174
|
-
console.log(
|
|
175
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
|
|
176
|
-
pools,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
180
|
-
|
|
181
|
-
const poolPrices = await stader.getPricesVolume(
|
|
182
|
-
tokens[srcTokenSymbol],
|
|
183
|
-
tokens[destTokenSymbol],
|
|
184
|
-
amountsForSell,
|
|
185
|
-
SwapSide.SELL,
|
|
186
|
-
blockNumber,
|
|
187
|
-
pools,
|
|
188
|
-
);
|
|
189
|
-
console.log(
|
|
190
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
|
|
191
|
-
poolPrices,
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
expect(poolPrices).not.toBeNull();
|
|
195
|
-
checkPoolPrices(poolPrices!, amountsForSell, SwapSide.SELL, dexKey);
|
|
196
|
-
|
|
197
|
-
// Check if onchain pricing equals to calculated ones
|
|
198
|
-
await checkOnChainPricing(
|
|
199
|
-
stader,
|
|
200
|
-
'previewDeposit',
|
|
201
|
-
poolPrices![0].poolAddresses![0],
|
|
202
|
-
blockNumber,
|
|
203
|
-
poolPrices![0].prices,
|
|
204
|
-
amountsForSell,
|
|
205
|
-
dexHelper,
|
|
206
|
-
tokens[srcTokenSymbol].address,
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
3
|
-
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
4
|
-
import { Address, Log, Logger } from '../../types';
|
|
5
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
6
|
-
import { catchParseLogError } from '../../utils';
|
|
7
|
-
import { ETHxPoolState } from './types';
|
|
8
|
-
import { getOnChainStateETHx } from './utils';
|
|
9
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
10
|
-
|
|
11
|
-
export class ETHxEventPool extends StatefulEventSubscriber<ETHxPoolState> {
|
|
12
|
-
decoder = (log: Log) => this.poolInterface.parseLog(log);
|
|
13
|
-
DECIMALS = 1000000000000000000n;
|
|
14
|
-
addressesSubscribed: string[];
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
parentName: string,
|
|
18
|
-
protected dexHelper: IDexHelper,
|
|
19
|
-
private poolAddress: Address,
|
|
20
|
-
private poolInterface: Interface,
|
|
21
|
-
logger: Logger,
|
|
22
|
-
) {
|
|
23
|
-
super(parentName, 'ETHx', dexHelper, logger);
|
|
24
|
-
this.addressesSubscribed = [poolAddress];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected processLog(
|
|
28
|
-
state: DeepReadonly<ETHxPoolState>,
|
|
29
|
-
log: Readonly<Log>,
|
|
30
|
-
): DeepReadonly<ETHxPoolState> | null {
|
|
31
|
-
try {
|
|
32
|
-
const event = this.decoder(log);
|
|
33
|
-
if (event.name === 'ExchangeRateUpdated') {
|
|
34
|
-
const totalEth = BigInt(event.args.totalEth);
|
|
35
|
-
const ethxSupply = BigInt(event.args.ethxSupply);
|
|
36
|
-
return {
|
|
37
|
-
totalETHBalance: totalEth,
|
|
38
|
-
totalETHXSupply: ethxSupply,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
} catch (e) {
|
|
42
|
-
catchParseLogError(e, this.logger);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async generateState(
|
|
49
|
-
blockNumber: number,
|
|
50
|
-
): Promise<DeepReadonly<ETHxPoolState>> {
|
|
51
|
-
const state = await getOnChainStateETHx(
|
|
52
|
-
this.dexHelper.multiContract,
|
|
53
|
-
this.poolAddress,
|
|
54
|
-
this.poolInterface,
|
|
55
|
-
blockNumber,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getPrice(blockNumber: number, ethAmount: bigint): bigint {
|
|
62
|
-
const state = this.getState(blockNumber);
|
|
63
|
-
if (!state) throw new Error('Cannot compute price');
|
|
64
|
-
const { totalETHBalance, totalETHXSupply } = state;
|
|
65
|
-
|
|
66
|
-
return (ethAmount * totalETHXSupply) / totalETHBalance;
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/dex/stader/stader.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import { NumberAsString, SwapSide } from '@paraswap/core';
|
|
3
|
-
import {
|
|
4
|
-
AdapterExchangeParam,
|
|
5
|
-
Address,
|
|
6
|
-
DexExchangeParam,
|
|
7
|
-
ExchangePrices,
|
|
8
|
-
Logger,
|
|
9
|
-
PoolLiquidity,
|
|
10
|
-
PoolPrices,
|
|
11
|
-
Token,
|
|
12
|
-
TransferFeeParams,
|
|
13
|
-
} from '../../types';
|
|
14
|
-
import { IDexTxBuilder } from '../idex';
|
|
15
|
-
import SSPMAbi from '../../abi/SSPM.json';
|
|
16
|
-
import StadeOracleAbi from '../../abi/StaderOracle.json';
|
|
17
|
-
import { ETHER_ADDRESS, Network, NULL_ADDRESS } from '../../constants';
|
|
18
|
-
import { IDexHelper } from '../../dex-helper';
|
|
19
|
-
import { SimpleExchange } from '../simple-exchange';
|
|
20
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
21
|
-
import { AsyncOrSync } from 'ts-essentials';
|
|
22
|
-
import { ETHxEventPool } from './stader-pool';
|
|
23
|
-
import { StaderData, SSPMFunctions } from './types';
|
|
24
|
-
import { StaderConfig } from './config';
|
|
25
|
-
import { WethFunctions } from '../weth/types';
|
|
26
|
-
import ERC20ABI from '../../abi/erc20.json';
|
|
27
|
-
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
28
|
-
import _ from 'lodash';
|
|
29
|
-
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
30
|
-
import { getDexKeysWithNetwork, isETHAddress } from '../../utils';
|
|
31
|
-
|
|
32
|
-
export class Stader
|
|
33
|
-
extends SimpleExchange
|
|
34
|
-
implements IDexTxBuilder<StaderData, any>
|
|
35
|
-
{
|
|
36
|
-
static dexKeys = ['Stader'];
|
|
37
|
-
ETHxAddress: string;
|
|
38
|
-
SSPM_Address: string;
|
|
39
|
-
SSPMInterface: Interface;
|
|
40
|
-
StaderOracleAddress: string;
|
|
41
|
-
StaderOracleInterface: Interface;
|
|
42
|
-
erc20Interface: Interface;
|
|
43
|
-
needWrapNative = false;
|
|
44
|
-
ethxPool: ETHxEventPool;
|
|
45
|
-
logger: Logger;
|
|
46
|
-
hasConstantPriceLargeAmounts: boolean = true;
|
|
47
|
-
|
|
48
|
-
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
49
|
-
getDexKeysWithNetwork(_.pick(StaderConfig, ['Stader']));
|
|
50
|
-
|
|
51
|
-
constructor(
|
|
52
|
-
protected network: Network,
|
|
53
|
-
dexKey: string,
|
|
54
|
-
dexHelper: IDexHelper,
|
|
55
|
-
protected config = StaderConfig[dexKey][network],
|
|
56
|
-
) {
|
|
57
|
-
super(dexHelper, 'Stader');
|
|
58
|
-
this.network = dexHelper.config.data.network;
|
|
59
|
-
this.ETHxAddress = this.config.ETHx.toLowerCase();
|
|
60
|
-
this.SSPM_Address = this.config.SSPM.toLowerCase();
|
|
61
|
-
this.SSPMInterface = new Interface(SSPMAbi as JsonFragment[]);
|
|
62
|
-
this.StaderOracleAddress = this.config.StaderOracle.toLowerCase();
|
|
63
|
-
this.StaderOracleInterface = new Interface(
|
|
64
|
-
StadeOracleAbi as JsonFragment[],
|
|
65
|
-
);
|
|
66
|
-
this.erc20Interface = new Interface(ERC20ABI);
|
|
67
|
-
this.logger = dexHelper.getLogger(this.dexKey);
|
|
68
|
-
this.ethxPool = new ETHxEventPool(
|
|
69
|
-
this.dexKey,
|
|
70
|
-
dexHelper,
|
|
71
|
-
this.StaderOracleAddress,
|
|
72
|
-
this.StaderOracleInterface,
|
|
73
|
-
this.logger,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getAdapterParam(
|
|
78
|
-
srcToken: Address,
|
|
79
|
-
destToken: Address,
|
|
80
|
-
srcAmount: NumberAsString,
|
|
81
|
-
destAmount: NumberAsString,
|
|
82
|
-
data: StaderData,
|
|
83
|
-
side: SwapSide,
|
|
84
|
-
): AdapterExchangeParam {
|
|
85
|
-
return {
|
|
86
|
-
targetExchange: NULL_ADDRESS,
|
|
87
|
-
payload: '0x',
|
|
88
|
-
networkFee: '0',
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async initializePricing(blockNumber: number) {
|
|
93
|
-
await this.ethxPool.initialize(blockNumber);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async getPricesVolume(
|
|
97
|
-
srcToken: Token,
|
|
98
|
-
destToken: Token,
|
|
99
|
-
amountsIn: bigint[],
|
|
100
|
-
side: SwapSide,
|
|
101
|
-
blockNumber: number,
|
|
102
|
-
limitPools?: string[] | undefined,
|
|
103
|
-
transferFees?: TransferFeeParams | undefined,
|
|
104
|
-
isFirstSwap?: boolean | undefined,
|
|
105
|
-
): Promise<ExchangePrices<StaderData> | null> {
|
|
106
|
-
if (side === SwapSide.BUY) return null;
|
|
107
|
-
if (!this.isEligibleSwap(srcToken, destToken)) return null;
|
|
108
|
-
|
|
109
|
-
const pool = this.ethxPool;
|
|
110
|
-
if (!pool.getState(blockNumber)) return null;
|
|
111
|
-
|
|
112
|
-
const unitIn = BI_POWS[18];
|
|
113
|
-
const unitOut = pool.getPrice(blockNumber, unitIn);
|
|
114
|
-
const amountsOut = amountsIn.map(amountIn =>
|
|
115
|
-
pool.getPrice(blockNumber, amountIn),
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
return [
|
|
119
|
-
{
|
|
120
|
-
prices: amountsOut,
|
|
121
|
-
unit: unitOut,
|
|
122
|
-
data: {},
|
|
123
|
-
exchange: this.dexKey,
|
|
124
|
-
poolIdentifier: `${ETHER_ADDRESS}_${destToken.address}`.toLowerCase(),
|
|
125
|
-
gasCost: 120_000,
|
|
126
|
-
poolAddresses: [destToken.address],
|
|
127
|
-
},
|
|
128
|
-
];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
isEligibleSwap(srcToken: Token | string, destToken: Token | string): boolean {
|
|
132
|
-
const srcTokenAddress = (
|
|
133
|
-
typeof srcToken === 'string' ? srcToken : srcToken.address
|
|
134
|
-
).toLowerCase();
|
|
135
|
-
const destTokenAddress = (
|
|
136
|
-
typeof destToken === 'string' ? destToken : destToken.address
|
|
137
|
-
).toLowerCase();
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
(isETHAddress(srcTokenAddress) || this.isWETH(srcTokenAddress)) &&
|
|
141
|
-
destTokenAddress === this.ETHxAddress
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getDexParam(
|
|
146
|
-
srcToken: Address,
|
|
147
|
-
_destToken: Address,
|
|
148
|
-
srcAmount: NumberAsString,
|
|
149
|
-
_destAmount: NumberAsString,
|
|
150
|
-
_recipient: Address,
|
|
151
|
-
_data: StaderData,
|
|
152
|
-
_side: SwapSide,
|
|
153
|
-
): DexExchangeParam {
|
|
154
|
-
if (_side === SwapSide.BUY) throw new Error(`Buy not supported`);
|
|
155
|
-
|
|
156
|
-
const swapData = this.SSPMInterface.encodeFunctionData(
|
|
157
|
-
SSPMFunctions.deposit,
|
|
158
|
-
[_recipient],
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
needWrapNative: this.needWrapNative,
|
|
163
|
-
dexFuncHasRecipient: true,
|
|
164
|
-
exchangeData: swapData,
|
|
165
|
-
targetExchange: this.config.SSPM.toLowerCase(),
|
|
166
|
-
preSwapUnwrapCalldata: this.isWETH(srcToken)
|
|
167
|
-
? this.erc20Interface.encodeFunctionData(WethFunctions.withdraw, [
|
|
168
|
-
srcAmount,
|
|
169
|
-
])
|
|
170
|
-
: undefined,
|
|
171
|
-
returnAmountPos:
|
|
172
|
-
_side === SwapSide.SELL
|
|
173
|
-
? extractReturnAmountPosition(
|
|
174
|
-
this.SSPMInterface,
|
|
175
|
-
SSPMFunctions.deposit,
|
|
176
|
-
)
|
|
177
|
-
: undefined,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async getPoolIdentifiers(
|
|
182
|
-
srcToken: Token,
|
|
183
|
-
destToken: Token,
|
|
184
|
-
side: SwapSide,
|
|
185
|
-
blockNumber: number,
|
|
186
|
-
): Promise<string[]> {
|
|
187
|
-
if (side === SwapSide.BUY) return [];
|
|
188
|
-
|
|
189
|
-
if (!this.isEligibleSwap(srcToken, destToken)) return [];
|
|
190
|
-
|
|
191
|
-
return [`${ETHER_ADDRESS}_${destToken.address}`.toLowerCase()];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getCalldataGasCost(poolPrices: PoolPrices<StaderData>): number | number[] {
|
|
195
|
-
return CALLDATA_GAS_COST.DEX_OVERHEAD + CALLDATA_GAS_COST.LENGTH_SMALL;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
getTopPoolsForToken(
|
|
203
|
-
tokenAddress: string,
|
|
204
|
-
limit: number,
|
|
205
|
-
): AsyncOrSync<PoolLiquidity[]> {
|
|
206
|
-
return [];
|
|
207
|
-
}
|
|
208
|
-
}
|
package/src/dex/stader/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type ETHxPoolState = {
|
|
2
|
-
totalETHBalance: bigint;
|
|
3
|
-
totalETHXSupply: bigint;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type StaderData = {};
|
|
7
|
-
|
|
8
|
-
export type DexParams = {
|
|
9
|
-
ETHx: string;
|
|
10
|
-
SSPM: string;
|
|
11
|
-
StaderOracle: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export enum SSPMFunctions {
|
|
15
|
-
deposit = 'deposit',
|
|
16
|
-
}
|
package/src/dex/stader/utils.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Contract } from 'web3-eth-contract';
|
|
2
|
-
import { ETHxPoolState } from './types';
|
|
3
|
-
import { Interface, AbiCoder } from '@ethersproject/abi';
|
|
4
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
5
|
-
|
|
6
|
-
export async function getOnChainStateETHx(
|
|
7
|
-
multiContract: Contract,
|
|
8
|
-
poolAddress: string,
|
|
9
|
-
poolInterface: Interface,
|
|
10
|
-
blockNumber: number | 'latest',
|
|
11
|
-
): Promise<ETHxPoolState> {
|
|
12
|
-
const coder = new AbiCoder();
|
|
13
|
-
const data: { returnData: any[] } = await multiContract.methods
|
|
14
|
-
.aggregate([
|
|
15
|
-
{
|
|
16
|
-
target: poolAddress,
|
|
17
|
-
callData: poolInterface.encodeFunctionData('getExchangeRate', []),
|
|
18
|
-
},
|
|
19
|
-
])
|
|
20
|
-
.call({}, blockNumber);
|
|
21
|
-
|
|
22
|
-
const decodedData = coder.decode(
|
|
23
|
-
['uint256', 'uint256', 'uint256'],
|
|
24
|
-
data.returnData[0],
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const totalETHBalance = BigInt(decodedData[1].toString());
|
|
28
|
-
const totalETHXSupply = BigInt(decodedData[2].toString());
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
totalETHBalance,
|
|
32
|
-
totalETHXSupply,
|
|
33
|
-
};
|
|
34
|
-
}
|