@uswap/toolboxes 4.3.10 → 4.3.11
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/src/cardano/index.cjs.map +2 -2
- package/dist/src/cardano/index.js.map +2 -2
- package/dist/src/cosmos/index.cjs +2 -2
- package/dist/src/cosmos/index.cjs.map +8 -8
- package/dist/src/cosmos/index.js +2 -2
- package/dist/src/cosmos/index.js.map +8 -8
- package/dist/src/evm/index.cjs +2 -2
- package/dist/src/evm/index.cjs.map +5 -5
- package/dist/src/evm/index.js +2 -2
- package/dist/src/evm/index.js.map +5 -5
- package/dist/src/index.cjs +3 -3
- package/dist/src/index.cjs.map +32 -32
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +32 -32
- package/dist/src/near/index.cjs +2 -2
- package/dist/src/near/index.cjs.map +5 -5
- package/dist/src/near/index.js +2 -2
- package/dist/src/near/index.js.map +5 -5
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/ripple/index.cjs +2 -2
- package/dist/src/ripple/index.cjs.map +3 -3
- package/dist/src/ripple/index.js +2 -2
- package/dist/src/ripple/index.js.map +3 -3
- package/dist/src/solana/index.cjs.map +2 -2
- package/dist/src/solana/index.js.map +2 -2
- package/dist/src/substrate/index.cjs +2 -2
- package/dist/src/substrate/index.cjs.map +4 -4
- package/dist/src/substrate/index.js +2 -2
- package/dist/src/substrate/index.js.map +4 -4
- package/dist/src/sui/index.cjs.map +2 -2
- package/dist/src/sui/index.js.map +2 -2
- package/dist/src/ton/index.cjs +2 -2
- package/dist/src/ton/index.cjs.map +3 -3
- package/dist/src/ton/index.js +2 -2
- package/dist/src/ton/index.js.map +3 -3
- package/dist/src/tron/index.cjs.map +3 -3
- package/dist/src/tron/index.js.map +3 -3
- package/dist/src/utxo/index.cjs +3 -3
- package/dist/src/utxo/index.cjs.map +11 -11
- package/dist/src/utxo/index.js +3 -3
- package/dist/src/utxo/index.js.map +11 -11
- package/dist/types/cardano/toolbox.d.ts +0 -2
- package/dist/types/cardano/toolbox.d.ts.map +1 -1
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +0 -2
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -1
- package/dist/types/cosmos/thorchainUtils/messages.d.ts +0 -2
- package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -1
- package/dist/types/cosmos/toolbox/cosmos.d.ts +4 -6
- package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -1
- package/dist/types/cosmos/toolbox/index.d.ts +0 -2
- package/dist/types/cosmos/toolbox/index.d.ts.map +1 -1
- package/dist/types/cosmos/toolbox/thorchain.d.ts +4 -6
- package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -1
- package/dist/types/cosmos/util.d.ts +0 -2
- package/dist/types/cosmos/util.d.ts.map +1 -1
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +0 -2
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -1
- package/dist/types/evm/toolbox/evm.d.ts.map +1 -1
- package/dist/types/evm/toolbox/op.d.ts +0 -2
- package/dist/types/evm/toolbox/op.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/near/helpers/core.d.ts +0 -2
- package/dist/types/near/helpers/core.d.ts.map +1 -1
- package/dist/types/near/toolbox.d.ts +0 -2
- package/dist/types/near/toolbox.d.ts.map +1 -1
- package/dist/types/radix/index.d.ts +2 -4
- package/dist/types/radix/index.d.ts.map +1 -1
- package/dist/types/ripple/index.d.ts +0 -2
- package/dist/types/ripple/index.d.ts.map +1 -1
- package/dist/types/solana/toolbox.d.ts +0 -2
- package/dist/types/solana/toolbox.d.ts.map +1 -1
- package/dist/types/substrate/balance.d.ts +3 -0
- package/dist/types/substrate/balance.d.ts.map +1 -1
- package/dist/types/substrate/substrate.d.ts +0 -2
- package/dist/types/substrate/substrate.d.ts.map +1 -1
- package/dist/types/sui/toolbox.d.ts +0 -2
- package/dist/types/sui/toolbox.d.ts.map +1 -1
- package/dist/types/ton/toolbox.d.ts +0 -2
- package/dist/types/ton/toolbox.d.ts.map +1 -1
- package/dist/types/tron/helpers/trongrid.d.ts +0 -2
- package/dist/types/tron/helpers/trongrid.d.ts.map +1 -1
- package/dist/types/tron/toolbox.d.ts +0 -2
- package/dist/types/tron/toolbox.d.ts.map +1 -1
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/utxo/helpers/api.d.ts +0 -2
- package/dist/types/utxo/helpers/api.d.ts.map +1 -1
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +0 -2
- package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -1
- package/dist/types/utxo/helpers/coinselect.d.ts +0 -2
- package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -1
- package/dist/types/utxo/helpers/txSize.d.ts +0 -2
- package/dist/types/utxo/helpers/txSize.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +0 -2
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/index.d.ts +0 -2
- package/dist/types/utxo/toolbox/index.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/utxo.d.ts +0 -2
- package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/zcash.d.ts +0 -2
- package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -1
- package/package.json +5 -11
- package/src/cardano/toolbox.ts +0 -2
- package/src/cosmos/thorchainUtils/addressFormat.ts +0 -2
- package/src/cosmos/thorchainUtils/messages.ts +0 -2
- package/src/cosmos/toolbox/cosmos.ts +9 -11
- package/src/cosmos/toolbox/index.ts +0 -2
- package/src/cosmos/toolbox/thorchain.ts +6 -8
- package/src/cosmos/util.ts +1 -3
- package/src/evm/__tests__/ethereum.test.ts +6 -2
- package/src/evm/toolbox/baseEVMToolbox.ts +4 -6
- package/src/evm/toolbox/op.ts +0 -2
- package/src/index.ts +0 -2
- package/src/near/helpers/core.ts +0 -2
- package/src/near/toolbox.ts +0 -2
- package/src/radix/index.ts +3 -5
- package/src/ripple/index.ts +2 -4
- package/src/solana/toolbox.ts +0 -2
- package/src/substrate/balance.ts +9 -5
- package/src/substrate/substrate.ts +2 -4
- package/src/sui/toolbox.ts +0 -2
- package/src/ton/toolbox.ts +2 -4
- package/src/tron/__tests__/toolbox.test.ts +6 -2
- package/src/tron/helpers/trongrid.ts +0 -2
- package/src/tron/toolbox.ts +1 -3
- package/src/utils.ts +6 -2
- package/src/utxo/helpers/api.ts +2 -4
- package/src/utxo/helpers/bchaddrjs.ts +0 -2
- package/src/utxo/helpers/coinselect.ts +0 -2
- package/src/utxo/helpers/txSize.ts +0 -2
- package/src/utxo/toolbox/bitcoinCash.ts +0 -2
- package/src/utxo/toolbox/index.ts +0 -2
- package/src/utxo/toolbox/utxo.ts +2 -4
- package/src/utxo/toolbox/zcash.ts +2 -4
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -16,10 +14,10 @@ import {
|
|
|
16
14
|
getRPCUrl,
|
|
17
15
|
NetworkDerivationPath,
|
|
18
16
|
RequestClient,
|
|
19
|
-
SKConfig,
|
|
20
|
-
SwapKitNumber,
|
|
21
17
|
type TCLikeChain,
|
|
18
|
+
USwapConfig,
|
|
22
19
|
USwapError,
|
|
20
|
+
USwapNumber,
|
|
23
21
|
updateDerivationPath,
|
|
24
22
|
} from "@uswap/helpers";
|
|
25
23
|
|
|
@@ -141,7 +139,7 @@ async function signWithPrivateKey({ privateKey, message }: { privateKey: Uint8Ar
|
|
|
141
139
|
export async function createThorchainToolbox({ chain, ...toolboxParams }: CosmosToolboxParams<TCLikeChain>) {
|
|
142
140
|
const rpcUrl = await getRPCUrl(chain);
|
|
143
141
|
const { nodeUrl } = getChainConfig(chain);
|
|
144
|
-
const { isStagenet } =
|
|
142
|
+
const { isStagenet } = USwapConfig.get("envs");
|
|
145
143
|
const isThorchain = chain === Chain.THORChain;
|
|
146
144
|
const chainPrefix = `${isStagenet ? "s" : ""}${CosmosChainPrefixes[chain]}`;
|
|
147
145
|
|
|
@@ -162,7 +160,7 @@ export async function createThorchainToolbox({ chain, ...toolboxParams }: Cosmos
|
|
|
162
160
|
const defaultFee = getDefaultChainFee(chain);
|
|
163
161
|
|
|
164
162
|
async function getFees() {
|
|
165
|
-
let fee:
|
|
163
|
+
let fee: USwapNumber;
|
|
166
164
|
|
|
167
165
|
const constantsUrl = `${nodeUrl}/${isThorchain ? "thorchain" : "mayachain"}/constants`;
|
|
168
166
|
|
|
@@ -175,9 +173,9 @@ export async function createThorchainToolbox({ chain, ...toolboxParams }: Cosmos
|
|
|
175
173
|
throw new USwapError("toolbox_cosmos_invalid_fee", { nativeFee: nativeFee.toString() });
|
|
176
174
|
}
|
|
177
175
|
|
|
178
|
-
fee = new
|
|
176
|
+
fee = new USwapNumber(nativeFee);
|
|
179
177
|
} catch {
|
|
180
|
-
fee = new
|
|
178
|
+
fee = new USwapNumber({ decimal: getChainConfig(chain).baseDecimal, value: isThorchain ? 0.02 : 1 });
|
|
181
179
|
}
|
|
182
180
|
|
|
183
181
|
return { [FeeOption.Average]: fee, [FeeOption.Fast]: fee, [FeeOption.Fastest]: fee };
|
package/src/cosmos/util.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -81,7 +79,7 @@ export async function createStargateClient(url: string) {
|
|
|
81
79
|
const defaultRequestHeaders =
|
|
82
80
|
typeof window !== "undefined"
|
|
83
81
|
? ({} as Record<string, string>)
|
|
84
|
-
: { referer: "https://sdk.
|
|
82
|
+
: { referer: "https://sdk.uswap.dev", referrer: "https://sdk.uswap.dev" };
|
|
85
83
|
|
|
86
84
|
return StargateClient.connect({ headers: defaultRequestHeaders, url });
|
|
87
85
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { beforeEach, describe, expect, test } from "bun:test";
|
|
2
6
|
import { existsSync } from "node:fs";
|
|
3
7
|
import { resolve } from "node:path";
|
|
4
8
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { AssetValue, Chain,
|
|
9
|
+
import { AssetValue, Chain, USwapConfig } from "@uswap/helpers";
|
|
6
10
|
import { erc20ABI } from "@uswap/helpers/contracts";
|
|
7
11
|
import type { JsonRpcProvider, Signer } from "ethers";
|
|
8
12
|
import { getEvmToolbox } from "../toolbox";
|
|
@@ -39,7 +43,7 @@ beforeEach(async () => {
|
|
|
39
43
|
const provider = (connection as any).ethers.provider as JsonRpcProvider;
|
|
40
44
|
const signer = await (connection as any).ethers.getImpersonatedSigner(testAddress);
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
USwapConfig.set({ apiKeys: { uSwap: process.env.TEST_API_KEY || Bun.env.TEST_API_KEY } });
|
|
43
47
|
|
|
44
48
|
context.provider = provider;
|
|
45
49
|
context.signer = signer as any;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -14,8 +12,8 @@ import {
|
|
|
14
12
|
EVMChains,
|
|
15
13
|
FeeOption,
|
|
16
14
|
isGasAsset,
|
|
17
|
-
SwapKitNumber,
|
|
18
15
|
USwapError,
|
|
16
|
+
USwapNumber,
|
|
19
17
|
} from "@uswap/helpers";
|
|
20
18
|
import { erc20ABI } from "@uswap/helpers/contracts";
|
|
21
19
|
import {
|
|
@@ -387,7 +385,7 @@ function getIsApproved({ provider, chain }: ToolboxWrapParams) {
|
|
|
387
385
|
return async function isApproved({ assetAddress, spenderAddress, from, amount = MAX_APPROVAL }: IsApprovedParams) {
|
|
388
386
|
const approvedAmount = await getApprovedAmount({ chain, provider })({ assetAddress, from, spenderAddress });
|
|
389
387
|
|
|
390
|
-
return
|
|
388
|
+
return USwapNumber.fromBigInt(approvedAmount).gte(USwapNumber.fromBigInt(BigInt(amount)));
|
|
391
389
|
};
|
|
392
390
|
}
|
|
393
391
|
|
|
@@ -689,13 +687,13 @@ function getEstimateTransactionFee({
|
|
|
689
687
|
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = gasPrices[feeOption];
|
|
690
688
|
|
|
691
689
|
if (!isEIP1559Compatible && gasPrice) {
|
|
692
|
-
return assetValue.set(
|
|
690
|
+
return assetValue.set(USwapNumber.fromBigInt(gasPrice * gasLimit, assetValue.decimal));
|
|
693
691
|
}
|
|
694
692
|
|
|
695
693
|
if (maxFeePerGas && maxPriorityFeePerGas) {
|
|
696
694
|
const fee = (maxFeePerGas + maxPriorityFeePerGas) * gasLimit;
|
|
697
695
|
|
|
698
|
-
return assetValue.set(
|
|
696
|
+
return assetValue.set(USwapNumber.fromBigInt(fee, assetValue.decimal));
|
|
699
697
|
}
|
|
700
698
|
|
|
701
699
|
throw new USwapError("toolbox_evm_no_gas_price");
|
package/src/evm/toolbox/op.ts
CHANGED
package/src/index.ts
CHANGED
package/src/near/helpers/core.ts
CHANGED
package/src/near/toolbox.ts
CHANGED
package/src/radix/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -11,7 +9,7 @@ import type {
|
|
|
11
9
|
StateEntityFungiblesPageRequest,
|
|
12
10
|
StateEntityFungiblesPageResponse,
|
|
13
11
|
} from "@radixdlt/babylon-gateway-api-sdk";
|
|
14
|
-
import { AssetValue, Chain,
|
|
12
|
+
import { AssetValue, Chain, USwapConfig, type USwapConfigIntegrations, USwapError } from "@uswap/helpers";
|
|
15
13
|
|
|
16
14
|
export type RadixWallet = Awaited<ReturnType<typeof RadixToolbox>>;
|
|
17
15
|
|
|
@@ -123,10 +121,10 @@ function currentStateVersion(networkApi: GatewayApiClient) {
|
|
|
123
121
|
return networkApi.status.getCurrent().then((status) => status.ledger_state.state_version);
|
|
124
122
|
}
|
|
125
123
|
|
|
126
|
-
export const RadixToolbox = async ({ dappConfig }: { dappConfig?:
|
|
124
|
+
export const RadixToolbox = async ({ dappConfig }: { dappConfig?: USwapConfigIntegrations["radix"] } = {}) => {
|
|
127
125
|
const { RadixDappToolkit } = await import("@radixdlt/radix-dapp-toolkit");
|
|
128
126
|
const { GatewayApiClient } = await import("@radixdlt/babylon-gateway-api-sdk");
|
|
129
|
-
const config = dappConfig ||
|
|
127
|
+
const config = dappConfig || USwapConfig.get("integrations").radix;
|
|
130
128
|
|
|
131
129
|
const radixToolkit = RadixDappToolkit({ ...config, networkId: config.network?.networkId || 1 });
|
|
132
130
|
|
package/src/ripple/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -11,8 +9,8 @@ import {
|
|
|
11
9
|
type GenericTransferParams,
|
|
12
10
|
getChainConfig,
|
|
13
11
|
getRPCUrl,
|
|
14
|
-
SwapKitNumber,
|
|
15
12
|
USwapError,
|
|
13
|
+
USwapNumber,
|
|
16
14
|
} from "@uswap/helpers";
|
|
17
15
|
import type { Transaction } from "xrpl";
|
|
18
16
|
import { Client, isValidAddress, type Payment, Wallet, xrpToDrops } from "xrpl";
|
|
@@ -94,7 +92,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
|
|
|
94
92
|
return AssetValue.from({
|
|
95
93
|
chain: Chain.Ripple,
|
|
96
94
|
fromBaseDecimal: baseDecimal,
|
|
97
|
-
value:
|
|
95
|
+
value: USwapNumber.fromBigInt(BigInt(feeDrops), baseDecimal),
|
|
98
96
|
});
|
|
99
97
|
};
|
|
100
98
|
|
package/src/solana/toolbox.ts
CHANGED
package/src/substrate/balance.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import type { ApiPromise } from "@polkadot/api";
|
|
2
|
-
import { AssetValue, Chain,
|
|
6
|
+
import { AssetValue, Chain, USwapNumber } from "@uswap/helpers";
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Get balance for standard Substrate chains (Polkadot, etc.)
|
|
@@ -22,8 +26,8 @@ export async function getSubstrateBalance(
|
|
|
22
26
|
data: { free },
|
|
23
27
|
} = account;
|
|
24
28
|
|
|
25
|
-
// Convert the free balance to string using
|
|
26
|
-
const freeBalance =
|
|
29
|
+
// Convert the free balance to string using USwapNumber for proper decimal handling
|
|
30
|
+
const freeBalance = USwapNumber.fromBigInt(BigInt(free.toString()), gasAsset.decimal).getValue("string");
|
|
27
31
|
|
|
28
32
|
return [gasAsset.set(freeBalance)];
|
|
29
33
|
} catch (error) {
|
|
@@ -59,8 +63,8 @@ export async function getChainflipBalance(
|
|
|
59
63
|
return [gasAsset.set(0)];
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
// Convert balance to string using
|
|
63
|
-
const balanceStr =
|
|
66
|
+
// Convert balance to string using USwapNumber
|
|
67
|
+
const balanceStr = USwapNumber.fromBigInt(BigInt(balance.toString()), gasAsset.decimal).getValue("string");
|
|
64
68
|
|
|
65
69
|
return [gasAsset.set(balanceStr)];
|
|
66
70
|
} catch (error) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -17,8 +15,8 @@ import {
|
|
|
17
15
|
type GenericCreateTransactionParams,
|
|
18
16
|
getRPCUrl,
|
|
19
17
|
type SubstrateChain,
|
|
20
|
-
SwapKitNumber,
|
|
21
18
|
USwapError,
|
|
19
|
+
USwapNumber,
|
|
22
20
|
} from "@uswap/helpers";
|
|
23
21
|
|
|
24
22
|
import { match, P } from "ts-pattern";
|
|
@@ -120,7 +118,7 @@ const estimateTransactionFee = async (
|
|
|
120
118
|
partialFee: 0,
|
|
121
119
|
};
|
|
122
120
|
return gasAsset.set(
|
|
123
|
-
|
|
121
|
+
USwapNumber.fromBigInt(BigInt(paymentInfo.partialFee.toString()), gasAsset.decimal).getValue("string"),
|
|
124
122
|
);
|
|
125
123
|
};
|
|
126
124
|
|
package/src/sui/toolbox.ts
CHANGED
package/src/ton/toolbox.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
7
5
|
import type { Cell, OpenedContract, TonClient, WalletContractV4 } from "@ton/ton";
|
|
8
|
-
import { AssetValue, Chain, getChainConfig,
|
|
6
|
+
import { AssetValue, Chain, getChainConfig, USwapError, USwapNumber } from "@uswap/helpers";
|
|
9
7
|
import { match, P } from "ts-pattern";
|
|
10
8
|
|
|
11
9
|
import type { TONSigner, TONToolboxParams, TONTransferParams } from "./types";
|
|
@@ -57,7 +55,7 @@ export async function getTONToolbox(toolboxParams: TONToolboxParams = {}) {
|
|
|
57
55
|
|
|
58
56
|
try {
|
|
59
57
|
const balance = await client.getBalance(Address.parse(address));
|
|
60
|
-
return [AssetValue.from({ chain: Chain.Ton, value:
|
|
58
|
+
return [AssetValue.from({ chain: Chain.Ton, value: USwapNumber.fromBigInt(balance, baseDecimal) })];
|
|
61
59
|
} catch {
|
|
62
60
|
return [AssetValue.from({ chain: Chain.Ton })];
|
|
63
61
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { AssetValue, Chain,
|
|
6
|
+
import { AssetValue, Chain, USwapConfig } from "@uswap/helpers";
|
|
3
7
|
import { createTronToolbox, getTronAddressValidator } from "../toolbox";
|
|
4
8
|
|
|
5
9
|
const context: {
|
|
@@ -16,7 +20,7 @@ beforeEach(async () => {
|
|
|
16
20
|
});
|
|
17
21
|
|
|
18
22
|
afterAll(() => {
|
|
19
|
-
|
|
23
|
+
USwapConfig.reinitialize();
|
|
20
24
|
});
|
|
21
25
|
|
|
22
26
|
describe("TRON Address Validation", () => {
|
package/src/tron/toolbox.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -133,7 +131,7 @@ export const createTronToolbox = async (
|
|
|
133
131
|
const TronWeb = TW.TronWeb ?? TW.default?.TronWeb;
|
|
134
132
|
|
|
135
133
|
const rpcUrl = await getRPCUrl(Chain.Tron);
|
|
136
|
-
// Note: TRON API key support can be added to
|
|
134
|
+
// Note: TRON API key support can be added to USwapConfig apiKeys when needed
|
|
137
135
|
const headers = undefined; // No API key needed for basic TronGrid access
|
|
138
136
|
|
|
139
137
|
const tronWeb = new TronWeb({ fullHost: rpcUrl, headers });
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { AssetValue, type Chain, getChainConfig } from "@uswap/helpers";
|
|
2
|
-
import {
|
|
6
|
+
import { USwapApi } from "@uswap/helpers/api";
|
|
3
7
|
|
|
4
8
|
const pid = typeof process !== "undefined" && process.pid ? process.pid.toString(36) : "";
|
|
5
9
|
|
|
@@ -18,7 +22,7 @@ export function uniqid() {
|
|
|
18
22
|
|
|
19
23
|
export function getBalance<T extends Chain>(chain: T) {
|
|
20
24
|
return async function getBalance(address: string, scamFilter = true) {
|
|
21
|
-
const balances = await
|
|
25
|
+
const balances = await USwapApi.getChainBalance({ address, chain, scamFilter });
|
|
22
26
|
const { baseDecimal } = getChainConfig(chain);
|
|
23
27
|
const assetValues = balances.map(({ identifier, value, decimal }) => {
|
|
24
28
|
return new AssetValue({ decimal: decimal || baseDecimal, identifier, value });
|
package/src/utxo/helpers/api.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
7
5
|
import { networks as zcashNetworks } from "@bitgo/utxo-lib";
|
|
8
|
-
import { Chain, getRPCUrl, RequestClient,
|
|
6
|
+
import { Chain, getRPCUrl, RequestClient, USwapConfig, USwapError, type UTXOChain, warnOnce } from "@uswap/helpers";
|
|
9
7
|
import { networks } from "bitcoinjs-lib";
|
|
10
8
|
// @ts-expect-error
|
|
11
9
|
import coininfo from "coininfo";
|
|
@@ -296,7 +294,7 @@ async function getUtxos({
|
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
export function getUtxoApi(chain: UTXOChain) {
|
|
299
|
-
const apiKey =
|
|
297
|
+
const apiKey = USwapConfig.get("apiKeys").blockchair || "";
|
|
300
298
|
|
|
301
299
|
warnOnce({
|
|
302
300
|
condition: !apiKey,
|
package/src/utxo/toolbox/utxo.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -19,8 +17,8 @@ import {
|
|
|
19
17
|
derivationPathToString,
|
|
20
18
|
FeeOption,
|
|
21
19
|
NetworkDerivationPath,
|
|
22
|
-
SwapKitNumber,
|
|
23
20
|
USwapError,
|
|
21
|
+
USwapNumber,
|
|
24
22
|
type UTXOChain,
|
|
25
23
|
updateDerivationPath,
|
|
26
24
|
} from "@uswap/helpers";
|
|
@@ -296,7 +294,7 @@ function estimateTransactionFee(chain: UTXOChain) {
|
|
|
296
294
|
}) => {
|
|
297
295
|
const inputFees = await getInputsOutputsFee(params);
|
|
298
296
|
|
|
299
|
-
return AssetValue.from({ chain, value:
|
|
297
|
+
return AssetValue.from({ chain, value: USwapNumber.fromBigInt(BigInt(inputFees.fee), 8).getValue("string") });
|
|
300
298
|
};
|
|
301
299
|
}
|
|
302
300
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Based on code from SwapKit (https://github.com/swapkit/SwapKit),
|
|
3
|
-
* licensed under the Apache License 2.0.
|
|
4
2
|
* Modifications © 2025 Horizontal Systems.
|
|
5
3
|
*/
|
|
6
4
|
|
|
@@ -15,7 +13,7 @@ import {
|
|
|
15
13
|
derivationPathToString,
|
|
16
14
|
FeeOption,
|
|
17
15
|
NetworkDerivationPath,
|
|
18
|
-
|
|
16
|
+
USwapConfig,
|
|
19
17
|
USwapError,
|
|
20
18
|
updateDerivationPath,
|
|
21
19
|
} from "@uswap/helpers";
|
|
@@ -63,7 +61,7 @@ function createZcashSignerFromPhrase({
|
|
|
63
61
|
const keyPair = ECPair.fromPrivateKey(Buffer.from(node.privateKey), { network: ecpairNetwork });
|
|
64
62
|
|
|
65
63
|
const pubKeyHash = crypto.hash160(keyPair.publicKey);
|
|
66
|
-
const { isStagenet } =
|
|
64
|
+
const { isStagenet } = USwapConfig.get("envs");
|
|
67
65
|
|
|
68
66
|
const prefix = isStagenet
|
|
69
67
|
? Buffer.from([0x1d, 0x25]) // testnet prefix (results in tm... addresses)
|