@bankofai/mcp-server-tron 1.1.1

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +312 -0
  3. package/bin/cli.js +51 -0
  4. package/build/core/chains.d.ts +17 -0
  5. package/build/core/chains.js +55 -0
  6. package/build/core/chains.js.map +1 -0
  7. package/build/core/prompts.d.ts +16 -0
  8. package/build/core/prompts.js +468 -0
  9. package/build/core/prompts.js.map +1 -0
  10. package/build/core/resources.d.ts +14 -0
  11. package/build/core/resources.js +42 -0
  12. package/build/core/resources.js.map +1 -0
  13. package/build/core/services/address.d.ts +8 -0
  14. package/build/core/services/address.js +52 -0
  15. package/build/core/services/address.js.map +1 -0
  16. package/build/core/services/balance.d.ts +26 -0
  17. package/build/core/services/balance.js +60 -0
  18. package/build/core/services/balance.js.map +1 -0
  19. package/build/core/services/blocks.d.ts +16 -0
  20. package/build/core/services/blocks.js +46 -0
  21. package/build/core/services/blocks.js.map +1 -0
  22. package/build/core/services/clients.d.ts +9 -0
  23. package/build/core/services/clients.js +46 -0
  24. package/build/core/services/clients.js.map +1 -0
  25. package/build/core/services/contracts.d.ts +50 -0
  26. package/build/core/services/contracts.js +225 -0
  27. package/build/core/services/contracts.js.map +1 -0
  28. package/build/core/services/index.d.ts +119 -0
  29. package/build/core/services/index.js +39 -0
  30. package/build/core/services/index.js.map +1 -0
  31. package/build/core/services/multicall-abi.d.ts +55 -0
  32. package/build/core/services/multicall-abi.js +61 -0
  33. package/build/core/services/multicall-abi.js.map +1 -0
  34. package/build/core/services/tokens.d.ts +22 -0
  35. package/build/core/services/tokens.js +68 -0
  36. package/build/core/services/tokens.js.map +1 -0
  37. package/build/core/services/transactions.d.ts +16 -0
  38. package/build/core/services/transactions.js +42 -0
  39. package/build/core/services/transactions.js.map +1 -0
  40. package/build/core/services/transfer.d.ts +24 -0
  41. package/build/core/services/transfer.js +70 -0
  42. package/build/core/services/transfer.js.map +1 -0
  43. package/build/core/services/utils.d.ts +13 -0
  44. package/build/core/services/utils.js +39 -0
  45. package/build/core/services/utils.js.map +1 -0
  46. package/build/core/services/wallet.d.ts +33 -0
  47. package/build/core/services/wallet.js +113 -0
  48. package/build/core/services/wallet.js.map +1 -0
  49. package/build/core/tools.d.ts +16 -0
  50. package/build/core/tools.js +792 -0
  51. package/build/core/tools.js.map +1 -0
  52. package/build/index.d.ts +1 -0
  53. package/build/index.js +20 -0
  54. package/build/index.js.map +1 -0
  55. package/build/server/http-server.d.ts +1 -0
  56. package/build/server/http-server.js +197 -0
  57. package/build/server/http-server.js.map +1 -0
  58. package/build/server/server.d.ts +3 -0
  59. package/build/server/server.js +46 -0
  60. package/build/server/server.js.map +1 -0
  61. package/package.json +91 -0
@@ -0,0 +1,60 @@
1
+ import { getTronWeb } from "./clients.js";
2
+ import { utils } from "./utils.js";
3
+ /**
4
+ * Get TRX balance for an address
5
+ */
6
+ export async function getTRXBalance(address, network = "mainnet") {
7
+ const tronWeb = getTronWeb(network);
8
+ const balanceSun = await tronWeb.trx.getBalance(address);
9
+ return {
10
+ wei: BigInt(balanceSun), // Keeping 'wei' property name for compatibility if tools rely on it, but strictly it's Sun
11
+ ether: utils.fromSun(balanceSun), // 'ether' -> TRX
12
+ formatted: utils.fromSun(balanceSun),
13
+ symbol: "TRX",
14
+ decimals: 6,
15
+ };
16
+ }
17
+ /**
18
+ * Get TRC20 token balance
19
+ */
20
+ export async function getTRC20Balance(tokenAddress, walletAddress, network = "mainnet") {
21
+ const tronWeb = getTronWeb(network);
22
+ try {
23
+ const contract = await tronWeb.contract().at(tokenAddress);
24
+ // TRC20 standard functions
25
+ const balance = await contract.methods.balanceOf(walletAddress).call();
26
+ const decimals = await contract.methods.decimals().call();
27
+ const symbol = await contract.methods.symbol().call();
28
+ const balanceBigInt = BigInt(balance.toString());
29
+ const divisor = BigInt(10) ** BigInt(decimals.toString());
30
+ // Basic formatting
31
+ const formatted = (Number(balanceBigInt) / Number(divisor)).toString();
32
+ return {
33
+ raw: balanceBigInt,
34
+ formatted: formatted,
35
+ token: {
36
+ symbol: symbol,
37
+ decimals: Number(decimals),
38
+ address: tokenAddress,
39
+ },
40
+ };
41
+ }
42
+ catch (error) {
43
+ throw new Error(`Failed to get TRC20 balance: ${error.message}`);
44
+ }
45
+ }
46
+ /**
47
+ * Get TRC1155 balance
48
+ */
49
+ export async function getTRC1155Balance(contractAddress, ownerAddress, tokenId, network = "mainnet") {
50
+ const tronWeb = getTronWeb(network);
51
+ try {
52
+ const contract = await tronWeb.contract().at(contractAddress);
53
+ const balance = await contract.methods.balanceOf(ownerAddress, tokenId.toString()).call();
54
+ return BigInt(balance.toString());
55
+ }
56
+ catch (error) {
57
+ throw new Error(`Failed to get TRC1155 balance: ${error.message}`);
58
+ }
59
+ }
60
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../../src/core/services/balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe,EAAE,OAAO,GAAG,SAAS;IACtE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,2FAA2F;QACpH,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,iBAAiB;QACnD,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QACpC,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,CAAC;KACZ,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAA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BAAiB,CACrC,eAAuB,EACvB,YAAoB,EACpB,OAAe,EACf,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1F,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ type Block = any;
2
+ /**
3
+ * Get block details by block number or hash
4
+ */
5
+ export declare function getBlockByNumber(blockNumber: number, network?: string): Promise<Block>;
6
+ export declare function getBlockByHash(blockHash: string, network?: string): Promise<Block>;
7
+ /**
8
+ * Get the latest block from the network
9
+ */
10
+ export declare function getLatestBlock(network?: string): Promise<Block>;
11
+ /**
12
+ * Get current block number
13
+ */
14
+ export declare function getBlockNumber(network?: string): Promise<number>;
15
+ export declare function getChainId(network?: string): Promise<number>;
16
+ export {};
@@ -0,0 +1,46 @@
1
+ import { getTronWeb } from "./clients.js";
2
+ /**
3
+ * Get block details by block number or hash
4
+ */
5
+ export async function getBlockByNumber(blockNumber, network = "mainnet") {
6
+ const tronWeb = getTronWeb(network);
7
+ const block = await tronWeb.trx.getBlock(blockNumber);
8
+ return block;
9
+ }
10
+ export async function getBlockByHash(blockHash, network = "mainnet") {
11
+ const tronWeb = getTronWeb(network);
12
+ const block = await tronWeb.trx.getBlock(blockHash);
13
+ return block;
14
+ }
15
+ /**
16
+ * Get the latest block from the network
17
+ */
18
+ export async function getLatestBlock(network = "mainnet") {
19
+ const tronWeb = getTronWeb(network);
20
+ const block = await tronWeb.trx.getCurrentBlock();
21
+ return block;
22
+ }
23
+ /**
24
+ * Get current block number
25
+ */
26
+ export async function getBlockNumber(network = "mainnet") {
27
+ const block = await getLatestBlock(network);
28
+ // Type assertion or checking structure; TronWeb block structure varies slightly by version/response
29
+ return block.block_header.raw_data.number;
30
+ }
31
+ // Chain ID is not standard in TronWeb like EVM, but we can return network ID or similar
32
+ // For compatibility with tool interface
33
+ export async function getChainId(network = "mainnet") {
34
+ // Tron Mainnet ID is often considered 0x2b6653dc (hex) or similar in some contexts,
35
+ // but typically we just return a placeholder or specific known ID if needed.
36
+ // FullNode info might have it.
37
+ // For now, mapping known networks to some integer IDs if needed, or just return 0
38
+ if (network === "mainnet")
39
+ return 728126428; // Tron Mainnet ID (often used)
40
+ if (network === "nile")
41
+ return 20191029; // Nile ID
42
+ if (network === "shasta")
43
+ return 1;
44
+ return 0;
45
+ }
46
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../../src/core/services/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,WAAmB,EAAE,OAAO,GAAG,SAAS;IAC7E,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB,EAAE,OAAO,GAAG,SAAS;IACzE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAO,GAAG,SAAS;IACtD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;IAClD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAO,GAAG,SAAS;IACtD,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;IAC5C,oGAAoG;IACpG,OAAQ,KAAa,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;AACrD,CAAC;AAED,wFAAwF;AACxF,wCAAwC;AACxC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAO,GAAG,SAAS;IAClD,oFAAoF;IACpF,6EAA6E;IAC7E,+BAA+B;IAE/B,kFAAkF;IAClF,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,CAAC,+BAA+B;IAC5E,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,QAAQ,CAAC,CAAC,UAAU;IACnD,IAAI,OAAO,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { TronWeb } from "tronweb";
2
+ /**
3
+ * Get a TronWeb instance for a specific network
4
+ */
5
+ export declare function getTronWeb(network?: string): TronWeb;
6
+ /**
7
+ * Create a TronWeb instance with a private key for signing
8
+ */
9
+ export declare function getWallet(privateKey: string, network?: string): TronWeb;
@@ -0,0 +1,46 @@
1
+ import { TronWeb } from "tronweb";
2
+ import { getNetworkConfig } from "../chains.js";
3
+ // Cache for clients to avoid recreating them for each request
4
+ const clientCache = new Map();
5
+ /**
6
+ * Get a TronWeb instance for a specific network
7
+ */
8
+ export function getTronWeb(network = "mainnet") {
9
+ const cacheKey = String(network);
10
+ // Return cached client if available
11
+ if (clientCache.has(cacheKey)) {
12
+ return clientCache.get(cacheKey);
13
+ }
14
+ // Create a new client
15
+ const config = getNetworkConfig(network);
16
+ const apiKey = process.env.TRONGRID_API_KEY;
17
+ const client = new TronWeb({
18
+ fullHost: config.fullNode,
19
+ solidityNode: config.solidityNode,
20
+ eventServer: config.eventServer,
21
+ headers: apiKey ? { "TRON-PRO-API-KEY": apiKey } : undefined,
22
+ });
23
+ // Set a default address for read-only calls that might require it
24
+ client.setAddress("T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb");
25
+ // Cache the client
26
+ clientCache.set(cacheKey, client);
27
+ return client;
28
+ }
29
+ /**
30
+ * Create a TronWeb instance with a private key for signing
31
+ */
32
+ export function getWallet(privateKey, network = "mainnet") {
33
+ const config = getNetworkConfig(network);
34
+ const apiKey = process.env.TRONGRID_API_KEY;
35
+ // TronWeb expects private key without 0x prefix usually, but handles it if present?
36
+ // Let's strip 0x to be safe as TronWeb often prefers clean hex
37
+ const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
38
+ return new TronWeb({
39
+ fullHost: config.fullNode,
40
+ solidityNode: config.solidityNode,
41
+ eventServer: config.eventServer,
42
+ privateKey: cleanKey,
43
+ headers: apiKey ? { "TRON-PRO-API-KEY": apiKey } : undefined,
44
+ });
45
+ }
46
+ //# sourceMappingURL=clients.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/core/services/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,UAA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AAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Read from a smart contract (view/pure functions)
3
+ */
4
+ export declare function readContract(params: {
5
+ address: string;
6
+ functionName: string;
7
+ args?: any[];
8
+ abi?: any[];
9
+ }, network?: string): Promise<any>;
10
+ /**
11
+ * Write to a smart contract (state changing functions)
12
+ */
13
+ export declare function writeContract(privateKey: string, params: {
14
+ address: string;
15
+ functionName: string;
16
+ args?: any[];
17
+ value?: string;
18
+ abi?: any[];
19
+ }, network?: string): Promise<any>;
20
+ /**
21
+ * Fetch contract ABI via TronWeb (available for verified contracts)
22
+ */
23
+ export declare function fetchContractABI(contractAddress: string, network?: string): Promise<any>;
24
+ /**
25
+ * Parse ABI (helper to ensure correct format for TronWeb if needed)
26
+ */
27
+ export declare function parseABI(abiJson: string | any[]): any[];
28
+ /**
29
+ * Get readable function signatures from ABI
30
+ */
31
+ export declare function getReadableFunctions(abi: any[]): string[];
32
+ /**
33
+ * Helper to get a specific function definition from ABI
34
+ */
35
+ export declare function getFunctionFromABI(abi: any[], functionName: string): any;
36
+ /**
37
+ * Multicall (Simulated or Native Multicall2/3)
38
+ */
39
+ export declare function multicall(params: {
40
+ calls: Array<{
41
+ address: string;
42
+ functionName: string;
43
+ args?: any[];
44
+ abi: any[];
45
+ allowFailure?: boolean;
46
+ }>;
47
+ multicallAddress?: string;
48
+ version?: 2 | 3;
49
+ allowFailure?: boolean;
50
+ }, network?: string): Promise<any>;
@@ -0,0 +1,225 @@
1
+ import { getTronWeb, getWallet } from "./clients.js";
2
+ import { MULTICALL2_ABI, MULTICALL3_ABI } from "./multicall-abi.js";
3
+ /**
4
+ * Read from a smart contract (view/pure functions)
5
+ */
6
+ export async function readContract(params, network = "mainnet") {
7
+ const tronWeb = getTronWeb(network);
8
+ try {
9
+ let contract;
10
+ if (params.abi) {
11
+ contract = tronWeb.contract(params.abi, params.address);
12
+ }
13
+ else {
14
+ contract = await tronWeb.contract().at(params.address);
15
+ }
16
+ const method = contract.methods[params.functionName];
17
+ if (!method) {
18
+ throw new Error(`Function ${params.functionName} not found in contract`);
19
+ }
20
+ const args = params.args || [];
21
+ const result = await method(...args).call();
22
+ return result;
23
+ }
24
+ catch (error) {
25
+ throw new Error(`Read contract failed: ${error.message}`);
26
+ }
27
+ }
28
+ /**
29
+ * Write to a smart contract (state changing functions)
30
+ */
31
+ export async function writeContract(privateKey, params, network = "mainnet") {
32
+ const tronWeb = getWallet(privateKey, network);
33
+ try {
34
+ let contract;
35
+ if (params.abi) {
36
+ contract = tronWeb.contract(params.abi, params.address);
37
+ }
38
+ else {
39
+ contract = await tronWeb.contract().at(params.address);
40
+ }
41
+ const method = contract.methods[params.functionName];
42
+ if (!method) {
43
+ throw new Error(`Function ${params.functionName} not found in contract`);
44
+ }
45
+ const args = params.args || [];
46
+ const options = {};
47
+ if (params.value) {
48
+ options.callValue = params.value;
49
+ }
50
+ const txId = await method(...args).send(options);
51
+ return txId;
52
+ }
53
+ catch (error) {
54
+ throw new Error(`Write contract failed: ${error.message}`);
55
+ }
56
+ }
57
+ /**
58
+ * Fetch contract ABI via TronWeb (available for verified contracts)
59
+ */
60
+ export async function fetchContractABI(contractAddress, network = "mainnet") {
61
+ const tronWeb = getTronWeb(network);
62
+ try {
63
+ const contract = await tronWeb.trx.getContract(contractAddress);
64
+ if (contract && contract.abi) {
65
+ return contract.abi.entrys;
66
+ }
67
+ throw new Error("ABI not found in contract data");
68
+ }
69
+ catch (error) {
70
+ throw new Error(`Failed to fetch ABI: ${error.message}`);
71
+ }
72
+ }
73
+ /**
74
+ * Parse ABI (helper to ensure correct format for TronWeb if needed)
75
+ */
76
+ export function parseABI(abiJson) {
77
+ if (typeof abiJson === "string") {
78
+ return JSON.parse(abiJson);
79
+ }
80
+ return abiJson;
81
+ }
82
+ /**
83
+ * Get readable function signatures from ABI
84
+ */
85
+ export function getReadableFunctions(abi) {
86
+ return abi
87
+ .filter((item) => item.type === "function")
88
+ .map((item) => {
89
+ const inputs = item.inputs
90
+ ? item.inputs.map((i) => `${i.type} ${i.name}`).join(", ")
91
+ : "";
92
+ const outputs = item.outputs
93
+ ? item.outputs.map((i) => `${i.type} ${i.name || ""}`).join(", ")
94
+ : "";
95
+ return `${item.name}(${inputs}) -> (${outputs})`;
96
+ });
97
+ }
98
+ /**
99
+ * Helper to get a specific function definition from ABI
100
+ */
101
+ export function getFunctionFromABI(abi, functionName) {
102
+ const func = abi.find((item) => item.type === "function" && item.name === functionName);
103
+ if (!func) {
104
+ throw new Error(`Function ${functionName} not found in ABI`);
105
+ }
106
+ return func;
107
+ }
108
+ /**
109
+ * Multicall (Simulated or Native Multicall2/3)
110
+ */
111
+ export async function multicall(params, network = "mainnet") {
112
+ const { calls, version = 3, allowFailure: globalAllowFailure = true } = params;
113
+ const mAddress = params.multicallAddress;
114
+ const fallbackToSimulation = async (error) => {
115
+ if (error)
116
+ console.error(`Multicall failed, falling back to simulation: ${error}`);
117
+ const results = await Promise.allSettled(calls.map((call) => readContract(call, network)));
118
+ return results.map((result, idx) => {
119
+ if (result.status === "fulfilled") {
120
+ return { success: true, result: result.value };
121
+ }
122
+ else {
123
+ return {
124
+ success: false,
125
+ error: `Call to ${calls[idx].functionName} failed: ${result.reason}`,
126
+ };
127
+ }
128
+ });
129
+ };
130
+ if (!mAddress) {
131
+ return fallbackToSimulation();
132
+ }
133
+ const tronWeb = getTronWeb(network);
134
+ try {
135
+ const callDataWithFuncs = calls.map((call) => {
136
+ const func = call.abi.find((i) => i.name === call.functionName && i.type === "function");
137
+ if (!func) {
138
+ throw new Error(`Function ${call.functionName} not found in ABI for ${call.address}`);
139
+ }
140
+ const inputs = func.inputs || [];
141
+ const types = inputs.map((i) => i.type);
142
+ const signature = `${call.functionName}(${types.join(",")})`;
143
+ const fullHash = tronWeb.sha3(signature);
144
+ const selector = fullHash.startsWith("0x")
145
+ ? fullHash.slice(0, 10)
146
+ : "0x" + fullHash.slice(0, 8);
147
+ const values = call.args || [];
148
+ const encodedArgs = tronWeb.utils.abi.encodeParams(types, values).replace(/^0x/, "");
149
+ const callData = selector + encodedArgs;
150
+ const callAllowFailure = call.allowFailure !== undefined ? call.allowFailure : globalAllowFailure;
151
+ return {
152
+ callData: version === 3 ? [call.address, callAllowFailure, callData] : [call.address, callData],
153
+ func,
154
+ };
155
+ });
156
+ const encodedCalls = callDataWithFuncs.map((item) => item.callData);
157
+ const multicallAbi = version === 3 ? MULTICALL3_ABI : MULTICALL2_ABI;
158
+ const method = version === 3 ? "aggregate3" : "tryAggregate";
159
+ const multicallArgs = version === 3 ? [encodedCalls] : [!globalAllowFailure, encodedCalls];
160
+ const contract = tronWeb.contract(multicallAbi, mAddress);
161
+ const results = await contract[method](...multicallArgs).call();
162
+ // TronWeb might wrap the result array in another array
163
+ const finalResults = Array.isArray(results) &&
164
+ results.length === 1 &&
165
+ Array.isArray(results[0]) &&
166
+ (Array.isArray(results[0][0]) || typeof results[0][0] === "object")
167
+ ? results[0]
168
+ : results;
169
+ return finalResults.map((res, index) => {
170
+ const success = res.success !== undefined ? res.success : res[0];
171
+ const returnData = res.returnData !== undefined ? res.returnData : res[1];
172
+ if (!success) {
173
+ return {
174
+ success: false,
175
+ error: `Call to ${calls[index].functionName} failed in multicall`,
176
+ };
177
+ }
178
+ const func = callDataWithFuncs[index].func;
179
+ const outputs = func.outputs || [];
180
+ const outputTypes = outputs.map((o) => o.type);
181
+ const outputNames = outputs.map((o) => o.name || "");
182
+ try {
183
+ const decoded = tronWeb.utils.abi.decodeParams(outputNames, outputTypes, returnData, true);
184
+ let result;
185
+ if (outputTypes.length === 1) {
186
+ if (typeof decoded === "object" && !Array.isArray(decoded)) {
187
+ // TronWeb decodeParams returns an object with both index keys and named keys
188
+ // For example: { "0": 123n, "timestamp": 123n }
189
+ // We want to return the raw value if it's a single output,
190
+ // but we need to be careful if the user expects the object structure.
191
+ // MCP tools usually prefer the raw value for single outputs for simplicity.
192
+ const entries = Object.entries(decoded);
193
+ const namedEntry = entries.find(([k]) => isNaN(Number(k)) && k !== "");
194
+ // If it's a single output AND it has a name, we return the WHOLE object
195
+ // so results[0].result.timestamp works.
196
+ // If it has NO name (just "0"), we return the raw value.
197
+ if (namedEntry) {
198
+ result = decoded;
199
+ }
200
+ else {
201
+ result = entries[0] ? entries[0][1] : decoded;
202
+ }
203
+ }
204
+ else {
205
+ result = Array.isArray(decoded) && decoded.length === 1 ? decoded[0] : decoded;
206
+ }
207
+ }
208
+ else {
209
+ result = decoded;
210
+ }
211
+ return { success: true, result };
212
+ }
213
+ catch (e) {
214
+ return {
215
+ success: false,
216
+ error: `Failed to decode ${calls[index].functionName}: ${e.message}`,
217
+ };
218
+ }
219
+ });
220
+ }
221
+ catch (error) {
222
+ return fallbackToSimulation(error.message);
223
+ }
224
+ }
225
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/core/services/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAKC,EACD,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,CAAC;QACH,IAAI,QAAQ,CAAC;QACb,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;YACf,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC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AU,EAAE,CAAC;QACpB,OAAO,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,119 @@
1
+ export * from "./clients.js";
2
+ export * from "./balance.js";
3
+ export * from "./transfer.js";
4
+ export * from "./blocks.js";
5
+ export * from "./transactions.js";
6
+ export * from "./contracts.js";
7
+ export * from "./tokens.js";
8
+ export * from "./address.js";
9
+ export * from "./wallet.js";
10
+ export * from "./multicall-abi.js";
11
+ export * from "./utils.js";
12
+ import * as wallet from "./wallet.js";
13
+ import * as transactions from "./transactions.js";
14
+ export declare const helpers: {
15
+ formatJson: (obj: unknown) => string;
16
+ utils: {
17
+ toSun: (trx: number | string) => string;
18
+ fromSun: (sun: number | string | bigint) => string;
19
+ formatBigInt: (value: bigint | number) => string;
20
+ formatJson: (obj: unknown) => string;
21
+ formatNumber: (value: number | string) => string;
22
+ hexToNumber: (hex: string) => number;
23
+ numberToHex: (num: number) => string;
24
+ isAddress: (address: string) => boolean;
25
+ };
26
+ toHexAddress(address: string): string;
27
+ toBase58Address(address: string): string;
28
+ isBase58(address: string): boolean;
29
+ isHex(address: string): boolean;
30
+ resolveAddress: (nameOrAddress: string, _network?: string) => Promise<string>;
31
+ transferTRX(privateKey: string, to: string, amount: string, network?: string): Promise<any>;
32
+ transferTRC20(tokenAddress: string, to: string, amount: string, privateKey: string, network?: string): Promise<{
33
+ txHash: any;
34
+ amount: {
35
+ raw: string;
36
+ formatted: string;
37
+ };
38
+ token: {
39
+ symbol: any;
40
+ decimals: number;
41
+ };
42
+ }>;
43
+ approveTRC20(tokenAddress: string, spenderAddress: string, amount: string, privateKey: string, network?: string): Promise<any>;
44
+ getTRC20TokenInfo(tokenAddress: string, network?: string): Promise<{
45
+ name: string;
46
+ symbol: string;
47
+ decimals: number;
48
+ totalSupply: bigint;
49
+ formattedTotalSupply: string;
50
+ }>;
51
+ getTRC721TokenMetadata(tokenAddress: string, tokenId: bigint, network?: string): Promise<{
52
+ name: string;
53
+ symbol: string;
54
+ tokenURI: string;
55
+ }>;
56
+ getTRC1155TokenURI(tokenAddress: string, tokenId: bigint, network?: string): Promise<string>;
57
+ readContract(params: {
58
+ address: string;
59
+ functionName: string;
60
+ args?: any[];
61
+ abi?: any[];
62
+ }, network?: string): Promise<any>;
63
+ writeContract(privateKey: string, params: {
64
+ address: string;
65
+ functionName: string;
66
+ args?: any[];
67
+ value?: string;
68
+ abi?: any[];
69
+ }, network?: string): Promise<any>;
70
+ fetchContractABI(contractAddress: string, network?: string): Promise<any>;
71
+ parseABI(abiJson: string | any[]): any[];
72
+ getReadableFunctions(abi: any[]): string[];
73
+ getFunctionFromABI(abi: any[], functionName: string): any;
74
+ multicall(params: {
75
+ calls: Array<{
76
+ address: string;
77
+ functionName: string;
78
+ args?: any[];
79
+ abi: any[];
80
+ allowFailure?: boolean;
81
+ }>;
82
+ multicallAddress?: string;
83
+ version?: 2 | 3;
84
+ allowFailure?: boolean;
85
+ }, network?: string): Promise<any>;
86
+ getTransaction(txHash: string, network?: string): Promise<any>;
87
+ getTransactionInfo(txHash: string, network?: string): Promise<any>;
88
+ waitForTransaction(txHash: string, network?: string): Promise<any>;
89
+ getTransactionReceipt: typeof transactions.getTransactionInfo;
90
+ getBlockByNumber(blockNumber: number, network?: string): Promise<any>;
91
+ getBlockByHash(blockHash: string, network?: string): Promise<any>;
92
+ getLatestBlock(network?: string): Promise<any>;
93
+ getBlockNumber(network?: string): Promise<number>;
94
+ getChainId(network?: string): Promise<number>;
95
+ getTRXBalance(address: string, network?: string): Promise<{
96
+ wei: bigint;
97
+ ether: string;
98
+ formatted: string;
99
+ symbol: string;
100
+ decimals: number;
101
+ }>;
102
+ getTRC20Balance(tokenAddress: string, walletAddress: string, network?: string): Promise<{
103
+ raw: bigint;
104
+ formatted: string;
105
+ token: {
106
+ symbol: any;
107
+ decimals: number;
108
+ address: string;
109
+ };
110
+ }>;
111
+ getTRC1155Balance(contractAddress: string, ownerAddress: string, tokenId: bigint, network?: string): Promise<bigint>;
112
+ getConfiguredWallet: () => wallet.ConfiguredWallet;
113
+ getConfiguredPrivateKey: () => string;
114
+ getWalletAddressFromKey: () => string;
115
+ signMessage: (message: string) => Promise<string>;
116
+ signTypedData: (domain: object, types: object, value: object) => Promise<string>;
117
+ getTronWeb(network?: string): import("tronweb").TronWeb;
118
+ getWallet(privateKey: string, network?: string): import("tronweb").TronWeb;
119
+ };
@@ -0,0 +1,39 @@
1
+ // Export all services
2
+ export * from "./clients.js";
3
+ export * from "./balance.js";
4
+ export * from "./transfer.js";
5
+ export * from "./blocks.js";
6
+ export * from "./transactions.js";
7
+ export * from "./contracts.js";
8
+ export * from "./tokens.js";
9
+ export * from "./address.js";
10
+ export * from "./wallet.js";
11
+ export * from "./multicall-abi.js";
12
+ export * from "./utils.js"; // Export utils as top level as well
13
+ // Add a helper object for easier access to everything
14
+ import * as clients from "./clients.js";
15
+ import * as wallet from "./wallet.js";
16
+ import * as balance from "./balance.js";
17
+ import * as blocks from "./blocks.js";
18
+ import * as transactions from "./transactions.js";
19
+ import * as contracts from "./contracts.js";
20
+ import * as tokens from "./tokens.js";
21
+ import * as transfer from "./transfer.js";
22
+ import * as utils from "./utils.js";
23
+ import * as address from "./address.js";
24
+ // Re-export specific utils function as 'helpers' for backward compatibility with tools code
25
+ export const helpers = {
26
+ ...clients,
27
+ ...wallet,
28
+ ...balance,
29
+ ...blocks,
30
+ ...transactions,
31
+ ...contracts,
32
+ ...tokens,
33
+ ...transfer,
34
+ ...address,
35
+ ...utils,
36
+ // Specifically map formatJson from utils to helpers root as tools expect it there
37
+ formatJson: utils.utils.formatJson,
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/services/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC,CAAC,oCAAoC;AAEhE,sDAAsD;AACtD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,GAAG,OAAO;IACV,GAAG,MAAM;IACT,GAAG,OAAO;IACV,GAAG,MAAM;IACT,GAAG,YAAY;IACf,GAAG,SAAS;IACZ,GAAG,MAAM;IACT,GAAG,QAAQ;IACX,GAAG,OAAO;IACV,GAAG,KAAK;IACR,kFAAkF;IAClF,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU;CACnC,CAAC"}