@dynamic-labs/tron 4.34.0 → 4.36.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/CHANGELOG.md +26 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -3
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.cjs +20 -0
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +7 -0
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +16 -0
- package/src/connectors/BitgetTronConnector/index.d.ts +1 -0
- package/src/connectors/BybitTronConnector/BybitTronConnector.cjs +20 -0
- package/src/connectors/BybitTronConnector/BybitTronConnector.d.ts +7 -0
- package/src/connectors/BybitTronConnector/BybitTronConnector.js +16 -0
- package/src/connectors/BybitTronConnector/index.d.ts +1 -0
- package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +20 -0
- package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +7 -0
- package/src/connectors/OKXTronConnector/OKXTronConnector.js +16 -0
- package/src/connectors/OKXTronConnector/index.d.ts +1 -0
- package/src/connectors/TronWalletConnector/TronWalletConnector.cjs +255 -0
- package/src/connectors/TronWalletConnector/TronWalletConnector.d.ts +42 -0
- package/src/connectors/TronWalletConnector/TronWalletConnector.js +251 -0
- package/src/connectors/TronWalletConnector/index.d.ts +1 -0
- package/src/connectors/TrustTronConnector/TrustTronConnector.cjs +20 -0
- package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +7 -0
- package/src/connectors/TrustTronConnector/TrustTronConnector.js +16 -0
- package/src/connectors/TrustTronConnector/index.d.ts +1 -0
- package/src/index.cjs +18 -0
- package/src/index.d.ts +6 -1
- package/src/index.js +14 -0
- package/src/types.d.ts +13 -2
- package/src/utils/TronUiTransaction/TronUiTransaction.cjs +121 -0
- package/src/utils/TronUiTransaction/TronUiTransaction.d.ts +39 -0
- package/src/utils/TronUiTransaction/TronUiTransaction.js +116 -0
- package/src/utils/TronUiTransaction/index.d.ts +1 -0
- package/src/utils/getDefaultTronNetworks.cjs +60 -0
- package/src/utils/getDefaultTronNetworks.js +53 -0
- package/src/utils/getTronGasEstimation.cjs +136 -0
- package/src/utils/getTronGasEstimation.d.ts +47 -0
- package/src/utils/getTronGasEstimation.js +129 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/provider.cjs +59 -0
- package/src/utils/provider.js +53 -0
- package/src/wallet/TronWallet.cjs +106 -0
- package/src/wallet/TronWallet.d.ts +22 -0
- package/src/wallet/TronWallet.js +102 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isTronWallet/index.d.ts +1 -0
- package/src/wallet/isTronWallet/isTronWallet.cjs +8 -0
- package/src/wallet/isTronWallet/isTronWallet.d.ts +3 -0
- package/src/wallet/isTronWallet/isTronWallet.js +4 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { assertProvider, getCurrentAddress } from '../utils/provider.js';
|
|
6
|
+
|
|
7
|
+
class TronWallet extends Wallet {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
}
|
|
11
|
+
getProvider() {
|
|
12
|
+
return this._connector.getProvider();
|
|
13
|
+
}
|
|
14
|
+
getTronWeb() {
|
|
15
|
+
var _a;
|
|
16
|
+
return (_a = this.getProvider()) === null || _a === void 0 ? void 0 : _a.tronWeb;
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
21
|
+
const address = getCurrentAddress(provider);
|
|
22
|
+
if (!address)
|
|
23
|
+
throw new DynamicError('No address available');
|
|
24
|
+
return address;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getNetwork() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this._connector.getNetwork();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
signMessage(message) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const messageString = typeof message === 'string' ? message : new TextDecoder().decode(message);
|
|
35
|
+
const signature = yield this._connector.signMessage(messageString);
|
|
36
|
+
if (!signature) {
|
|
37
|
+
throw new DynamicError('Failed to sign message with signMessageV2');
|
|
38
|
+
}
|
|
39
|
+
return signature;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getBalance(address) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const targetAddress = address || (yield this.getAddress());
|
|
45
|
+
return this._connector.getBalance(targetAddress);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
sendBalance() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
throw new DynamicError('sendBalance not implemented. Use sendTrx or sendToken.');
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
sendTrx(to, amount, options) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
57
|
+
if (!((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.sendTransaction)) {
|
|
58
|
+
throw new DynamicError('TRX transfer not supported');
|
|
59
|
+
}
|
|
60
|
+
const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || (yield this.getAddress());
|
|
61
|
+
const amountInSun = provider.tronWeb.toSun(amount);
|
|
62
|
+
return provider.tronWeb.trx.sendTransaction(to, Number(amountInSun), {
|
|
63
|
+
address: fromAddress,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getTokenBalance(tokenId, address) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
var _a;
|
|
70
|
+
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
71
|
+
const targetAddress = address || (yield this.getAddress());
|
|
72
|
+
if (!((_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.contract)) {
|
|
73
|
+
throw new DynamicError('TRC20 token balance not supported by this wallet');
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const contract = yield provider.tronWeb.contract().at(tokenId);
|
|
77
|
+
const balance = yield contract.balanceOf(targetAddress).call();
|
|
78
|
+
return typeof balance === 'string'
|
|
79
|
+
? parseInt(balance, 10)
|
|
80
|
+
: Number(balance);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new DynamicError(`TRC20 token balance query failed: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
getNetworkDetails() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const provider = assertProvider(this.getProvider(), 'Tron');
|
|
90
|
+
if (provider.getNetwork) {
|
|
91
|
+
return provider.getNetwork();
|
|
92
|
+
}
|
|
93
|
+
const chainId = yield this._connector.getNetwork();
|
|
94
|
+
return {
|
|
95
|
+
chainId: chainId || '0x2b6653dc', // mainnet default
|
|
96
|
+
name: chainId === '0x94a9059e' ? 'Nile Testnet' : 'Mainnet',
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { TronWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isTronWallet } from './isTronWallet';
|