@paraswap/dex-lib 2.20.3 → 2.21.1-chronos
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/build/config.js +2 -4
- package/build/config.js.map +1 -1
- package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +74 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +116 -0
- package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
- package/build/dex/balancer-v2/balancer-v2.js +0 -83
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +0 -4
- package/build/dex/balancer-v2/constants.js +1 -6
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +1 -20
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +0 -1
- package/build/dex/curve-v1/constants.js +1 -2
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +3 -9
- package/build/dex/curve-v1/curve-v1.js +4 -92
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/types.d.ts +0 -24
- package/build/dex/curve-v1/types.js +1 -6
- package/build/dex/curve-v1/types.js.map +1 -1
- package/build/dex/curve-v1-factory/constants.d.ts +0 -1
- package/build/dex/curve-v1-factory/constants.js +1 -2
- package/build/dex/curve-v1-factory/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
- package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +0 -24
- package/build/dex/curve-v1-factory/types.js +1 -6
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2.d.ts +7 -29
- package/build/dex/curve-v2.js +1 -91
- package/build/dex/curve-v2.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/index.js +2 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/pancakeswap-v3/types.js +3 -0
- package/build/dex/pancakeswap-v3/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/utils.js.map +1 -1
- package/build/dex/quickswap/camelot-v3.d.ts +6 -0
- package/build/dex/quickswap/camelot-v3.js +19 -0
- package/build/dex/quickswap/camelot-v3.js.map +1 -0
- package/build/dex/simple-exchange.d.ts +0 -2
- package/build/dex/simple-exchange.js +0 -1
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/solidly/config.js +13 -0
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
- package/build/dex/solidly/forks-override/chronos.js +132 -0
- package/build/dex/solidly/forks-override/chronos.js.map +1 -0
- package/build/dex/solidly/solidly.js +1 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +0 -4
- package/build/dex/uniswap-v3/constants.js +1 -6
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +3 -20
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +6 -6
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -5
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/router/directswap.js +1 -7
- package/build/router/directswap.js.map +1 -1
- package/build/router/index.js.map +1 -1
- package/build/router/payload-encoder.js +6 -16
- package/build/router/payload-encoder.js.map +1 -1
- package/build/types.d.ts +0 -2
- package/build/utils.d.ts +0 -2
- package/build/utils.js +1 -5
- package/build/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/config.ts +2 -5
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
- package/src/dex/balancer-v2/balancer-v2.ts +4 -153
- package/src/dex/balancer-v2/constants.ts +0 -5
- package/src/dex/balancer-v2/types.ts +1 -21
- package/src/dex/curve-v1/constants.ts +0 -2
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
- package/src/dex/curve-v1/curve-v1.ts +5 -144
- package/src/dex/curve-v1/types.ts +0 -26
- package/src/dex/curve-v1-factory/constants.ts +0 -2
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
- package/src/dex/curve-v1-factory/types.ts +0 -26
- package/src/dex/curve-v2.ts +8 -169
- package/src/dex/idex.ts +0 -6
- package/src/dex/index.ts +2 -2
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
- package/src/dex/pancakeswap-v3/utils.ts +4 -1
- package/src/dex/simple-exchange.ts +0 -6
- package/src/dex/solidly/config.ts +14 -0
- package/src/dex/solidly/forks-override/chronos.ts +206 -0
- package/src/dex/solidly/solidly-e2e.test.ts +205 -31
- package/src/dex/solidly/solidly-integration.test.ts +141 -0
- package/src/dex/solidly/solidly.ts +1 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
- package/src/dex/uniswap-v3/constants.ts +0 -5
- package/src/dex/uniswap-v3/types.ts +3 -23
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
- package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
- package/src/dex/woo-fi-v2/config.ts +6 -6
- package/src/dex/zerox/index.ts +0 -7
- package/src/implementations/local-paraswap-sdk.ts +1 -8
- package/src/router/directswap.ts +0 -23
- package/src/router/index.ts +2 -0
- package/src/router/payload-encoder.ts +5 -22
- package/src/types.ts +0 -2
- package/src/utils.ts +0 -5
- package/tests/constants-e2e.ts +9 -4
- package/tests/utils-e2e.ts +20 -140
- package/tests/utils.ts +0 -52
- package/src/abi/DirectSwap.json +0 -1018
- package/src/abi/swaap-v2/vault.json +0 -918
- package/src/dex/swaap-v2/config.ts +0 -19
- package/src/dex/swaap-v2/constants.ts +0 -37
- package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
- package/src/dex/swaap-v2/swaap-v2.ts +0 -901
- package/src/dex/swaap-v2/types.ts +0 -95
- package/src/dex/swaap-v2/utils.ts +0 -36
- package/src/dex/swaap-v2/validators.ts +0 -128
package/src/dex/curve-v2.ts
CHANGED
|
@@ -3,26 +3,15 @@ import { SwapSide } from '../constants';
|
|
|
3
3
|
import {
|
|
4
4
|
AdapterExchangeParam,
|
|
5
5
|
Address,
|
|
6
|
-
ExchangeTxInfo,
|
|
7
6
|
NumberAsString,
|
|
8
|
-
PreprocessTransactionOptions,
|
|
9
7
|
SimpleExchangeParam,
|
|
10
|
-
Token,
|
|
11
|
-
TxInfo,
|
|
12
8
|
} from '../types';
|
|
13
9
|
import { IDexTxBuilder } from './idex';
|
|
14
|
-
import {
|
|
15
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
16
|
-
SimpleExchange,
|
|
17
|
-
} from './simple-exchange';
|
|
10
|
+
import { SimpleExchange } from './simple-exchange';
|
|
18
11
|
import GenericFactoryZapABI from '../abi/curve-v2/GenericFactoryZap.json';
|
|
19
|
-
import DirectSwapABI from '../abi/DirectSwap.json';
|
|
20
12
|
import CurveV2ABI from '../abi/CurveV2.json';
|
|
13
|
+
import Web3 from 'web3';
|
|
21
14
|
import { IDexHelper } from '../dex-helper';
|
|
22
|
-
import { assert } from 'ts-essentials';
|
|
23
|
-
import { Logger } from 'log4js';
|
|
24
|
-
import { OptimalSwapExchange } from '@paraswap/core';
|
|
25
|
-
import { uuidToBytes16 } from '../utils';
|
|
26
15
|
|
|
27
16
|
export enum CurveV2SwapType {
|
|
28
17
|
EXCHANGE,
|
|
@@ -30,15 +19,12 @@ export enum CurveV2SwapType {
|
|
|
30
19
|
EXCHANGE_GENERIC_FACTORY_ZAP,
|
|
31
20
|
}
|
|
32
21
|
|
|
33
|
-
const DIRECT_METHOD_NAME = 'directCurveV2Swap';
|
|
34
|
-
|
|
35
22
|
type CurveV2Data = {
|
|
36
23
|
i: number;
|
|
37
24
|
j: number;
|
|
38
25
|
exchange: string;
|
|
39
26
|
originalPoolAddress: Address;
|
|
40
27
|
swapType: CurveV2SwapType;
|
|
41
|
-
isApproved?: boolean;
|
|
42
28
|
};
|
|
43
29
|
|
|
44
30
|
type CurveV2Param = [
|
|
@@ -57,26 +43,6 @@ type CurveV2ParamsForGenericFactoryZap = [
|
|
|
57
43
|
min_dy: NumberAsString,
|
|
58
44
|
];
|
|
59
45
|
|
|
60
|
-
export type DirectCurveV2Param = [
|
|
61
|
-
fromToken: Address,
|
|
62
|
-
toToken: Address,
|
|
63
|
-
exchange: Address,
|
|
64
|
-
poolAddress: Address,
|
|
65
|
-
fromAmount: NumberAsString,
|
|
66
|
-
toAmount: NumberAsString,
|
|
67
|
-
expectedAmount: NumberAsString,
|
|
68
|
-
feePercent: NumberAsString,
|
|
69
|
-
i: NumberAsString,
|
|
70
|
-
j: NumberAsString,
|
|
71
|
-
partner: Address,
|
|
72
|
-
isApproved: boolean,
|
|
73
|
-
swapType: CurveV2SwapType,
|
|
74
|
-
beneficiary: Address,
|
|
75
|
-
needWrapNative: boolean,
|
|
76
|
-
permit: string,
|
|
77
|
-
uuid: string,
|
|
78
|
-
];
|
|
79
|
-
|
|
80
46
|
enum CurveV2SwapFunctions {
|
|
81
47
|
exchange = 'exchange(uint256 i, uint256 j, uint256 dx, uint256 minDy)',
|
|
82
48
|
exchange_underlying = 'exchange_underlying(uint256 i, uint256 j, uint256 dx, uint256 minDy)',
|
|
@@ -85,31 +51,25 @@ enum CurveV2SwapFunctions {
|
|
|
85
51
|
|
|
86
52
|
export class CurveV2
|
|
87
53
|
extends SimpleExchange
|
|
88
|
-
implements IDexTxBuilder<CurveV2Data,
|
|
54
|
+
implements IDexTxBuilder<CurveV2Data, CurveV2Param>
|
|
89
55
|
{
|
|
90
56
|
static dexKeys = ['curvev2'];
|
|
91
57
|
exchangeRouterInterface: Interface;
|
|
92
58
|
genericFactoryZapIface: Interface;
|
|
93
59
|
minConversionRate = '1';
|
|
94
60
|
needWrapNative = true;
|
|
95
|
-
logger: Logger;
|
|
96
|
-
|
|
97
|
-
readonly directSwapIface = new Interface(DirectSwapABI);
|
|
98
61
|
|
|
99
|
-
constructor(
|
|
62
|
+
constructor(dexHelper: IDexHelper) {
|
|
100
63
|
super(dexHelper, 'curvev2');
|
|
101
64
|
this.exchangeRouterInterface = new Interface(CurveV2ABI as JsonFragment[]);
|
|
102
65
|
this.genericFactoryZapIface = new Interface(GenericFactoryZapABI);
|
|
103
|
-
this.logger = dexHelper.getLogger(
|
|
104
|
-
`CurveV2_${dexHelper.config.data.network}`,
|
|
105
|
-
);
|
|
106
66
|
}
|
|
107
67
|
|
|
108
68
|
getAdapterParam(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
69
|
+
srcToken: string,
|
|
70
|
+
destToken: string,
|
|
71
|
+
srcAmount: string,
|
|
72
|
+
destAmount: string,
|
|
113
73
|
data: CurveV2Data,
|
|
114
74
|
side: SwapSide,
|
|
115
75
|
): AdapterExchangeParam {
|
|
@@ -140,127 +100,6 @@ export class CurveV2
|
|
|
140
100
|
};
|
|
141
101
|
}
|
|
142
102
|
|
|
143
|
-
getTokenFromAddress(address: Address): Token {
|
|
144
|
-
// In this Dex decimals are not used
|
|
145
|
-
return { address, decimals: 0 };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async preProcessTransaction(
|
|
149
|
-
optimalSwapExchange: OptimalSwapExchange<CurveV2Data>,
|
|
150
|
-
srcToken: Token,
|
|
151
|
-
_0: Token,
|
|
152
|
-
_1: SwapSide,
|
|
153
|
-
options: PreprocessTransactionOptions,
|
|
154
|
-
): Promise<[OptimalSwapExchange<CurveV2Data>, ExchangeTxInfo]> {
|
|
155
|
-
if (!options.isDirectMethod) {
|
|
156
|
-
return [
|
|
157
|
-
optimalSwapExchange,
|
|
158
|
-
{
|
|
159
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
160
|
-
},
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
assert(
|
|
165
|
-
optimalSwapExchange.data !== undefined,
|
|
166
|
-
`preProcessTransaction: data field is missing`,
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
let isApproved: boolean | undefined;
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
this.erc20Contract.options.address =
|
|
173
|
-
this.dexHelper.config.wrapETH(srcToken).address;
|
|
174
|
-
const allowance = await this.erc20Contract.methods
|
|
175
|
-
.allowance(this.augustusAddress, optimalSwapExchange.data.exchange)
|
|
176
|
-
.call(undefined, 'latest');
|
|
177
|
-
isApproved =
|
|
178
|
-
BigInt(allowance.toString()) >= BigInt(optimalSwapExchange.srcAmount);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
this.logger.error(
|
|
181
|
-
`preProcessTransaction failed to retrieve allowance info: `,
|
|
182
|
-
e,
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return [
|
|
187
|
-
{
|
|
188
|
-
...optimalSwapExchange,
|
|
189
|
-
data: {
|
|
190
|
-
...optimalSwapExchange.data,
|
|
191
|
-
isApproved,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
deadline: BigInt(getLocalDeadlineAsFriendlyPlaceholder()),
|
|
196
|
-
},
|
|
197
|
-
];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getDirectParam(
|
|
201
|
-
srcToken: Address,
|
|
202
|
-
destToken: Address,
|
|
203
|
-
srcAmount: NumberAsString,
|
|
204
|
-
destAmount: NumberAsString,
|
|
205
|
-
expectedAmount: NumberAsString,
|
|
206
|
-
data: CurveV2Data,
|
|
207
|
-
side: SwapSide,
|
|
208
|
-
permit: string,
|
|
209
|
-
uuid: string,
|
|
210
|
-
feePercent: NumberAsString,
|
|
211
|
-
_0: NumberAsString,
|
|
212
|
-
partner: string,
|
|
213
|
-
beneficiary: string,
|
|
214
|
-
contractMethod?: string,
|
|
215
|
-
): TxInfo<DirectCurveV2Param> {
|
|
216
|
-
if (contractMethod !== DIRECT_METHOD_NAME) {
|
|
217
|
-
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
218
|
-
}
|
|
219
|
-
assert(side === SwapSide.SELL, 'Buy not supported');
|
|
220
|
-
|
|
221
|
-
let isApproved: boolean = !!data.isApproved;
|
|
222
|
-
if (data.isApproved === undefined) {
|
|
223
|
-
this.logger.warn(`isApproved is undefined, defaulting to false`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const swapParams: DirectCurveV2Param = [
|
|
227
|
-
srcToken,
|
|
228
|
-
destToken,
|
|
229
|
-
data.exchange,
|
|
230
|
-
data.originalPoolAddress,
|
|
231
|
-
srcAmount,
|
|
232
|
-
destAmount,
|
|
233
|
-
expectedAmount,
|
|
234
|
-
feePercent,
|
|
235
|
-
data.i.toString(),
|
|
236
|
-
data.j.toString(),
|
|
237
|
-
partner,
|
|
238
|
-
isApproved,
|
|
239
|
-
data.swapType,
|
|
240
|
-
beneficiary,
|
|
241
|
-
// For now we always wrap native. We don't support non native trade
|
|
242
|
-
true,
|
|
243
|
-
permit,
|
|
244
|
-
uuidToBytes16(uuid),
|
|
245
|
-
];
|
|
246
|
-
|
|
247
|
-
const encoder = (...params: DirectCurveV2Param) => {
|
|
248
|
-
return this.directSwapIface.encodeFunctionData(DIRECT_METHOD_NAME, [
|
|
249
|
-
params,
|
|
250
|
-
]);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
return {
|
|
254
|
-
params: swapParams,
|
|
255
|
-
encoder,
|
|
256
|
-
networkFee: '0',
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
static getDirectFunctionName(): string[] {
|
|
261
|
-
return [DIRECT_METHOD_NAME];
|
|
262
|
-
}
|
|
263
|
-
|
|
264
103
|
async getSimpleParam(
|
|
265
104
|
srcToken: string,
|
|
266
105
|
destToken: string,
|
package/src/dex/idex.ts
CHANGED
|
@@ -76,15 +76,9 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
|
|
|
76
76
|
destToken: Address,
|
|
77
77
|
srcAmount: NumberAsString,
|
|
78
78
|
destAmount: NumberAsString,
|
|
79
|
-
expectedAmount: NumberAsString,
|
|
80
79
|
data: ExchangeData,
|
|
81
80
|
side: SwapSide,
|
|
82
81
|
permit: string,
|
|
83
|
-
uuid: string,
|
|
84
|
-
feePercent: NumberAsString,
|
|
85
|
-
deadline: NumberAsString,
|
|
86
|
-
partner: string,
|
|
87
|
-
beneficiary: string,
|
|
88
82
|
contractMethod?: string,
|
|
89
83
|
): TxInfo<DirectParam>;
|
|
90
84
|
}
|
package/src/dex/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { ParaSwapLimitOrders } from './paraswap-limit-orders/paraswap-limit-orde
|
|
|
43
43
|
import { AugustusRFQOrder } from './augustus-rfq';
|
|
44
44
|
import { Solidly } from './solidly/solidly';
|
|
45
45
|
import { Thena } from './solidly/forks-override/thena';
|
|
46
|
+
import { Chronos } from './solidly/forks-override/chronos';
|
|
46
47
|
import { Velodrome } from './solidly/forks-override/velodrome';
|
|
47
48
|
import { SpiritSwapV2 } from './solidly/forks-override/spiritSwapV2';
|
|
48
49
|
import { Synthetix } from './synthetix/synthetix';
|
|
@@ -64,7 +65,6 @@ import { MaverickV1 } from './maverick-v1/maverick-v1';
|
|
|
64
65
|
import { QuickSwapV3 } from './quickswap/quickswap-v3';
|
|
65
66
|
import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
|
|
66
67
|
import { TraderJoeV2 } from './trader-joe-v2';
|
|
67
|
-
import { SwaapV2 } from './swaap-v2/swaap-v2';
|
|
68
68
|
import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
|
|
69
69
|
import { TraderJoeV21 } from './trader-joe-v2.1';
|
|
70
70
|
import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
|
|
@@ -122,6 +122,7 @@ const Dexes = [
|
|
|
122
122
|
SolidlyEthereum,
|
|
123
123
|
SpiritSwapV2,
|
|
124
124
|
Thena,
|
|
125
|
+
Chronos,
|
|
125
126
|
Velodrome,
|
|
126
127
|
Cone,
|
|
127
128
|
SoliSnek,
|
|
@@ -132,7 +133,6 @@ const Dexes = [
|
|
|
132
133
|
Hashflow,
|
|
133
134
|
MaverickV1,
|
|
134
135
|
Camelot,
|
|
135
|
-
SwaapV2,
|
|
136
136
|
];
|
|
137
137
|
|
|
138
138
|
export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
|
|
@@ -32,7 +32,10 @@ describe('PancakeswapV3 E2E', () => {
|
|
|
32
32
|
ContractMethod.megaSwap,
|
|
33
33
|
],
|
|
34
34
|
],
|
|
35
|
-
[SwapSide.BUY, [
|
|
35
|
+
[SwapSide.BUY, [
|
|
36
|
+
ContractMethod.simpleBuy,
|
|
37
|
+
ContractMethod.buy,
|
|
38
|
+
]],
|
|
36
39
|
]);
|
|
37
40
|
|
|
38
41
|
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
|
|
@@ -95,8 +98,8 @@ describe('PancakeswapV3 E2E', () => {
|
|
|
95
98
|
sellAmount: '10000000000',
|
|
96
99
|
buyAmount: '500000000000000000000',
|
|
97
100
|
},
|
|
98
|
-
]
|
|
99
|
-
]
|
|
101
|
+
]
|
|
102
|
+
]
|
|
100
103
|
|
|
101
104
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
102
105
|
describe(`${side}`, () => {
|
|
@@ -76,6 +76,7 @@ const testingData: Partial<{ [key in Network]: any }> = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
describe('PancakeswapV3', function () {
|
|
79
|
+
|
|
79
80
|
describe('BSC', () => {
|
|
80
81
|
describe('WBNB -> USDT', () => {
|
|
81
82
|
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
@@ -87,7 +88,11 @@ describe('PancakeswapV3', function () {
|
|
|
87
88
|
const WBNB = Tokens[network]['WBNB'];
|
|
88
89
|
const USDT = Tokens[network]['USDT'];
|
|
89
90
|
|
|
90
|
-
const amounts = [
|
|
91
|
+
const amounts = [
|
|
92
|
+
0n,
|
|
93
|
+
1n * BI_POWS[18],
|
|
94
|
+
2n * BI_POWS[18],
|
|
95
|
+
];
|
|
91
96
|
|
|
92
97
|
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
93
98
|
WBNB,
|
|
@@ -95,7 +100,10 @@ describe('PancakeswapV3', function () {
|
|
|
95
100
|
SwapSide.SELL,
|
|
96
101
|
blockNumber,
|
|
97
102
|
);
|
|
98
|
-
console.log(
|
|
103
|
+
console.log(
|
|
104
|
+
`WBNB <> USDT Pool Identifiers: `,
|
|
105
|
+
pools,
|
|
106
|
+
);
|
|
99
107
|
|
|
100
108
|
expect(pools.length).toBeGreaterThan(0);
|
|
101
109
|
|
|
@@ -107,7 +115,10 @@ describe('PancakeswapV3', function () {
|
|
|
107
115
|
blockNumber,
|
|
108
116
|
pools,
|
|
109
117
|
);
|
|
110
|
-
console.log(
|
|
118
|
+
console.log(
|
|
119
|
+
`WBNB <> USDT Pool Prices: `,
|
|
120
|
+
poolPrices,
|
|
121
|
+
);
|
|
111
122
|
|
|
112
123
|
expect(poolPrices).not.toBeNull();
|
|
113
124
|
checkPoolPrices(
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
PoolState,
|
|
29
29
|
UniswapV3Data,
|
|
30
30
|
UniswapV3Functions,
|
|
31
|
-
|
|
31
|
+
UniswapV3Param,
|
|
32
32
|
} from '../uniswap-v3/types';
|
|
33
33
|
import {
|
|
34
34
|
getLocalDeadlineAsFriendlyPlaceholder,
|
|
@@ -69,7 +69,7 @@ const PANCAKESWAPV3_QUOTE_GASLIMIT = 200_000;
|
|
|
69
69
|
|
|
70
70
|
export class PancakeswapV3
|
|
71
71
|
extends SimpleExchange
|
|
72
|
-
implements IDex<UniswapV3Data>
|
|
72
|
+
implements IDex<UniswapV3Data, UniswapV3Param>
|
|
73
73
|
{
|
|
74
74
|
readonly isFeeOnTransferSupported: boolean = false;
|
|
75
75
|
readonly eventPools: Record<string, PancakeSwapV3EventPool | null> = {};
|
|
@@ -733,7 +733,7 @@ export class PancakeswapV3
|
|
|
733
733
|
: UniswapV3Functions.exactOutput;
|
|
734
734
|
|
|
735
735
|
const path = this._encodePath(data.path, side);
|
|
736
|
-
const swapFunctionParams:
|
|
736
|
+
const swapFunctionParams: UniswapV3Param =
|
|
737
737
|
side === SwapSide.SELL
|
|
738
738
|
? {
|
|
739
739
|
recipient: this.augustusAddress,
|
|
@@ -2,7 +2,10 @@ import { BytesLike, ethers } from 'ethers';
|
|
|
2
2
|
import { assert } from 'ts-essentials';
|
|
3
3
|
import { extractSuccessAndValue } from '../../lib/decoders';
|
|
4
4
|
import { MultiResult } from '../../lib/multi-wrapper';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DecodedStateMultiCallResultWithRelativeBitmaps,
|
|
7
|
+
} from '../uniswap-v3/types';
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
export function decodeStateMultiCallResultWithRelativeBitmaps(
|
|
8
11
|
result: MultiResult<BytesLike> | BytesLike,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Interface } from '@ethersproject/abi';
|
|
2
2
|
import Web3Abi, { AbiCoder } from 'web3-eth-abi';
|
|
3
|
-
import { Contract } from 'web3-eth-contract';
|
|
4
3
|
import { Address, SimpleExchangeParam, NumberAsString } from '../types';
|
|
5
4
|
import { CACHE_PREFIX, ETHER_ADDRESS } from '../constants';
|
|
6
5
|
import SimpleSwapHelperABI from '../abi/SimpleSwapHelperRouter.json';
|
|
@@ -10,7 +9,6 @@ import { isETHAddress } from '../utils';
|
|
|
10
9
|
import { MAX_UINT } from '../constants';
|
|
11
10
|
import Web3 from 'web3';
|
|
12
11
|
import { IDexHelper } from '../dex-helper';
|
|
13
|
-
import { AbiItem } from 'web3-utils';
|
|
14
12
|
|
|
15
13
|
/*
|
|
16
14
|
* Context: Augustus routers have all a deadline protection logic implemented globally.
|
|
@@ -28,7 +26,6 @@ export class SimpleExchange {
|
|
|
28
26
|
simpleSwapHelper: Interface;
|
|
29
27
|
protected abiCoder: AbiCoder;
|
|
30
28
|
erc20Interface: Interface;
|
|
31
|
-
erc20Contract: Contract;
|
|
32
29
|
|
|
33
30
|
needWrapNative = false;
|
|
34
31
|
isFeeOnTransferSupported = false;
|
|
@@ -45,9 +42,6 @@ export class SimpleExchange {
|
|
|
45
42
|
constructor(dexHelper: IDexHelper, public dexKey: string) {
|
|
46
43
|
this.simpleSwapHelper = new Interface(SimpleSwapHelperABI);
|
|
47
44
|
this.erc20Interface = new Interface(ERC20ABI);
|
|
48
|
-
this.erc20Contract = new dexHelper.web3Provider.eth.Contract(
|
|
49
|
-
ERC20ABI as AbiItem[],
|
|
50
|
-
);
|
|
51
45
|
this.abiCoder = Web3Abi as unknown as AbiCoder;
|
|
52
46
|
|
|
53
47
|
this.network = dexHelper.config.data.network;
|
|
@@ -114,6 +114,17 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
|
|
|
114
114
|
feeCode: 2,
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
|
+
Chronos: {
|
|
118
|
+
[Network.ARBITRUM]: {
|
|
119
|
+
subgraphURL: 'https://api.thegraph.com/subgraphs/name/xliee/chronos',
|
|
120
|
+
factoryAddress: '0xce9240869391928253ed9cc9bcb8cb98cb5b0722',
|
|
121
|
+
router: '0xb2634B3CBc1E401AB3C2743DB44d459C5c9aA662',
|
|
122
|
+
initCode:
|
|
123
|
+
'0x1840ae455256f509042de907fe0623f2e5e0ad44751ef974c4c37c1e516b7644',
|
|
124
|
+
poolGasCost: 180 * 1000,
|
|
125
|
+
feeCode: 0,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
117
128
|
};
|
|
118
129
|
|
|
119
130
|
export const Adapters: Record<number, AdapterMappings> = {
|
|
@@ -135,4 +146,7 @@ export const Adapters: Record<number, AdapterMappings> = {
|
|
|
135
146
|
[Network.AVALANCHE]: {
|
|
136
147
|
[SwapSide.SELL]: [{ name: 'AvalancheAdapter02', index: 3 }], // solisnek
|
|
137
148
|
},
|
|
149
|
+
[Network.ARBITRUM]: {
|
|
150
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter02', index: 1 }], // chronos
|
|
151
|
+
},
|
|
138
152
|
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Solidly } from '../solidly';
|
|
2
|
+
import { SolidlyPair } from '../types';
|
|
3
|
+
import { Network, SUBGRAPH_TIMEOUT } from '../../../constants';
|
|
4
|
+
import { IDexHelper } from '../../../dex-helper';
|
|
5
|
+
import { Interface } from '@ethersproject/abi';
|
|
6
|
+
import { getDexKeysWithNetwork } from '../../../utils';
|
|
7
|
+
import { SolidlyConfig } from '../config';
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import { Address, PoolLiquidity } from '../../../types';
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
|
|
12
|
+
const ChronosFactoryABI = [
|
|
13
|
+
{
|
|
14
|
+
inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
|
|
15
|
+
name: 'getFee',
|
|
16
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
17
|
+
stateMutability: 'view',
|
|
18
|
+
type: 'function',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const chronosFactoryIface = new Interface(ChronosFactoryABI);
|
|
23
|
+
|
|
24
|
+
type ChronosSubgraphPool = {
|
|
25
|
+
id: string;
|
|
26
|
+
isStable: boolean;
|
|
27
|
+
token0: { id: string; decimals: string };
|
|
28
|
+
reserve0: string;
|
|
29
|
+
reserve1: string;
|
|
30
|
+
token1: { id: string; decimals: string; };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export class Chronos extends Solidly {
|
|
34
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
35
|
+
getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Chronos']));
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
protected network: Network,
|
|
39
|
+
dexKey: string,
|
|
40
|
+
protected dexHelper: IDexHelper,
|
|
41
|
+
) {
|
|
42
|
+
super(
|
|
43
|
+
network,
|
|
44
|
+
dexKey,
|
|
45
|
+
dexHelper,
|
|
46
|
+
true, // dynamic fees
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected getFeesMultiCallData(pair: SolidlyPair) {
|
|
51
|
+
const callEntry = {
|
|
52
|
+
target: this.factoryAddress,
|
|
53
|
+
callData: chronosFactoryIface.encodeFunctionData('getFee', [pair.stable]),
|
|
54
|
+
};
|
|
55
|
+
const callDecoder = (values: any[]) =>
|
|
56
|
+
parseInt(
|
|
57
|
+
chronosFactoryIface
|
|
58
|
+
.decodeFunctionResult('getFee', values)[0]
|
|
59
|
+
.toString(),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
callEntry,
|
|
64
|
+
callDecoder,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getTopPoolsForToken(
|
|
69
|
+
tokenAddress: Address,
|
|
70
|
+
count: number,
|
|
71
|
+
): Promise<PoolLiquidity[]> {
|
|
72
|
+
if (!this.subgraphURL) return [];
|
|
73
|
+
|
|
74
|
+
const query = `query ($token: Bytes!, $count: Int) {
|
|
75
|
+
pools0: pairs(first: $count, orderBy: reserve0, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
|
|
76
|
+
id
|
|
77
|
+
isStable
|
|
78
|
+
token0 {
|
|
79
|
+
id
|
|
80
|
+
decimals
|
|
81
|
+
}
|
|
82
|
+
token1 {
|
|
83
|
+
id
|
|
84
|
+
decimals
|
|
85
|
+
}
|
|
86
|
+
reserve0,
|
|
87
|
+
reserve1,
|
|
88
|
+
}
|
|
89
|
+
pools1: pairs(first: $count, orderBy: reserve1, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
|
|
90
|
+
id
|
|
91
|
+
isStable
|
|
92
|
+
token0 {
|
|
93
|
+
id
|
|
94
|
+
decimals
|
|
95
|
+
}
|
|
96
|
+
token1 {
|
|
97
|
+
id
|
|
98
|
+
decimals
|
|
99
|
+
},
|
|
100
|
+
reserve0,
|
|
101
|
+
reserve1,
|
|
102
|
+
}
|
|
103
|
+
}`;
|
|
104
|
+
|
|
105
|
+
const { data } = await this.dexHelper.httpRequest.post(
|
|
106
|
+
this.subgraphURL,
|
|
107
|
+
{
|
|
108
|
+
query,
|
|
109
|
+
variables: { token: tokenAddress.toLowerCase(), count },
|
|
110
|
+
},
|
|
111
|
+
SUBGRAPH_TIMEOUT,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
if (!(data && data.pools0 && data.pools1))
|
|
115
|
+
throw new Error("Couldn't fetch the pools from the subgraph");
|
|
116
|
+
|
|
117
|
+
const pools0 = await this.prepareSubgraphPools(data.pools0, (pool,{
|
|
118
|
+
address1, decimals1, liquidityUSDToken0, liquidityUSDToken1,
|
|
119
|
+
}) => ({
|
|
120
|
+
exchange: this.dexKey,
|
|
121
|
+
stable: pool.isStable,
|
|
122
|
+
address: pool.id.toLowerCase(),
|
|
123
|
+
connectorTokens: [
|
|
124
|
+
{
|
|
125
|
+
address: address1,
|
|
126
|
+
decimals: decimals1,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
liquidityUSD: parseFloat((liquidityUSDToken0 + liquidityUSDToken1).toFixed()),
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
const pools1 = await this.prepareSubgraphPools(data.pools1, (pool,{
|
|
133
|
+
address0, decimals0, liquidityUSDToken0, liquidityUSDToken1,
|
|
134
|
+
}) => ({
|
|
135
|
+
exchange: this.dexKey,
|
|
136
|
+
stable: pool.isStable,
|
|
137
|
+
address: pool.id.toLowerCase(),
|
|
138
|
+
connectorTokens: [
|
|
139
|
+
{
|
|
140
|
+
address: address0,
|
|
141
|
+
decimals: decimals0,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
liquidityUSD: parseFloat((liquidityUSDToken0 + liquidityUSDToken1).toFixed()),
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
return _.slice(
|
|
148
|
+
_.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
|
|
149
|
+
0,
|
|
150
|
+
count,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async prepareSubgraphPools(
|
|
155
|
+
pools: ChronosSubgraphPool[],
|
|
156
|
+
iterator: (
|
|
157
|
+
pool: ChronosSubgraphPool, {
|
|
158
|
+
address0,
|
|
159
|
+
address1,
|
|
160
|
+
decimals0,
|
|
161
|
+
decimals1,
|
|
162
|
+
reserve0,
|
|
163
|
+
reserve1,
|
|
164
|
+
liquidityUSDToken0,
|
|
165
|
+
liquidityUSDToken1,
|
|
166
|
+
}: {
|
|
167
|
+
address0: string,
|
|
168
|
+
address1: string,
|
|
169
|
+
decimals0: number,
|
|
170
|
+
decimals1: number,
|
|
171
|
+
reserve0: bigint,
|
|
172
|
+
reserve1: bigint,
|
|
173
|
+
liquidityUSDToken0: number,
|
|
174
|
+
liquidityUSDToken1: number,
|
|
175
|
+
}) => PoolLiquidity
|
|
176
|
+
): Promise<PoolLiquidity[]> {
|
|
177
|
+
return Promise.all(pools.map(async (
|
|
178
|
+
pool: ChronosSubgraphPool,
|
|
179
|
+
) => {
|
|
180
|
+
const address0 = pool.token0.id.toLowerCase();
|
|
181
|
+
const address1 = pool.token1.id.toLowerCase();
|
|
182
|
+
|
|
183
|
+
const decimals0 = parseInt(pool.token0.decimals);
|
|
184
|
+
const decimals1 = parseInt(pool.token1.decimals);
|
|
185
|
+
|
|
186
|
+
const reserve0 = BigInt(new BigNumber(pool.reserve0).multipliedBy(10 ** decimals0).toFixed());
|
|
187
|
+
const reserve1 = BigInt(new BigNumber(pool.reserve1).multipliedBy(10 ** decimals1).toFixed());
|
|
188
|
+
|
|
189
|
+
const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice({
|
|
190
|
+
address: address0,
|
|
191
|
+
decimals: decimals0,
|
|
192
|
+
}, reserve0);
|
|
193
|
+
|
|
194
|
+
const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice({
|
|
195
|
+
address: address1,
|
|
196
|
+
decimals: decimals1,
|
|
197
|
+
}, reserve1);
|
|
198
|
+
|
|
199
|
+
return iterator(
|
|
200
|
+
pool, {
|
|
201
|
+
address0, address1, decimals0, decimals1, reserve0, reserve1, liquidityUSDToken0, liquidityUSDToken1,
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
}
|