@paraswap/dex-lib 3.8.37 → 3.8.39-1701-1507
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/USDM.json +807 -0
- package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/build/abi/cables/CablesMainnetRFQ.json +1073 -0
- package/build/abi/wUSDM.json +757 -0
- package/build/config.js +16 -9
- package/build/config.js.map +1 -1
- package/build/dex/aave-v2/aave-v2.d.ts +1 -0
- package/build/dex/aave-v2/aave-v2.js +1 -0
- package/build/dex/aave-v2/aave-v2.js.map +1 -1
- package/build/dex/aave-v3/aave-v3.d.ts +1 -0
- package/build/dex/aave-v3/aave-v3.js +1 -0
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +1 -0
- package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
- package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
- package/build/dex/bancor/bancor.d.ts +1 -0
- package/build/dex/bancor/bancor.js +1 -0
- package/build/dex/bancor/bancor.js.map +1 -1
- package/build/dex/bebop/bebop.d.ts +55 -0
- package/build/dex/bebop/bebop.js +524 -0
- package/build/dex/bebop/bebop.js.map +1 -0
- package/build/dex/bebop/config.d.ts +3 -0
- package/build/dex/bebop/config.js +38 -0
- package/build/dex/bebop/config.js.map +1 -0
- package/build/dex/bebop/constants.d.ts +9 -0
- package/build/dex/bebop/constants.js +13 -0
- package/build/dex/bebop/constants.js.map +1 -0
- package/build/dex/bebop/rate-fetcher.d.ts +22 -0
- package/build/dex/bebop/rate-fetcher.js +80 -0
- package/build/dex/bebop/rate-fetcher.js.map +1 -0
- package/build/dex/bebop/types.d.ts +76 -0
- package/build/dex/bebop/types.js +3 -0
- package/build/dex/bebop/types.js.map +1 -0
- package/build/dex/bebop/validators.d.ts +4 -0
- package/build/dex/bebop/validators.js +42 -0
- package/build/dex/bebop/validators.js.map +1 -0
- package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
- package/build/dex/bebop/websocket-fetcher.js +87 -0
- package/build/dex/bebop/websocket-fetcher.js.map +1 -0
- package/build/dex/cables/cables.d.ts +64 -0
- package/build/dex/cables/cables.js +445 -0
- package/build/dex/cables/cables.js.map +1 -0
- package/build/dex/cables/config.d.ts +4 -0
- package/build/dex/cables/config.js +15 -0
- package/build/dex/cables/config.js.map +1 -0
- package/build/dex/cables/constants.d.ts +19 -0
- package/build/dex/cables/constants.js +26 -0
- package/build/dex/cables/constants.js.map +1 -0
- package/build/dex/cables/rate-fetcher.d.ts +34 -0
- package/build/dex/cables/rate-fetcher.js +117 -0
- package/build/dex/cables/rate-fetcher.js.map +1 -0
- package/build/dex/cables/types.d.ts +106 -0
- package/build/dex/cables/types.js +12 -0
- package/build/dex/cables/types.js.map +1 -0
- package/build/dex/cables/validators.d.ts +5 -0
- package/build/dex/cables/validators.js +49 -0
- package/build/dex/cables/validators.js.map +1 -0
- package/build/dex/compound/compound.d.ts +1 -0
- package/build/dex/compound/compound.js +1 -0
- package/build/dex/compound/compound.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +1 -0
- package/build/dex/curve-v1/curve-v1.js +1 -0
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/dodo-v1/dodo-v1.d.ts +1 -0
- package/build/dex/dodo-v1/dodo-v1.js +1 -0
- package/build/dex/dodo-v1/dodo-v1.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +6 -4
- package/build/dex/hashflow/hashflow.js +183 -29
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/types.d.ts +2 -0
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/idex.d.ts +8 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.d.ts +1 -0
- package/build/dex/jarvis-v6/jarvis-v6.js +1 -0
- package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
- package/build/dex/lido/lido.d.ts +1 -0
- package/build/dex/lido/lido.js +1 -0
- package/build/dex/lido/lido.js.map +1 -1
- package/build/dex/lite-psm/lite-psm.d.ts +1 -0
- package/build/dex/lite-psm/lite-psm.js +1 -0
- package/build/dex/lite-psm/lite-psm.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.d.ts +1 -0
- package/build/dex/maker-psm/maker-psm.js +1 -0
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/nerve/nerve.d.ts +1 -0
- package/build/dex/nerve/nerve.js +1 -0
- package/build/dex/nerve/nerve.js.map +1 -1
- package/build/dex/polygon-migrator/polygon-migrator.d.ts +1 -0
- package/build/dex/polygon-migrator/polygon-migrator.js +1 -0
- package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +3 -1
- package/build/dex/simple-exchange.js +1 -0
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/smoothy/smoothy.d.ts +1 -0
- package/build/dex/smoothy/smoothy.js +1 -0
- package/build/dex/smoothy/smoothy.js.map +1 -1
- package/build/dex/spark/config.js +25 -0
- package/build/dex/spark/config.js.map +1 -1
- package/build/dex/spark/scripts/validate-state.js +1 -1
- package/build/dex/spark/scripts/validate-state.js.map +1 -1
- package/build/dex/spark/spark-sdai-pool.d.ts +7 -3
- package/build/dex/spark/spark-sdai-pool.js +24 -28
- package/build/dex/spark/spark-sdai-pool.js.map +1 -1
- package/build/dex/spark/spark.d.ts +11 -5
- package/build/dex/spark/spark.js +47 -31
- package/build/dex/spark/spark.js.map +1 -1
- package/build/dex/spark/types.d.ts +6 -0
- package/build/dex/spark/types.js.map +1 -1
- package/build/dex/spark/utils.d.ts +3 -1
- package/build/dex/spark/utils.js +43 -7
- package/build/dex/spark/utils.js.map +1 -1
- package/build/dex/stable-pool/stable-pool.d.ts +3 -2
- package/build/dex/stable-pool/stable-pool.js +2 -1
- package/build/dex/stable-pool/stable-pool.js.map +1 -1
- package/build/dex/swaap-v2/swaap-v2.d.ts +5 -3
- package/build/dex/swaap-v2/swaap-v2.js +112 -21
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swaap-v2/types.d.ts +2 -0
- package/build/dex/swaap-v2/types.js.map +1 -1
- package/build/dex/trader-joe-v2.1/base.d.ts +1 -0
- package/build/dex/trader-joe-v2.1/base.js +1 -0
- package/build/dex/trader-joe-v2.1/base.js.map +1 -1
- package/build/dex/weth/weth.d.ts +1 -0
- package/build/dex/weth/weth.js +1 -0
- package/build/dex/weth/weth.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/dex/wusdm/config.d.ts +3 -0
- package/build/dex/wusdm/config.js +29 -0
- package/build/dex/wusdm/config.js.map +1 -0
- package/build/dex/wusdm/types.d.ts +10 -0
- package/build/dex/wusdm/types.js +3 -0
- package/build/dex/wusdm/types.js.map +1 -0
- package/build/dex/wusdm/wusdm.d.ts +39 -0
- package/build/dex/wusdm/wusdm.js +212 -0
- package/build/dex/wusdm/wusdm.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.d.ts +3 -3
- package/build/executor/Executor01BytecodeBuilder.js +65 -16
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.d.ts +4 -4
- package/build/executor/Executor02BytecodeBuilder.js +65 -18
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.d.ts +2 -2
- package/build/executor/Executor03BytecodeBuilder.js +52 -8
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.d.ts +5 -4
- package/build/executor/ExecutorBytecodeBuilder.js +4 -4
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorDetector.js +2 -1
- package/build/executor/ExecutorDetector.js.map +1 -1
- package/build/executor/types.d.ts +1 -0
- package/build/executor/types.js +1 -0
- package/build/executor/types.js.map +1 -1
- package/build/generic-swap-transaction-builder.d.ts +2 -0
- package/build/generic-swap-transaction-builder.js +49 -11
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +3 -1
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/lib/fetcher/wsFetcher.d.ts +35 -0
- package/build/lib/fetcher/wsFetcher.js +87 -0
- package/build/lib/fetcher/wsFetcher.js.map +1 -0
- package/build/router/simpleswap.js +51 -13
- package/build/router/simpleswap.js.map +1 -1
- package/build/types.d.ts +2 -0
- package/package.json +4 -2
- package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/src/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/src/config.ts +17 -9
- package/src/dex/aave-v2/aave-v2.ts +2 -0
- package/src/dex/aave-v3/aave-v3.ts +2 -0
- package/src/dex/aave-v3-stata/aave-v3-stata.ts +2 -0
- package/src/dex/bancor/bancor.ts +2 -0
- package/src/dex/bebop/bebop-e2e.test.ts +195 -0
- package/src/dex/bebop/bebop-integration.test.ts +170 -0
- package/src/dex/bebop/bebop.ts +732 -0
- package/src/dex/bebop/config.ts +37 -0
- package/src/dex/bebop/constants.ts +9 -0
- package/src/dex/bebop/rate-fetcher.ts +138 -0
- package/src/dex/bebop/types.ts +81 -0
- package/src/dex/bebop/validators.ts +43 -0
- package/src/dex/compound/compound.ts +2 -0
- package/src/dex/curve-v1/curve-v1.ts +2 -0
- package/src/dex/dodo-v1/dodo-v1.ts +2 -0
- package/src/dex/hashflow/hashflow-e2e.test.ts +281 -28
- package/src/dex/hashflow/hashflow.ts +285 -54
- package/src/dex/hashflow/types.ts +2 -0
- package/src/dex/idex.ts +18 -1
- package/src/dex/index.ts +2 -0
- package/src/dex/jarvis-v6/jarvis-v6.ts +2 -0
- package/src/dex/lido/lido.ts +2 -0
- package/src/dex/lite-psm/lite-psm.ts +2 -0
- package/src/dex/maker-psm/maker-psm.ts +2 -0
- package/src/dex/nerve/nerve.ts +2 -0
- package/src/dex/polygon-migrator/polygon-migrator.ts +2 -0
- package/src/dex/simple-exchange.ts +4 -2
- package/src/dex/smoothy/smoothy.ts +2 -0
- package/src/dex/spark/config.ts +24 -0
- package/src/dex/spark/scripts/validate-state.ts +1 -0
- package/src/dex/spark/spark-e2e.test.ts +25 -21
- package/src/dex/spark/spark-events.test.ts +77 -62
- package/src/dex/spark/spark-integration.test.ts +290 -7
- package/src/dex/spark/spark-sdai-pool.ts +22 -19
- package/src/dex/spark/spark.ts +64 -36
- package/src/dex/spark/types.ts +6 -0
- package/src/dex/spark/utils.ts +83 -19
- package/src/dex/stable-pool/stable-pool.ts +4 -1
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +13 -13
- package/src/dex/swaap-v2/swaap-v2.ts +217 -32
- package/src/dex/swaap-v2/types.ts +2 -0
- package/src/dex/trader-joe-v2.1/base.ts +2 -0
- package/src/dex/weth/weth.ts +2 -0
- package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
- package/src/executor/Executor01BytecodeBuilder.ts +105 -11
- package/src/executor/Executor02BytecodeBuilder.ts +95 -8
- package/src/executor/Executor03BytecodeBuilder.ts +89 -5
- package/src/executor/ExecutorBytecodeBuilder.ts +6 -0
- package/src/executor/ExecutorDetector.ts +2 -1
- package/src/executor/types.ts +1 -0
- package/src/generic-swap-transaction-builder.ts +96 -24
- package/src/implementations/local-paraswap-sdk.ts +21 -10
- package/src/lib/fetcher/wsFetcher.ts +126 -0
- package/src/router/simpleswap.ts +94 -18
- package/src/types.ts +2 -0
- package/tests/constants-e2e.ts +7 -2
- package/tests/utils-e2e.ts +308 -2
package/src/dex/spark/spark.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { SimpleExchange } from '../simple-exchange';
|
|
2
2
|
import { Context, IDex } from '../idex';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
SparkParams,
|
|
5
|
+
SparkData,
|
|
6
|
+
SparkSDaiFunctions,
|
|
7
|
+
SparkSDaiPoolState,
|
|
8
|
+
} from './types';
|
|
4
9
|
import { Network, SwapSide } from '../../constants';
|
|
5
10
|
import { getDexKeysWithNetwork } from '../../utils';
|
|
6
11
|
import { Adapters, SDaiConfig } from './config';
|
|
@@ -21,7 +26,7 @@ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
|
21
26
|
import PotAbi from '../../abi/maker-psm/pot.json';
|
|
22
27
|
import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
|
|
23
28
|
import { Interface } from 'ethers/lib/utils';
|
|
24
|
-
import { SparkSDaiEventPool } from './spark-sdai-pool';
|
|
29
|
+
import { calcChi, RAY, SparkSDaiEventPool } from './spark-sdai-pool';
|
|
25
30
|
import { BI_POWS } from '../../bigint-constants';
|
|
26
31
|
import { SDAI_DEPOSIT_GAS_COST, SDAI_REDEEM_GAS_COST } from './constants';
|
|
27
32
|
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
@@ -33,6 +38,8 @@ export class Spark
|
|
|
33
38
|
readonly hasConstantPriceLargeAmounts = true;
|
|
34
39
|
readonly isFeeOnTransferSupported = false;
|
|
35
40
|
|
|
41
|
+
needWrapNative = false;
|
|
42
|
+
|
|
36
43
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
37
44
|
getDexKeysWithNetwork(SDaiConfig);
|
|
38
45
|
|
|
@@ -42,25 +49,29 @@ export class Spark
|
|
|
42
49
|
constructor(
|
|
43
50
|
protected network: Network,
|
|
44
51
|
dexKey: string,
|
|
45
|
-
|
|
52
|
+
readonly dexHelper: IDexHelper,
|
|
46
53
|
|
|
47
54
|
readonly daiAddress: string = SDaiConfig[dexKey][network].daiAddress,
|
|
48
55
|
readonly sdaiAddress: string = SDaiConfig[dexKey][network].sdaiAddress,
|
|
49
56
|
readonly potAddress: string = SDaiConfig[dexKey][network].potAddress,
|
|
57
|
+
readonly abiInterface: Interface = SDaiConfig[dexKey][network]
|
|
58
|
+
.poolInterface,
|
|
50
59
|
|
|
51
60
|
protected adapters = Adapters[network] || {},
|
|
52
61
|
protected sdaiInterface = new Interface(SavingsDaiAbi),
|
|
53
|
-
protected potInterface = new Interface(PotAbi),
|
|
54
62
|
) {
|
|
55
63
|
super(dexHelper, dexKey);
|
|
56
64
|
this.logger = dexHelper.getLogger(dexKey);
|
|
57
65
|
this.eventPool = new SparkSDaiEventPool(
|
|
58
66
|
this.dexKey,
|
|
67
|
+
this.network,
|
|
59
68
|
`${this.daiAddress}_${this.sdaiAddress}`,
|
|
60
69
|
dexHelper,
|
|
61
70
|
this.potAddress,
|
|
62
|
-
this.
|
|
71
|
+
this.abiInterface,
|
|
63
72
|
this.logger,
|
|
73
|
+
SDaiConfig[dexKey][network].savingsRate.topic,
|
|
74
|
+
SDaiConfig[dexKey][network].savingsRate.symbol,
|
|
64
75
|
);
|
|
65
76
|
}
|
|
66
77
|
|
|
@@ -107,41 +118,38 @@ export class Spark
|
|
|
107
118
|
limitPools?: string[],
|
|
108
119
|
): Promise<null | ExchangePrices<SparkData>> {
|
|
109
120
|
if (!this.isAppropriatePair(srcToken, destToken)) return null;
|
|
110
|
-
|
|
121
|
+
const state = this.eventPool.getState(blockNumber);
|
|
122
|
+
if (!state) return null;
|
|
123
|
+
|
|
124
|
+
const isSrcAsset = this.isDai(srcToken.address);
|
|
125
|
+
|
|
126
|
+
let calcFunction: Function;
|
|
111
127
|
|
|
112
128
|
if (side === SwapSide.SELL) {
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return [
|
|
119
|
-
{
|
|
120
|
-
prices: amounts.map(amount => calcSellFn(blockNumber, amount)),
|
|
121
|
-
unit: calcSellFn(blockNumber, BI_POWS[18]),
|
|
122
|
-
gasCost: SDAI_DEPOSIT_GAS_COST,
|
|
123
|
-
exchange: this.dexKey,
|
|
124
|
-
data: { exchange: `${this.sdaiAddress}` },
|
|
125
|
-
poolAddresses: [`${this.sdaiAddress}`],
|
|
126
|
-
},
|
|
127
|
-
];
|
|
129
|
+
if (isSrcAsset) {
|
|
130
|
+
calcFunction = this.previewDeposit.bind(this);
|
|
131
|
+
} else {
|
|
132
|
+
calcFunction = this.previewRedeem.bind(this);
|
|
133
|
+
}
|
|
128
134
|
} else {
|
|
129
|
-
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return [
|
|
135
|
-
{
|
|
136
|
-
prices: amounts.map(amount => calcBuyFn(blockNumber, amount)),
|
|
137
|
-
unit: calcBuyFn(blockNumber, BI_POWS[18]),
|
|
138
|
-
gasCost: SDAI_REDEEM_GAS_COST,
|
|
139
|
-
exchange: this.dexKey,
|
|
140
|
-
data: { exchange: `${this.sdaiAddress}` },
|
|
141
|
-
poolAddresses: [`${this.sdaiAddress}`],
|
|
142
|
-
},
|
|
143
|
-
];
|
|
135
|
+
if (isSrcAsset) {
|
|
136
|
+
calcFunction = this.previewMint.bind(this);
|
|
137
|
+
} else {
|
|
138
|
+
calcFunction = this.previewWithdraw.bind(this);
|
|
139
|
+
}
|
|
144
140
|
}
|
|
141
|
+
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
// cannot produce 1:1 price without making an rpc call for block.timestamp and using it for price calculation in `calcChi` function
|
|
145
|
+
prices: amounts.map(amount => calcFunction(amount, state)),
|
|
146
|
+
unit: BI_POWS[18],
|
|
147
|
+
gasCost: SDAI_DEPOSIT_GAS_COST,
|
|
148
|
+
exchange: this.dexKey,
|
|
149
|
+
data: { exchange: `${this.sdaiAddress}` },
|
|
150
|
+
poolAddresses: [`${this.sdaiAddress}`],
|
|
151
|
+
},
|
|
152
|
+
];
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
@@ -286,4 +294,24 @@ export class Spark
|
|
|
286
294
|
networkFee: '0',
|
|
287
295
|
};
|
|
288
296
|
}
|
|
297
|
+
|
|
298
|
+
previewRedeem(shares: bigint, state: SparkSDaiPoolState) {
|
|
299
|
+
return (shares * calcChi(state)) / RAY;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
previewMint(shares: bigint, state: SparkSDaiPoolState) {
|
|
303
|
+
return this.divUp(shares * calcChi(state), RAY);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
previewWithdraw(assets: bigint, state: SparkSDaiPoolState) {
|
|
307
|
+
return this.divUp(assets * RAY, calcChi(state));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
previewDeposit(assets: bigint, state: SparkSDaiPoolState) {
|
|
311
|
+
return (assets * RAY) / calcChi(state);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
divUp(x: bigint, y: bigint): bigint {
|
|
315
|
+
return x !== 0n ? (x - 1n) / y + 1n : 0n;
|
|
316
|
+
}
|
|
289
317
|
}
|
package/src/dex/spark/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
1
2
|
import { Address } from '../../types';
|
|
2
3
|
|
|
3
4
|
export type SparkData = { exchange: Address };
|
|
@@ -6,6 +7,11 @@ export type SparkParams = {
|
|
|
6
7
|
sdaiAddress: Address;
|
|
7
8
|
daiAddress: Address;
|
|
8
9
|
potAddress: Address;
|
|
10
|
+
savingsRate: {
|
|
11
|
+
symbol: 'dsr' | 'ssr';
|
|
12
|
+
topic: string;
|
|
13
|
+
};
|
|
14
|
+
poolInterface: Interface;
|
|
9
15
|
};
|
|
10
16
|
|
|
11
17
|
export enum SparkSDaiFunctions {
|
package/src/dex/spark/utils.ts
CHANGED
|
@@ -4,34 +4,60 @@ import { Interface, AbiCoder } from '@ethersproject/abi';
|
|
|
4
4
|
|
|
5
5
|
const coder = new AbiCoder();
|
|
6
6
|
|
|
7
|
-
// - `dsr`: the Dai Savings Rate
|
|
7
|
+
// - `dsr` || `ssr`: the Dai Savings Rate or USDS savings rate
|
|
8
8
|
// - `chi`: the Rate Accumulator
|
|
9
9
|
// - `rho`: time of last drip
|
|
10
10
|
export async function getOnChainState(
|
|
11
11
|
multiContract: Contract,
|
|
12
12
|
potAddress: string,
|
|
13
13
|
potInterface: Interface,
|
|
14
|
+
savingsRateSymbol: 'dsr' | 'ssr',
|
|
14
15
|
blockNumber: number | 'latest',
|
|
15
16
|
): Promise<SparkSDaiPoolState> {
|
|
17
|
+
if (savingsRateSymbol === 'dsr') {
|
|
18
|
+
return getOnChainStateSDAI(
|
|
19
|
+
multiContract,
|
|
20
|
+
potAddress,
|
|
21
|
+
potInterface,
|
|
22
|
+
blockNumber,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return getOnChainStateUSDS(
|
|
27
|
+
multiContract,
|
|
28
|
+
potAddress,
|
|
29
|
+
potInterface,
|
|
30
|
+
blockNumber,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function getOnChainStateSDAI(
|
|
35
|
+
multiContract: Contract,
|
|
36
|
+
potAddress: string,
|
|
37
|
+
potInterface: Interface,
|
|
38
|
+
blockNumber: number | 'latest',
|
|
39
|
+
): Promise<SparkSDaiPoolState> {
|
|
40
|
+
const calls = [
|
|
41
|
+
{
|
|
42
|
+
target: potAddress,
|
|
43
|
+
callData: potInterface.encodeFunctionData('dsr', []),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
target: potAddress,
|
|
47
|
+
callData: potInterface.encodeFunctionData('chi', []),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
target: potAddress,
|
|
51
|
+
callData: potInterface.encodeFunctionData('rho', []),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
target: potAddress,
|
|
55
|
+
callData: potInterface.encodeFunctionData('live', []),
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
|
|
16
59
|
const data: { returnData: any[] } = await multiContract.methods
|
|
17
|
-
.aggregate(
|
|
18
|
-
{
|
|
19
|
-
target: potAddress,
|
|
20
|
-
callData: potInterface.encodeFunctionData('dsr', []),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
target: potAddress,
|
|
24
|
-
callData: potInterface.encodeFunctionData('chi', []),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
target: potAddress,
|
|
28
|
-
callData: potInterface.encodeFunctionData('rho', []),
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
target: potAddress,
|
|
32
|
-
callData: potInterface.encodeFunctionData('live', []),
|
|
33
|
-
},
|
|
34
|
-
])
|
|
60
|
+
.aggregate(calls)
|
|
35
61
|
.call({}, blockNumber);
|
|
36
62
|
|
|
37
63
|
const [dsr, chi, rho, live] = data.returnData.map(item =>
|
|
@@ -45,3 +71,41 @@ export async function getOnChainState(
|
|
|
45
71
|
rho,
|
|
46
72
|
};
|
|
47
73
|
}
|
|
74
|
+
|
|
75
|
+
export async function getOnChainStateUSDS(
|
|
76
|
+
multiContract: Contract,
|
|
77
|
+
potAddress: string,
|
|
78
|
+
potInterface: Interface,
|
|
79
|
+
blockNumber: number | 'latest',
|
|
80
|
+
): Promise<SparkSDaiPoolState> {
|
|
81
|
+
const calls = [
|
|
82
|
+
{
|
|
83
|
+
target: potAddress,
|
|
84
|
+
callData: potInterface.encodeFunctionData('ssr', []),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
target: potAddress,
|
|
88
|
+
callData: potInterface.encodeFunctionData('chi', []),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
target: potAddress,
|
|
92
|
+
callData: potInterface.encodeFunctionData('rho', []),
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const data: { returnData: any[] } = await multiContract.methods
|
|
97
|
+
.aggregate(calls)
|
|
98
|
+
.call({}, blockNumber);
|
|
99
|
+
|
|
100
|
+
const [dsr, chi, rho] = data.returnData.map(item =>
|
|
101
|
+
coder.decode(['uint256'], item)[0].toString(),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
// 'hack' - sUSDS doesn't have global shutdown and no notion of `live`, so it's always `live`
|
|
106
|
+
live: true,
|
|
107
|
+
dsr,
|
|
108
|
+
chi,
|
|
109
|
+
rho,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
NumberAsString,
|
|
8
8
|
SimpleExchangeParam,
|
|
9
9
|
} from '../../types';
|
|
10
|
-
import { IDexTxBuilder } from '../idex';
|
|
10
|
+
import { Context, IDexTxBuilder } from '../idex';
|
|
11
11
|
import { SimpleExchange } from '../simple-exchange';
|
|
12
12
|
import StablePoolABI from '../../abi/StablePool.json';
|
|
13
13
|
import { IDexHelper } from '../../dex-helper';
|
|
@@ -22,6 +22,8 @@ export class StablePool
|
|
|
22
22
|
exchangeRouterInterface: Interface;
|
|
23
23
|
minConversionRate = '1';
|
|
24
24
|
|
|
25
|
+
needWrapNative = false;
|
|
26
|
+
|
|
25
27
|
constructor(dexHelper: IDexHelper) {
|
|
26
28
|
super(dexHelper, 'stablePool');
|
|
27
29
|
this.exchangeRouterInterface = new Interface(StablePoolABI);
|
|
@@ -96,6 +98,7 @@ export class StablePool
|
|
|
96
98
|
_recipient: Address,
|
|
97
99
|
data: StablePoolData,
|
|
98
100
|
side: SwapSide,
|
|
101
|
+
context: Context,
|
|
99
102
|
): DexExchangeParam {
|
|
100
103
|
if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
|
|
101
104
|
|
|
@@ -23,7 +23,7 @@ describe('SwaapV2 E2E', () => {
|
|
|
23
23
|
],
|
|
24
24
|
],
|
|
25
25
|
// [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
26
|
-
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
26
|
+
// [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
29
|
describe('Mainnet', () => {
|
|
@@ -48,18 +48,18 @@ describe('SwaapV2 E2E', () => {
|
|
|
48
48
|
buyAmount: '100000000',
|
|
49
49
|
},
|
|
50
50
|
],
|
|
51
|
-
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
],
|
|
51
|
+
// [
|
|
52
|
+
// {
|
|
53
|
+
// name: 'USDC',
|
|
54
|
+
// sellAmount: '45410357',
|
|
55
|
+
// buyAmount: '1000000000000000000',
|
|
56
|
+
// },
|
|
57
|
+
// {
|
|
58
|
+
// name: 'ETH',
|
|
59
|
+
// sellAmount: '1000000000000000000',
|
|
60
|
+
// buyAmount: '100000000',
|
|
61
|
+
// },
|
|
62
|
+
// ],
|
|
63
63
|
];
|
|
64
64
|
|
|
65
65
|
sideToContractMethods.forEach((contractMethods, side) =>
|