@dynamic-labs/tron 4.39.0 → 4.40.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.
- package/CHANGELOG.md +19 -0
- package/README.md +264 -20
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -6
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.cjs +5 -5
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +4 -4
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +5 -5
- package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +5 -5
- package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +4 -4
- package/src/connectors/OKXTronConnector/OKXTronConnector.js +5 -5
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs +5 -13
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.d.ts +4 -4
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.js +5 -13
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs +304 -0
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.d.ts +107 -0
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.js +300 -0
- package/src/connectors/TronWalletAdapterConnector/index.d.ts +1 -0
- package/src/connectors/TrustTronConnector/TrustTronConnector.cjs +5 -16
- package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +4 -4
- package/src/connectors/TrustTronConnector/TrustTronConnector.js +5 -16
- package/src/index.cjs +2 -3
- package/src/index.d.ts +5 -4
- package/src/index.js +1 -2
- package/src/types.d.ts +11 -181
- package/src/utils/TronUiTransaction/TronUiTransaction.cjs +67 -26
- package/src/utils/TronUiTransaction/TronUiTransaction.d.ts +38 -5
- package/src/utils/TronUiTransaction/TronUiTransaction.js +67 -26
- package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.cjs +16 -0
- package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.d.ts +9 -0
- package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.js +12 -0
- package/src/utils/convertChainIdToDecimal/index.d.ts +1 -0
- package/src/utils/getTronGasEstimation/getTronGasEstimation.cjs +162 -0
- package/src/utils/getTronGasEstimation/getTronGasEstimation.d.ts +49 -0
- package/src/utils/getTronGasEstimation/getTronGasEstimation.js +158 -0
- package/src/utils/getTronGasEstimation/index.d.ts +1 -0
- package/src/wallet/TronWallet/TronWallet.cjs +124 -0
- package/src/wallet/TronWallet/TronWallet.d.ts +51 -0
- package/src/wallet/TronWallet/TronWallet.js +120 -0
- package/src/wallet/TronWallet/index.d.ts +1 -0
- package/src/connectors/BybitTronConnector/BybitTronConnector.d.ts +0 -7
- package/src/connectors/BybitTronConnector/index.d.ts +0 -1
- package/src/connectors/TronWalletConnector/TronWalletConnector.cjs +0 -255
- package/src/connectors/TronWalletConnector/TronWalletConnector.d.ts +0 -42
- package/src/connectors/TronWalletConnector/TronWalletConnector.js +0 -251
- package/src/connectors/TronWalletConnector/index.d.ts +0 -1
- package/src/utils/detectTronNetworkFromProvider.cjs +0 -67
- package/src/utils/detectTronNetworkFromProvider.d.ts +0 -30
- package/src/utils/detectTronNetworkFromProvider.js +0 -62
- package/src/utils/getDefaultTronNetworks.cjs +0 -60
- package/src/utils/getDefaultTronNetworks.d.ts +0 -9
- package/src/utils/getDefaultTronNetworks.js +0 -53
- package/src/utils/getTronGasEstimation.cjs +0 -136
- package/src/utils/getTronGasEstimation.d.ts +0 -47
- package/src/utils/getTronGasEstimation.js +0 -129
- package/src/utils/index.d.ts +0 -4
- package/src/utils/provider.cjs +0 -59
- package/src/utils/provider.d.ts +0 -24
- package/src/utils/provider.js +0 -53
- package/src/wallet/TronWallet.cjs +0 -106
- package/src/wallet/TronWallet.d.ts +0 -22
- package/src/wallet/TronWallet.js +0 -102
- package/src/wallet/index.d.ts +0 -2
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
|
+
import { TronWallet } from '../../wallet/TronWallet/TronWallet.js';
|
|
6
|
+
import { TronUiTransaction } from '../../utils/TronUiTransaction/TronUiTransaction.js';
|
|
7
|
+
import { convertChainIdToDecimal } from '../../utils/convertChainIdToDecimal/convertChainIdToDecimal.js';
|
|
8
|
+
|
|
9
|
+
class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts);
|
|
12
|
+
this.ChainWallet = TronWallet;
|
|
13
|
+
this.name = 'Tron';
|
|
14
|
+
this.overrideKey = 'tron';
|
|
15
|
+
this.connectedChain = 'TRON';
|
|
16
|
+
this.supportedChains = ['TRON'];
|
|
17
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
18
|
+
this.tronNetworks = opts.tronNetworks;
|
|
19
|
+
// Initialize adapter immediately so it can start detecting the wallet
|
|
20
|
+
this.adapter = this.createAdapter();
|
|
21
|
+
}
|
|
22
|
+
confirmTransactionStatus() {
|
|
23
|
+
throw new Error('Method not implemented.');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the TronWallet Adapter instance
|
|
27
|
+
*/
|
|
28
|
+
getAdapter() {
|
|
29
|
+
return this.adapter;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if the wallet is installed
|
|
33
|
+
*/
|
|
34
|
+
isInstalledOnBrowser() {
|
|
35
|
+
const adapter = this.getAdapter();
|
|
36
|
+
return adapter.readyState === 'Found';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Connect to the wallet
|
|
40
|
+
*/
|
|
41
|
+
connect() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const adapter = this.getAdapter();
|
|
44
|
+
if (adapter.connected) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (adapter.readyState !== 'Found') {
|
|
48
|
+
throw new DynamicError(`${this.name} wallet not found. Please install the extension.`);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
yield adapter.connect();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the current address
|
|
60
|
+
*/
|
|
61
|
+
getAddress() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const adapter = this.getAdapter();
|
|
64
|
+
// If not connected, trigger the connection flow
|
|
65
|
+
if (!adapter.connected) {
|
|
66
|
+
yield this.connect();
|
|
67
|
+
}
|
|
68
|
+
return adapter.address || undefined;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get connected accounts
|
|
73
|
+
*/
|
|
74
|
+
getConnectedAccounts() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const address = yield this.getAddress();
|
|
77
|
+
return address ? [address] : [];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the current network
|
|
82
|
+
*/
|
|
83
|
+
getNetwork() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
try {
|
|
86
|
+
const networkInfo = yield this.adapter.network();
|
|
87
|
+
return convertChainIdToDecimal(networkInfo.chainId);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// If adapter is not connected, fall back to mainnet
|
|
91
|
+
return '728126428'; // Mainnet in decimal format
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if current network is testnet
|
|
97
|
+
*/
|
|
98
|
+
isTestnet() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
try {
|
|
101
|
+
const networkInfo = yield this.adapter.network();
|
|
102
|
+
// Testnet networkTypes: Shasta, Nile
|
|
103
|
+
return (networkInfo.networkType === 'Shasta' ||
|
|
104
|
+
networkInfo.networkType === 'Nile');
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
// If adapter is not connected, assume mainnet (not testnet)
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sign a message using the adapter
|
|
114
|
+
*/
|
|
115
|
+
signMessage(messageToSign) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const adapter = this.getAdapter();
|
|
118
|
+
if (!adapter.connected) {
|
|
119
|
+
throw new DynamicError('Wallet not connected');
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const signature = yield adapter.signMessage(messageToSign);
|
|
123
|
+
return signature;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
logger.error(`[${this.name}] Sign message failed:`, error);
|
|
127
|
+
throw new DynamicError(`Failed to sign message: ${error}`);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the TronWeb instance from the adapter
|
|
133
|
+
* The adapters store TronWeb in their internal _wallet property
|
|
134
|
+
*/
|
|
135
|
+
getWalletTronWeb() {
|
|
136
|
+
var _a;
|
|
137
|
+
const adapter = this.adapter;
|
|
138
|
+
// Try to access adapter's internal tronWeb directly
|
|
139
|
+
if (adapter.tronWeb) {
|
|
140
|
+
return adapter.tronWeb;
|
|
141
|
+
}
|
|
142
|
+
// Most adapters store it in _wallet.tronWeb
|
|
143
|
+
if ((_a = adapter._wallet) === null || _a === void 0 ? void 0 : _a.tronWeb) {
|
|
144
|
+
return adapter._wallet.tronWeb;
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get balance of an address
|
|
150
|
+
*/
|
|
151
|
+
getBalance(address) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
const tronWeb = this.getWalletTronWeb();
|
|
155
|
+
if (!((_a = tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.trx) === null || _a === void 0 ? void 0 : _a.getBalance)) {
|
|
156
|
+
return '0';
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const balance = yield tronWeb.trx.getBalance(address);
|
|
160
|
+
return (balance / 1000000).toFixed(6); // SUN → TRX
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
logger.error(`[${this.name}] Failed to get balance:`, error);
|
|
164
|
+
return '0';
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get enabled networks
|
|
170
|
+
*/
|
|
171
|
+
getEnabledNetworks() {
|
|
172
|
+
return this.tronNetworks;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Switch network (must be done in wallet UI)
|
|
176
|
+
*/
|
|
177
|
+
switchNetwork() {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
throw new DynamicError('Network switching must be done manually in the Tron wallet UI');
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get block explorer URLs for current network
|
|
184
|
+
*/
|
|
185
|
+
getBlockExplorerUrlsForCurrentNetwork() {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
var _a, _b, _c, _d;
|
|
188
|
+
try {
|
|
189
|
+
const networkInfo = yield this.adapter.network();
|
|
190
|
+
const decimalChainId = convertChainIdToDecimal(networkInfo.chainId);
|
|
191
|
+
return ((_b = (_a = this.tronNetworks.find((n) => String(n.chainId) === decimalChainId)) === null || _a === void 0 ? void 0 : _a.blockExplorerUrls) !== null && _b !== void 0 ? _b : []);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
// If adapter is not connected, return mainnet block explorer URLs
|
|
195
|
+
return ((_d = (_c = this.tronNetworks.find((n) => String(n.chainId) === '728126428')) === null || _c === void 0 ? void 0 : _c.blockExplorerUrls) !== null && _d !== void 0 ? _d : []);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Disconnect and cleanup
|
|
201
|
+
*/
|
|
202
|
+
endSession() {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const adapter = this.getAdapter();
|
|
205
|
+
if (adapter.connected) {
|
|
206
|
+
try {
|
|
207
|
+
yield adapter.disconnect();
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Setup event listeners - called by Dynamic's initEventListener()
|
|
217
|
+
*/
|
|
218
|
+
setupEventListeners() {
|
|
219
|
+
const { adapter } = this;
|
|
220
|
+
// Connect event
|
|
221
|
+
adapter.on('connect', (address) => {
|
|
222
|
+
this.emit('accountChange', {
|
|
223
|
+
accounts: [address],
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
// Disconnect event
|
|
227
|
+
adapter.on('disconnect', () => {
|
|
228
|
+
this.emit('disconnect');
|
|
229
|
+
});
|
|
230
|
+
// Account change event
|
|
231
|
+
adapter.on('accountsChanged', (address) => {
|
|
232
|
+
this.emit('accountChange', {
|
|
233
|
+
accounts: [address],
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
// Chain change event
|
|
237
|
+
adapter.on('chainChanged', (chainData) => {
|
|
238
|
+
const data = chainData;
|
|
239
|
+
this.emit('chainChange', {
|
|
240
|
+
chain: data.chainId,
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Cleanup event listeners
|
|
246
|
+
*/
|
|
247
|
+
teardownEventListeners() {
|
|
248
|
+
this.adapter.removeAllListeners();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create a UI transaction for the send balance flow
|
|
252
|
+
*
|
|
253
|
+
* @param from - The address sending the transaction
|
|
254
|
+
* @returns A TronUiTransaction instance
|
|
255
|
+
*/
|
|
256
|
+
createUiTransaction(from) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
yield this.validateActiveWallet(from);
|
|
259
|
+
// Get TronWeb from the wallet-specific window location
|
|
260
|
+
const tronWeb = this.getWalletTronWeb();
|
|
261
|
+
if (!tronWeb) {
|
|
262
|
+
throw new DynamicError('TronWeb not available');
|
|
263
|
+
}
|
|
264
|
+
return new TronUiTransaction({
|
|
265
|
+
from,
|
|
266
|
+
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
var _a;
|
|
268
|
+
if (!transaction.to) {
|
|
269
|
+
throw new DynamicError('Destination address is required');
|
|
270
|
+
}
|
|
271
|
+
// Create a minimal wallet instance for sending
|
|
272
|
+
const wallet = new TronWallet({
|
|
273
|
+
address: from,
|
|
274
|
+
chain: 'TRON',
|
|
275
|
+
connector: this,
|
|
276
|
+
id: 'temp-id',
|
|
277
|
+
isAuthenticated: false,
|
|
278
|
+
key: 'temp-key',
|
|
279
|
+
});
|
|
280
|
+
if (transaction.nonNativeAddress && transaction.nonNativeValue) {
|
|
281
|
+
// Handle TRC20 token transfers - not yet implemented
|
|
282
|
+
throw new DynamicError('TRC20 token transfers not yet implemented');
|
|
283
|
+
}
|
|
284
|
+
else if (transaction.value) {
|
|
285
|
+
// Handle native TRX transfers
|
|
286
|
+
const trxAmount = Number(transaction.value) / 1000000; // Convert SUN to TRX
|
|
287
|
+
const result = yield wallet.sendTrx(transaction.to, trxAmount, {
|
|
288
|
+
from,
|
|
289
|
+
});
|
|
290
|
+
return result.txid || ((_a = result.transaction) === null || _a === void 0 ? void 0 : _a.txID);
|
|
291
|
+
}
|
|
292
|
+
throw new DynamicError('Invalid transaction parameters');
|
|
293
|
+
}),
|
|
294
|
+
tronWeb,
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { TronWalletAdapterConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TronWalletAdapterConnector } from './TronWalletAdapterConnector';
|
|
@@ -3,28 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var tronwalletAdapters = require('@tronweb3/tronwallet-adapters');
|
|
7
|
+
var TronWalletAdapterConnector = require('../TronWalletAdapterConnector/TronWalletAdapterConnector.cjs');
|
|
7
8
|
|
|
8
|
-
class TrustTronConnector extends
|
|
9
|
+
class TrustTronConnector extends TronWalletAdapterConnector.TronWalletAdapterConnector {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
11
12
|
this.name = 'Trust Wallet';
|
|
12
13
|
this.overrideKey = 'trusttron';
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const provider = (_a = window.trustwallet) === null || _a === void 0 ? void 0 : _a.tronLink;
|
|
17
|
-
if (provider && provider.ready && !provider.chainId) {
|
|
18
|
-
// Trust Wallet doesn't expose chainId/network, set them manually
|
|
19
|
-
const host = (_c = (_b = provider.tronWeb) === null || _b === void 0 ? void 0 : _b.fullNode) === null || _c === void 0 ? void 0 : _c.host;
|
|
20
|
-
if (host === null || host === void 0 ? void 0 : host.includes('tron.twnodes.com')) {
|
|
21
|
-
Object.assign(provider, {
|
|
22
|
-
chainId: '728126428',
|
|
23
|
-
network: 'mainnet',
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return provider;
|
|
15
|
+
createAdapter() {
|
|
16
|
+
return new tronwalletAdapters.TrustAdapter();
|
|
28
17
|
}
|
|
29
18
|
}
|
|
30
19
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export declare class TrustTronConnector extends
|
|
1
|
+
import { TrustAdapter } from '@tronweb3/tronwallet-adapters';
|
|
2
|
+
import { TronWalletAdapterConnector } from '../TronWalletAdapterConnector';
|
|
3
|
+
export declare class TrustTronConnector extends TronWalletAdapterConnector {
|
|
4
4
|
name: string;
|
|
5
5
|
overrideKey: string;
|
|
6
|
-
|
|
6
|
+
protected createAdapter(): TrustAdapter;
|
|
7
7
|
}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
2
|
+
import { TrustAdapter } from '@tronweb3/tronwallet-adapters';
|
|
3
|
+
import { TronWalletAdapterConnector } from '../TronWalletAdapterConnector/TronWalletAdapterConnector.js';
|
|
3
4
|
|
|
4
|
-
class TrustTronConnector extends
|
|
5
|
+
class TrustTronConnector extends TronWalletAdapterConnector {
|
|
5
6
|
constructor() {
|
|
6
7
|
super(...arguments);
|
|
7
8
|
this.name = 'Trust Wallet';
|
|
8
9
|
this.overrideKey = 'trusttron';
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const provider = (_a = window.trustwallet) === null || _a === void 0 ? void 0 : _a.tronLink;
|
|
13
|
-
if (provider && provider.ready && !provider.chainId) {
|
|
14
|
-
// Trust Wallet doesn't expose chainId/network, set them manually
|
|
15
|
-
const host = (_c = (_b = provider.tronWeb) === null || _b === void 0 ? void 0 : _b.fullNode) === null || _c === void 0 ? void 0 : _c.host;
|
|
16
|
-
if (host === null || host === void 0 ? void 0 : host.includes('tron.twnodes.com')) {
|
|
17
|
-
Object.assign(provider, {
|
|
18
|
-
chainId: '728126428',
|
|
19
|
-
network: 'mainnet',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return provider;
|
|
11
|
+
createAdapter() {
|
|
12
|
+
return new TrustAdapter();
|
|
24
13
|
}
|
|
25
14
|
}
|
|
26
15
|
|
package/src/index.cjs
CHANGED
|
@@ -9,18 +9,17 @@ var BitgetTronConnector = require('./connectors/BitgetTronConnector/BitgetTronCo
|
|
|
9
9
|
var OKXTronConnector = require('./connectors/OKXTronConnector/OKXTronConnector.cjs');
|
|
10
10
|
var TokenPocketTronConnector = require('./connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs');
|
|
11
11
|
var TrustTronConnector = require('./connectors/TrustTronConnector/TrustTronConnector.cjs');
|
|
12
|
+
var TronWallet = require('./wallet/TronWallet/TronWallet.cjs');
|
|
12
13
|
var isTronWallet = require('./wallet/isTronWallet/isTronWallet.cjs');
|
|
13
|
-
var TronWallet = require('./wallet/TronWallet.cjs');
|
|
14
14
|
|
|
15
15
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/tron', _package.version);
|
|
16
16
|
const TronWalletConnectors = () => [
|
|
17
|
-
// BybitTronConnector, // Currently Bybit can't sign messages
|
|
18
17
|
BitgetTronConnector.BitgetTronConnector,
|
|
19
18
|
OKXTronConnector.OKXTronConnector,
|
|
20
19
|
TokenPocketTronConnector.TokenPocketTronConnector,
|
|
21
20
|
TrustTronConnector.TrustTronConnector,
|
|
22
21
|
];
|
|
23
22
|
|
|
24
|
-
exports.isTronWallet = isTronWallet.isTronWallet;
|
|
25
23
|
exports.TronWallet = TronWallet.TronWallet;
|
|
24
|
+
exports.isTronWallet = isTronWallet.isTronWallet;
|
|
26
25
|
exports.TronWalletConnectors = TronWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BitgetTronConnector } from './connectors/BitgetTronConnector';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { OKXTronConnector } from './connectors/OKXTronConnector';
|
|
3
|
+
import { TokenPocketTronConnector } from './connectors/TokenPocketTronConnector';
|
|
4
|
+
import { TrustTronConnector } from './connectors/TrustTronConnector';
|
|
5
5
|
export { TronWallet } from './wallet/TronWallet';
|
|
6
|
-
export
|
|
6
|
+
export { isTronWallet } from './wallet/isTronWallet';
|
|
7
|
+
export declare const TronWalletConnectors: () => (typeof BitgetTronConnector | typeof OKXTronConnector | typeof TokenPocketTronConnector | typeof TrustTronConnector)[];
|
package/src/index.js
CHANGED
|
@@ -5,12 +5,11 @@ import { BitgetTronConnector } from './connectors/BitgetTronConnector/BitgetTron
|
|
|
5
5
|
import { OKXTronConnector } from './connectors/OKXTronConnector/OKXTronConnector.js';
|
|
6
6
|
import { TokenPocketTronConnector } from './connectors/TokenPocketTronConnector/TokenPocketTronConnector.js';
|
|
7
7
|
import { TrustTronConnector } from './connectors/TrustTronConnector/TrustTronConnector.js';
|
|
8
|
+
export { TronWallet } from './wallet/TronWallet/TronWallet.js';
|
|
8
9
|
export { isTronWallet } from './wallet/isTronWallet/isTronWallet.js';
|
|
9
|
-
export { TronWallet } from './wallet/TronWallet.js';
|
|
10
10
|
|
|
11
11
|
assertPackageVersion('@dynamic-labs/tron', version);
|
|
12
12
|
const TronWalletConnectors = () => [
|
|
13
|
-
// BybitTronConnector, // Currently Bybit can't sign messages
|
|
14
13
|
BitgetTronConnector,
|
|
15
14
|
OKXTronConnector,
|
|
16
15
|
TokenPocketTronConnector,
|
package/src/types.d.ts
CHANGED
|
@@ -1,182 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tronWeb?: TronWeb;
|
|
9
|
-
bitkeep?: {
|
|
10
|
-
tron?: ITronProvider;
|
|
11
|
-
};
|
|
12
|
-
bybitWallet?: {
|
|
13
|
-
tronLink?: ITronProvider;
|
|
14
|
-
tronWeb?: TronWeb;
|
|
15
|
-
};
|
|
16
|
-
okxwallet?: {
|
|
17
|
-
tronLink?: ITronProvider;
|
|
18
|
-
tronWeb?: TronWeb;
|
|
19
|
-
};
|
|
20
|
-
trustwallet?: {
|
|
21
|
-
tronLink?: ITronProvider;
|
|
22
|
-
tronWeb?: TronWeb;
|
|
23
|
-
};
|
|
24
|
-
tokenpocket?: {
|
|
25
|
-
tron?: ITronProvider;
|
|
26
|
-
tronWeb?: TronWeb;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Interface that all Tron wallet providers must implement.
|
|
32
|
-
*
|
|
33
|
-
* This interface is designed to be flexible and work with different
|
|
34
|
-
* Tron wallet implementations like TronLink, TokenPocket, etc.
|
|
35
|
-
*/
|
|
36
|
-
export interface ITronProvider {
|
|
37
|
-
/** Whether the wallet is currently connected */
|
|
38
|
-
isConnected?: boolean;
|
|
39
|
-
/** Whether the wallet is ready */
|
|
40
|
-
ready?: boolean;
|
|
41
|
-
/** The current network chain ID */
|
|
42
|
-
chainId?: string;
|
|
43
|
-
/** The current network name */
|
|
44
|
-
network?: string;
|
|
45
|
-
/** The current wallet address */
|
|
46
|
-
address?: string;
|
|
47
|
-
/** TronWeb instance */
|
|
48
|
-
tronWeb?: TronWeb;
|
|
49
|
-
/** TronLink specific flag */
|
|
50
|
-
isTronLink?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Request connection to the wallet
|
|
53
|
-
* @returns Promise that resolves to connection result
|
|
54
|
-
*/
|
|
55
|
-
request?(params: {
|
|
56
|
-
method: string;
|
|
57
|
-
params?: unknown;
|
|
58
|
-
}): Promise<unknown>;
|
|
59
|
-
/**
|
|
60
|
-
* Connect to the wallet (TronLink style)
|
|
61
|
-
* @returns Promise that resolves to connection result
|
|
62
|
-
*/
|
|
63
|
-
connect?(): Promise<TronConnectionResult>;
|
|
64
|
-
/**
|
|
65
|
-
* Disconnect from the wallet
|
|
66
|
-
* @returns Promise that resolves when disconnected
|
|
67
|
-
*/
|
|
68
|
-
disconnect?(): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Sign a message
|
|
71
|
-
* @param message - Message to sign
|
|
72
|
-
* @returns Promise that resolves to the signature
|
|
73
|
-
*/
|
|
74
|
-
signMessage?(message: string): Promise<string>;
|
|
75
|
-
/**
|
|
76
|
-
* Sign a transaction
|
|
77
|
-
* @param transaction - Transaction to sign
|
|
78
|
-
* @returns Promise that resolves to the signed transaction
|
|
79
|
-
*/
|
|
80
|
-
signTransaction?(transaction: Types.Transaction): Promise<Types.SignedTransaction>;
|
|
81
|
-
/**
|
|
82
|
-
* Send a transaction
|
|
83
|
-
* @param transaction - Transaction to send
|
|
84
|
-
* @returns Promise that resolves to transaction result
|
|
85
|
-
*/
|
|
86
|
-
sendTransaction?(transaction: Types.SignedTransaction): Promise<Types.BroadcastReturn<Types.SignedTransaction>>;
|
|
87
|
-
/**
|
|
88
|
-
* Send TRX to an address
|
|
89
|
-
* @param to - Recipient address
|
|
90
|
-
* @param amount - Amount in TRX
|
|
91
|
-
* @param options - Optional parameters
|
|
92
|
-
* @returns Promise that resolves to transaction result
|
|
93
|
-
*/
|
|
94
|
-
sendTrx?(to: string, amount: number, options?: {
|
|
95
|
-
from?: string;
|
|
96
|
-
}): Promise<Types.BroadcastReturn<Types.SignedTransaction>>;
|
|
97
|
-
/**
|
|
98
|
-
* Send tokens to an address
|
|
99
|
-
* @param to - Recipient address
|
|
100
|
-
* @param amount - Amount of tokens
|
|
101
|
-
* @param tokenId - Token ID
|
|
102
|
-
* @param options - Optional parameters
|
|
103
|
-
* @returns Promise that resolves to transaction result
|
|
104
|
-
*/
|
|
105
|
-
sendToken?(to: string, amount: number, tokenId: string | number, options?: {
|
|
106
|
-
from?: string;
|
|
107
|
-
}): Promise<Types.BroadcastReturn<Types.SignedTransaction>>;
|
|
108
|
-
/**
|
|
109
|
-
* Get account balance
|
|
110
|
-
* @param address - Optional address (defaults to current account)
|
|
111
|
-
* @returns Promise that resolves to balance in SUN
|
|
112
|
-
*/
|
|
113
|
-
getBalance?(address?: string): Promise<number>;
|
|
114
|
-
/**
|
|
115
|
-
* Get token balance
|
|
116
|
-
* @param tokenId - Token ID
|
|
117
|
-
* @param address - Optional address (defaults to current account)
|
|
118
|
-
* @returns Promise that resolves to token balance
|
|
119
|
-
*/
|
|
120
|
-
getTokenBalance?(tokenId: string, address?: string): Promise<number>;
|
|
121
|
-
/**
|
|
122
|
-
* Get current network information
|
|
123
|
-
* @returns Promise that resolves to network info
|
|
124
|
-
*/
|
|
125
|
-
getNetwork?(): Promise<{
|
|
1
|
+
import type { Adapter, AdapterState, WalletReadyState } from '@tronweb3/tronwallet-abstract-adapter';
|
|
2
|
+
export type { Adapter, AdapterState, WalletReadyState };
|
|
3
|
+
export type TronAdapterEvents = {
|
|
4
|
+
connect: (address: string) => void;
|
|
5
|
+
disconnect: () => void;
|
|
6
|
+
accountsChanged: (address: string, preAddress?: string) => void;
|
|
7
|
+
chainChanged: (chainData: {
|
|
126
8
|
chainId: string;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* @param networkId - Network ID to switch to
|
|
132
|
-
* @returns Promise that resolves when network is switched
|
|
133
|
-
*/
|
|
134
|
-
switchNetwork?(networkId: string): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Add network
|
|
137
|
-
* @param network - Network configuration to add
|
|
138
|
-
* @returns Promise that resolves when network is added
|
|
139
|
-
*/
|
|
140
|
-
addNetwork?(network: {
|
|
141
|
-
networkId: string;
|
|
142
|
-
name: string;
|
|
143
|
-
rpcUrl: string;
|
|
144
|
-
chainId?: string;
|
|
145
|
-
}): Promise<void>;
|
|
146
|
-
/**
|
|
147
|
-
* Listen for account changes
|
|
148
|
-
* @param callback - Callback function for account changes
|
|
149
|
-
*/
|
|
150
|
-
onAccountChange?(callback: (address: string) => void): void;
|
|
151
|
-
/**
|
|
152
|
-
* Listen for network changes
|
|
153
|
-
* @param callback - Callback function for network changes
|
|
154
|
-
*/
|
|
155
|
-
onNetworkChange?(callback: (network: {
|
|
156
|
-
chainId: string;
|
|
157
|
-
name: string;
|
|
158
|
-
}) => void): void;
|
|
159
|
-
/**
|
|
160
|
-
* Remove account change listener
|
|
161
|
-
* @param callback - Callback function to remove
|
|
162
|
-
*/
|
|
163
|
-
removeAccountChangeListener?(callback: (address: string) => void): void;
|
|
164
|
-
/**
|
|
165
|
-
* Remove network change listener
|
|
166
|
-
* @param callback - Callback function to remove
|
|
167
|
-
*/
|
|
168
|
-
removeNetworkChangeListener?(callback: (network: {
|
|
169
|
-
chainId: string;
|
|
170
|
-
name: string;
|
|
171
|
-
}) => void): void;
|
|
172
|
-
/** Additional properties that providers may implement */
|
|
173
|
-
[key: string]: unknown;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Result from wallet connection
|
|
177
|
-
*/
|
|
178
|
-
export type TronConnectionResult = {
|
|
179
|
-
address: string;
|
|
180
|
-
chainId?: string;
|
|
181
|
-
network?: string;
|
|
182
|
-
} | string | boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
readyStateChanged: (state: WalletReadyState) => void;
|
|
11
|
+
error: (error: Error) => void;
|
|
12
|
+
};
|