@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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @funkit/fun-relay
2
2
 
3
+ ## 2.2.0-next.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 7312429: adopt checkedIndexedAccess for safety
8
+
9
+ ## 2.2.0-next.3
10
+
11
+ ### Minor Changes
12
+
13
+ - c289ca6: feat(fun-relay): require api key for relay to prevent rate limiting
14
+ feat(connect): pass pseudo api key to fun-relay
15
+ - aa767b0: feat: add tron adapter
16
+
17
+ ### Patch Changes
18
+
19
+ - fd5fe29: fix(fun-relay): add protocolVersion to tests
20
+
3
21
  ## 2.1.16-next.2
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { getRelayAssetPriceInfo } from './src/price';
7
7
  export { getRelayAssetInfo } from './src/currency';
8
8
  export { type GetRelayQuoteParams, type RelayQuote, getRelayQuote, getReferrer, RelayQuoteClientError, } from './src/quote';
9
9
  export { type SolanaAddress, type SolanaTxHash, type SolanaWallet, getSolanaWallet, } from './src/solana';
10
+ export { type TronAddress, type TronTxHash, type TronWallet, getTronWallet, } from './src/tron';
10
11
  export type { LighterAccountIndex, LighterWallet } from './src/lighter';
11
12
  export { getRelayExecutionRefundState, getRelayExecutionState, isRelayExecutionTerminalStatus, convertFunToRelayTokenAddress, convertFunToRelayChainId, } from './src/utils';
12
13
  export { LogLevel, type RelayExecutionInfo, type RelayExecutionStatus, type RelayTokenPriceInfo, } from './src/types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,gBAAgB,EAChB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EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,eAAe,GAChB,MAAM,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,2BAA2B,GACjC,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,aAAa,EACb,WAAW,EACX,qBAAqB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,eAAe,GAChB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,aAAa,GACd,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxE,YAAY,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,eAAe,GAChB,MAAM,2BAA2B,CAAA"}
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  getRelayExecutionState: () => getRelayExecutionState,
48
48
  getRelayQuote: () => getRelayQuote,
49
49
  getSolanaWallet: () => getSolanaWallet,
50
+ getTronWallet: () => getTronWallet,
50
51
  initDynamicRouting: () => initDynamicRouting,
51
52
  initializeRelayClient: () => initializeRelayClient,
52
53
  isRelayExecutionTerminalStatus: () => isRelayExecutionTerminalStatus,
@@ -84,6 +85,8 @@ var FUN_SOLANA_CHAIN_ID_NUMBER = 1151111081099710;
84
85
  var FUN_HYPERCORE_CHAIN_ID_NUMBER = 1337;
85
86
  var RELAY_LIGHTER_CHAIN_ID_NUMBER = 3586256;
86
87
  var RELAY_LIGHTER_CHAIN_ID = `${RELAY_LIGHTER_CHAIN_ID_NUMBER}`;
88
+ var RELAY_TRON_CHAIN_ID_NUMBER = 728126428;
89
+ var RELAY_TRON_CHAIN_ID = `${RELAY_TRON_CHAIN_ID_NUMBER}`;
87
90
  var FUNKIT_NATIVE_TOKEN = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
88
91
  var RELAY_NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
89
92
  var RELAY_NATIVE_TOKEN_HYPERCORE = "0x00000000000000000000000000000000";
@@ -215,6 +218,15 @@ function indexBy(items, getKey) {
215
218
  }
216
219
  return indexedItems;
217
220
  }
221
+ function filterNullishHeaders(params) {
222
+ const result = {};
223
+ for (const [key, value] of Object.entries(params)) {
224
+ if (value != null) {
225
+ result[key] = value;
226
+ }
227
+ }
228
+ return result;
229
+ }
218
230
 
219
231
  // src/execution.ts
220
232
  function getTxHash({
@@ -232,7 +244,7 @@ function getTxHash({
232
244
  };
233
245
  logger.info(`${logPrefix}:started`, logProps);
234
246
  const getTxHashFromTxHashes = () => {
235
- const rawTxHashWithUnreliableTyping = txHashes[0].txHash;
247
+ const rawTxHashWithUnreliableTyping = txHashes[0]?.txHash;
236
248
  const txHash = typeof rawTxHashWithUnreliableTyping === "object" ? rawTxHashWithUnreliableTyping.id : rawTxHashWithUnreliableTyping;
237
249
  logger.info(`${logPrefix}:txHashesMode`, {
238
250
  ...logProps,
@@ -367,12 +379,14 @@ async function executeRelayQuote({
367
379
  ) {
368
380
  logger.info(`${logPrefix}:onTransactionConfirmed`, txHashes);
369
381
  isTransactionConfirmed = true;
370
- if (relayQuote.steps[0].requestId) {
382
+ const firstStep = relayQuote.steps[0];
383
+ const firstItem = firstStep?.items[0];
384
+ if (firstStep?.requestId && firstItem) {
371
385
  manuallyRegisterIndex(logger, {
372
- requestId: relayQuote.steps[0].requestId,
373
- chainId: relayQuote.steps[0].items[0].data.chainId,
386
+ requestId: firstStep.requestId,
387
+ chainId: firstItem.data.chainId,
374
388
  tx: jsonStringifyWithBigIntSanitization({
375
- ...relayQuote.steps[0].items[0].data,
389
+ ...firstItem.data,
376
390
  txHash
377
391
  })
378
392
  });
@@ -426,9 +440,11 @@ async function manuallyRegisterIndex(logger, registerRequest) {
426
440
  });
427
441
  }
428
442
  }
429
- async function getRelayExecutionInfo(requestId) {
443
+ async function getRelayExecutionInfo(requestId, apiKey) {
430
444
  const url = `${import_relay_sdk3.MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`;
431
- const response = await fetch(url);
445
+ const response = await fetch(url, {
446
+ headers: { "x-api-key": apiKey }
447
+ });
432
448
  if (!response.ok) {
433
449
  throw Error(response.statusText);
434
450
  }
@@ -510,7 +526,8 @@ function parseRelayFees({
510
526
  var import_relay_sdk4 = require("@relayprotocol/relay-sdk");
511
527
  async function getRelayAssetPriceInfo({
512
528
  chainId,
513
- address
529
+ address,
530
+ apiKey
514
531
  }) {
515
532
  const relayChainId = convertFunToRelayChainId(Number(chainId));
516
533
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -518,7 +535,8 @@ async function getRelayAssetPriceInfo({
518
535
  relayChainId
519
536
  );
520
537
  const url = `${import_relay_sdk4.MAINNET_RELAY_API}/currencies/token/price?chainId=${relayChainId}&address=${relayTokenAddress}`;
521
- const response = await fetch(url);
538
+ const headers = filterNullishHeaders({ "x-api-key": apiKey });
539
+ const response = await fetch(url, { headers });
522
540
  if (!response.ok) {
523
541
  throw Error(response.statusText);
524
542
  }
@@ -530,7 +548,8 @@ async function getRelayAssetPriceInfo({
530
548
  var import_relay_sdk5 = require("@relayprotocol/relay-sdk");
531
549
  async function getRelayAssetInfo({
532
550
  chainId,
533
- address
551
+ address,
552
+ apiKey
534
553
  }) {
535
554
  const relayChainId = convertFunToRelayChainId(Number(chainId));
536
555
  const relayTokenAddress = convertFunToRelayTokenAddress(
@@ -538,13 +557,17 @@ async function getRelayAssetInfo({
538
557
  relayChainId
539
558
  );
540
559
  const url = `${import_relay_sdk5.MAINNET_RELAY_API}/currencies/v2`;
560
+ const headers = filterNullishHeaders({
561
+ "Content-Type": "application/json",
562
+ "x-api-key": apiKey
563
+ });
541
564
  const body = {
542
565
  chainIds: [relayChainId],
543
566
  address: relayTokenAddress
544
567
  };
545
568
  const response = await fetch(url, {
546
569
  method: "POST",
547
- headers: { "Content-Type": "application/json" },
570
+ headers,
548
571
  body: JSON.stringify(body)
549
572
  });
550
573
  if (!response.ok) {
@@ -561,7 +584,8 @@ async function getQuoteEstUsdValue({
561
584
  tokenChainId,
562
585
  tokenAddress,
563
586
  tokenAmountBaseUnit,
564
- logger
587
+ logger,
588
+ apiKey
565
589
  }) {
566
590
  try {
567
591
  const normalizedChainId = convertFunToRelayChainId(
@@ -574,11 +598,13 @@ async function getQuoteEstUsdValue({
574
598
  const [tokenPriceRes, tokenInfoRes] = await Promise.all([
575
599
  getRelayAssetPriceInfo({
576
600
  chainId: normalizedChainId,
577
- address: normalizedTokenAddress
601
+ address: normalizedTokenAddress,
602
+ apiKey
578
603
  }),
579
604
  getRelayAssetInfo({
580
605
  chainId: normalizedChainId,
581
- address: normalizedTokenAddress
606
+ address: normalizedTokenAddress,
607
+ apiKey
582
608
  })
583
609
  ]);
584
610
  const isWUsdeEthereal = normalizedChainId === "5064014" && normalizedTokenAddress.toLowerCase() === "0xB6fC4B1BFF391e5F6b4a3D2C7Bda1FeE3524692D".toLowerCase();
@@ -609,11 +635,9 @@ var RelayQuoteClientError = class extends Error {
609
635
  Object.setPrototypeOf(this, new.target.prototype);
610
636
  }
611
637
  };
612
- var getHeaders = (funRelayConfig, subsidizeFeesSecretKey) => {
613
- const subsidizeFees = !!funRelayConfig.config.options.subsidizeFees;
638
+ var getHeaders = (funRelayConfig, apiKey) => {
614
639
  const headers = {
615
- // only apply subsidizeFeesSecretKey if subsidizeFees is true
616
- ...subsidizeFees && subsidizeFeesSecretKey ? { "x-api-key": subsidizeFeesSecretKey } : {},
640
+ "x-api-key": apiKey,
617
641
  // Remote headers will override passed in headers
618
642
  ...funRelayConfig.headers ? { ...funRelayConfig.headers } : {}
619
643
  };
@@ -635,7 +659,7 @@ async function getRelayQuote({
635
659
  toTokenAddress,
636
660
  tradeType,
637
661
  userAddress,
638
- subsidizeFeesSecretKey
662
+ apiKey
639
663
  } = params;
640
664
  const vmType = walletClient && "vmType" in walletClient ? walletClient.vmType : "evm";
641
665
  try {
@@ -668,7 +692,8 @@ async function getRelayQuote({
668
692
  tokenChainId: queryTokenChainId,
669
693
  tokenAddress: queryTokenAddress,
670
694
  tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),
671
- logger
695
+ logger,
696
+ apiKey
672
697
  });
673
698
  const funRelayConfig = await getFunRelayFees({
674
699
  clientId,
@@ -680,7 +705,7 @@ async function getRelayQuote({
680
705
  toTokenAddress,
681
706
  toChainId
682
707
  });
683
- const headers = getHeaders(funRelayConfig, subsidizeFeesSecretKey);
708
+ const headers = getHeaders(funRelayConfig, apiKey);
684
709
  const appFeeBp = funRelayConfig.b + funRelayConfig.v;
685
710
  logger.info("getRelayQuoteParams", {
686
711
  ...params,
@@ -839,6 +864,12 @@ function getSolanaWallet(walletAddress, connection, signTransaction, payerKey) {
839
864
  );
840
865
  }
841
866
 
867
+ // src/tron.ts
868
+ var import_relay_tron_wallet_adapter = require("@relayprotocol/relay-tron-wallet-adapter");
869
+ function getTronWallet(walletAddress, tronWeb) {
870
+ return (0, import_relay_tron_wallet_adapter.adaptTronWallet)(walletAddress, tronWeb);
871
+ }
872
+
842
873
  // src/dynamicRoutes/lighter.ts
843
874
  var import_viem4 = require("viem");
844
875
  var import_chains2 = require("viem/chains");