@paraswap/dex-lib 2.15.6 → 2.15.7
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/config.js +7 -7
- package/build/config.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.js +1 -1
- package/build/dex/curve-v1/curve-v1.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 +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/test-dex/config.d.ts +4 -0
- package/build/dex/test-dex/config.js +15 -0
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
- package/build/dex/test-dex/test-dex-pool.js +63 -0
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/test-dex/test-dex.d.ts +37 -0
- package/build/dex/test-dex/test-dex.js +126 -0
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/test-dex/types.d.ts +6 -0
- package/build/dex/test-dex/types.js +3 -0
- package/build/dex/test-dex/types.js.map +1 -0
- 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/dex/woo-fi-v2/config.js +5 -5
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/build/transaction-builder.js +7 -0
- package/build/transaction-builder.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +7 -7
- package/src/dex/curve-v1/curve-v1.ts +4 -2
- 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/dex/woo-fi-v2/config.ts +5 -5
- package/src/dex/woo-fi-v2/woo-fi-v2-e2e.test.ts +1 -1
- package/src/dex/woo-fi-v2/woo-fi-v2-integration.test.ts +1 -1
- package/src/transaction-builder.ts +12 -0
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/runConfigurations.xml +0 -10
- package/.idea/vcs.xml +0 -6
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WooFiV2Math = void 0;
|
|
4
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
function handleMathError(e, logger) {
|
|
7
|
+
if (e instanceof Error && e.message.startsWith('WooGuardian:')) {
|
|
8
|
+
logger.warn('WooFi Guardian check Error:', e);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
logger.error('Unexpected error in WooFi math:', e);
|
|
12
|
+
}
|
|
13
|
+
function max(a, b) {
|
|
14
|
+
return a > b ? a : b;
|
|
15
|
+
}
|
|
16
|
+
class WooFiV2Math {
|
|
17
|
+
constructor(logger, _quoteToken) {
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this._quoteToken = _quoteToken;
|
|
20
|
+
this.state = constants_1.NULL_STATE;
|
|
21
|
+
}
|
|
22
|
+
query(fromToken, toToken, fromAmounts) {
|
|
23
|
+
try {
|
|
24
|
+
if (fromToken === this._quoteToken) {
|
|
25
|
+
return this._querySellQuote(toToken, fromAmounts);
|
|
26
|
+
}
|
|
27
|
+
else if (toToken === this._quoteToken) {
|
|
28
|
+
return this._querySellBase(fromToken, fromAmounts);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return this._queryBaseToBase(fromToken, toToken, fromAmounts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
handleMathError(e, this.logger);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_querySellBase(baseToken, baseAmounts) {
|
|
40
|
+
try {
|
|
41
|
+
const _state = this.state.tokenStates[baseToken];
|
|
42
|
+
let quoteAmounts = this._calcQuoteAmountSellBase(baseToken, baseAmounts, _state);
|
|
43
|
+
quoteAmounts = quoteAmounts.map(amount => {
|
|
44
|
+
return amount <= this.state.tokenInfos[this._quoteToken].reserve
|
|
45
|
+
? amount
|
|
46
|
+
: 0n;
|
|
47
|
+
});
|
|
48
|
+
const feeRate = this.state.tokenInfos[baseToken].feeRate;
|
|
49
|
+
return this._takeFee(quoteAmounts, feeRate);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
handleMathError(e, this.logger);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_querySellQuote(baseToken, quoteAmounts) {
|
|
57
|
+
try {
|
|
58
|
+
const feeRate = this.state.tokenInfos[baseToken].feeRate;
|
|
59
|
+
quoteAmounts = this._takeFee(quoteAmounts, feeRate);
|
|
60
|
+
const _state = this.state.tokenStates[baseToken];
|
|
61
|
+
let toAmounts = this._calcBaseAmountSellQuote(baseToken, quoteAmounts, _state);
|
|
62
|
+
const baseReserve = this.state.tokenInfos[baseToken].reserve;
|
|
63
|
+
return toAmounts.map(amount => {
|
|
64
|
+
return amount >= baseReserve ? amount : 0n;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
handleMathError(e, this.logger);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
_queryBaseToBase(baseToken1, baseToken2, base1Amounts) {
|
|
73
|
+
try {
|
|
74
|
+
let state1 = this.state.tokenStates[baseToken1];
|
|
75
|
+
let state2 = this.state.tokenStates[baseToken1];
|
|
76
|
+
const feeRate1 = this.state.tokenInfos[baseToken1].feeRate;
|
|
77
|
+
const feeRate2 = this.state.tokenInfos[baseToken2].feeRate;
|
|
78
|
+
const spread = max(state1.spread, state2.spread) / 2n;
|
|
79
|
+
const feeRate = max(feeRate1, feeRate2);
|
|
80
|
+
state1.spread = spread;
|
|
81
|
+
state2.spread = spread;
|
|
82
|
+
let quoteAmounts = this._calcQuoteAmountSellBase(baseToken1, base1Amounts, state1);
|
|
83
|
+
quoteAmounts = this._takeFeeAndCheckReserve(quoteAmounts, feeRate);
|
|
84
|
+
let toAmounts = this._calcBaseAmountSellQuote(baseToken2, quoteAmounts, state2);
|
|
85
|
+
return toAmounts.map(toAmount => {
|
|
86
|
+
return toAmount <= this.state.tokenInfos[baseToken2].reserve
|
|
87
|
+
? toAmount
|
|
88
|
+
: 0n;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
handleMathError(e, this.logger);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
_takeFeeAndCheckReserve(amounts, feeRate) {
|
|
97
|
+
return amounts.map(amount => {
|
|
98
|
+
if (amount === 0n)
|
|
99
|
+
return 0n;
|
|
100
|
+
const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
|
|
101
|
+
const reserve = this.state.tokenInfos[this._quoteToken].reserve;
|
|
102
|
+
return lpFee > reserve ? 0n : amount - lpFee;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_takeFee(amounts, feeRate) {
|
|
106
|
+
return amounts.map(amount => {
|
|
107
|
+
const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
|
|
108
|
+
return amount === 0n ? 0n : amount - lpFee;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
_calcQuoteAmountSellBase(baseToken, baseAmounts, state) {
|
|
112
|
+
let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
|
|
113
|
+
return baseAmounts.map(baseAmount => {
|
|
114
|
+
if (baseAmount === 0n)
|
|
115
|
+
return 0n;
|
|
116
|
+
const coef = bigint_constants_1.BI_POWS[18] -
|
|
117
|
+
(state.coeff * baseAmount * state.price) / baseDec / priceDec -
|
|
118
|
+
state.spread;
|
|
119
|
+
return ((((baseAmount * quoteDec * state.price) / priceDec) * coef) /
|
|
120
|
+
bigint_constants_1.BI_POWS[18] /
|
|
121
|
+
baseDec);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
_calcBaseAmountSellQuote(baseToken, quoteAmounts, state) {
|
|
125
|
+
let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
|
|
126
|
+
return quoteAmounts.map(quoteAmount => {
|
|
127
|
+
if (quoteAmount === 0n)
|
|
128
|
+
return 0n;
|
|
129
|
+
const coef = bigint_constants_1.BI_POWS[18] - (quoteAmount * state.coeff) / quoteDec - state.spread;
|
|
130
|
+
return ((((quoteAmount * baseDec * priceDec) / state.price) * coef) /
|
|
131
|
+
bigint_constants_1.BI_POWS[18] /
|
|
132
|
+
quoteDec);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.WooFiV2Math = WooFiV2Math;
|
|
137
|
+
//# sourceMappingURL=woo-fi-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"woo-fi-math.js","sourceRoot":"","sources":["../../../src/dex/woo-fi-v2/woo-fi-math.ts"],"names":[],"mappings":";;;AAEA,6DAAiD;AAEjD,2CAAyC;AAEzC,SAAS,eAAe,CAAC,CAAU,EAAE,MAAc;IACjD,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;QAC9D,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO;KACR;IACD,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS;IAC/B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,MAAa,WAAW;IAGtB,YACmB,MAAc,EACd,WAAoB;QADpB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAS;QAJvC,UAAK,GAAc,sBAAU,CAAC;IAK3B,CAAC;IAEJ,KAAK,CACH,SAAkB,EAClB,OAAgB,EAChB,WAAqB;QAErB,IAAI;YACF,IAAI,SAAS,KAAK,IAAI,CAAC,WAAW,EAAE;gBAClC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;aACnD;iBAAM,IAAI,OAAO,KAAK,IAAI,CAAC,WAAW,EAAE;gBACvC,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;aACpD;iBAAM;gBACL,OAAO,IAAI,CAAC,gBAA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,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;gBAC3D,0BAAO,CAAC,EAAE,CAAC;gBACX,QAAQ,CACT,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhLD,kCAgLC"}
|
|
@@ -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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K,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
package/src/config.ts
CHANGED
|
@@ -56,7 +56,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
56
56
|
'0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07',
|
|
57
57
|
rpcPollingMaxAllowedStateDelayInBlocks: 0,
|
|
58
58
|
rpcPollingBlocksBackToTriggerUpdate: 0,
|
|
59
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
59
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
60
60
|
hashFlowDisabledMMs:
|
|
61
61
|
process.env[`HASHFLOW_DISABLED_MMS_1`]?.split(',') || [],
|
|
62
62
|
uniswapV3EventLoggingSampleRate: 0,
|
|
@@ -153,7 +153,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
153
153
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
154
154
|
multicallV2Address: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D',
|
|
155
155
|
privateHttpProvider: process.env.HTTP_PROVIDER_56,
|
|
156
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
156
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
157
157
|
hashFlowDisabledMMs:
|
|
158
158
|
process.env[`HASHFLOW_DISABLED_MMS_56`]?.split(',') || [],
|
|
159
159
|
adapterAddresses: {
|
|
@@ -180,7 +180,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
180
180
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
181
181
|
multicallV2Address: '0x275617327c958bD06b5D6b871E7f491D76113dd8',
|
|
182
182
|
privateHttpProvider: process.env.HTTP_PROVIDER_137,
|
|
183
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
183
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
184
184
|
hashFlowDisabledMMs:
|
|
185
185
|
process.env[`HASHFLOW_DISABLED_MMS_137`]?.split(',') || [],
|
|
186
186
|
adapterAddresses: {
|
|
@@ -208,7 +208,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
208
208
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
209
209
|
multicallV2Address: '0xd7Fc8aD069f95B6e2835f4DEff03eF84241cF0E1',
|
|
210
210
|
privateHttpProvider: process.env.HTTP_PROVIDER_43114,
|
|
211
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
211
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
212
212
|
hashFlowDisabledMMs:
|
|
213
213
|
process.env[`HASHFLOW_DISABLED_MMS_43114`]?.split(',') || [],
|
|
214
214
|
adapterAddresses: {
|
|
@@ -235,7 +235,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
235
235
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
236
236
|
multicallV2Address: '0xdC6E2b14260F972ad4e5a31c68294Fba7E720701',
|
|
237
237
|
privateHttpProvider: process.env.HTTP_PROVIDER_250,
|
|
238
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
238
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
239
239
|
hashFlowDisabledMMs:
|
|
240
240
|
process.env[`HASHFLOW_DISABLED_MMS_250`]?.split(',') || [],
|
|
241
241
|
|
|
@@ -262,7 +262,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
262
262
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
263
263
|
multicallV2Address: '0x7eCfBaa8742fDf5756DAC92fbc8b90a19b8815bF',
|
|
264
264
|
privateHttpProvider: process.env.HTTP_PROVIDER_42161,
|
|
265
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
265
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
266
266
|
hashFlowDisabledMMs:
|
|
267
267
|
process.env[`HASHFLOW_DISABLED_MMS_42161`]?.split(',') || [],
|
|
268
268
|
adapterAddresses: {
|
|
@@ -290,7 +290,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
290
290
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
291
291
|
multicallV2Address: '0x2DC0E2aa608532Da689e89e237dF582B783E552C',
|
|
292
292
|
privateHttpProvider: process.env.HTTP_PROVIDER_10,
|
|
293
|
-
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN,
|
|
293
|
+
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
294
294
|
hashFlowDisabledMMs:
|
|
295
295
|
process.env[`HASHFLOW_DISABLED_MMS_10`]?.split(',') || [],
|
|
296
296
|
|
|
@@ -331,8 +331,10 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
331
331
|
`Error_${this.dexKey} requested unsupported event pool with address ${poolAddress}`,
|
|
332
332
|
);
|
|
333
333
|
|
|
334
|
-
const addressesSubscribed = newPool.addressesSubscribed.map(
|
|
335
|
-
|
|
334
|
+
const addressesSubscribed = newPool.addressesSubscribed.map(address =>
|
|
335
|
+
address.toLowerCase(),
|
|
336
|
+
);
|
|
337
|
+
if (!addressesSubscribed.includes(poolAddress)) {
|
|
336
338
|
newPool.addressesSubscribed.push(poolAddress);
|
|
337
339
|
}
|
|
338
340
|
|
|
@@ -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,
|
|
@@ -15,12 +15,12 @@ export const WooFiV2Config: DexConfigMap<DexParams> = {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
[Network.BSC]: {
|
|
18
|
-
wooPPV2Address: '
|
|
19
|
-
wooOracleV2Address: '
|
|
20
|
-
integrationHelperAddress: '
|
|
21
|
-
//
|
|
18
|
+
wooPPV2Address: '0x59dE3B49314Bf5067719364A2Cb43e8525ab93FA',
|
|
19
|
+
wooOracleV2Address: '0x4B11B9BfAafA840c436a1ddDc13D3738C8ebfD62',
|
|
20
|
+
integrationHelperAddress: '0xAA9c15cd603428cA8ddD45e933F8EfE3Afbcc173',
|
|
21
|
+
// USDT
|
|
22
22
|
quoteToken: {
|
|
23
|
-
address: '
|
|
23
|
+
address: '0x55d398326f99059fF775485246999027B3197955',
|
|
24
24
|
decimals: 18,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
@@ -114,7 +114,7 @@ describe('WooFiV2 E2E', () => {
|
|
|
114
114
|
|
|
115
115
|
const baseATokenSymbol = 'WBNB';
|
|
116
116
|
const baseBTokenSymbol = 'bBTC';
|
|
117
|
-
const quoteTokenSymbol = '
|
|
117
|
+
const quoteTokenSymbol = 'USDT';
|
|
118
118
|
|
|
119
119
|
const tokenBaseAAmount = '1000000000000000000';
|
|
120
120
|
const tokenQuoteAmount = '1000000000000000000';
|