@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,56 +1,21 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getClientSideQuote = exports.getRouter = void 0;
43
- var sdk_core_1 = require("@uniswap/sdk-core");
6
+ exports.getRouter = getRouter;
7
+ exports.getClientSideQuote = getClientSideQuote;
8
+ const sdk_core_1 = require("@uniswap/sdk-core");
44
9
  // This file is lazy-loaded, so the import of smart-order-router is intentional.
45
10
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
46
- var smart_order_router_1 = require("@uniswap/smart-order-router");
47
- var chains_1 = require("../constants/chains");
48
- var providers_1 = require("../constants/providers");
49
- var tokens_1 = require("../constants/tokens");
50
- var jsbi_1 = __importDefault(require("jsbi"));
51
- var types_1 = require("../routing/types");
52
- var transformSwapRouteToGetQuoteResult_1 = require("../utils/transformSwapRouteToGetQuoteResult");
53
- var CLIENT_SIDE_ROUTING_ALLOW_LIST = [
11
+ const smart_order_router_1 = require("@uniswap/smart-order-router");
12
+ const chains_1 = require("../constants/chains");
13
+ const providers_1 = require("../constants/providers");
14
+ const tokens_1 = require("../constants/tokens");
15
+ const jsbi_1 = __importDefault(require("jsbi"));
16
+ const types_1 = require("../routing/types");
17
+ const transformSwapRouteToGetQuoteResult_1 = require("../utils/transformSwapRouteToGetQuoteResult");
18
+ const CLIENT_SIDE_ROUTING_ALLOW_LIST = [
54
19
  sdk_core_1.ChainId.MAINNET,
55
20
  sdk_core_1.ChainId.OPTIMISM,
56
21
  sdk_core_1.ChainId.OPTIMISM_GOERLI,
@@ -66,86 +31,72 @@ var CLIENT_SIDE_ROUTING_ALLOW_LIST = [
66
31
  sdk_core_1.ChainId.AVALANCHE,
67
32
  sdk_core_1.ChainId.BASE,
68
33
  ];
69
- var routers = new Map();
34
+ const routers = new Map();
70
35
  function getRouter(chainId) {
71
- var router = routers.get(chainId);
36
+ const router = routers.get(chainId);
72
37
  if (router)
73
38
  return router;
74
- var supportedChainId = (0, chains_1.asSupportedChain)(chainId);
39
+ const supportedChainId = (0, chains_1.asSupportedChain)(chainId);
75
40
  if (supportedChainId && CLIENT_SIDE_ROUTING_ALLOW_LIST.includes(chainId)) {
76
- var provider = providers_1.RPC_PROVIDERS[supportedChainId];
77
- var router_1 = new smart_order_router_1.AlphaRouter({ chainId: chainId, provider: provider });
78
- routers.set(chainId, router_1);
79
- return router_1;
41
+ const provider = providers_1.RPC_PROVIDERS[supportedChainId];
42
+ const router = new smart_order_router_1.AlphaRouter({ chainId, provider });
43
+ routers.set(chainId, router);
44
+ return router;
80
45
  }
81
- throw new Error("Router does not support this chain (chainId: ".concat(chainId, ")."));
46
+ throw new Error(`Router does not support this chain (chainId: ${chainId}).`);
82
47
  }
83
- exports.getRouter = getRouter;
84
- function getQuote(_a, router, routerConfig) {
85
- var tradeType = _a.tradeType, tokenIn = _a.tokenIn, tokenOut = _a.tokenOut, amountRaw = _a.amount;
86
- return __awaiter(this, void 0, void 0, function () {
87
- var tokenInIsNative, tokenOutIsNative, currencyIn, currencyOut, baseCurrency, quoteCurrency, amount, swapRoute;
88
- return __generator(this, function (_b) {
89
- switch (_b.label) {
90
- case 0:
91
- console.log("Checkpoint: getQuote");
92
- tokenInIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenIn.address);
93
- tokenOutIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenOut.address);
94
- console.log("Checkpoint: getQuote2");
95
- if (tokenInIsNative) {
96
- console.log("Checkpoint: tokenInIsNative");
97
- currencyIn = (0, tokens_1.nativeOnChain)(tokenIn.chainId); // Use the native token for the chain if tokenIn is native
98
- }
99
- else {
100
- console.log("Checkpoint: !tokenInIsNative tokenIn: ", tokenIn);
101
- currencyIn = new sdk_core_1.Token(tokenIn.chainId, tokenIn.address, tokenIn.decimals, tokenIn.symbol); // Otherwise, create a new token
102
- }
103
- if (tokenOutIsNative) {
104
- console.log("Checkpoint: tokenOutIsNative");
105
- currencyOut = (0, tokens_1.nativeOnChain)(tokenOut.chainId); // Use the native token for the chain if tokenOut is native
106
- }
107
- else {
108
- console.log("Checkpoint: !tokenOutIsNative");
109
- currencyOut = new sdk_core_1.Token(tokenOut.chainId, tokenOut.address, tokenOut.decimals, tokenOut.symbol); // Otherwise, create a new token
110
- }
111
- baseCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyIn : currencyOut;
112
- quoteCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyOut : currencyIn;
113
- console.log("baseCurrency", baseCurrency);
114
- console.log("quoteCurrency", quoteCurrency);
115
- amount = sdk_core_1.CurrencyAmount.fromRawAmount(baseCurrency, jsbi_1.default.BigInt(amountRaw));
116
- return [4 /*yield*/, router.route(amount, quoteCurrency, tradeType, /*swapConfig=*/ undefined, routerConfig)];
117
- case 1:
118
- swapRoute = _b.sent();
119
- console.log("swapRoute", swapRoute);
120
- if (!swapRoute) {
121
- return [2 /*return*/, { state: types_1.QuoteState.NOT_FOUND }];
122
- }
123
- return [2 /*return*/, (0, transformSwapRouteToGetQuoteResult_1.transformSwapRouteToGetQuoteResult)(tradeType, amount, swapRoute)];
124
- }
125
- });
126
- });
48
+ async function getQuote({ tradeType, tokenIn, tokenOut, amount: amountRaw, }, router, routerConfig) {
49
+ console.log("Checkpoint: getQuote");
50
+ const tokenInIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenIn.address);
51
+ const tokenOutIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenOut.address);
52
+ console.log("Checkpoint: getQuote2");
53
+ let currencyIn;
54
+ if (tokenInIsNative) {
55
+ console.log("Checkpoint: tokenInIsNative");
56
+ currencyIn = (0, tokens_1.nativeOnChain)(tokenIn.chainId); // Use the native token for the chain if tokenIn is native
57
+ }
58
+ else {
59
+ console.log("Checkpoint: !tokenInIsNative tokenIn: ", tokenIn);
60
+ currencyIn = new sdk_core_1.Token(tokenIn.chainId, tokenIn.address, tokenIn.decimals, tokenIn.symbol); // Otherwise, create a new token
61
+ }
62
+ // Determine the output currency type
63
+ let currencyOut;
64
+ if (tokenOutIsNative) {
65
+ console.log("Checkpoint: tokenOutIsNative");
66
+ currencyOut = (0, tokens_1.nativeOnChain)(tokenOut.chainId); // Use the native token for the chain if tokenOut is native
67
+ }
68
+ else {
69
+ console.log("Checkpoint: !tokenOutIsNative");
70
+ currencyOut = new sdk_core_1.Token(tokenOut.chainId, tokenOut.address, tokenOut.decimals, tokenOut.symbol); // Otherwise, create a new token
71
+ }
72
+ const baseCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyIn : currencyOut;
73
+ const quoteCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyOut : currencyIn;
74
+ console.log("baseCurrency", baseCurrency);
75
+ console.log("quoteCurrency", quoteCurrency);
76
+ const amount = sdk_core_1.CurrencyAmount.fromRawAmount(baseCurrency, jsbi_1.default.BigInt(amountRaw));
77
+ // TODO (WEB-2055): explore initializing client side routing on first load (when amountRaw is null) if there are enough users using client-side router preference.
78
+ const swapRoute = await router.route(amount, quoteCurrency, tradeType, /*swapConfig=*/ undefined, routerConfig);
79
+ console.log("swapRoute", swapRoute);
80
+ if (!swapRoute) {
81
+ return { state: types_1.QuoteState.NOT_FOUND };
82
+ }
83
+ return (0, transformSwapRouteToGetQuoteResult_1.transformSwapRouteToGetQuoteResult)(tradeType, amount, swapRoute);
127
84
  }
128
- function getClientSideQuote(_a, router, config) {
129
- var tokenInAddress = _a.tokenInAddress, tokenInChainId = _a.tokenInChainId, tokenInDecimals = _a.tokenInDecimals, tokenInSymbol = _a.tokenInSymbol, tokenOutAddress = _a.tokenOutAddress, tokenOutChainId = _a.tokenOutChainId, tokenOutDecimals = _a.tokenOutDecimals, tokenOutSymbol = _a.tokenOutSymbol, amount = _a.amount, tradeType = _a.tradeType;
130
- return __awaiter(this, void 0, void 0, function () {
131
- return __generator(this, function (_b) {
132
- return [2 /*return*/, getQuote({
133
- tradeType: tradeType,
134
- tokenIn: {
135
- address: tokenInAddress,
136
- chainId: tokenInChainId,
137
- decimals: tokenInDecimals,
138
- symbol: tokenInSymbol,
139
- },
140
- tokenOut: {
141
- address: tokenOutAddress,
142
- chainId: tokenOutChainId,
143
- decimals: tokenOutDecimals,
144
- symbol: tokenOutSymbol,
145
- },
146
- amount: amount,
147
- }, router, config)];
148
- });
149
- });
85
+ async function getClientSideQuote({ tokenInAddress, tokenInChainId, tokenInDecimals, tokenInSymbol, tokenOutAddress, tokenOutChainId, tokenOutDecimals, tokenOutSymbol, amount, tradeType, }, router, config) {
86
+ return getQuote({
87
+ tradeType,
88
+ tokenIn: {
89
+ address: tokenInAddress,
90
+ chainId: tokenInChainId,
91
+ decimals: tokenInDecimals,
92
+ symbol: tokenInSymbol,
93
+ },
94
+ tokenOut: {
95
+ address: tokenOutAddress,
96
+ chainId: tokenOutChainId,
97
+ decimals: tokenOutDecimals,
98
+ symbol: tokenOutSymbol,
99
+ },
100
+ amount,
101
+ }, router, config);
150
102
  }
151
- exports.getClientSideQuote = getClientSideQuote;
@@ -1,158 +1,71 @@
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
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
5
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.getWrapInfo = exports.getApproveInfo = void 0;
54
- var permit2_sdk_1 = require("@uniswap/permit2-sdk");
55
- var sdk_core_1 = require("@uniswap/sdk-core");
56
- var providers_1 = require("../constants/providers");
57
- var tokens_1 = require("../constants/tokens");
58
- var erc20_json_1 = __importDefault(require("../uniswap/src/abis/erc20.json"));
59
- var weth_json_1 = __importDefault(require("../uniswap/src/abis/weth.json"));
60
- var getContract_1 = require("../utils/contracts/getContract");
6
+ exports.getApproveInfo = getApproveInfo;
7
+ exports.getWrapInfo = getWrapInfo;
8
+ const permit2_sdk_1 = require("@uniswap/permit2-sdk");
9
+ const sdk_core_1 = require("@uniswap/sdk-core");
10
+ const providers_1 = require("../constants/providers");
11
+ const tokens_1 = require("../constants/tokens");
12
+ const erc20_json_1 = __importDefault(require("../uniswap/src/abis/erc20.json"));
13
+ const weth_json_1 = __importDefault(require("../uniswap/src/abis/weth.json"));
14
+ const getContract_1 = require("../utils/contracts/getContract");
61
15
  // TODO(UniswapX): add fallback gas limits per chain? l2s have higher costs
62
- var WRAP_FALLBACK_GAS_LIMIT = 45000;
63
- var APPROVE_FALLBACK_GAS_LIMIT = 65000;
64
- function getApproveInfo(account, currency, amount, usdCostPerGas) {
65
- return __awaiter(this, void 0, void 0, function () {
66
- var provider, tokenContract, approveGasUseEstimate, allowance, _1, approveTx, _2;
67
- return __generator(this, function (_a) {
68
- switch (_a.label) {
69
- case 0:
70
- // native currencies do not need token approvals
71
- if (currency.isNative)
72
- return [2 /*return*/, { needsApprove: false }
73
- // If any of these arguments aren't provided, then we cannot generate approval cost info
74
- ];
75
- // If any of these arguments aren't provided, then we cannot generate approval cost info
76
- if (!account || !usdCostPerGas)
77
- return [2 /*return*/, { needsApprove: false }
78
- // routing-api under estimates gas for Arbitrum swaps so it inflates cost per gas by a lot
79
- // so disable showing approves for Arbitrum until routing-api gives more accurate gas estimates
80
- ];
81
- // routing-api under estimates gas for Arbitrum swaps so it inflates cost per gas by a lot
82
- // so disable showing approves for Arbitrum until routing-api gives more accurate gas estimates
83
- if (currency.chainId === sdk_core_1.ChainId.ARBITRUM_ONE || currency.chainId === sdk_core_1.ChainId.ARBITRUM_GOERLI) {
84
- return [2 /*return*/, { needsApprove: false }];
85
- }
86
- provider = providers_1.RPC_PROVIDERS[currency.chainId];
87
- tokenContract = (0, getContract_1.getContract)(currency.address, erc20_json_1.default, provider);
88
- _a.label = 1;
89
- case 1:
90
- _a.trys.push([1, 3, , 4]);
91
- return [4 /*yield*/, tokenContract.callStatic.allowance(account, permit2_sdk_1.PERMIT2_ADDRESS)];
92
- case 2:
93
- allowance = _a.sent();
94
- if (!allowance.lt(amount))
95
- return [2 /*return*/, { needsApprove: false }];
96
- return [3 /*break*/, 4];
97
- case 3:
98
- _1 = _a.sent();
99
- // If contract lookup fails (eg if Infura goes down), then don't show gas info for approving the token
100
- return [2 /*return*/, { needsApprove: false }];
101
- case 4:
102
- _a.trys.push([4, 7, , 8]);
103
- return [4 /*yield*/, tokenContract.populateTransaction.approve(permit2_sdk_1.PERMIT2_ADDRESS, permit2_sdk_1.MaxUint256)];
104
- case 5:
105
- approveTx = _a.sent();
106
- return [4 /*yield*/, provider.estimateGas(__assign({ from: account }, approveTx))];
107
- case 6:
108
- approveGasUseEstimate = (_a.sent()).toNumber();
109
- return [3 /*break*/, 8];
110
- case 7:
111
- _2 = _a.sent();
112
- // estimateGas will error if the account doesn't have sufficient token balance, but we should show an estimated cost anyway
113
- approveGasUseEstimate = APPROVE_FALLBACK_GAS_LIMIT;
114
- return [3 /*break*/, 8];
115
- case 8: return [2 /*return*/, { needsApprove: true, approveGasEstimateUSD: approveGasUseEstimate * usdCostPerGas }];
116
- }
117
- });
118
- });
16
+ const WRAP_FALLBACK_GAS_LIMIT = 45000;
17
+ const APPROVE_FALLBACK_GAS_LIMIT = 65000;
18
+ async function getApproveInfo(account, currency, amount, usdCostPerGas) {
19
+ // native currencies do not need token approvals
20
+ if (currency.isNative)
21
+ return { needsApprove: false };
22
+ // If any of these arguments aren't provided, then we cannot generate approval cost info
23
+ if (!account || !usdCostPerGas)
24
+ return { needsApprove: false };
25
+ // routing-api under estimates gas for Arbitrum swaps so it inflates cost per gas by a lot
26
+ // so disable showing approves for Arbitrum until routing-api gives more accurate gas estimates
27
+ if (currency.chainId === sdk_core_1.ChainId.ARBITRUM_ONE || currency.chainId === sdk_core_1.ChainId.ARBITRUM_GOERLI) {
28
+ return { needsApprove: false };
29
+ }
30
+ const provider = providers_1.RPC_PROVIDERS[currency.chainId];
31
+ const tokenContract = (0, getContract_1.getContract)(currency.address, erc20_json_1.default, provider);
32
+ let approveGasUseEstimate;
33
+ try {
34
+ const allowance = await tokenContract.callStatic.allowance(account, permit2_sdk_1.PERMIT2_ADDRESS);
35
+ if (!allowance.lt(amount))
36
+ return { needsApprove: false };
37
+ }
38
+ catch (_) {
39
+ // If contract lookup fails (eg if Infura goes down), then don't show gas info for approving the token
40
+ return { needsApprove: false };
41
+ }
42
+ try {
43
+ const approveTx = await tokenContract.populateTransaction.approve(permit2_sdk_1.PERMIT2_ADDRESS, permit2_sdk_1.MaxUint256);
44
+ approveGasUseEstimate = (await provider.estimateGas({ from: account, ...approveTx })).toNumber();
45
+ }
46
+ catch (_) {
47
+ // estimateGas will error if the account doesn't have sufficient token balance, but we should show an estimated cost anyway
48
+ approveGasUseEstimate = APPROVE_FALLBACK_GAS_LIMIT;
49
+ }
50
+ return { needsApprove: true, approveGasEstimateUSD: approveGasUseEstimate * usdCostPerGas };
119
51
  }
120
- exports.getApproveInfo = getApproveInfo;
121
- function getWrapInfo(needsWrap, account, chainId, amount, usdCostPerGas) {
122
- var _a;
123
- return __awaiter(this, void 0, void 0, function () {
124
- var provider, wethAddress, wrapGasUseEstimate, wethContract, wethTx, _3;
125
- return __generator(this, function (_b) {
126
- switch (_b.label) {
127
- case 0:
128
- if (!needsWrap)
129
- return [2 /*return*/, { needsWrap: false }];
130
- provider = providers_1.RPC_PROVIDERS[chainId];
131
- wethAddress = (_a = tokens_1.WRAPPED_NATIVE_CURRENCY[chainId]) === null || _a === void 0 ? void 0 : _a.address;
132
- // If any of these arguments aren't provided, then we cannot generate wrap cost info
133
- if (!wethAddress || !usdCostPerGas)
134
- return [2 /*return*/, { needsWrap: false }];
135
- _b.label = 1;
136
- case 1:
137
- _b.trys.push([1, 4, , 5]);
138
- wethContract = (0, getContract_1.getContract)(wethAddress, weth_json_1.default, provider, account);
139
- return [4 /*yield*/, wethContract.populateTransaction.deposit({ value: amount })
140
- // estimateGas will error if the account doesn't have sufficient ETH balance, but we should show an estimated cost anyway
141
- ];
142
- case 2:
143
- wethTx = _b.sent();
144
- return [4 /*yield*/, provider.estimateGas(__assign({ from: account }, wethTx))];
145
- case 3:
146
- // estimateGas will error if the account doesn't have sufficient ETH balance, but we should show an estimated cost anyway
147
- wrapGasUseEstimate = (_b.sent()).toNumber();
148
- return [3 /*break*/, 5];
149
- case 4:
150
- _3 = _b.sent();
151
- wrapGasUseEstimate = WRAP_FALLBACK_GAS_LIMIT;
152
- return [3 /*break*/, 5];
153
- case 5: return [2 /*return*/, { needsWrap: true, wrapGasEstimateUSD: wrapGasUseEstimate * usdCostPerGas }];
154
- }
155
- });
156
- });
52
+ async function getWrapInfo(needsWrap, account, chainId, amount, usdCostPerGas) {
53
+ if (!needsWrap)
54
+ return { needsWrap: false };
55
+ const provider = providers_1.RPC_PROVIDERS[chainId];
56
+ const wethAddress = tokens_1.WRAPPED_NATIVE_CURRENCY[chainId]?.address;
57
+ // If any of these arguments aren't provided, then we cannot generate wrap cost info
58
+ if (!wethAddress || !usdCostPerGas)
59
+ return { needsWrap: false };
60
+ let wrapGasUseEstimate;
61
+ try {
62
+ const wethContract = (0, getContract_1.getContract)(wethAddress, weth_json_1.default, provider, account);
63
+ const wethTx = await wethContract.populateTransaction.deposit({ value: amount });
64
+ // estimateGas will error if the account doesn't have sufficient ETH balance, but we should show an estimated cost anyway
65
+ wrapGasUseEstimate = (await provider.estimateGas({ from: account, ...wethTx })).toNumber();
66
+ }
67
+ catch (_) {
68
+ wrapGasUseEstimate = WRAP_FALLBACK_GAS_LIMIT;
69
+ }
70
+ return { needsWrap: true, wrapGasEstimateUSD: wrapGasUseEstimate * usdCostPerGas };
157
71
  }
158
- exports.getWrapInfo = getWrapInfo;
@@ -241,8 +241,8 @@ export declare class DutchOrderTrade extends IDutchOrderTrade<Currency, Currency
241
241
  startTimeBufferSecs: number;
242
242
  deadlineBufferSecs: number;
243
243
  slippageTolerance: Percent;
244
- inputTax: Percent;
245
- outputTax: Percent;
244
+ inputTax: any;
245
+ outputTax: any;
246
246
  swapFee: SwapFeeInfo | undefined;
247
247
  constructor({ currencyIn, currenciesOut, orderInfo, tradeType, quoteId, requestId, wrapInfo, approveInfo, classicGasUseEstimateUSD, auctionPeriodSecs, startTimeBufferSecs, deadlineBufferSecs, slippageTolerance, swapFee, }: {
248
248
  currencyIn: Currency;
@@ -303,11 +303,11 @@ export declare class LimitOrderTrade {
303
303
  tradeType: TradeType;
304
304
  swapper: string;
305
305
  deadline: number;
306
- inputTax: Percent;
307
- outputTax: Percent;
308
- slippageTolerance: Percent;
309
- quoteId: undefined;
310
- requestId: undefined;
306
+ inputTax: any;
307
+ outputTax: any;
308
+ slippageTolerance: any;
309
+ quoteId: any;
310
+ requestId: any;
311
311
  constructor({ tradeType, amountIn, amountOut, deadlineBufferSecs, swapFee, wrapInfo, approveInfo, swapper, }: {
312
312
  tradeType: TradeType;
313
313
  amountIn: CurrencyAmount<Token>;