@paraswap/dex-lib 2.12.15-friendly-local-deadline.1 → 2.12.15
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/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.vscode/launch.json +21 -0
- package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +50 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/mainnet.json +44 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +98 -0
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +79 -0
- package/build/dex/balancer-v2/VirtualBoostedPool.js +382 -0
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +1 -0
- package/build/dex/generic-rfq/e2e-test-config.d.ts +9 -0
- package/build/dex/generic-rfq/e2e-test-config.js +33 -0
- package/build/dex/generic-rfq/e2e-test-config.js.map +1 -0
- package/build/dex/generic-rfq/rate-fetcher.js +2 -0
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/validators.d.ts +1 -1
- package/build/dex/generic-rfq/validators.js +36 -26
- package/build/dex/generic-rfq/validators.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1.js +4 -4
- package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
- package/build/dex/maverick-v1/types.d.ts +3 -2
- package/build/dex/maverick-v1/types.js.map +1 -1
- package/build/dex/platypus/platypus.js +3 -3
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/shell.d.ts +1 -1
- package/build/dex/shell.js +1 -1
- package/build/dex/shell.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +1 -2
- package/build/dex/simple-exchange.js +4 -12
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/test-aave-v3/config.d.ts +4 -0
- package/build/dex/test-aave-v3/config.js +15 -0
- package/build/dex/test-aave-v3/config.js.map +1 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.d.ts +39 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.js +63 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +1 -0
- package/build/dex/test-aave-v3/test-aave-v3.d.ts +37 -0
- package/build/dex/test-aave-v3/test-aave-v3.js +126 -0
- package/build/dex/test-aave-v3/test-aave-v3.js.map +1 -0
- package/build/dex/test-aave-v3/types.d.ts +6 -0
- package/build/dex/test-aave-v3/types.js +3 -0
- package/build/dex/test-aave-v3/types.js.map +1 -0
- package/build/dex/trader-joe-v2.d.ts +2 -1
- package/build/dex/trader-joe-v2.js +3 -3
- package/build/dex/trader-joe-v2.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +2 -2
- package/build/dex/uniswap-v3/uniswap-v3.js +3 -3
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/uniswap-v3.d.ts +3 -2
- package/build/dex/uniswap-v3.js +5 -5
- package/build/dex/uniswap-v3.js.map +1 -1
- package/build/lib/fetcher/fetcher.js +3 -0
- package/build/lib/fetcher/fetcher.js.map +1 -1
- package/build/transaction-builder.js +0 -9
- package/build/transaction-builder.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/generic-rfq/e2e-test-config.ts +37 -0
- package/src/dex/generic-rfq/generic-rfq-e2e-arbitrum.test.ts +360 -0
- package/src/dex/generic-rfq/generic-rfq-e2e-bsc.test.ts +346 -0
- package/src/dex/generic-rfq/generic-rfq-e2e-polygon.test.ts +360 -0
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +63 -258
- package/src/dex/generic-rfq/generic-rfq-local-e2e.test.ts +121 -0
- package/src/dex/generic-rfq/rate-fetcher.ts +2 -0
- package/src/dex/generic-rfq/validators.test.ts +6 -32
- package/src/dex/generic-rfq/validators.ts +57 -32
- package/src/dex/maverick-v1/maverick-v1.ts +5 -8
- package/src/dex/maverick-v1/types.ts +3 -2
- package/src/dex/platypus/platypus.ts +4 -7
- package/src/dex/shell.ts +4 -6
- package/src/dex/simple-exchange.ts +4 -12
- package/src/dex/trader-joe-v2.ts +6 -8
- package/src/dex/uniswap-v3/types.ts +2 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +4 -7
- package/src/dex/uniswap-v3.ts +9 -11
- package/src/lib/fetcher/fetcher.ts +6 -0
- package/src/transaction-builder.ts +0 -15
- package/tests/constants-e2e.ts +2 -0
- package/tests/utils-e2e.ts +59 -48
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
|
+
import { Network, ContractMethod, SwapSide, MAX_UINT } from '../../constants';
|
|
6
|
+
import { generateConfig } from '../../config';
|
|
7
|
+
import { newTestE2E } from '../../../tests/utils-e2e';
|
|
8
|
+
import { SmartTokens, GENERIC_ADDR1 } from '../../../tests/constants-e2e';
|
|
9
|
+
import { startTestServer } from './example-api.test';
|
|
10
|
+
|
|
11
|
+
const PK_KEY = process.env.TEST_PK_KEY;
|
|
12
|
+
|
|
13
|
+
if (!PK_KEY) {
|
|
14
|
+
throw new Error('Missing TEST_PK_KEY');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const testAccount = new ethers.Wallet(PK_KEY!);
|
|
18
|
+
|
|
19
|
+
jest.setTimeout(1000 * 60 * 3);
|
|
20
|
+
|
|
21
|
+
describe('GenericRFQ E2E Mainnet', () => {
|
|
22
|
+
let stopServer: undefined | Function = undefined;
|
|
23
|
+
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
stopServer = startTestServer(testAccount);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const network = Network.MAINNET;
|
|
29
|
+
const smartTokens = SmartTokens[network];
|
|
30
|
+
|
|
31
|
+
const srcToken = smartTokens.WETH;
|
|
32
|
+
const destToken = smartTokens.DAI;
|
|
33
|
+
|
|
34
|
+
const config = generateConfig(network);
|
|
35
|
+
|
|
36
|
+
describe('GenericRFQ', () => {
|
|
37
|
+
const dexKey = 'DummyParaSwapPool';
|
|
38
|
+
|
|
39
|
+
srcToken.addBalance(testAccount.address, MAX_UINT);
|
|
40
|
+
srcToken.addAllowance(
|
|
41
|
+
testAccount.address,
|
|
42
|
+
config.augustusRFQAddress,
|
|
43
|
+
MAX_UINT,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
destToken.addBalance(testAccount.address, MAX_UINT);
|
|
47
|
+
destToken.addAllowance(
|
|
48
|
+
testAccount.address,
|
|
49
|
+
config.augustusRFQAddress,
|
|
50
|
+
MAX_UINT,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
describe('Simpleswap', () => {
|
|
54
|
+
it('SELL WETH -> DAI', async () => {
|
|
55
|
+
await newTestE2E({
|
|
56
|
+
config,
|
|
57
|
+
srcToken,
|
|
58
|
+
destToken,
|
|
59
|
+
senderAddress: GENERIC_ADDR1,
|
|
60
|
+
thirdPartyAddress: testAccount.address,
|
|
61
|
+
_amount: '1000000000000000000',
|
|
62
|
+
swapSide: SwapSide.SELL,
|
|
63
|
+
dexKey: dexKey,
|
|
64
|
+
contractMethod: ContractMethod.simpleSwap,
|
|
65
|
+
network: network,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('SELL DAI -> WETH', async () => {
|
|
70
|
+
await newTestE2E({
|
|
71
|
+
config,
|
|
72
|
+
destToken,
|
|
73
|
+
srcToken,
|
|
74
|
+
senderAddress: GENERIC_ADDR1,
|
|
75
|
+
thirdPartyAddress: testAccount.address,
|
|
76
|
+
_amount: '1000000000000000000',
|
|
77
|
+
swapSide: SwapSide.SELL,
|
|
78
|
+
dexKey: dexKey,
|
|
79
|
+
contractMethod: ContractMethod.simpleSwap,
|
|
80
|
+
network: network,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('BUY WETH -> DAI', async () => {
|
|
85
|
+
await newTestE2E({
|
|
86
|
+
config,
|
|
87
|
+
srcToken,
|
|
88
|
+
destToken,
|
|
89
|
+
senderAddress: GENERIC_ADDR1,
|
|
90
|
+
thirdPartyAddress: testAccount.address,
|
|
91
|
+
_amount: '1000000000000000000',
|
|
92
|
+
swapSide: SwapSide.BUY,
|
|
93
|
+
dexKey: dexKey,
|
|
94
|
+
contractMethod: ContractMethod.simpleBuy,
|
|
95
|
+
network: network,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('BUY DAI -> WETH', async () => {
|
|
100
|
+
await newTestE2E({
|
|
101
|
+
config,
|
|
102
|
+
destToken,
|
|
103
|
+
srcToken,
|
|
104
|
+
senderAddress: GENERIC_ADDR1,
|
|
105
|
+
thirdPartyAddress: testAccount.address,
|
|
106
|
+
_amount: '1000000000000000000',
|
|
107
|
+
swapSide: SwapSide.BUY,
|
|
108
|
+
dexKey: dexKey,
|
|
109
|
+
contractMethod: ContractMethod.simpleBuy,
|
|
110
|
+
network: network,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
afterAll(() => {
|
|
117
|
+
if (stopServer) {
|
|
118
|
+
stopServer();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -403,9 +403,11 @@ export class RateFetcher {
|
|
|
403
403
|
delete payload.secret;
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
this.logger.debug('FirmRate Request:', payload);
|
|
406
407
|
const { data } = await this.dexHelper.httpRequest.request<unknown>(
|
|
407
408
|
payload,
|
|
408
409
|
);
|
|
410
|
+
this.logger.debug('FirmRate Response: ', data);
|
|
409
411
|
|
|
410
412
|
const firmRateResp = validateAndCast<RFQFirmRateResponse>(
|
|
411
413
|
data,
|
|
@@ -112,10 +112,11 @@ describe('GenericRFQ Validator test', () => {
|
|
|
112
112
|
},
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
const
|
|
115
|
+
const pricesNegativeSpread = {
|
|
116
116
|
prices: {
|
|
117
117
|
'WETH/DAI': {
|
|
118
118
|
bids: [
|
|
119
|
+
['1337.425240000000000000', '1.166200000000000000'],
|
|
119
120
|
['1333.024812000000000000', '1.166200000000000000'],
|
|
120
121
|
['1333.425240000000000000', '1.166200000000000000'],
|
|
121
122
|
['1332.624384000000000000', '1.166200000000000000'],
|
|
@@ -135,29 +136,6 @@ describe('GenericRFQ Validator test', () => {
|
|
|
135
136
|
},
|
|
136
137
|
};
|
|
137
138
|
|
|
138
|
-
const pricesInvalidAskNotSortedAsc = {
|
|
139
|
-
prices: {
|
|
140
|
-
'WETH/DAI': {
|
|
141
|
-
bids: [
|
|
142
|
-
['1333.425240000000000000', '1.166200000000000000'],
|
|
143
|
-
['1333.024812000000000000', '1.166200000000000000'],
|
|
144
|
-
['1332.624384000000000000', '1.166200000000000000'],
|
|
145
|
-
['1332.223956000000000000', '1.166200000000000000'],
|
|
146
|
-
['1331.823528000000000000', '1.166200000000000000'],
|
|
147
|
-
['1331.423100000000000000', '1.169000000000000000'],
|
|
148
|
-
],
|
|
149
|
-
asks: [
|
|
150
|
-
['1337.146033000000000000', '1.166200000000000000'],
|
|
151
|
-
['1336.745410000000000000', '1.166200000000000000'],
|
|
152
|
-
['1337.546656000000000000', '1.166200000000000000'],
|
|
153
|
-
['1337.947279000000000000', '1.166200000000000000'],
|
|
154
|
-
['1338.347902000000000000', '1.166200000000000000'],
|
|
155
|
-
['1338.748525000000000000', '1.169000000000000000'],
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
139
|
const noPrices = {
|
|
162
140
|
prices: {
|
|
163
141
|
'WETH/DAI': {},
|
|
@@ -200,12 +178,6 @@ describe('GenericRFQ Validator test', () => {
|
|
|
200
178
|
|
|
201
179
|
it('Price test', () => {
|
|
202
180
|
expect(() => validateAndCast(prices, pricesResponse)).not.toThrowError();
|
|
203
|
-
expect(() =>
|
|
204
|
-
validateAndCast(pricesInvalidBidsNotSortedDesc, pricesResponse),
|
|
205
|
-
).toThrowError();
|
|
206
|
-
expect(() =>
|
|
207
|
-
validateAndCast(pricesInvalidAskNotSortedAsc, pricesResponse),
|
|
208
|
-
).toThrowError();
|
|
209
181
|
expect(() =>
|
|
210
182
|
validateAndCast(noPrices, pricesResponse),
|
|
211
183
|
).not.toThrowError();
|
|
@@ -218,6 +190,9 @@ describe('GenericRFQ Validator test', () => {
|
|
|
218
190
|
expect(() =>
|
|
219
191
|
validateAndCast(onlyAsks, pricesResponse),
|
|
220
192
|
).not.toThrowError();
|
|
193
|
+
expect(() =>
|
|
194
|
+
validateAndCast(pricesNegativeSpread, pricesResponse),
|
|
195
|
+
).toThrowError('the maximum bid is higher than minimum ask');
|
|
221
196
|
});
|
|
222
197
|
});
|
|
223
198
|
|
|
@@ -261,11 +236,10 @@ describe('GenericRFQ Validator test', () => {
|
|
|
261
236
|
},
|
|
262
237
|
};
|
|
263
238
|
|
|
264
|
-
it('
|
|
239
|
+
it('Order test', () => {
|
|
265
240
|
expect(() =>
|
|
266
241
|
validateAndCast(order, firmRateResponseValidator),
|
|
267
242
|
).not.toThrowError();
|
|
268
|
-
// expect(() => validateAndCast(invalidBlacklist, blacklistResponseValidator)).toThrowError();
|
|
269
243
|
});
|
|
270
244
|
});
|
|
271
245
|
});
|
|
@@ -56,7 +56,7 @@ const stringNumberValidator = (
|
|
|
56
56
|
return value;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const pricesValidator = joi
|
|
60
60
|
.array()
|
|
61
61
|
.items(
|
|
62
62
|
joi
|
|
@@ -66,47 +66,58 @@ const pricesValidatorWithoutSorting = joi
|
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
const ext: joi.Extension = {
|
|
69
|
-
type: '
|
|
70
|
-
base:
|
|
69
|
+
type: 'validatedPrices',
|
|
70
|
+
base: joi.object({
|
|
71
|
+
bids: pricesValidator,
|
|
72
|
+
asks: pricesValidator,
|
|
73
|
+
}),
|
|
71
74
|
rules: {
|
|
72
|
-
|
|
73
|
-
validate: (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
bidsLowerThanAsks: {
|
|
76
|
+
validate: (
|
|
77
|
+
values: { bids: string[]; asks: string[] },
|
|
78
|
+
helpers: CustomHelpers,
|
|
79
|
+
) => {
|
|
80
|
+
if (
|
|
81
|
+
!values.bids ||
|
|
82
|
+
!values.asks ||
|
|
83
|
+
values.bids.length === 0 ||
|
|
84
|
+
values.asks.length === 0
|
|
85
|
+
) {
|
|
86
|
+
return values;
|
|
87
|
+
}
|
|
88
|
+
const maxBid = values.bids
|
|
89
|
+
.map(numbers => new BigNumber(numbers[0]))
|
|
90
|
+
.reduce(
|
|
91
|
+
(previousValue, currentValue) =>
|
|
92
|
+
currentValue.gte(previousValue) ? currentValue : previousValue,
|
|
93
|
+
new BigNumber(0),
|
|
94
|
+
);
|
|
95
|
+
const minAsk = values.asks
|
|
96
|
+
.map(numbers => new BigNumber(numbers[0]))
|
|
97
|
+
.reduce(
|
|
98
|
+
(previousValue, currentValue) =>
|
|
99
|
+
currentValue.lte(previousValue) ? currentValue : previousValue,
|
|
100
|
+
new BigNumber('123456789012345678901234567890'),
|
|
101
|
+
);
|
|
102
|
+
return maxBid < minAsk
|
|
79
103
|
? values
|
|
80
104
|
: helpers.message({
|
|
81
|
-
custom:
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
desc: {
|
|
86
|
-
validate: (values: string[][], helpers: CustomHelpers) => {
|
|
87
|
-
const prices = values.map(numbers => new BigNumber(numbers[0]));
|
|
88
|
-
const isAscOrder = prices.every(
|
|
89
|
-
(x, i) => i === 0 || x.lte(prices[i - 1]),
|
|
90
|
-
);
|
|
91
|
-
return isAscOrder
|
|
92
|
-
? values
|
|
93
|
-
: helpers.message({
|
|
94
|
-
custom: `array is not desc sorted ${JSON.stringify(values)}`,
|
|
105
|
+
custom: 'the maximum bid is higher than minimum ask',
|
|
95
106
|
});
|
|
96
107
|
},
|
|
97
108
|
},
|
|
98
109
|
},
|
|
99
110
|
};
|
|
100
111
|
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
export const priceValidator = joi.object({
|
|
104
|
-
bids: pricesArrayValidator.sortedArray().desc(),
|
|
105
|
-
asks: pricesArrayValidator.sortedArray().asc(),
|
|
106
|
-
});
|
|
112
|
+
export const priceValidator = joi.extend(ext);
|
|
107
113
|
|
|
108
114
|
export const pricesResponse = joi.object({
|
|
109
|
-
prices: joi
|
|
115
|
+
prices: joi
|
|
116
|
+
.object()
|
|
117
|
+
.pattern(
|
|
118
|
+
joi.string().min(1),
|
|
119
|
+
priceValidator.validatedPrices().bidsLowerThanAsks(),
|
|
120
|
+
),
|
|
110
121
|
});
|
|
111
122
|
|
|
112
123
|
export const validateAndCast = <T>(
|
|
@@ -171,12 +182,26 @@ const stringStartWithHex0x = (
|
|
|
171
182
|
return value;
|
|
172
183
|
};
|
|
173
184
|
|
|
185
|
+
const mustBeAugustusSwapper = (
|
|
186
|
+
value: string,
|
|
187
|
+
helpers: CustomHelpers,
|
|
188
|
+
): string | ErrorReport => {
|
|
189
|
+
const allowedTakers = [
|
|
190
|
+
'0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57'.toLowerCase(),
|
|
191
|
+
];
|
|
192
|
+
return allowedTakers.includes(value.toLowerCase())
|
|
193
|
+
? value
|
|
194
|
+
: helpers.message({
|
|
195
|
+
custom: `"order.taker" must be any of ${JSON.stringify(allowedTakers)}`,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
174
199
|
export const orderWithSignatureValidator = joi
|
|
175
200
|
.object({
|
|
176
201
|
nonceAndMeta: joi.string().custom(stringPositiveBigIntValidator),
|
|
177
202
|
expiry: joi.number().min(0),
|
|
178
203
|
maker: addressSchema.required(),
|
|
179
|
-
taker: addressSchema.required(),
|
|
204
|
+
taker: addressSchema.required().custom(mustBeAugustusSwapper),
|
|
180
205
|
makerAsset: addressSchema.required(),
|
|
181
206
|
takerAsset: addressSchema.required(),
|
|
182
207
|
makerAmount: joi
|
|
@@ -20,10 +20,7 @@ import {
|
|
|
20
20
|
MaverickV1Param,
|
|
21
21
|
SubgraphPoolBase,
|
|
22
22
|
} from './types';
|
|
23
|
-
import {
|
|
24
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
25
|
-
SimpleExchange,
|
|
26
|
-
} from '../simple-exchange';
|
|
23
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
27
24
|
import {
|
|
28
25
|
MaverickV1Config,
|
|
29
26
|
Adapters,
|
|
@@ -294,7 +291,7 @@ export class MaverickV1
|
|
|
294
291
|
data: MaverickV1Data,
|
|
295
292
|
side: SwapSide,
|
|
296
293
|
): AdapterExchangeParam {
|
|
297
|
-
const { pool } = data;
|
|
294
|
+
const { deadline, pool } = data;
|
|
298
295
|
const payload = this.abiCoder.encodeParameter(
|
|
299
296
|
{
|
|
300
297
|
ParentStruct: {
|
|
@@ -304,7 +301,7 @@ export class MaverickV1
|
|
|
304
301
|
},
|
|
305
302
|
{
|
|
306
303
|
pool,
|
|
307
|
-
deadline:
|
|
304
|
+
deadline: deadline || this.getDeadline(),
|
|
308
305
|
},
|
|
309
306
|
);
|
|
310
307
|
|
|
@@ -332,7 +329,7 @@ export class MaverickV1
|
|
|
332
329
|
side === SwapSide.SELL
|
|
333
330
|
? {
|
|
334
331
|
recipient: this.augustusAddress,
|
|
335
|
-
deadline:
|
|
332
|
+
deadline: this.getDeadline(),
|
|
336
333
|
amountIn: srcAmount,
|
|
337
334
|
amountOutMinimum: destAmount,
|
|
338
335
|
tokenIn: srcToken,
|
|
@@ -342,7 +339,7 @@ export class MaverickV1
|
|
|
342
339
|
}
|
|
343
340
|
: {
|
|
344
341
|
recipient: this.augustusAddress,
|
|
345
|
-
deadline:
|
|
342
|
+
deadline: this.getDeadline(),
|
|
346
343
|
amountOut: destAmount,
|
|
347
344
|
amountInMaximum: srcAmount,
|
|
348
345
|
tokenIn: srcToken,
|
|
@@ -45,6 +45,7 @@ export type MaverickV1Data = {
|
|
|
45
45
|
tokenA: Address;
|
|
46
46
|
tokenB: Address;
|
|
47
47
|
exchange: Address;
|
|
48
|
+
deadline?: number;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
export enum MaverickV1Functions {
|
|
@@ -57,7 +58,7 @@ export type MaverickV1SellParam = {
|
|
|
57
58
|
tokenOut: Address;
|
|
58
59
|
pool: Address;
|
|
59
60
|
recipient: Address;
|
|
60
|
-
deadline:
|
|
61
|
+
deadline: number;
|
|
61
62
|
amountIn: NumberAsString;
|
|
62
63
|
amountOutMinimum: NumberAsString;
|
|
63
64
|
sqrtPriceLimitD18: NumberAsString;
|
|
@@ -68,7 +69,7 @@ export type MaverickV1BuyParam = {
|
|
|
68
69
|
tokenOut: Address;
|
|
69
70
|
pool: Address;
|
|
70
71
|
recipient: Address;
|
|
71
|
-
deadline:
|
|
72
|
+
deadline: number;
|
|
72
73
|
amountOut: NumberAsString;
|
|
73
74
|
amountInMaximum: NumberAsString;
|
|
74
75
|
sqrtPriceLimitD18: NumberAsString;
|
|
@@ -21,10 +21,7 @@ import {
|
|
|
21
21
|
PlatypusData,
|
|
22
22
|
PlatypusConfigInfo,
|
|
23
23
|
} from './types';
|
|
24
|
-
import {
|
|
25
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
26
|
-
SimpleExchange,
|
|
27
|
-
} from '../simple-exchange';
|
|
24
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
28
25
|
import { PlatypusConfig, Adapters } from './config';
|
|
29
26
|
import { ChainLinkSubscriber } from '../../lib/chainlink';
|
|
30
27
|
import { PlatypusPoolBase } from './pool-base';
|
|
@@ -464,7 +461,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
464
461
|
destToken,
|
|
465
462
|
1,
|
|
466
463
|
this.augustusAddress,
|
|
467
|
-
|
|
464
|
+
this.getDeadline(),
|
|
468
465
|
])
|
|
469
466
|
: isETHAddress(destToken)
|
|
470
467
|
? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
|
|
@@ -472,7 +469,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
472
469
|
srcAmount,
|
|
473
470
|
1,
|
|
474
471
|
this.augustusAddress,
|
|
475
|
-
|
|
472
|
+
this.getDeadline(),
|
|
476
473
|
])
|
|
477
474
|
: Platypus.poolInterface.encodeFunctionData('swap', [
|
|
478
475
|
srcToken,
|
|
@@ -480,7 +477,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
480
477
|
srcAmount,
|
|
481
478
|
1,
|
|
482
479
|
this.augustusAddress,
|
|
483
|
-
|
|
480
|
+
this.getDeadline(),
|
|
484
481
|
]),
|
|
485
482
|
data.pool,
|
|
486
483
|
);
|
package/src/dex/shell.ts
CHANGED
|
@@ -2,11 +2,9 @@ import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
|
2
2
|
import { SwapSide } from '../constants';
|
|
3
3
|
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
4
|
import { IDexTxBuilder } from './idex';
|
|
5
|
-
import {
|
|
6
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
-
SimpleExchange,
|
|
8
|
-
} from './simple-exchange';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
9
6
|
import ShellABI from '../abi/Shell.json';
|
|
7
|
+
import Web3 from 'web3';
|
|
10
8
|
import { IDexHelper } from '../dex-helper';
|
|
11
9
|
|
|
12
10
|
export type ShellData = {
|
|
@@ -18,7 +16,7 @@ type ShellParam = [
|
|
|
18
16
|
_target: string,
|
|
19
17
|
_originAmount: string,
|
|
20
18
|
_minTargetAmount: string,
|
|
21
|
-
_deadline
|
|
19
|
+
_deadline?: number,
|
|
22
20
|
];
|
|
23
21
|
enum ShellFunctions {
|
|
24
22
|
originSwap = 'originSwap',
|
|
@@ -65,7 +63,7 @@ export class Shell
|
|
|
65
63
|
destToken,
|
|
66
64
|
srcAmount,
|
|
67
65
|
destAmount,
|
|
68
|
-
|
|
66
|
+
data.deadline || this.getDeadline(),
|
|
69
67
|
];
|
|
70
68
|
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
71
69
|
swapFunction,
|
|
@@ -10,18 +10,6 @@ import { MAX_UINT } from '../constants';
|
|
|
10
10
|
import Web3 from 'web3';
|
|
11
11
|
import { IDexHelper } from '../dex-helper';
|
|
12
12
|
|
|
13
|
-
/*
|
|
14
|
-
* Context: Augustus routers have all a deadline protection logic implemented globally.
|
|
15
|
-
* But some integrations (router, pools,...) require passing a deadline generally as uint256.
|
|
16
|
-
* While this problem can be solved in adapters easily by passing block.timestamp (or block.timestamp +1 for some marginal cases),
|
|
17
|
-
* In the context of direct calls like simpleSwap we have to generate this value offchain.
|
|
18
|
-
* One can naively pick type(uint).max but that would impose a higher gas cost on the calldata.
|
|
19
|
-
* Here we decide to go with a high enough default so that the local deadline rarely supersedes the global router deadline.
|
|
20
|
-
*/
|
|
21
|
-
export const FRIENDLY_LOCAL_DEADLINE = 7 * 24 * 60 * 60;
|
|
22
|
-
export const getLocalDeadlineAsFriendlyPlaceholder = () =>
|
|
23
|
-
String(Math.floor(new Date().getTime() / 1000) + FRIENDLY_LOCAL_DEADLINE);
|
|
24
|
-
|
|
25
13
|
export class SimpleExchange {
|
|
26
14
|
simpleSwapHelper: Interface;
|
|
27
15
|
protected abiCoder: AbiCoder;
|
|
@@ -134,4 +122,8 @@ export class SimpleExchange {
|
|
|
134
122
|
networkFee,
|
|
135
123
|
};
|
|
136
124
|
}
|
|
125
|
+
|
|
126
|
+
getDeadline() {
|
|
127
|
+
return Math.floor(new Date().getTime() / 1000) + 60 * 60;
|
|
128
|
+
}
|
|
137
129
|
}
|
package/src/dex/trader-joe-v2.ts
CHANGED
|
@@ -2,10 +2,7 @@ import { Network, SwapSide } from '../constants';
|
|
|
2
2
|
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
3
3
|
import { IDexTxBuilder } from './idex';
|
|
4
4
|
import { IDexHelper } from '../dex-helper';
|
|
5
|
-
import {
|
|
6
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
-
SimpleExchange,
|
|
8
|
-
} from './simple-exchange';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
9
6
|
import { NumberAsString } from '@paraswap/core';
|
|
10
7
|
import { AsyncOrSync } from 'ts-essentials';
|
|
11
8
|
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
@@ -32,7 +29,7 @@ type TraderJoeV2RouterBuyParams = [
|
|
|
32
29
|
_pairBinSteps: NumberAsString[],
|
|
33
30
|
_tokenPath: Address[],
|
|
34
31
|
to: Address,
|
|
35
|
-
_deadline:
|
|
32
|
+
_deadline: number,
|
|
36
33
|
];
|
|
37
34
|
|
|
38
35
|
type TraderJoeV2RouterParam =
|
|
@@ -40,6 +37,7 @@ type TraderJoeV2RouterParam =
|
|
|
40
37
|
| TraderJoeV2RouterBuyParams;
|
|
41
38
|
|
|
42
39
|
export type TraderJoeV2Data = {
|
|
40
|
+
deadline?: number;
|
|
43
41
|
tokenIn: string; // redundant
|
|
44
42
|
tokenOut: string; // redundant
|
|
45
43
|
binStep: string;
|
|
@@ -89,7 +87,7 @@ export class TraderJoeV2
|
|
|
89
87
|
{
|
|
90
88
|
_pairBinSteps: [data.binStep],
|
|
91
89
|
_tokenPath: [data.tokenIn, data.tokenOut], // FIXME: redundant, shoot & read from contract
|
|
92
|
-
_deadline:
|
|
90
|
+
_deadline: data.deadline || this.getDeadline(),
|
|
93
91
|
},
|
|
94
92
|
);
|
|
95
93
|
|
|
@@ -121,7 +119,7 @@ export class TraderJoeV2
|
|
|
121
119
|
[data.binStep],
|
|
122
120
|
[srcToken, destToken],
|
|
123
121
|
this.augustusAddress,
|
|
124
|
-
|
|
122
|
+
data.deadline || this.getDeadline(),
|
|
125
123
|
]
|
|
126
124
|
: [
|
|
127
125
|
destAmount,
|
|
@@ -129,7 +127,7 @@ export class TraderJoeV2
|
|
|
129
127
|
[data.binStep],
|
|
130
128
|
[srcToken, destToken],
|
|
131
129
|
this.augustusAddress,
|
|
132
|
-
|
|
130
|
+
data.deadline || this.getDeadline(),
|
|
133
131
|
];
|
|
134
132
|
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
135
133
|
swapFunction,
|
|
@@ -72,7 +72,7 @@ export type DexParams = {
|
|
|
72
72
|
export type UniswapV3SellParam = {
|
|
73
73
|
path: string;
|
|
74
74
|
recipient: Address;
|
|
75
|
-
deadline:
|
|
75
|
+
deadline: number;
|
|
76
76
|
amountIn: NumberAsString;
|
|
77
77
|
amountOutMinimum: NumberAsString;
|
|
78
78
|
};
|
|
@@ -80,7 +80,7 @@ export type UniswapV3SellParam = {
|
|
|
80
80
|
export type UniswapV3BuyParam = {
|
|
81
81
|
path: string;
|
|
82
82
|
recipient: Address;
|
|
83
|
-
deadline:
|
|
83
|
+
deadline: number;
|
|
84
84
|
amountOut: NumberAsString;
|
|
85
85
|
amountInMaximum: NumberAsString;
|
|
86
86
|
};
|
|
@@ -30,10 +30,7 @@ import {
|
|
|
30
30
|
UniswapV3Functions,
|
|
31
31
|
UniswapV3Param,
|
|
32
32
|
} from './types';
|
|
33
|
-
import {
|
|
34
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
35
|
-
SimpleExchange,
|
|
36
|
-
} from '../simple-exchange';
|
|
33
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
37
34
|
import { UniswapV3Config, Adapters, PoolsToPreload } from './config';
|
|
38
35
|
import { UniswapV3EventPool } from './uniswap-v3-pool';
|
|
39
36
|
import UniswapV3RouterABI from '../../abi/uniswap-v3/UniswapV3Router.abi.json';
|
|
@@ -689,7 +686,7 @@ export class UniswapV3
|
|
|
689
686
|
},
|
|
690
687
|
{
|
|
691
688
|
path,
|
|
692
|
-
deadline:
|
|
689
|
+
deadline: this.getDeadline(),
|
|
693
690
|
},
|
|
694
691
|
);
|
|
695
692
|
|
|
@@ -743,14 +740,14 @@ export class UniswapV3
|
|
|
743
740
|
side === SwapSide.SELL
|
|
744
741
|
? {
|
|
745
742
|
recipient: this.augustusAddress,
|
|
746
|
-
deadline:
|
|
743
|
+
deadline: this.getDeadline(),
|
|
747
744
|
amountIn: srcAmount,
|
|
748
745
|
amountOutMinimum: destAmount,
|
|
749
746
|
path,
|
|
750
747
|
}
|
|
751
748
|
: {
|
|
752
749
|
recipient: this.augustusAddress,
|
|
753
|
-
deadline:
|
|
750
|
+
deadline: this.getDeadline(),
|
|
754
751
|
amountOut: destAmount,
|
|
755
752
|
amountInMaximum: srcAmount,
|
|
756
753
|
path,
|