@pioneer-platform/uniswap-client 0.0.21 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/constants/chainInfo.d.ts +19 -22
  2. package/lib/constants/chainInfo.js +134 -117
  3. package/lib/constants/chains.d.ts +36 -47
  4. package/lib/constants/chains.js +118 -83
  5. package/lib/constants/chains.test.js +22 -25
  6. package/lib/constants/governance.d.ts +8 -0
  7. package/lib/constants/governance.js +24 -0
  8. package/lib/constants/lists.d.ts +12 -0
  9. package/lib/constants/lists.js +64 -0
  10. package/lib/constants/localCurrencies.d.ts +6 -0
  11. package/lib/constants/localCurrencies.js +94 -0
  12. package/lib/constants/localCurrencyIcons.d.ts +18 -0
  13. package/lib/constants/localCurrencyIcons.js +298 -0
  14. package/lib/constants/locales.d.ts +1 -1
  15. package/lib/constants/locales.js +0 -3
  16. package/lib/constants/misc.d.ts +2 -7
  17. package/lib/constants/misc.js +17 -23
  18. package/lib/constants/networks.d.ts +21 -0
  19. package/lib/constants/networks.js +170 -0
  20. package/lib/constants/proposals/index.d.ts +5 -0
  21. package/lib/constants/proposals/index.js +8 -0
  22. package/lib/constants/proposals/polygon_proposal_title.d.ts +1 -0
  23. package/lib/constants/proposals/polygon_proposal_title.js +4 -0
  24. package/lib/constants/proposals/uniswap_grants_proposal_description.d.ts +1 -0
  25. package/lib/constants/proposals/uniswap_grants_proposal_description.js +4 -0
  26. package/lib/constants/providers.d.ts +19 -0
  27. package/lib/constants/providers.js +33 -0
  28. package/lib/constants/routing.d.ts +9 -13
  29. package/lib/constants/routing.js +91 -55
  30. package/lib/constants/routing.test.d.ts +1 -0
  31. package/lib/constants/routing.test.js +32 -0
  32. package/lib/constants/supportArticles.d.ts +13 -0
  33. package/lib/constants/supportArticles.js +17 -0
  34. package/lib/constants/tokenLists/broken.tokenlist.json +22 -0
  35. package/lib/constants/tokenLogoLookup.d.ts +8 -0
  36. package/lib/constants/tokenLogoLookup.js +48 -0
  37. package/lib/constants/tokenSafety.js +129 -0
  38. package/lib/constants/tokenSafetyLookup.d.ts +18 -0
  39. package/lib/constants/tokenSafetyLookup.js +66 -0
  40. package/lib/constants/tokenSaftey.test.d.ts +1 -0
  41. package/lib/constants/tokenSaftey.test.js +31 -0
  42. package/lib/constants/tokens.d.ts +34 -42
  43. package/lib/constants/tokens.js +190 -147
  44. package/lib/index.d.ts +1 -40
  45. package/lib/index.js +150 -570
  46. package/lib/routing/clientSideSmartOrderRouter.d.ts +5 -0
  47. package/lib/routing/clientSideSmartOrderRouter.js +136 -0
  48. package/lib/routing/gas.d.ts +5 -0
  49. package/lib/routing/gas.js +158 -0
  50. package/lib/routing/types.d.ts +393 -0
  51. package/lib/routing/types.js +424 -0
  52. package/lib/routing/utils.d.ts +28 -0
  53. package/lib/routing/utils.js +319 -0
  54. package/lib/rpc/AppJsonRpcProvider.d.ts +44 -0
  55. package/lib/rpc/AppJsonRpcProvider.js +183 -0
  56. package/lib/rpc/ConfiguredJsonRpcProvider.d.ts +8 -0
  57. package/lib/rpc/ConfiguredJsonRpcProvider.js +35 -0
  58. package/lib/utils/contracts/getContract.d.ts +3 -0
  59. package/lib/utils/contracts/getContract.js +29 -0
  60. package/lib/utils/transformSwapRouteToGetQuoteResult.d.ts +4 -0
  61. package/lib/utils/transformSwapRouteToGetQuoteResult.js +116 -0
  62. package/lib/utils/uniswapData.d.ts +21 -0
  63. package/lib/utils/uniswapData.js +217 -0
  64. package/package.json +12 -8
  65. package/lib/constants/addresses.d.ts +0 -9
  66. package/lib/constants/addresses.js +0 -41
  67. package/lib/constants/eip1193.d.ts +0 -8
  68. package/lib/constants/eip1193.js +0 -14
  69. package/lib/constants/index.d.ts +0 -9
  70. package/lib/constants/index.js +0 -26
  71. package/lib/constants/jsonRpcEndpoints.d.ts +0 -12
  72. package/lib/constants/jsonRpcEndpoints.js +0 -101
  73. package/lib/constants/utils/constructSameAddressMap.d.ts +0 -4
  74. package/lib/constants/utils/constructSameAddressMap.js +0 -19
package/lib/index.js CHANGED
@@ -56,119 +56,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
56
56
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
57
  }
58
58
  };
59
+ var __importDefault = (this && this.__importDefault) || function (mod) {
60
+ return (mod && mod.__esModule) ? mod : { "default": mod };
61
+ };
59
62
  Object.defineProperty(exports, "__esModule", { value: true });
60
- exports.getDefaultTransactionTtl = exports.LOOKSRARE_TOKEN = exports.LOOKSRARE_REWARDS_DISTRIBUTOR = exports.ROUTER_REWARDS_DISTRIBUTOR = exports.V2_INIT_CODE_HASH_MAINNET = exports.V3_INIT_CODE_HASH_MAINNET = exports.V3_FACTORY_MAINNET = exports.V2_FACTORY_MAINNET = exports.NFTX_ERC_1155_VAULT_ID = exports.NFTX_ERC_1155_VAULT = exports.NFTX_MILADY_VAULT_ID = exports.NFTX_MILADY_VAULT = exports.NFTX_COVEN_VAULT_ID = exports.NFTX_COVEN_VAULT = exports.CRYPTOPUNKS_MARKET_ADDRESS = exports.ENS_NFT_ADDRESS = exports.CAMEO_ADDRESS = exports.MENTAL_WORLDS_ADDRESS = exports.ALPHABETTIES_ADDRESS = exports.MILADY_ADDRESS = exports.TWERKY_ADDRESS = exports.TOWNSTAR_ADDRESS = exports.DECENTRA_DRAGON_ADDRESS = exports.COVEN_ADDRESS = exports.OPENSEA_CONDUIT_KEY = exports.OPENSEA_CONDUIT = exports.SOURCE_ROUTER = exports.SOURCE_MSG_SENDER = exports.ADDRESS_THIS = exports.MSG_SENDER = exports.ONE_PERCENT_BIPS = exports.ZERO_ADDRESS = exports.ETH_ADDRESS = exports.ALICE_ADDRESS = exports.ALREADY_PAID = exports.CONTRACT_BALANCE = exports.DEADLINE = exports.MAX_UINT160 = exports.MAX_UINT = void 0;
61
63
  var TAG = " | Uniswap | ";
64
+ var axios_1 = __importDefault(require("axios"));
65
+ var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
62
66
  var uuid = require('uuidv4').uuid;
63
67
  var log = require('@pioneer-platform/loggerdog')();
64
- var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
65
- var permit2_sdk_1 = require("@uniswap/permit2-sdk");
66
- var _b = require('@pioneer-platform/pioneer-coins'), createMemo = _b.createMemo, parseMemo = _b.parseMemo;
67
- var _c = require('@uniswap/v2-sdk'), Pair = _c.Pair, WETH = _c.WETH, Route = _c.Route, Trade = _c.Trade, TokenAmount = _c.TokenAmount; // Import necessary components from v2-sdk
68
- var constants_1 = require("./constants");
69
- // import JSBI from 'jsbi'
70
- // import { ethers } from 'ethers'
68
+ var _b = require('ethers'), ethers = _b.ethers, BigNumber = _b.BigNumber;
69
+ var ethers_1 = require("ethers");
71
70
  var sdk_core_1 = require("@uniswap/sdk-core");
72
71
  var v3_sdk_1 = require("@uniswap/v3-sdk");
73
- var universal_router_sdk_1 = require("@uniswap/universal-router-sdk");
74
- var _d = require('ethers'), ethers = _d.ethers, BigNumber = _d.BigNumber;
75
- var PERMIT2_BASE = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
76
- // This file is lazy-loaded, so the import of smart-order-router is intentional.
77
- // eslint-disable-next-line @typescript-eslint/no-restricted-imports
78
- var smart_order_router_1 = require("@uniswap/smart-order-router");
79
- //TODO - add all networks
80
72
  var networkSupport = [
81
73
  ChainToNetworkId["ETH"],
82
74
  ChainToNetworkId["BASE"],
83
75
  ];
84
- var router_sdk_1 = require("@uniswap/router-sdk");
85
- var protocols = [router_sdk_1.Protocol.V2, router_sdk_1.Protocol.V3, router_sdk_1.Protocol.MIXED];
86
- module.exports = {
87
- init: function (settings) {
88
- return true;
89
- },
90
- networkSupport: function () {
91
- return networkSupport;
92
- },
93
- getQuote: function (quote) {
94
- return get_quote(quote);
95
- },
96
- // //buildSwapTx
97
- buildSwapTx: function (quote, permitSig) {
98
- return buildSwapTx(quote);
99
- },
100
- // buildApprovalTx: function (approval:any) {
101
- // return build_approval_tx(approval);
102
- // }
103
- };
104
- // Router Helpers
105
- exports.MAX_UINT = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
106
- exports.MAX_UINT160 = '0xffffffffffffffffffffffffffffffffffffffff';
107
- exports.DEADLINE = 2000000000;
108
- exports.CONTRACT_BALANCE = '0x8000000000000000000000000000000000000000000000000000000000000000';
109
- exports.ALREADY_PAID = 0;
110
- exports.ALICE_ADDRESS = '0x28c6c06298d514db089934071355e5743bf21d60';
111
- exports.ETH_ADDRESS = ethers.constants.AddressZero;
112
- exports.ZERO_ADDRESS = ethers.constants.AddressZero;
113
- exports.ONE_PERCENT_BIPS = 100;
114
- exports.MSG_SENDER = '0x0000000000000000000000000000000000000001';
115
- exports.ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
116
- exports.SOURCE_MSG_SENDER = true;
117
- exports.SOURCE_ROUTER = false;
118
- // Protocol Data
119
- exports.OPENSEA_CONDUIT = '0x1E0049783F008A0085193E00003D00cd54003c71';
120
- exports.OPENSEA_CONDUIT_KEY = '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000';
121
- // NFT Addresses
122
- exports.COVEN_ADDRESS = '0x5180db8f5c931aae63c74266b211f580155ecac8';
123
- exports.DECENTRA_DRAGON_ADDRESS = '0xAA107cCFe230a29C345Fd97bc6eb9Bd2fccD0750';
124
- exports.TOWNSTAR_ADDRESS = '0xc36cF0cFcb5d905B8B513860dB0CFE63F6Cf9F5c';
125
- exports.TWERKY_ADDRESS = '0xf4680c917a873e2dd6ead72f9f433e74eb9c623c';
126
- exports.MILADY_ADDRESS = '0x5af0d9827e0c53e4799bb226655a1de152a425a5';
127
- exports.ALPHABETTIES_ADDRESS = '0x6d05064fe99e40f1c3464e7310a23ffaded56e20';
128
- exports.MENTAL_WORLDS_ADDRESS = '0xEf96021Af16BD04918b0d87cE045d7984ad6c38c';
129
- exports.CAMEO_ADDRESS = '0x93317E87a3a47821803CAADC54Ae418Af80603DA';
130
- exports.ENS_NFT_ADDRESS = '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85';
131
- exports.CRYPTOPUNKS_MARKET_ADDRESS = '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB';
132
- exports.NFTX_COVEN_VAULT = '0xd89b16331f39ab3878daf395052851d3ac8cf3cd';
133
- exports.NFTX_COVEN_VAULT_ID = '333';
134
- exports.NFTX_MILADY_VAULT = '0x227c7df69d3ed1ae7574a1a7685fded90292eb48';
135
- exports.NFTX_MILADY_VAULT_ID = '392';
136
- exports.NFTX_ERC_1155_VAULT = '0x78e09c5ec42d505742a52fd10078a57ea186002a';
137
- exports.NFTX_ERC_1155_VAULT_ID = '61';
138
- // Constructor Params
139
- exports.V2_FACTORY_MAINNET = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
140
- exports.V3_FACTORY_MAINNET = '0x1F98431c8aD98523631AE4a59f267346ea31F984';
141
- exports.V3_INIT_CODE_HASH_MAINNET = '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54';
142
- exports.V2_INIT_CODE_HASH_MAINNET = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f';
143
- exports.ROUTER_REWARDS_DISTRIBUTOR = '0x0000000000000000000000000000000000000000';
144
- exports.LOOKSRARE_REWARDS_DISTRIBUTOR = '0x0554f068365eD43dcC98dcd7Fd7A8208a5638C72';
145
- exports.LOOKSRARE_TOKEN = '0xf4d2888d29D722226FafA5d9B24F9164c092421E';
146
- var BASE_UNIVERSIAL_ROUTER = {
147
- "UniversalRouterV1_2": "0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4",
148
- "UniversalRouterV1_2_V2Support": "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
149
- "UnsupportedProtocol": "0x9E18Efb3BE848940b0C92D300504Fb08C287FE85"
150
- };
151
- var ETH_UNIVERSIAL_ROUTER = {
152
- "UniversalRouter": "0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B",
153
- "UniversalRouterV1_2": "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
154
- "UnsupportedProtocol": "0x76D631990d505E4e5b432EEDB852A60897824D68"
155
- };
156
- var BASE_CONTRACTS = {
157
- Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
158
- UniversalRouter: "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
159
- V3CoreFactory: "0x33128a8fC17869897dcE68Ed026d694621f6FDfD",
160
- Multicall: "0x091e99cb1C49331a94dD62755D168E941AbD0693",
161
- ProxyAdmin: "0x3334d83e224aF5ef9C2E7DDA7c7C98Efd9621fA9",
162
- TickLens: "0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d",
163
- NftDescriptor: "0xF9d1077fd35670d4ACbD27af82652a8d84577d9F",
164
- NonfungibleTokenPositionDescriptor: "0x4f225937EDc33EFD6109c4ceF7b560B2D6401009",
165
- DescriptorProxy: "0x4615C383F85D0a2BbED973d83ccecf5CB7121463",
166
- NonfungibleTokenPositionManager: "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1",
167
- V3Migrator: "0x23cF10b1ee3AdfCA73B0eF17C07F7577e7ACd2d7",
168
- V3Staker: "0x42bE4D6527829FeFA1493e1fb9F3676d2425C3C1",
169
- QuoterV2: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",
170
- SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481"
171
- };
172
76
  var EIP155_MAINNET_CHAINS = {
173
77
  'eip155:1': {
174
78
  chainId: 1,
@@ -176,52 +80,18 @@ var EIP155_MAINNET_CHAINS = {
176
80
  name: 'Ethereum',
177
81
  logo: '/chain-logos/eip155-1.png',
178
82
  rgb: '99, 125, 234',
179
- permit2: permit2_sdk_1.PERMIT2_ADDRESS,
180
- universalRouter: universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS,
83
+ universalRouter: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
181
84
  rpc: 'https://eth.llamarpc.com',
182
85
  defaultGasLimit: 250000,
183
86
  namespace: 'eip155'
184
87
  },
185
- // 'eip155:43114': {
186
- // chainId: 43114,
187
- // name: 'Avalanche C-Chain',
188
- // logo: '/chain-logos/eip155-43113.png',
189
- // rgb: '232, 65, 66',
190
- // rpc: 'https://api.avax.network/ext/bc/C/rpc',
191
- // namespace: 'eip155'
192
- // },
193
- // 'eip155:137': {
194
- // chainId: 137,
195
- // name: 'Polygon',
196
- // logo: '/chain-logos/eip155-137.png',
197
- // rgb: '130, 71, 229',
198
- // rpc: 'https://polygon-rpc.com/',
199
- // namespace: 'eip155'
200
- // },
201
- // 'eip155:10': {
202
- // chainId: 10,
203
- // name: 'Optimism',
204
- // logo: '/chain-logos/eip155-10.png',
205
- // rgb: '235, 0, 25',
206
- // rpc: 'https://mainnet.optimism.io',
207
- // namespace: 'eip155'
208
- // },
209
- // 'eip155:324': {
210
- // chainId: 324,
211
- // name: 'zkSync Era',
212
- // logo: '/chain-logos/eip155-324.svg',
213
- // rgb: '242, 242, 242',
214
- // rpc: 'https://mainnet.era.zksync.io/',
215
- // namespace: 'eip155'
216
- // },
217
88
  'eip155:8453': {
218
89
  chainId: 8453,
219
90
  WETH: '0x4200000000000000000000000000000000000006',
220
91
  name: 'Base',
221
92
  logo: '/chain-logos/base.png',
222
93
  rgb: '242, 242, 242',
223
- permit2: BASE_CONTRACTS.Permit2,
224
- universalRouter: BASE_CONTRACTS.UniversalRouter,
94
+ universalRouter: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
225
95
  rpc: 'https://mainnet.base.org',
226
96
  defaultGasLimit: 135120,
227
97
  namespace: 'eip155'
@@ -229,327 +99,33 @@ var EIP155_MAINNET_CHAINS = {
229
99
  };
230
100
  var ERC20_ABI = [
231
101
  "function allowance(address owner, address spender) view returns (uint256)",
232
- "function decimals() view returns (uint8)",
233
102
  "function balanceOf(address owner) view returns (uint256)",
234
103
  "function approve(address spender, uint256 amount) returns (bool)",
235
- "function transfer(address to, uint256 amount) returns (bool)"
104
+ "function transfer(address to, uint256 amount) returns (bool)",
105
+ "function symbol() view returns (string)",
106
+ "function decimals() view returns (uint8)"
236
107
  ];
237
- var routersCache = new WeakMap();
238
- function getRouter(chainId, provider) {
239
- var routers = routersCache.get(provider) || {};
240
- var cached = routers[chainId];
241
- if (cached)
242
- return cached;
243
- // V2 is unsupported for chains other than mainnet.
244
- // TODO(zzmp): Upstream to @uniswap/smart-order-router, exporting an enum of supported v2 chains for clarity.
245
- var v2SubgraphProvider;
246
- if (chainId !== sdk_core_1.ChainId.MAINNET) {
247
- v2SubgraphProvider = new smart_order_router_1.StaticV2SubgraphProvider(chainId);
248
- }
249
- // V3 computes on-chain, so the quoter must have gas limits appropriate to the provider.
250
- // Most defaults are fine, but polygon needs a lower gas limit.
251
- // TODO(zzmp): Upstream to @uniswap/smart-order-router, possibly making this easier to modify
252
- // (eg allowing configuration without an instance to avoid duplicating multicall2Provider).
253
- var onChainQuoteProvider;
254
- var multicall2Provider;
255
- if ([sdk_core_1.ChainId.POLYGON, sdk_core_1.ChainId.POLYGON_MUMBAI].includes(chainId)) {
256
- multicall2Provider = new smart_order_router_1.UniswapMulticallProvider(chainId, provider, 375000);
257
- // See https://github.com/Uniswap/smart-order-router/blob/98c58bdee9981fd9ffac9e7d7a97b18302d5f77a/src/routers/alpha-router/alpha-router.ts#L464-L487
258
- onChainQuoteProvider = new smart_order_router_1.OnChainQuoteProvider(chainId, provider, multicall2Provider, {
259
- retries: 2,
260
- minTimeout: 100,
261
- maxTimeout: 1000,
262
- }, {
263
- multicallChunk: 10,
264
- gasLimitPerCall: 5000000,
265
- quoteMinSuccessRate: 0.1,
266
- }, {
267
- gasLimitOverride: 5000000,
268
- multicallChunk: 5,
269
- }, {
270
- gasLimitOverride: 6250000,
271
- multicallChunk: 4,
272
- });
108
+ module.exports = {
109
+ init: function (settings) {
110
+ return true;
111
+ },
112
+ networkSupport: function () {
113
+ return networkSupport;
114
+ },
115
+ getQuote: function (quote) {
116
+ return get_quote(quote);
273
117
  }
274
- var router = new smart_order_router_1.AlphaRouter({ chainId: chainId, provider: provider, v2SubgraphProvider: v2SubgraphProvider, multicall2Provider: multicall2Provider, onChainQuoteProvider: onChainQuoteProvider });
275
- routers[chainId] = router;
276
- routersCache.set(provider, routers);
277
- return router;
278
- }
279
- var SwapRouterNativeAssets;
280
- (function (SwapRouterNativeAssets) {
281
- SwapRouterNativeAssets["MATIC"] = "MATIC";
282
- SwapRouterNativeAssets["ETH"] = "ETH";
283
- })(SwapRouterNativeAssets || (SwapRouterNativeAssets = {}));
284
- // interface SwapOptions {
285
- // slippageTolerance: Percent
286
- // deadline?: BigNumber
287
- // permit?: PermitSignature
288
- // feeOptions?: FeeOptions
289
- // }
290
- var getRoute = function (_a) {
291
- var sellToken = _a.sellToken, buyToken = _a.buyToken, chainId = _a.chainId, amountIn = _a.amountIn, provider = _a.provider;
292
- return __awaiter(this, void 0, void 0, function () {
293
- var tag, router, amount, route, e_1;
294
- return __generator(this, function (_b) {
295
- switch (_b.label) {
296
- case 0:
297
- tag = " | getMinAmountOut | ";
298
- _b.label = 1;
299
- case 1:
300
- _b.trys.push([1, 3, , 4]);
301
- log.info(tag, "sellToken: ", sellToken);
302
- log.info(tag, "buyToken: ", buyToken);
303
- router = getRouter(chainId, provider);
304
- amount = sdk_core_1.CurrencyAmount.fromRawAmount(buyToken, BigNumber.from(amountIn !== null && amountIn !== void 0 ? amountIn : '1'));
305
- // const amount = CurrencyAmount.fromRawAmount(buyToken, JSBI.BigInt(amountIn ?? '1')) // a null amountRaw should initialize the route
306
- log.info(tag, "amount: ", amount);
307
- return [4 /*yield*/, router.route(amount, sellToken, sdk_core_1.TradeType.EXACT_INPUT, /*swapConfig=*/ undefined, { protocols: protocols })];
308
- case 2:
309
- route = _b.sent();
310
- log.info(tag, "route: ", route);
311
- return [2 /*return*/, route];
312
- case 3:
313
- e_1 = _b.sent();
314
- console.error(tag, "Error in getMinAmountOut: ", e_1);
315
- throw e_1;
316
- case 4: return [2 /*return*/];
317
- }
318
- });
319
- });
320
- };
321
- var isZero = function isZero(hexNumberString) {
322
- return hexNumberString === '0' || /^0x0*$/.test(hexNumberString);
323
- };
324
- /** Returns the default transaction TTL for the chain, in minutes. */
325
- function getDefaultTransactionTtl(chainId) {
326
- if (chainId && constants_1.L2_CHAIN_IDS.includes(chainId))
327
- return constants_1.L2_DEADLINE_FROM_NOW / 60;
328
- return constants_1.DEFAULT_DEADLINE_FROM_NOW / 60;
329
- }
330
- exports.getDefaultTransactionTtl = getDefaultTransactionTtl;
331
- var getDeadline = function (provider) { return __awaiter(void 0, void 0, void 0, function () {
332
- var block, deadline, error_1;
333
- return __generator(this, function (_a) {
334
- switch (_a.label) {
335
- case 0:
336
- _a.trys.push([0, 2, , 3]);
337
- return [4 /*yield*/, provider.getBlock('latest')];
338
- case 1:
339
- block = _a.sent();
340
- deadline = block.timestamp + 60 * 60;
341
- console.log("Current Block Timestamp: ".concat(block.timestamp));
342
- console.log("Deadline (60 minutes later): ".concat(deadline));
343
- return [2 /*return*/, deadline];
344
- case 2:
345
- error_1 = _a.sent();
346
- console.error('Error fetching block or calculating deadline:', error_1);
347
- return [2 /*return*/, null];
348
- case 3: return [2 /*return*/];
349
- }
350
- });
351
- }); };
352
- var buildSwapTx = function (_a) {
353
- var trade = _a.trade, permit = _a.permit, from = _a.from, chainId = _a.chainId, provider = _a.provider;
354
- return __awaiter(this, void 0, void 0, function () {
355
- var tag, BIPS_BASE, slippageTolerance, deadline, responseRouter, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
356
- return __generator(this, function (_b) {
357
- switch (_b.label) {
358
- case 0:
359
- tag = TAG + " | buildTx | ";
360
- _b.label = 1;
361
- case 1:
362
- _b.trys.push([1, 9, , 10]);
363
- BIPS_BASE = BigNumber.from(10000);
364
- slippageTolerance = new sdk_core_1.Percent(BigNumber.from(200), BIPS_BASE);
365
- log.info(tag, "slippageTolerance: ", slippageTolerance);
366
- //buildTx
367
- log.info(tag, "trade: ", trade.tradeType);
368
- log.info(tag, "swaps: ", trade.swaps[0]);
369
- log.info(tag, "routes: ", trade.routes[0]);
370
- return [4 /*yield*/, getDeadline(provider)];
371
- case 2:
372
- deadline = _b.sent();
373
- log.info(tag, "deadline: ", deadline);
374
- permit.signature = "0x3e1d72164c5656b61bb438fd0527cf317451d334e54468ab58dfd54eb12cae6f3aafdff7d8f7952e6935a463a7920c1a16298694a976496d40918d718260cc781b";
375
- responseRouter = universal_router_sdk_1.SwapRouter.swapERC20CallParameters(trade, {
376
- recipient: from,
377
- slippageTolerance: slippageTolerance,
378
- deadlineOrPreviousBlockhash: deadline,
379
- inputTokenPermit: permit,
380
- // fee: options.feeOptions,
381
- });
382
- log.info(tag, "responseRouter: ", responseRouter);
383
- data = responseRouter.calldata;
384
- value = responseRouter.value;
385
- return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
386
- case 3:
387
- nonce = _b.sent();
388
- gas = "0x".concat(BigInt("135120").toString(16));
389
- _b.label = 4;
390
- case 4:
391
- _b.trys.push([4, 6, , 7]);
392
- return [4 /*yield*/, provider.estimateGas({
393
- from: from,
394
- to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, // Uniswap Router address
395
- data: data,
396
- value: ethers.utils.parseEther("0"), // Value for token swaps
397
- })];
398
- case 5:
399
- estimatedGas = _b.sent();
400
- console.log("estimatedGas: ", estimatedGas);
401
- gas = "0x".concat(estimatedGas.toString(16));
402
- return [3 /*break*/, 7];
403
- case 6:
404
- e_2 = _b.sent();
405
- console.error("Error in estimateGas: ", e_2);
406
- //@TODO get custom gas limit defaults per chain
407
- gas = "0x".concat(BigInt("335120").toString(16));
408
- return [3 /*break*/, 7];
409
- case 7: return [4 /*yield*/, provider.getGasPrice()];
410
- case 8:
411
- gasPrice = _b.sent();
412
- adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
413
- tx = __assign(__assign({ from: from, to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, chainId: chainId, data: data }, (value && !isZero(value) ? { value: (0, v3_sdk_1.toHex)(value) } : {})), { gas: gas, gasPrice: (0, v3_sdk_1.toHex)(adjustedGasPrice), nonce: (0, v3_sdk_1.toHex)(nonce) });
414
- return [2 /*return*/, tx];
415
- case 9:
416
- e_3 = _b.sent();
417
- console.error(e_3);
418
- return [3 /*break*/, 10];
419
- case 10: return [2 /*return*/];
420
- }
421
- });
422
- });
423
- };
424
- var buildApprovalTx = function (_a) {
425
- var from = _a.from, contract = _a.contract, address = _a.address, chainId = _a.chainId, provider = _a.provider;
426
- return __awaiter(this, void 0, void 0, function () {
427
- var tag, data, value, nonce, gas, estimatedGas, e_4, gasPrice, adjustedGasPrice, tx, e_5;
428
- return __generator(this, function (_b) {
429
- switch (_b.label) {
430
- case 0:
431
- tag = TAG + " | buildTx | ";
432
- _b.label = 1;
433
- case 1:
434
- _b.trys.push([1, 8, , 9]);
435
- //
436
- // let result = await contract.approve(contract.address, address, ethers.constants.MaxUint256)
437
- console.log(tag, "from: ", from);
438
- data = contract.interface.encodeFunctionData("approve", [address, ethers.constants.MaxUint256]);
439
- console.log(tag, "data: ", data);
440
- value = '0x';
441
- return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
442
- case 2:
443
- nonce = _b.sent();
444
- gas = "0x".concat(BigInt("135120").toString(16));
445
- _b.label = 3;
446
- case 3:
447
- _b.trys.push([3, 5, , 6]);
448
- return [4 /*yield*/, provider.estimateGas({
449
- from: from,
450
- to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, // Uniswap Router address
451
- data: data,
452
- value: ethers.utils.parseEther("0"), // Value for token swaps
453
- })];
454
- case 4:
455
- estimatedGas = _b.sent();
456
- console.log("estimatedGas: ", estimatedGas);
457
- gas = "0x".concat(estimatedGas.toString(16));
458
- return [3 /*break*/, 6];
459
- case 5:
460
- e_4 = _b.sent();
461
- console.error("Error in estimateGas: ", e_4);
462
- //@TODO get custom gas limit defaults per chain
463
- gas = "0x".concat(BigInt("335120").toString(16));
464
- return [3 /*break*/, 6];
465
- case 6: return [4 /*yield*/, provider.getGasPrice()];
466
- case 7:
467
- gasPrice = _b.sent();
468
- adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
469
- tx = __assign(__assign({ from: from, to: contract.address, chainId: chainId, data: data }, (value && !isZero(value) ? { value: (0, v3_sdk_1.toHex)(value) } : {})), { gas: gas, gasPrice: (0, v3_sdk_1.toHex)(adjustedGasPrice), nonce: (0, v3_sdk_1.toHex)(nonce) });
470
- return [2 /*return*/, tx];
471
- case 8:
472
- e_5 = _b.sent();
473
- console.error(e_5);
474
- return [3 /*break*/, 9];
475
- case 9: return [2 /*return*/];
476
- }
477
- });
478
- });
479
- };
480
- function toDeadline(expiration) {
481
- return Math.floor((Date.now() + expiration) / 1000);
482
- }
483
- var build_permit_tx = function (_a) {
484
- var from = _a.from, token = _a.token, amount = _a.amount, chainId = _a.chainId;
485
- return __awaiter(this, void 0, void 0, function () {
486
- var PERMIT_EXPIRATION, PERMIT_SIG_EXPIRATION, providerUrl, provider, nonce, permit, fullResponse, domain, types, values, typedData, tx, e_6;
487
- return __generator(this, function (_b) {
488
- switch (_b.label) {
489
- case 0:
490
- _b.trys.push([0, 2, , 3]);
491
- PERMIT_EXPIRATION = 2592000000;
492
- PERMIT_SIG_EXPIRATION = 1800000;
493
- providerUrl = EIP155_MAINNET_CHAINS['eip155:' + chainId].rpc;
494
- if (!providerUrl)
495
- throw new Error("missing providerUrl");
496
- log.info("providerUrl: ", providerUrl);
497
- provider = new ethers.providers.JsonRpcProvider(providerUrl);
498
- return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
499
- case 1:
500
- nonce = _b.sent();
501
- permit = {
502
- details: {
503
- token: token,
504
- amount: amount,
505
- expiration: toDeadline(PERMIT_EXPIRATION),
506
- nonce: nonce,
507
- },
508
- spender: from,
509
- sigDeadline: toDeadline(PERMIT_SIG_EXPIRATION),
510
- };
511
- fullResponse = permit2_sdk_1.AllowanceTransfer.getPermitData(permit, permit2_sdk_1.PERMIT2_ADDRESS, chainId);
512
- log.info("fullResponse: ", fullResponse);
513
- domain = fullResponse.domain, types = fullResponse.types, values = fullResponse.values;
514
- // Ensure 'EIP712Domain' is included in the types definitions
515
- // If it's not already present or not recognized for some reason, define it explicitly
516
- if (!types['EIP712Domain']) {
517
- types['EIP712Domain'] = [
518
- { name: "name", type: "string" },
519
- { name: "chainId", type: "uint256" },
520
- { name: "verifyingContract", type: "address" },
521
- ];
522
- }
523
- typedData = {
524
- domain: domain,
525
- types: types,
526
- message: values, // Use 'values' as the 'message' for EIP712 signing
527
- primaryType: "PermitSingle" // Assuming 'PermitSingle' as the primaryType based on your types definition
528
- };
529
- tx = {
530
- type: 'signTypedData',
531
- txParams: typedData // Ensuring txParams contains the correctly formatted EIP-712 data
532
- };
533
- return [2 /*return*/, tx];
534
- case 2:
535
- e_6 = _b.sent();
536
- console.error(e_6);
537
- return [3 /*break*/, 3];
538
- case 3: return [2 /*return*/];
539
- }
540
- });
541
- });
542
118
  };
543
119
  var get_quote = function (quote) {
544
120
  return __awaiter(this, void 0, void 0, function () {
545
- var tag, output, slippageTolerance, recipient, inputChain, outputChain, providerUrl, chainIdInt, provider, sellTokenContract, buyTokenContract, buyTokenAddress_1, balance, sellTokenAddress_1, permit2, router, planner, sellAmountBigNumber, path, permit2Address, currentAllowance, allowanceTx, formattedAllowanceTx, _a, sellTokenAddress, buyTokenAddress, sellTokenDecimals, _b, buyTokenDecimals, _c, amountInBigNumber, sellToken, buyToken, route, trade, amountOut, PERMIT_EXPIRATION, PERMIT_SIG_EXPIRATION, nonce, permit, tx, e_7;
546
- return __generator(this, function (_d) {
547
- switch (_d.label) {
121
+ var tag, output, from, recipient, inputChain, outputChain, providerUrl, chainIdInt, chainId, provider, sellTokenContract, buyTokenContract, BUY_TOKEN, SELL_TOKEN, BUY_TOKEN_ADDRESS, SELL_TOKEN_ADDRESS, buyTokenAddress, symbolBuy, decimalsBuy, balance, sellTokenAddress, symbolSell, decimalsSell, FEE_AMOUNT, inputPRO, args, Protocol, QuoteIntent, CLIENT_PARAMS, tokenIn, tokenInChainId, tokenOut, tokenOutChainId, amount, tradeType, sendPortionEnabled, requestBody, response, uraQuoteResponse, calldata, value, nonce, gas, gasPrice, adjustedGasPrice, isZero, tx, e_1;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
548
124
  case 0:
549
125
  tag = TAG + " | get_quote | ";
550
- _d.label = 1;
126
+ _a.label = 1;
551
127
  case 1:
552
- _d.trys.push([1, 16, , 17]);
128
+ _a.trys.push([1, 14, , 15]);
553
129
  output = {};
554
130
  if (!quote.sellAsset)
555
131
  throw new Error("missing sellAsset");
@@ -563,8 +139,9 @@ var get_quote = function (quote) {
563
139
  throw new Error("missing recipientAddress");
564
140
  if (!quote.slippage)
565
141
  throw new Error("missing slippage");
142
+ // if(!quote.permit2) throw new Error("missing permit2, required for uniswap")
566
143
  output.txs = [];
567
- slippageTolerance = quote.slippage;
144
+ from = quote.senderAddress;
568
145
  recipient = quote.recipientAddress;
569
146
  inputChain = caipToNetworkId(quote.sellAsset);
570
147
  outputChain = caipToNetworkId(quote.buyAsset);
@@ -577,135 +154,138 @@ var get_quote = function (quote) {
577
154
  log.info("providerUrl: ", providerUrl);
578
155
  chainIdInt = parseInt(inputChain.replace('eip155:', ''));
579
156
  log.info(tag, "chainIdInt: ", chainIdInt);
157
+ chainId = chainIdInt;
580
158
  provider = new ethers.providers.JsonRpcProvider(providerUrl);
581
159
  sellTokenContract = void 0, buyTokenContract = void 0;
582
- if (!(quote.buyAsset.indexOf('erc20') > -1)) return [3 /*break*/, 3];
583
- buyTokenAddress_1 = quote.buyAsset.split(":")[2].toLowerCase();
584
- log.info("buyTokenAddress: ", buyTokenAddress_1);
585
- buyTokenContract = new ethers.Contract(buyTokenAddress_1.toLowerCase(), ERC20_ABI, provider);
586
- return [4 /*yield*/, buyTokenContract.balanceOf(quote.senderAddress)];
160
+ BUY_TOKEN = void 0, SELL_TOKEN = void 0;
161
+ BUY_TOKEN_ADDRESS = void 0, SELL_TOKEN_ADDRESS = void 0;
162
+ if (!(quote.buyAsset.indexOf('erc20') > -1)) return [3 /*break*/, 5];
163
+ buyTokenAddress = quote.buyAsset.split(":")[2].toLowerCase();
164
+ BUY_TOKEN_ADDRESS = buyTokenAddress;
165
+ log.info("buyTokenAddress: ", buyTokenAddress);
166
+ buyTokenContract = new ethers.Contract(buyTokenAddress.toLowerCase(), ERC20_ABI, provider);
167
+ return [4 /*yield*/, buyTokenContract.symbol()];
587
168
  case 2:
588
- balance = _d.sent();
589
- log.info("balance: ", balance.toString());
590
- _d.label = 3;
169
+ symbolBuy = _a.sent();
170
+ return [4 /*yield*/, buyTokenContract.decimals()];
591
171
  case 3:
592
- if (quote.sellAsset.indexOf('erc20') > -1) {
593
- sellTokenAddress_1 = quote.sellAsset.split(":")[2].toLowerCase();
594
- log.info("sellTokenAddress: ", sellTokenAddress_1);
595
- sellTokenContract = new ethers.Contract(sellTokenAddress_1, ERC20_ABI, provider);
596
- }
597
- permit2 = permit2_sdk_1.PERMIT2_ADDRESS;
598
- router = universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS;
599
- planner = new universal_router_sdk_1.RoutePlanner();
600
- sellAmountBigNumber = ethers.utils.parseUnits(quote.sellAmount.toString(), 'ether');
601
- path = void 0;
602
- //build path
603
- if (sellTokenContract && !buyTokenContract) {
604
- path = [sellTokenContract.address, EIP155_MAINNET_CHAINS[inputChain].WETH];
605
- }
606
- else if (!sellTokenContract && buyTokenContract) {
607
- path = [EIP155_MAINNET_CHAINS[inputChain].WETH, buyTokenContract.address];
608
- }
609
- else if (sellTokenContract && buyTokenContract) {
610
- path = [sellTokenContract.address, buyTokenContract.address];
611
- }
612
- log.info("path: ", path);
613
- // @ts-ignore
614
- if ((path[0] !== undefined && path[1] !== undefined) && path[0] === path[1]) {
615
- throw new Error("Both tokens are the same");
616
- }
617
- if (!path)
618
- throw new Error("missing path");
619
- if (!sellTokenContract) return [3 /*break*/, 6];
620
- permit2Address = EIP155_MAINNET_CHAINS[inputChain].permit2;
621
- if (!permit2Address)
622
- throw new Error("missing permit2Address for chain: " + inputChain);
623
- console.log("sellTokenContract: ", sellTokenContract);
624
- log.info(tag, "permit2Address: ", permit2Address);
625
- log.info(tag, "quote.senderAddress: ", quote.senderAddress.toLowerCase());
626
- return [4 /*yield*/, sellTokenContract.allowance(quote.senderAddress.toLowerCase(), permit2)];
172
+ decimalsBuy = _a.sent();
173
+ return [4 /*yield*/, buyTokenContract.balanceOf(quote.senderAddress)];
627
174
  case 4:
628
- currentAllowance = _d.sent();
629
- console.log("currentAllowance: ", currentAllowance.toString());
630
- console.log("sellAmountBigNumber: ", sellAmountBigNumber.toString());
631
- if (!currentAllowance.lt(sellAmountBigNumber)) return [3 /*break*/, 6];
632
- return [4 /*yield*/, buildApprovalTx({ provider: provider, contract: sellTokenContract, address: EIP155_MAINNET_CHAINS['eip155:' + chainIdInt].universalRouter, from: quote.senderAddress, chainId: chainIdInt })];
175
+ balance = _a.sent();
176
+ log.info("balance: ", balance.toString());
177
+ BUY_TOKEN = new sdk_core_1.Token(8453, buyTokenAddress, decimalsBuy, symbolBuy, symbolBuy.toLowerCase());
178
+ return [3 /*break*/, 6];
633
179
  case 5:
634
- allowanceTx = _d.sent();
635
- console.log("allowanceTx: ", allowanceTx);
636
- formattedAllowanceTx = {
637
- type: "evm",
638
- description: 'approve router to spend tokens',
639
- chain: inputChain,
640
- txParams: allowanceTx
641
- };
642
- output.txs.push(formattedAllowanceTx);
643
- _d.label = 6;
180
+ BUY_TOKEN = new sdk_core_1.Token(8453, '0x4200000000000000000000000000000000000006', 18, 'WETH');
181
+ BUY_TOKEN_ADDRESS = '0x4200000000000000000000000000000000000006';
182
+ _a.label = 6;
644
183
  case 6:
645
- _a = path.map(function (address) { return ethers.utils.getAddress(address); }), sellTokenAddress = _a[0], buyTokenAddress = _a[1];
646
- console.info("".concat(tag, " sellTokenAddress: ").concat(sellTokenAddress, ", buyTokenAddress: ").concat(buyTokenAddress));
647
- if (!(sellTokenAddress !== ethers.constants.AddressZero)) return [3 /*break*/, 8];
648
- return [4 /*yield*/, new ethers.Contract(sellTokenAddress, ERC20_ABI, provider).decimals()];
184
+ if (!(quote.sellAsset.indexOf('erc20') > -1)) return [3 /*break*/, 9];
185
+ sellTokenAddress = quote.sellAsset.split(":")[2].toLowerCase();
186
+ SELL_TOKEN_ADDRESS = sellTokenAddress;
187
+ log.info("sellTokenAddress: ", sellTokenAddress);
188
+ sellTokenContract = new ethers.Contract(sellTokenAddress, ERC20_ABI, provider);
189
+ return [4 /*yield*/, sellTokenContract.symbol()];
649
190
  case 7:
650
- _b = _d.sent();
651
- return [3 /*break*/, 9];
191
+ symbolSell = _a.sent();
192
+ return [4 /*yield*/, sellTokenContract.decimals()];
652
193
  case 8:
653
- _b = 18;
654
- _d.label = 9;
194
+ decimalsSell = _a.sent();
195
+ SELL_TOKEN = new sdk_core_1.Token(8453, sellTokenAddress, decimalsSell, symbolSell, symbolSell.toLowerCase());
196
+ return [3 /*break*/, 10];
655
197
  case 9:
656
- sellTokenDecimals = _b;
657
- if (!(buyTokenAddress !== ethers.constants.AddressZero)) return [3 /*break*/, 11];
658
- return [4 /*yield*/, new ethers.Contract(buyTokenAddress, ERC20_ABI, provider).decimals()];
198
+ //WETH
199
+ SELL_TOKEN = new sdk_core_1.Token(8453, '0x4200000000000000000000000000000000000006', 18, 'WETH');
200
+ SELL_TOKEN_ADDRESS = '0x4200000000000000000000000000000000000006';
201
+ _a.label = 10;
659
202
  case 10:
660
- _c = _d.sent();
661
- return [3 /*break*/, 12];
203
+ FEE_AMOUNT = v3_sdk_1.FeeAmount.MEDIUM;
204
+ inputPRO = ethers_1.utils.parseUnits('1000', 18).toString();
205
+ args = {
206
+ tokenInAddress: SELL_TOKEN_ADDRESS,
207
+ tokenInChainId: chainIdInt,
208
+ tokenOutAddress: BUY_TOKEN_ADDRESS,
209
+ tokenOutChainId: chainIdInt,
210
+ amount: "10000000000000000000",
211
+ tradeType: 'EXACT_INPUT',
212
+ sendPortionEnabled: false,
213
+ };
214
+ Protocol = void 0;
215
+ (function (Protocol) {
216
+ Protocol["V2"] = "V2";
217
+ Protocol["V3"] = "V3";
218
+ Protocol["MIXED"] = "MIXED";
219
+ })(Protocol || (Protocol = {}));
220
+ QuoteIntent = void 0;
221
+ (function (QuoteIntent) {
222
+ QuoteIntent["Pricing"] = "pricing";
223
+ QuoteIntent["Quote"] = "quote";
224
+ })(QuoteIntent || (QuoteIntent = {}));
225
+ CLIENT_PARAMS = {
226
+ protocols: [Protocol.V2, Protocol.V3, Protocol.MIXED],
227
+ };
228
+ tokenIn = args.tokenInAddress, tokenInChainId = args.tokenInChainId, tokenOut = args.tokenOutAddress, tokenOutChainId = args.tokenOutChainId, amount = args.amount, tradeType = args.tradeType, sendPortionEnabled = args.sendPortionEnabled;
229
+ requestBody = {
230
+ tokenInChainId: tokenInChainId,
231
+ tokenIn: tokenIn,
232
+ tokenOutChainId: tokenOutChainId,
233
+ tokenOut: tokenOut,
234
+ amount: amount,
235
+ sendPortionEnabled: sendPortionEnabled,
236
+ type: 'EXACT_INPUT',
237
+ intent: QuoteIntent.Quote,
238
+ configs: [
239
+ {
240
+ "protocols": [
241
+ "V2",
242
+ "V3",
243
+ "MIXED"
244
+ ],
245
+ "enableUniversalRouter": true,
246
+ "routingType": "CLASSIC",
247
+ "recipient": from,
248
+ "enableFeeOnTransferFeeFetching": true
249
+ }
250
+ ],
251
+ };
252
+ return [4 /*yield*/, (0, axios_1.default)({
253
+ method: 'POST',
254
+ url: 'https://interface.gateway.uniswap.org/v2/quote',
255
+ data: requestBody,
256
+ headers: {
257
+ 'x-request-source': 'uniswap-web',
258
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
259
+ 'Origin': 'http://localhost:3000',
260
+ 'Referer': 'http://localhost:3000',
261
+ 'Accept': 'application/json, text/plain, */*',
262
+ 'Content-Type': 'application/json'
263
+ }
264
+ })];
662
265
  case 11:
663
- _c = 18;
664
- _d.label = 12;
266
+ response = _a.sent();
267
+ log.info(tag, 'response', response.data);
268
+ uraQuoteResponse = response.data;
269
+ log.info(tag, 'uraQuoteResponse', uraQuoteResponse);
270
+ calldata = uraQuoteResponse.quote.methodParameters.calldata;
271
+ value = uraQuoteResponse.quote.methodParameters.value;
272
+ log.info("calldata: ", calldata);
273
+ log.info("value: ", value);
274
+ return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
665
275
  case 12:
666
- buyTokenDecimals = _c;
667
- log.info("".concat(tag, " sellTokenDecimals: ").concat(sellTokenDecimals, ", buyTokenDecimals: ").concat(buyTokenDecimals));
668
- amountInBigNumber = ethers.utils.parseUnits(quote.sellAmount.toString(), sellTokenDecimals);
669
- sellToken = sellTokenAddress === ethers.constants.AddressZero ?
670
- WETH[sdk_core_1.ChainId.MAINNET] : new sdk_core_1.Token(chainIdInt, sellTokenAddress, sellTokenDecimals);
671
- buyToken = buyTokenAddress === ethers.constants.AddressZero ?
672
- WETH[sdk_core_1.ChainId.MAINNET] : new sdk_core_1.Token(chainIdInt, buyTokenAddress, buyTokenDecimals);
673
- return [4 /*yield*/, getRoute({
674
- sellToken: sellToken,
675
- buyToken: buyToken,
676
- chainId: chainIdInt,
677
- amountIn: amountInBigNumber,
678
- provider: provider
679
- })];
276
+ nonce = _a.sent();
277
+ log.info("nonce: ", nonce);
278
+ gas = "0x".concat(BigInt("935120").toString(16)) // 935120
279
+ ;
280
+ return [4 /*yield*/, provider.getGasPrice()];
680
281
  case 13:
681
- route = _d.sent();
682
- console.log("route: ", route);
683
- if (!route)
684
- throw new Error("missing route, failed to find route");
685
- trade = route.trade;
686
- log.info(tag, "trade: ", trade);
687
- amountOut = trade.swaps[0].outputAmount;
688
- log.info(tag, "amountOut: ", amountOut);
689
- output.amountOut = amountOut.toFixed(18);
690
- PERMIT_EXPIRATION = 2592000000;
691
- PERMIT_SIG_EXPIRATION = 1800000;
692
- return [4 /*yield*/, provider.getTransactionCount(quote.senderAddress, "latest")];
693
- case 14:
694
- nonce = _d.sent();
695
- permit = {
696
- details: {
697
- token: sellToken.address,
698
- amount: "1000000000000000000000000",
699
- expiration: toDeadline(PERMIT_EXPIRATION),
700
- nonce: nonce,
701
- },
702
- spender: quote.senderAddress,
703
- sigDeadline: toDeadline(PERMIT_SIG_EXPIRATION),
282
+ gasPrice = _a.sent();
283
+ log.info("gasPrice: ", gasPrice.toString());
284
+ adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
285
+ isZero = function isZero(hexNumberString) {
286
+ return hexNumberString === '0' || /^0x0*$/.test(hexNumberString);
704
287
  };
705
- return [4 /*yield*/, buildSwapTx({ trade: trade, permit: permit, from: quote.senderAddress, chainId: chainIdInt, provider: provider })];
706
- case 15:
707
- tx = _d.sent();
708
- log.info(tag, "tx: ", tx);
288
+ tx = __assign(__assign({ from: from, to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, chainId: chainId, data: calldata }, (value && !isZero(value) ? { value: (0, v3_sdk_1.toHex)(value) } : {})), { gas: gas, gasPrice: (0, v3_sdk_1.toHex)(adjustedGasPrice), nonce: (0, v3_sdk_1.toHex)(nonce) });
709
289
  output.txs.push({
710
290
  type: "evm",
711
291
  description: 'swap tokens',
@@ -720,11 +300,11 @@ var get_quote = function (quote) {
720
300
  output.type = 'EVM';
721
301
  output.id = uuid();
722
302
  return [2 /*return*/, output];
723
- case 16:
724
- e_7 = _d.sent();
725
- console.error(tag, "e: ", e_7);
726
- throw e_7;
727
- case 17: return [2 /*return*/];
303
+ case 14:
304
+ e_1 = _a.sent();
305
+ console.error(tag, "e: ", e_1);
306
+ throw e_1;
307
+ case 15: return [2 /*return*/];
728
308
  }
729
309
  });
730
310
  });