@funkit/fun-relay 2.1.16-next.1 → 2.2.0-next.3

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({
@@ -378,9 +389,11 @@ async function manuallyRegisterIndex(logger, registerRequest) {
378
389
  });
379
390
  }
380
391
  }
381
- async function getRelayExecutionInfo(requestId) {
392
+ async function getRelayExecutionInfo(requestId, apiKey) {
382
393
  const url = `${MAINNET_RELAY_API2}/intents/status/v2?requestId=${requestId}`;
383
- const response = await fetch(url);
394
+ const response = await fetch(url, {
395
+ headers: { "x-api-key": apiKey }
396
+ });
384
397
  if (!response.ok) {
385
398
  throw Error(response.statusText);
386
399
  }
@@ -462,7 +475,8 @@ function parseRelayFees({
462
475
  import { MAINNET_RELAY_API as MAINNET_RELAY_API3 } from "@relayprotocol/relay-sdk";
463
476
  async function getRelayAssetPriceInfo({
464
477
  chainId,
465
- address
478
+ address,
479
+ apiKey
466
480
  }) {
467
481
  const relayChainId = convertFunToRelayChainId(Number(chainId));
468
482
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -470,7 +484,8 @@ async function getRelayAssetPriceInfo({
470
484
  relayChainId
471
485
  );
472
486
  const url = `${MAINNET_RELAY_API3}/currencies/token/price?chainId=${relayChainId}&address=${relayTokenAddress}`;
473
- const response = await fetch(url);
487
+ const headers = filterNullishHeaders({ "x-api-key": apiKey });
488
+ const response = await fetch(url, { headers });
474
489
  if (!response.ok) {
475
490
  throw Error(response.statusText);
476
491
  }
@@ -482,7 +497,8 @@ async function getRelayAssetPriceInfo({
482
497
  import { MAINNET_RELAY_API as MAINNET_RELAY_API4 } from "@relayprotocol/relay-sdk";
483
498
  async function getRelayAssetInfo({
484
499
  chainId,
485
- address
500
+ address,
501
+ apiKey
486
502
  }) {
487
503
  const relayChainId = convertFunToRelayChainId(Number(chainId));
488
504
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -490,13 +506,17 @@ async function getRelayAssetInfo({
490
506
  relayChainId
491
507
  );
492
508
  const url = `${MAINNET_RELAY_API4}/currencies/v2`;
509
+ const headers = filterNullishHeaders({
510
+ "Content-Type": "application/json",
511
+ "x-api-key": apiKey
512
+ });
493
513
  const body = {
494
514
  chainIds: [relayChainId],
495
515
  address: relayTokenAddress
496
516
  };
497
517
  const response = await fetch(url, {
498
518
  method: "POST",
499
- headers: { "Content-Type": "application/json" },
519
+ headers,
500
520
  body: JSON.stringify(body)
501
521
  });
502
522
  if (!response.ok) {
@@ -515,7 +535,8 @@ async function getQuoteEstUsdValue({
515
535
  tokenChainId,
516
536
  tokenAddress,
517
537
  tokenAmountBaseUnit,
518
- logger
538
+ logger,
539
+ apiKey
519
540
  }) {
520
541
  try {
521
542
  const normalizedChainId = convertFunToRelayChainId(
@@ -528,11 +549,13 @@ async function getQuoteEstUsdValue({
528
549
  const [tokenPriceRes, tokenInfoRes] = await Promise.all([
529
550
  getRelayAssetPriceInfo({
530
551
  chainId: normalizedChainId,
531
- address: normalizedTokenAddress
552
+ address: normalizedTokenAddress,
553
+ apiKey
532
554
  }),
533
555
  getRelayAssetInfo({
534
556
  chainId: normalizedChainId,
535
- address: normalizedTokenAddress
557
+ address: normalizedTokenAddress,
558
+ apiKey
536
559
  })
537
560
  ]);
538
561
  const isWUsdeEthereal = normalizedChainId === "5064014" && normalizedTokenAddress.toLowerCase() === "0xB6fC4B1BFF391e5F6b4a3D2C7Bda1FeE3524692D".toLowerCase();
@@ -563,11 +586,9 @@ var RelayQuoteClientError = class extends Error {
563
586
  Object.setPrototypeOf(this, new.target.prototype);
564
587
  }
565
588
  };
566
- var getHeaders = (funRelayConfig, subsidizeFeesSecretKey) => {
567
- const subsidizeFees = !!funRelayConfig.config.options.subsidizeFees;
589
+ var getHeaders = (funRelayConfig, apiKey) => {
568
590
  const headers = {
569
- // only apply subsidizeFeesSecretKey if subsidizeFees is true
570
- ...subsidizeFees && subsidizeFeesSecretKey ? { "x-api-key": subsidizeFeesSecretKey } : {},
591
+ "x-api-key": apiKey,
571
592
  // Remote headers will override passed in headers
572
593
  ...funRelayConfig.headers ? { ...funRelayConfig.headers } : {}
573
594
  };
@@ -589,7 +610,7 @@ async function getRelayQuote({
589
610
  toTokenAddress,
590
611
  tradeType,
591
612
  userAddress,
592
- subsidizeFeesSecretKey
613
+ apiKey
593
614
  } = params;
594
615
  const vmType = walletClient && "vmType" in walletClient ? walletClient.vmType : "evm";
595
616
  try {
@@ -622,7 +643,8 @@ async function getRelayQuote({
622
643
  tokenChainId: queryTokenChainId,
623
644
  tokenAddress: queryTokenAddress,
624
645
  tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),
625
- logger
646
+ logger,
647
+ apiKey
626
648
  });
627
649
  const funRelayConfig = await getFunRelayFees({
628
650
  clientId,
@@ -634,7 +656,7 @@ async function getRelayQuote({
634
656
  toTokenAddress,
635
657
  toChainId
636
658
  });
637
- const headers = getHeaders(funRelayConfig, subsidizeFeesSecretKey);
659
+ const headers = getHeaders(funRelayConfig, apiKey);
638
660
  const appFeeBp = funRelayConfig.b + funRelayConfig.v;
639
661
  logger.info("getRelayQuoteParams", {
640
662
  ...params,
@@ -795,6 +817,12 @@ function getSolanaWallet(walletAddress, connection, signTransaction, payerKey) {
795
817
  );
796
818
  }
797
819
 
820
+ // src/tron.ts
821
+ import { adaptTronWallet } from "@relayprotocol/relay-tron-wallet-adapter";
822
+ function getTronWallet(walletAddress, tronWeb) {
823
+ return adaptTronWallet(walletAddress, tronWeb);
824
+ }
825
+
798
826
  // src/dynamicRoutes/lighter.ts
799
827
  import {
800
828
  concat,
@@ -1593,7 +1621,7 @@ var LIGHTER_DYNAMIC_ROUTES = [
1593
1621
  targetChain: RELAY_LIGHTER_CHAIN_ID2.toString(),
1594
1622
  targetAsset: RELAY_LIGHTER_USDC_PERPS_ADDRESS,
1595
1623
  targetAssetTicker: USDC_PERPS_SYMBOL,
1596
- iconSrc: ASSET_LOGO_SRCS.ETH,
1624
+ iconSrc: ASSET_LOGO_SRCS.USDC,
1597
1625
  getCustomRecipient: ({ l2Address }) => {
1598
1626
  return l2Address;
1599
1627
  }
@@ -1644,6 +1672,7 @@ export {
1644
1672
  getRelayExecutionState,
1645
1673
  getRelayQuote,
1646
1674
  getSolanaWallet,
1675
+ getTronWallet,
1647
1676
  initDynamicRouting,
1648
1677
  initializeRelayClient,
1649
1678
  isRelayExecutionTerminalStatus,