@swapkit/toolboxes 1.0.0-beta.17 → 1.0.0-beta.18

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.
Files changed (91) hide show
  1. package/dist/{chunk-fjfxga2v.js → chunk-5yxc1e69.js} +1 -1
  2. package/dist/{chunk-fjfxga2v.js.map → chunk-5yxc1e69.js.map} +1 -1
  3. package/dist/chunk-vhc011em.js +4 -0
  4. package/dist/{chunk-0h4xdrwz.js.map → chunk-vhc011em.js.map} +2 -2
  5. package/dist/src/cosmos/index.cjs +3 -0
  6. package/dist/src/cosmos/index.cjs.map +16 -0
  7. package/dist/src/cosmos/index.js +3 -0
  8. package/dist/src/cosmos/index.js.map +16 -0
  9. package/dist/src/evm/index.cjs +3 -0
  10. package/dist/src/evm/index.cjs.map +18 -0
  11. package/dist/src/evm/index.js +3 -0
  12. package/dist/src/evm/index.js.map +18 -0
  13. package/dist/src/index.cjs +3 -0
  14. package/dist/src/index.cjs.map +10 -0
  15. package/dist/src/index.js +3 -0
  16. package/dist/src/index.js.map +10 -0
  17. package/dist/{radix → src/radix}/index.cjs +2 -2
  18. package/dist/src/radix/index.cjs.map +10 -0
  19. package/dist/src/radix/index.js +3 -0
  20. package/dist/src/radix/index.js.map +10 -0
  21. package/dist/src/ripple/index.js +3 -0
  22. package/dist/{ripple → src/ripple}/index.js.map +1 -1
  23. package/dist/src/solana/index.js +3 -0
  24. package/dist/{solana → src/solana}/index.js.map +1 -1
  25. package/dist/src/substrate/index.cjs +3 -0
  26. package/dist/src/substrate/index.cjs.map +11 -0
  27. package/dist/src/substrate/index.js +3 -0
  28. package/dist/src/substrate/index.js.map +11 -0
  29. package/dist/src/tron/index.cjs +3 -0
  30. package/dist/src/tron/index.cjs.map +11 -0
  31. package/dist/src/tron/index.js +3 -0
  32. package/dist/src/tron/index.js.map +11 -0
  33. package/dist/src/utxo/index.cjs +3 -0
  34. package/dist/src/utxo/index.cjs.map +16 -0
  35. package/dist/src/utxo/index.js +3 -0
  36. package/dist/src/utxo/index.js.map +16 -0
  37. package/package.json +24 -18
  38. package/src/cosmos/thorchainUtils/addressFormat.ts +4 -1
  39. package/src/cosmos/thorchainUtils/messages.ts +2 -2
  40. package/src/cosmos/toolbox/cosmos.ts +2 -4
  41. package/src/cosmos/toolbox/index.ts +2 -2
  42. package/src/cosmos/toolbox/thorchain.ts +3 -2
  43. package/src/cosmos/util.ts +10 -3
  44. package/src/evm/helpers.ts +4 -3
  45. package/src/evm/toolbox/baseEVMToolbox.ts +15 -12
  46. package/src/evm/toolbox/index.ts +2 -2
  47. package/src/evm/toolbox/op.ts +10 -2
  48. package/src/index.ts +104 -104
  49. package/src/radix/index.ts +8 -2
  50. package/src/substrate/substrate.ts +1 -1
  51. package/src/tron/helpers/trc20.abi.ts +40 -0
  52. package/src/tron/index.ts +16 -0
  53. package/src/tron/toolbox.ts +328 -0
  54. package/src/tron/types.ts +22 -0
  55. package/src/utxo/helpers/api.ts +25 -11
  56. package/src/utxo/helpers/bchaddrjs.ts +8 -8
  57. package/src/utxo/helpers/coinselect.ts +2 -2
  58. package/src/utxo/helpers/txSize.ts +2 -1
  59. package/src/utxo/toolbox/bitcoinCash.ts +14 -6
  60. package/src/utxo/toolbox/index.ts +2 -1
  61. package/src/utxo/toolbox/utxo.ts +23 -9
  62. package/dist/chunk-0h4xdrwz.js +0 -4
  63. package/dist/cosmos/index.cjs +0 -3
  64. package/dist/cosmos/index.cjs.map +0 -16
  65. package/dist/cosmos/index.js +0 -3
  66. package/dist/cosmos/index.js.map +0 -16
  67. package/dist/evm/index.cjs +0 -3
  68. package/dist/evm/index.cjs.map +0 -18
  69. package/dist/evm/index.js +0 -3
  70. package/dist/evm/index.js.map +0 -18
  71. package/dist/index.cjs +0 -3
  72. package/dist/index.cjs.map +0 -10
  73. package/dist/index.js +0 -3
  74. package/dist/index.js.map +0 -10
  75. package/dist/radix/index.cjs.map +0 -10
  76. package/dist/radix/index.js +0 -3
  77. package/dist/radix/index.js.map +0 -10
  78. package/dist/ripple/index.js +0 -3
  79. package/dist/solana/index.js +0 -3
  80. package/dist/substrate/index.cjs +0 -3
  81. package/dist/substrate/index.cjs.map +0 -11
  82. package/dist/substrate/index.js +0 -3
  83. package/dist/substrate/index.js.map +0 -11
  84. package/dist/utxo/index.cjs +0 -3
  85. package/dist/utxo/index.cjs.map +0 -16
  86. package/dist/utxo/index.js +0 -3
  87. package/dist/utxo/index.js.map +0 -16
  88. /package/dist/{ripple → src/ripple}/index.cjs +0 -0
  89. /package/dist/{ripple → src/ripple}/index.cjs.map +0 -0
  90. /package/dist/{solana → src/solana}/index.cjs +0 -0
  91. /package/dist/{solana → src/solana}/index.cjs.map +0 -0
@@ -1,6 +1,13 @@
1
1
  import type { OfflineSigner } from "@cosmjs/proto-signing";
2
2
  import type { SigningStargateClientOptions } from "@cosmjs/stargate";
3
- import { AssetValue, Chain, ChainId, type CosmosChain, SKConfig } from "@swapkit/helpers";
3
+ import {
4
+ AssetValue,
5
+ Chain,
6
+ ChainId,
7
+ type CosmosChain,
8
+ SKConfig,
9
+ SwapKitError,
10
+ } from "@swapkit/helpers";
4
11
 
5
12
  import type { CosmosCreateTransactionParams } from "./thorchainUtils";
6
13
 
@@ -126,7 +133,7 @@ const getTransferMsgTypeByChain = (chain: CosmosChain) => {
126
133
  case Chain.Kujira:
127
134
  return "/cosmos.bank.v1beta1.MsgSend";
128
135
  default:
129
- throw new Error("Unsupported chain");
136
+ throw new SwapKitError("toolbox_cosmos_not_supported", { chain });
130
137
  }
131
138
  };
132
139
 
@@ -149,7 +156,7 @@ export const cosmosCreateTransaction = async ({
149
156
  const accountOnChain = await client.getAccount(sender);
150
157
 
151
158
  if (!accountOnChain) {
152
- throw new Error("Account does not exist");
159
+ throw new SwapKitError("toolbox_cosmos_account_not_found", { sender });
153
160
  }
154
161
 
155
162
  const gasAsset = AssetValue.from({ chain });
@@ -8,6 +8,7 @@ import {
8
8
  FeeOption,
9
9
  type NetworkParams,
10
10
  SKConfig,
11
+ SwapKitError,
11
12
  SwapKitNumber,
12
13
  } from "@swapkit/helpers";
13
14
  import type { BrowserProvider, Provider } from "ethers";
@@ -71,7 +72,7 @@ export const estimateMaxSendableAmount = async ({
71
72
  const isFeeEVMLegacyCompatible = "gasPrice" in gasRate && gasRate.gasPrice !== undefined;
72
73
 
73
74
  if (!(gasRate && (isFeeEVMLegacyCompatible || isFeeEIP1559Compatible))) {
74
- throw new Error("Could not fetch fee data");
75
+ throw new SwapKitError("toolbox_evm_no_fee_data");
75
76
  }
76
77
 
77
78
  const gasPrice = isFeeEIP1559Compatible
@@ -116,7 +117,7 @@ export function getEstimateTransactionFee({
116
117
  return assetValue.set(SwapKitNumber.fromBigInt(fee, assetValue.decimal));
117
118
  }
118
119
 
119
- throw new Error("No gas price found");
120
+ throw new SwapKitError("toolbox_evm_no_gas_price");
120
121
  };
121
122
  }
122
123
 
@@ -168,6 +169,6 @@ function getNetworkInfo<C extends EVMChain>({ chain }: { chain: C }) {
168
169
  nativeCurrency: { name: "Polygon", symbol: Chain.Polygon, decimals },
169
170
  };
170
171
  default:
171
- throw new Error(`Chain ${chain} is not supported`);
172
+ throw new SwapKitError("toolbox_evm_not_supported", { chain });
172
173
  }
173
174
  }
@@ -208,7 +208,7 @@ export function getEstimateGasPrices({
208
208
  try {
209
209
  const { gasPrice } = await provider.getFeeData();
210
210
 
211
- if (!gasPrice) throw new Error("No fee data available");
211
+ if (!gasPrice) throw new SwapKitError("toolbox_evm_no_fee_data");
212
212
 
213
213
  return {
214
214
  [FeeOption.Average]: { gasPrice },
@@ -216,9 +216,9 @@ export function getEstimateGasPrices({
216
216
  [FeeOption.Fastest]: { gasPrice },
217
217
  };
218
218
  } catch (error) {
219
- throw new Error(
220
- `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,
221
- );
219
+ throw new SwapKitError("toolbox_evm_gas_estimation_error", {
220
+ error: (error as any).msg ?? (error as any).toString(),
221
+ });
222
222
  }
223
223
  };
224
224
  }
@@ -231,7 +231,7 @@ export function getEstimateGasPrices({
231
231
  const price = gasPrice as bigint;
232
232
 
233
233
  if (!(maxFeePerGas && maxPriorityFeePerGas)) {
234
- throw new Error("No fee data available");
234
+ throw new SwapKitError("toolbox_evm_no_fee_data");
235
235
  }
236
236
 
237
237
  return {
@@ -255,9 +255,9 @@ export function getEstimateGasPrices({
255
255
  },
256
256
  };
257
257
  } catch (error) {
258
- throw new Error(
259
- `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,
260
- );
258
+ throw new SwapKitError("toolbox_evm_gas_estimation_error", {
259
+ error: (error as any).msg ?? (error as any).toString(),
260
+ });
261
261
  }
262
262
  };
263
263
  }
@@ -290,9 +290,9 @@ export function getEstimateGasPrices({
290
290
  [FeeOption.Fastest]: { gasPrice: gasPrice * 2n },
291
291
  };
292
292
  } catch (error) {
293
- throw new Error(
294
- `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,
295
- );
293
+ throw new SwapKitError("toolbox_evm_gas_estimation_error", {
294
+ error: (error as any).msg ?? (error as any).toString(),
295
+ });
296
296
  }
297
297
  };
298
298
  }
@@ -314,7 +314,10 @@ function getCall({ provider, isEIP1559Compatible, signer, chain }: ToolboxWrapPa
314
314
  feeOption = FeeOption.Fast,
315
315
  }: CallParams): Promise<T> {
316
316
  const contractProvider = callProvider || provider;
317
- if (!contractAddress) throw new Error("contractAddress must be provided");
317
+ if (!contractAddress)
318
+ throw new SwapKitError("toolbox_evm_invalid_params", {
319
+ error: "contractAddress must be provided",
320
+ });
318
321
 
319
322
  const isStateChanging = isStateChangingCall({ abi, funcName });
320
323
 
@@ -1,4 +1,4 @@
1
- import { Chain, type EVMChain } from "@swapkit/helpers";
1
+ import { Chain, type EVMChain, SwapKitError } from "@swapkit/helpers";
2
2
 
3
3
  import { getProvider } from "../helpers";
4
4
  import type { EVMToolboxParams } from "../types";
@@ -27,7 +27,7 @@ export async function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMTo
27
27
  case Chain.Ethereum:
28
28
  return ETHToolbox(toolboxParams);
29
29
  default:
30
- throw new Error(`Chain ${chain} is not supported`);
30
+ throw new SwapKitError("toolbox_evm_not_supported", { chain });
31
31
  }
32
32
  }
33
33
 
@@ -1,4 +1,11 @@
1
- import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, SKConfig } from "@swapkit/helpers";
1
+ import {
2
+ BaseDecimal,
3
+ Chain,
4
+ ChainId,
5
+ ChainToExplorerUrl,
6
+ SKConfig,
7
+ SwapKitError,
8
+ } from "@swapkit/helpers";
2
9
  import type {
3
10
  Authorization,
4
11
  BrowserProvider,
@@ -38,7 +45,8 @@ function serializeTx<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
38
45
  return async function serializeTx({ from, to, nonce, ...tx }: TransactionRequest) {
39
46
  const { Transaction } = await import("ethers");
40
47
 
41
- if (!to) throw new Error("Missing to address");
48
+ if (!to)
49
+ throw new SwapKitError("toolbox_evm_invalid_transaction", { error: "Missing to address" });
42
50
 
43
51
  return Transaction.from({
44
52
  ...tx,
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  FeeOption,
7
7
  type GenericCreateTransactionParams,
8
8
  type SubstrateChain,
9
+ SwapKitError,
9
10
  type UTXOChain,
10
11
  } from "@swapkit/helpers";
11
12
  import type { getCosmosToolbox } from "@swapkit/toolboxes/cosmos";
@@ -15,6 +16,7 @@ import type { RadixToolbox } from "@swapkit/toolboxes/radix";
15
16
  import type { getRippleToolbox } from "@swapkit/toolboxes/ripple";
16
17
  import type { SolanaCreateTransactionParams, getSolanaToolbox } from "@swapkit/toolboxes/solana";
17
18
  import type { getSubstrateToolbox } from "@swapkit/toolboxes/substrate";
19
+ import type { createTronToolbox } from "@swapkit/toolboxes/tron";
18
20
  import type { getUtxoToolbox } from "@swapkit/toolboxes/utxo";
19
21
 
20
22
  export async function getAddressValidator() {
@@ -26,9 +28,11 @@ export async function getAddressValidator() {
26
28
  const { getSolanaAddressValidator } = await import("@swapkit/toolboxes/solana");
27
29
  const { rippleValidateAddress } = await import("@swapkit/toolboxes/ripple");
28
30
  const { radixValidateAddress } = await import("@swapkit/toolboxes/radix");
31
+ const { getTronAddressValidator } = await import("@swapkit/toolboxes/tron");
29
32
 
30
33
  const solanaValidateAddress = await getSolanaAddressValidator();
31
34
  const utxoValidateAddress = await getUTXOAddressValidator();
35
+ const tronValidateAddress = await getTronAddressValidator();
32
36
 
33
37
  return function validateAddress({ address, chain }: { address: string; chain: Chain }) {
34
38
  const isValid = match(chain)
@@ -54,70 +58,58 @@ export async function getAddressValidator() {
54
58
  .with(Chain.Radix, () => radixValidateAddress(address))
55
59
  .with(Chain.Ripple, () => rippleValidateAddress(address))
56
60
  .with(Chain.Solana, () => solanaValidateAddress(address))
61
+ .with(Chain.Tron, () => tronValidateAddress(address))
57
62
  .otherwise(() => false);
58
63
 
59
64
  return isValid;
60
65
  };
61
66
  }
62
67
 
63
- export async function getFeeEstimator<T extends keyof CreateTransactionParams>(chain: T) {
64
- const toolbox = await getToolbox(chain);
65
-
68
+ export function getFeeEstimator<T extends keyof CreateTransactionParams>(chain: T) {
66
69
  return async function estimateFee(params: CreateTransactionParams[T]) {
67
- switch (chain) {
68
- case Chain.Arbitrum:
69
- case Chain.Avalanche:
70
- case Chain.Optimism:
71
- case Chain.BinanceSmartChain:
72
- case Chain.Base:
73
- case Chain.Polygon:
74
- case Chain.Ethereum: {
75
- const txObject = await (
76
- toolbox as Awaited<ReturnType<typeof ETHToolbox>>
77
- ).createTransaction(params as EVMCreateTransactionParams);
78
- return (toolbox as Awaited<ReturnType<typeof ETHToolbox>>).estimateTransactionFee({
79
- ...txObject,
80
- feeOption: params.feeOptionKey || FeeOption.Fast,
81
- chain,
82
- });
83
- }
84
- case Chain.Bitcoin:
85
- case Chain.BitcoinCash:
86
- case Chain.Dogecoin:
87
- case Chain.Dash:
88
- case Chain.Litecoin: {
89
- return (toolbox as Awaited<ReturnType<typeof getUtxoToolbox>>).estimateTransactionFee(
90
- params as CreateTransactionParams[Chain.Bitcoin],
91
- );
92
- }
70
+ const { match } = await import("ts-pattern");
93
71
 
94
- case Chain.THORChain:
95
- case Chain.Maya:
96
- case Chain.Kujira:
97
- case Chain.Cosmos: {
72
+ return match(chain as Chain)
73
+ .returnType<Promise<AssetValue>>()
74
+ .with(
75
+ Chain.Arbitrum,
76
+ Chain.Avalanche,
77
+ Chain.Optimism,
78
+ Chain.BinanceSmartChain,
79
+ Chain.Base,
80
+ Chain.Polygon,
81
+ Chain.Ethereum,
82
+ async (chain) => {
83
+ const toolbox = await getToolbox(chain);
84
+ const txObject = await toolbox.createTransaction(params);
85
+
86
+ return (toolbox as Awaited<ReturnType<typeof ETHToolbox>>).estimateTransactionFee({
87
+ ...txObject,
88
+ feeOption: params.feeOptionKey || FeeOption.Fast,
89
+ chain,
90
+ });
91
+ },
92
+ )
93
+ .with(
94
+ Chain.Bitcoin,
95
+ Chain.BitcoinCash,
96
+ Chain.Dogecoin,
97
+ Chain.Dash,
98
+ Chain.Litecoin,
99
+ Chain.Polkadot,
100
+ Chain.Solana,
101
+ Chain.Ripple,
102
+ Chain.Tron,
103
+ async (chain) => {
104
+ const toolbox = await getToolbox(chain);
105
+ return toolbox.estimateTransactionFee(params) as Promise<AssetValue>;
106
+ },
107
+ )
108
+ .with(Chain.THORChain, Chain.Maya, Chain.Kujira, Chain.Cosmos, async () => {
98
109
  const { estimateTransactionFee } = await import("@swapkit/toolboxes/cosmos");
99
110
  return estimateTransactionFee(params);
100
- }
101
-
102
- case Chain.Polkadot: {
103
- return (
104
- toolbox as Awaited<ReturnType<typeof getSubstrateToolbox<Chain.Polkadot>>>
105
- ).estimateTransactionFee(params);
106
- }
107
-
108
- case Chain.Solana: {
109
- return (toolbox as Awaited<ReturnType<typeof getSolanaToolbox>>).estimateTransactionFee(
110
- params as CreateTransactionParams[Chain.Solana],
111
- );
112
- }
113
-
114
- case Chain.Ripple: {
115
- return (toolbox as Awaited<ReturnType<typeof getRippleToolbox>>).estimateTransactionFee();
116
- }
117
-
118
- default:
119
- return AssetValue.from({ chain });
120
- }
111
+ })
112
+ .otherwise(async () => AssetValue.from({ chain }));
121
113
  };
122
114
  }
123
115
 
@@ -133,6 +125,7 @@ type Toolboxes = {
133
125
  [Chain.Radix]: Awaited<ReturnType<typeof RadixToolbox>>;
134
126
  [Chain.Ripple]: Awaited<ReturnType<typeof getRippleToolbox>>;
135
127
  [Chain.Solana]: Awaited<ReturnType<typeof getSolanaToolbox>>;
128
+ [Chain.Tron]: Awaited<ReturnType<typeof createTronToolbox>>;
136
129
  };
137
130
 
138
131
  type ToolboxParams = { [key in EVMChain]: Parameters<typeof getEvmToolbox>[1] } & {
@@ -145,6 +138,7 @@ type ToolboxParams = { [key in EVMChain]: Parameters<typeof getEvmToolbox>[1] }
145
138
  [Chain.Radix]: Parameters<typeof RadixToolbox>[0];
146
139
  [Chain.Ripple]: Parameters<typeof getRippleToolbox>[0];
147
140
  [Chain.Solana]: Parameters<typeof getSolanaToolbox>[0];
141
+ [Chain.Tron]: Parameters<typeof createTronToolbox>[0];
148
142
  };
149
143
 
150
144
  type CreateTransactionParams = { [key in EVMChain]: EVMCreateTransactionParams } & {
@@ -157,84 +151,90 @@ type CreateTransactionParams = { [key in EVMChain]: EVMCreateTransactionParams }
157
151
  [Chain.Radix]: GenericCreateTransactionParams;
158
152
  [Chain.Ripple]: GenericCreateTransactionParams;
159
153
  [Chain.Solana]: SolanaCreateTransactionParams;
154
+ [Chain.Tron]: GenericCreateTransactionParams;
160
155
  };
161
156
 
162
157
  export async function getToolbox<T extends keyof Toolboxes>(
163
158
  chain: T,
164
159
  params?: ToolboxParams[T],
165
160
  ): Promise<Toolboxes[T]> {
166
- switch (chain) {
167
- case Chain.Arbitrum:
168
- case Chain.Avalanche:
169
- case Chain.Optimism:
170
- case Chain.BinanceSmartChain:
171
- case Chain.Base:
172
- case Chain.Polygon:
173
- case Chain.Ethereum: {
174
- const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
175
- const evmToolbox = await getEvmToolbox(chain, params as Parameters<typeof getEvmToolbox>[1]);
176
- return evmToolbox as Toolboxes[T];
177
- }
178
-
179
- case Chain.Litecoin:
180
- case Chain.Dash:
181
- case Chain.Dogecoin:
182
- case Chain.BitcoinCash:
183
- case Chain.Bitcoin: {
184
- const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
185
- const utxoToolbox = await getUtxoToolbox(
186
- chain,
187
- params as Parameters<typeof getUtxoToolbox>[1],
188
- );
189
- return utxoToolbox as Toolboxes[T];
190
- }
161
+ const { match } = await import("ts-pattern");
191
162
 
192
- case Chain.Cosmos:
193
- case Chain.Kujira:
194
- case Chain.Maya:
195
- case Chain.THORChain: {
163
+ return match(chain as Chain)
164
+ .returnType<Promise<Toolboxes[T]>>()
165
+ .with(
166
+ Chain.Arbitrum,
167
+ Chain.Avalanche,
168
+ Chain.Optimism,
169
+ Chain.BinanceSmartChain,
170
+ Chain.Base,
171
+ Chain.Polygon,
172
+ Chain.Ethereum,
173
+ async () => {
174
+ const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
175
+ const evmToolbox = await getEvmToolbox(
176
+ chain as EVMChain,
177
+ params as Parameters<typeof getEvmToolbox>[1],
178
+ );
179
+ return evmToolbox as Toolboxes[T];
180
+ },
181
+ )
182
+ .with(
183
+ Chain.Litecoin,
184
+ Chain.Dash,
185
+ Chain.Dogecoin,
186
+ Chain.BitcoinCash,
187
+ Chain.Bitcoin,
188
+ async () => {
189
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
190
+ const utxoToolbox = await getUtxoToolbox(
191
+ chain as UTXOChain,
192
+ params as Parameters<typeof getUtxoToolbox>[1],
193
+ );
194
+ return utxoToolbox as Toolboxes[T];
195
+ },
196
+ )
197
+ .with(Chain.Cosmos, Chain.Kujira, Chain.Maya, Chain.THORChain, async () => {
196
198
  const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
197
199
  const cosmosToolbox = await getCosmosToolbox(
198
- chain,
200
+ chain as CosmosChain,
199
201
  params as Parameters<typeof getCosmosToolbox>[1],
200
202
  );
201
-
202
203
  return cosmosToolbox as Toolboxes[T];
203
- }
204
-
205
- case Chain.Chainflip:
206
- case Chain.Polkadot: {
204
+ })
205
+ .with(Chain.Chainflip, Chain.Polkadot, async () => {
207
206
  const { getSubstrateToolbox } = await import("@swapkit/toolboxes/substrate");
208
207
  const substrateToolbox = await getSubstrateToolbox(
209
- chain,
208
+ chain as SubstrateChain,
210
209
  params as Parameters<typeof getSubstrateToolbox>[1],
211
210
  );
212
211
  return substrateToolbox as Toolboxes[T];
213
- }
214
-
215
- case Chain.Radix: {
212
+ })
213
+ .with(Chain.Radix, async () => {
216
214
  const { RadixToolbox } = await import("@swapkit/toolboxes/radix");
217
215
  const radixToolbox = await RadixToolbox(params as Parameters<typeof RadixToolbox>[0]);
218
216
  return radixToolbox as Toolboxes[T];
219
- }
220
-
221
- case Chain.Ripple: {
217
+ })
218
+ .with(Chain.Ripple, async () => {
222
219
  const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
223
220
  const rippleToolbox = await getRippleToolbox(
224
221
  params as Parameters<typeof getRippleToolbox>[0],
225
222
  );
226
223
  return rippleToolbox as Toolboxes[T];
227
- }
228
-
229
- case Chain.Solana: {
224
+ })
225
+ .with(Chain.Solana, async () => {
230
226
  const { getSolanaToolbox } = await import("@swapkit/toolboxes/solana");
231
227
  const solanaToolbox = await getSolanaToolbox(
232
228
  params as Parameters<typeof getSolanaToolbox>[0],
233
229
  );
234
230
  return solanaToolbox as Toolboxes[T];
235
- }
236
-
237
- default:
238
- throw new Error(`Chain ${chain} is not supported`);
239
- }
231
+ })
232
+ .with(Chain.Tron, async () => {
233
+ const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
234
+ const tronToolbox = await createTronToolbox(params);
235
+ return tronToolbox as Toolboxes[T];
236
+ })
237
+ .otherwise(() => {
238
+ throw new SwapKitError("toolbox_not_supported", { chain });
239
+ });
240
240
  }
@@ -5,7 +5,13 @@ import type {
5
5
  StateEntityFungiblesPageRequest,
6
6
  StateEntityFungiblesPageResponse,
7
7
  } from "@radixdlt/babylon-gateway-api-sdk";
8
- import { AssetValue, Chain, SKConfig, type SKConfigIntegrations } from "@swapkit/helpers";
8
+ import {
9
+ AssetValue,
10
+ Chain,
11
+ SKConfig,
12
+ type SKConfigIntegrations,
13
+ SwapKitError,
14
+ } from "@swapkit/helpers";
9
15
 
10
16
  export type RadixWallet = Awaited<ReturnType<typeof RadixToolbox>>;
11
17
 
@@ -144,7 +150,7 @@ export const RadixToolbox = async ({
144
150
  networkApi,
145
151
  validateAddress: radixValidateAddress,
146
152
  signAndBroadcast: (() => {
147
- throw new Error("Not implemented");
153
+ throw new SwapKitError("toolbox_radix_method_not_supported", { method: "signAndBroadcast" });
148
154
  }) as (params: any) => Promise<string>,
149
155
  };
150
156
  };
@@ -53,7 +53,7 @@ export function getSubstrateToolbox<T extends SubstrateChain>(chain: T, params?:
53
53
  return PolkadotToolbox(params);
54
54
  }
55
55
  default:
56
- throw new Error(`Chain ${chain} is not supported`);
56
+ throw new SwapKitError("toolbox_substrate_not_supported", { chain });
57
57
  }
58
58
  }
59
59
 
@@ -0,0 +1,40 @@
1
+ export const trc20ABI = [
2
+ {
3
+ constant: true,
4
+ inputs: [{ name: "_owner", type: "address" }],
5
+ name: "balanceOf",
6
+ outputs: [{ name: "balance", type: "uint256" }],
7
+ type: "function",
8
+ },
9
+ {
10
+ constant: false,
11
+ inputs: [
12
+ { name: "_to", type: "address" },
13
+ { name: "_value", type: "uint256" },
14
+ ],
15
+ name: "transfer",
16
+ outputs: [{ name: "success", type: "bool" }],
17
+ type: "function",
18
+ },
19
+ {
20
+ constant: true,
21
+ inputs: [],
22
+ name: "decimals",
23
+ outputs: [{ name: "", type: "uint8" }],
24
+ type: "function",
25
+ },
26
+ {
27
+ constant: true,
28
+ inputs: [],
29
+ name: "symbol",
30
+ outputs: [{ name: "", type: "string" }],
31
+ type: "function",
32
+ },
33
+ {
34
+ constant: true,
35
+ inputs: [],
36
+ name: "name",
37
+ outputs: [{ name: "", type: "string" }],
38
+ type: "function",
39
+ },
40
+ ] as const;
@@ -0,0 +1,16 @@
1
+ export {
2
+ createTronToolbox,
3
+ getTronAddressValidator,
4
+ getTronPrivateKeyFromMnemonic,
5
+ } from "./toolbox";
6
+ export type {
7
+ TronSigner,
8
+ TronToolboxOptions,
9
+ TronTransferParams,
10
+ TronContract,
11
+ TronTransaction,
12
+ } from "./types";
13
+ export { trc20ABI } from "./helpers/trc20.abi";
14
+
15
+ import type { createTronToolbox } from "./toolbox.js";
16
+ export type TronWallet = Awaited<ReturnType<typeof createTronToolbox>>;