@dynamic-labs/tron 4.40.0 → 4.40.2
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 +13 -0
- package/README.md +264 -20
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -6
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs +436 -0
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.d.ts +115 -0
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.js +432 -0
- package/src/connectors/TronWalletAdapterConnector/index.d.ts +1 -0
- package/src/index.cjs +4 -13
- package/src/index.d.ts +5 -5
- package/src/index.js +3 -12
- 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/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.cjs +80 -0
- package/src/utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.d.ts +35 -0
- package/src/utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.js +75 -0
- package/src/utils/fetchTronWalletAdapterConnectors/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/utils/index.d.ts +1 -4
- 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/BitgetTronConnector/BitgetTronConnector.cjs +0 -20
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +0 -7
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +0 -16
- package/src/connectors/BitgetTronConnector/index.d.ts +0 -1
- package/src/connectors/BybitTronConnector/BybitTronConnector.d.ts +0 -7
- package/src/connectors/BybitTronConnector/index.d.ts +0 -1
- package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +0 -20
- package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +0 -7
- package/src/connectors/OKXTronConnector/OKXTronConnector.js +0 -16
- package/src/connectors/OKXTronConnector/index.d.ts +0 -1
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs +0 -28
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.d.ts +0 -7
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.js +0 -24
- package/src/connectors/TokenPocketTronConnector/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/connectors/TrustTronConnector/TrustTronConnector.cjs +0 -31
- package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +0 -7
- package/src/connectors/TrustTronConnector/TrustTronConnector.js +0 -27
- package/src/connectors/TrustTronConnector/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/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
package/src/utils/provider.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
/**
|
|
3
|
-
* Asserts that a provider is available and throws an error if not
|
|
4
|
-
* @param provider - The provider to validate
|
|
5
|
-
* @param providerName - Human-readable name for error messages
|
|
6
|
-
* @returns The validated provider
|
|
7
|
-
* @throws {Error} If provider is not available
|
|
8
|
-
*/
|
|
9
|
-
const assertProvider = (provider, providerName) => {
|
|
10
|
-
if (!provider) {
|
|
11
|
-
throw new Error(`${providerName} provider not available`);
|
|
12
|
-
}
|
|
13
|
-
return provider;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Gets the current address from a Tron provider using various methods
|
|
17
|
-
* @param provider - The Tron provider
|
|
18
|
-
* @returns The current address or undefined if not available
|
|
19
|
-
*/
|
|
20
|
-
const getCurrentAddress = (provider) => {
|
|
21
|
-
var _a, _b, _c, _d;
|
|
22
|
-
// Try different ways to get the address
|
|
23
|
-
if (provider.address) {
|
|
24
|
-
return provider.address;
|
|
25
|
-
}
|
|
26
|
-
if ((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.defaultAddress) === null || _b === void 0 ? void 0 : _b.base58) {
|
|
27
|
-
return provider.tronWeb.defaultAddress.base58;
|
|
28
|
-
}
|
|
29
|
-
if (typeof ((_c = provider.tronWeb) === null || _c === void 0 ? void 0 : _c.defaultAddress) === 'string') {
|
|
30
|
-
return provider.tronWeb.defaultAddress;
|
|
31
|
-
}
|
|
32
|
-
// Check global tronWeb
|
|
33
|
-
if (typeof window !== 'undefined' && ((_d = window.tronWeb) === null || _d === void 0 ? void 0 : _d.defaultAddress)) {
|
|
34
|
-
if (typeof window.tronWeb.defaultAddress === 'string') {
|
|
35
|
-
return window.tronWeb.defaultAddress;
|
|
36
|
-
}
|
|
37
|
-
if (window.tronWeb.defaultAddress.base58) {
|
|
38
|
-
return window.tronWeb.defaultAddress.base58;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a Tron provider is ready and connected
|
|
45
|
-
* @param provider - The Tron provider
|
|
46
|
-
* @returns True if the provider is ready and connected
|
|
47
|
-
*/
|
|
48
|
-
const isProviderReady = (provider) => {
|
|
49
|
-
const hasAddress = getCurrentAddress(provider);
|
|
50
|
-
return Boolean(provider.ready !== false && (provider.isConnected || hasAddress));
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export { assertProvider, getCurrentAddress, isProviderReady };
|
|
@@ -1,106 +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 utils = require('@dynamic-labs/utils');
|
|
8
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
-
var provider = require('../utils/provider.cjs');
|
|
10
|
-
|
|
11
|
-
class TronWallet extends walletConnectorCore.Wallet {
|
|
12
|
-
constructor(props) {
|
|
13
|
-
super(props);
|
|
14
|
-
}
|
|
15
|
-
getProvider() {
|
|
16
|
-
return this._connector.getProvider();
|
|
17
|
-
}
|
|
18
|
-
getTronWeb() {
|
|
19
|
-
var _a;
|
|
20
|
-
return (_a = this.getProvider()) === null || _a === void 0 ? void 0 : _a.tronWeb;
|
|
21
|
-
}
|
|
22
|
-
getAddress() {
|
|
23
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
25
|
-
const address = provider.getCurrentAddress(provider$1);
|
|
26
|
-
if (!address)
|
|
27
|
-
throw new utils.DynamicError('No address available');
|
|
28
|
-
return address;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
getNetwork() {
|
|
32
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return this._connector.getNetwork();
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
signMessage(message) {
|
|
37
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const messageString = typeof message === 'string' ? message : new TextDecoder().decode(message);
|
|
39
|
-
const signature = yield this._connector.signMessage(messageString);
|
|
40
|
-
if (!signature) {
|
|
41
|
-
throw new utils.DynamicError('Failed to sign message with signMessageV2');
|
|
42
|
-
}
|
|
43
|
-
return signature;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
getBalance(address) {
|
|
47
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const targetAddress = address || (yield this.getAddress());
|
|
49
|
-
return this._connector.getBalance(targetAddress);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
sendBalance() {
|
|
53
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
throw new utils.DynamicError('sendBalance not implemented. Use sendTrx or sendToken.');
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
sendTrx(to, amount, options) {
|
|
58
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
61
|
-
if (!((_b = (_a = provider$1.tronWeb) === null || _a === void 0 ? void 0 : _a.trx) === null || _b === void 0 ? void 0 : _b.sendTransaction)) {
|
|
62
|
-
throw new utils.DynamicError('TRX transfer not supported');
|
|
63
|
-
}
|
|
64
|
-
const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || (yield this.getAddress());
|
|
65
|
-
const amountInSun = provider$1.tronWeb.toSun(amount);
|
|
66
|
-
return provider$1.tronWeb.trx.sendTransaction(to, Number(amountInSun), {
|
|
67
|
-
address: fromAddress,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
getTokenBalance(tokenId, address) {
|
|
72
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
var _a;
|
|
74
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
75
|
-
const targetAddress = address || (yield this.getAddress());
|
|
76
|
-
if (!((_a = provider$1.tronWeb) === null || _a === void 0 ? void 0 : _a.contract)) {
|
|
77
|
-
throw new utils.DynamicError('TRC20 token balance not supported by this wallet');
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const contract = yield provider$1.tronWeb.contract().at(tokenId);
|
|
81
|
-
const balance = yield contract.balanceOf(targetAddress).call();
|
|
82
|
-
return typeof balance === 'string'
|
|
83
|
-
? parseInt(balance, 10)
|
|
84
|
-
: Number(balance);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw new utils.DynamicError(`TRC20 token balance query failed: ${error}`);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
getNetworkDetails() {
|
|
92
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const provider$1 = provider.assertProvider(this.getProvider(), 'Tron');
|
|
94
|
-
if (provider$1.getNetwork) {
|
|
95
|
-
return provider$1.getNetwork();
|
|
96
|
-
}
|
|
97
|
-
const chainId = yield this._connector.getNetwork();
|
|
98
|
-
return {
|
|
99
|
-
chainId: chainId || '0x2b6653dc', // mainnet default
|
|
100
|
-
name: chainId === '0x94a9059e' ? 'Nile Testnet' : 'Mainnet',
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
exports.TronWallet = TronWallet;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { TronWeb, Types } from 'tronweb';
|
|
2
|
-
import { Wallet, WalletProps } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import type { ITronProvider } from '../types';
|
|
4
|
-
import type { TronWalletConnector } from '../connectors/TronWalletConnector';
|
|
5
|
-
export declare class TronWallet extends Wallet<TronWalletConnector> {
|
|
6
|
-
constructor(props: WalletProps<TronWalletConnector>);
|
|
7
|
-
getProvider(): ITronProvider | undefined;
|
|
8
|
-
getTronWeb(): TronWeb | undefined;
|
|
9
|
-
getAddress(): Promise<string>;
|
|
10
|
-
getNetwork(): Promise<string | number | undefined>;
|
|
11
|
-
signMessage(message: string | Uint8Array): Promise<string>;
|
|
12
|
-
getBalance(address?: string): Promise<string | undefined>;
|
|
13
|
-
sendBalance(): Promise<string | undefined>;
|
|
14
|
-
sendTrx(to: string, amount: number, options?: {
|
|
15
|
-
from?: string;
|
|
16
|
-
}): Promise<Types.BroadcastReturn<Types.SignedTransaction>>;
|
|
17
|
-
getTokenBalance(tokenId: string, address?: string): Promise<number>;
|
|
18
|
-
getNetworkDetails(): Promise<{
|
|
19
|
-
chainId: string;
|
|
20
|
-
name: string;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
package/src/wallet/TronWallet.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
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 };
|
package/src/wallet/index.d.ts
DELETED