@paraswap/dex-lib 2.14.6 → 2.14.7-friendly-local-deadline.0
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/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 +2 -3
- 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 +2 -1
- package/build/dex/simple-exchange.js +12 -4
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/trader-joe-v2.d.ts +1 -2
- 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 +2 -3
- package/build/dex/uniswap-v3.js +5 -5
- package/build/dex/uniswap-v3.js.map +1 -1
- package/build/transaction-builder.js +7 -0
- package/build/transaction-builder.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +7 -3
- package/src/dex/maverick-v1/maverick-v1.ts +8 -5
- package/src/dex/maverick-v1/types.ts +2 -3
- package/src/dex/platypus/platypus.ts +7 -4
- package/src/dex/shell.ts +6 -4
- package/src/dex/simple-exchange.ts +12 -4
- package/src/dex/trader-joe-v2.ts +8 -6
- package/src/dex/uniswap-v3/types.ts +2 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +7 -4
- package/src/dex/uniswap-v3.ts +11 -9
- package/src/transaction-builder.ts +12 -0
- package/build/abi/maverick/pool.json +0 -913
- package/build/abi/maverick/router.json +0 -703
- package/build/dex/maverick/config.d.ts +0 -4
- package/build/dex/maverick/config.js +0 -20
- package/build/dex/maverick/config.js.map +0 -1
- package/build/dex/maverick/maverick-math/maverick-pool-math.d.ts +0 -67
- package/build/dex/maverick/maverick-math/maverick-pool-math.js +0 -406
- package/build/dex/maverick/maverick-math/maverick-pool-math.js.map +0 -1
- package/build/dex/maverick/maverick-math/maverick-sol-math.d.ts +0 -17
- package/build/dex/maverick/maverick-math/maverick-sol-math.js +0 -139
- package/build/dex/maverick/maverick-math/maverick-sol-math.js.map +0 -1
- package/build/dex/maverick/maverick-pool.d.ts +0 -41
- package/build/dex/maverick/maverick-pool.js +0 -130
- package/build/dex/maverick/maverick-pool.js.map +0 -1
- package/build/dex/maverick/maverick.d.ts +0 -42
- package/build/dex/maverick/maverick.js +0 -174
- package/build/dex/maverick/maverick.js.map +0 -1
- package/build/dex/maverick/subgraph-queries.d.ts +0 -4
- package/build/dex/maverick/subgraph-queries.js +0 -114
- package/build/dex/maverick/subgraph-queries.js.map +0 -1
- package/build/dex/maverick/types.d.ts +0 -46
- package/build/dex/maverick/types.js +0 -3
- package/build/dex/maverick/types.js.map +0 -1
|
@@ -3,12 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TransactionBuilder = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const router_1 = require("./router");
|
|
6
|
+
const simple_exchange_1 = require("./dex/simple-exchange");
|
|
6
7
|
class TransactionBuilder {
|
|
7
8
|
constructor(dexAdapterService) {
|
|
8
9
|
this.dexAdapterService = dexAdapterService;
|
|
9
10
|
this.routerService = new router_1.RouterService(this.dexAdapterService);
|
|
10
11
|
}
|
|
11
12
|
async build({ priceRoute, minMaxAmount, userAddress, referrerAddress, partnerAddress, partnerFeePercent, positiveSlippageToUser, gasPrice, maxFeePerGas, maxPriorityFeePerGas, permit, deadline, uuid, beneficiary, onlyParams = false, }) {
|
|
13
|
+
const globalDeadline = +deadline;
|
|
14
|
+
if (isNaN(globalDeadline))
|
|
15
|
+
throw new Error('deadline should be a number');
|
|
16
|
+
const localDeadline = +(0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)();
|
|
17
|
+
if (globalDeadline > localDeadline)
|
|
18
|
+
throw new Error(`Deadline is too high. Maximum allowed is ${simple_exchange_1.FRIENDLY_LOCAL_DEADLINE} seconds`);
|
|
12
19
|
const _beneficiary = beneficiary || userAddress;
|
|
13
20
|
const { encoder, params, networkFee } = await this.routerService
|
|
14
21
|
.getRouterByContractMethod(priceRoute.contractMethod)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-builder.js","sourceRoot":"","sources":["../src/transaction-builder.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,qCAAyC;
|
|
1
|
+
{"version":3,"file":"transaction-builder.js","sourceRoot":"","sources":["../src/transaction-builder.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,qCAAyC;AAEzC,2DAG+B;AAE/B,MAAa,kBAAkB;IAG7B,YAAsB,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACxD,IAAI,CAAC,aAAa,GAAG,IAAI,sBAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,UAAU,GAAG,KAAK,GAiBnB;QACC,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC;QACjC,IAAI,KAAK,CAAC,cAAc,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC1E,MAAM,aAAa,GAAG,CAAC,IAAA,uDAAqC,GAAE,CAAC;QAC/D,IAAI,cAAc,GAAG,aAAa;YAChC,MAAM,IAAI,KAAK,CACb,4CAA4C,yCAAuB,UAAU,CAC9E,CAAC;QAEJ,MAAM,YAAY,GAAG,WAAW,IAAI,WAAW,CAAC;QAChD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa;aAC7D,yBAAyB,CAAC,UAAU,CAAC,cAAc,CAAC;aACpD,KAAK,CACJ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,sBAAsB,IAAI,IAAI,EAC9B,YAAY,EACZ,MAAM,IAAI,IAAI,EACd,QAAQ,EACR,IAAI,CACL,CAAC;QAEJ,IAAI,UAAU;YAAE,OAAO,MAAM,CAAC;QAE9B,MAAM,KAAK,GAAG,CACZ,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,yBAAa,CAAC,WAAW,EAAE;YAC/D,CAAC,CAAC,MAAM,CACJ,UAAU,CAAC,IAAI,KAAK,oBAAQ,CAAC,IAAI;gBAC/B,CAAC,CAAC,UAAU,CAAC,SAAS;gBACtB,CAAC,CAAC,YAAY,CACjB,GAAG,MAAM,CAAC,UAAU,CAAC;YACxB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CACvB,CAAC,QAAQ,EAAE,CAAC;QAEb,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,EAAE,EAAE,UAAU,CAAC,eAAe;YAC9B,KAAK;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;YACjC,QAAQ;YACR,YAAY;YACZ,oBAAoB;SACrB,CAAC;IACJ,CAAC;CACF;AAvFD,gDAuFC"}
|
package/package.json
CHANGED
|
@@ -92,10 +92,14 @@ describe(`GenericRFQ ${dexKey} E2E`, () => {
|
|
|
92
92
|
describe(`${Network[network]}`, () => {
|
|
93
93
|
for (const testCase of testCases) {
|
|
94
94
|
if (!smartTokens.hasOwnProperty(testCase.srcToken)) {
|
|
95
|
-
throw new Error(
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Please add "addBalance" and "addAllowance" functions for ${testCase.srcToken} on ${Network[network]} (in constants-e2e.ts).`,
|
|
97
|
+
);
|
|
96
98
|
}
|
|
97
|
-
if (!smartTokens.hasOwnProperty(testCase.destToken)){
|
|
98
|
-
throw new Error(
|
|
99
|
+
if (!smartTokens.hasOwnProperty(testCase.destToken)) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Please add "addBalance" and "addAllowance" functions for ${testCase.destToken} on ${Network[network]} (in constants-e2e.ts).`,
|
|
102
|
+
);
|
|
99
103
|
}
|
|
100
104
|
const srcToken = smartTokens[testCase.srcToken];
|
|
101
105
|
const destToken = smartTokens[testCase.destToken];
|
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
MaverickV1Param,
|
|
22
22
|
SubgraphPoolBase,
|
|
23
23
|
} from './types';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
26
|
+
SimpleExchange,
|
|
27
|
+
} from '../simple-exchange';
|
|
25
28
|
import {
|
|
26
29
|
MaverickV1Config,
|
|
27
30
|
Adapters,
|
|
@@ -320,7 +323,7 @@ export class MaverickV1
|
|
|
320
323
|
data: MaverickV1Data,
|
|
321
324
|
side: SwapSide,
|
|
322
325
|
): AdapterExchangeParam {
|
|
323
|
-
const {
|
|
326
|
+
const { pool } = data;
|
|
324
327
|
const payload = this.abiCoder.encodeParameter(
|
|
325
328
|
{
|
|
326
329
|
ParentStruct: {
|
|
@@ -330,7 +333,7 @@ export class MaverickV1
|
|
|
330
333
|
},
|
|
331
334
|
{
|
|
332
335
|
pool,
|
|
333
|
-
deadline:
|
|
336
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
334
337
|
},
|
|
335
338
|
);
|
|
336
339
|
|
|
@@ -358,7 +361,7 @@ export class MaverickV1
|
|
|
358
361
|
side === SwapSide.SELL
|
|
359
362
|
? {
|
|
360
363
|
recipient: this.augustusAddress,
|
|
361
|
-
deadline:
|
|
364
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
362
365
|
amountIn: srcAmount,
|
|
363
366
|
amountOutMinimum: destAmount,
|
|
364
367
|
tokenIn: srcToken,
|
|
@@ -368,7 +371,7 @@ export class MaverickV1
|
|
|
368
371
|
}
|
|
369
372
|
: {
|
|
370
373
|
recipient: this.augustusAddress,
|
|
371
|
-
deadline:
|
|
374
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
372
375
|
amountOut: destAmount,
|
|
373
376
|
amountInMaximum: srcAmount,
|
|
374
377
|
tokenIn: srcToken,
|
|
@@ -45,7 +45,6 @@ export type MaverickV1Data = {
|
|
|
45
45
|
tokenA: Address;
|
|
46
46
|
tokenB: Address;
|
|
47
47
|
exchange: Address;
|
|
48
|
-
deadline?: number;
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
export enum MaverickV1Functions {
|
|
@@ -58,7 +57,7 @@ export type MaverickV1SellParam = {
|
|
|
58
57
|
tokenOut: Address;
|
|
59
58
|
pool: Address;
|
|
60
59
|
recipient: Address;
|
|
61
|
-
deadline:
|
|
60
|
+
deadline: string;
|
|
62
61
|
amountIn: NumberAsString;
|
|
63
62
|
amountOutMinimum: NumberAsString;
|
|
64
63
|
sqrtPriceLimitD18: NumberAsString;
|
|
@@ -69,7 +68,7 @@ export type MaverickV1BuyParam = {
|
|
|
69
68
|
tokenOut: Address;
|
|
70
69
|
pool: Address;
|
|
71
70
|
recipient: Address;
|
|
72
|
-
deadline:
|
|
71
|
+
deadline: string;
|
|
73
72
|
amountOut: NumberAsString;
|
|
74
73
|
amountInMaximum: NumberAsString;
|
|
75
74
|
sqrtPriceLimitD18: NumberAsString;
|
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
PlatypusData,
|
|
22
22
|
PlatypusConfigInfo,
|
|
23
23
|
} from './types';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
26
|
+
SimpleExchange,
|
|
27
|
+
} from '../simple-exchange';
|
|
25
28
|
import { PlatypusConfig, Adapters } from './config';
|
|
26
29
|
import { ChainLinkSubscriber } from '../../lib/chainlink';
|
|
27
30
|
import { PlatypusPoolBase } from './pool-base';
|
|
@@ -461,7 +464,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
461
464
|
destToken,
|
|
462
465
|
1,
|
|
463
466
|
this.augustusAddress,
|
|
464
|
-
|
|
467
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
465
468
|
])
|
|
466
469
|
: isETHAddress(destToken)
|
|
467
470
|
? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
|
|
@@ -469,7 +472,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
469
472
|
srcAmount,
|
|
470
473
|
1,
|
|
471
474
|
this.augustusAddress,
|
|
472
|
-
|
|
475
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
473
476
|
])
|
|
474
477
|
: Platypus.poolInterface.encodeFunctionData('swap', [
|
|
475
478
|
srcToken,
|
|
@@ -477,7 +480,7 @@ export class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
|
477
480
|
srcAmount,
|
|
478
481
|
1,
|
|
479
482
|
this.augustusAddress,
|
|
480
|
-
|
|
483
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
481
484
|
]),
|
|
482
485
|
data.pool,
|
|
483
486
|
);
|
package/src/dex/shell.ts
CHANGED
|
@@ -2,9 +2,11 @@ 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 {
|
|
5
|
+
import {
|
|
6
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
+
SimpleExchange,
|
|
8
|
+
} from './simple-exchange';
|
|
6
9
|
import ShellABI from '../abi/Shell.json';
|
|
7
|
-
import Web3 from 'web3';
|
|
8
10
|
import { IDexHelper } from '../dex-helper';
|
|
9
11
|
|
|
10
12
|
export type ShellData = {
|
|
@@ -16,7 +18,7 @@ type ShellParam = [
|
|
|
16
18
|
_target: string,
|
|
17
19
|
_originAmount: string,
|
|
18
20
|
_minTargetAmount: string,
|
|
19
|
-
_deadline
|
|
21
|
+
_deadline: string,
|
|
20
22
|
];
|
|
21
23
|
enum ShellFunctions {
|
|
22
24
|
originSwap = 'originSwap',
|
|
@@ -63,7 +65,7 @@ export class Shell
|
|
|
63
65
|
destToken,
|
|
64
66
|
srcAmount,
|
|
65
67
|
destAmount,
|
|
66
|
-
|
|
68
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
67
69
|
];
|
|
68
70
|
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
69
71
|
swapFunction,
|
|
@@ -10,6 +10,18 @@ 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
|
+
|
|
13
25
|
export class SimpleExchange {
|
|
14
26
|
simpleSwapHelper: Interface;
|
|
15
27
|
protected abiCoder: AbiCoder;
|
|
@@ -122,8 +134,4 @@ export class SimpleExchange {
|
|
|
122
134
|
networkFee,
|
|
123
135
|
};
|
|
124
136
|
}
|
|
125
|
-
|
|
126
|
-
getDeadline() {
|
|
127
|
-
return Math.floor(new Date().getTime() / 1000) + 60 * 60;
|
|
128
|
-
}
|
|
129
137
|
}
|
package/src/dex/trader-joe-v2.ts
CHANGED
|
@@ -2,7 +2,10 @@ 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 {
|
|
5
|
+
import {
|
|
6
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
7
|
+
SimpleExchange,
|
|
8
|
+
} from './simple-exchange';
|
|
6
9
|
import { NumberAsString } from '@paraswap/core';
|
|
7
10
|
import { AsyncOrSync } from 'ts-essentials';
|
|
8
11
|
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
@@ -29,7 +32,7 @@ type TraderJoeV2RouterBuyParams = [
|
|
|
29
32
|
_pairBinSteps: NumberAsString[],
|
|
30
33
|
_tokenPath: Address[],
|
|
31
34
|
to: Address,
|
|
32
|
-
_deadline:
|
|
35
|
+
_deadline: string,
|
|
33
36
|
];
|
|
34
37
|
|
|
35
38
|
type TraderJoeV2RouterParam =
|
|
@@ -37,7 +40,6 @@ type TraderJoeV2RouterParam =
|
|
|
37
40
|
| TraderJoeV2RouterBuyParams;
|
|
38
41
|
|
|
39
42
|
export type TraderJoeV2Data = {
|
|
40
|
-
deadline?: number;
|
|
41
43
|
tokenIn: string; // redundant
|
|
42
44
|
tokenOut: string; // redundant
|
|
43
45
|
binStep: string;
|
|
@@ -87,7 +89,7 @@ export class TraderJoeV2
|
|
|
87
89
|
{
|
|
88
90
|
_pairBinSteps: [data.binStep],
|
|
89
91
|
_tokenPath: [data.tokenIn, data.tokenOut], // FIXME: redundant, shoot & read from contract
|
|
90
|
-
_deadline:
|
|
92
|
+
_deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
91
93
|
},
|
|
92
94
|
);
|
|
93
95
|
|
|
@@ -119,7 +121,7 @@ export class TraderJoeV2
|
|
|
119
121
|
[data.binStep],
|
|
120
122
|
[srcToken, destToken],
|
|
121
123
|
this.augustusAddress,
|
|
122
|
-
|
|
124
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
123
125
|
]
|
|
124
126
|
: [
|
|
125
127
|
destAmount,
|
|
@@ -127,7 +129,7 @@ export class TraderJoeV2
|
|
|
127
129
|
[data.binStep],
|
|
128
130
|
[srcToken, destToken],
|
|
129
131
|
this.augustusAddress,
|
|
130
|
-
|
|
132
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
131
133
|
];
|
|
132
134
|
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
133
135
|
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: string;
|
|
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: string;
|
|
84
84
|
amountOut: NumberAsString;
|
|
85
85
|
amountInMaximum: NumberAsString;
|
|
86
86
|
};
|
|
@@ -30,7 +30,10 @@ import {
|
|
|
30
30
|
UniswapV3Functions,
|
|
31
31
|
UniswapV3Param,
|
|
32
32
|
} from './types';
|
|
33
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
35
|
+
SimpleExchange,
|
|
36
|
+
} from '../simple-exchange';
|
|
34
37
|
import { UniswapV3Config, Adapters, PoolsToPreload } from './config';
|
|
35
38
|
import { UniswapV3EventPool } from './uniswap-v3-pool';
|
|
36
39
|
import UniswapV3RouterABI from '../../abi/uniswap-v3/UniswapV3Router.abi.json';
|
|
@@ -686,7 +689,7 @@ export class UniswapV3
|
|
|
686
689
|
},
|
|
687
690
|
{
|
|
688
691
|
path,
|
|
689
|
-
deadline:
|
|
692
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
690
693
|
},
|
|
691
694
|
);
|
|
692
695
|
|
|
@@ -740,14 +743,14 @@ export class UniswapV3
|
|
|
740
743
|
side === SwapSide.SELL
|
|
741
744
|
? {
|
|
742
745
|
recipient: this.augustusAddress,
|
|
743
|
-
deadline:
|
|
746
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
744
747
|
amountIn: srcAmount,
|
|
745
748
|
amountOutMinimum: destAmount,
|
|
746
749
|
path,
|
|
747
750
|
}
|
|
748
751
|
: {
|
|
749
752
|
recipient: this.augustusAddress,
|
|
750
|
-
deadline:
|
|
753
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
751
754
|
amountOut: destAmount,
|
|
752
755
|
amountInMaximum: srcAmount,
|
|
753
756
|
path,
|
package/src/dex/uniswap-v3.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { pack } from '@ethersproject/solidity';
|
|
|
3
3
|
import { Network, SwapSide } from '../constants';
|
|
4
4
|
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
5
5
|
import { IDexTxBuilder } from './idex';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
8
|
+
SimpleExchange,
|
|
9
|
+
} from './simple-exchange';
|
|
7
10
|
import UniswapV3RouterABI from '../abi/UniswapV3Router.json';
|
|
8
11
|
import { NumberAsString } from '@paraswap/core';
|
|
9
12
|
import { IDexHelper } from '../dex-helper';
|
|
@@ -17,7 +20,6 @@ const UNISWAP_V3_ROUTER_ADDRESSES: { [network: number]: Address } = {
|
|
|
17
20
|
|
|
18
21
|
export type UniswapV3Data = {
|
|
19
22
|
// ExactInputSingleParams
|
|
20
|
-
deadline?: number;
|
|
21
23
|
path: {
|
|
22
24
|
tokenIn: Address;
|
|
23
25
|
tokenOut: Address;
|
|
@@ -28,7 +30,7 @@ export type UniswapV3Data = {
|
|
|
28
30
|
type UniswapV3SellParam = {
|
|
29
31
|
path: string;
|
|
30
32
|
recipient: Address;
|
|
31
|
-
deadline:
|
|
33
|
+
deadline: string;
|
|
32
34
|
amountIn: NumberAsString;
|
|
33
35
|
amountOutMinimum: NumberAsString;
|
|
34
36
|
};
|
|
@@ -36,7 +38,7 @@ type UniswapV3SellParam = {
|
|
|
36
38
|
type UniswapV3BuyParam = {
|
|
37
39
|
path: string;
|
|
38
40
|
recipient: Address;
|
|
39
|
-
deadline:
|
|
41
|
+
deadline: string;
|
|
40
42
|
amountOut: NumberAsString;
|
|
41
43
|
amountInMaximum: NumberAsString;
|
|
42
44
|
};
|
|
@@ -112,7 +114,7 @@ export class UniswapV3
|
|
|
112
114
|
data: UniswapV3Data,
|
|
113
115
|
side: SwapSide,
|
|
114
116
|
): AdapterExchangeParam {
|
|
115
|
-
const {
|
|
117
|
+
const { path: rawPath } = data;
|
|
116
118
|
const path = this.encodePath(rawPath, side);
|
|
117
119
|
const payload = this.abiCoder.encodeParameter(
|
|
118
120
|
{
|
|
@@ -123,14 +125,14 @@ export class UniswapV3
|
|
|
123
125
|
},
|
|
124
126
|
{
|
|
125
127
|
path,
|
|
126
|
-
deadline:
|
|
128
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
127
129
|
},
|
|
128
130
|
);
|
|
129
131
|
|
|
130
132
|
return {
|
|
131
133
|
targetExchange: this.routerAddress,
|
|
132
134
|
payload,
|
|
133
|
-
networkFee: '0',
|
|
135
|
+
networkFee: '0',
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -151,14 +153,14 @@ export class UniswapV3
|
|
|
151
153
|
side === SwapSide.SELL
|
|
152
154
|
? {
|
|
153
155
|
recipient: this.augustusAddress,
|
|
154
|
-
deadline:
|
|
156
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
155
157
|
amountIn: srcAmount,
|
|
156
158
|
amountOutMinimum: destAmount,
|
|
157
159
|
path,
|
|
158
160
|
}
|
|
159
161
|
: {
|
|
160
162
|
recipient: this.augustusAddress,
|
|
161
|
-
deadline:
|
|
163
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
162
164
|
amountOut: destAmount,
|
|
163
165
|
amountInMaximum: srcAmount,
|
|
164
166
|
path,
|
|
@@ -2,6 +2,10 @@ import { OptimalRate, Address, Adapters } from './types';
|
|
|
2
2
|
import { ETHER_ADDRESS, SwapSide } from './constants';
|
|
3
3
|
import { RouterService } from './router';
|
|
4
4
|
import { DexAdapterService } from './dex';
|
|
5
|
+
import {
|
|
6
|
+
FRIENDLY_LOCAL_DEADLINE,
|
|
7
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
8
|
+
} from './dex/simple-exchange';
|
|
5
9
|
|
|
6
10
|
export class TransactionBuilder {
|
|
7
11
|
routerService: RouterService;
|
|
@@ -43,6 +47,14 @@ export class TransactionBuilder {
|
|
|
43
47
|
beneficiary?: Address;
|
|
44
48
|
onlyParams?: boolean;
|
|
45
49
|
}) {
|
|
50
|
+
const globalDeadline = +deadline;
|
|
51
|
+
if (isNaN(globalDeadline)) throw new Error('deadline should be a number');
|
|
52
|
+
const localDeadline = +getLocalDeadlineAsFriendlyPlaceholder();
|
|
53
|
+
if (globalDeadline > localDeadline)
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Deadline is too high. Maximum allowed is ${FRIENDLY_LOCAL_DEADLINE} seconds`,
|
|
56
|
+
);
|
|
57
|
+
|
|
46
58
|
const _beneficiary = beneficiary || userAddress;
|
|
47
59
|
const { encoder, params, networkFee } = await this.routerService
|
|
48
60
|
.getRouterByContractMethod(priceRoute.contractMethod)
|