@swapkit/helpers 3.0.0-beta.12 → 3.0.0-beta.14
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/api/index.cjs +2 -2
- package/dist/api/index.cjs.map +6 -6
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +6 -6
- package/dist/{chunk-hk0jx7rp.js → chunk-7shcm26h.js} +3 -3
- package/dist/{chunk-hk0jx7rp.js.map → chunk-7shcm26h.js.map} +1 -1
- package/dist/chunk-8fdws4se.js +4 -0
- package/dist/chunk-8fdws4se.js.map +10 -0
- package/dist/{chunk-k2m9hvag.js → chunk-b8hashv0.js} +3 -3
- package/dist/{chunk-k2m9hvag.js.map → chunk-b8hashv0.js.map} +1 -1
- package/dist/{chunk-c4ndre32.js → chunk-bf0ph1bk.js} +3 -3
- package/dist/{chunk-c4ndre32.js.map → chunk-bf0ph1bk.js.map} +1 -1
- package/dist/{chunk-4mz4n5jc.js → chunk-bh986mnf.js} +3 -3
- package/dist/{chunk-4mz4n5jc.js.map → chunk-bh986mnf.js.map} +1 -1
- package/dist/{chunk-hbnf5tky.js → chunk-dzypg9sp.js} +3 -3
- package/dist/{chunk-hbnf5tky.js.map → chunk-dzypg9sp.js.map} +1 -1
- package/dist/{chunk-mt3sdnfg.js → chunk-ghdhtvtt.js} +3 -3
- package/dist/{chunk-mt3sdnfg.js.map → chunk-ghdhtvtt.js.map} +1 -1
- package/dist/{chunk-3ts9cha8.js → chunk-jhmhh7ax.js} +3 -3
- package/dist/{chunk-3ts9cha8.js.map → chunk-jhmhh7ax.js.map} +1 -1
- package/dist/{chunk-frkpmajq.js → chunk-nm1av1e6.js} +3 -3
- package/dist/{chunk-frkpmajq.js.map → chunk-nm1av1e6.js.map} +1 -1
- package/dist/{chunk-4edjz16h.js → chunk-rarep8vg.js} +3 -3
- package/dist/{chunk-4edjz16h.js.map → chunk-rarep8vg.js.map} +1 -1
- package/dist/{chunk-2vqx8ecy.js → chunk-rr043vwc.js} +3 -3
- package/dist/{chunk-2vqx8ecy.js.map → chunk-rr043vwc.js.map} +1 -1
- package/dist/{chunk-ganzk321.js → chunk-s82pm7xc.js} +2 -2
- package/dist/{chunk-ganzk321.js.map → chunk-s82pm7xc.js.map} +1 -1
- package/dist/chunk-sb9hymk1.js +3 -0
- package/dist/chunk-sb9hymk1.js.map +10 -0
- package/dist/{chunk-prm0g9b0.js → chunk-tn4e7zrk.js} +3 -3
- package/dist/{chunk-prm0g9b0.js.map → chunk-tn4e7zrk.js.map} +1 -1
- package/dist/{chunk-zv69dnwn.js → chunk-vadspc46.js} +3 -3
- package/dist/{chunk-zv69dnwn.js.map → chunk-vadspc46.js.map} +1 -1
- package/dist/{chunk-qpz3c078.js → chunk-vgg88vt8.js} +3 -3
- package/dist/{chunk-qpz3c078.js.map → chunk-vgg88vt8.js.map} +1 -1
- package/dist/{chunk-qkreqkaa.js → chunk-wssz50sc.js} +3 -3
- package/dist/{chunk-qkreqkaa.js.map → chunk-wssz50sc.js.map} +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +15 -16
- package/dist/index.js +3 -3
- package/dist/index.js.map +15 -16
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/index.js.map +2 -2
- package/package.json +2 -2
- package/src/api/midgard/endpoints.ts +6 -47
- package/src/api/swapkitApi/endpoints.ts +9 -26
- package/src/api/swapkitApi/types.ts +1 -1
- package/src/api/thornode/endpoints.ts +8 -26
- package/src/modules/__tests__/assetValue.test.ts +42 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
- package/src/modules/assetValue.ts +12 -28
- package/src/modules/bigIntArithmetics.ts +12 -1
- package/src/modules/requestClient.ts +36 -22
- package/src/modules/swapKitConfig.ts +1 -29
- package/src/modules/swapKitError.ts +294 -105
- package/src/types/chains.ts +45 -37
- package/src/types/derivationPath.ts +1 -0
- package/src/types/wallet.ts +2 -0
- package/src/utils/asset.ts +3 -2
- package/src/utils/memo.ts +5 -11
- package/src/utils/others.ts +1 -2
- package/src/utils/wallets.ts +5 -2
package/src/types/chains.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
2
|
+
import { SwapKitError } from "../modules/swapKitError";
|
|
3
|
+
|
|
1
4
|
export enum Chain {
|
|
2
5
|
Arbitrum = "ARB",
|
|
3
6
|
Avalanche = "AVAX",
|
|
@@ -22,6 +25,7 @@ export enum Chain {
|
|
|
22
25
|
Ripple = "XRP",
|
|
23
26
|
THORChain = "THOR",
|
|
24
27
|
Solana = "SOL",
|
|
28
|
+
Tron = "TRX",
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export enum StagenetChain {
|
|
@@ -62,6 +66,7 @@ export enum ChainId {
|
|
|
62
66
|
THORChain = "thorchain-1",
|
|
63
67
|
THORChainStagenet = "thorchain-stagenet-v2",
|
|
64
68
|
Solana = "solana",
|
|
69
|
+
Tron = "tron",
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
@@ -97,6 +102,7 @@ export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
|
97
102
|
[ChainId.Solana]: Chain.Solana,
|
|
98
103
|
[ChainId.THORChainStagenet]: Chain.THORChain,
|
|
99
104
|
[ChainId.THORChain]: Chain.THORChain,
|
|
105
|
+
[ChainId.Tron]: Chain.Tron,
|
|
100
106
|
};
|
|
101
107
|
|
|
102
108
|
type ChainNameType = keyof typeof Chain;
|
|
@@ -125,6 +131,7 @@ export const BaseDecimal: Record<Chain, number> = {
|
|
|
125
131
|
OP: 18,
|
|
126
132
|
SOL: 9,
|
|
127
133
|
THOR: 8,
|
|
134
|
+
TRX: 6,
|
|
128
135
|
XRD: 18,
|
|
129
136
|
XRP: 6,
|
|
130
137
|
};
|
|
@@ -153,6 +160,7 @@ export const BlockTimes: Record<Partial<Chain>, number> = {
|
|
|
153
160
|
[Chain.Ripple]: 5,
|
|
154
161
|
[Chain.Solana]: 0.4,
|
|
155
162
|
[Chain.THORChain]: 6,
|
|
163
|
+
[Chain.Tron]: 3,
|
|
156
164
|
};
|
|
157
165
|
|
|
158
166
|
export type SubstrateChain = Chain.Polkadot | Chain.Chainflip;
|
|
@@ -245,6 +253,7 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
|
|
|
245
253
|
[Chain.Ripple]: "wss://xrpl.ws/",
|
|
246
254
|
[Chain.Solana]: "https://solana-rpc.publicnode.com",
|
|
247
255
|
[Chain.THORChain]: "https://rpc.thorswap.net",
|
|
256
|
+
[Chain.Tron]: "https://api.trongrid.io",
|
|
248
257
|
[StagenetChain.Maya]: "https://stagenet.tendermint.mayachain.info",
|
|
249
258
|
[StagenetChain.THORChain]: "https://stagenet-rpc.ninerealms.com",
|
|
250
259
|
};
|
|
@@ -300,6 +309,7 @@ export const FALLBACK_URLS: Record<Chain | StagenetChain, string[]> = {
|
|
|
300
309
|
[Chain.THORChain]: ["https://thornode.ninerealms.com", NODE_URLS[Chain.THORChain]],
|
|
301
310
|
[StagenetChain.THORChain]: [],
|
|
302
311
|
[Chain.Solana]: ["https://api.mainnet-beta.solana.com", "https://rpc.ankr.com/solana"],
|
|
312
|
+
[Chain.Tron]: ["https://api.tronstack.io", "https://api.tron.network"],
|
|
303
313
|
};
|
|
304
314
|
|
|
305
315
|
export const EXPLORER_URLS: Record<Chain, string> = {
|
|
@@ -326,51 +336,49 @@ export const EXPLORER_URLS: Record<Chain, string> = {
|
|
|
326
336
|
[Chain.Ripple]: "https://livenet.xrpl.org/",
|
|
327
337
|
[Chain.THORChain]: "https://runescan.io",
|
|
328
338
|
[Chain.Solana]: "https://solscan.io",
|
|
339
|
+
[Chain.Tron]: "https://tronscan.org",
|
|
329
340
|
};
|
|
330
341
|
|
|
331
342
|
let RPCUrlsMerged = RPC_URLS;
|
|
332
343
|
|
|
333
344
|
const getRpcBody = (chain: Chain | StagenetChain) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
345
|
+
return match(chain)
|
|
346
|
+
.with(
|
|
347
|
+
Chain.Arbitrum,
|
|
348
|
+
Chain.Avalanche,
|
|
349
|
+
Chain.Base,
|
|
350
|
+
Chain.BinanceSmartChain,
|
|
351
|
+
Chain.Ethereum,
|
|
352
|
+
Chain.Optimism,
|
|
353
|
+
Chain.Polygon,
|
|
354
|
+
Chain.Tron,
|
|
355
|
+
() => ({ id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] }),
|
|
356
|
+
)
|
|
357
|
+
.with(Chain.Bitcoin, Chain.Dogecoin, Chain.BitcoinCash, Chain.Dash, Chain.Litecoin, () => ({
|
|
358
|
+
id: "test",
|
|
359
|
+
jsonrpc: "1.0",
|
|
360
|
+
method: "getblockchaininfo",
|
|
361
|
+
params: [],
|
|
362
|
+
}))
|
|
363
|
+
.with(
|
|
364
|
+
Chain.Cosmos,
|
|
365
|
+
Chain.Kujira,
|
|
366
|
+
Chain.Maya,
|
|
367
|
+
Chain.THORChain,
|
|
368
|
+
StagenetChain.Maya,
|
|
369
|
+
StagenetChain.THORChain,
|
|
370
|
+
() => ({ id: 1, jsonrpc: "2.0", method: "status", params: {} }),
|
|
371
|
+
)
|
|
372
|
+
.with(Chain.Polkadot, () => ({ id: 1, jsonrpc: "2.0", method: "system_health", params: [] }))
|
|
373
|
+
.with(Chain.Solana, () => ({ id: 1, jsonrpc: "2.0", method: "getHealth" }))
|
|
374
|
+
.with(Chain.Radix, () => "")
|
|
375
|
+
.otherwise(() => {
|
|
376
|
+
throw new SwapKitError("helpers_chain_not_supported", { chain });
|
|
377
|
+
});
|
|
365
378
|
};
|
|
366
379
|
|
|
367
380
|
function getChainStatusEndpoint(chain: Chain | StagenetChain) {
|
|
368
|
-
|
|
369
|
-
case Chain.Radix:
|
|
370
|
-
return "/status/network-configuration";
|
|
371
|
-
default:
|
|
372
|
-
return "";
|
|
373
|
-
}
|
|
381
|
+
return chain === Chain.Radix ? "/status/network-configuration" : "";
|
|
374
382
|
}
|
|
375
383
|
|
|
376
384
|
const testRPCConnection = async (chain: Chain | StagenetChain, url: string) => {
|
|
@@ -32,6 +32,7 @@ export const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {
|
|
|
32
32
|
OP: [44, 60, 0, 0, 0],
|
|
33
33
|
SOL: [44, 501, 0, 0, 0],
|
|
34
34
|
THOR: [44, 931, 0, 0, 0],
|
|
35
|
+
TRX: [44, 195, 0, 0, 0],
|
|
35
36
|
|
|
36
37
|
// Polkadot and related network derivation path is not number based
|
|
37
38
|
DOT: [0, 0, 0, 0, 0],
|
package/src/types/wallet.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { RadixWallet } from "@swapkit/toolboxes/radix";
|
|
|
4
4
|
import type { RippleWallet } from "@swapkit/toolboxes/ripple";
|
|
5
5
|
import type { SolanaWallet } from "@swapkit/toolboxes/solana";
|
|
6
6
|
import type { SubstrateToolboxes } from "@swapkit/toolboxes/substrate";
|
|
7
|
+
import type { TronWallet } from "@swapkit/toolboxes/tron";
|
|
7
8
|
import type { UTXOToolboxes } from "@swapkit/toolboxes/utxo";
|
|
8
9
|
import type { BrowserProvider } from "ethers";
|
|
9
10
|
import type { Eip1193Provider } from "ethers";
|
|
@@ -108,6 +109,7 @@ export type FullWallet = BaseWallet<
|
|
|
108
109
|
[Chain.Radix]: RadixWallet;
|
|
109
110
|
[Chain.Ripple]: RippleWallet;
|
|
110
111
|
[Chain.Solana]: SolanaWallet;
|
|
112
|
+
[Chain.Tron]: TronWallet;
|
|
111
113
|
}
|
|
112
114
|
>;
|
|
113
115
|
|
package/src/utils/asset.ts
CHANGED
|
@@ -53,7 +53,7 @@ async function getContractDecimals({ chain, to }: { chain: EVMChain; to: string
|
|
|
53
53
|
|
|
54
54
|
return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
|
|
55
55
|
} catch (error) {
|
|
56
|
-
console.error(error);
|
|
56
|
+
console.error(`Failed to fetch contract decimals for ${to} on ${chain}:`, error);
|
|
57
57
|
return BaseDecimal[chain];
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -77,7 +77,7 @@ async function getRadixAssetDecimal(symbol: string) {
|
|
|
77
77
|
|
|
78
78
|
return manager.divisibility.value.divisibility;
|
|
79
79
|
} catch (error) {
|
|
80
|
-
console.error(error);
|
|
80
|
+
console.error(`Failed to fetch Radix asset decimal for ${symbol}:`, error);
|
|
81
81
|
return BaseDecimal[Chain.Radix];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -139,6 +139,7 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
|
|
|
139
139
|
Chain.Kujira,
|
|
140
140
|
Chain.Ripple,
|
|
141
141
|
Chain.Polkadot,
|
|
142
|
+
Chain.Tron,
|
|
142
143
|
(asset) => ({ identifier: `${asset}.${asset}`, decimal }),
|
|
143
144
|
)
|
|
144
145
|
.with(Chain.Radix, "XRD.XRD", () => ({ identifier: "XRD.XRD", decimal }))
|
package/src/utils/memo.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
1
2
|
import { Chain } from "../types/chains";
|
|
2
3
|
import { MemoType } from "../types/sdk";
|
|
3
4
|
|
|
@@ -95,17 +96,10 @@ function getPoolIdentifier({
|
|
|
95
96
|
chain: Chain;
|
|
96
97
|
symbol: string;
|
|
97
98
|
}) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return chain.slice(0, 1).toLowerCase();
|
|
103
|
-
case Chain.BitcoinCash:
|
|
104
|
-
return "c";
|
|
105
|
-
|
|
106
|
-
default:
|
|
107
|
-
return `${chain}.${symbol}`;
|
|
108
|
-
}
|
|
99
|
+
return match(chain)
|
|
100
|
+
.with(Chain.Bitcoin, Chain.Dogecoin, Chain.Litecoin, () => chain.slice(0, 1).toLowerCase())
|
|
101
|
+
.with(Chain.BitcoinCash, () => "c")
|
|
102
|
+
.otherwise(() => `${chain}.${symbol}`);
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
type WithAffiliate<T extends {}> = T & {
|
package/src/utils/others.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
|
34
34
|
throw new SwapKitError(errorKey, error);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -62,7 +62,6 @@ export function warnOnce(condition: boolean, warning: string) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
warnings.add(warning);
|
|
65
|
-
console.warn(warning);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
|
package/src/utils/wallets.ts
CHANGED
|
@@ -70,7 +70,10 @@ export async function switchEVMWalletNetwork(
|
|
|
70
70
|
});
|
|
71
71
|
} catch (_error) {
|
|
72
72
|
if (!networkParams) {
|
|
73
|
-
throw new
|
|
73
|
+
throw new SwapKitError("helpers_failed_to_switch_network", {
|
|
74
|
+
error: _error,
|
|
75
|
+
reason: "networkParams not provided",
|
|
76
|
+
});
|
|
74
77
|
}
|
|
75
78
|
await addEVMWalletNetwork(provider, networkParams);
|
|
76
79
|
}
|
|
@@ -107,7 +110,7 @@ export function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(
|
|
|
107
110
|
provider: BrowserProvider,
|
|
108
111
|
chain: Chain,
|
|
109
112
|
) {
|
|
110
|
-
(async (...args: any[]) => {
|
|
113
|
+
return (async (...args: any[]) => {
|
|
111
114
|
try {
|
|
112
115
|
await switchEVMWalletNetwork(provider, chain);
|
|
113
116
|
} catch (error) {
|