@pioneer-platform/uniswap-client 0.0.21 → 0.0.24
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/lib/constants/chainInfo.d.ts +19 -22
- package/lib/constants/chainInfo.js +134 -117
- package/lib/constants/chains.d.ts +36 -47
- package/lib/constants/chains.js +118 -83
- package/lib/constants/chains.test.js +22 -25
- package/lib/constants/governance.d.ts +8 -0
- package/lib/constants/governance.js +24 -0
- package/lib/constants/lists.d.ts +12 -0
- package/lib/constants/lists.js +64 -0
- package/lib/constants/localCurrencies.d.ts +6 -0
- package/lib/constants/localCurrencies.js +94 -0
- package/lib/constants/localCurrencyIcons.d.ts +18 -0
- package/lib/constants/localCurrencyIcons.js +298 -0
- package/lib/constants/locales.d.ts +1 -1
- package/lib/constants/locales.js +0 -3
- package/lib/constants/misc.d.ts +2 -7
- package/lib/constants/misc.js +17 -23
- package/lib/constants/networks.d.ts +21 -0
- package/lib/constants/networks.js +170 -0
- package/lib/constants/proposals/index.d.ts +5 -0
- package/lib/constants/proposals/index.js +8 -0
- package/lib/constants/proposals/polygon_proposal_title.d.ts +1 -0
- package/lib/constants/proposals/polygon_proposal_title.js +4 -0
- package/lib/constants/proposals/uniswap_grants_proposal_description.d.ts +1 -0
- package/lib/constants/proposals/uniswap_grants_proposal_description.js +4 -0
- package/lib/constants/providers.d.ts +19 -0
- package/lib/constants/providers.js +33 -0
- package/lib/constants/routing.d.ts +9 -13
- package/lib/constants/routing.js +91 -55
- package/lib/constants/routing.test.d.ts +1 -0
- package/lib/constants/routing.test.js +32 -0
- package/lib/constants/supportArticles.d.ts +13 -0
- package/lib/constants/supportArticles.js +17 -0
- package/lib/constants/tokenLists/broken.tokenlist.json +22 -0
- package/lib/constants/tokenLogoLookup.d.ts +8 -0
- package/lib/constants/tokenLogoLookup.js +48 -0
- package/lib/constants/tokenSafety.js +129 -0
- package/lib/constants/tokenSafetyLookup.d.ts +18 -0
- package/lib/constants/tokenSafetyLookup.js +66 -0
- package/lib/constants/tokenSaftey.test.d.ts +1 -0
- package/lib/constants/tokenSaftey.test.js +31 -0
- package/lib/constants/tokens.d.ts +34 -42
- package/lib/constants/tokens.js +190 -147
- package/lib/index.d.ts +1 -40
- package/lib/index.js +150 -570
- package/lib/routing/clientSideSmartOrderRouter.d.ts +5 -0
- package/lib/routing/clientSideSmartOrderRouter.js +136 -0
- package/lib/routing/gas.d.ts +5 -0
- package/lib/routing/gas.js +158 -0
- package/lib/routing/types.d.ts +393 -0
- package/lib/routing/types.js +424 -0
- package/lib/routing/utils.d.ts +28 -0
- package/lib/routing/utils.js +319 -0
- package/lib/rpc/AppJsonRpcProvider.d.ts +44 -0
- package/lib/rpc/AppJsonRpcProvider.js +183 -0
- package/lib/rpc/ConfiguredJsonRpcProvider.d.ts +8 -0
- package/lib/rpc/ConfiguredJsonRpcProvider.js +35 -0
- package/lib/utils/contracts/getContract.d.ts +3 -0
- package/lib/utils/contracts/getContract.js +29 -0
- package/lib/utils/transformSwapRouteToGetQuoteResult.d.ts +4 -0
- package/lib/utils/transformSwapRouteToGetQuoteResult.js +116 -0
- package/lib/utils/uniswapData.d.ts +21 -0
- package/lib/utils/uniswapData.js +217 -0
- package/package.json +12 -8
- package/lib/constants/addresses.d.ts +0 -9
- package/lib/constants/addresses.js +0 -41
- package/lib/constants/eip1193.d.ts +0 -8
- package/lib/constants/eip1193.js +0 -14
- package/lib/constants/index.d.ts +0 -9
- package/lib/constants/index.js +0 -26
- package/lib/constants/jsonRpcEndpoints.d.ts +0 -12
- package/lib/constants/jsonRpcEndpoints.js +0 -101
- package/lib/constants/utils/constructSameAddressMap.d.ts +0 -4
- package/lib/constants/utils/constructSameAddressMap.js +0 -19
|
@@ -0,0 +1,424 @@
|
|
|
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
|
+
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.isClassicQuoteResponse = exports.QuoteIntent = exports.RouterPreference = exports.INTERNAL_ROUTER_PREFERENCE_PRICE = exports.QuoteMethod = exports.TradeState = void 0;
|
|
31
|
+
var constants_1 = require("@ethersproject/constants");
|
|
32
|
+
var router_sdk_1 = require("@uniswap/router-sdk");
|
|
33
|
+
var sdk_core_1 = require("@uniswap/sdk-core");
|
|
34
|
+
var uniswapx_sdk_1 = require("@uniswap/uniswapx-sdk");
|
|
35
|
+
var misc_1 = require("../constants/misc");
|
|
36
|
+
var ethers_1 = require("ethers/lib/ethers");
|
|
37
|
+
var SignatureType;
|
|
38
|
+
(function (SignatureType) {
|
|
39
|
+
SignatureType["SIGN_UNISWAPX_ORDER"] = "signUniswapXOrder";
|
|
40
|
+
SignatureType["SIGN_UNISWAPX_V2_ORDER"] = "signUniswapXV2Order";
|
|
41
|
+
SignatureType["SIGN_LIMIT"] = "signLimit";
|
|
42
|
+
})(SignatureType || (SignatureType = {}));
|
|
43
|
+
var TradeState;
|
|
44
|
+
(function (TradeState) {
|
|
45
|
+
TradeState["LOADING"] = "loading";
|
|
46
|
+
TradeState["INVALID"] = "invalid";
|
|
47
|
+
TradeState["STALE"] = "stale";
|
|
48
|
+
TradeState["NO_ROUTE_FOUND"] = "no_route_found";
|
|
49
|
+
TradeState["VALID"] = "valid";
|
|
50
|
+
})(TradeState || (exports.TradeState = TradeState = {}));
|
|
51
|
+
var QuoteMethod;
|
|
52
|
+
(function (QuoteMethod) {
|
|
53
|
+
QuoteMethod["ROUTING_API"] = "ROUTING_API";
|
|
54
|
+
QuoteMethod["QUICK_ROUTE"] = "QUICK_ROUTE";
|
|
55
|
+
QuoteMethod["CLIENT_SIDE_FALLBACK"] = "CLIENT_SIDE_FALLBACK";
|
|
56
|
+
})(QuoteMethod || (exports.QuoteMethod = QuoteMethod = {}));
|
|
57
|
+
// This is excluded from `RouterPreference` enum because it's only used
|
|
58
|
+
// internally for token -> USDC trades to get a USD value.
|
|
59
|
+
exports.INTERNAL_ROUTER_PREFERENCE_PRICE = 'price';
|
|
60
|
+
var RouterPreference;
|
|
61
|
+
(function (RouterPreference) {
|
|
62
|
+
RouterPreference["X"] = "uniswapx";
|
|
63
|
+
RouterPreference["API"] = "api";
|
|
64
|
+
})(RouterPreference || (exports.RouterPreference = RouterPreference = {}));
|
|
65
|
+
// TODO(limits): add Limit market price intent
|
|
66
|
+
var QuoteIntent;
|
|
67
|
+
(function (QuoteIntent) {
|
|
68
|
+
QuoteIntent["Pricing"] = "pricing";
|
|
69
|
+
QuoteIntent["Quote"] = "quote";
|
|
70
|
+
})(QuoteIntent || (exports.QuoteIntent = QuoteIntent = {}));
|
|
71
|
+
function isClassicQuoteResponse(data) {
|
|
72
|
+
return data.routing === URAQuoteType.CLASSIC;
|
|
73
|
+
}
|
|
74
|
+
exports.isClassicQuoteResponse = isClassicQuoteResponse;
|
|
75
|
+
var TradeFillType;
|
|
76
|
+
(function (TradeFillType) {
|
|
77
|
+
TradeFillType["Classic"] = "classic";
|
|
78
|
+
TradeFillType["UniswapX"] = "uniswap_x";
|
|
79
|
+
TradeFillType["None"] = "none";
|
|
80
|
+
})(TradeFillType || (exports.TradeFillType = TradeFillType = {}));
|
|
81
|
+
var ClassicTrade = /** @class */ (function (_super) {
|
|
82
|
+
__extends(ClassicTrade, _super);
|
|
83
|
+
function ClassicTrade(_a) {
|
|
84
|
+
var _this = this;
|
|
85
|
+
var gasUseEstimate = _a.gasUseEstimate, gasUseEstimateUSD = _a.gasUseEstimateUSD, blockNumber = _a.blockNumber, requestId = _a.requestId, quoteMethod = _a.quoteMethod, approveInfo = _a.approveInfo, swapFee = _a.swapFee, routes = __rest(_a, ["gasUseEstimate", "gasUseEstimateUSD", "blockNumber", "requestId", "quoteMethod", "approveInfo", "swapFee"]);
|
|
86
|
+
_this = _super.call(this, routes) || this;
|
|
87
|
+
_this.fillType = TradeFillType.Classic;
|
|
88
|
+
_this.blockNumber = blockNumber;
|
|
89
|
+
_this.gasUseEstimateUSD = gasUseEstimateUSD;
|
|
90
|
+
_this.requestId = requestId;
|
|
91
|
+
_this.quoteMethod = quoteMethod;
|
|
92
|
+
_this.approveInfo = approveInfo;
|
|
93
|
+
_this.swapFee = swapFee;
|
|
94
|
+
_this.gasUseEstimate = gasUseEstimate;
|
|
95
|
+
return _this;
|
|
96
|
+
}
|
|
97
|
+
Object.defineProperty(ClassicTrade.prototype, "executionPrice", {
|
|
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));
|
|
133
|
+
exports.ClassicTrade = ClassicTrade;
|
|
134
|
+
var OffchainOrderType;
|
|
135
|
+
(function (OffchainOrderType) {
|
|
136
|
+
OffchainOrderType["DUTCH_AUCTION"] = "Dutch";
|
|
137
|
+
OffchainOrderType["DUTCH_V2_AUCTION"] = "Dutch_V2";
|
|
138
|
+
OffchainOrderType["LIMIT_ORDER"] = "Limit";
|
|
139
|
+
})(OffchainOrderType || (exports.OffchainOrderType = OffchainOrderType = {}));
|
|
140
|
+
exports.OFFCHAIN_ORDER_TYPE_TO_SIGNATURE_TYPE = (_a = {},
|
|
141
|
+
_a[OffchainOrderType.DUTCH_AUCTION] = SignatureType.SIGN_UNISWAPX_ORDER,
|
|
142
|
+
_a[OffchainOrderType.DUTCH_V2_AUCTION] = SignatureType.SIGN_UNISWAPX_V2_ORDER,
|
|
143
|
+
_a[OffchainOrderType.LIMIT_ORDER] = SignatureType.SIGN_LIMIT,
|
|
144
|
+
_a);
|
|
145
|
+
var DutchOrderTrade = /** @class */ (function (_super) {
|
|
146
|
+
__extends(DutchOrderTrade, _super);
|
|
147
|
+
function DutchOrderTrade(_a) {
|
|
148
|
+
var currencyIn = _a.currencyIn, currenciesOut = _a.currenciesOut, orderInfo = _a.orderInfo, tradeType = _a.tradeType, quoteId = _a.quoteId, requestId = _a.requestId, wrapInfo = _a.wrapInfo, approveInfo = _a.approveInfo, classicGasUseEstimateUSD = _a.classicGasUseEstimateUSD, auctionPeriodSecs = _a.auctionPeriodSecs, startTimeBufferSecs = _a.startTimeBufferSecs, deadlineBufferSecs = _a.deadlineBufferSecs, slippageTolerance = _a.slippageTolerance, swapFee = _a.swapFee;
|
|
149
|
+
var _this = _super.call(this, { currencyIn: currencyIn, currenciesOut: currenciesOut, orderInfo: orderInfo, tradeType: tradeType }) || this;
|
|
150
|
+
_this.fillType = TradeFillType.UniswapX;
|
|
151
|
+
_this.offchainOrderType = OffchainOrderType.DUTCH_AUCTION;
|
|
152
|
+
_this.inputTax = misc_1.ZERO_PERCENT;
|
|
153
|
+
_this.outputTax = misc_1.ZERO_PERCENT;
|
|
154
|
+
_this.quoteId = quoteId;
|
|
155
|
+
_this.requestId = requestId;
|
|
156
|
+
_this.approveInfo = approveInfo;
|
|
157
|
+
_this.wrapInfo = wrapInfo;
|
|
158
|
+
_this.classicGasUseEstimateUSD = classicGasUseEstimateUSD;
|
|
159
|
+
_this.auctionPeriodSecs = auctionPeriodSecs;
|
|
160
|
+
_this.deadlineBufferSecs = deadlineBufferSecs;
|
|
161
|
+
_this.slippageTolerance = slippageTolerance;
|
|
162
|
+
_this.startTimeBufferSecs = startTimeBufferSecs;
|
|
163
|
+
_this.swapFee = swapFee;
|
|
164
|
+
return _this;
|
|
165
|
+
}
|
|
166
|
+
Object.defineProperty(DutchOrderTrade.prototype, "totalGasUseEstimateUSD", {
|
|
167
|
+
get: function () {
|
|
168
|
+
if (this.wrapInfo.needsWrap && this.approveInfo.needsApprove) {
|
|
169
|
+
return this.wrapInfo.wrapGasEstimateUSD + this.approveInfo.approveGasEstimateUSD;
|
|
170
|
+
}
|
|
171
|
+
if (this.wrapInfo.needsWrap)
|
|
172
|
+
return this.wrapInfo.wrapGasEstimateUSD;
|
|
173
|
+
if (this.approveInfo.needsApprove)
|
|
174
|
+
return this.approveInfo.approveGasEstimateUSD;
|
|
175
|
+
return 0;
|
|
176
|
+
},
|
|
177
|
+
enumerable: false,
|
|
178
|
+
configurable: true
|
|
179
|
+
});
|
|
180
|
+
DutchOrderTrade.prototype.asDutchOrderTrade = function () {
|
|
181
|
+
return this;
|
|
182
|
+
};
|
|
183
|
+
return DutchOrderTrade;
|
|
184
|
+
}(uniswapx_sdk_1.DutchOrderTrade));
|
|
185
|
+
exports.DutchOrderTrade = DutchOrderTrade;
|
|
186
|
+
var PreviewTrade = /** @class */ (function () {
|
|
187
|
+
function PreviewTrade(_a) {
|
|
188
|
+
var inputAmount = _a.inputAmount, outputAmount = _a.outputAmount, tradeType = _a.tradeType;
|
|
189
|
+
this.fillType = TradeFillType.None;
|
|
190
|
+
this.quoteMethod = QuoteMethod.QUICK_ROUTE;
|
|
191
|
+
this.inputAmount = inputAmount;
|
|
192
|
+
this.outputAmount = outputAmount;
|
|
193
|
+
this.tradeType = tradeType;
|
|
194
|
+
}
|
|
195
|
+
// below methods are copied from router-sdk
|
|
196
|
+
// Trade https://github.com/Uniswap/router-sdk/blob/main/src/entities/trade.ts#L10
|
|
197
|
+
PreviewTrade.prototype.minimumAmountOut = function (slippageTolerance, amountOut) {
|
|
198
|
+
if (amountOut === void 0) { amountOut = this.outputAmount; }
|
|
199
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
200
|
+
return amountOut;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
var slippageAdjustedAmountOut = new sdk_core_1.Fraction(router_sdk_1.ONE)
|
|
204
|
+
.add(slippageTolerance)
|
|
205
|
+
.invert()
|
|
206
|
+
.multiply(amountOut.quotient).quotient;
|
|
207
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
PreviewTrade.prototype.maximumAmountIn = function (slippageTolerance, amountIn) {
|
|
211
|
+
if (amountIn === void 0) { amountIn = this.inputAmount; }
|
|
212
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
213
|
+
return amountIn;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
var slippageAdjustedAmountIn = new sdk_core_1.Fraction(router_sdk_1.ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
|
|
217
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
Object.defineProperty(PreviewTrade.prototype, "inputTax", {
|
|
221
|
+
/**
|
|
222
|
+
* Returns the sell tax of the input token
|
|
223
|
+
*/
|
|
224
|
+
get: function () {
|
|
225
|
+
var inputCurrency = this.inputAmount.currency;
|
|
226
|
+
if (inputCurrency.isNative || !inputCurrency.wrapped.sellFeeBps)
|
|
227
|
+
return misc_1.ZERO_PERCENT;
|
|
228
|
+
return new sdk_core_1.Percent(inputCurrency.wrapped.sellFeeBps.toNumber(), 10000);
|
|
229
|
+
},
|
|
230
|
+
enumerable: false,
|
|
231
|
+
configurable: true
|
|
232
|
+
});
|
|
233
|
+
Object.defineProperty(PreviewTrade.prototype, "outputTax", {
|
|
234
|
+
/**
|
|
235
|
+
* Returns the buy tax of the output token
|
|
236
|
+
*/
|
|
237
|
+
get: function () {
|
|
238
|
+
var outputCurrency = this.outputAmount.currency;
|
|
239
|
+
if (outputCurrency.isNative || !outputCurrency.wrapped.buyFeeBps)
|
|
240
|
+
return misc_1.ZERO_PERCENT;
|
|
241
|
+
return new sdk_core_1.Percent(outputCurrency.wrapped.buyFeeBps.toNumber(), 10000);
|
|
242
|
+
},
|
|
243
|
+
enumerable: false,
|
|
244
|
+
configurable: true
|
|
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) {
|
|
258
|
+
return new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
|
|
259
|
+
};
|
|
260
|
+
return PreviewTrade;
|
|
261
|
+
}());
|
|
262
|
+
exports.PreviewTrade = PreviewTrade;
|
|
263
|
+
// TODO(limits): get this from uniswapx-sdk
|
|
264
|
+
var UNISWAPX_REACTOR = '0x6000da47483062a0d734ba3dc7576ce6a0b645c4';
|
|
265
|
+
var LimitOrderTrade = /** @class */ (function () {
|
|
266
|
+
function LimitOrderTrade(_a) {
|
|
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;
|
|
268
|
+
this.fillType = TradeFillType.UniswapX;
|
|
269
|
+
this.offchainOrderType = OffchainOrderType.LIMIT_ORDER;
|
|
270
|
+
// Placeholder values that aren't used in a limit trade
|
|
271
|
+
this.inputTax = misc_1.ZERO_PERCENT;
|
|
272
|
+
this.outputTax = misc_1.ZERO_PERCENT;
|
|
273
|
+
this.slippageTolerance = misc_1.ZERO_PERCENT;
|
|
274
|
+
this.quoteId = undefined;
|
|
275
|
+
this.requestId = undefined;
|
|
276
|
+
this.deadlineBufferSecs = deadlineBufferSecs;
|
|
277
|
+
this.swapFee = swapFee;
|
|
278
|
+
this.wrapInfo = wrapInfo;
|
|
279
|
+
this.approveInfo = approveInfo;
|
|
280
|
+
this.amountIn = amountIn;
|
|
281
|
+
this.amountOut = amountOut;
|
|
282
|
+
this.tradeType = tradeType;
|
|
283
|
+
this.swapper = swapper;
|
|
284
|
+
// deadline is shown in the review modal, but updated on submission
|
|
285
|
+
var nowSecs = Math.floor(Date.now() / 1000);
|
|
286
|
+
this.deadline = (nowSecs + deadlineBufferSecs) * 1000;
|
|
287
|
+
}
|
|
288
|
+
LimitOrderTrade.prototype.asDutchOrderTrade = function (options) {
|
|
289
|
+
var _a, _b, _c;
|
|
290
|
+
var swapperOutput = {
|
|
291
|
+
token: this.amountOut.currency.isNative ? constants_1.AddressZero : this.amountOut.currency.address,
|
|
292
|
+
recipient: (_a = options === null || options === void 0 ? void 0 : options.swapper) !== null && _a !== void 0 ? _a : this.swapper,
|
|
293
|
+
startAmount: ethers_1.BigNumber.from(this.amountOut.quotient.toString()),
|
|
294
|
+
endAmount: ethers_1.BigNumber.from(this.amountOut.quotient.toString()),
|
|
295
|
+
};
|
|
296
|
+
var swapFee = this.swapFee && {
|
|
297
|
+
token: this.amountOut.currency.isNative ? constants_1.AddressZero : this.amountOut.currency.address,
|
|
298
|
+
recipient: this.swapFee.recipient,
|
|
299
|
+
startAmount: ethers_1.BigNumber.from(this.amountOut.multiply(this.swapFee.percent).quotient.toString()),
|
|
300
|
+
endAmount: ethers_1.BigNumber.from(this.amountOut.multiply(this.swapFee.percent).quotient.toString()),
|
|
301
|
+
};
|
|
302
|
+
var outputs = swapFee ? [swapperOutput, swapFee] : [swapperOutput];
|
|
303
|
+
var nowSecs = Math.floor(Date.now() / 1000);
|
|
304
|
+
return new uniswapx_sdk_1.DutchOrderTrade({
|
|
305
|
+
currencyIn: this.amountIn.currency,
|
|
306
|
+
currenciesOut: [this.amountOut.currency],
|
|
307
|
+
orderInfo: {
|
|
308
|
+
reactor: UNISWAPX_REACTOR,
|
|
309
|
+
swapper: (_b = options === null || options === void 0 ? void 0 : options.swapper) !== null && _b !== void 0 ? _b : this.swapper,
|
|
310
|
+
deadline: (nowSecs + this.deadlineBufferSecs) * 1000,
|
|
311
|
+
additionalValidationContract: constants_1.AddressZero,
|
|
312
|
+
additionalValidationData: '0x',
|
|
313
|
+
nonce: (_c = options === null || options === void 0 ? void 0 : options.nonce) !== null && _c !== void 0 ? _c : ethers_1.BigNumber.from(0),
|
|
314
|
+
// decay timings dont matter at all
|
|
315
|
+
decayStartTime: nowSecs,
|
|
316
|
+
decayEndTime: nowSecs,
|
|
317
|
+
exclusiveFiller: constants_1.AddressZero,
|
|
318
|
+
exclusivityOverrideBps: ethers_1.BigNumber.from(0),
|
|
319
|
+
input: {
|
|
320
|
+
token: this.amountIn.currency.isNative ? constants_1.AddressZero : this.amountIn.currency.address,
|
|
321
|
+
startAmount: ethers_1.BigNumber.from(this.amountIn.quotient.toString()),
|
|
322
|
+
endAmount: ethers_1.BigNumber.from(this.amountIn.quotient.toString()),
|
|
323
|
+
},
|
|
324
|
+
outputs: outputs,
|
|
325
|
+
},
|
|
326
|
+
tradeType: this.tradeType,
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
Object.defineProperty(LimitOrderTrade.prototype, "inputAmount", {
|
|
330
|
+
get: function () {
|
|
331
|
+
return this.amountIn;
|
|
332
|
+
},
|
|
333
|
+
enumerable: false,
|
|
334
|
+
configurable: true
|
|
335
|
+
});
|
|
336
|
+
Object.defineProperty(LimitOrderTrade.prototype, "outputAmount", {
|
|
337
|
+
get: function () {
|
|
338
|
+
return this.amountOut;
|
|
339
|
+
},
|
|
340
|
+
enumerable: false,
|
|
341
|
+
configurable: true
|
|
342
|
+
});
|
|
343
|
+
Object.defineProperty(LimitOrderTrade.prototype, "postTaxOutputAmount", {
|
|
344
|
+
/** For UniswapX, handling token taxes in the output amount is outsourced to quoters */
|
|
345
|
+
get: function () {
|
|
346
|
+
return this.outputAmount;
|
|
347
|
+
},
|
|
348
|
+
enumerable: false,
|
|
349
|
+
configurable: true
|
|
350
|
+
});
|
|
351
|
+
Object.defineProperty(LimitOrderTrade.prototype, "totalGasUseEstimateUSD", {
|
|
352
|
+
get: function () {
|
|
353
|
+
return this.wrapInfo.needsWrap ? this.wrapInfo.wrapGasEstimateUSD : 0;
|
|
354
|
+
},
|
|
355
|
+
enumerable: false,
|
|
356
|
+
configurable: true
|
|
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 () {
|
|
389
|
+
return this.executionPrice;
|
|
390
|
+
};
|
|
391
|
+
LimitOrderTrade.prototype.maximumAmountIn = function () {
|
|
392
|
+
return this.inputAmount;
|
|
393
|
+
};
|
|
394
|
+
LimitOrderTrade.prototype.minimumAmountOut = function () {
|
|
395
|
+
return this.outputAmount;
|
|
396
|
+
};
|
|
397
|
+
return LimitOrderTrade;
|
|
398
|
+
}());
|
|
399
|
+
exports.LimitOrderTrade = LimitOrderTrade;
|
|
400
|
+
var QuoteState;
|
|
401
|
+
(function (QuoteState) {
|
|
402
|
+
QuoteState["SUCCESS"] = "Success";
|
|
403
|
+
QuoteState["NOT_FOUND"] = "Not found";
|
|
404
|
+
})(QuoteState || (exports.QuoteState = QuoteState = {}));
|
|
405
|
+
var PoolType;
|
|
406
|
+
(function (PoolType) {
|
|
407
|
+
PoolType["V2Pool"] = "v2-pool";
|
|
408
|
+
PoolType["V3Pool"] = "v3-pool";
|
|
409
|
+
})(PoolType || (exports.PoolType = PoolType = {}));
|
|
410
|
+
// swap router API special cases these strings to represent native currencies
|
|
411
|
+
// all chains except for bnb chain and polygon
|
|
412
|
+
// have "ETH" as native currency symbol
|
|
413
|
+
var SwapRouterNativeAssets;
|
|
414
|
+
(function (SwapRouterNativeAssets) {
|
|
415
|
+
SwapRouterNativeAssets["MATIC"] = "MATIC";
|
|
416
|
+
SwapRouterNativeAssets["BNB"] = "BNB";
|
|
417
|
+
SwapRouterNativeAssets["AVAX"] = "AVAX";
|
|
418
|
+
SwapRouterNativeAssets["ETH"] = "ETH";
|
|
419
|
+
})(SwapRouterNativeAssets || (exports.SwapRouterNativeAssets = SwapRouterNativeAssets = {}));
|
|
420
|
+
var URAQuoteType;
|
|
421
|
+
(function (URAQuoteType) {
|
|
422
|
+
URAQuoteType["CLASSIC"] = "CLASSIC";
|
|
423
|
+
URAQuoteType["DUTCH_LIMIT"] = "DUTCH_LIMIT";
|
|
424
|
+
})(URAQuoteType || (exports.URAQuoteType = URAQuoteType = {}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MixedRouteSDK } from '@uniswap/router-sdk';
|
|
2
|
+
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core';
|
|
3
|
+
import { Route as V2Route } from '@uniswap/v2-sdk';
|
|
4
|
+
import { Route as V3Route } from '@uniswap/v3-sdk';
|
|
5
|
+
import { ClassicQuoteData, ClassicTrade, DutchOrderTrade, GetQuickQuoteArgs, GetQuoteArgs, InterfaceTrade, LimitOrderTrade, PreviewTrade, QuickRouteResponse, QuoteMethod, SubmittableTrade, TradeResult, URAQuoteResponse } from './types';
|
|
6
|
+
interface RouteResult {
|
|
7
|
+
routev3: V3Route<Currency, Currency> | null;
|
|
8
|
+
routev2: V2Route<Currency, Currency> | null;
|
|
9
|
+
mixedRoute: MixedRouteSDK<Currency, Currency> | null;
|
|
10
|
+
inputAmount: CurrencyAmount<Currency>;
|
|
11
|
+
outputAmount: CurrencyAmount<Currency>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Transforms a Routing API quote into an array of routes that can be used to
|
|
15
|
+
* create a `Trade`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeRoutes(args: GetQuoteArgs, routes: ClassicQuoteData['route']): RouteResult[] | undefined;
|
|
18
|
+
export declare function transformQuickRouteToTrade(args: GetQuickQuoteArgs, data: QuickRouteResponse): PreviewTrade;
|
|
19
|
+
export declare function getUSDCostPerGas(gasUseEstimateUSD?: number, gasUseEstimate?: number): number | undefined;
|
|
20
|
+
export declare function transformQuoteToTrade(args: GetQuoteArgs, data: URAQuoteResponse, quoteMethod: QuoteMethod): Promise<TradeResult>;
|
|
21
|
+
export declare function isExactInput(tradeType: TradeType): boolean;
|
|
22
|
+
export declare function currencyAddressForSwapQuote(currency: Currency): string;
|
|
23
|
+
export declare function isClassicTrade(trade?: InterfaceTrade): trade is ClassicTrade;
|
|
24
|
+
export declare function isPreviewTrade(trade?: InterfaceTrade): trade is PreviewTrade;
|
|
25
|
+
export declare function isSubmittableTrade(trade?: InterfaceTrade): trade is SubmittableTrade;
|
|
26
|
+
export declare function isUniswapXTrade(trade?: InterfaceTrade): trade is DutchOrderTrade | LimitOrderTrade;
|
|
27
|
+
export declare function isLimitTrade(trade?: InterfaceTrade): trade is LimitOrderTrade;
|
|
28
|
+
export {};
|