@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/constants/chainInfo.d.ts +2 -2
  3. package/lib/constants/chainInfo.js +40 -43
  4. package/lib/constants/chains.d.ts +20 -20
  5. package/lib/constants/chains.js +25 -26
  6. package/lib/constants/governance.js +13 -14
  7. package/lib/constants/lists.js +20 -28
  8. package/lib/constants/misc.d.ts +4 -5
  9. package/lib/constants/misc.js +2 -2
  10. package/lib/constants/networks.js +45 -46
  11. package/lib/constants/proposals/uniswap_grants_proposal_description.js +106 -1
  12. package/lib/constants/providers.d.ts +16 -15
  13. package/lib/constants/providers.js +23 -24
  14. package/lib/constants/routing.js +44 -61
  15. package/lib/constants/tokens.d.ts +49 -49
  16. package/lib/constants/tokens.js +133 -170
  17. package/lib/index.js +556 -877
  18. package/lib/routing/clientSideSmartOrderRouter.js +72 -121
  19. package/lib/routing/gas.js +63 -150
  20. package/lib/routing/types.d.ts +7 -7
  21. package/lib/routing/types.js +160 -264
  22. package/lib/routing/utils.js +141 -196
  23. package/lib/rpc/AppJsonRpcProvider.js +40 -131
  24. package/lib/rpc/ConfiguredJsonRpcProvider.d.ts +1 -1
  25. package/lib/rpc/ConfiguredJsonRpcProvider.js +8 -27
  26. package/lib/utils/contracts/getContract.js +6 -7
  27. package/lib/utils/transformSwapRouteToGetQuoteResult.js +24 -27
  28. package/lib/utils/uniswapData.d.ts +6 -6
  29. package/lib/utils/uniswapData.js +64 -142
  30. package/package.json +19 -19
  31. package/tsconfig.json +27 -8
  32. package/lib/constants/chains.test.d.ts +0 -1
  33. package/lib/constants/chains.test.js +0 -26
  34. package/lib/constants/localCurrencies.d.ts +0 -6
  35. package/lib/constants/localCurrencies.js +0 -94
  36. package/lib/constants/localCurrencyIcons.d.ts +0 -18
  37. package/lib/constants/localCurrencyIcons.js +0 -298
  38. package/lib/constants/routing.test.d.ts +0 -1
  39. package/lib/constants/routing.test.js +0 -32
  40. package/lib/constants/tokenLists/broken.tokenlist.json +0 -22
  41. package/lib/constants/tokenLogoLookup.d.ts +0 -8
  42. package/lib/constants/tokenLogoLookup.js +0 -48
  43. package/lib/constants/tokenSafety.js +0 -129
  44. package/lib/constants/tokenSafetyLookup.d.ts +0 -18
  45. package/lib/constants/tokenSafetyLookup.js +0 -66
  46. package/lib/constants/tokenSaftey.test.d.ts +0 -1
  47. package/lib/constants/tokenSaftey.test.js +0 -31
@@ -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.isLimitTrade = exports.isUniswapXTrade = exports.isSubmittableTrade = exports.isPreviewTrade = exports.isClassicTrade = exports.currencyAddressForSwapQuote = exports.isExactInput = exports.transformQuoteToTrade = exports.getUSDCostPerGas = exports.transformQuickRouteToTrade = exports.computeRoutes = void 0;
51
- var bignumber_1 = require("@ethersproject/bignumber");
52
- var router_sdk_1 = require("@uniswap/router-sdk");
53
- var sdk_core_1 = require("@uniswap/sdk-core");
54
- var v2_sdk_1 = require("@uniswap/v2-sdk");
55
- var v3_sdk_1 = require("@uniswap/v3-sdk");
56
- var misc_1 = require("../constants/misc");
57
- var tokens_1 = require("../constants/tokens");
58
- var PRECISION = 10000;
59
- var DENOMINATOR = PRECISION * 100;
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
- var numerator = Number(slippage) * PRECISION;
24
+ const numerator = Number(slippage) * PRECISION;
62
25
  return new sdk_core_1.Percent(numerator, DENOMINATOR);
63
26
  }
64
- var gas_1 = require("./gas");
65
- var types_1 = require("./types");
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
- var _a = getTradeCurrencies(args, false, routes), currencyIn = _a[0], currencyOut = _a[1];
36
+ const [currencyIn, currencyOut] = getTradeCurrencies(args, false, routes);
74
37
  try {
75
- return routes.map(function (route) {
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
- var rawAmountIn = route[0].amountIn;
80
- var rawAmountOut = route[route.length - 1].amountOut;
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
- var isOnlyV2 = isVersionedRoute(types_1.PoolType.V2Pool, route);
85
- var isOnlyV3 = isVersionedRoute(types_1.PoolType.V3Pool, route);
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
- exports.computeRoutes = computeRoutes;
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(function (pool) { return pool.type === type; });
67
+ return route.every((pool) => pool.type === type);
106
68
  }
107
69
  function toDutchOrderInfo(orderInfoJSON) {
108
- var nonce = orderInfoJSON.nonce, input = orderInfoJSON.input, outputs = orderInfoJSON.outputs, exclusivityOverrideBps = orderInfoJSON.exclusivityOverrideBps;
109
- return __assign(__assign({}, orderInfoJSON), { nonce: bignumber_1.BigNumber.from(nonce), exclusivityOverrideBps: bignumber_1.BigNumber.from(exclusivityOverrideBps), input: __assign(__assign({}, input), { startAmount: bignumber_1.BigNumber.from(input.startAmount), endAmount: bignumber_1.BigNumber.from(input.endAmount) }), outputs: outputs.map(function (output) { return (__assign(__assign({}, output), { startAmount: bignumber_1.BigNumber.from(output.startAmount), endAmount: bignumber_1.BigNumber.from(output.endAmount) })); }) });
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
- var _a, _b, _c, _d, _e;
116
- var tokenInAddress = args.tokenInAddress, tokenInChainId = args.tokenInChainId, tokenInDecimals = args.tokenInDecimals, tokenInSymbol = args.tokenInSymbol, tokenOutAddress = args.tokenOutAddress, tokenOutChainId = args.tokenOutChainId, tokenOutDecimals = args.tokenOutDecimals, tokenOutSymbol = args.tokenOutSymbol;
117
- var tokenInIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenInAddress);
118
- var tokenOutIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenOutAddress);
119
- var serializedTokenIn = (_b = (_a = routes === null || routes === void 0 ? void 0 : routes[0]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.tokenIn;
120
- var serializedTokenOut = (_e = (_c = routes === null || routes === void 0 ? void 0 : routes[0]) === null || _c === void 0 ? void 0 : _c[((_d = routes[0]) === null || _d === void 0 ? void 0 : _d.length) - 1]) === null || _e === void 0 ? void 0 : _e.tokenOut;
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 === null || serializedTokenIn === void 0 ? void 0 : serializedTokenIn.buyFeeBps,
129
- sellFeeBps: serializedTokenIn === null || serializedTokenIn === void 0 ? void 0 : serializedTokenIn.sellFeeBps,
103
+ buyFeeBps: serializedTokenIn?.buyFeeBps,
104
+ sellFeeBps: serializedTokenIn?.sellFeeBps,
130
105
  });
131
- var currencyOut = tokenOutIsNative
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 === null || serializedTokenOut === void 0 ? void 0 : serializedTokenOut.buyFeeBps,
139
- sellFeeBps: serializedTokenOut === null || serializedTokenOut === void 0 ? void 0 : serializedTokenOut.sellFeeBps,
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
- var portionAmount = data.portionAmount, portionBips = data.portionBips, portionRecipient = data.portionRecipient;
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
- var _a;
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
- var amount = args.amount, tradeType = args.tradeType;
172
- var _a = getTradeCurrencies(args, false), currencyIn = _a[0], currencyOut = _a[1];
173
- var _b = data.tradeType === 'EXACT_IN' ? [amount, data.quote.amount] : [data.quote.amount, amount], rawAmountIn = _b[0], rawAmountOut = _b[1];
174
- var inputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(currencyIn, rawAmountIn);
175
- var outputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(currencyOut, rawAmountOut);
176
- return new types_1.PreviewTrade({ inputAmount: inputAmount, outputAmount: outputAmount, tradeType: tradeType });
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
- exports.getUSDCostPerGas = getUSDCostPerGas;
186
- function transformQuoteToTrade(args, data, quoteMethod) {
187
- var _a, _b, _c;
188
- return __awaiter(this, void 0, void 0, function () {
189
- var tradeType, needsWrapIfUniswapX, routerPreference, account, amount, showUniswapXTrade, _d, currencyIn, currencyOut, _e, gasUseEstimateUSD, blockNumber, routes, gasUseEstimate, swapFee, usdCostPerGas, approveInfo, classicTrade, isUniswapXBetter, orderInfo, swapFee_1, wrapInfo, uniswapXTrade;
190
- return __generator(this, function (_f) {
191
- switch (_f.label) {
192
- case 0:
193
- tradeType = args.tradeType, needsWrapIfUniswapX = args.needsWrapIfUniswapX, routerPreference = args.routerPreference, account = args.account, amount = args.amount;
194
- showUniswapXTrade = data.routing === types_1.URAQuoteType.DUTCH_LIMIT && routerPreference === types_1.RouterPreference.X;
195
- _d = getTradeCurrencies(args, showUniswapXTrade), currencyIn = _d[0], currencyOut = _d[1];
196
- _e = getClassicTradeDetails(args, data), gasUseEstimateUSD = _e.gasUseEstimateUSD, blockNumber = _e.blockNumber, routes = _e.routes, gasUseEstimate = _e.gasUseEstimate, swapFee = _e.swapFee;
197
- usdCostPerGas = getUSDCostPerGas(gasUseEstimateUSD, gasUseEstimate);
198
- return [4 /*yield*/, (0, gas_1.getApproveInfo)(account, currencyIn, amount, usdCostPerGas)];
199
- case 1:
200
- approveInfo = _f.sent();
201
- classicTrade = new types_1.ClassicTrade({
202
- v2Routes: (_a = routes === null || routes === void 0 ? void 0 : routes.filter(function (r) { return r.routev2 !== null; }).map(function (_a) {
203
- var routev2 = _a.routev2, inputAmount = _a.inputAmount, outputAmount = _a.outputAmount;
204
- return ({
205
- routev2: routev2,
206
- inputAmount: inputAmount,
207
- outputAmount: outputAmount,
208
- });
209
- })) !== null && _a !== void 0 ? _a : [],
210
- v3Routes: (_b = routes === null || routes === void 0 ? void 0 : routes.filter(function (r) { return r.routev3 !== null; }).map(function (_a) {
211
- var routev3 = _a.routev3, inputAmount = _a.inputAmount, outputAmount = _a.outputAmount;
212
- return ({
213
- routev3: routev3,
214
- inputAmount: inputAmount,
215
- outputAmount: outputAmount,
216
- });
217
- })) !== null && _b !== void 0 ? _b : [],
218
- mixedRoutes: (_c = routes === null || routes === void 0 ? void 0 : routes.filter(function (r) { return r.mixedRoute !== null; }).map(function (_a) {
219
- var mixedRoute = _a.mixedRoute, inputAmount = _a.inputAmount, outputAmount = _a.outputAmount;
220
- return ({
221
- mixedRoute: mixedRoute,
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
- exports.transformQuoteToTrade = transformQuoteToTrade;
268
- function parseToken(_a) {
269
- var address = _a.address, chainId = _a.chainId, decimals = _a.decimals, symbol = _a.symbol, buyFeeBps = _a.buyFeeBps, sellFeeBps = _a.sellFeeBps;
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(_a) {
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
- var parsePair = function (_a) {
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 (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.Classic;
251
+ return trade?.fillType === types_1.TradeFillType.Classic;
302
252
  }
303
- exports.isClassicTrade = isClassicTrade;
304
253
  function isPreviewTrade(trade) {
305
- return (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.None;
254
+ return trade?.fillType === types_1.TradeFillType.None;
306
255
  }
307
- exports.isPreviewTrade = isPreviewTrade;
308
256
  function isSubmittableTrade(trade) {
309
- return (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.Classic || (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.UniswapX;
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 (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.UniswapX;
260
+ return trade?.fillType === types_1.TradeFillType.UniswapX;
314
261
  }
315
- exports.isUniswapXTrade = isUniswapXTrade;
316
262
  function isLimitTrade(trade) {
317
- return (trade === null || trade === void 0 ? void 0 : trade.fillType) === types_1.TradeFillType.UniswapX && (trade === null || trade === void 0 ? void 0 : trade.offchainOrderType) === types_1.OffchainOrderType.LIMIT_ORDER;
263
+ return trade?.fillType === types_1.TradeFillType.UniswapX && trade?.offchainOrderType === types_1.OffchainOrderType.LIMIT_ORDER;
318
264
  }
319
- exports.isLimitTrade = isLimitTrade;