@uswap/toolboxes 4.3.6 → 4.3.9

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 (149) hide show
  1. package/dist/src/cardano/index.cjs +2 -2
  2. package/dist/src/cardano/index.cjs.map +3 -3
  3. package/dist/src/cardano/index.js +2 -2
  4. package/dist/src/cardano/index.js.map +3 -3
  5. package/dist/src/cosmos/index.cjs +2 -2
  6. package/dist/src/cosmos/index.cjs.map +8 -8
  7. package/dist/src/cosmos/index.js +2 -2
  8. package/dist/src/cosmos/index.js.map +8 -8
  9. package/dist/src/evm/index.cjs +2 -2
  10. package/dist/src/evm/index.cjs.map +7 -7
  11. package/dist/src/evm/index.js +2 -2
  12. package/dist/src/evm/index.js.map +7 -7
  13. package/dist/src/index.cjs +3 -3
  14. package/dist/src/index.cjs.map +34 -34
  15. package/dist/src/index.js +3 -3
  16. package/dist/src/index.js.map +34 -34
  17. package/dist/src/near/index.cjs +2 -2
  18. package/dist/src/near/index.cjs.map +5 -5
  19. package/dist/src/near/index.js +2 -2
  20. package/dist/src/near/index.js.map +5 -5
  21. package/dist/src/radix/index.cjs +2 -2
  22. package/dist/src/radix/index.cjs.map +3 -3
  23. package/dist/src/radix/index.js +2 -2
  24. package/dist/src/radix/index.js.map +3 -3
  25. package/dist/src/ripple/index.cjs +2 -2
  26. package/dist/src/ripple/index.cjs.map +3 -3
  27. package/dist/src/ripple/index.js +2 -2
  28. package/dist/src/ripple/index.js.map +3 -3
  29. package/dist/src/solana/index.cjs +2 -2
  30. package/dist/src/solana/index.cjs.map +3 -3
  31. package/dist/src/solana/index.js +2 -2
  32. package/dist/src/solana/index.js.map +3 -3
  33. package/dist/src/substrate/index.cjs +2 -2
  34. package/dist/src/substrate/index.cjs.map +4 -4
  35. package/dist/src/substrate/index.js +2 -2
  36. package/dist/src/substrate/index.js.map +4 -4
  37. package/dist/src/sui/index.cjs +2 -2
  38. package/dist/src/sui/index.cjs.map +3 -3
  39. package/dist/src/sui/index.js +2 -2
  40. package/dist/src/sui/index.js.map +3 -3
  41. package/dist/src/ton/index.cjs +2 -2
  42. package/dist/src/ton/index.cjs.map +3 -3
  43. package/dist/src/ton/index.js +2 -2
  44. package/dist/src/ton/index.js.map +3 -3
  45. package/dist/src/tron/index.cjs +2 -2
  46. package/dist/src/tron/index.cjs.map +4 -4
  47. package/dist/src/tron/index.js +2 -2
  48. package/dist/src/tron/index.js.map +4 -4
  49. package/dist/src/utxo/index.cjs +3 -3
  50. package/dist/src/utxo/index.cjs.map +11 -11
  51. package/dist/src/utxo/index.js +3 -3
  52. package/dist/src/utxo/index.js.map +11 -11
  53. package/dist/types/cardano/toolbox.d.ts +5 -0
  54. package/dist/types/cardano/toolbox.d.ts.map +1 -1
  55. package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +5 -0
  56. package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -1
  57. package/dist/types/cosmos/thorchainUtils/messages.d.ts +5 -0
  58. package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -1
  59. package/dist/types/cosmos/toolbox/cosmos.d.ts +5 -0
  60. package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -1
  61. package/dist/types/cosmos/toolbox/index.d.ts +5 -0
  62. package/dist/types/cosmos/toolbox/index.d.ts.map +1 -1
  63. package/dist/types/cosmos/toolbox/thorchain.d.ts +5 -0
  64. package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -1
  65. package/dist/types/cosmos/util.d.ts +5 -0
  66. package/dist/types/cosmos/util.d.ts.map +1 -1
  67. package/dist/types/evm/helpers.d.ts +1 -1
  68. package/dist/types/evm/helpers.d.ts.map +1 -1
  69. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +7 -0
  70. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -1
  71. package/dist/types/evm/toolbox/evm.d.ts +38 -38
  72. package/dist/types/evm/toolbox/evm.d.ts.map +1 -1
  73. package/dist/types/evm/toolbox/op.d.ts +7 -14
  74. package/dist/types/evm/toolbox/op.d.ts.map +1 -1
  75. package/dist/types/index.d.ts +5 -0
  76. package/dist/types/index.d.ts.map +1 -1
  77. package/dist/types/near/helpers/core.d.ts +5 -0
  78. package/dist/types/near/helpers/core.d.ts.map +1 -1
  79. package/dist/types/near/toolbox.d.ts +5 -0
  80. package/dist/types/near/toolbox.d.ts.map +1 -1
  81. package/dist/types/radix/index.d.ts +5 -0
  82. package/dist/types/radix/index.d.ts.map +1 -1
  83. package/dist/types/ripple/index.d.ts +5 -0
  84. package/dist/types/ripple/index.d.ts.map +1 -1
  85. package/dist/types/solana/toolbox.d.ts +5 -0
  86. package/dist/types/solana/toolbox.d.ts.map +1 -1
  87. package/dist/types/substrate/substrate.d.ts +5 -0
  88. package/dist/types/substrate/substrate.d.ts.map +1 -1
  89. package/dist/types/sui/toolbox.d.ts +5 -0
  90. package/dist/types/sui/toolbox.d.ts.map +1 -1
  91. package/dist/types/ton/toolbox.d.ts +5 -0
  92. package/dist/types/ton/toolbox.d.ts.map +1 -1
  93. package/dist/types/tron/helpers/trongrid.d.ts +5 -0
  94. package/dist/types/tron/helpers/trongrid.d.ts.map +1 -1
  95. package/dist/types/tron/toolbox.d.ts +5 -0
  96. package/dist/types/tron/toolbox.d.ts.map +1 -1
  97. package/dist/types/utils.d.ts.map +1 -1
  98. package/dist/types/utxo/helpers/api.d.ts +5 -0
  99. package/dist/types/utxo/helpers/api.d.ts.map +1 -1
  100. package/dist/types/utxo/helpers/bchaddrjs.d.ts +5 -0
  101. package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -1
  102. package/dist/types/utxo/helpers/coinselect.d.ts +5 -0
  103. package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -1
  104. package/dist/types/utxo/helpers/txSize.d.ts +5 -0
  105. package/dist/types/utxo/helpers/txSize.d.ts.map +1 -1
  106. package/dist/types/utxo/toolbox/bitcoinCash.d.ts +5 -0
  107. package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -1
  108. package/dist/types/utxo/toolbox/index.d.ts +5 -0
  109. package/dist/types/utxo/toolbox/index.d.ts.map +1 -1
  110. package/dist/types/utxo/toolbox/utxo.d.ts +5 -0
  111. package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -1
  112. package/dist/types/utxo/toolbox/zcash.d.ts +6 -1
  113. package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -1
  114. package/package.json +4 -4
  115. package/src/cardano/toolbox.ts +12 -6
  116. package/src/cosmos/__tests__/toolbox.test.ts +8 -4
  117. package/src/cosmos/thorchainUtils/addressFormat.ts +8 -2
  118. package/src/cosmos/thorchainUtils/messages.ts +8 -2
  119. package/src/cosmos/toolbox/cosmos.ts +11 -5
  120. package/src/cosmos/toolbox/index.ts +8 -2
  121. package/src/cosmos/toolbox/thorchain.ts +9 -3
  122. package/src/cosmos/util.ts +9 -3
  123. package/src/evm/helpers.ts +7 -9
  124. package/src/evm/toolbox/baseEVMToolbox.ts +34 -26
  125. package/src/evm/toolbox/evm.ts +2 -3
  126. package/src/evm/toolbox/op.ts +10 -17
  127. package/src/index.ts +8 -2
  128. package/src/near/helpers/core.ts +8 -2
  129. package/src/near/toolbox.ts +21 -15
  130. package/src/radix/index.ts +15 -3
  131. package/src/ripple/index.ts +15 -12
  132. package/src/solana/toolbox.ts +16 -16
  133. package/src/substrate/balance.ts +2 -2
  134. package/src/substrate/substrate.ts +17 -11
  135. package/src/sui/__tests__/toolbox.test.ts +9 -5
  136. package/src/sui/toolbox.ts +18 -11
  137. package/src/ton/__tests__/toolbox.test.ts +9 -5
  138. package/src/ton/toolbox.ts +14 -8
  139. package/src/tron/helpers/trongrid.ts +8 -2
  140. package/src/tron/toolbox.ts +21 -15
  141. package/src/utils.ts +8 -1
  142. package/src/utxo/helpers/api.ts +15 -9
  143. package/src/utxo/helpers/bchaddrjs.ts +9 -3
  144. package/src/utxo/helpers/coinselect.ts +8 -2
  145. package/src/utxo/helpers/txSize.ts +8 -2
  146. package/src/utxo/toolbox/bitcoinCash.ts +13 -7
  147. package/src/utxo/toolbox/index.ts +8 -2
  148. package/src/utxo/toolbox/utxo.ts +16 -10
  149. package/src/utxo/toolbox/zcash.ts +24 -21
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import {
2
8
  type Asset,
3
9
  AssetValue,
@@ -8,8 +14,8 @@ import {
8
14
  EVMChains,
9
15
  FeeOption,
10
16
  isGasAsset,
11
- SwapKitError,
12
17
  SwapKitNumber,
18
+ USwapError,
13
19
  } from "@uswap/helpers";
14
20
  import { erc20ABI } from "@uswap/helpers/contracts";
15
21
  import {
@@ -26,7 +32,8 @@ import {
26
32
  type Signer,
27
33
  } from "ethers";
28
34
  import { match } from "ts-pattern";
29
- import { toHexString } from "../helpers";
35
+ import { getEvmApi } from "../api";
36
+ import { getNetworkParams, toHexString } from "../helpers";
30
37
  import type {
31
38
  ApproveParams,
32
39
  CallParams,
@@ -80,6 +87,8 @@ export function BaseEVMToolbox<
80
87
  getAddress: () => {
81
88
  return signer ? signer.getAddress() : undefined;
82
89
  },
90
+ getBalance: getEvmApi(chain).getBalance,
91
+ getNetworkParams: getNetworkParams(chain),
83
92
  isApproved: getIsApproved({ chain, provider }),
84
93
  sendTransaction: getSendTransaction({ chain, isEIP1559Compatible, provider, signer }),
85
94
  signMessage: signer ? (message: string | Uint8Array) => signer.signMessage(message) : undefined,
@@ -115,7 +124,7 @@ const stateMutable = ["payable", "nonpayable"];
115
124
  // const nonStateMutable = ['view', 'pure'];
116
125
  export function isStateChangingCall({ abi, funcName }: { abi: readonly JsonFragment[]; funcName: string }) {
117
126
  const abiFragment = abi.find((fragment: any) => fragment.name === funcName) as any;
118
- if (!abiFragment) throw new SwapKitError("toolbox_evm_no_abi_fragment", { funcName });
127
+ if (!abiFragment) throw new USwapError("toolbox_evm_no_abi_fragment", { funcName });
119
128
  return abiFragment.stateMutability && stateMutable.includes(abiFragment.stateMutability);
120
129
  }
121
130
 
@@ -126,7 +135,7 @@ export function toChecksumAddress(address: string) {
126
135
  export function getEIP1193SendTransaction(provider: Provider | BrowserProvider) {
127
136
  return function EIP1193SendTransaction({ value, ...params }: EVMTxParams | ContractTransaction): Promise<string> {
128
137
  if (!isBrowserProvider(provider)) {
129
- throw new SwapKitError("toolbox_evm_provider_not_eip1193_compatible");
138
+ throw new USwapError("toolbox_evm_provider_not_eip1193_compatible");
130
139
  }
131
140
 
132
141
  // Remove gas-related parameters to let the wallet estimate them
@@ -152,7 +161,7 @@ export function getChecksumAddressFromAsset(asset: Asset, chain: EVMChain) {
152
161
  return getAddress(assetAddress.toLowerCase());
153
162
  }
154
163
 
155
- throw new SwapKitError("toolbox_evm_invalid_gas_asset_address");
164
+ throw new USwapError("toolbox_evm_invalid_gas_asset_address");
156
165
  }
157
166
 
158
167
  const baseContractAddresses = EVMChains.reduce(
@@ -211,7 +220,7 @@ export function getEstimateGasPrices({
211
220
  return async function estimateGasPrices() {
212
221
  try {
213
222
  const { gasPrice, maxPriorityFeePerGas } = await provider.getFeeData();
214
- if (!gasPrice || maxPriorityFeePerGas === null) throw new SwapKitError("toolbox_evm_no_fee_data");
223
+ if (!gasPrice || maxPriorityFeePerGas === null) throw new USwapError("toolbox_evm_no_fee_data");
215
224
 
216
225
  return {
217
226
  [FeeOption.Average]: {
@@ -228,7 +237,7 @@ export function getEstimateGasPrices({
228
237
  },
229
238
  };
230
239
  } catch (error) {
231
- throw new SwapKitError("toolbox_evm_gas_estimation_error", {
240
+ throw new USwapError("toolbox_evm_gas_estimation_error", {
232
241
  error: (error as any).msg ?? (error as any).toString(),
233
242
  });
234
243
  }
@@ -238,7 +247,7 @@ export function getEstimateGasPrices({
238
247
  return async function estimateGasPrices() {
239
248
  try {
240
249
  const { gasPrice } = await provider.getFeeData();
241
- if (!gasPrice) throw new SwapKitError("toolbox_evm_no_fee_data");
250
+ if (!gasPrice) throw new USwapError("toolbox_evm_no_fee_data");
242
251
 
243
252
  return {
244
253
  [FeeOption.Average]: { gasPrice },
@@ -246,7 +255,7 @@ export function getEstimateGasPrices({
246
255
  [FeeOption.Fastest]: { gasPrice },
247
256
  };
248
257
  } catch (error) {
249
- throw new SwapKitError("toolbox_evm_gas_estimation_error", {
258
+ throw new USwapError("toolbox_evm_gas_estimation_error", {
250
259
  error: (error as any).msg ?? (error as any).toString(),
251
260
  });
252
261
  }
@@ -258,8 +267,7 @@ export function getEstimateGasPrices({
258
267
  const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();
259
268
 
260
269
  if (isEIP1559Compatible) {
261
- if (maxFeePerGas === null || maxPriorityFeePerGas === null)
262
- throw new SwapKitError("toolbox_evm_no_fee_data");
270
+ if (maxFeePerGas === null || maxPriorityFeePerGas === null) throw new USwapError("toolbox_evm_no_fee_data");
263
271
 
264
272
  return {
265
273
  [FeeOption.Average]: { maxFeePerGas, maxPriorityFeePerGas },
@@ -273,7 +281,7 @@ export function getEstimateGasPrices({
273
281
  },
274
282
  };
275
283
  }
276
- if (!gasPrice) throw new SwapKitError("toolbox_evm_no_gas_price");
284
+ if (!gasPrice) throw new USwapError("toolbox_evm_no_gas_price");
277
285
 
278
286
  return {
279
287
  [FeeOption.Average]: { gasPrice },
@@ -281,7 +289,7 @@ export function getEstimateGasPrices({
281
289
  [FeeOption.Fastest]: { gasPrice: applyFeeMultiplierToBigInt(gasPrice, FeeOption.Fastest) },
282
290
  };
283
291
  } catch (error) {
284
- throw new SwapKitError("toolbox_evm_gas_estimation_error", {
292
+ throw new USwapError("toolbox_evm_gas_estimation_error", {
285
293
  error: (error as any).msg ?? (error as any).toString(),
286
294
  });
287
295
  }
@@ -306,7 +314,7 @@ function getCall({ provider, isEIP1559Compatible, signer, chain }: ToolboxWrapPa
306
314
  }: CallParams): Promise<T> {
307
315
  const contractProvider = callProvider || provider;
308
316
  if (!contractAddress)
309
- throw new SwapKitError("toolbox_evm_invalid_params", { error: "contractAddress must be provided" });
317
+ throw new USwapError("toolbox_evm_invalid_params", { error: "contractAddress must be provided" });
310
318
 
311
319
  const isStateChanging = isStateChangingCall({ abi, funcName });
312
320
 
@@ -328,10 +336,10 @@ function getCall({ provider, isEIP1559Compatible, signer, chain }: ToolboxWrapPa
328
336
 
329
337
  // only use signer if the contract function is state changing
330
338
  if (isStateChanging) {
331
- if (!signer) throw new SwapKitError("toolbox_evm_no_signer");
339
+ if (!signer) throw new USwapError("toolbox_evm_no_signer");
332
340
 
333
341
  const from = txOverrides?.from || (await signer.getAddress());
334
- if (!from) throw new SwapKitError("toolbox_evm_no_signer_address");
342
+ if (!from) throw new USwapError("toolbox_evm_no_signer_address");
335
343
 
336
344
  const connectedContract = contract.connect(signer);
337
345
  const estimateGasPrices = getEstimateGasPrices({ chain, isEIP1559Compatible, provider });
@@ -444,7 +452,7 @@ function getTransfer({ signer, isEIP1559Compatible = true, provider }: ToolboxWr
444
452
  const from = sender || (await signer?.getAddress());
445
453
  const sendTx = getSendTransaction({ chain, isEIP1559Compatible, provider, signer });
446
454
 
447
- if (!from) throw new SwapKitError("toolbox_evm_no_from_address");
455
+ if (!from) throw new USwapError("toolbox_evm_no_from_address");
448
456
 
449
457
  if (assetValue.isGasAsset) {
450
458
  const transaction = {
@@ -461,7 +469,7 @@ function getTransfer({ signer, isEIP1559Compatible = true, provider }: ToolboxWr
461
469
 
462
470
  // const call = getCall({ signer, provider, isEIP1559Compatible });
463
471
  const contractAddress = getTokenAddress(assetValue, chain);
464
- if (!contractAddress) throw new SwapKitError("toolbox_evm_no_contract_address");
472
+ if (!contractAddress) throw new USwapError("toolbox_evm_no_contract_address");
465
473
 
466
474
  const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = (
467
475
  await getEstimateGasPrices({ chain, isEIP1559Compatible, provider })()
@@ -484,7 +492,7 @@ function getTransfer({ signer, isEIP1559Compatible = true, provider }: ToolboxWr
484
492
 
485
493
  function getEstimateCall({ provider, signer }: { signer?: Signer; provider: Provider }) {
486
494
  return function estimateCall({ contractAddress, abi, funcName, funcParams = [], txOverrides }: EstimateCallParams) {
487
- if (!contractAddress) throw new SwapKitError("toolbox_evm_no_contract_address");
495
+ if (!contractAddress) throw new USwapError("toolbox_evm_no_contract_address");
488
496
 
489
497
  const contract = createContract(contractAddress, abi, provider);
490
498
  return signer
@@ -547,8 +555,8 @@ function getSendTransaction({ provider, signer, isEIP1559Compatible = true, chai
547
555
  }: EVMTxParams & { feeOptionKey?: FeeOption }) {
548
556
  const { from, to, data, value, ...transaction } = tx;
549
557
 
550
- if (!signer) throw new SwapKitError("toolbox_evm_no_signer");
551
- if (!to) throw new SwapKitError("toolbox_evm_no_to_address");
558
+ if (!signer) throw new USwapError("toolbox_evm_no_signer");
559
+ if (!to) throw new USwapError("toolbox_evm_no_to_address");
552
560
 
553
561
  const parsedTxObject = { ...transaction, data: data || "0x", from, to, value: BigInt(value || 0) };
554
562
 
@@ -581,7 +589,7 @@ function getSendTransaction({ provider, signer, isEIP1559Compatible = true, chai
581
589
  try {
582
590
  gasLimit = toHexString(parsedTxObject.gasLimit || ((await provider.estimateGas(parsedTxObject)) * 11n) / 10n);
583
591
  } catch (error) {
584
- throw new SwapKitError("toolbox_evm_error_estimating_gas_limit", { error });
592
+ throw new USwapError("toolbox_evm_error_estimating_gas_limit", { error });
585
593
  }
586
594
 
587
595
  try {
@@ -596,7 +604,7 @@ function getSendTransaction({ provider, signer, isEIP1559Compatible = true, chai
596
604
  return response.hash;
597
605
  }
598
606
  } catch (error) {
599
- throw new SwapKitError("toolbox_evm_error_sending_transaction", { error });
607
+ throw new USwapError("toolbox_evm_error_sending_transaction", { error });
600
608
  }
601
609
  };
602
610
  }
@@ -617,7 +625,7 @@ function getCreateTransferTx({ provider, signer }: ToolboxWrapParams) {
617
625
  const chain = assetValue.chain as EVMChain;
618
626
  const from = fromOverride || (await signer?.getAddress());
619
627
 
620
- if (!from) throw new SwapKitError("toolbox_evm_no_from_address");
628
+ if (!from) throw new USwapError("toolbox_evm_no_from_address");
621
629
 
622
630
  if (isGasAsset(assetValue)) {
623
631
  const { hexlify, toUtf8Bytes } = await import("ethers");
@@ -626,7 +634,7 @@ function getCreateTransferTx({ provider, signer }: ToolboxWrapParams) {
626
634
  }
627
635
 
628
636
  const contractAddress = getTokenAddress(assetValue, chain);
629
- if (!contractAddress) throw new SwapKitError("toolbox_evm_no_contract_address");
637
+ if (!contractAddress) throw new USwapError("toolbox_evm_no_contract_address");
630
638
  const createTx = getCreateContractTxObject({ chain: assetValue.chain as EVMChain, provider });
631
639
 
632
640
  return createTx({
@@ -690,6 +698,6 @@ function getEstimateTransactionFee({
690
698
  return assetValue.set(SwapKitNumber.fromBigInt(fee, assetValue.decimal));
691
699
  }
692
700
 
693
- throw new SwapKitError("toolbox_evm_no_gas_price");
701
+ throw new USwapError("toolbox_evm_no_gas_price");
694
702
  };
695
703
  }
@@ -1,9 +1,8 @@
1
1
  import { Chain, type EVMChain, FeeOption, getRPCUrl } from "@uswap/helpers";
2
2
  import { match, P } from "ts-pattern";
3
3
 
4
- import { getEvmApi } from "../api";
5
4
  import { multicallAbi } from "../contracts/eth/multicall";
6
- import { getIsEIP1559Compatible, getNetworkParams, getProvider } from "../helpers";
5
+ import { getIsEIP1559Compatible, getProvider } from "../helpers";
7
6
  import type { EVMToolboxParams } from "../types";
8
7
  import { BaseEVMToolbox } from "./baseEVMToolbox";
9
8
 
@@ -62,6 +61,6 @@ function createEvmToolbox<C extends EVMChain>(chain: C) {
62
61
 
63
62
  const evmToolbox = BaseEVMToolbox({ chain, isEIP1559Compatible, provider, signer });
64
63
 
65
- return { ...evmToolbox, getBalance: getEvmApi(chain).getBalance, getNetworkParams: getNetworkParams(chain) };
64
+ return evmToolbox;
66
65
  };
67
66
  }
@@ -1,4 +1,10 @@
1
- import { applyFeeMultiplierToBigInt, Chain, FeeOption, getChainConfig, getRPCUrl, SwapKitError } from "@uswap/helpers";
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
7
+ import { applyFeeMultiplierToBigInt, Chain, FeeOption, getRPCUrl, USwapError } from "@uswap/helpers";
2
8
  import type { Authorization, BrowserProvider, JsonRpcProvider, Provider, TransactionRequest } from "ethers";
3
9
  import { Contract, HDNodeWallet } from "ethers";
4
10
  import { match, P } from "ts-pattern";
@@ -30,7 +36,7 @@ function serializeTx<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
30
36
  return async function serializeTx({ from, to, nonce, ...tx }: TransactionRequest) {
31
37
  const { Transaction } = await import("ethers");
32
38
 
33
- if (!to) throw new SwapKitError("toolbox_evm_invalid_transaction", { error: "Missing to address" });
39
+ if (!to) throw new USwapError("toolbox_evm_invalid_transaction", { error: "Missing to address" });
34
40
 
35
41
  return Transaction.from({
36
42
  ...tx,
@@ -79,18 +85,6 @@ function estimateL1Gas<P extends JsonRpcProvider | BrowserProvider>(provider: P)
79
85
  };
80
86
  }
81
87
 
82
- function getNetworkParams() {
83
- const { baseDecimal, chainId, explorerUrl, name, rpcUrls } = getChainConfig(Chain.Optimism);
84
-
85
- return {
86
- blockExplorerUrls: [explorerUrl],
87
- chainId,
88
- chainName: name,
89
- nativeCurrency: { decimals: baseDecimal, name: "Ethereum", symbol: Chain.Ethereum },
90
- rpcUrls,
91
- };
92
- }
93
-
94
88
  async function estimateGasPrices(provider: Provider) {
95
89
  try {
96
90
  const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();
@@ -98,7 +92,7 @@ async function estimateGasPrices(provider: Provider) {
98
92
  const price = gasPrice as bigint;
99
93
 
100
94
  if (!(maxFeePerGas && maxPriorityFeePerGas)) {
101
- throw new SwapKitError("toolbox_evm_no_fee_data");
95
+ throw new USwapError("toolbox_evm_no_fee_data");
102
96
  }
103
97
 
104
98
  return {
@@ -124,7 +118,7 @@ async function estimateGasPrices(provider: Provider) {
124
118
  };
125
119
  };
126
120
  } catch (error) {
127
- throw new SwapKitError("toolbox_evm_gas_estimation_error", {
121
+ throw new USwapError("toolbox_evm_gas_estimation_error", {
128
122
  error: (error as any).msg ?? (error as any).toString(),
129
123
  });
130
124
  }
@@ -151,6 +145,5 @@ export async function OPToolbox({ provider: providerParam, ...toolboxSignerParam
151
145
  estimateTotalGasCost: estimateTotalGasCost(provider),
152
146
  getBalance: getEvmApi(Chain.Optimism).getBalance,
153
147
  getL1GasPrice,
154
- getNetworkParams,
155
148
  };
156
149
  }
package/src/index.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import {
2
8
  AssetValue,
3
9
  Chain,
@@ -9,7 +15,7 @@ import {
9
15
  type GenericCreateTransactionParams,
10
16
  type SubstrateChain,
11
17
  SubstrateChains,
12
- SwapKitError,
18
+ USwapError,
13
19
  type UTXOChain,
14
20
  UTXOChains,
15
21
  } from "@uswap/helpers";
@@ -255,6 +261,6 @@ export async function getToolbox<T extends keyof Toolboxes>(
255
261
  return tonToolbox as Toolboxes[T];
256
262
  })
257
263
  .otherwise(() => {
258
- throw new SwapKitError("toolbox_not_supported", { chain });
264
+ throw new USwapError("toolbox_not_supported", { chain });
259
265
  });
260
266
  }
@@ -1,7 +1,13 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import type { KeyPair } from "@near-js/crypto";
2
8
  import type { Provider } from "@near-js/providers";
3
9
  import { KeyPairSigner } from "@near-js/signers";
4
- import { type DerivationPathArray, derivationPathToString, SwapKitError } from "@uswap/helpers";
10
+ import { type DerivationPathArray, derivationPathToString, USwapError } from "@uswap/helpers";
5
11
  import type { NearSigner } from "../types";
6
12
 
7
13
  export async function getValidateNearAddress() {
@@ -74,7 +80,7 @@ export async function getFullAccessPublicKey(provider: Provider, accountId: stri
74
80
  const fullAccessKey = (response as any).keys.find((key: any) => key.access_key.permission === "FullAccess");
75
81
 
76
82
  if (!fullAccessKey) {
77
- throw new SwapKitError("toolbox_near_no_public_key_found");
83
+ throw new USwapError("toolbox_near_no_public_key_found");
78
84
  }
79
85
  const { PublicKey } = await import("@near-js/crypto");
80
86
 
@@ -1,6 +1,12 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import type { Account, Contract } from "@near-js/accounts";
2
8
  import type { SignedTransaction, Transaction } from "@near-js/transactions";
3
- import { AssetValue, Chain, getChainConfig, getRPCUrl, SwapKitError } from "@uswap/helpers";
9
+ import { AssetValue, Chain, getChainConfig, getRPCUrl, USwapError } from "@uswap/helpers";
4
10
  import { getBalance } from "../utils";
5
11
  import {
6
12
  getFullAccessPublicKey,
@@ -62,7 +68,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
62
68
 
63
69
  async function getAddress() {
64
70
  if (!signer) {
65
- throw new SwapKitError("toolbox_near_no_signer");
71
+ throw new USwapError("toolbox_near_no_signer");
66
72
  }
67
73
  const address = await signer.getAddress();
68
74
  return address;
@@ -110,7 +116,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
110
116
 
111
117
  async function transfer(params: NearTransferParams) {
112
118
  if (!signer) {
113
- throw new SwapKitError("toolbox_near_no_signer");
119
+ throw new USwapError("toolbox_near_no_signer");
114
120
  }
115
121
 
116
122
  const { assetValue, recipient, memo } = params;
@@ -135,11 +141,11 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
135
141
  const validateNearAddress = await getValidateNearAddress();
136
142
 
137
143
  if (!validateNearAddress(recipient)) {
138
- throw new SwapKitError("toolbox_near_invalid_address", { recipient: recipient });
144
+ throw new USwapError("toolbox_near_invalid_address", { recipient: recipient });
139
145
  }
140
146
 
141
147
  if (!validateNearAddress(signerId)) {
142
- throw new SwapKitError("toolbox_near_invalid_address", { signerId: signerId });
148
+ throw new USwapError("toolbox_near_invalid_address", { signerId: signerId });
143
149
  }
144
150
 
145
151
  if (functionCall) {
@@ -149,7 +155,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
149
155
  if (!assetValue.isGasAsset) {
150
156
  const contractId = assetValue.address;
151
157
  if (!contractId) {
152
- throw new SwapKitError("toolbox_near_missing_contract_address");
158
+ throw new USwapError("toolbox_near_missing_contract_address");
153
159
  }
154
160
 
155
161
  return createContractFunctionCall({
@@ -224,7 +230,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
224
230
 
225
231
  async function signTransaction(transaction: Transaction): Promise<SignedTransaction> {
226
232
  if (!signer) {
227
- throw new SwapKitError("toolbox_near_no_signer");
233
+ throw new USwapError("toolbox_near_no_signer");
228
234
  }
229
235
 
230
236
  const [_hash, signedTx] = await signer.signTransaction(transaction);
@@ -238,7 +244,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
238
244
 
239
245
  async function signAndSendTransaction(transaction: Transaction) {
240
246
  if (!signer) {
241
- throw new SwapKitError("toolbox_near_no_signer");
247
+ throw new USwapError("toolbox_near_no_signer");
242
248
  }
243
249
 
244
250
  try {
@@ -287,7 +293,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
287
293
 
288
294
  async function createSubAccount(subAccountId: string, publicKey: string, initialBalance: string): Promise<string> {
289
295
  if (!signer) {
290
- throw new SwapKitError("toolbox_near_no_signer");
296
+ throw new USwapError("toolbox_near_no_signer");
291
297
  }
292
298
 
293
299
  const account = await getAccount();
@@ -304,7 +310,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
304
310
  async function callFunction(params: NearFunctionCallParams): Promise<string> {
305
311
  try {
306
312
  if (!signer) {
307
- throw new SwapKitError("toolbox_near_no_signer");
313
+ throw new USwapError("toolbox_near_no_signer");
308
314
  }
309
315
 
310
316
  const { actionCreators } = await import("@near-js/transactions");
@@ -325,7 +331,7 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
325
331
 
326
332
  return result.transaction_outcome.id;
327
333
  } catch (error) {
328
- throw new SwapKitError("toolbox_near_transfer_failed", { error });
334
+ throw new USwapError("toolbox_near_transfer_failed", { error });
329
335
  }
330
336
  }
331
337
 
@@ -343,11 +349,11 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
343
349
 
344
350
  async function executeBatchTransaction(batch: BatchTransaction): Promise<string> {
345
351
  if (!signer) {
346
- throw new SwapKitError("toolbox_near_no_signer");
352
+ throw new USwapError("toolbox_near_no_signer");
347
353
  }
348
354
 
349
355
  if (batch.actions.length === 0) {
350
- throw new SwapKitError("toolbox_near_empty_batch");
356
+ throw new USwapError("toolbox_near_empty_batch");
351
357
  }
352
358
 
353
359
  const account = await getAccount();
@@ -369,12 +375,12 @@ export async function getNearToolbox(toolboxParams?: NearToolboxParams) {
369
375
  .when(isContractDeployment, () => GAS_COSTS.CONTRACT_DEPLOYMENT)
370
376
  .when(isCustomEstimator, (p) => {
371
377
  if (!account) {
372
- throw new SwapKitError("toolbox_near_no_account");
378
+ throw new USwapError("toolbox_near_no_account");
373
379
  }
374
380
  return p.customEstimator(account);
375
381
  })
376
382
  .otherwise(() => {
377
- throw new SwapKitError("toolbox_near_invalid_gas_params");
383
+ throw new USwapError("toolbox_near_invalid_gas_params");
378
384
  });
379
385
 
380
386
  const gasInUnits = BigInt(gasInTGas) * BigInt(10 ** 12);
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import type {
2
8
  FungibleResourcesCollectionItem,
3
9
  GatewayApiClient,
@@ -5,7 +11,7 @@ import type {
5
11
  StateEntityFungiblesPageRequest,
6
12
  StateEntityFungiblesPageResponse,
7
13
  } from "@radixdlt/babylon-gateway-api-sdk";
8
- import { AssetValue, Chain, SKConfig, type SKConfigIntegrations, SwapKitError } from "@uswap/helpers";
14
+ import { AssetValue, Chain, SKConfig, type SKConfigIntegrations, USwapError } from "@uswap/helpers";
9
15
 
10
16
  export type RadixWallet = Awaited<ReturnType<typeof RadixToolbox>>;
11
17
 
@@ -18,7 +24,13 @@ export function radixValidateAddress(address: string) {
18
24
  function getBalance({ networkApi }: { networkApi: GatewayApiClient }) {
19
25
  return async function getBalance(address: string) {
20
26
  const fungibleResources = await fetchFungibleResources({ address, networkApi });
21
- const fungibleBalances = convertResourcesToBalances({ networkApi, resources: fungibleResources });
27
+ const fungibleBalances = await convertResourcesToBalances({ networkApi, resources: fungibleResources });
28
+
29
+ const hasNativeAsset = fungibleBalances.some((asset) => asset.isGasAsset);
30
+ if (!hasNativeAsset) {
31
+ return [AssetValue.from({ chain: Chain.Radix }), ...fungibleBalances];
32
+ }
33
+
22
34
  return fungibleBalances;
23
35
  };
24
36
  }
@@ -125,7 +137,7 @@ export const RadixToolbox = async ({ dappConfig }: { dappConfig?: SKConfigIntegr
125
137
  getBalance: getBalance({ networkApi }),
126
138
  networkApi,
127
139
  signAndBroadcast: (() => {
128
- throw new SwapKitError("toolbox_radix_method_not_supported", { method: "signAndBroadcast" });
140
+ throw new USwapError("toolbox_radix_method_not_supported", { method: "signAndBroadcast" });
129
141
  }) as (params: any) => Promise<string>,
130
142
  validateAddress: radixValidateAddress,
131
143
  };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Based on code from SwapKit (https://github.com/swapkit/SwapKit),
3
+ * licensed under the Apache License 2.0.
4
+ * Modifications © 2025 Horizontal Systems.
5
+ */
6
+
1
7
  import {
2
8
  AssetValue,
3
9
  Chain,
@@ -5,8 +11,8 @@ import {
5
11
  type GenericTransferParams,
6
12
  getChainConfig,
7
13
  getRPCUrl,
8
- SwapKitError,
9
14
  SwapKitNumber,
15
+ USwapError,
10
16
  } from "@uswap/helpers";
11
17
  import type { Transaction } from "xrpl";
12
18
  import { Client, isValidAddress, type Payment, Wallet, xrpToDrops } from "xrpl";
@@ -47,7 +53,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
47
53
 
48
54
  const rpcUrl = await getRPCUrl(Chain.Ripple);
49
55
  if (!rpcUrl) {
50
- throw new SwapKitError({ errorKey: "toolbox_ripple_rpc_not_configured", info: { chain: Chain.Ripple } });
56
+ throw new USwapError({ errorKey: "toolbox_ripple_rpc_not_configured", info: { chain: Chain.Ripple } });
51
57
  }
52
58
 
53
59
  const client = new Client(rpcUrl);
@@ -55,7 +61,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
55
61
 
56
62
  const getAddress = () => {
57
63
  if (!signer) {
58
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
64
+ throw new USwapError({ errorKey: "toolbox_ripple_signer_not_found" });
59
65
  }
60
66
  return signer.getAddress();
61
67
  };
@@ -75,7 +81,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
75
81
  if ((error as any).data.error_code === RIPPLE_ERROR_CODES.ACCOUNT_NOT_FOUND) {
76
82
  return [AssetValue.from({ chain: Chain.Ripple, value: 0 })];
77
83
  }
78
- throw new SwapKitError("toolbox_ripple_get_balance_error", { info: { address: addr, error } });
84
+ throw new USwapError("toolbox_ripple_get_balance_error", { info: { address: addr, error } });
79
85
  }
80
86
  };
81
87
 
@@ -104,16 +110,13 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
104
110
  memo?: string;
105
111
  }) => {
106
112
  if (!rippleValidateAddress(recipient)) {
107
- throw new SwapKitError({ errorKey: "core_transaction_invalid_recipient_address" });
113
+ throw new USwapError({ errorKey: "core_transaction_invalid_recipient_address" });
108
114
  }
109
115
 
110
116
  const senderAddress = sender || (await getAddress());
111
117
 
112
118
  if (!assetValue.isGasAsset || assetValue.chain !== Chain.Ripple) {
113
- throw new SwapKitError({
114
- errorKey: "toolbox_ripple_asset_not_supported",
115
- info: { asset: assetValue.toString() },
116
- });
119
+ throw new USwapError({ errorKey: "toolbox_ripple_asset_not_supported", info: { asset: assetValue.toString() } });
117
120
  }
118
121
 
119
122
  const transaction: Payment = {
@@ -133,7 +136,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
133
136
 
134
137
  const signTransaction = (tx: Transaction) => {
135
138
  if (!signer) {
136
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
139
+ throw new USwapError({ errorKey: "toolbox_ripple_signer_not_found" });
137
140
  }
138
141
  return signer.signTransaction(tx);
139
142
  };
@@ -146,12 +149,12 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
146
149
  return result.hash;
147
150
  }
148
151
 
149
- throw new SwapKitError({ errorKey: "toolbox_ripple_broadcast_error", info: { chain: Chain.Ripple } });
152
+ throw new USwapError({ errorKey: "toolbox_ripple_broadcast_error", info: { chain: Chain.Ripple } });
150
153
  };
151
154
 
152
155
  const transfer = async (params: GenericTransferParams) => {
153
156
  if (!signer) {
154
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
157
+ throw new USwapError({ errorKey: "toolbox_ripple_signer_not_found" });
155
158
  }
156
159
  const sender = await signer.getAddress();
157
160
  const tx = await createTransaction({ ...params, sender });