@pioneer-platform/uniswap-client 0.0.28 → 0.1.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/CHANGELOG.md +16 -0
- package/lib/constants/chainInfo.d.ts +2 -2
- package/lib/constants/chainInfo.js +40 -43
- package/lib/constants/chains.d.ts +20 -20
- package/lib/constants/chains.js +25 -26
- package/lib/constants/governance.js +13 -14
- package/lib/constants/lists.js +20 -28
- package/lib/constants/misc.d.ts +4 -5
- package/lib/constants/misc.js +2 -2
- package/lib/constants/networks.js +45 -46
- package/lib/constants/proposals/uniswap_grants_proposal_description.js +106 -1
- package/lib/constants/providers.d.ts +16 -15
- package/lib/constants/providers.js +23 -24
- package/lib/constants/routing.js +44 -61
- package/lib/constants/tokens.d.ts +49 -49
- package/lib/constants/tokens.js +133 -170
- package/lib/index.js +556 -877
- package/lib/routing/clientSideSmartOrderRouter.js +72 -121
- package/lib/routing/gas.js +63 -150
- package/lib/routing/types.d.ts +7 -7
- package/lib/routing/types.js +160 -264
- package/lib/routing/utils.js +141 -196
- package/lib/rpc/AppJsonRpcProvider.js +40 -131
- package/lib/rpc/ConfiguredJsonRpcProvider.d.ts +1 -1
- package/lib/rpc/ConfiguredJsonRpcProvider.js +8 -27
- package/lib/utils/contracts/getContract.js +6 -7
- package/lib/utils/transformSwapRouteToGetQuoteResult.js +24 -27
- package/lib/utils/uniswapData.d.ts +6 -6
- package/lib/utils/uniswapData.js +64 -142
- package/package.json +19 -19
- package/tsconfig.json +27 -8
- package/lib/constants/chains.test.d.ts +0 -1
- package/lib/constants/chains.test.js +0 -26
- package/lib/constants/localCurrencies.d.ts +0 -6
- package/lib/constants/localCurrencies.js +0 -94
- package/lib/constants/localCurrencyIcons.d.ts +0 -18
- package/lib/constants/localCurrencyIcons.js +0 -298
- package/lib/constants/routing.test.d.ts +0 -1
- package/lib/constants/routing.test.js +0 -32
- package/lib/constants/tokenLists/broken.tokenlist.json +0 -22
- package/lib/constants/tokenLogoLookup.d.ts +0 -8
- package/lib/constants/tokenLogoLookup.js +0 -48
- package/lib/constants/tokenSafety.js +0 -129
- package/lib/constants/tokenSafetyLookup.d.ts +0 -18
- package/lib/constants/tokenSafetyLookup.js +0 -66
- package/lib/constants/tokenSaftey.test.d.ts +0 -1
- package/lib/constants/tokenSaftey.test.js +0 -31
package/lib/routing/types.js
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
-
var t = {};
|
|
19
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
-
t[p] = s[p];
|
|
21
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
-
t[p[i]] = s[p[i]];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
var _a;
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.URAQuoteType = exports.SwapRouterNativeAssets = exports.PoolType = exports.QuoteState = exports.LimitOrderTrade = exports.PreviewTrade = exports.DutchOrderTrade = exports.OFFCHAIN_ORDER_TYPE_TO_SIGNATURE_TYPE = exports.OffchainOrderType = exports.ClassicTrade = exports.TradeFillType = exports.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
3
|
+
exports.URAQuoteType = exports.SwapRouterNativeAssets = exports.PoolType = exports.QuoteState = exports.LimitOrderTrade = exports.PreviewTrade = exports.DutchOrderTrade = exports.OFFCHAIN_ORDER_TYPE_TO_SIGNATURE_TYPE = exports.OffchainOrderType = exports.ClassicTrade = exports.TradeFillType = exports.QuoteIntent = exports.RouterPreference = exports.INTERNAL_ROUTER_PREFERENCE_PRICE = exports.QuoteMethod = exports.TradeState = void 0;
|
|
4
|
+
exports.isClassicQuoteResponse = isClassicQuoteResponse;
|
|
5
|
+
const constants_1 = require("@ethersproject/constants");
|
|
6
|
+
const router_sdk_1 = require("@uniswap/router-sdk");
|
|
7
|
+
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
8
|
+
const uniswapx_sdk_1 = require("@uniswap/uniswapx-sdk");
|
|
9
|
+
const misc_1 = require("../constants/misc");
|
|
10
|
+
const ethers_1 = require("ethers/lib/ethers");
|
|
37
11
|
var SignatureType;
|
|
38
12
|
(function (SignatureType) {
|
|
39
13
|
SignatureType["SIGN_UNISWAPX_ORDER"] = "signUniswapXOrder";
|
|
@@ -71,65 +45,46 @@ var QuoteIntent;
|
|
|
71
45
|
function isClassicQuoteResponse(data) {
|
|
72
46
|
return data.routing === URAQuoteType.CLASSIC;
|
|
73
47
|
}
|
|
74
|
-
exports.isClassicQuoteResponse = isClassicQuoteResponse;
|
|
75
48
|
var TradeFillType;
|
|
76
49
|
(function (TradeFillType) {
|
|
77
50
|
TradeFillType["Classic"] = "classic";
|
|
78
51
|
TradeFillType["UniswapX"] = "uniswap_x";
|
|
79
52
|
TradeFillType["None"] = "none";
|
|
80
53
|
})(TradeFillType || (exports.TradeFillType = TradeFillType = {}));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
54
|
+
class ClassicTrade extends router_sdk_1.Trade {
|
|
55
|
+
constructor({ gasUseEstimate, gasUseEstimateUSD, blockNumber, requestId, quoteMethod, approveInfo, swapFee, ...routes }) {
|
|
56
|
+
super(routes);
|
|
57
|
+
this.fillType = TradeFillType.Classic;
|
|
58
|
+
this.blockNumber = blockNumber;
|
|
59
|
+
this.gasUseEstimateUSD = gasUseEstimateUSD;
|
|
60
|
+
this.requestId = requestId;
|
|
61
|
+
this.quoteMethod = quoteMethod;
|
|
62
|
+
this.approveInfo = approveInfo;
|
|
63
|
+
this.swapFee = swapFee;
|
|
64
|
+
this.gasUseEstimate = gasUseEstimate;
|
|
65
|
+
}
|
|
66
|
+
get executionPrice() {
|
|
67
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT || !this.swapFee) { // @ts-ignore
|
|
68
|
+
return super.executionPrice;
|
|
69
|
+
}
|
|
70
|
+
// Fix inaccurate price calculation for exact output trades
|
|
71
|
+
return new sdk_core_1.Price({ baseAmount: this.inputAmount, quoteAmount: this.postSwapFeeOutputAmount });
|
|
72
|
+
}
|
|
73
|
+
get postSwapFeeOutputAmount() {
|
|
74
|
+
// Routing api already applies the swap fee to the output amount for exact-in
|
|
75
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT)
|
|
76
|
+
return this.outputAmount;
|
|
77
|
+
const swapFeeAmount = sdk_core_1.CurrencyAmount.fromRawAmount(this.outputAmount.currency, this.swapFee?.amount ?? 0);
|
|
78
|
+
return this.outputAmount.subtract(swapFeeAmount);
|
|
79
|
+
}
|
|
80
|
+
// gas estimate for maybe approve + swap
|
|
81
|
+
get totalGasUseEstimateUSD() {
|
|
82
|
+
if (this.approveInfo.needsApprove && this.gasUseEstimateUSD) {
|
|
83
|
+
return this.approveInfo.approveGasEstimateUSD + this.gasUseEstimateUSD;
|
|
84
|
+
}
|
|
85
|
+
return this.gasUseEstimateUSD;
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
get: function () {
|
|
99
|
-
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT || !this.swapFee) { // @ts-ignore
|
|
100
|
-
return _super.prototype.executionPrice;
|
|
101
|
-
}
|
|
102
|
-
// Fix inaccurate price calculation for exact output trades
|
|
103
|
-
return new sdk_core_1.Price({ baseAmount: this.inputAmount, quoteAmount: this.postSwapFeeOutputAmount });
|
|
104
|
-
},
|
|
105
|
-
enumerable: false,
|
|
106
|
-
configurable: true
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(ClassicTrade.prototype, "postSwapFeeOutputAmount", {
|
|
109
|
-
get: function () {
|
|
110
|
-
var _a, _b;
|
|
111
|
-
// Routing api already applies the swap fee to the output amount for exact-in
|
|
112
|
-
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT)
|
|
113
|
-
return this.outputAmount;
|
|
114
|
-
var swapFeeAmount = sdk_core_1.CurrencyAmount.fromRawAmount(this.outputAmount.currency, (_b = (_a = this.swapFee) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
115
|
-
return this.outputAmount.subtract(swapFeeAmount);
|
|
116
|
-
},
|
|
117
|
-
enumerable: false,
|
|
118
|
-
configurable: true
|
|
119
|
-
});
|
|
120
|
-
Object.defineProperty(ClassicTrade.prototype, "totalGasUseEstimateUSD", {
|
|
121
|
-
// gas estimate for maybe approve + swap
|
|
122
|
-
get: function () {
|
|
123
|
-
if (this.approveInfo.needsApprove && this.gasUseEstimateUSD) {
|
|
124
|
-
return this.approveInfo.approveGasEstimateUSD + this.gasUseEstimateUSD;
|
|
125
|
-
}
|
|
126
|
-
return this.gasUseEstimateUSD;
|
|
127
|
-
},
|
|
128
|
-
enumerable: false,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
return ClassicTrade;
|
|
132
|
-
}(router_sdk_1.Trade));
|
|
87
|
+
}
|
|
133
88
|
exports.ClassicTrade = ClassicTrade;
|
|
134
89
|
var OffchainOrderType;
|
|
135
90
|
(function (OffchainOrderType) {
|
|
@@ -137,55 +92,46 @@ var OffchainOrderType;
|
|
|
137
92
|
OffchainOrderType["DUTCH_V2_AUCTION"] = "Dutch_V2";
|
|
138
93
|
OffchainOrderType["LIMIT_ORDER"] = "Limit";
|
|
139
94
|
})(OffchainOrderType || (exports.OffchainOrderType = OffchainOrderType = {}));
|
|
140
|
-
exports.OFFCHAIN_ORDER_TYPE_TO_SIGNATURE_TYPE =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
_this.startTimeBufferSecs = startTimeBufferSecs;
|
|
163
|
-
_this.swapFee = swapFee;
|
|
164
|
-
return _this;
|
|
95
|
+
exports.OFFCHAIN_ORDER_TYPE_TO_SIGNATURE_TYPE = {
|
|
96
|
+
[OffchainOrderType.DUTCH_AUCTION]: SignatureType.SIGN_UNISWAPX_ORDER,
|
|
97
|
+
[OffchainOrderType.DUTCH_V2_AUCTION]: SignatureType.SIGN_UNISWAPX_V2_ORDER,
|
|
98
|
+
[OffchainOrderType.LIMIT_ORDER]: SignatureType.SIGN_LIMIT,
|
|
99
|
+
};
|
|
100
|
+
class DutchOrderTrade extends uniswapx_sdk_1.DutchOrderTrade {
|
|
101
|
+
constructor({ currencyIn, currenciesOut, orderInfo, tradeType, quoteId, requestId, wrapInfo, approveInfo, classicGasUseEstimateUSD, auctionPeriodSecs, startTimeBufferSecs, deadlineBufferSecs, slippageTolerance, swapFee, }) {
|
|
102
|
+
super({ currencyIn, currenciesOut, orderInfo, tradeType });
|
|
103
|
+
this.fillType = TradeFillType.UniswapX;
|
|
104
|
+
this.offchainOrderType = OffchainOrderType.DUTCH_AUCTION;
|
|
105
|
+
this.inputTax = misc_1.ZERO_PERCENT;
|
|
106
|
+
this.outputTax = misc_1.ZERO_PERCENT;
|
|
107
|
+
this.quoteId = quoteId;
|
|
108
|
+
this.requestId = requestId;
|
|
109
|
+
this.approveInfo = approveInfo;
|
|
110
|
+
this.wrapInfo = wrapInfo;
|
|
111
|
+
this.classicGasUseEstimateUSD = classicGasUseEstimateUSD;
|
|
112
|
+
this.auctionPeriodSecs = auctionPeriodSecs;
|
|
113
|
+
this.deadlineBufferSecs = deadlineBufferSecs;
|
|
114
|
+
this.slippageTolerance = slippageTolerance;
|
|
115
|
+
this.startTimeBufferSecs = startTimeBufferSecs;
|
|
116
|
+
this.swapFee = swapFee;
|
|
165
117
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
enumerable: false,
|
|
178
|
-
configurable: true
|
|
179
|
-
});
|
|
180
|
-
DutchOrderTrade.prototype.asDutchOrderTrade = function () {
|
|
118
|
+
get totalGasUseEstimateUSD() {
|
|
119
|
+
if (this.wrapInfo.needsWrap && this.approveInfo.needsApprove) {
|
|
120
|
+
return this.wrapInfo.wrapGasEstimateUSD + this.approveInfo.approveGasEstimateUSD;
|
|
121
|
+
}
|
|
122
|
+
if (this.wrapInfo.needsWrap)
|
|
123
|
+
return this.wrapInfo.wrapGasEstimateUSD;
|
|
124
|
+
if (this.approveInfo.needsApprove)
|
|
125
|
+
return this.approveInfo.approveGasEstimateUSD;
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
asDutchOrderTrade() {
|
|
181
129
|
return this;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
}(uniswapx_sdk_1.DutchOrderTrade));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
185
132
|
exports.DutchOrderTrade = DutchOrderTrade;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var inputAmount = _a.inputAmount, outputAmount = _a.outputAmount, tradeType = _a.tradeType;
|
|
133
|
+
class PreviewTrade {
|
|
134
|
+
constructor({ inputAmount, outputAmount, tradeType, }) {
|
|
189
135
|
this.fillType = TradeFillType.None;
|
|
190
136
|
this.quoteMethod = QuoteMethod.QUICK_ROUTE;
|
|
191
137
|
this.inputAmount = inputAmount;
|
|
@@ -194,77 +140,61 @@ var PreviewTrade = /** @class */ (function () {
|
|
|
194
140
|
}
|
|
195
141
|
// below methods are copied from router-sdk
|
|
196
142
|
// Trade https://github.com/Uniswap/router-sdk/blob/main/src/entities/trade.ts#L10
|
|
197
|
-
|
|
198
|
-
if (amountOut === void 0) { amountOut = this.outputAmount; }
|
|
143
|
+
minimumAmountOut(slippageTolerance, amountOut = this.outputAmount) {
|
|
199
144
|
if (this.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
200
145
|
return amountOut;
|
|
201
146
|
}
|
|
202
147
|
else {
|
|
203
|
-
|
|
148
|
+
const slippageAdjustedAmountOut = new sdk_core_1.Fraction(router_sdk_1.ONE)
|
|
204
149
|
.add(slippageTolerance)
|
|
205
150
|
.invert()
|
|
206
151
|
.multiply(amountOut.quotient).quotient;
|
|
207
152
|
return sdk_core_1.CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
|
|
208
153
|
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (amountIn === void 0) { amountIn = this.inputAmount; }
|
|
154
|
+
}
|
|
155
|
+
maximumAmountIn(slippageTolerance, amountIn = this.inputAmount) {
|
|
212
156
|
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
213
157
|
return amountIn;
|
|
214
158
|
}
|
|
215
159
|
else {
|
|
216
|
-
|
|
160
|
+
const slippageAdjustedAmountIn = new sdk_core_1.Fraction(router_sdk_1.ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
|
|
217
161
|
return sdk_core_1.CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
|
|
218
162
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
Object.defineProperty(PreviewTrade.prototype, "executionPrice", {
|
|
247
|
-
/**
|
|
248
|
-
* The price expressed in terms of output amount/input amount.
|
|
249
|
-
*/
|
|
250
|
-
get: function () {
|
|
251
|
-
var _a;
|
|
252
|
-
return ((_a = this._executionPrice) !== null && _a !== void 0 ? _a : (this._executionPrice = new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient)));
|
|
253
|
-
},
|
|
254
|
-
enumerable: false,
|
|
255
|
-
configurable: true
|
|
256
|
-
});
|
|
257
|
-
PreviewTrade.prototype.worstExecutionPrice = function (slippageTolerance) {
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns the sell tax of the input token
|
|
166
|
+
*/
|
|
167
|
+
get inputTax() {
|
|
168
|
+
const inputCurrency = this.inputAmount.currency;
|
|
169
|
+
if (inputCurrency.isNative || !inputCurrency.wrapped.sellFeeBps)
|
|
170
|
+
return misc_1.ZERO_PERCENT;
|
|
171
|
+
return new sdk_core_1.Percent(inputCurrency.wrapped.sellFeeBps.toNumber(), 10000);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the buy tax of the output token
|
|
175
|
+
*/
|
|
176
|
+
get outputTax() {
|
|
177
|
+
const outputCurrency = this.outputAmount.currency;
|
|
178
|
+
if (outputCurrency.isNative || !outputCurrency.wrapped.buyFeeBps)
|
|
179
|
+
return misc_1.ZERO_PERCENT;
|
|
180
|
+
return new sdk_core_1.Percent(outputCurrency.wrapped.buyFeeBps.toNumber(), 10000);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The price expressed in terms of output amount/input amount.
|
|
184
|
+
*/
|
|
185
|
+
get executionPrice() {
|
|
186
|
+
return (this._executionPrice ??
|
|
187
|
+
(this._executionPrice = new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient)));
|
|
188
|
+
}
|
|
189
|
+
worstExecutionPrice(slippageTolerance) {
|
|
258
190
|
return new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
}());
|
|
191
|
+
}
|
|
192
|
+
}
|
|
262
193
|
exports.PreviewTrade = PreviewTrade;
|
|
263
194
|
// TODO(limits): get this from uniswapx-sdk
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
var tradeType = _a.tradeType, amountIn = _a.amountIn, amountOut = _a.amountOut, deadlineBufferSecs = _a.deadlineBufferSecs, swapFee = _a.swapFee, wrapInfo = _a.wrapInfo, approveInfo = _a.approveInfo, swapper = _a.swapper;
|
|
195
|
+
const UNISWAPX_REACTOR = '0x6000da47483062a0d734ba3dc7576ce6a0b645c4';
|
|
196
|
+
class LimitOrderTrade {
|
|
197
|
+
constructor({ tradeType, amountIn, amountOut, deadlineBufferSecs, swapFee, wrapInfo, approveInfo, swapper, }) {
|
|
268
198
|
this.fillType = TradeFillType.UniswapX;
|
|
269
199
|
this.offchainOrderType = OffchainOrderType.LIMIT_ORDER;
|
|
270
200
|
// Placeholder values that aren't used in a limit trade
|
|
@@ -282,35 +212,34 @@ var LimitOrderTrade = /** @class */ (function () {
|
|
|
282
212
|
this.tradeType = tradeType;
|
|
283
213
|
this.swapper = swapper;
|
|
284
214
|
// deadline is shown in the review modal, but updated on submission
|
|
285
|
-
|
|
215
|
+
const nowSecs = Math.floor(Date.now() / 1000);
|
|
286
216
|
this.deadline = (nowSecs + deadlineBufferSecs) * 1000;
|
|
287
217
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
var swapperOutput = {
|
|
218
|
+
asDutchOrderTrade(options) {
|
|
219
|
+
const swapperOutput = {
|
|
291
220
|
token: this.amountOut.currency.isNative ? constants_1.AddressZero : this.amountOut.currency.address,
|
|
292
|
-
recipient:
|
|
221
|
+
recipient: options?.swapper ?? this.swapper,
|
|
293
222
|
startAmount: ethers_1.BigNumber.from(this.amountOut.quotient.toString()),
|
|
294
223
|
endAmount: ethers_1.BigNumber.from(this.amountOut.quotient.toString()),
|
|
295
224
|
};
|
|
296
|
-
|
|
225
|
+
const swapFee = this.swapFee && {
|
|
297
226
|
token: this.amountOut.currency.isNative ? constants_1.AddressZero : this.amountOut.currency.address,
|
|
298
227
|
recipient: this.swapFee.recipient,
|
|
299
228
|
startAmount: ethers_1.BigNumber.from(this.amountOut.multiply(this.swapFee.percent).quotient.toString()),
|
|
300
229
|
endAmount: ethers_1.BigNumber.from(this.amountOut.multiply(this.swapFee.percent).quotient.toString()),
|
|
301
230
|
};
|
|
302
|
-
|
|
303
|
-
|
|
231
|
+
const outputs = swapFee ? [swapperOutput, swapFee] : [swapperOutput];
|
|
232
|
+
const nowSecs = Math.floor(Date.now() / 1000);
|
|
304
233
|
return new uniswapx_sdk_1.DutchOrderTrade({
|
|
305
234
|
currencyIn: this.amountIn.currency,
|
|
306
235
|
currenciesOut: [this.amountOut.currency],
|
|
307
236
|
orderInfo: {
|
|
308
237
|
reactor: UNISWAPX_REACTOR,
|
|
309
|
-
swapper:
|
|
238
|
+
swapper: options?.swapper ?? this.swapper,
|
|
310
239
|
deadline: (nowSecs + this.deadlineBufferSecs) * 1000,
|
|
311
240
|
additionalValidationContract: constants_1.AddressZero,
|
|
312
241
|
additionalValidationData: '0x',
|
|
313
|
-
nonce:
|
|
242
|
+
nonce: options?.nonce ?? ethers_1.BigNumber.from(0),
|
|
314
243
|
// decay timings dont matter at all
|
|
315
244
|
decayStartTime: nowSecs,
|
|
316
245
|
decayEndTime: nowSecs,
|
|
@@ -321,81 +250,48 @@ var LimitOrderTrade = /** @class */ (function () {
|
|
|
321
250
|
startAmount: ethers_1.BigNumber.from(this.amountIn.quotient.toString()),
|
|
322
251
|
endAmount: ethers_1.BigNumber.from(this.amountIn.quotient.toString()),
|
|
323
252
|
},
|
|
324
|
-
outputs
|
|
253
|
+
outputs,
|
|
325
254
|
},
|
|
326
255
|
tradeType: this.tradeType,
|
|
327
256
|
});
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
358
|
-
Object.defineProperty(LimitOrderTrade.prototype, "classicGasUseEstimateUSD", {
|
|
359
|
-
get: function () {
|
|
360
|
-
return 0;
|
|
361
|
-
},
|
|
362
|
-
enumerable: false,
|
|
363
|
-
configurable: true
|
|
364
|
-
});
|
|
365
|
-
Object.defineProperty(LimitOrderTrade.prototype, "startTimeBufferSecs", {
|
|
366
|
-
// no decay for limit orders
|
|
367
|
-
get: function () {
|
|
368
|
-
return 0;
|
|
369
|
-
},
|
|
370
|
-
enumerable: false,
|
|
371
|
-
configurable: true
|
|
372
|
-
});
|
|
373
|
-
Object.defineProperty(LimitOrderTrade.prototype, "auctionPeriodSecs", {
|
|
374
|
-
// no decay auction for limit orders
|
|
375
|
-
get: function () {
|
|
376
|
-
return 0;
|
|
377
|
-
},
|
|
378
|
-
enumerable: false,
|
|
379
|
-
configurable: true
|
|
380
|
-
});
|
|
381
|
-
Object.defineProperty(LimitOrderTrade.prototype, "executionPrice", {
|
|
382
|
-
get: function () {
|
|
383
|
-
return new sdk_core_1.Price(this.amountIn.currency, this.amountOut.currency, this.amountIn.quotient, this.amountOut.quotient);
|
|
384
|
-
},
|
|
385
|
-
enumerable: false,
|
|
386
|
-
configurable: true
|
|
387
|
-
});
|
|
388
|
-
LimitOrderTrade.prototype.worstExecutionPrice = function () {
|
|
257
|
+
}
|
|
258
|
+
get inputAmount() {
|
|
259
|
+
return this.amountIn;
|
|
260
|
+
}
|
|
261
|
+
get outputAmount() {
|
|
262
|
+
return this.amountOut;
|
|
263
|
+
}
|
|
264
|
+
/** For UniswapX, handling token taxes in the output amount is outsourced to quoters */
|
|
265
|
+
get postTaxOutputAmount() {
|
|
266
|
+
return this.outputAmount;
|
|
267
|
+
}
|
|
268
|
+
get totalGasUseEstimateUSD() {
|
|
269
|
+
return this.wrapInfo.needsWrap ? this.wrapInfo.wrapGasEstimateUSD : 0;
|
|
270
|
+
}
|
|
271
|
+
get classicGasUseEstimateUSD() {
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
// no decay for limit orders
|
|
275
|
+
get startTimeBufferSecs() {
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
// no decay auction for limit orders
|
|
279
|
+
get auctionPeriodSecs() {
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
get executionPrice() {
|
|
283
|
+
return new sdk_core_1.Price(this.amountIn.currency, this.amountOut.currency, this.amountIn.quotient, this.amountOut.quotient);
|
|
284
|
+
}
|
|
285
|
+
worstExecutionPrice() {
|
|
389
286
|
return this.executionPrice;
|
|
390
|
-
}
|
|
391
|
-
|
|
287
|
+
}
|
|
288
|
+
maximumAmountIn() {
|
|
392
289
|
return this.inputAmount;
|
|
393
|
-
}
|
|
394
|
-
|
|
290
|
+
}
|
|
291
|
+
minimumAmountOut() {
|
|
395
292
|
return this.outputAmount;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
}());
|
|
293
|
+
}
|
|
294
|
+
}
|
|
399
295
|
exports.LimitOrderTrade = LimitOrderTrade;
|
|
400
296
|
var QuoteState;
|
|
401
297
|
(function (QuoteState) {
|