@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
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
-
var utils = require('@dynamic-labs/utils');
|
|
9
|
-
var TronWallet = require('../../wallet/TronWallet.cjs');
|
|
10
|
-
var provider = require('../../utils/provider.cjs');
|
|
11
|
-
var getDefaultTronNetworks = require('../../utils/getDefaultTronNetworks.cjs');
|
|
12
|
-
var TronUiTransaction = require('../../utils/TronUiTransaction/TronUiTransaction.cjs');
|
|
13
|
-
|
|
14
|
-
class TronWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
15
|
-
constructor(opts) {
|
|
16
|
-
super(opts);
|
|
17
|
-
this.ChainWallet = TronWallet.TronWallet;
|
|
18
|
-
this.name = 'Tron';
|
|
19
|
-
this.overrideKey = 'injectedtron';
|
|
20
|
-
this.connectedChain = 'TRON';
|
|
21
|
-
this.supportedChains = ['TRON'];
|
|
22
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
23
|
-
this.tronNetworks = opts.tronNetworks || getDefaultTronNetworks.getDefaultTronNetworks();
|
|
24
|
-
this.setupNetworkChangeListener();
|
|
25
|
-
}
|
|
26
|
-
setupNetworkChangeListener() {
|
|
27
|
-
const provider = this.getProvider();
|
|
28
|
-
if (!provider)
|
|
29
|
-
return;
|
|
30
|
-
if (provider.onNetworkChange &&
|
|
31
|
-
typeof provider.onNetworkChange === 'function') {
|
|
32
|
-
provider.onNetworkChange((network) => {
|
|
33
|
-
walletConnectorCore.logger.debug(`[${this.name}] Network change via provider:`, network);
|
|
34
|
-
this.emit('chainChange', {
|
|
35
|
-
chain: network.chainId || network.name || 'unknown',
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
connect() {
|
|
41
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
43
|
-
try {
|
|
44
|
-
if (provider$1.request) {
|
|
45
|
-
yield provider$1.request({ method: 'tron_requestAccounts' });
|
|
46
|
-
}
|
|
47
|
-
else if (provider$1.connect) {
|
|
48
|
-
yield provider$1.connect();
|
|
49
|
-
}
|
|
50
|
-
walletConnectorCore.logger.debug(`[${this.name}] Connected successfully`);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
walletConnectorCore.logger.error(`[${this.name}] Connection failed:`, error);
|
|
54
|
-
throw new utils.DynamicError('Failed to connect to Tron wallet');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
getAddress() {
|
|
59
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const provider$1 = this.getProvider();
|
|
61
|
-
if (!provider$1)
|
|
62
|
-
return undefined;
|
|
63
|
-
const address = provider.getCurrentAddress(provider$1);
|
|
64
|
-
if (address)
|
|
65
|
-
return address;
|
|
66
|
-
if (!provider.isProviderReady(provider$1)) {
|
|
67
|
-
yield this.connect();
|
|
68
|
-
return provider.getCurrentAddress(provider$1);
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
getNetwork() {
|
|
74
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
var _a, _b;
|
|
76
|
-
const provider = this.getProvider();
|
|
77
|
-
if (!provider)
|
|
78
|
-
return undefined;
|
|
79
|
-
if (provider.chainId)
|
|
80
|
-
return String(provider.chainId);
|
|
81
|
-
if (provider.getNetwork) {
|
|
82
|
-
try {
|
|
83
|
-
const networkInfo = yield provider.getNetwork();
|
|
84
|
-
return (networkInfo === null || networkInfo === void 0 ? void 0 : networkInfo.chainId) ? String(networkInfo.chainId) : undefined;
|
|
85
|
-
}
|
|
86
|
-
catch (_c) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if ((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.fullNode) === null || _b === void 0 ? void 0 : _b.host) {
|
|
91
|
-
const { host } = provider.tronWeb.fullNode;
|
|
92
|
-
const match = this.findNetworkByRpcUrl(host) || this.findNetworkByHostPattern(host);
|
|
93
|
-
return (match === null || match === void 0 ? void 0 : match.chainId) ? String(match.chainId) : undefined;
|
|
94
|
-
}
|
|
95
|
-
return undefined;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
findNetworkByRpcUrl(host) {
|
|
99
|
-
return this.tronNetworks.find((network) => network.rpcUrls.some((rpcUrl) => {
|
|
100
|
-
try {
|
|
101
|
-
const rpcHostname = new URL(rpcUrl).hostname;
|
|
102
|
-
const providerHostname = new URL(host).hostname;
|
|
103
|
-
return (providerHostname.includes(rpcHostname) ||
|
|
104
|
-
rpcHostname.includes(providerHostname));
|
|
105
|
-
}
|
|
106
|
-
catch (_a) {
|
|
107
|
-
return host.includes(rpcUrl) || rpcUrl.includes(host);
|
|
108
|
-
}
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
findNetworkByHostPattern(host) {
|
|
112
|
-
const hostLower = host.toLowerCase();
|
|
113
|
-
return this.tronNetworks.find((network) => {
|
|
114
|
-
const networkNameLower = network.name.toLowerCase();
|
|
115
|
-
if (hostLower.includes('nile') && networkNameLower.includes('nile'))
|
|
116
|
-
return true;
|
|
117
|
-
if (hostLower.includes('shasta') && networkNameLower.includes('shasta'))
|
|
118
|
-
return true;
|
|
119
|
-
if (hostLower.includes('mainnet') && networkNameLower.includes('mainnet'))
|
|
120
|
-
return true;
|
|
121
|
-
if (hostLower.includes('trongrid') &&
|
|
122
|
-
!hostLower.includes('nile') &&
|
|
123
|
-
!hostLower.includes('shasta') &&
|
|
124
|
-
networkNameLower.includes('mainnet'))
|
|
125
|
-
return true;
|
|
126
|
-
return false;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
getConnectedAccounts() {
|
|
130
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const address = yield this.getAddress();
|
|
132
|
-
return address ? [address] : [];
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
isTestnet() {
|
|
136
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
var _a;
|
|
138
|
-
const networkId = yield this.getNetwork();
|
|
139
|
-
const tronNetwork = this.tronNetworks.find((n) => n.chainId === networkId);
|
|
140
|
-
return (_a = tronNetwork === null || tronNetwork === void 0 ? void 0 : tronNetwork.isTestnet) !== null && _a !== void 0 ? _a : false;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* 🔑 Enforce signMessageV2 only
|
|
145
|
-
*/
|
|
146
|
-
signMessage(messageToSign) {
|
|
147
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
150
|
-
if (!provider.isProviderReady(provider$1)) {
|
|
151
|
-
yield this.connect();
|
|
152
|
-
}
|
|
153
|
-
if ((_b = (_a = provider$1.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.signMessageV2) {
|
|
154
|
-
const sig = yield provider$1.tronWeb.trx.signMessageV2(messageToSign);
|
|
155
|
-
if (typeof sig !== 'string') {
|
|
156
|
-
throw new utils.DynamicError('Invalid signature format from wallet');
|
|
157
|
-
}
|
|
158
|
-
return sig;
|
|
159
|
-
}
|
|
160
|
-
throw new utils.DynamicError('Wallet does not support signMessageV2, which is required');
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
getBalance(address) {
|
|
164
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
var _a, _b;
|
|
166
|
-
const provider = this.getProvider();
|
|
167
|
-
if (!((_b = (_a = provider === null || provider === void 0 ? void 0 : provider.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.getBalance))
|
|
168
|
-
return '0';
|
|
169
|
-
try {
|
|
170
|
-
const balance = yield provider.tronWeb.trx.getBalance(address);
|
|
171
|
-
return (balance / 1000000).toFixed(6); // SUN → TRX
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
walletConnectorCore.logger.error(`[${this.name}] Failed to get balance:`, error);
|
|
175
|
-
return '0';
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
isInstalledOnBrowser() {
|
|
180
|
-
const provider = this.getProvider();
|
|
181
|
-
return Boolean(provider);
|
|
182
|
-
}
|
|
183
|
-
getEnabledNetworks() {
|
|
184
|
-
return this.tronNetworks;
|
|
185
|
-
}
|
|
186
|
-
switchNetwork() {
|
|
187
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
throw new utils.DynamicError('Network switching must be done manually in the Tron wallet UI');
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
getBlockExplorerUrlsForCurrentNetwork() {
|
|
192
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
var _a, _b;
|
|
194
|
-
const currentNetwork = yield this.getNetwork();
|
|
195
|
-
return ((_b = (_a = this.tronNetworks.find((n) => n.chainId.toString() === (currentNetwork === null || currentNetwork === void 0 ? void 0 : currentNetwork.toString()))) === null || _a === void 0 ? void 0 : _a.blockExplorerUrls) !== null && _b !== void 0 ? _b : []);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
endSession() {
|
|
199
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
const provider = this.getProvider();
|
|
201
|
-
if (provider === null || provider === void 0 ? void 0 : provider.disconnect) {
|
|
202
|
-
try {
|
|
203
|
-
yield provider.disconnect();
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
walletConnectorCore.logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
/** Function used to create transactions in the SDK interface */
|
|
212
|
-
createUiTransaction(from) {
|
|
213
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
yield this.validateActiveWallet(from);
|
|
215
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
216
|
-
if (!provider$1.tronWeb) {
|
|
217
|
-
throw new utils.DynamicError('TronWeb not available');
|
|
218
|
-
}
|
|
219
|
-
return new TronUiTransaction.TronUiTransaction({
|
|
220
|
-
from,
|
|
221
|
-
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
var _a;
|
|
223
|
-
if (!transaction.to) {
|
|
224
|
-
throw new utils.DynamicError('Destination address is required');
|
|
225
|
-
}
|
|
226
|
-
// Create a minimal wallet instance for sending
|
|
227
|
-
const wallet = new TronWallet.TronWallet({
|
|
228
|
-
address: from,
|
|
229
|
-
chain: 'TRON',
|
|
230
|
-
connector: this,
|
|
231
|
-
id: 'temp-id',
|
|
232
|
-
isAuthenticated: false,
|
|
233
|
-
key: 'temp-key',
|
|
234
|
-
});
|
|
235
|
-
if (transaction.nonNativeAddress && transaction.nonNativeValue) {
|
|
236
|
-
// Handle TRC20 token transfers - simplified for now
|
|
237
|
-
throw new utils.DynamicError('TRC20 token transfers not yet implemented');
|
|
238
|
-
}
|
|
239
|
-
else if (transaction.value) {
|
|
240
|
-
// Handle native TRX transfers
|
|
241
|
-
const trxAmount = Number(transaction.value) / 1000000; // Convert SUN to TRX
|
|
242
|
-
const result = yield wallet.sendTrx(transaction.to, trxAmount, {
|
|
243
|
-
from,
|
|
244
|
-
});
|
|
245
|
-
return result.txid || ((_a = result.transaction) === null || _a === void 0 ? void 0 : _a.txID);
|
|
246
|
-
}
|
|
247
|
-
throw new utils.DynamicError('Invalid transaction parameters');
|
|
248
|
-
}),
|
|
249
|
-
provider: provider$1,
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
exports.TronWalletConnector = TronWalletConnector;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
-
import { Chain, WalletConnectorBase, WalletMetadata, ISendBalanceWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
|
|
4
|
-
import type { ITronProvider } from '../../types';
|
|
5
|
-
import { TronWallet } from '../../wallet/TronWallet';
|
|
6
|
-
export type TronWalletConnectorOpts = {
|
|
7
|
-
walletBook: WalletBookSchema;
|
|
8
|
-
metadata?: WalletMetadata;
|
|
9
|
-
tronNetworks?: GenericNetwork[];
|
|
10
|
-
};
|
|
11
|
-
export declare abstract class TronWalletConnector extends WalletConnectorBase<typeof TronWallet> implements ISendBalanceWalletConnector {
|
|
12
|
-
ChainWallet: typeof TronWallet;
|
|
13
|
-
name: string;
|
|
14
|
-
overrideKey: string;
|
|
15
|
-
connectedChain: Chain;
|
|
16
|
-
supportedChains: Chain[];
|
|
17
|
-
switchNetworkOnlyFromWallet: boolean;
|
|
18
|
-
protected tronNetworks: GenericNetwork[];
|
|
19
|
-
constructor(opts: TronWalletConnectorOpts);
|
|
20
|
-
abstract getProvider(): ITronProvider | undefined;
|
|
21
|
-
protected setupNetworkChangeListener(): void;
|
|
22
|
-
connect(): Promise<void>;
|
|
23
|
-
getAddress(): Promise<string | undefined>;
|
|
24
|
-
getNetwork(): Promise<string | undefined>;
|
|
25
|
-
private findNetworkByRpcUrl;
|
|
26
|
-
private findNetworkByHostPattern;
|
|
27
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
28
|
-
isTestnet(): Promise<boolean>;
|
|
29
|
-
/**
|
|
30
|
-
* 🔑 Enforce signMessageV2 only
|
|
31
|
-
*/
|
|
32
|
-
signMessage(messageToSign: string): Promise<string>;
|
|
33
|
-
getBalance(address: string): Promise<string | undefined>;
|
|
34
|
-
isInstalledOnBrowser(): boolean;
|
|
35
|
-
getEnabledNetworks(): GenericNetwork[];
|
|
36
|
-
switchNetwork(): Promise<void>;
|
|
37
|
-
getBlockExplorerUrlsForCurrentNetwork(): Promise<string[]>;
|
|
38
|
-
endSession(): Promise<void>;
|
|
39
|
-
/** Function used to create transactions in the SDK interface */
|
|
40
|
-
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
41
|
-
}
|
|
42
|
-
export type TronWalletConnectorType = TronWalletConnector;
|
|
@@ -1,251 +0,0 @@
|
|
|
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.js';
|
|
6
|
-
import { assertProvider, getCurrentAddress, isProviderReady } from '../../utils/provider.js';
|
|
7
|
-
import { getDefaultTronNetworks } from '../../utils/getDefaultTronNetworks.js';
|
|
8
|
-
import { TronUiTransaction } from '../../utils/TronUiTransaction/TronUiTransaction.js';
|
|
9
|
-
|
|
10
|
-
class TronWalletConnector extends WalletConnectorBase {
|
|
11
|
-
constructor(opts) {
|
|
12
|
-
super(opts);
|
|
13
|
-
this.ChainWallet = TronWallet;
|
|
14
|
-
this.name = 'Tron';
|
|
15
|
-
this.overrideKey = 'injectedtron';
|
|
16
|
-
this.connectedChain = 'TRON';
|
|
17
|
-
this.supportedChains = ['TRON'];
|
|
18
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
19
|
-
this.tronNetworks = opts.tronNetworks || getDefaultTronNetworks();
|
|
20
|
-
this.setupNetworkChangeListener();
|
|
21
|
-
}
|
|
22
|
-
setupNetworkChangeListener() {
|
|
23
|
-
const provider = this.getProvider();
|
|
24
|
-
if (!provider)
|
|
25
|
-
return;
|
|
26
|
-
if (provider.onNetworkChange &&
|
|
27
|
-
typeof provider.onNetworkChange === 'function') {
|
|
28
|
-
provider.onNetworkChange((network) => {
|
|
29
|
-
logger.debug(`[${this.name}] Network change via provider:`, network);
|
|
30
|
-
this.emit('chainChange', {
|
|
31
|
-
chain: network.chainId || network.name || 'unknown',
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
connect() {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
39
|
-
try {
|
|
40
|
-
if (provider.request) {
|
|
41
|
-
yield provider.request({ method: 'tron_requestAccounts' });
|
|
42
|
-
}
|
|
43
|
-
else if (provider.connect) {
|
|
44
|
-
yield provider.connect();
|
|
45
|
-
}
|
|
46
|
-
logger.debug(`[${this.name}] Connected successfully`);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
logger.error(`[${this.name}] Connection failed:`, error);
|
|
50
|
-
throw new DynamicError('Failed to connect to Tron wallet');
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
getAddress() {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const provider = this.getProvider();
|
|
57
|
-
if (!provider)
|
|
58
|
-
return undefined;
|
|
59
|
-
const address = getCurrentAddress(provider);
|
|
60
|
-
if (address)
|
|
61
|
-
return address;
|
|
62
|
-
if (!isProviderReady(provider)) {
|
|
63
|
-
yield this.connect();
|
|
64
|
-
return getCurrentAddress(provider);
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
getNetwork() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
const provider = this.getProvider();
|
|
73
|
-
if (!provider)
|
|
74
|
-
return undefined;
|
|
75
|
-
if (provider.chainId)
|
|
76
|
-
return String(provider.chainId);
|
|
77
|
-
if (provider.getNetwork) {
|
|
78
|
-
try {
|
|
79
|
-
const networkInfo = yield provider.getNetwork();
|
|
80
|
-
return (networkInfo === null || networkInfo === void 0 ? void 0 : networkInfo.chainId) ? String(networkInfo.chainId) : undefined;
|
|
81
|
-
}
|
|
82
|
-
catch (_c) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if ((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.fullNode) === null || _b === void 0 ? void 0 : _b.host) {
|
|
87
|
-
const { host } = provider.tronWeb.fullNode;
|
|
88
|
-
const match = this.findNetworkByRpcUrl(host) || this.findNetworkByHostPattern(host);
|
|
89
|
-
return (match === null || match === void 0 ? void 0 : match.chainId) ? String(match.chainId) : undefined;
|
|
90
|
-
}
|
|
91
|
-
return undefined;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
findNetworkByRpcUrl(host) {
|
|
95
|
-
return this.tronNetworks.find((network) => network.rpcUrls.some((rpcUrl) => {
|
|
96
|
-
try {
|
|
97
|
-
const rpcHostname = new URL(rpcUrl).hostname;
|
|
98
|
-
const providerHostname = new URL(host).hostname;
|
|
99
|
-
return (providerHostname.includes(rpcHostname) ||
|
|
100
|
-
rpcHostname.includes(providerHostname));
|
|
101
|
-
}
|
|
102
|
-
catch (_a) {
|
|
103
|
-
return host.includes(rpcUrl) || rpcUrl.includes(host);
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
findNetworkByHostPattern(host) {
|
|
108
|
-
const hostLower = host.toLowerCase();
|
|
109
|
-
return this.tronNetworks.find((network) => {
|
|
110
|
-
const networkNameLower = network.name.toLowerCase();
|
|
111
|
-
if (hostLower.includes('nile') && networkNameLower.includes('nile'))
|
|
112
|
-
return true;
|
|
113
|
-
if (hostLower.includes('shasta') && networkNameLower.includes('shasta'))
|
|
114
|
-
return true;
|
|
115
|
-
if (hostLower.includes('mainnet') && networkNameLower.includes('mainnet'))
|
|
116
|
-
return true;
|
|
117
|
-
if (hostLower.includes('trongrid') &&
|
|
118
|
-
!hostLower.includes('nile') &&
|
|
119
|
-
!hostLower.includes('shasta') &&
|
|
120
|
-
networkNameLower.includes('mainnet'))
|
|
121
|
-
return true;
|
|
122
|
-
return false;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
getConnectedAccounts() {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const address = yield this.getAddress();
|
|
128
|
-
return address ? [address] : [];
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
isTestnet() {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
var _a;
|
|
134
|
-
const networkId = yield this.getNetwork();
|
|
135
|
-
const tronNetwork = this.tronNetworks.find((n) => n.chainId === networkId);
|
|
136
|
-
return (_a = tronNetwork === null || tronNetwork === void 0 ? void 0 : tronNetwork.isTestnet) !== null && _a !== void 0 ? _a : false;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 🔑 Enforce signMessageV2 only
|
|
141
|
-
*/
|
|
142
|
-
signMessage(messageToSign) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
var _a, _b;
|
|
145
|
-
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
146
|
-
if (!isProviderReady(provider)) {
|
|
147
|
-
yield this.connect();
|
|
148
|
-
}
|
|
149
|
-
if ((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.signMessageV2) {
|
|
150
|
-
const sig = yield provider.tronWeb.trx.signMessageV2(messageToSign);
|
|
151
|
-
if (typeof sig !== 'string') {
|
|
152
|
-
throw new DynamicError('Invalid signature format from wallet');
|
|
153
|
-
}
|
|
154
|
-
return sig;
|
|
155
|
-
}
|
|
156
|
-
throw new DynamicError('Wallet does not support signMessageV2, which is required');
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
getBalance(address) {
|
|
160
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
var _a, _b;
|
|
162
|
-
const provider = this.getProvider();
|
|
163
|
-
if (!((_b = (_a = provider === null || provider === void 0 ? void 0 : provider.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.getBalance))
|
|
164
|
-
return '0';
|
|
165
|
-
try {
|
|
166
|
-
const balance = yield provider.tronWeb.trx.getBalance(address);
|
|
167
|
-
return (balance / 1000000).toFixed(6); // SUN → TRX
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
logger.error(`[${this.name}] Failed to get balance:`, error);
|
|
171
|
-
return '0';
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
isInstalledOnBrowser() {
|
|
176
|
-
const provider = this.getProvider();
|
|
177
|
-
return Boolean(provider);
|
|
178
|
-
}
|
|
179
|
-
getEnabledNetworks() {
|
|
180
|
-
return this.tronNetworks;
|
|
181
|
-
}
|
|
182
|
-
switchNetwork() {
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
throw new DynamicError('Network switching must be done manually in the Tron wallet UI');
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
getBlockExplorerUrlsForCurrentNetwork() {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
var _a, _b;
|
|
190
|
-
const currentNetwork = yield this.getNetwork();
|
|
191
|
-
return ((_b = (_a = this.tronNetworks.find((n) => n.chainId.toString() === (currentNetwork === null || currentNetwork === void 0 ? void 0 : currentNetwork.toString()))) === null || _a === void 0 ? void 0 : _a.blockExplorerUrls) !== null && _b !== void 0 ? _b : []);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
endSession() {
|
|
195
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
const provider = this.getProvider();
|
|
197
|
-
if (provider === null || provider === void 0 ? void 0 : provider.disconnect) {
|
|
198
|
-
try {
|
|
199
|
-
yield provider.disconnect();
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/** Function used to create transactions in the SDK interface */
|
|
208
|
-
createUiTransaction(from) {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
-
yield this.validateActiveWallet(from);
|
|
211
|
-
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
212
|
-
if (!provider.tronWeb) {
|
|
213
|
-
throw new DynamicError('TronWeb not available');
|
|
214
|
-
}
|
|
215
|
-
return new TronUiTransaction({
|
|
216
|
-
from,
|
|
217
|
-
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
var _a;
|
|
219
|
-
if (!transaction.to) {
|
|
220
|
-
throw new DynamicError('Destination address is required');
|
|
221
|
-
}
|
|
222
|
-
// Create a minimal wallet instance for sending
|
|
223
|
-
const wallet = new TronWallet({
|
|
224
|
-
address: from,
|
|
225
|
-
chain: 'TRON',
|
|
226
|
-
connector: this,
|
|
227
|
-
id: 'temp-id',
|
|
228
|
-
isAuthenticated: false,
|
|
229
|
-
key: 'temp-key',
|
|
230
|
-
});
|
|
231
|
-
if (transaction.nonNativeAddress && transaction.nonNativeValue) {
|
|
232
|
-
// Handle TRC20 token transfers - simplified for now
|
|
233
|
-
throw new DynamicError('TRC20 token transfers not yet implemented');
|
|
234
|
-
}
|
|
235
|
-
else if (transaction.value) {
|
|
236
|
-
// Handle native TRX transfers
|
|
237
|
-
const trxAmount = Number(transaction.value) / 1000000; // Convert SUN to TRX
|
|
238
|
-
const result = yield wallet.sendTrx(transaction.to, trxAmount, {
|
|
239
|
-
from,
|
|
240
|
-
});
|
|
241
|
-
return result.txid || ((_a = result.transaction) === null || _a === void 0 ? void 0 : _a.txID);
|
|
242
|
-
}
|
|
243
|
-
throw new DynamicError('Invalid transaction parameters');
|
|
244
|
-
}),
|
|
245
|
-
provider,
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export { TronWalletConnector };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { TronWalletConnector } from './TronWalletConnector';
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default endpoint mappings for common TRON networks
|
|
8
|
-
*/
|
|
9
|
-
const DEFAULT_TRON_ENDPOINT_MAPPINGS = [
|
|
10
|
-
{
|
|
11
|
-
hostPatterns: ['api.trongrid.io', 'trx.mytokenpocket.vip'],
|
|
12
|
-
networkConfig: {
|
|
13
|
-
chainId: '728126428',
|
|
14
|
-
network: 'mainnet',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
hostPatterns: ['api.shasta.trongrid.io'],
|
|
19
|
-
networkConfig: {
|
|
20
|
-
chainId: '2494104990',
|
|
21
|
-
network: 'shasta',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
hostPatterns: ['api.nileex.io'],
|
|
26
|
-
networkConfig: {
|
|
27
|
-
chainId: '3448148188',
|
|
28
|
-
network: 'nile',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
/**
|
|
33
|
-
* Detects and sets TRON network information based on the provider's TronWeb endpoint.
|
|
34
|
-
* This is useful for wallets that don't expose chainId/network properties directly.
|
|
35
|
-
*
|
|
36
|
-
* @param provider - The TRON provider to detect network information for
|
|
37
|
-
* @param additionalMappings - Additional endpoint mappings to check before the defaults.
|
|
38
|
-
* @returns The provider with network information set (if detected), or the original provider
|
|
39
|
-
*/
|
|
40
|
-
const detectTronNetworkFromProvider = (provider, additionalMappings = []) => {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
if (!provider || provider.chainId) {
|
|
43
|
-
// Return early if provider is null/undefined or already has chainId
|
|
44
|
-
return provider;
|
|
45
|
-
}
|
|
46
|
-
const host = (_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.fullNode) === null || _b === void 0 ? void 0 : _b.host;
|
|
47
|
-
if (!host) {
|
|
48
|
-
return provider;
|
|
49
|
-
}
|
|
50
|
-
// Combine additional mappings with defaults, with additional mappings taking precedence
|
|
51
|
-
const allMappings = [
|
|
52
|
-
...additionalMappings,
|
|
53
|
-
...DEFAULT_TRON_ENDPOINT_MAPPINGS,
|
|
54
|
-
];
|
|
55
|
-
// Find the first matching endpoint mapping
|
|
56
|
-
for (const mapping of allMappings) {
|
|
57
|
-
const isMatch = mapping.hostPatterns.some((pattern) => host.includes(pattern));
|
|
58
|
-
if (isMatch) {
|
|
59
|
-
Object.assign(provider, mapping.networkConfig);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return provider;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.DEFAULT_TRON_ENDPOINT_MAPPINGS = DEFAULT_TRON_ENDPOINT_MAPPINGS;
|
|
67
|
-
exports.detectTronNetworkFromProvider = detectTronNetworkFromProvider;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ITronProvider } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Network configuration for TRON networks
|
|
4
|
-
*/
|
|
5
|
-
export interface TronNetworkConfig {
|
|
6
|
-
chainId: string;
|
|
7
|
-
network: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Endpoint mapping configuration for network detection
|
|
11
|
-
*/
|
|
12
|
-
export interface TronEndpointMapping {
|
|
13
|
-
/** URL patterns that should match this network (checked with includes()) */
|
|
14
|
-
hostPatterns: string[];
|
|
15
|
-
/** Network configuration to apply when pattern matches */
|
|
16
|
-
networkConfig: TronNetworkConfig;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Default endpoint mappings for common TRON networks
|
|
20
|
-
*/
|
|
21
|
-
export declare const DEFAULT_TRON_ENDPOINT_MAPPINGS: TronEndpointMapping[];
|
|
22
|
-
/**
|
|
23
|
-
* Detects and sets TRON network information based on the provider's TronWeb endpoint.
|
|
24
|
-
* This is useful for wallets that don't expose chainId/network properties directly.
|
|
25
|
-
*
|
|
26
|
-
* @param provider - The TRON provider to detect network information for
|
|
27
|
-
* @param additionalMappings - Additional endpoint mappings to check before the defaults.
|
|
28
|
-
* @returns The provider with network information set (if detected), or the original provider
|
|
29
|
-
*/
|
|
30
|
-
export declare const detectTronNetworkFromProvider: <T extends ITronProvider>(provider: T, additionalMappings?: TronEndpointMapping[]) => T;
|