@sun-protocol/tron-mcp-server 1.0.0-beta.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 +282 -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 +268 -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 +90 -0
@@ -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,CA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AAC;YACnC,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,oBAAoB,KAAK,CAAC,KAAK,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,OAAO,EAAE;iBACrE,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAU,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"}
@@ -0,0 +1,55 @@
1
+ export declare const MULTICALL2_ABI: {
2
+ inputs: ({
3
+ internalType: string;
4
+ name: string;
5
+ type: string;
6
+ components?: undefined;
7
+ } | {
8
+ components: {
9
+ internalType: string;
10
+ name: string;
11
+ type: string;
12
+ }[];
13
+ internalType: string;
14
+ name: string;
15
+ type: string;
16
+ })[];
17
+ name: string;
18
+ outputs: {
19
+ components: {
20
+ internalType: string;
21
+ name: string;
22
+ type: string;
23
+ }[];
24
+ internalType: string;
25
+ name: string;
26
+ type: string;
27
+ }[];
28
+ stateMutability: string;
29
+ type: string;
30
+ }[];
31
+ export declare const MULTICALL3_ABI: {
32
+ inputs: {
33
+ components: {
34
+ internalType: string;
35
+ name: string;
36
+ type: string;
37
+ }[];
38
+ internalType: string;
39
+ name: string;
40
+ type: string;
41
+ }[];
42
+ name: string;
43
+ outputs: {
44
+ components: {
45
+ internalType: string;
46
+ name: string;
47
+ type: string;
48
+ }[];
49
+ internalType: string;
50
+ name: string;
51
+ type: string;
52
+ }[];
53
+ stateMutability: string;
54
+ type: string;
55
+ }[];
@@ -0,0 +1,61 @@
1
+ export const MULTICALL2_ABI = [
2
+ {
3
+ inputs: [
4
+ { internalType: "bool", name: "requireSuccess", type: "bool" },
5
+ {
6
+ components: [
7
+ { internalType: "address", name: "target", type: "address" },
8
+ { internalType: "bytes", name: "callData", type: "bytes" },
9
+ ],
10
+ internalType: "struct Multicall2.Call[]",
11
+ name: "calls",
12
+ type: "tuple[]",
13
+ },
14
+ ],
15
+ name: "tryAggregate",
16
+ outputs: [
17
+ {
18
+ components: [
19
+ { internalType: "bool", name: "success", type: "bool" },
20
+ { internalType: "bytes", name: "returnData", type: "bytes" },
21
+ ],
22
+ internalType: "struct Multicall2.Result[]",
23
+ name: "returnData",
24
+ type: "tuple[]",
25
+ },
26
+ ],
27
+ stateMutability: "view",
28
+ type: "function",
29
+ },
30
+ ];
31
+ export const MULTICALL3_ABI = [
32
+ {
33
+ inputs: [
34
+ {
35
+ components: [
36
+ { internalType: "address", name: "target", type: "address" },
37
+ { internalType: "bool", name: "allowFailure", type: "bool" },
38
+ { internalType: "bytes", name: "callData", type: "bytes" },
39
+ ],
40
+ internalType: "struct Multicall3.Call3[]",
41
+ name: "calls",
42
+ type: "tuple[]",
43
+ },
44
+ ],
45
+ name: "aggregate3",
46
+ outputs: [
47
+ {
48
+ components: [
49
+ { internalType: "bool", name: "success", type: "bool" },
50
+ { internalType: "bytes", name: "returnData", type: "bytes" },
51
+ ],
52
+ internalType: "struct Multicall3.Result[]",
53
+ name: "returnData",
54
+ type: "tuple[]",
55
+ },
56
+ ],
57
+ stateMutability: "view",
58
+ type: "function",
59
+ },
60
+ ];
61
+ //# sourceMappingURL=multicall-abi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multicall-abi.js","sourceRoot":"","sources":["../../../src/core/services/multicall-abi.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;QACE,MAAM,EAAE;YACN,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;YAC9D;gBACE,UAAU,EAAE;oBACV,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC5D,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE;iBAC3D;gBACD,YAAY,EAAE,0BAA0B;gBACxC,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE;YACP;gBACE,UAAU,EAAE;oBACV,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE;oBACvD,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;iBAC7D;gBACD,YAAY,EAAE,4BAA4B;gBAC1C,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;QACE,MAAM,EAAE;YACN;gBACE,UAAU,EAAE;oBACV,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC5D,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE;oBAC5D,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE;iBAC3D;gBACD,YAAY,EAAE,2BAA2B;gBACzC,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,UAAU,EAAE;oBACV,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE;oBACvD,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;iBAC7D;gBACD,YAAY,EAAE,4BAA4B;gBAC1C,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Get TRC20 token information
3
+ */
4
+ export declare function getTRC20TokenInfo(tokenAddress: string, network?: string): Promise<{
5
+ name: string;
6
+ symbol: string;
7
+ decimals: number;
8
+ totalSupply: bigint;
9
+ formattedTotalSupply: string;
10
+ }>;
11
+ /**
12
+ * Get TRC721 token metadata
13
+ */
14
+ export declare function getTRC721TokenMetadata(tokenAddress: string, tokenId: bigint, network?: string): Promise<{
15
+ name: string;
16
+ symbol: string;
17
+ tokenURI: string;
18
+ }>;
19
+ /**
20
+ * Get TRC1155 token URI
21
+ */
22
+ export declare function getTRC1155TokenURI(tokenAddress: string, tokenId: bigint, network?: string): Promise<string>;
@@ -0,0 +1,68 @@
1
+ import { getTronWeb } from "./clients.js";
2
+ /**
3
+ * Get TRC20 token information
4
+ */
5
+ export async function getTRC20TokenInfo(tokenAddress, network = "mainnet") {
6
+ const tronWeb = getTronWeb(network);
7
+ try {
8
+ const contract = await tronWeb.contract().at(tokenAddress);
9
+ const [name, symbol, decimals, totalSupply] = await Promise.all([
10
+ contract.methods.name().call(),
11
+ contract.methods.symbol().call(),
12
+ contract.methods.decimals().call(),
13
+ contract.methods.totalSupply().call(),
14
+ ]);
15
+ const decimalsNum = Number(decimals);
16
+ const totalSupplyBigInt = BigInt(totalSupply.toString());
17
+ const divisor = BigInt(10) ** BigInt(decimalsNum);
18
+ // Formatting total supply
19
+ const formattedTotalSupply = (Number(totalSupplyBigInt) / Number(divisor)).toString();
20
+ return {
21
+ name,
22
+ symbol,
23
+ decimals: decimalsNum,
24
+ totalSupply: totalSupplyBigInt,
25
+ formattedTotalSupply,
26
+ };
27
+ }
28
+ catch (error) {
29
+ throw new Error(`Failed to get TRC20 token info: ${error.message}`);
30
+ }
31
+ }
32
+ /**
33
+ * Get TRC721 token metadata
34
+ */
35
+ export async function getTRC721TokenMetadata(tokenAddress, tokenId, network = "mainnet") {
36
+ const tronWeb = getTronWeb(network);
37
+ try {
38
+ const contract = await tronWeb.contract().at(tokenAddress);
39
+ const [name, symbol, tokenURI] = await Promise.all([
40
+ contract.methods.name().call(),
41
+ contract.methods.symbol().call(),
42
+ contract.methods.tokenURI(tokenId.toString()).call(),
43
+ ]);
44
+ return {
45
+ name,
46
+ symbol,
47
+ tokenURI,
48
+ };
49
+ }
50
+ catch (error) {
51
+ throw new Error(`Failed to get TRC721 metadata: ${error.message}`);
52
+ }
53
+ }
54
+ /**
55
+ * Get TRC1155 token URI
56
+ */
57
+ export async function getTRC1155TokenURI(tokenAddress, tokenId, network = "mainnet") {
58
+ const tronWeb = getTronWeb(network);
59
+ try {
60
+ const contract = await tronWeb.contract().at(tokenAddress);
61
+ const uri = await contract.methods.uri(tokenId.toString()).call();
62
+ return uri;
63
+ }
64
+ catch (error) {
65
+ throw new Error(`Failed to get TRC1155 URI: ${error.message}`);
66
+ }
67
+ }
68
+ //# sourceMappingURL=tokens.js.map