@funkit/fun-relay 2.1.16-next.2 → 2.2.0-next.4

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/dist/index.mjs CHANGED
@@ -34,6 +34,8 @@ var FUN_SOLANA_CHAIN_ID_NUMBER = 1151111081099710;
34
34
  var FUN_HYPERCORE_CHAIN_ID_NUMBER = 1337;
35
35
  var RELAY_LIGHTER_CHAIN_ID_NUMBER = 3586256;
36
36
  var RELAY_LIGHTER_CHAIN_ID = `${RELAY_LIGHTER_CHAIN_ID_NUMBER}`;
37
+ var RELAY_TRON_CHAIN_ID_NUMBER = 728126428;
38
+ var RELAY_TRON_CHAIN_ID = `${RELAY_TRON_CHAIN_ID_NUMBER}`;
37
39
  var FUNKIT_NATIVE_TOKEN = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
38
40
  var RELAY_NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
39
41
  var RELAY_NATIVE_TOKEN_HYPERCORE = "0x00000000000000000000000000000000";
@@ -167,6 +169,15 @@ function indexBy(items, getKey) {
167
169
  }
168
170
  return indexedItems;
169
171
  }
172
+ function filterNullishHeaders(params) {
173
+ const result = {};
174
+ for (const [key, value] of Object.entries(params)) {
175
+ if (value != null) {
176
+ result[key] = value;
177
+ }
178
+ }
179
+ return result;
180
+ }
170
181
 
171
182
  // src/execution.ts
172
183
  function getTxHash({
@@ -184,7 +195,7 @@ function getTxHash({
184
195
  };
185
196
  logger.info(`${logPrefix}:started`, logProps);
186
197
  const getTxHashFromTxHashes = () => {
187
- const rawTxHashWithUnreliableTyping = txHashes[0].txHash;
198
+ const rawTxHashWithUnreliableTyping = txHashes[0]?.txHash;
188
199
  const txHash = typeof rawTxHashWithUnreliableTyping === "object" ? rawTxHashWithUnreliableTyping.id : rawTxHashWithUnreliableTyping;
189
200
  logger.info(`${logPrefix}:txHashesMode`, {
190
201
  ...logProps,
@@ -319,12 +330,14 @@ async function executeRelayQuote({
319
330
  ) {
320
331
  logger.info(`${logPrefix}:onTransactionConfirmed`, txHashes);
321
332
  isTransactionConfirmed = true;
322
- if (relayQuote.steps[0].requestId) {
333
+ const firstStep = relayQuote.steps[0];
334
+ const firstItem = firstStep?.items[0];
335
+ if (firstStep?.requestId && firstItem) {
323
336
  manuallyRegisterIndex(logger, {
324
- requestId: relayQuote.steps[0].requestId,
325
- chainId: relayQuote.steps[0].items[0].data.chainId,
337
+ requestId: firstStep.requestId,
338
+ chainId: firstItem.data.chainId,
326
339
  tx: jsonStringifyWithBigIntSanitization({
327
- ...relayQuote.steps[0].items[0].data,
340
+ ...firstItem.data,
328
341
  txHash
329
342
  })
330
343
  });
@@ -378,9 +391,11 @@ async function manuallyRegisterIndex(logger, registerRequest) {
378
391
  });
379
392
  }
380
393
  }
381
- async function getRelayExecutionInfo(requestId) {
394
+ async function getRelayExecutionInfo(requestId, apiKey) {
382
395
  const url = `${MAINNET_RELAY_API2}/intents/status/v2?requestId=${requestId}`;
383
- const response = await fetch(url);
396
+ const response = await fetch(url, {
397
+ headers: { "x-api-key": apiKey }
398
+ });
384
399
  if (!response.ok) {
385
400
  throw Error(response.statusText);
386
401
  }
@@ -462,7 +477,8 @@ function parseRelayFees({
462
477
  import { MAINNET_RELAY_API as MAINNET_RELAY_API3 } from "@relayprotocol/relay-sdk";
463
478
  async function getRelayAssetPriceInfo({
464
479
  chainId,
465
- address
480
+ address,
481
+ apiKey
466
482
  }) {
467
483
  const relayChainId = convertFunToRelayChainId(Number(chainId));
468
484
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -470,7 +486,8 @@ async function getRelayAssetPriceInfo({
470
486
  relayChainId
471
487
  );
472
488
  const url = `${MAINNET_RELAY_API3}/currencies/token/price?chainId=${relayChainId}&address=${relayTokenAddress}`;
473
- const response = await fetch(url);
489
+ const headers = filterNullishHeaders({ "x-api-key": apiKey });
490
+ const response = await fetch(url, { headers });
474
491
  if (!response.ok) {
475
492
  throw Error(response.statusText);
476
493
  }
@@ -482,7 +499,8 @@ async function getRelayAssetPriceInfo({
482
499
  import { MAINNET_RELAY_API as MAINNET_RELAY_API4 } from "@relayprotocol/relay-sdk";
483
500
  async function getRelayAssetInfo({
484
501
  chainId,
485
- address
502
+ address,
503
+ apiKey
486
504
  }) {
487
505
  const relayChainId = convertFunToRelayChainId(Number(chainId));
488
506
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -490,13 +508,17 @@ async function getRelayAssetInfo({
490
508
  relayChainId
491
509
  );
492
510
  const url = `${MAINNET_RELAY_API4}/currencies/v2`;
511
+ const headers = filterNullishHeaders({
512
+ "Content-Type": "application/json",
513
+ "x-api-key": apiKey
514
+ });
493
515
  const body = {
494
516
  chainIds: [relayChainId],
495
517
  address: relayTokenAddress
496
518
  };
497
519
  const response = await fetch(url, {
498
520
  method: "POST",
499
- headers: { "Content-Type": "application/json" },
521
+ headers,
500
522
  body: JSON.stringify(body)
501
523
  });
502
524
  if (!response.ok) {
@@ -515,7 +537,8 @@ async function getQuoteEstUsdValue({
515
537
  tokenChainId,
516
538
  tokenAddress,
517
539
  tokenAmountBaseUnit,
518
- logger
540
+ logger,
541
+ apiKey
519
542
  }) {
520
543
  try {
521
544
  const normalizedChainId = convertFunToRelayChainId(
@@ -528,11 +551,13 @@ async function getQuoteEstUsdValue({
528
551
  const [tokenPriceRes, tokenInfoRes] = await Promise.all([
529
552
  getRelayAssetPriceInfo({
530
553
  chainId: normalizedChainId,
531
- address: normalizedTokenAddress
554
+ address: normalizedTokenAddress,
555
+ apiKey
532
556
  }),
533
557
  getRelayAssetInfo({
534
558
  chainId: normalizedChainId,
535
- address: normalizedTokenAddress
559
+ address: normalizedTokenAddress,
560
+ apiKey
536
561
  })
537
562
  ]);
538
563
  const isWUsdeEthereal = normalizedChainId === "5064014" && normalizedTokenAddress.toLowerCase() === "0xB6fC4B1BFF391e5F6b4a3D2C7Bda1FeE3524692D".toLowerCase();
@@ -563,11 +588,9 @@ var RelayQuoteClientError = class extends Error {
563
588
  Object.setPrototypeOf(this, new.target.prototype);
564
589
  }
565
590
  };
566
- var getHeaders = (funRelayConfig, subsidizeFeesSecretKey) => {
567
- const subsidizeFees = !!funRelayConfig.config.options.subsidizeFees;
591
+ var getHeaders = (funRelayConfig, apiKey) => {
568
592
  const headers = {
569
- // only apply subsidizeFeesSecretKey if subsidizeFees is true
570
- ...subsidizeFees && subsidizeFeesSecretKey ? { "x-api-key": subsidizeFeesSecretKey } : {},
593
+ "x-api-key": apiKey,
571
594
  // Remote headers will override passed in headers
572
595
  ...funRelayConfig.headers ? { ...funRelayConfig.headers } : {}
573
596
  };
@@ -589,7 +612,7 @@ async function getRelayQuote({
589
612
  toTokenAddress,
590
613
  tradeType,
591
614
  userAddress,
592
- subsidizeFeesSecretKey
615
+ apiKey
593
616
  } = params;
594
617
  const vmType = walletClient && "vmType" in walletClient ? walletClient.vmType : "evm";
595
618
  try {
@@ -622,7 +645,8 @@ async function getRelayQuote({
622
645
  tokenChainId: queryTokenChainId,
623
646
  tokenAddress: queryTokenAddress,
624
647
  tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),
625
- logger
648
+ logger,
649
+ apiKey
626
650
  });
627
651
  const funRelayConfig = await getFunRelayFees({
628
652
  clientId,
@@ -634,7 +658,7 @@ async function getRelayQuote({
634
658
  toTokenAddress,
635
659
  toChainId
636
660
  });
637
- const headers = getHeaders(funRelayConfig, subsidizeFeesSecretKey);
661
+ const headers = getHeaders(funRelayConfig, apiKey);
638
662
  const appFeeBp = funRelayConfig.b + funRelayConfig.v;
639
663
  logger.info("getRelayQuoteParams", {
640
664
  ...params,
@@ -795,6 +819,12 @@ function getSolanaWallet(walletAddress, connection, signTransaction, payerKey) {
795
819
  );
796
820
  }
797
821
 
822
+ // src/tron.ts
823
+ import { adaptTronWallet } from "@relayprotocol/relay-tron-wallet-adapter";
824
+ function getTronWallet(walletAddress, tronWeb) {
825
+ return adaptTronWallet(walletAddress, tronWeb);
826
+ }
827
+
798
828
  // src/dynamicRoutes/lighter.ts
799
829
  import {
800
830
  concat,
@@ -1644,6 +1674,7 @@ export {
1644
1674
  getRelayExecutionState,
1645
1675
  getRelayQuote,
1646
1676
  getSolanaWallet,
1677
+ getTronWallet,
1647
1678
  initDynamicRouting,
1648
1679
  initializeRelayClient,
1649
1680
  isRelayExecutionTerminalStatus,