@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/CHANGELOG.md +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -17
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +46 -17
- package/dist/index.mjs.map +3 -3
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/currency.d.ts +5 -2
- package/dist/src/currency.d.ts.map +1 -1
- package/dist/src/execution.d.ts +8 -3
- package/dist/src/execution.d.ts.map +1 -1
- package/dist/src/price.d.ts +5 -2
- package/dist/src/price.d.ts.map +1 -1
- package/dist/src/quote.d.ts +3 -3
- package/dist/src/quote.d.ts.map +1 -1
- package/dist/src/tron.d.ts +10 -0
- package/dist/src/tron.d.ts.map +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @funkit/fun-relay
|
|
2
2
|
|
|
3
|
+
## 2.2.0-next.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c289ca6: feat(fun-relay): require api key for relay to prevent rate limiting
|
|
8
|
+
feat(connect): pass pseudo api key to fun-relay
|
|
9
|
+
- aa767b0: feat: add tron adapter
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fd5fe29: fix(fun-relay): add protocolVersion to tests
|
|
14
|
+
|
|
15
|
+
## 2.1.16-next.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- e009c8d: Fix USDC_PERPS icon displaying ETH logo instead of USDC logo
|
|
20
|
+
|
|
3
21
|
## 2.1.16-next.1
|
|
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';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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,KAA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,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({
|
|
@@ -426,9 +438,11 @@ async function manuallyRegisterIndex(logger, registerRequest) {
|
|
|
426
438
|
});
|
|
427
439
|
}
|
|
428
440
|
}
|
|
429
|
-
async function getRelayExecutionInfo(requestId) {
|
|
441
|
+
async function getRelayExecutionInfo(requestId, apiKey) {
|
|
430
442
|
const url = `${import_relay_sdk3.MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`;
|
|
431
|
-
const response = await fetch(url
|
|
443
|
+
const response = await fetch(url, {
|
|
444
|
+
headers: { "x-api-key": apiKey }
|
|
445
|
+
});
|
|
432
446
|
if (!response.ok) {
|
|
433
447
|
throw Error(response.statusText);
|
|
434
448
|
}
|
|
@@ -510,7 +524,8 @@ function parseRelayFees({
|
|
|
510
524
|
var import_relay_sdk4 = require("@relayprotocol/relay-sdk");
|
|
511
525
|
async function getRelayAssetPriceInfo({
|
|
512
526
|
chainId,
|
|
513
|
-
address
|
|
527
|
+
address,
|
|
528
|
+
apiKey
|
|
514
529
|
}) {
|
|
515
530
|
const relayChainId = convertFunToRelayChainId(Number(chainId));
|
|
516
531
|
const relayTokenAddress = convertFunToRelayTokenAddress(
|
|
@@ -518,7 +533,8 @@ async function getRelayAssetPriceInfo({
|
|
|
518
533
|
relayChainId
|
|
519
534
|
);
|
|
520
535
|
const url = `${import_relay_sdk4.MAINNET_RELAY_API}/currencies/token/price?chainId=${relayChainId}&address=${relayTokenAddress}`;
|
|
521
|
-
const
|
|
536
|
+
const headers = filterNullishHeaders({ "x-api-key": apiKey });
|
|
537
|
+
const response = await fetch(url, { headers });
|
|
522
538
|
if (!response.ok) {
|
|
523
539
|
throw Error(response.statusText);
|
|
524
540
|
}
|
|
@@ -530,7 +546,8 @@ async function getRelayAssetPriceInfo({
|
|
|
530
546
|
var import_relay_sdk5 = require("@relayprotocol/relay-sdk");
|
|
531
547
|
async function getRelayAssetInfo({
|
|
532
548
|
chainId,
|
|
533
|
-
address
|
|
549
|
+
address,
|
|
550
|
+
apiKey
|
|
534
551
|
}) {
|
|
535
552
|
const relayChainId = convertFunToRelayChainId(Number(chainId));
|
|
536
553
|
const relayTokenAddress = convertFunToRelayTokenAddress(
|
|
@@ -538,13 +555,17 @@ async function getRelayAssetInfo({
|
|
|
538
555
|
relayChainId
|
|
539
556
|
);
|
|
540
557
|
const url = `${import_relay_sdk5.MAINNET_RELAY_API}/currencies/v2`;
|
|
558
|
+
const headers = filterNullishHeaders({
|
|
559
|
+
"Content-Type": "application/json",
|
|
560
|
+
"x-api-key": apiKey
|
|
561
|
+
});
|
|
541
562
|
const body = {
|
|
542
563
|
chainIds: [relayChainId],
|
|
543
564
|
address: relayTokenAddress
|
|
544
565
|
};
|
|
545
566
|
const response = await fetch(url, {
|
|
546
567
|
method: "POST",
|
|
547
|
-
headers
|
|
568
|
+
headers,
|
|
548
569
|
body: JSON.stringify(body)
|
|
549
570
|
});
|
|
550
571
|
if (!response.ok) {
|
|
@@ -561,7 +582,8 @@ async function getQuoteEstUsdValue({
|
|
|
561
582
|
tokenChainId,
|
|
562
583
|
tokenAddress,
|
|
563
584
|
tokenAmountBaseUnit,
|
|
564
|
-
logger
|
|
585
|
+
logger,
|
|
586
|
+
apiKey
|
|
565
587
|
}) {
|
|
566
588
|
try {
|
|
567
589
|
const normalizedChainId = convertFunToRelayChainId(
|
|
@@ -574,11 +596,13 @@ async function getQuoteEstUsdValue({
|
|
|
574
596
|
const [tokenPriceRes, tokenInfoRes] = await Promise.all([
|
|
575
597
|
getRelayAssetPriceInfo({
|
|
576
598
|
chainId: normalizedChainId,
|
|
577
|
-
address: normalizedTokenAddress
|
|
599
|
+
address: normalizedTokenAddress,
|
|
600
|
+
apiKey
|
|
578
601
|
}),
|
|
579
602
|
getRelayAssetInfo({
|
|
580
603
|
chainId: normalizedChainId,
|
|
581
|
-
address: normalizedTokenAddress
|
|
604
|
+
address: normalizedTokenAddress,
|
|
605
|
+
apiKey
|
|
582
606
|
})
|
|
583
607
|
]);
|
|
584
608
|
const isWUsdeEthereal = normalizedChainId === "5064014" && normalizedTokenAddress.toLowerCase() === "0xB6fC4B1BFF391e5F6b4a3D2C7Bda1FeE3524692D".toLowerCase();
|
|
@@ -609,11 +633,9 @@ var RelayQuoteClientError = class extends Error {
|
|
|
609
633
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
610
634
|
}
|
|
611
635
|
};
|
|
612
|
-
var getHeaders = (funRelayConfig,
|
|
613
|
-
const subsidizeFees = !!funRelayConfig.config.options.subsidizeFees;
|
|
636
|
+
var getHeaders = (funRelayConfig, apiKey) => {
|
|
614
637
|
const headers = {
|
|
615
|
-
|
|
616
|
-
...subsidizeFees && subsidizeFeesSecretKey ? { "x-api-key": subsidizeFeesSecretKey } : {},
|
|
638
|
+
"x-api-key": apiKey,
|
|
617
639
|
// Remote headers will override passed in headers
|
|
618
640
|
...funRelayConfig.headers ? { ...funRelayConfig.headers } : {}
|
|
619
641
|
};
|
|
@@ -635,7 +657,7 @@ async function getRelayQuote({
|
|
|
635
657
|
toTokenAddress,
|
|
636
658
|
tradeType,
|
|
637
659
|
userAddress,
|
|
638
|
-
|
|
660
|
+
apiKey
|
|
639
661
|
} = params;
|
|
640
662
|
const vmType = walletClient && "vmType" in walletClient ? walletClient.vmType : "evm";
|
|
641
663
|
try {
|
|
@@ -668,7 +690,8 @@ async function getRelayQuote({
|
|
|
668
690
|
tokenChainId: queryTokenChainId,
|
|
669
691
|
tokenAddress: queryTokenAddress,
|
|
670
692
|
tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),
|
|
671
|
-
logger
|
|
693
|
+
logger,
|
|
694
|
+
apiKey
|
|
672
695
|
});
|
|
673
696
|
const funRelayConfig = await getFunRelayFees({
|
|
674
697
|
clientId,
|
|
@@ -680,7 +703,7 @@ async function getRelayQuote({
|
|
|
680
703
|
toTokenAddress,
|
|
681
704
|
toChainId
|
|
682
705
|
});
|
|
683
|
-
const headers = getHeaders(funRelayConfig,
|
|
706
|
+
const headers = getHeaders(funRelayConfig, apiKey);
|
|
684
707
|
const appFeeBp = funRelayConfig.b + funRelayConfig.v;
|
|
685
708
|
logger.info("getRelayQuoteParams", {
|
|
686
709
|
...params,
|
|
@@ -839,6 +862,12 @@ function getSolanaWallet(walletAddress, connection, signTransaction, payerKey) {
|
|
|
839
862
|
);
|
|
840
863
|
}
|
|
841
864
|
|
|
865
|
+
// src/tron.ts
|
|
866
|
+
var import_relay_tron_wallet_adapter = require("@relayprotocol/relay-tron-wallet-adapter");
|
|
867
|
+
function getTronWallet(walletAddress, tronWeb) {
|
|
868
|
+
return (0, import_relay_tron_wallet_adapter.adaptTronWallet)(walletAddress, tronWeb);
|
|
869
|
+
}
|
|
870
|
+
|
|
842
871
|
// src/dynamicRoutes/lighter.ts
|
|
843
872
|
var import_viem4 = require("viem");
|
|
844
873
|
var import_chains2 = require("viem/chains");
|
|
@@ -1632,7 +1661,7 @@ var LIGHTER_DYNAMIC_ROUTES = [
|
|
|
1632
1661
|
targetChain: RELAY_LIGHTER_CHAIN_ID2.toString(),
|
|
1633
1662
|
targetAsset: RELAY_LIGHTER_USDC_PERPS_ADDRESS,
|
|
1634
1663
|
targetAssetTicker: USDC_PERPS_SYMBOL,
|
|
1635
|
-
iconSrc: ASSET_LOGO_SRCS.
|
|
1664
|
+
iconSrc: ASSET_LOGO_SRCS.USDC,
|
|
1636
1665
|
getCustomRecipient: ({ l2Address }) => {
|
|
1637
1666
|
return l2Address;
|
|
1638
1667
|
}
|