@pioneer-platform/uniswap-client 0.0.22 → 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 -641
- 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 +11 -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,5 @@
|
|
|
1
|
+
import { ChainId } from '@uniswap/sdk-core';
|
|
2
|
+
import { AlphaRouter, AlphaRouterConfig } from '@uniswap/smart-order-router';
|
|
3
|
+
import { GetQuoteArgs, QuoteResult } from '../routing/types';
|
|
4
|
+
export declare function getRouter(chainId: ChainId): AlphaRouter;
|
|
5
|
+
export declare function getClientSideQuote({ tokenInAddress, tokenInChainId, tokenInDecimals, tokenInSymbol, tokenOutAddress, tokenOutChainId, tokenOutDecimals, tokenOutSymbol, amount, tradeType, }: GetQuoteArgs, router: AlphaRouter, config: Partial<AlphaRouterConfig>): Promise<QuoteResult>;
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getClientSideQuote = exports.getRouter = void 0;
|
|
43
|
+
var sdk_core_1 = require("@uniswap/sdk-core");
|
|
44
|
+
// This file is lazy-loaded, so the import of smart-order-router is intentional.
|
|
45
|
+
// 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 = [
|
|
54
|
+
sdk_core_1.ChainId.MAINNET,
|
|
55
|
+
sdk_core_1.ChainId.OPTIMISM,
|
|
56
|
+
sdk_core_1.ChainId.OPTIMISM_GOERLI,
|
|
57
|
+
sdk_core_1.ChainId.ARBITRUM_ONE,
|
|
58
|
+
sdk_core_1.ChainId.ARBITRUM_GOERLI,
|
|
59
|
+
sdk_core_1.ChainId.POLYGON,
|
|
60
|
+
sdk_core_1.ChainId.POLYGON_MUMBAI,
|
|
61
|
+
sdk_core_1.ChainId.GOERLI,
|
|
62
|
+
sdk_core_1.ChainId.SEPOLIA,
|
|
63
|
+
sdk_core_1.ChainId.CELO_ALFAJORES,
|
|
64
|
+
sdk_core_1.ChainId.CELO,
|
|
65
|
+
sdk_core_1.ChainId.BNB,
|
|
66
|
+
sdk_core_1.ChainId.AVALANCHE,
|
|
67
|
+
sdk_core_1.ChainId.BASE,
|
|
68
|
+
];
|
|
69
|
+
var routers = new Map();
|
|
70
|
+
function getRouter(chainId) {
|
|
71
|
+
var router = routers.get(chainId);
|
|
72
|
+
if (router)
|
|
73
|
+
return router;
|
|
74
|
+
var supportedChainId = (0, chains_1.asSupportedChain)(chainId);
|
|
75
|
+
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;
|
|
80
|
+
}
|
|
81
|
+
throw new Error("Router does not support this chain (chainId: ".concat(chainId, ")."));
|
|
82
|
+
}
|
|
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
|
+
tokenInIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenIn.address);
|
|
92
|
+
tokenOutIsNative = Object.values(types_1.SwapRouterNativeAssets).includes(tokenOut.address);
|
|
93
|
+
currencyIn = tokenInIsNative
|
|
94
|
+
? (0, tokens_1.nativeOnChain)(tokenIn.chainId)
|
|
95
|
+
: new sdk_core_1.Token(tokenIn.chainId, tokenIn.address, tokenIn.decimals, tokenIn.symbol);
|
|
96
|
+
currencyOut = tokenOutIsNative
|
|
97
|
+
? (0, tokens_1.nativeOnChain)(tokenOut.chainId)
|
|
98
|
+
: new sdk_core_1.Token(tokenOut.chainId, tokenOut.address, tokenOut.decimals, tokenOut.symbol);
|
|
99
|
+
baseCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyIn : currencyOut;
|
|
100
|
+
quoteCurrency = tradeType === sdk_core_1.TradeType.EXACT_INPUT ? currencyOut : currencyIn;
|
|
101
|
+
amount = sdk_core_1.CurrencyAmount.fromRawAmount(baseCurrency, jsbi_1.default.BigInt(amountRaw));
|
|
102
|
+
return [4 /*yield*/, router.route(amount, quoteCurrency, tradeType, /*swapConfig=*/ undefined, routerConfig)];
|
|
103
|
+
case 1:
|
|
104
|
+
swapRoute = _b.sent();
|
|
105
|
+
if (!swapRoute) {
|
|
106
|
+
return [2 /*return*/, { state: types_1.QuoteState.NOT_FOUND }];
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, (0, transformSwapRouteToGetQuoteResult_1.transformSwapRouteToGetQuoteResult)(tradeType, amount, swapRoute)];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function getClientSideQuote(_a, router, config) {
|
|
114
|
+
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;
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_b) {
|
|
117
|
+
return [2 /*return*/, getQuote({
|
|
118
|
+
tradeType: tradeType,
|
|
119
|
+
tokenIn: {
|
|
120
|
+
address: tokenInAddress,
|
|
121
|
+
chainId: tokenInChainId,
|
|
122
|
+
decimals: tokenInDecimals,
|
|
123
|
+
symbol: tokenInSymbol,
|
|
124
|
+
},
|
|
125
|
+
tokenOut: {
|
|
126
|
+
address: tokenOutAddress,
|
|
127
|
+
chainId: tokenOutChainId,
|
|
128
|
+
decimals: tokenOutDecimals,
|
|
129
|
+
symbol: tokenOutSymbol,
|
|
130
|
+
},
|
|
131
|
+
amount: amount,
|
|
132
|
+
}, router, config)];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.getClientSideQuote = getClientSideQuote;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Currency } from '@uniswap/sdk-core';
|
|
2
|
+
import { SupportedInterfaceChain } from '../constants/chains';
|
|
3
|
+
import { ApproveInfo, WrapInfo } from './types';
|
|
4
|
+
export declare function getApproveInfo(account: string | undefined, currency: Currency, amount: string, usdCostPerGas?: number): Promise<ApproveInfo>;
|
|
5
|
+
export declare function getWrapInfo(needsWrap: boolean, account: string | undefined, chainId: SupportedInterfaceChain, amount: string, usdCostPerGas?: number): Promise<WrapInfo>;
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
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");
|
|
61
|
+
// 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
|
+
});
|
|
119
|
+
}
|
|
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
|
+
});
|
|
157
|
+
}
|
|
158
|
+
exports.getWrapInfo = getWrapInfo;
|