@missionsquad/mcp-server-tron 1.2.0
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/LICENSE +21 -0
- package/README.md +537 -0
- package/bin/cli.js +51 -0
- package/build/core/chains.d.ts +17 -0
- package/build/core/chains.js +87 -0
- package/build/core/chains.js.map +1 -0
- package/build/core/prompts.d.ts +19 -0
- package/build/core/prompts.js +485 -0
- package/build/core/prompts.js.map +1 -0
- package/build/core/resources.d.ts +14 -0
- package/build/core/resources.js +42 -0
- package/build/core/resources.js.map +1 -0
- package/build/core/services/account-data.d.ts +144 -0
- package/build/core/services/account-data.js +228 -0
- package/build/core/services/account-data.js.map +1 -0
- package/build/core/services/account-resource.d.ts +56 -0
- package/build/core/services/account-resource.js +133 -0
- package/build/core/services/account-resource.js.map +1 -0
- package/build/core/services/account.d.ts +141 -0
- package/build/core/services/account.js +191 -0
- package/build/core/services/account.js.map +1 -0
- package/build/core/services/address.d.ts +8 -0
- package/build/core/services/address.js +52 -0
- package/build/core/services/address.js.map +1 -0
- package/build/core/services/agent-wallet.d.ts +62 -0
- package/build/core/services/agent-wallet.js +234 -0
- package/build/core/services/agent-wallet.js.map +1 -0
- package/build/core/services/balance.d.ts +26 -0
- package/build/core/services/balance.js +60 -0
- package/build/core/services/balance.js.map +1 -0
- package/build/core/services/blocks.d.ts +25 -0
- package/build/core/services/blocks.js +65 -0
- package/build/core/services/blocks.js.map +1 -0
- package/build/core/services/broadcast.d.ts +13 -0
- package/build/core/services/broadcast.js +24 -0
- package/build/core/services/broadcast.js.map +1 -0
- package/build/core/services/clients.d.ts +5 -0
- package/build/core/services/clients.js +29 -0
- package/build/core/services/clients.js.map +1 -0
- package/build/core/services/contract-data.d.ts +31 -0
- package/build/core/services/contract-data.js +54 -0
- package/build/core/services/contract-data.js.map +1 -0
- package/build/core/services/contracts.d.ts +108 -0
- package/build/core/services/contracts.js +482 -0
- package/build/core/services/contracts.js.map +1 -0
- package/build/core/services/events.d.ts +56 -0
- package/build/core/services/events.js +99 -0
- package/build/core/services/events.js.map +1 -0
- package/build/core/services/governance.d.ts +78 -0
- package/build/core/services/governance.js +207 -0
- package/build/core/services/governance.js.map +1 -0
- package/build/core/services/index.d.ts +28 -0
- package/build/core/services/index.js +81 -0
- package/build/core/services/index.js.map +1 -0
- package/build/core/services/mempool.d.ts +12 -0
- package/build/core/services/mempool.js +32 -0
- package/build/core/services/mempool.js.map +1 -0
- package/build/core/services/multicall-abi.d.ts +55 -0
- package/build/core/services/multicall-abi.js +61 -0
- package/build/core/services/multicall-abi.js.map +1 -0
- package/build/core/services/nodes.d.ts +8 -0
- package/build/core/services/nodes.js +18 -0
- package/build/core/services/nodes.js.map +1 -0
- package/build/core/services/proposals.d.ts +33 -0
- package/build/core/services/proposals.js +95 -0
- package/build/core/services/proposals.js.map +1 -0
- package/build/core/services/query.d.ts +34 -0
- package/build/core/services/query.js +60 -0
- package/build/core/services/query.js.map +1 -0
- package/build/core/services/staking.d.ts +40 -0
- package/build/core/services/staking.js +113 -0
- package/build/core/services/staking.js.map +1 -0
- package/build/core/services/tokens.d.ts +22 -0
- package/build/core/services/tokens.js +68 -0
- package/build/core/services/tokens.js.map +1 -0
- package/build/core/services/transactions.d.ts +16 -0
- package/build/core/services/transactions.js +42 -0
- package/build/core/services/transactions.js.map +1 -0
- package/build/core/services/transfer.d.ts +24 -0
- package/build/core/services/transfer.js +84 -0
- package/build/core/services/transfer.js.map +1 -0
- package/build/core/services/trongrid-client.d.ts +14 -0
- package/build/core/services/trongrid-client.js +19 -0
- package/build/core/services/trongrid-client.js.map +1 -0
- package/build/core/services/utils.d.ts +13 -0
- package/build/core/services/utils.js +39 -0
- package/build/core/services/utils.js.map +1 -0
- package/build/core/services/wallet.d.ts +13 -0
- package/build/core/services/wallet.js +18 -0
- package/build/core/services/wallet.js.map +1 -0
- package/build/core/tools/account-data.d.ts +2 -0
- package/build/core/tools/account-data.js +253 -0
- package/build/core/tools/account-data.js.map +1 -0
- package/build/core/tools/account-resource.d.ts +2 -0
- package/build/core/tools/account-resource.js +269 -0
- package/build/core/tools/account-resource.js.map +1 -0
- package/build/core/tools/account.d.ts +2 -0
- package/build/core/tools/account.js +451 -0
- package/build/core/tools/account.js.map +1 -0
- package/build/core/tools/address.d.ts +2 -0
- package/build/core/tools/address.js +45 -0
- package/build/core/tools/address.js.map +1 -0
- package/build/core/tools/balance.d.ts +2 -0
- package/build/core/tools/balance.js +94 -0
- package/build/core/tools/balance.js.map +1 -0
- package/build/core/tools/block.d.ts +2 -0
- package/build/core/tools/block.js +74 -0
- package/build/core/tools/block.js.map +1 -0
- package/build/core/tools/broadcast.d.ts +2 -0
- package/build/core/tools/broadcast.js +102 -0
- package/build/core/tools/broadcast.js.map +1 -0
- package/build/core/tools/contract-data.d.ts +2 -0
- package/build/core/tools/contract-data.js +159 -0
- package/build/core/tools/contract-data.js.map +1 -0
- package/build/core/tools/contract.d.ts +2 -0
- package/build/core/tools/contract.js +600 -0
- package/build/core/tools/contract.js.map +1 -0
- package/build/core/tools/event.d.ts +2 -0
- package/build/core/tools/event.js +159 -0
- package/build/core/tools/event.js.map +1 -0
- package/build/core/tools/governance.d.ts +6 -0
- package/build/core/tools/governance.js +424 -0
- package/build/core/tools/governance.js.map +1 -0
- package/build/core/tools/index.d.ts +15 -0
- package/build/core/tools/index.js +93 -0
- package/build/core/tools/index.js.map +1 -0
- package/build/core/tools/mempool.d.ts +2 -0
- package/build/core/tools/mempool.js +116 -0
- package/build/core/tools/mempool.js.map +1 -0
- package/build/core/tools/network.d.ts +2 -0
- package/build/core/tools/network.js +114 -0
- package/build/core/tools/network.js.map +1 -0
- package/build/core/tools/node.d.ts +2 -0
- package/build/core/tools/node.js +75 -0
- package/build/core/tools/node.js.map +1 -0
- package/build/core/tools/proposals.d.ts +6 -0
- package/build/core/tools/proposals.js +219 -0
- package/build/core/tools/proposals.js.map +1 -0
- package/build/core/tools/query.d.ts +2 -0
- package/build/core/tools/query.js +399 -0
- package/build/core/tools/query.js.map +1 -0
- package/build/core/tools/staking.d.ts +2 -0
- package/build/core/tools/staking.js +281 -0
- package/build/core/tools/staking.js.map +1 -0
- package/build/core/tools/transaction.d.ts +2 -0
- package/build/core/tools/transaction.js +65 -0
- package/build/core/tools/transaction.js.map +1 -0
- package/build/core/tools/transfer.d.ts +2 -0
- package/build/core/tools/transfer.js +101 -0
- package/build/core/tools/transfer.js.map +1 -0
- package/build/core/tools/types.d.ts +13 -0
- package/build/core/tools/types.js +2 -0
- package/build/core/tools/types.js.map +1 -0
- package/build/core/tools/wallet.d.ts +2 -0
- package/build/core/tools/wallet.js +172 -0
- package/build/core/tools/wallet.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +21 -0
- package/build/index.js.map +1 -0
- package/build/middleware/auth.d.ts +16 -0
- package/build/middleware/auth.js +44 -0
- package/build/middleware/auth.js.map +1 -0
- package/build/oauth/OAuthService.d.ts +100 -0
- package/build/oauth/OAuthService.js +507 -0
- package/build/oauth/OAuthService.js.map +1 -0
- package/build/oauth/page.d.ts +1 -0
- package/build/oauth/page.js +255 -0
- package/build/oauth/page.js.map +1 -0
- package/build/oauth/types.d.ts +65 -0
- package/build/oauth/types.js +2 -0
- package/build/oauth/types.js.map +1 -0
- package/build/server/http-app.d.ts +9 -0
- package/build/server/http-app.js +128 -0
- package/build/server/http-app.js.map +1 -0
- package/build/server/http-server.d.ts +1 -0
- package/build/server/http-server.js +35 -0
- package/build/server/http-server.js.map +1 -0
- package/build/server/oauth-routes.d.ts +7 -0
- package/build/server/oauth-routes.js +157 -0
- package/build/server/oauth-routes.js.map +1 -0
- package/build/server/server.d.ts +9 -0
- package/build/server/server.js +54 -0
- package/build/server/server.js.map +1 -0
- package/build/tenant/TenantManager.d.ts +35 -0
- package/build/tenant/TenantManager.js +167 -0
- package/build/tenant/TenantManager.js.map +1 -0
- package/build/tenant/context.d.ts +11 -0
- package/build/tenant/context.js +23 -0
- package/build/tenant/context.js.map +1 -0
- package/build/tenant/types.d.ts +16 -0
- package/build/tenant/types.js +2 -0
- package/build/tenant/types.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-wallet integration layer for mcp-server-tron.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified signing interface via agent-wallet SDK.
|
|
5
|
+
*/
|
|
6
|
+
import { resolveWalletProvider, } from "@missionsquad/agent-wallet";
|
|
7
|
+
import { TronWeb } from "tronweb";
|
|
8
|
+
import { getTronWeb } from "./clients.js";
|
|
9
|
+
import { getRequestContext } from "../../tenant/context.js";
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Module-level singleton state
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
let provider = null;
|
|
14
|
+
let activeWallet = null;
|
|
15
|
+
let activeAddress = null;
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
function getProvider() {
|
|
18
|
+
if (provider)
|
|
19
|
+
return provider;
|
|
20
|
+
try {
|
|
21
|
+
provider = resolveWalletProvider({ network: "tron" });
|
|
22
|
+
return provider;
|
|
23
|
+
}
|
|
24
|
+
catch (_e) {
|
|
25
|
+
// Config missing or invalid - SDK throws ValueError
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getRuntime() {
|
|
30
|
+
const context = getRequestContext();
|
|
31
|
+
if (context?.auth) {
|
|
32
|
+
return {
|
|
33
|
+
mode: "tenant",
|
|
34
|
+
tenant: context.auth.tenant,
|
|
35
|
+
provider: context.tenantManager.getTenantWalletProvider(context.auth.tenant.tenantId),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
mode: "legacy",
|
|
40
|
+
provider: getProvider(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Active wallet management
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
/**
|
|
47
|
+
* Get the currently active agent-wallet.
|
|
48
|
+
*/
|
|
49
|
+
export async function getActiveWallet() {
|
|
50
|
+
const runtime = getRuntime();
|
|
51
|
+
if (runtime.mode === "tenant") {
|
|
52
|
+
return runtime.provider.getPrimaryWallet();
|
|
53
|
+
}
|
|
54
|
+
if (activeWallet)
|
|
55
|
+
return activeWallet;
|
|
56
|
+
if (!runtime.provider) {
|
|
57
|
+
throw new Error("Wallet not configured.");
|
|
58
|
+
}
|
|
59
|
+
activeWallet = await runtime.provider.getActiveWallet();
|
|
60
|
+
activeAddress = await activeWallet.getAddress();
|
|
61
|
+
return activeWallet;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the address of the active wallet.
|
|
65
|
+
*/
|
|
66
|
+
export async function getOwnerAddress() {
|
|
67
|
+
const runtime = getRuntime();
|
|
68
|
+
if (runtime.mode === "tenant") {
|
|
69
|
+
return runtime.tenant.walletAddressBase58;
|
|
70
|
+
}
|
|
71
|
+
if (activeAddress)
|
|
72
|
+
return activeAddress;
|
|
73
|
+
await getActiveWallet();
|
|
74
|
+
if (activeAddress == null) {
|
|
75
|
+
throw new Error("Failed to resolve active wallet address");
|
|
76
|
+
}
|
|
77
|
+
return activeAddress;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Switch the active wallet at runtime when the provider supports multi-wallet selection.
|
|
81
|
+
*/
|
|
82
|
+
export async function selectWallet(walletId) {
|
|
83
|
+
const runtime = getRuntime();
|
|
84
|
+
if (runtime.mode === "tenant") {
|
|
85
|
+
throw new Error("select_wallet is not available in HTTP tenant mode.");
|
|
86
|
+
}
|
|
87
|
+
const p = runtime.provider;
|
|
88
|
+
if (!p || typeof p.setActive !== "function") {
|
|
89
|
+
throw new Error("select_wallet is not available.");
|
|
90
|
+
}
|
|
91
|
+
const lp = p;
|
|
92
|
+
lp.setActive(walletId);
|
|
93
|
+
const wallet = await lp.getWallet(walletId);
|
|
94
|
+
const address = await wallet.getAddress();
|
|
95
|
+
// Update cached state
|
|
96
|
+
activeWallet = wallet;
|
|
97
|
+
activeAddress = address;
|
|
98
|
+
return { id: walletId, address };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* List all available wallets.
|
|
102
|
+
*/
|
|
103
|
+
export async function listAgentWallets() {
|
|
104
|
+
const runtime = getRuntime();
|
|
105
|
+
if (runtime.mode === "tenant") {
|
|
106
|
+
return [
|
|
107
|
+
{
|
|
108
|
+
id: "primary",
|
|
109
|
+
type: "local_secure",
|
|
110
|
+
address: runtime.tenant.walletAddressBase58,
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
const p = runtime.provider;
|
|
115
|
+
if (!p)
|
|
116
|
+
return [];
|
|
117
|
+
if (typeof p.listWallets === "function") {
|
|
118
|
+
const lp = p;
|
|
119
|
+
// agent-wallet@2.3+: listWallets(): Array<[walletId, walletConfig, isActive]>
|
|
120
|
+
// agent-wallet@2.2 (and tests) may return Promise<Array<{id,type,...}>>.
|
|
121
|
+
const wallets = await lp.listWallets();
|
|
122
|
+
const result = [];
|
|
123
|
+
for (const w of wallets) {
|
|
124
|
+
let walletId;
|
|
125
|
+
let walletType;
|
|
126
|
+
if (Array.isArray(w)) {
|
|
127
|
+
walletId = w[0];
|
|
128
|
+
walletType = (w[1]?.type ?? "unknown");
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
walletId = w.id ?? "";
|
|
132
|
+
walletType = (w.type ?? "unknown");
|
|
133
|
+
}
|
|
134
|
+
if (!walletId) {
|
|
135
|
+
// Skip malformed entries so one bad import does not hide all wallets.
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const wallet = await lp.getWallet(walletId);
|
|
139
|
+
const address = await wallet.getAddress();
|
|
140
|
+
result.push({ id: walletId, type: walletType, address });
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
// Single-wallet mode
|
|
145
|
+
const wallet = await p.getActiveWallet();
|
|
146
|
+
const address = await wallet.getAddress();
|
|
147
|
+
if (address == null) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
return [{ id: "single", type: "single", address }];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the currently active wallet ID.
|
|
154
|
+
*/
|
|
155
|
+
export function getActiveWalletId() {
|
|
156
|
+
const runtime = getRuntime();
|
|
157
|
+
if (runtime.mode === "tenant") {
|
|
158
|
+
return "primary";
|
|
159
|
+
}
|
|
160
|
+
const p = runtime.provider;
|
|
161
|
+
if (!p)
|
|
162
|
+
return null;
|
|
163
|
+
if (typeof p.getActiveId === "function") {
|
|
164
|
+
return p.getActiveId();
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Signing
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
/**
|
|
172
|
+
* Sign an unsigned transaction.
|
|
173
|
+
*/
|
|
174
|
+
export async function signTransaction(unsignedTx) {
|
|
175
|
+
const wallet = await getActiveWallet();
|
|
176
|
+
const signedJson = await wallet.signTransaction(unsignedTx);
|
|
177
|
+
return JSON.parse(signedJson);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Sign using raw crypto.
|
|
181
|
+
*/
|
|
182
|
+
export async function signTransactionRaw(unsignedTx, _network = "mainnet") {
|
|
183
|
+
const wallet = await getActiveWallet();
|
|
184
|
+
const signedJson = await wallet.signTransaction(unsignedTx);
|
|
185
|
+
return JSON.parse(signedJson);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sign an unsigned transaction and broadcast it.
|
|
189
|
+
*/
|
|
190
|
+
export async function buildSignBroadcast(unsignedTx, network = "mainnet") {
|
|
191
|
+
const signedTx = await signTransaction(unsignedTx);
|
|
192
|
+
const tronWeb = getTronWeb(network);
|
|
193
|
+
const result = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
194
|
+
if (result.result) {
|
|
195
|
+
return result.txid;
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`Broadcast failed: ${JSON.stringify(result)}`);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Sign a message using the active wallet.
|
|
201
|
+
*/
|
|
202
|
+
export async function signMessageWithWallet(message) {
|
|
203
|
+
const wallet = await getActiveWallet();
|
|
204
|
+
const msgBytes = Buffer.from(message, "utf-8");
|
|
205
|
+
return await wallet.signMessage(msgBytes);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Sign typed data (EIP-712) using the active wallet.
|
|
209
|
+
*/
|
|
210
|
+
export async function signTypedDataWithWallet(domain, types, value) {
|
|
211
|
+
const wallet = await getActiveWallet();
|
|
212
|
+
const eip712Wallet = wallet;
|
|
213
|
+
if (typeof eip712Wallet.signTypedData !== "function") {
|
|
214
|
+
throw new Error("Active wallet does not support signTypedData");
|
|
215
|
+
}
|
|
216
|
+
return await eip712Wallet.signTypedData({ domain, types, value });
|
|
217
|
+
}
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
// Account generation
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
/**
|
|
222
|
+
* Unified account generation.
|
|
223
|
+
* Generates a keypair and returns it directly. It is NOT stored in agent-wallet.
|
|
224
|
+
*/
|
|
225
|
+
export async function generateAccountKeypair() {
|
|
226
|
+
// Generate keypair via TronWeb
|
|
227
|
+
const account = await TronWeb.createAccount();
|
|
228
|
+
return {
|
|
229
|
+
address: account.address.base58,
|
|
230
|
+
privateKey: account.privateKey,
|
|
231
|
+
message: "Account generated successfully. Note: This account is NOT stored. Please save your private key manually.",
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=agent-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-wallet.js","sourceRoot":"","sources":["../../../src/core/services/agent-wallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,O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ACzD,MAAM,MAAM,GAAG,MAAM,eAAe,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAc,EACd,KAAa,EACb,KAAa;IAEb,MAAM,MAAM,GAAG,MAAM,eAAe,EAAE,CAAC;IACvC,MAAM,YAAY,GAAG,MAAkC,CAAC;IACxD,IAAI,OAAO,YAAY,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAS,CAAC,CAAC;AAC3E,CAAC;AAED,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAK1C,+BAA+B;IAC/B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC;IAE9C,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM;QAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,OAAO,EACL,0GAA0G;KAC7G,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get TRX balance for an address
|
|
3
|
+
*/
|
|
4
|
+
export declare function getTRXBalance(address: string, network?: string): Promise<{
|
|
5
|
+
wei: bigint;
|
|
6
|
+
ether: string;
|
|
7
|
+
formatted: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
decimals: number;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Get TRC20 token balance
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTRC20Balance(tokenAddress: string, walletAddress: string, network?: string): Promise<{
|
|
15
|
+
raw: bigint;
|
|
16
|
+
formatted: string;
|
|
17
|
+
token: {
|
|
18
|
+
symbol: any;
|
|
19
|
+
decimals: number;
|
|
20
|
+
address: string;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Get TRC1155 balance
|
|
25
|
+
*/
|
|
26
|
+
export declare function getTRC1155Balance(contractAddress: string, ownerAddress: string, tokenId: bigint, network?: string): Promise<bigint>;
|
|
@@ -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,CAA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AAS;YACpB,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;gBAC1B,OAAO,EAAE,YAAY;aACtB;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,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,25 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Get current chain parameters (energy price, bandwidth price, etc.)
|
|
18
|
+
*/
|
|
19
|
+
export declare function getChainParameters(network?: string): Promise<{
|
|
20
|
+
network: string;
|
|
21
|
+
energy_price_sun: number | undefined;
|
|
22
|
+
bandwidth_price_sun: number | undefined;
|
|
23
|
+
all_parameters: any[];
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
/**
|
|
47
|
+
* Get current chain parameters (energy price, bandwidth price, etc.)
|
|
48
|
+
*/
|
|
49
|
+
export async function getChainParameters(network = "mainnet") {
|
|
50
|
+
const tronWeb = getTronWeb(network);
|
|
51
|
+
const parameters = await tronWeb.trx.getChainParameters();
|
|
52
|
+
const paramMap = new Map();
|
|
53
|
+
for (const param of parameters) {
|
|
54
|
+
if (param.key) {
|
|
55
|
+
paramMap.set(param.key, param.value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
network,
|
|
60
|
+
energy_price_sun: paramMap.get("getEnergyFee"),
|
|
61
|
+
bandwidth_price_sun: paramMap.get("getTransactionFee"),
|
|
62
|
+
all_parameters: parameters,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# 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,C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AK,UAAU,kBAAkB,CAAC,OAAO,GAAG,SAAS;IAM1D,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;IAE1D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA8B,CAAC;IACvD,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;YACd,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,gBAAgB,EAAE,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC;QAC9C,mBAAmB,EAAE,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACtD,cAAc,EAAE,UAAU;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast a signed transaction to the network (BroadcastTransaction)
|
|
3
|
+
*/
|
|
4
|
+
export declare function broadcastTransaction(transaction: Record<string, unknown>, network?: string): Promise<any>;
|
|
5
|
+
/**
|
|
6
|
+
* Broadcast a signed transaction in hex format (BroadcastHex)
|
|
7
|
+
*/
|
|
8
|
+
export declare function broadcastHex(transaction: string, network?: string): Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a TRX transfer transaction (CreateTransaction)
|
|
11
|
+
* Returns an unsigned transaction object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createTransaction(ownerAddress: string, toAddress: string, amount: number, network?: string): Promise<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getTronWeb } from "./clients.js";
|
|
2
|
+
/**
|
|
3
|
+
* Broadcast a signed transaction to the network (BroadcastTransaction)
|
|
4
|
+
*/
|
|
5
|
+
export async function broadcastTransaction(transaction, network = "mainnet") {
|
|
6
|
+
const tronWeb = getTronWeb(network);
|
|
7
|
+
return tronWeb.trx.sendRawTransaction(transaction);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Broadcast a signed transaction in hex format (BroadcastHex)
|
|
11
|
+
*/
|
|
12
|
+
export async function broadcastHex(transaction, network = "mainnet") {
|
|
13
|
+
const tronWeb = getTronWeb(network);
|
|
14
|
+
return tronWeb.trx.sendHexTransaction(transaction);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a TRX transfer transaction (CreateTransaction)
|
|
18
|
+
* Returns an unsigned transaction object.
|
|
19
|
+
*/
|
|
20
|
+
export async function createTransaction(ownerAddress, toAddress, amount, network = "mainnet") {
|
|
21
|
+
const tronWeb = getTronWeb(network);
|
|
22
|
+
return tronWeb.transactionBuilder.sendTrx(toAddress, amount, ownerAddress);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=broadcast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../../../src/core/services/broadcast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,WAAoC,EACpC,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,WAAkB,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAmB,EAAE,OAAO,GAAG,SAAS;IACzE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,YAAoB,EACpB,SAAiB,EACjB,MAAc,EACd,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
//# 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,UAAU,CAAC,OAAO,GAAG,SAAS;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,oCAAoC;IACpC,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;IACpC,CAAC;IAED,sBAAsB;IACtB,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE5C,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAC;IAEH,kEAAkE;IAClE,MAAM,CAAC,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAExD,mBAAmB;IACnB,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type PaginationOptions } from "./account-data.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get contract transactions from TronGrid `/v1/contracts/{address}/transactions`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getContractTransactions(address: string, options?: PaginationOptions, network?: string): Promise<{
|
|
6
|
+
transactions: import("./account-data.js").FormattedTransaction[];
|
|
7
|
+
count: number;
|
|
8
|
+
fingerprint?: string;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Get contract internal transactions from TronGrid `/v1/accounts/{address}/internal-transactions`.
|
|
12
|
+
* Note: TronGrid uses the accounts path for contract internal transactions as well.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getContractInternalTransactions(address: string, options?: PaginationOptions, network?: string): Promise<{
|
|
15
|
+
transactions: import("./account-data.js").FormattedInternalTransaction[];
|
|
16
|
+
count: number;
|
|
17
|
+
fingerprint?: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Get TRC20 token holders from TronGrid `/v1/contracts/{address}/tokens`.
|
|
21
|
+
* Returns normalised address + balance pairs.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTrc20TokenHolders(address: string, options?: {
|
|
24
|
+
limit?: number;
|
|
25
|
+
fingerprint?: string;
|
|
26
|
+
orderBy?: string;
|
|
27
|
+
}, network?: string): Promise<{
|
|
28
|
+
fingerprint?: string | undefined;
|
|
29
|
+
holders: import("./account-data.js").NormalizedBalance[];
|
|
30
|
+
count: number;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { formatTransactions, formatInternalTransactions, normalizeKeyValuePairs, } from "./account-data.js";
|
|
2
|
+
import { tronGridGet } from "./trongrid-client.js";
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Service functions
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
/**
|
|
7
|
+
* Get contract transactions from TronGrid `/v1/contracts/{address}/transactions`.
|
|
8
|
+
*/
|
|
9
|
+
export async function getContractTransactions(address, options = {}, network = "mainnet") {
|
|
10
|
+
const raw = await tronGridGet(network, `/v1/contracts/${address}/transactions`, {
|
|
11
|
+
limit: options.limit,
|
|
12
|
+
fingerprint: options.fingerprint,
|
|
13
|
+
only_confirmed: options.onlyConfirmed,
|
|
14
|
+
only_unconfirmed: options.onlyUnconfirmed,
|
|
15
|
+
order_by: options.orderBy,
|
|
16
|
+
min_timestamp: options.minTimestamp,
|
|
17
|
+
max_timestamp: options.maxTimestamp,
|
|
18
|
+
});
|
|
19
|
+
return formatTransactions(raw);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get contract internal transactions from TronGrid `/v1/accounts/{address}/internal-transactions`.
|
|
23
|
+
* Note: TronGrid uses the accounts path for contract internal transactions as well.
|
|
24
|
+
*/
|
|
25
|
+
export async function getContractInternalTransactions(address, options = {}, network = "mainnet") {
|
|
26
|
+
const raw = await tronGridGet(network, `/v1/accounts/${address}/internal-transactions`, {
|
|
27
|
+
limit: options.limit,
|
|
28
|
+
fingerprint: options.fingerprint,
|
|
29
|
+
only_confirmed: options.onlyConfirmed,
|
|
30
|
+
only_unconfirmed: options.onlyUnconfirmed,
|
|
31
|
+
order_by: options.orderBy,
|
|
32
|
+
min_timestamp: options.minTimestamp,
|
|
33
|
+
max_timestamp: options.maxTimestamp,
|
|
34
|
+
});
|
|
35
|
+
return formatInternalTransactions(raw);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get TRC20 token holders from TronGrid `/v1/contracts/{address}/tokens`.
|
|
39
|
+
* Returns normalised address + balance pairs.
|
|
40
|
+
*/
|
|
41
|
+
export async function getTrc20TokenHolders(address, options = {}, network = "mainnet") {
|
|
42
|
+
const raw = await tronGridGet(network, `/v1/contracts/${address}/tokens`, {
|
|
43
|
+
limit: options.limit,
|
|
44
|
+
fingerprint: options.fingerprint,
|
|
45
|
+
order_by: options.orderBy,
|
|
46
|
+
});
|
|
47
|
+
const data = raw.data ?? [];
|
|
48
|
+
return {
|
|
49
|
+
holders: normalizeKeyValuePairs(data),
|
|
50
|
+
count: data.length,
|
|
51
|
+
...(raw.meta?.fingerprint ? { fingerprint: raw.meta.fingerprint } : {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=contract-data.js.map
|
|
@@ -0,0 +1 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