@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/utils.js
CHANGED
|
@@ -1,68 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
3
|
+
exports.computeRoutes = computeRoutes;
|
|
4
|
+
exports.transformQuickRouteToTrade = transformQuickRouteToTrade;
|
|
5
|
+
exports.getUSDCostPerGas = getUSDCostPerGas;
|
|
6
|
+
exports.transformQuoteToTrade = transformQuoteToTrade;
|
|
7
|
+
exports.isExactInput = isExactInput;
|
|
8
|
+
exports.currencyAddressForSwapQuote = currencyAddressForSwapQuote;
|
|
9
|
+
exports.isClassicTrade = isClassicTrade;
|
|
10
|
+
exports.isPreviewTrade = isPreviewTrade;
|
|
11
|
+
exports.isSubmittableTrade = isSubmittableTrade;
|
|
12
|
+
exports.isUniswapXTrade = isUniswapXTrade;
|
|
13
|
+
exports.isLimitTrade = isLimitTrade;
|
|
14
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
15
|
+
const router_sdk_1 = require("@uniswap/router-sdk");
|
|
16
|
+
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
17
|
+
const v2_sdk_1 = require("@uniswap/v2-sdk");
|
|
18
|
+
const v3_sdk_1 = require("@uniswap/v3-sdk");
|
|
19
|
+
const misc_1 = require("../constants/misc");
|
|
20
|
+
const tokens_1 = require("../constants/tokens");
|
|
21
|
+
const PRECISION = 10000;
|
|
22
|
+
const DENOMINATOR = PRECISION * 100;
|
|
60
23
|
function toSlippagePercent(slippage) {
|
|
61
|
-
|
|
24
|
+
const numerator = Number(slippage) * PRECISION;
|
|
62
25
|
return new sdk_core_1.Percent(numerator, DENOMINATOR);
|
|
63
26
|
}
|
|
64
|
-
|
|
65
|
-
|
|
27
|
+
const gas_1 = require("./gas");
|
|
28
|
+
const types_1 = require("./types");
|
|
66
29
|
/**
|
|
67
30
|
* Transforms a Routing API quote into an array of routes that can be used to
|
|
68
31
|
* create a `Trade`.
|
|
@@ -70,19 +33,19 @@ var types_1 = require("./types");
|
|
|
70
33
|
function computeRoutes(args, routes) {
|
|
71
34
|
if (routes.length === 0)
|
|
72
35
|
return [];
|
|
73
|
-
|
|
36
|
+
const [currencyIn, currencyOut] = getTradeCurrencies(args, false, routes);
|
|
74
37
|
try {
|
|
75
|
-
return routes.map(
|
|
38
|
+
return routes.map((route) => {
|
|
76
39
|
if (route.length === 0) {
|
|
77
40
|
throw new Error('Expected route to have at least one pair or pool');
|
|
78
41
|
}
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
const rawAmountIn = route[0].amountIn;
|
|
43
|
+
const rawAmountOut = route[route.length - 1].amountOut;
|
|
81
44
|
if (!rawAmountIn || !rawAmountOut) {
|
|
82
45
|
throw new Error('Expected both amountIn and amountOut to be present');
|
|
83
46
|
}
|
|
84
|
-
|
|
85
|
-
|
|
47
|
+
const isOnlyV2 = isVersionedRoute(types_1.PoolType.V2Pool, route);
|
|
48
|
+
const isOnlyV3 = isVersionedRoute(types_1.PoolType.V3Pool, route);
|
|
86
49
|
return {
|
|
87
50
|
routev3: isOnlyV3 ? new v3_sdk_1.Route(route.map(parsePool), currencyIn, currencyOut) : null,
|
|
88
51
|
routev2: isOnlyV2 ? new v2_sdk_1.Route(route.map(parsePair), currencyIn, currencyOut) : null,
|
|
@@ -97,46 +60,58 @@ function computeRoutes(args, routes) {
|
|
|
97
60
|
return;
|
|
98
61
|
}
|
|
99
62
|
}
|
|
100
|
-
|
|
101
|
-
var parsePoolOrPair = function (pool) {
|
|
63
|
+
const parsePoolOrPair = (pool) => {
|
|
102
64
|
return pool.type === types_1.PoolType.V3Pool ? parsePool(pool) : parsePair(pool);
|
|
103
65
|
};
|
|
104
66
|
function isVersionedRoute(type, route) {
|
|
105
|
-
return route.every(
|
|
67
|
+
return route.every((pool) => pool.type === type);
|
|
106
68
|
}
|
|
107
69
|
function toDutchOrderInfo(orderInfoJSON) {
|
|
108
|
-
|
|
109
|
-
return
|
|
70
|
+
const { nonce, input, outputs, exclusivityOverrideBps } = orderInfoJSON;
|
|
71
|
+
return {
|
|
72
|
+
...orderInfoJSON,
|
|
73
|
+
nonce: bignumber_1.BigNumber.from(nonce),
|
|
74
|
+
exclusivityOverrideBps: bignumber_1.BigNumber.from(exclusivityOverrideBps),
|
|
75
|
+
input: {
|
|
76
|
+
...input,
|
|
77
|
+
startAmount: bignumber_1.BigNumber.from(input.startAmount),
|
|
78
|
+
endAmount: bignumber_1.BigNumber.from(input.endAmount),
|
|
79
|
+
},
|
|
80
|
+
outputs: outputs.map((output) => ({
|
|
81
|
+
...output,
|
|
82
|
+
startAmount: bignumber_1.BigNumber.from(output.startAmount),
|
|
83
|
+
endAmount: bignumber_1.BigNumber.from(output.endAmount),
|
|
84
|
+
})),
|
|
85
|
+
};
|
|
110
86
|
}
|
|
111
87
|
// Prepares the currencies used for the actual Swap (either UniswapX or Universal Router)
|
|
112
88
|
// May not match `currencyIn` that the user selected because for ETH inputs in UniswapX, the actual
|
|
113
89
|
// swap will use WETH.
|
|
114
90
|
function getTradeCurrencies(args, isUniswapXTrade, routes) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var currencyIn = tokenInIsNative
|
|
91
|
+
const { tokenInAddress, tokenInChainId, tokenInDecimals, tokenInSymbol, tokenOutAddress, tokenOutChainId, tokenOutDecimals, tokenOutSymbol, } = args;
|
|
92
|
+
const tokenInIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenInAddress);
|
|
93
|
+
const tokenOutIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenOutAddress);
|
|
94
|
+
const serializedTokenIn = routes?.[0]?.[0]?.tokenIn;
|
|
95
|
+
const serializedTokenOut = routes?.[0]?.[routes[0]?.length - 1]?.tokenOut;
|
|
96
|
+
const currencyIn = tokenInIsNative
|
|
122
97
|
? (0, tokens_1.nativeOnChain)(tokenInChainId)
|
|
123
98
|
: parseToken({
|
|
124
99
|
address: tokenInAddress,
|
|
125
100
|
chainId: tokenInChainId,
|
|
126
101
|
decimals: tokenInDecimals,
|
|
127
102
|
symbol: tokenInSymbol,
|
|
128
|
-
buyFeeBps: serializedTokenIn
|
|
129
|
-
sellFeeBps: serializedTokenIn
|
|
103
|
+
buyFeeBps: serializedTokenIn?.buyFeeBps,
|
|
104
|
+
sellFeeBps: serializedTokenIn?.sellFeeBps,
|
|
130
105
|
});
|
|
131
|
-
|
|
106
|
+
const currencyOut = tokenOutIsNative
|
|
132
107
|
? (0, tokens_1.nativeOnChain)(tokenOutChainId)
|
|
133
108
|
: parseToken({
|
|
134
109
|
address: tokenOutAddress,
|
|
135
110
|
chainId: tokenOutChainId,
|
|
136
111
|
decimals: tokenOutDecimals,
|
|
137
112
|
symbol: tokenOutSymbol,
|
|
138
|
-
buyFeeBps: serializedTokenOut
|
|
139
|
-
sellFeeBps: serializedTokenOut
|
|
113
|
+
buyFeeBps: serializedTokenOut?.buyFeeBps,
|
|
114
|
+
sellFeeBps: serializedTokenOut?.sellFeeBps,
|
|
140
115
|
});
|
|
141
116
|
if (!isUniswapXTrade) {
|
|
142
117
|
return [currencyIn, currencyOut];
|
|
@@ -144,7 +119,7 @@ function getTradeCurrencies(args, isUniswapXTrade, routes) {
|
|
|
144
119
|
return [currencyIn.isNative ? currencyIn.wrapped : currencyIn, currencyOut];
|
|
145
120
|
}
|
|
146
121
|
function getSwapFee(data) {
|
|
147
|
-
|
|
122
|
+
const { portionAmount, portionBips, portionRecipient } = data;
|
|
148
123
|
if (!portionAmount || !portionBips || !portionRecipient)
|
|
149
124
|
return undefined;
|
|
150
125
|
return {
|
|
@@ -154,8 +129,7 @@ function getSwapFee(data) {
|
|
|
154
129
|
};
|
|
155
130
|
}
|
|
156
131
|
function getClassicTradeDetails(args, data) {
|
|
157
|
-
|
|
158
|
-
var classicQuote = data.routing === types_1.URAQuoteType.CLASSIC ? data.quote : (_a = data.allQuotes.find(types_1.isClassicQuoteResponse)) === null || _a === void 0 ? void 0 : _a.quote;
|
|
132
|
+
const classicQuote = data.routing === types_1.URAQuoteType.CLASSIC ? data.quote : data.allQuotes.find(types_1.isClassicQuoteResponse)?.quote;
|
|
159
133
|
if (!classicQuote) {
|
|
160
134
|
return {};
|
|
161
135
|
}
|
|
@@ -168,122 +142,99 @@ function getClassicTradeDetails(args, data) {
|
|
|
168
142
|
};
|
|
169
143
|
}
|
|
170
144
|
function transformQuickRouteToTrade(args, data) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return new types_1.PreviewTrade({ inputAmount
|
|
145
|
+
const { amount, tradeType } = args;
|
|
146
|
+
const [currencyIn, currencyOut] = getTradeCurrencies(args, false);
|
|
147
|
+
const [rawAmountIn, rawAmountOut] = data.tradeType === 'EXACT_IN' ? [amount, data.quote.amount] : [data.quote.amount, amount];
|
|
148
|
+
const inputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(currencyIn, rawAmountIn);
|
|
149
|
+
const outputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(currencyOut, rawAmountOut);
|
|
150
|
+
return new types_1.PreviewTrade({ inputAmount, outputAmount, tradeType });
|
|
177
151
|
}
|
|
178
|
-
exports.transformQuickRouteToTrade = transformQuickRouteToTrade;
|
|
179
152
|
function getUSDCostPerGas(gasUseEstimateUSD, gasUseEstimate) {
|
|
180
153
|
// Some sus javascript float math but it's ok because its just an estimate for display purposes
|
|
181
154
|
if (!gasUseEstimateUSD || !gasUseEstimate)
|
|
182
155
|
return undefined;
|
|
183
156
|
return gasUseEstimateUSD / gasUseEstimate;
|
|
184
157
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
inputAmount: inputAmount,
|
|
223
|
-
outputAmount: outputAmount,
|
|
224
|
-
});
|
|
225
|
-
})) !== null && _c !== void 0 ? _c : [],
|
|
226
|
-
tradeType: tradeType,
|
|
227
|
-
gasUseEstimateUSD: gasUseEstimateUSD,
|
|
228
|
-
gasUseEstimate: gasUseEstimate,
|
|
229
|
-
approveInfo: approveInfo,
|
|
230
|
-
blockNumber: blockNumber,
|
|
231
|
-
requestId: data.quote.requestId,
|
|
232
|
-
quoteMethod: quoteMethod,
|
|
233
|
-
swapFee: swapFee,
|
|
234
|
-
});
|
|
235
|
-
isUniswapXBetter = data.routing === types_1.URAQuoteType.DUTCH_LIMIT;
|
|
236
|
-
if (!isUniswapXBetter) return [3 /*break*/, 3];
|
|
237
|
-
orderInfo = toDutchOrderInfo(data.quote.orderInfo);
|
|
238
|
-
swapFee_1 = getSwapFee(data.quote);
|
|
239
|
-
return [4 /*yield*/, (0, gas_1.getWrapInfo)(needsWrapIfUniswapX, account, currencyIn.chainId, amount, usdCostPerGas)];
|
|
240
|
-
case 2:
|
|
241
|
-
wrapInfo = _f.sent();
|
|
242
|
-
uniswapXTrade = new types_1.DutchOrderTrade({
|
|
243
|
-
currencyIn: currencyIn,
|
|
244
|
-
currenciesOut: [currencyOut],
|
|
245
|
-
orderInfo: orderInfo,
|
|
246
|
-
tradeType: tradeType,
|
|
247
|
-
quoteId: data.quote.quoteId,
|
|
248
|
-
requestId: data.quote.requestId,
|
|
249
|
-
classicGasUseEstimateUSD: classicTrade.totalGasUseEstimateUSD,
|
|
250
|
-
wrapInfo: wrapInfo,
|
|
251
|
-
approveInfo: approveInfo,
|
|
252
|
-
auctionPeriodSecs: data.quote.auctionPeriodSecs,
|
|
253
|
-
startTimeBufferSecs: data.quote.startTimeBufferSecs,
|
|
254
|
-
deadlineBufferSecs: data.quote.deadlineBufferSecs,
|
|
255
|
-
slippageTolerance: toSlippagePercent(data.quote.slippageTolerance),
|
|
256
|
-
swapFee: swapFee_1,
|
|
257
|
-
});
|
|
258
|
-
return [2 /*return*/, {
|
|
259
|
-
state: types_1.QuoteState.SUCCESS,
|
|
260
|
-
trade: uniswapXTrade,
|
|
261
|
-
}];
|
|
262
|
-
case 3: return [2 /*return*/, { state: types_1.QuoteState.SUCCESS, trade: classicTrade }];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
158
|
+
async function transformQuoteToTrade(args, data, quoteMethod) {
|
|
159
|
+
const { tradeType, needsWrapIfUniswapX, routerPreference, account, amount } = args;
|
|
160
|
+
const showUniswapXTrade = data.routing === types_1.URAQuoteType.DUTCH_LIMIT && routerPreference === types_1.RouterPreference.X;
|
|
161
|
+
const [currencyIn, currencyOut] = getTradeCurrencies(args, showUniswapXTrade);
|
|
162
|
+
const { gasUseEstimateUSD, blockNumber, routes, gasUseEstimate, swapFee } = getClassicTradeDetails(args, data);
|
|
163
|
+
const usdCostPerGas = getUSDCostPerGas(gasUseEstimateUSD, gasUseEstimate);
|
|
164
|
+
const approveInfo = await (0, gas_1.getApproveInfo)(account, currencyIn, amount, usdCostPerGas);
|
|
165
|
+
const classicTrade = new types_1.ClassicTrade({
|
|
166
|
+
v2Routes: routes
|
|
167
|
+
?.filter((r) => r.routev2 !== null)
|
|
168
|
+
.map(({ routev2, inputAmount, outputAmount }) => ({
|
|
169
|
+
routev2,
|
|
170
|
+
inputAmount,
|
|
171
|
+
outputAmount,
|
|
172
|
+
})) ?? [],
|
|
173
|
+
v3Routes: routes
|
|
174
|
+
?.filter((r) => r.routev3 !== null)
|
|
175
|
+
.map(({ routev3, inputAmount, outputAmount }) => ({
|
|
176
|
+
routev3,
|
|
177
|
+
inputAmount,
|
|
178
|
+
outputAmount,
|
|
179
|
+
})) ?? [],
|
|
180
|
+
mixedRoutes: routes
|
|
181
|
+
?.filter((r) => r.mixedRoute !== null)
|
|
182
|
+
.map(({ mixedRoute, inputAmount, outputAmount }) => ({
|
|
183
|
+
mixedRoute,
|
|
184
|
+
inputAmount,
|
|
185
|
+
outputAmount,
|
|
186
|
+
})) ?? [],
|
|
187
|
+
tradeType,
|
|
188
|
+
gasUseEstimateUSD,
|
|
189
|
+
gasUseEstimate,
|
|
190
|
+
approveInfo,
|
|
191
|
+
blockNumber,
|
|
192
|
+
requestId: data.quote.requestId,
|
|
193
|
+
quoteMethod,
|
|
194
|
+
swapFee,
|
|
265
195
|
});
|
|
196
|
+
// If the top-level URA quote type is DUTCH_LIMIT, then UniswapX is better for the user
|
|
197
|
+
const isUniswapXBetter = data.routing === types_1.URAQuoteType.DUTCH_LIMIT;
|
|
198
|
+
if (isUniswapXBetter) {
|
|
199
|
+
const orderInfo = toDutchOrderInfo(data.quote.orderInfo);
|
|
200
|
+
const swapFee = getSwapFee(data.quote);
|
|
201
|
+
const wrapInfo = await (0, gas_1.getWrapInfo)(needsWrapIfUniswapX, account, currencyIn.chainId, amount, usdCostPerGas);
|
|
202
|
+
const uniswapXTrade = new types_1.DutchOrderTrade({
|
|
203
|
+
currencyIn,
|
|
204
|
+
currenciesOut: [currencyOut],
|
|
205
|
+
orderInfo,
|
|
206
|
+
tradeType,
|
|
207
|
+
quoteId: data.quote.quoteId,
|
|
208
|
+
requestId: data.quote.requestId,
|
|
209
|
+
classicGasUseEstimateUSD: classicTrade.totalGasUseEstimateUSD,
|
|
210
|
+
wrapInfo,
|
|
211
|
+
approveInfo,
|
|
212
|
+
auctionPeriodSecs: data.quote.auctionPeriodSecs,
|
|
213
|
+
startTimeBufferSecs: data.quote.startTimeBufferSecs,
|
|
214
|
+
deadlineBufferSecs: data.quote.deadlineBufferSecs,
|
|
215
|
+
slippageTolerance: toSlippagePercent(data.quote.slippageTolerance),
|
|
216
|
+
swapFee,
|
|
217
|
+
});
|
|
218
|
+
return {
|
|
219
|
+
state: types_1.QuoteState.SUCCESS,
|
|
220
|
+
trade: uniswapXTrade,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return { state: types_1.QuoteState.SUCCESS, trade: classicTrade };
|
|
266
224
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
var buyFeeBpsBN = buyFeeBps ? bignumber_1.BigNumber.from(buyFeeBps) : undefined;
|
|
271
|
-
var sellFeeBpsBN = sellFeeBps ? bignumber_1.BigNumber.from(sellFeeBps) : undefined;
|
|
225
|
+
function parseToken({ address, chainId, decimals, symbol, buyFeeBps, sellFeeBps }) {
|
|
226
|
+
const buyFeeBpsBN = buyFeeBps ? bignumber_1.BigNumber.from(buyFeeBps) : undefined;
|
|
227
|
+
const sellFeeBpsBN = sellFeeBps ? bignumber_1.BigNumber.from(sellFeeBps) : undefined;
|
|
272
228
|
return new sdk_core_1.Token(chainId, address, parseInt(decimals.toString()), symbol, undefined, false, buyFeeBpsBN, sellFeeBpsBN);
|
|
273
229
|
}
|
|
274
|
-
function parsePool(
|
|
275
|
-
var fee = _a.fee, sqrtRatioX96 = _a.sqrtRatioX96, liquidity = _a.liquidity, tickCurrent = _a.tickCurrent, tokenIn = _a.tokenIn, tokenOut = _a.tokenOut;
|
|
230
|
+
function parsePool({ fee, sqrtRatioX96, liquidity, tickCurrent, tokenIn, tokenOut }) {
|
|
276
231
|
return new v3_sdk_1.Pool(parseToken(tokenIn), parseToken(tokenOut), parseInt(fee), sqrtRatioX96, liquidity, parseInt(tickCurrent));
|
|
277
232
|
}
|
|
278
|
-
|
|
279
|
-
var reserve0 = _a.reserve0, reserve1 = _a.reserve1;
|
|
280
|
-
return new v2_sdk_1.Pair(sdk_core_1.CurrencyAmount.fromRawAmount(parseToken(reserve0.token), reserve0.quotient), sdk_core_1.CurrencyAmount.fromRawAmount(parseToken(reserve1.token), reserve1.quotient));
|
|
281
|
-
};
|
|
233
|
+
const parsePair = ({ reserve0, reserve1 }) => new v2_sdk_1.Pair(sdk_core_1.CurrencyAmount.fromRawAmount(parseToken(reserve0.token), reserve0.quotient), sdk_core_1.CurrencyAmount.fromRawAmount(parseToken(reserve1.token), reserve1.quotient));
|
|
282
234
|
// TODO(WEB-2050): Convert other instances of tradeType comparison to use this utility function
|
|
283
235
|
function isExactInput(tradeType) {
|
|
284
236
|
return tradeType === sdk_core_1.TradeType.EXACT_INPUT;
|
|
285
237
|
}
|
|
286
|
-
exports.isExactInput = isExactInput;
|
|
287
238
|
function currencyAddressForSwapQuote(currency) {
|
|
288
239
|
if (currency.isNative) {
|
|
289
240
|
if ((0, tokens_1.isPolygon)(currency.chainId))
|
|
@@ -296,24 +247,18 @@ function currencyAddressForSwapQuote(currency) {
|
|
|
296
247
|
}
|
|
297
248
|
return currency.address;
|
|
298
249
|
}
|
|
299
|
-
exports.currencyAddressForSwapQuote = currencyAddressForSwapQuote;
|
|
300
250
|
function isClassicTrade(trade) {
|
|
301
|
-
return
|
|
251
|
+
return trade?.fillType === types_1.TradeFillType.Classic;
|
|
302
252
|
}
|
|
303
|
-
exports.isClassicTrade = isClassicTrade;
|
|
304
253
|
function isPreviewTrade(trade) {
|
|
305
|
-
return
|
|
254
|
+
return trade?.fillType === types_1.TradeFillType.None;
|
|
306
255
|
}
|
|
307
|
-
exports.isPreviewTrade = isPreviewTrade;
|
|
308
256
|
function isSubmittableTrade(trade) {
|
|
309
|
-
return
|
|
257
|
+
return trade?.fillType === types_1.TradeFillType.Classic || trade?.fillType === types_1.TradeFillType.UniswapX;
|
|
310
258
|
}
|
|
311
|
-
exports.isSubmittableTrade = isSubmittableTrade;
|
|
312
259
|
function isUniswapXTrade(trade) {
|
|
313
|
-
return
|
|
260
|
+
return trade?.fillType === types_1.TradeFillType.UniswapX;
|
|
314
261
|
}
|
|
315
|
-
exports.isUniswapXTrade = isUniswapXTrade;
|
|
316
262
|
function isLimitTrade(trade) {
|
|
317
|
-
return
|
|
263
|
+
return trade?.fillType === types_1.TradeFillType.UniswapX && trade?.offchainOrderType === types_1.OffchainOrderType.LIMIT_ORDER;
|
|
318
264
|
}
|
|
319
|
-
exports.isLimitTrade = isLimitTrade;
|