@uswap/toolboxes 4.3.6
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 +4 -0
- package/dist/src/cardano/index.cjs.map +11 -0
- package/dist/src/cardano/index.js +4 -0
- package/dist/src/cardano/index.js.map +11 -0
- package/dist/src/cosmos/index.cjs +4 -0
- package/dist/src/cosmos/index.cjs.map +20 -0
- package/dist/src/cosmos/index.js +4 -0
- package/dist/src/cosmos/index.js.map +20 -0
- package/dist/src/evm/index.cjs +4 -0
- package/dist/src/evm/index.cjs.map +20 -0
- package/dist/src/evm/index.js +4 -0
- package/dist/src/evm/index.js.map +20 -0
- package/dist/src/index.cjs +5 -0
- package/dist/src/index.cjs.map +67 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +67 -0
- package/dist/src/near/index.cjs +4 -0
- package/dist/src/near/index.cjs.map +16 -0
- package/dist/src/near/index.js +4 -0
- package/dist/src/near/index.js.map +16 -0
- package/dist/src/radix/index.cjs +4 -0
- package/dist/src/radix/index.cjs.map +10 -0
- package/dist/src/radix/index.js +4 -0
- package/dist/src/radix/index.js.map +10 -0
- package/dist/src/ripple/index.cjs +4 -0
- package/dist/src/ripple/index.cjs.map +10 -0
- package/dist/src/ripple/index.js +4 -0
- package/dist/src/ripple/index.js.map +10 -0
- package/dist/src/solana/index.cjs +4 -0
- package/dist/src/solana/index.cjs.map +11 -0
- package/dist/src/solana/index.js +4 -0
- package/dist/src/solana/index.js.map +11 -0
- package/dist/src/substrate/index.cjs +4 -0
- package/dist/src/substrate/index.cjs.map +13 -0
- package/dist/src/substrate/index.js +4 -0
- package/dist/src/substrate/index.js.map +13 -0
- package/dist/src/sui/index.cjs +4 -0
- package/dist/src/sui/index.cjs.map +11 -0
- package/dist/src/sui/index.js +4 -0
- package/dist/src/sui/index.js.map +11 -0
- package/dist/src/ton/index.cjs +4 -0
- package/dist/src/ton/index.cjs.map +11 -0
- package/dist/src/ton/index.js +4 -0
- package/dist/src/ton/index.js.map +11 -0
- package/dist/src/tron/index.cjs +4 -0
- package/dist/src/tron/index.cjs.map +13 -0
- package/dist/src/tron/index.js +4 -0
- package/dist/src/tron/index.js.map +13 -0
- package/dist/src/utxo/index.cjs +5 -0
- package/dist/src/utxo/index.cjs.map +21 -0
- package/dist/src/utxo/index.js +5 -0
- package/dist/src/utxo/index.js.map +21 -0
- package/dist/types/cardano/index.d.ts +3 -0
- package/dist/types/cardano/index.d.ts.map +1 -0
- package/dist/types/cardano/toolbox.d.ts +34 -0
- package/dist/types/cardano/toolbox.d.ts.map +1 -0
- package/dist/types/cardano/types.d.ts +11 -0
- package/dist/types/cardano/types.d.ts.map +1 -0
- package/dist/types/cosmos/index.d.ts +5 -0
- package/dist/types/cosmos/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +5 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/index.d.ts +5 -0
- package/dist/types/cosmos/thorchainUtils/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts +208 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts +4 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +63 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts +62 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/index.d.ts +15 -0
- package/dist/types/cosmos/toolbox/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts +158 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -0
- package/dist/types/cosmos/types.d.ts +49 -0
- package/dist/types/cosmos/types.d.ts.map +1 -0
- package/dist/types/cosmos/util.d.ts +74 -0
- package/dist/types/cosmos/util.d.ts.map +1 -0
- package/dist/types/evm/api.d.ts +8 -0
- package/dist/types/evm/api.d.ts.map +1 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts +36 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts.map +1 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts +40 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts.map +1 -0
- package/dist/types/evm/helpers.d.ts +6 -0
- package/dist/types/evm/helpers.d.ts.map +1 -0
- package/dist/types/evm/index.d.ts +5 -0
- package/dist/types/evm/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +83 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -0
- package/dist/types/evm/toolbox/evm.d.ts +767 -0
- package/dist/types/evm/toolbox/evm.d.ts.map +1 -0
- package/dist/types/evm/toolbox/index.d.ts +7 -0
- package/dist/types/evm/toolbox/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/op.d.ts +76 -0
- package/dist/types/evm/toolbox/op.d.ts.map +1 -0
- package/dist/types/evm/types.d.ts +108 -0
- package/dist/types/evm/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +75 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/near/helpers/core.d.ts +15 -0
- package/dist/types/near/helpers/core.d.ts.map +1 -0
- package/dist/types/near/helpers/gasEstimation.d.ts +41 -0
- package/dist/types/near/helpers/gasEstimation.d.ts.map +1 -0
- package/dist/types/near/helpers/nep141.d.ts +36 -0
- package/dist/types/near/helpers/nep141.d.ts.map +1 -0
- package/dist/types/near/index.d.ts +10 -0
- package/dist/types/near/index.d.ts.map +1 -0
- package/dist/types/near/toolbox.d.ts +32 -0
- package/dist/types/near/toolbox.d.ts.map +1 -0
- package/dist/types/near/types/contract.d.ts +38 -0
- package/dist/types/near/types/contract.d.ts.map +1 -0
- package/dist/types/near/types/nep141.d.ts +29 -0
- package/dist/types/near/types/nep141.d.ts.map +1 -0
- package/dist/types/near/types/toolbox.d.ts +51 -0
- package/dist/types/near/types/toolbox.d.ts.map +1 -0
- package/dist/types/near/types.d.ts +47 -0
- package/dist/types/near/types.d.ts.map +1 -0
- package/dist/types/radix/index.d.ts +14 -0
- package/dist/types/radix/index.d.ts.map +1 -0
- package/dist/types/ripple/index.d.ts +46 -0
- package/dist/types/ripple/index.d.ts.map +1 -0
- package/dist/types/solana/index.d.ts +23 -0
- package/dist/types/solana/index.d.ts.map +1 -0
- package/dist/types/solana/toolbox.d.ts +51 -0
- package/dist/types/solana/toolbox.d.ts.map +1 -0
- package/dist/types/substrate/balance.d.ts +17 -0
- package/dist/types/substrate/balance.d.ts.map +1 -0
- package/dist/types/substrate/index.d.ts +3 -0
- package/dist/types/substrate/index.d.ts.map +1 -0
- package/dist/types/substrate/substrate.d.ts +148 -0
- package/dist/types/substrate/substrate.d.ts.map +1 -0
- package/dist/types/substrate/types.d.ts +100 -0
- package/dist/types/substrate/types.d.ts.map +1 -0
- package/dist/types/sui/index.d.ts +3 -0
- package/dist/types/sui/index.d.ts.map +1 -0
- package/dist/types/sui/toolbox.d.ts +19 -0
- package/dist/types/sui/toolbox.d.ts.map +1 -0
- package/dist/types/sui/types.d.ts +16 -0
- package/dist/types/sui/types.d.ts.map +1 -0
- package/dist/types/ton/index.d.ts +3 -0
- package/dist/types/ton/index.d.ts.map +1 -0
- package/dist/types/ton/toolbox.d.ts +14 -0
- package/dist/types/ton/toolbox.d.ts.map +1 -0
- package/dist/types/ton/types.d.ts +22 -0
- package/dist/types/ton/types.d.ts.map +1 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts +156 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts.map +1 -0
- package/dist/types/tron/helpers/trongrid.d.ts +8 -0
- package/dist/types/tron/helpers/trongrid.d.ts.map +1 -0
- package/dist/types/tron/index.d.ts +6 -0
- package/dist/types/tron/index.d.ts.map +1 -0
- package/dist/types/tron/toolbox.d.ts +26 -0
- package/dist/types/tron/toolbox.d.ts.map +1 -0
- package/dist/types/tron/types.d.ts +103 -0
- package/dist/types/tron/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +26 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utxo/helpers/api.d.ts +101 -0
- package/dist/types/utxo/helpers/api.d.ts.map +1 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +10 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -0
- package/dist/types/utxo/helpers/coinselect.d.ts +17 -0
- package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -0
- package/dist/types/utxo/helpers/index.d.ts +5 -0
- package/dist/types/utxo/helpers/index.d.ts.map +1 -0
- package/dist/types/utxo/helpers/txSize.d.ts +21 -0
- package/dist/types/utxo/helpers/txSize.d.ts.map +1 -0
- package/dist/types/utxo/index.d.ts +7 -0
- package/dist/types/utxo/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +93 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/index.d.ts +28 -0
- package/dist/types/utxo/toolbox/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/params.d.ts +32 -0
- package/dist/types/utxo/toolbox/params.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/utxo.d.ts +103 -0
- package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/validators.d.ts +4 -0
- package/dist/types/utxo/toolbox/validators.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/zcash.d.ts +72 -0
- package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -0
- package/dist/types/utxo/types.d.ts +46 -0
- package/dist/types/utxo/types.d.ts.map +1 -0
- package/package.json +205 -0
- package/src/__tests__/address-validation-all-chains.test.ts +162 -0
- package/src/__tests__/addressValidator.test.ts +162 -0
- package/src/cardano/__tests__/toolbox.test.ts +48 -0
- package/src/cardano/index.ts +2 -0
- package/src/cardano/toolbox.ts +168 -0
- package/src/cardano/types.ts +10 -0
- package/src/cosmos/__tests__/toolbox.test.ts +91 -0
- package/src/cosmos/index.ts +4 -0
- package/src/cosmos/thorchainUtils/addressFormat.ts +22 -0
- package/src/cosmos/thorchainUtils/index.ts +4 -0
- package/src/cosmos/thorchainUtils/messages.ts +212 -0
- package/src/cosmos/thorchainUtils/registry.ts +43 -0
- package/src/cosmos/thorchainUtils/types/MsgCompiled.ts +2800 -0
- package/src/cosmos/thorchainUtils/types/client-types.ts +54 -0
- package/src/cosmos/thorchainUtils/types/index.ts +1 -0
- package/src/cosmos/toolbox/cosmos.ts +345 -0
- package/src/cosmos/toolbox/index.ts +35 -0
- package/src/cosmos/toolbox/thorchain.ts +249 -0
- package/src/cosmos/types.ts +48 -0
- package/src/cosmos/util.ts +214 -0
- package/src/evm/__tests__/address-validation.test.ts +84 -0
- package/src/evm/__tests__/ethereum.test.ts +137 -0
- package/src/evm/__tests__/signMessage.test.ts +60 -0
- package/src/evm/api.ts +10 -0
- package/src/evm/contracts/eth/multicall.ts +165 -0
- package/src/evm/contracts/op/gasOracle.ts +145 -0
- package/src/evm/helpers.ts +73 -0
- package/src/evm/index.ts +4 -0
- package/src/evm/toolbox/baseEVMToolbox.ts +695 -0
- package/src/evm/toolbox/evm.ts +67 -0
- package/src/evm/toolbox/index.ts +44 -0
- package/src/evm/toolbox/op.ts +156 -0
- package/src/evm/types.ts +146 -0
- package/src/index.ts +260 -0
- package/src/near/__tests__/core.test.ts +70 -0
- package/src/near/helpers/core.ts +85 -0
- package/src/near/helpers/gasEstimation.ts +96 -0
- package/src/near/helpers/nep141.ts +50 -0
- package/src/near/index.ts +21 -0
- package/src/near/toolbox.ts +421 -0
- package/src/near/types/contract.ts +32 -0
- package/src/near/types/nep141.ts +34 -0
- package/src/near/types/toolbox.ts +55 -0
- package/src/near/types.ts +44 -0
- package/src/radix/index.ts +132 -0
- package/src/ripple/index.ts +179 -0
- package/src/solana/index.ts +36 -0
- package/src/solana/toolbox.ts +415 -0
- package/src/substrate/balance.ts +88 -0
- package/src/substrate/index.ts +2 -0
- package/src/substrate/substrate.ts +281 -0
- package/src/substrate/types.ts +115 -0
- package/src/sui/__tests__/toolbox.test.ts +82 -0
- package/src/sui/index.ts +2 -0
- package/src/sui/toolbox.ts +165 -0
- package/src/sui/types.ts +11 -0
- package/src/ton/__tests__/toolbox.test.ts +63 -0
- package/src/ton/index.ts +2 -0
- package/src/ton/toolbox.ts +136 -0
- package/src/ton/types.ts +13 -0
- package/src/tron/__tests__/toolbox.test.ts +221 -0
- package/src/tron/helpers/trc20.abi.ts +107 -0
- package/src/tron/helpers/trongrid.ts +53 -0
- package/src/tron/index.ts +21 -0
- package/src/tron/toolbox.ts +585 -0
- package/src/tron/types.ts +83 -0
- package/src/types.ts +28 -0
- package/src/utils.ts +27 -0
- package/src/utxo/__tests__/zcash-integration.test.ts +97 -0
- package/src/utxo/helpers/api.ts +471 -0
- package/src/utxo/helpers/bchaddrjs.ts +166 -0
- package/src/utxo/helpers/coinselect.ts +92 -0
- package/src/utxo/helpers/index.ts +4 -0
- package/src/utxo/helpers/txSize.ts +137 -0
- package/src/utxo/index.ts +6 -0
- package/src/utxo/toolbox/bitcoinCash.ts +243 -0
- package/src/utxo/toolbox/index.ts +59 -0
- package/src/utxo/toolbox/params.ts +18 -0
- package/src/utxo/toolbox/utxo.ts +439 -0
- package/src/utxo/toolbox/validators.ts +36 -0
- package/src/utxo/toolbox/zcash.ts +245 -0
- package/src/utxo/types.ts +39 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { AssetValue, Chain } from "@uswap/helpers";
|
|
3
|
+
import { getTONToolbox } from "../toolbox";
|
|
4
|
+
|
|
5
|
+
const TEST_PHRASE = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
6
|
+
const KNOWN_TON_ADDRESS = "EQCC1GV4iL5EkQqICYshf3AF7ESbceCYhVK-go1SkOMOBTNE";
|
|
7
|
+
|
|
8
|
+
const context: { toolbox: Awaited<ReturnType<typeof getTONToolbox>> } = {} as any;
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
context.toolbox = await getTONToolbox({ phrase: TEST_PHRASE });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("TON Toolbox", () => {
|
|
15
|
+
test("should validate valid TON addresses", () => {
|
|
16
|
+
const validAddresses = [KNOWN_TON_ADDRESS, "EQBvW8Z5huBkMJYdnfAEM5JqTNkuWX3diqYENkWsIL0XggGG"];
|
|
17
|
+
|
|
18
|
+
for (const address of validAddresses) {
|
|
19
|
+
expect(context.toolbox.validateAddress(address)).toBe(true);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("should reject invalid TON addresses", () => {
|
|
24
|
+
const invalidAddresses = [
|
|
25
|
+
"",
|
|
26
|
+
"invalid",
|
|
27
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
28
|
+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
29
|
+
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
for (const address of invalidAddresses) {
|
|
33
|
+
expect(context.toolbox.validateAddress(address)).toBe(false);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("should generate valid TON address from phrase", () => {
|
|
38
|
+
const address = context.toolbox.getAddress();
|
|
39
|
+
expect(context.toolbox.validateAddress(address)).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("should fetch balance for known address", async () => {
|
|
43
|
+
const balances = await context.toolbox.getBalance(KNOWN_TON_ADDRESS);
|
|
44
|
+
expect(balances[0]?.chain).toBe(Chain.Ton);
|
|
45
|
+
expect(balances[0]?.symbol).toBe("TON");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("should estimate transaction fee", async () => {
|
|
49
|
+
const fee = await context.toolbox.estimateTransactionFee();
|
|
50
|
+
expect(fee.chain).toBe(Chain.Ton);
|
|
51
|
+
expect(fee.getValue("number")).toBeGreaterThan(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("should create transaction without broadcasting", async () => {
|
|
55
|
+
const transferCell = await context.toolbox.createTransaction({
|
|
56
|
+
assetValue: AssetValue.from({ chain: Chain.Ton, value: "0.001" }),
|
|
57
|
+
recipient: KNOWN_TON_ADDRESS,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const hash = transferCell.hash().toString("hex");
|
|
61
|
+
expect(hash.length).toBeGreaterThan(0);
|
|
62
|
+
});
|
|
63
|
+
});
|
package/src/ton/index.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Cell, OpenedContract, TonClient, WalletContractV4 } from "@ton/ton";
|
|
2
|
+
import { AssetValue, Chain, getChainConfig, SwapKitError, SwapKitNumber } from "@uswap/helpers";
|
|
3
|
+
import { match, P } from "ts-pattern";
|
|
4
|
+
|
|
5
|
+
import type { TONSigner, TONToolboxParams, TONTransferParams } from "./types";
|
|
6
|
+
|
|
7
|
+
export async function getTONToolbox(toolboxParams: TONToolboxParams = {}) {
|
|
8
|
+
const { mnemonicToWalletKey } = await import("@ton/crypto");
|
|
9
|
+
const { Address, TonClient, WalletContractV4 } = await import("@ton/ton");
|
|
10
|
+
const validateAddress = await getTONAddressValidator();
|
|
11
|
+
let client: TonClient;
|
|
12
|
+
let wallet: OpenedContract<WalletContractV4>;
|
|
13
|
+
|
|
14
|
+
const signer = await match(toolboxParams)
|
|
15
|
+
.with({ phrase: P.string }, async ({ phrase }) => mnemonicToWalletKey(phrase.split(" ")))
|
|
16
|
+
.with({ signer: P.any }, ({ signer }) => signer as TONSigner)
|
|
17
|
+
.otherwise(() => undefined);
|
|
18
|
+
|
|
19
|
+
function getClient() {
|
|
20
|
+
const { rpcUrls } = getChainConfig(Chain.Ton);
|
|
21
|
+
const [endpoint] = rpcUrls;
|
|
22
|
+
|
|
23
|
+
if (!client || client.parameters.endpoint !== endpoint) {
|
|
24
|
+
client = new TonClient({ endpoint });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getWallet(paramSigner?: TONSigner) {
|
|
31
|
+
if (!wallet || paramSigner) {
|
|
32
|
+
const client = getClient();
|
|
33
|
+
const walletSigner = paramSigner || signer;
|
|
34
|
+
|
|
35
|
+
if (!walletSigner) {
|
|
36
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const walletContract = WalletContractV4.create({ publicKey: walletSigner.publicKey, workchain: 0 });
|
|
40
|
+
const contract = client.open(walletContract);
|
|
41
|
+
|
|
42
|
+
wallet = contract;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return wallet;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function getBalance(address: string) {
|
|
49
|
+
const client = getClient();
|
|
50
|
+
const { baseDecimal } = getChainConfig(Chain.Ton);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const balance = await client.getBalance(Address.parse(address));
|
|
54
|
+
return [AssetValue.from({ chain: Chain.Ton, value: SwapKitNumber.fromBigInt(balance, baseDecimal) })];
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new SwapKitError("core_wallet_connection_not_found", { error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function createTransaction({ assetValue, recipient, memo }: TONTransferParams) {
|
|
61
|
+
const wallet = getWallet();
|
|
62
|
+
if (!wallet || !signer) {
|
|
63
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { toNano, comment, internal } = await import("@ton/ton");
|
|
67
|
+
const seqno = await wallet.getSeqno();
|
|
68
|
+
const amount = toNano(assetValue.getValue("string"));
|
|
69
|
+
const messageBody = memo ? comment(memo) : undefined;
|
|
70
|
+
|
|
71
|
+
const transfer = wallet.createTransfer({
|
|
72
|
+
messages: [internal({ body: messageBody, to: recipient, value: amount })],
|
|
73
|
+
secretKey: signer.secretKey,
|
|
74
|
+
seqno,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return transfer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function transfer({ assetValue, recipient, memo }: TONTransferParams) {
|
|
81
|
+
const wallet = getWallet();
|
|
82
|
+
if (!wallet || !signer) {
|
|
83
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const transfer = await createTransaction({ assetValue, memo, recipient });
|
|
87
|
+
await wallet.send(transfer);
|
|
88
|
+
|
|
89
|
+
return transfer.hash().toString();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function sendTransaction(transferCell: Cell) {
|
|
93
|
+
const wallet = getWallet();
|
|
94
|
+
if (!wallet) {
|
|
95
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await wallet.send(transferCell);
|
|
100
|
+
return transferCell.hash().toString("hex");
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new SwapKitError("core_wallet_connection_not_found", { error });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getAddress() {
|
|
107
|
+
const wallet = getWallet();
|
|
108
|
+
return wallet.address.toString();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function estimateTransactionFee() {
|
|
112
|
+
return Promise.resolve(AssetValue.from({ chain: Chain.Ton, value: "0.0001" }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
createTransaction,
|
|
117
|
+
estimateTransactionFee,
|
|
118
|
+
getAddress,
|
|
119
|
+
getBalance,
|
|
120
|
+
sendTransaction,
|
|
121
|
+
transfer,
|
|
122
|
+
validateAddress,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function getTONAddressValidator() {
|
|
127
|
+
const { Address } = await import("@ton/ton");
|
|
128
|
+
return function validateAddress(address: string) {
|
|
129
|
+
try {
|
|
130
|
+
Address.parse(address);
|
|
131
|
+
return true;
|
|
132
|
+
} catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
package/src/ton/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AssetValue, DerivationPathArray, GenericTransferParams } from "@uswap/helpers";
|
|
2
|
+
import type { getTONToolbox } from "./toolbox";
|
|
3
|
+
|
|
4
|
+
export type TONSigner = { publicKey: any; secretKey: any };
|
|
5
|
+
|
|
6
|
+
export type TONToolboxParams = { provider?: string } & (
|
|
7
|
+
| { signer?: TONSigner }
|
|
8
|
+
| { phrase?: string; derivationPath?: DerivationPathArray; index?: number }
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export type TONTransferParams = GenericTransferParams & { assetValue: AssetValue; recipient: string; memo?: string };
|
|
12
|
+
|
|
13
|
+
export type TONWallet = Awaited<ReturnType<typeof getTONToolbox>>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { AssetValue, Chain, SKConfig } from "@uswap/helpers";
|
|
3
|
+
import { createTronToolbox, getTronAddressValidator } from "../toolbox";
|
|
4
|
+
|
|
5
|
+
const context: {
|
|
6
|
+
toolbox: Awaited<ReturnType<typeof createTronToolbox>>;
|
|
7
|
+
validateAddress: (address: string) => boolean;
|
|
8
|
+
} = {} as any;
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
context.validateAddress = await getTronAddressValidator();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
context.toolbox = await createTronToolbox({ phrase: process.env.TEST_PHRASE });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => {
|
|
19
|
+
SKConfig.reinitialize();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("TRON Address Validation", () => {
|
|
23
|
+
test("should validate valid TRON addresses", () => {
|
|
24
|
+
const validAddresses = [
|
|
25
|
+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // USDT contract
|
|
26
|
+
"TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7", // Mainnet address
|
|
27
|
+
"TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE", // Another valid address
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
for (const address of validAddresses) {
|
|
31
|
+
expect(context.validateAddress(address)).toBe(true);
|
|
32
|
+
expect(context.toolbox.validateAddress(address)).toBe(true);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("should reject invalid TRON addresses", () => {
|
|
37
|
+
const invalidAddresses = [
|
|
38
|
+
"",
|
|
39
|
+
"invalid",
|
|
40
|
+
"0x742d35Cc6648C532F5e7c3d2a7a8E1e1e5b7c8D3",
|
|
41
|
+
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
|
|
42
|
+
"cosmos1abc123",
|
|
43
|
+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6",
|
|
44
|
+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6tt",
|
|
45
|
+
"XR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
46
|
+
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6O",
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
for (const address of invalidAddresses) {
|
|
50
|
+
expect(context.validateAddress(address)).toBe(false);
|
|
51
|
+
expect(context.toolbox.validateAddress(address)).toBe(false);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("should create TRON transaction with valid addresses", async () => {
|
|
56
|
+
const toolbox = context.toolbox;
|
|
57
|
+
const fromAddress = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE";
|
|
58
|
+
const toAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
|
|
59
|
+
|
|
60
|
+
expect(toolbox.validateAddress(fromAddress)).toBe(true);
|
|
61
|
+
expect(toolbox.validateAddress(toAddress)).toBe(true);
|
|
62
|
+
|
|
63
|
+
const transaction = await toolbox.createTransaction({
|
|
64
|
+
assetValue: AssetValue.from({
|
|
65
|
+
chain: Chain.Tron,
|
|
66
|
+
value: "1", // 1 TRX
|
|
67
|
+
}),
|
|
68
|
+
recipient: toAddress,
|
|
69
|
+
sender: fromAddress,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(transaction).toBeDefined();
|
|
73
|
+
expect(transaction.raw_data_hex).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("should create TRON.USDT transaction with valid addresses", async () => {
|
|
77
|
+
const toolbox = context.toolbox;
|
|
78
|
+
const fromAddress = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE";
|
|
79
|
+
const toAddress = "TT87ESmqUmH87hMx1MKCEqYrJKaQyNg9ao";
|
|
80
|
+
|
|
81
|
+
expect(toolbox.validateAddress(fromAddress)).toBe(true);
|
|
82
|
+
expect(toolbox.validateAddress(toAddress)).toBe(true);
|
|
83
|
+
|
|
84
|
+
// Create a transaction
|
|
85
|
+
const transaction = await toolbox.createTransaction({
|
|
86
|
+
assetValue: AssetValue.from({
|
|
87
|
+
asset: "TRON.USDT-TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
88
|
+
value: "100", // 1 TRX
|
|
89
|
+
}),
|
|
90
|
+
recipient: toAddress,
|
|
91
|
+
sender: fromAddress,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(transaction).toBeDefined();
|
|
95
|
+
expect(transaction.raw_data_hex).toBeDefined();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("should handle case sensitivity in addresses", () => {
|
|
99
|
+
const address = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
|
|
100
|
+
const lowerCase = address.toLowerCase();
|
|
101
|
+
const upperCase = address.toUpperCase();
|
|
102
|
+
|
|
103
|
+
expect(context.validateAddress(address)).toBe(true);
|
|
104
|
+
expect(context.validateAddress(lowerCase)).toBe(false);
|
|
105
|
+
expect(context.validateAddress(upperCase)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("should handle edge cases", () => {
|
|
109
|
+
const edgeCases = [null, undefined, 123, {}, [], true, false];
|
|
110
|
+
|
|
111
|
+
for (const testCase of edgeCases) {
|
|
112
|
+
expect(context.validateAddress(testCase as any)).toBe(false);
|
|
113
|
+
expect(context.toolbox.validateAddress(testCase as any)).toBe(false);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("TRON createTransaction with Extended Expiration", () => {
|
|
119
|
+
const baseExpiration = 60; // default is 60s
|
|
120
|
+
const extendedExpiration = 240; // Adding 240 for 5 minutes total
|
|
121
|
+
const fromAddress = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE";
|
|
122
|
+
const toAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
|
|
123
|
+
const buffer = 10000;
|
|
124
|
+
const memo = "Test transfer with memo";
|
|
125
|
+
|
|
126
|
+
test("should create native TRX transfer with extended expiration", async () => {
|
|
127
|
+
const toolbox = context.toolbox;
|
|
128
|
+
const beforeTimestamp = Date.now();
|
|
129
|
+
|
|
130
|
+
const transaction = await toolbox.createTransaction({
|
|
131
|
+
assetValue: AssetValue.from({
|
|
132
|
+
chain: Chain.Tron,
|
|
133
|
+
value: "1", // 1 TRX
|
|
134
|
+
}),
|
|
135
|
+
expiration: extendedExpiration,
|
|
136
|
+
recipient: toAddress,
|
|
137
|
+
sender: fromAddress,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(transaction.raw_data.expiration).toBeDefined();
|
|
141
|
+
|
|
142
|
+
const expectedExpiration = beforeTimestamp + (baseExpiration + extendedExpiration) * 1000;
|
|
143
|
+
const actualExpiration = transaction.raw_data.expiration;
|
|
144
|
+
|
|
145
|
+
expect(actualExpiration).toBeGreaterThanOrEqual(expectedExpiration - buffer);
|
|
146
|
+
expect(actualExpiration).toBeLessThanOrEqual(expectedExpiration + buffer);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("should create native TRX transfer with extended expiration and memo", async () => {
|
|
150
|
+
const toolbox = context.toolbox;
|
|
151
|
+
const beforeTimestamp = Date.now();
|
|
152
|
+
|
|
153
|
+
const transaction = await toolbox.createTransaction({
|
|
154
|
+
assetValue: AssetValue.from({
|
|
155
|
+
chain: Chain.Tron,
|
|
156
|
+
value: "1", // 1 TRX
|
|
157
|
+
}),
|
|
158
|
+
expiration: extendedExpiration,
|
|
159
|
+
memo,
|
|
160
|
+
recipient: toAddress,
|
|
161
|
+
sender: fromAddress,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(transaction.raw_data.expiration).toBeDefined();
|
|
165
|
+
|
|
166
|
+
const expectedExpiration = beforeTimestamp + (baseExpiration + extendedExpiration) * 1000;
|
|
167
|
+
const actualExpiration = transaction.raw_data.expiration;
|
|
168
|
+
|
|
169
|
+
expect(actualExpiration).toBeGreaterThanOrEqual(expectedExpiration - buffer);
|
|
170
|
+
expect(actualExpiration).toBeLessThanOrEqual(expectedExpiration + buffer);
|
|
171
|
+
|
|
172
|
+
expect(transaction.raw_data.data).toBeDefined();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("should create token transfer with extended expiration", async () => {
|
|
176
|
+
const toolbox = context.toolbox;
|
|
177
|
+
const beforeTimestamp = Date.now();
|
|
178
|
+
|
|
179
|
+
const transaction = await toolbox.createTransaction({
|
|
180
|
+
assetValue: AssetValue.from({
|
|
181
|
+
asset: "TRON.USDT-TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
182
|
+
value: "100", // 100 USDT
|
|
183
|
+
}),
|
|
184
|
+
expiration: extendedExpiration,
|
|
185
|
+
recipient: toAddress,
|
|
186
|
+
sender: fromAddress,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(transaction.raw_data.expiration).toBeDefined();
|
|
190
|
+
|
|
191
|
+
const expectedExpiration = beforeTimestamp + (baseExpiration + extendedExpiration) * 1000;
|
|
192
|
+
const actualExpiration = transaction.raw_data.expiration;
|
|
193
|
+
|
|
194
|
+
// Allow 10 second tolerance for test execution time
|
|
195
|
+
expect(actualExpiration).toBeGreaterThanOrEqual(expectedExpiration - buffer);
|
|
196
|
+
expect(actualExpiration).toBeLessThanOrEqual(expectedExpiration + buffer);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("should create token transfer with extended expiration and memo", async () => {
|
|
200
|
+
const toolbox = context.toolbox;
|
|
201
|
+
const beforeTimestamp = Date.now();
|
|
202
|
+
|
|
203
|
+
const transaction = await toolbox.createTransaction({
|
|
204
|
+
assetValue: AssetValue.from({
|
|
205
|
+
asset: "TRON.USDT-TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
206
|
+
value: "100", // 100 USDT
|
|
207
|
+
}),
|
|
208
|
+
expiration: extendedExpiration,
|
|
209
|
+
memo,
|
|
210
|
+
recipient: toAddress,
|
|
211
|
+
sender: fromAddress,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const expectedExpiration = beforeTimestamp + (baseExpiration + extendedExpiration) * 1000;
|
|
215
|
+
const actualExpiration = transaction.raw_data.expiration;
|
|
216
|
+
|
|
217
|
+
expect(actualExpiration).toBeGreaterThanOrEqual(expectedExpiration - buffer);
|
|
218
|
+
expect(actualExpiration).toBeLessThanOrEqual(expectedExpiration + buffer);
|
|
219
|
+
expect(transaction.raw_data).toMatchObject({ data: expect.any(String), expiration: expect.any(Number) });
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const trc20ABI = [
|
|
2
|
+
{
|
|
3
|
+
constant: true,
|
|
4
|
+
inputs: [{ name: "_owner", type: "address" }],
|
|
5
|
+
name: "balanceOf",
|
|
6
|
+
outputs: [{ name: "balance", type: "uint256" }],
|
|
7
|
+
stateMutability: "view",
|
|
8
|
+
type: "function",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
constant: false,
|
|
12
|
+
inputs: [
|
|
13
|
+
{ name: "_to", type: "address" },
|
|
14
|
+
{ name: "_value", type: "uint256" },
|
|
15
|
+
],
|
|
16
|
+
name: "transfer",
|
|
17
|
+
outputs: [{ name: "success", type: "bool" }],
|
|
18
|
+
stateMutability: "nonpayable",
|
|
19
|
+
type: "function",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
constant: true,
|
|
23
|
+
inputs: [],
|
|
24
|
+
name: "decimals",
|
|
25
|
+
outputs: [{ name: "", type: "uint8" }],
|
|
26
|
+
stateMutability: "view",
|
|
27
|
+
type: "function",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
constant: true,
|
|
31
|
+
inputs: [],
|
|
32
|
+
name: "symbol",
|
|
33
|
+
outputs: [{ name: "", type: "string" }],
|
|
34
|
+
stateMutability: "view",
|
|
35
|
+
type: "function",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
constant: true,
|
|
39
|
+
inputs: [],
|
|
40
|
+
name: "name",
|
|
41
|
+
outputs: [{ name: "", type: "string" }],
|
|
42
|
+
stateMutability: "view",
|
|
43
|
+
type: "function",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
constant: true,
|
|
47
|
+
inputs: [
|
|
48
|
+
{ name: "_owner", type: "address" },
|
|
49
|
+
{ name: "_spender", type: "address" },
|
|
50
|
+
],
|
|
51
|
+
name: "allowance",
|
|
52
|
+
outputs: [{ name: "remaining", type: "uint256" }],
|
|
53
|
+
stateMutability: "view",
|
|
54
|
+
type: "function",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
constant: false,
|
|
58
|
+
inputs: [
|
|
59
|
+
{ name: "_spender", type: "address" },
|
|
60
|
+
{ name: "_value", type: "uint256" },
|
|
61
|
+
],
|
|
62
|
+
name: "approve",
|
|
63
|
+
outputs: [{ name: "success", type: "bool" }],
|
|
64
|
+
stateMutability: "nonpayable",
|
|
65
|
+
type: "function",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
constant: true,
|
|
69
|
+
inputs: [],
|
|
70
|
+
name: "totalSupply",
|
|
71
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
72
|
+
stateMutability: "view",
|
|
73
|
+
type: "function",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
constant: false,
|
|
77
|
+
inputs: [
|
|
78
|
+
{ name: "_from", type: "address" },
|
|
79
|
+
{ name: "_to", type: "address" },
|
|
80
|
+
{ name: "_value", type: "uint256" },
|
|
81
|
+
],
|
|
82
|
+
name: "transferFrom",
|
|
83
|
+
outputs: [{ name: "success", type: "bool" }],
|
|
84
|
+
stateMutability: "nonpayable",
|
|
85
|
+
type: "function",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
anonymous: false,
|
|
89
|
+
inputs: [
|
|
90
|
+
{ indexed: true, name: "_from", type: "address" },
|
|
91
|
+
{ indexed: true, name: "_to", type: "address" },
|
|
92
|
+
{ indexed: false, name: "_value", type: "uint256" },
|
|
93
|
+
],
|
|
94
|
+
name: "Transfer",
|
|
95
|
+
type: "event",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
anonymous: false,
|
|
99
|
+
inputs: [
|
|
100
|
+
{ indexed: true, name: "_owner", type: "address" },
|
|
101
|
+
{ indexed: true, name: "_spender", type: "address" },
|
|
102
|
+
{ indexed: false, name: "_value", type: "uint256" },
|
|
103
|
+
],
|
|
104
|
+
name: "Approval",
|
|
105
|
+
type: "event",
|
|
106
|
+
},
|
|
107
|
+
] as const;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SwapKitError } from "@uswap/helpers";
|
|
2
|
+
import type { TronGridAccountResponse } from "../types";
|
|
3
|
+
|
|
4
|
+
const TRONGRID_API_BASE = "https://api.trongrid.io";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetch account information including TRC20 balances from TronGrid API
|
|
8
|
+
*/
|
|
9
|
+
export async function fetchAccountFromTronGrid(address: string) {
|
|
10
|
+
const TW = await import("tronweb");
|
|
11
|
+
const TronWeb = TW.TronWeb ?? TW.default?.TronWeb;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(`${TRONGRID_API_BASE}/v1/accounts/${address}`);
|
|
15
|
+
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`TronGrid API error: ${response.status} ${response.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const data = (await response.json()) as TronGridAccountResponse;
|
|
21
|
+
|
|
22
|
+
if (!(data.success && data.data) || data.data.length === 0) {
|
|
23
|
+
throw new Error("Invalid response from TronGrid API");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Convert search address to hex format for comparison
|
|
27
|
+
let searchAddressHex: string;
|
|
28
|
+
try {
|
|
29
|
+
// If address is base58, convert to hex
|
|
30
|
+
searchAddressHex = TronWeb.address.toHex(address).toLowerCase();
|
|
31
|
+
} catch {
|
|
32
|
+
// If conversion fails, assume it's already hex
|
|
33
|
+
searchAddressHex = address.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Find the account that matches the requested address
|
|
37
|
+
const account = data.data.find((acc) => {
|
|
38
|
+
return acc.address.toLowerCase() === searchAddressHex;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!account) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Return simplified object with balance and trc20 array
|
|
46
|
+
return { balance: account.balance, trc20: account.trc20 || [] };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new SwapKitError("toolbox_tron_trongrid_api_error", {
|
|
49
|
+
address,
|
|
50
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { trc20ABI } from "./helpers/trc20.abi";
|
|
2
|
+
export {
|
|
3
|
+
createTronToolbox,
|
|
4
|
+
getTronAddressValidator,
|
|
5
|
+
getTronPrivateKeyFromMnemonic,
|
|
6
|
+
} from "./toolbox";
|
|
7
|
+
export type {
|
|
8
|
+
TronApprovedParams,
|
|
9
|
+
TronApproveParams,
|
|
10
|
+
TronContract,
|
|
11
|
+
TronCreateTransactionParams,
|
|
12
|
+
TronIsApprovedParams,
|
|
13
|
+
TronSignedTransaction,
|
|
14
|
+
TronSigner,
|
|
15
|
+
TronToolboxOptions,
|
|
16
|
+
TronTransaction,
|
|
17
|
+
TronTransferParams,
|
|
18
|
+
} from "./types";
|
|
19
|
+
|
|
20
|
+
import type { createTronToolbox } from "./toolbox";
|
|
21
|
+
export type TronWallet = Awaited<ReturnType<typeof createTronToolbox>>;
|