@paraswap/dex-lib 3.8.38 → 3.8.39-1701-1507-1721
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/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/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 +8 -0
- package/build/dex/spark/config.js.map +1 -1
- package/build/dex/spark/spark.d.ts +4 -1
- package/build/dex/spark/spark.js +20 -15
- package/build/dex/spark/spark.js.map +1 -1
- package/build/dex/spark/types.d.ts +9 -0
- package/build/dex/spark/types.js +8 -1
- package/build/dex/spark/types.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/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 +8 -1
- package/src/dex/spark/spark.ts +27 -18
- package/src/dex/spark/types.ts +10 -0
- 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 +2 -2
- package/tests/utils-e2e.ts +308 -2
package/src/dex/spark/spark.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { SimpleExchange } from '../simple-exchange';
|
|
2
2
|
import { Context, IDex } from '../idex';
|
|
3
|
-
import {
|
|
4
|
-
SparkParams,
|
|
5
|
-
SparkData,
|
|
6
|
-
SparkSDaiFunctions,
|
|
7
|
-
SparkSDaiPoolState,
|
|
8
|
-
} from './types';
|
|
3
|
+
import { SparkParams, SparkData, SparkSDaiPoolState } from './types';
|
|
9
4
|
import { Network, SwapSide } from '../../constants';
|
|
10
5
|
import { getDexKeysWithNetwork } from '../../utils';
|
|
11
6
|
import { Adapters, SDaiConfig } from './config';
|
|
@@ -23,12 +18,10 @@ import {
|
|
|
23
18
|
} from '../../types';
|
|
24
19
|
import { IDexHelper } from '../../dex-helper';
|
|
25
20
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
26
|
-
import PotAbi from '../../abi/maker-psm/pot.json';
|
|
27
|
-
import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
|
|
28
21
|
import { Interface } from 'ethers/lib/utils';
|
|
29
22
|
import { calcChi, RAY, SparkSDaiEventPool } from './spark-sdai-pool';
|
|
30
23
|
import { BI_POWS } from '../../bigint-constants';
|
|
31
|
-
import { SDAI_DEPOSIT_GAS_COST
|
|
24
|
+
import { SDAI_DEPOSIT_GAS_COST } from './constants';
|
|
32
25
|
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
33
26
|
|
|
34
27
|
export class Spark
|
|
@@ -38,6 +31,8 @@ export class Spark
|
|
|
38
31
|
readonly hasConstantPriceLargeAmounts = true;
|
|
39
32
|
readonly isFeeOnTransferSupported = false;
|
|
40
33
|
|
|
34
|
+
needWrapNative = false;
|
|
35
|
+
|
|
41
36
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
42
37
|
getDexKeysWithNetwork(SDaiConfig);
|
|
43
38
|
|
|
@@ -56,7 +51,9 @@ export class Spark
|
|
|
56
51
|
.poolInterface,
|
|
57
52
|
|
|
58
53
|
protected adapters = Adapters[network] || {},
|
|
59
|
-
protected sdaiInterface =
|
|
54
|
+
protected sdaiInterface = SDaiConfig[dexKey][network].exchangeInterface,
|
|
55
|
+
protected swapFunctions = SDaiConfig[dexKey][network].swapFunctions,
|
|
56
|
+
protected referralCode = SDaiConfig[dexKey][network].referralCode,
|
|
60
57
|
) {
|
|
61
58
|
super(dexHelper, dexKey);
|
|
62
59
|
this.logger = dexHelper.getLogger(dexKey);
|
|
@@ -191,13 +188,19 @@ export class Spark
|
|
|
191
188
|
|
|
192
189
|
let swapData: string;
|
|
193
190
|
if (this.isDai(srcToken)) {
|
|
191
|
+
const calldata = [isSell ? srcAmount : destAmount, this.augustusAddress];
|
|
192
|
+
|
|
193
|
+
if (this.referralCode) {
|
|
194
|
+
calldata.push(this.referralCode);
|
|
195
|
+
}
|
|
196
|
+
|
|
194
197
|
swapData = this.sdaiInterface.encodeFunctionData(
|
|
195
|
-
isSell ?
|
|
196
|
-
|
|
198
|
+
isSell ? this.swapFunctions.deposit : this.swapFunctions.mint,
|
|
199
|
+
calldata,
|
|
197
200
|
);
|
|
198
201
|
} else {
|
|
199
202
|
swapData = this.sdaiInterface.encodeFunctionData(
|
|
200
|
-
isSell ?
|
|
203
|
+
isSell ? this.swapFunctions.redeem : this.swapFunctions.withdraw,
|
|
201
204
|
[
|
|
202
205
|
isSell ? srcAmount : destAmount,
|
|
203
206
|
this.augustusAddress,
|
|
@@ -236,13 +239,19 @@ export class Spark
|
|
|
236
239
|
|
|
237
240
|
let swapData: string;
|
|
238
241
|
if (this.isDai(srcToken)) {
|
|
242
|
+
const calldata = [isSell ? srcAmount : destAmount, recipient];
|
|
243
|
+
|
|
244
|
+
if (this.referralCode) {
|
|
245
|
+
calldata.push(this.referralCode);
|
|
246
|
+
}
|
|
247
|
+
|
|
239
248
|
swapData = this.sdaiInterface.encodeFunctionData(
|
|
240
|
-
isSell ?
|
|
241
|
-
|
|
249
|
+
isSell ? this.swapFunctions.deposit : this.swapFunctions.mint,
|
|
250
|
+
calldata,
|
|
242
251
|
);
|
|
243
252
|
} else {
|
|
244
253
|
swapData = this.sdaiInterface.encodeFunctionData(
|
|
245
|
-
isSell ?
|
|
254
|
+
isSell ? this.swapFunctions.redeem : this.swapFunctions.withdraw,
|
|
246
255
|
[isSell ? srcAmount : destAmount, recipient, executorAddress],
|
|
247
256
|
);
|
|
248
257
|
}
|
|
@@ -256,8 +265,8 @@ export class Spark
|
|
|
256
265
|
? extractReturnAmountPosition(
|
|
257
266
|
this.sdaiInterface,
|
|
258
267
|
this.isDai(srcToken)
|
|
259
|
-
?
|
|
260
|
-
:
|
|
268
|
+
? this.swapFunctions.deposit
|
|
269
|
+
: this.swapFunctions.redeem,
|
|
261
270
|
this.isDai(srcToken) ? 'shares' : 'assets',
|
|
262
271
|
)
|
|
263
272
|
: undefined,
|
package/src/dex/spark/types.ts
CHANGED
|
@@ -12,6 +12,9 @@ export type SparkParams = {
|
|
|
12
12
|
topic: string;
|
|
13
13
|
};
|
|
14
14
|
poolInterface: Interface;
|
|
15
|
+
exchangeInterface: Interface;
|
|
16
|
+
swapFunctions: typeof SparkSDaiFunctions | typeof SparkSUSDSFunctions;
|
|
17
|
+
referralCode: null | string;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
export enum SparkSDaiFunctions {
|
|
@@ -21,6 +24,13 @@ export enum SparkSDaiFunctions {
|
|
|
21
24
|
mint = 'mint',
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
export enum SparkSUSDSFunctions {
|
|
28
|
+
deposit = 'deposit(uint256,address,uint16)',
|
|
29
|
+
redeem = 'redeem',
|
|
30
|
+
withdraw = 'withdraw',
|
|
31
|
+
mint = 'mint(uint256,address,uint16)',
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export type SparkSDaiPoolState = {
|
|
25
35
|
rho: string;
|
|
26
36
|
chi: string;
|
|
@@ -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) =>
|
|
@@ -18,10 +18,13 @@ import {
|
|
|
18
18
|
MAX_INT,
|
|
19
19
|
MAX_UINT,
|
|
20
20
|
CACHE_PREFIX,
|
|
21
|
+
NULL_ADDRESS,
|
|
22
|
+
ETHER_ADDRESS,
|
|
21
23
|
} from '../../constants';
|
|
22
24
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
25
|
+
import { uniq } from 'lodash';
|
|
23
26
|
import { getDexKeysWithNetwork, isAxiosError } from '../../utils';
|
|
24
|
-
import { IDex } from '../idex';
|
|
27
|
+
import { Context, IDex } from '../idex';
|
|
25
28
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
26
29
|
import {
|
|
27
30
|
SwaapV2Data,
|
|
@@ -78,19 +81,68 @@ import {
|
|
|
78
81
|
import { BI_MAX_UINT256 } from '../../bigint-constants';
|
|
79
82
|
import { SpecialDex } from '../../executor/types';
|
|
80
83
|
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
84
|
+
import { OptimalRate, OptimalSwap } from '@paraswap/core';
|
|
85
|
+
import { ZERO_ADDRESS } from '@hashflow/sdk';
|
|
81
86
|
|
|
82
87
|
const BLACKLISTED = 'blacklisted';
|
|
83
88
|
|
|
84
89
|
export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
85
90
|
readonly isStatePollingDex = true;
|
|
86
91
|
readonly hasConstantPriceLargeAmounts = false;
|
|
87
|
-
readonly needWrapNative = false;
|
|
88
92
|
readonly isFeeOnTransferSupported = false;
|
|
89
93
|
private rateFetcher: RateFetcher;
|
|
90
94
|
private swaapV2AuthToken: string;
|
|
91
95
|
private tokensMap: TokensMap = {};
|
|
92
96
|
private runtimeMMsRestrictHashMapKey: string;
|
|
93
97
|
|
|
98
|
+
needUnwrapWeth = (
|
|
99
|
+
priceRoute: OptimalRate,
|
|
100
|
+
swap: OptimalSwap,
|
|
101
|
+
se: OptimalSwapExchange<any>,
|
|
102
|
+
): boolean => {
|
|
103
|
+
const swapSrc = swap.srcToken.toLowerCase();
|
|
104
|
+
const swapDest = swap.destToken.toLowerCase();
|
|
105
|
+
|
|
106
|
+
const wethAddr =
|
|
107
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
108
|
+
const tokenIn = se.data.tokenIn.toLowerCase();
|
|
109
|
+
const tokenOut = se.data.tokenOut.toLowerCase();
|
|
110
|
+
|
|
111
|
+
if (swapSrc.toLowerCase() === wethAddr && tokenIn === NULL_ADDRESS) {
|
|
112
|
+
return true; // WETH is src but native ETH pool is used, we need unwrap weth in this case
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (swapDest.toLowerCase() === wethAddr && tokenOut === NULL_ADDRESS) {
|
|
116
|
+
return true; // WETH is dest but native ETH pool is used, we need unwrap weth in this case
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return false;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
needWrapNative = (
|
|
123
|
+
priceRoute: OptimalRate,
|
|
124
|
+
swap: OptimalSwap,
|
|
125
|
+
se: OptimalSwapExchange<any>,
|
|
126
|
+
): boolean => {
|
|
127
|
+
const swapSrc = swap.srcToken.toLowerCase();
|
|
128
|
+
const swapDest = swap.destToken.toLowerCase();
|
|
129
|
+
|
|
130
|
+
const wethAddr =
|
|
131
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
132
|
+
const tokenIn = se.data.tokenIn.toLowerCase();
|
|
133
|
+
const tokenOut = se.data.tokenOut.toLowerCase();
|
|
134
|
+
|
|
135
|
+
if (swapSrc === ETHER_ADDRESS.toLowerCase() && tokenIn === wethAddr) {
|
|
136
|
+
return true; // ETH is src but WETH pool is used, we need wrap native in this case
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (swapDest === ETHER_ADDRESS.toLowerCase() && tokenOut === wethAddr) {
|
|
140
|
+
return true; // ETH is dest but WETH pool is used, we need wrap native in this case
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return false;
|
|
144
|
+
};
|
|
145
|
+
|
|
94
146
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
95
147
|
getDexKeysWithNetwork(SwaapV2Config);
|
|
96
148
|
|
|
@@ -162,26 +214,68 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
162
214
|
return [];
|
|
163
215
|
}
|
|
164
216
|
|
|
165
|
-
const
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
217
|
+
const wethAddr =
|
|
218
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
219
|
+
const isSrcEth = normalizedSrcToken.address === NULL_ADDRESS; // SwaapV2 uses zero address for native eth
|
|
220
|
+
const isSrcWeth = this.isWETH(normalizedSrcToken.address);
|
|
221
|
+
|
|
222
|
+
const isDestEth = normalizedDestToken.address === NULL_ADDRESS; // SwaapV2 uses zero address for native eth
|
|
223
|
+
const isDestWeth = this.isWETH(normalizedDestToken.address);
|
|
224
|
+
|
|
225
|
+
const poolIdentifiers = [
|
|
226
|
+
getPoolIdentifier(
|
|
227
|
+
this.dexKey,
|
|
228
|
+
normalizedSrcToken.address,
|
|
229
|
+
normalizedDestToken.address,
|
|
230
|
+
),
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
if (isSrcWeth) {
|
|
234
|
+
poolIdentifiers.push(
|
|
235
|
+
getPoolIdentifier(
|
|
236
|
+
this.dexKey,
|
|
237
|
+
NULL_ADDRESS,
|
|
238
|
+
normalizedDestToken.address,
|
|
239
|
+
),
|
|
240
|
+
); // native eth pool
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (isSrcEth) {
|
|
244
|
+
poolIdentifiers.push(this.dexKey, wethAddr, normalizedDestToken.address); // weth pool
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (isDestWeth) {
|
|
248
|
+
poolIdentifiers.push(
|
|
249
|
+
getPoolIdentifier(
|
|
250
|
+
this.dexKey,
|
|
251
|
+
normalizedSrcToken.address,
|
|
252
|
+
NULL_ADDRESS,
|
|
253
|
+
),
|
|
254
|
+
); // native eth pool
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (isDestEth) {
|
|
258
|
+
poolIdentifiers.push(
|
|
259
|
+
getPoolIdentifier(this.dexKey, normalizedSrcToken.address, wethAddr),
|
|
260
|
+
); // weth pool
|
|
261
|
+
}
|
|
170
262
|
|
|
171
263
|
const levels = await this.getCachedLevels();
|
|
172
264
|
if (levels === null) {
|
|
173
265
|
return [];
|
|
174
266
|
}
|
|
175
267
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
268
|
+
const allPoolIds = Object.keys(levels).map((pair: string) => {
|
|
269
|
+
return getPoolIdentifier(
|
|
270
|
+
this.dexKey,
|
|
271
|
+
levels[pair].base!,
|
|
272
|
+
levels[pair].quote!,
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
return uniq(
|
|
277
|
+
allPoolIds.filter((pi: string) => poolIdentifiers.includes(pi)),
|
|
278
|
+
);
|
|
185
279
|
}
|
|
186
280
|
|
|
187
281
|
computePricesFromLevelsBids(
|
|
@@ -340,9 +434,17 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
340
434
|
return null;
|
|
341
435
|
}
|
|
342
436
|
|
|
437
|
+
const wethAddr =
|
|
438
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
439
|
+
const isSrcEth = normalizedSrcToken.address === NULL_ADDRESS; // SwaapV2 uses zero address for native eth
|
|
440
|
+
const isSrcWeth = this.isWETH(normalizedSrcToken.address);
|
|
441
|
+
|
|
442
|
+
const isDestEth = normalizedDestToken.address === NULL_ADDRESS; // SwaapV2 uses zero address for native eth
|
|
443
|
+
const isDestWeth = this.isWETH(normalizedDestToken.address);
|
|
444
|
+
|
|
343
445
|
const pools = limitPools
|
|
344
|
-
? limitPools.filter(
|
|
345
|
-
|
|
446
|
+
? limitPools.filter(p => {
|
|
447
|
+
const isAppropriatePool =
|
|
346
448
|
p ===
|
|
347
449
|
getPoolIdentifier(
|
|
348
450
|
this.dexKey,
|
|
@@ -354,8 +456,58 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
354
456
|
this.dexKey,
|
|
355
457
|
normalizedDestToken.address,
|
|
356
458
|
normalizedSrcToken.address,
|
|
357
|
-
)
|
|
358
|
-
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
if (isSrcEth) {
|
|
462
|
+
return (
|
|
463
|
+
isAppropriatePool ||
|
|
464
|
+
p ===
|
|
465
|
+
getPoolIdentifier(
|
|
466
|
+
this.dexKey,
|
|
467
|
+
wethAddr,
|
|
468
|
+
normalizedDestToken.address,
|
|
469
|
+
)
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (isSrcWeth) {
|
|
474
|
+
return (
|
|
475
|
+
isAppropriatePool ||
|
|
476
|
+
p ===
|
|
477
|
+
getPoolIdentifier(
|
|
478
|
+
this.dexKey,
|
|
479
|
+
NULL_ADDRESS,
|
|
480
|
+
normalizedDestToken.address,
|
|
481
|
+
)
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (isDestEth) {
|
|
486
|
+
return (
|
|
487
|
+
isAppropriatePool ||
|
|
488
|
+
p ===
|
|
489
|
+
getPoolIdentifier(
|
|
490
|
+
this.dexKey,
|
|
491
|
+
normalizedSrcToken.address,
|
|
492
|
+
wethAddr,
|
|
493
|
+
)
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (isDestWeth) {
|
|
498
|
+
return (
|
|
499
|
+
isAppropriatePool ||
|
|
500
|
+
p ===
|
|
501
|
+
getPoolIdentifier(
|
|
502
|
+
this.dexKey,
|
|
503
|
+
normalizedSrcToken.address,
|
|
504
|
+
NULL_ADDRESS,
|
|
505
|
+
)
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return isAppropriatePool;
|
|
510
|
+
})
|
|
359
511
|
: await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
|
|
360
512
|
|
|
361
513
|
if (pools.length === 0) {
|
|
@@ -370,14 +522,10 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
370
522
|
const levelEntries: SwaapV2PriceLevels[] = Object.keys(levels)
|
|
371
523
|
.filter(pair => {
|
|
372
524
|
const { base, quote } = levels[pair];
|
|
373
|
-
|
|
525
|
+
return (
|
|
374
526
|
pools.includes(getPoolIdentifier(this.dexKey, quote, base)) ||
|
|
375
527
|
pools.includes(getPoolIdentifier(this.dexKey, base, quote))
|
|
376
|
-
)
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return false;
|
|
528
|
+
);
|
|
381
529
|
})
|
|
382
530
|
.map(pair => {
|
|
383
531
|
return levels[pair];
|
|
@@ -421,13 +569,38 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
421
569
|
? STABLE_SWAP_GAS_COST_ESTIMATION
|
|
422
570
|
: VOLATILE_SWAP_GAS_COST_ESTIMATION;
|
|
423
571
|
|
|
572
|
+
const tokenIn =
|
|
573
|
+
normalizedSrcToken.address === NULL_ADDRESS &&
|
|
574
|
+
[askAndBids.base, askAndBids.quote].includes(wethAddr)
|
|
575
|
+
? wethAddr
|
|
576
|
+
: normalizedSrcToken.address === wethAddr &&
|
|
577
|
+
[askAndBids.base, askAndBids.quote].includes(NULL_ADDRESS)
|
|
578
|
+
? NULL_ADDRESS
|
|
579
|
+
: normalizedSrcToken.address;
|
|
580
|
+
|
|
581
|
+
const tokenOut =
|
|
582
|
+
normalizedDestToken.address === NULL_ADDRESS &&
|
|
583
|
+
[askAndBids.base, askAndBids.quote].includes(wethAddr)
|
|
584
|
+
? wethAddr
|
|
585
|
+
: normalizedDestToken.address === wethAddr &&
|
|
586
|
+
[askAndBids.base, askAndBids.quote].includes(NULL_ADDRESS)
|
|
587
|
+
? NULL_ADDRESS
|
|
588
|
+
: normalizedDestToken.address;
|
|
589
|
+
|
|
424
590
|
return {
|
|
425
591
|
gasCost: gasCost,
|
|
426
592
|
exchange: this.dexKey,
|
|
427
|
-
data: {
|
|
593
|
+
data: {
|
|
594
|
+
tokenIn,
|
|
595
|
+
tokenOut,
|
|
596
|
+
},
|
|
428
597
|
prices,
|
|
429
598
|
unit: unitPrice === undefined ? 0n : unitPrice,
|
|
430
|
-
poolIdentifier:
|
|
599
|
+
poolIdentifier: getPoolIdentifier(
|
|
600
|
+
this.dexKey,
|
|
601
|
+
askAndBids.base,
|
|
602
|
+
askAndBids.quote,
|
|
603
|
+
),
|
|
431
604
|
} as PoolPrices<SwaapV2Data>;
|
|
432
605
|
});
|
|
433
606
|
|
|
@@ -453,6 +626,7 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
453
626
|
recipient: string,
|
|
454
627
|
data: SwaapV2Data,
|
|
455
628
|
side: SwapSide,
|
|
629
|
+
context: Context,
|
|
456
630
|
): AsyncOrSync<DexExchangeParam> {
|
|
457
631
|
const { router, callData } = data;
|
|
458
632
|
const isBatchSwap = callData.slice(0, 10) === BATCH_SWAP_SELECTOR;
|
|
@@ -471,7 +645,16 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
471
645
|
);
|
|
472
646
|
|
|
473
647
|
return {
|
|
474
|
-
needWrapNative: this.needWrapNative
|
|
648
|
+
needWrapNative: this.needWrapNative(
|
|
649
|
+
context.priceRoute,
|
|
650
|
+
context.swap,
|
|
651
|
+
context.swapExchange,
|
|
652
|
+
),
|
|
653
|
+
needUnwrapWeth: this.needUnwrapWeth(
|
|
654
|
+
context.priceRoute,
|
|
655
|
+
context.swap,
|
|
656
|
+
context.swapExchange,
|
|
657
|
+
),
|
|
475
658
|
specialDexSupportsInsertFromAmount: true,
|
|
476
659
|
dexFuncHasRecipient: true,
|
|
477
660
|
exchangeData: callData,
|
|
@@ -520,8 +703,8 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
520
703
|
try {
|
|
521
704
|
const quote = await this.rateFetcher.getQuote(
|
|
522
705
|
this.network,
|
|
523
|
-
|
|
524
|
-
|
|
706
|
+
{ address: optimalSwapExchange.data!.tokenIn, decimals: 18 },
|
|
707
|
+
{ address: optimalSwapExchange.data!.tokenOut, decimals: 18 },
|
|
525
708
|
isSell ? optimalSwapExchange.srcAmount : optimalSwapExchange.destAmount,
|
|
526
709
|
isSell ? SWAAP_ORDER_TYPE_SELL : SWAAP_ORDER_TYPE_BUY,
|
|
527
710
|
options.userAddress,
|
|
@@ -628,6 +811,8 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
628
811
|
{
|
|
629
812
|
...optimalSwapExchange,
|
|
630
813
|
data: {
|
|
814
|
+
tokenIn: optimalSwapExchange.data!.tokenIn,
|
|
815
|
+
tokenOut: optimalSwapExchange.data!.tokenOut,
|
|
631
816
|
router: quote.router,
|
|
632
817
|
callData: quote.calldata,
|
|
633
818
|
},
|
|
@@ -659,7 +844,7 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
659
844
|
normalizedSrcToken.address,
|
|
660
845
|
normalizedDestToken.address,
|
|
661
846
|
);
|
|
662
|
-
|
|
847
|
+
let message = 'Unknown error';
|
|
663
848
|
if (e instanceof Error) {
|
|
664
849
|
message = `${e.name}: ${e.message}`;
|
|
665
850
|
}
|
package/src/dex/weth/weth.ts
CHANGED
|
@@ -34,6 +34,8 @@ export class Weth
|
|
|
34
34
|
readonly hasConstantPriceLargeAmounts = true;
|
|
35
35
|
readonly isFeeOnTransferSupported = false;
|
|
36
36
|
|
|
37
|
+
needWrapNative = false;
|
|
38
|
+
|
|
37
39
|
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
38
40
|
getDexKeysWithNetwork(WethConfig);
|
|
39
41
|
|