@dynamic-labs/tron 4.33.0 → 4.35.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/_virtual/_tslib.cjs +36 -0
  3. package/_virtual/_tslib.js +32 -0
  4. package/package.cjs +1 -1
  5. package/package.js +1 -1
  6. package/package.json +14 -4
  7. package/src/connectors/BitgetTronConnector/BitgetTronConnector.cjs +20 -0
  8. package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +7 -0
  9. package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +16 -0
  10. package/src/connectors/BitgetTronConnector/index.d.ts +1 -0
  11. package/src/connectors/BybitTronConnector/BybitTronConnector.cjs +20 -0
  12. package/src/connectors/BybitTronConnector/BybitTronConnector.d.ts +7 -0
  13. package/src/connectors/BybitTronConnector/BybitTronConnector.js +16 -0
  14. package/src/connectors/BybitTronConnector/index.d.ts +1 -0
  15. package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +20 -0
  16. package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +7 -0
  17. package/src/connectors/OKXTronConnector/OKXTronConnector.js +16 -0
  18. package/src/connectors/OKXTronConnector/index.d.ts +1 -0
  19. package/src/connectors/TronWalletConnector/TronWalletConnector.cjs +255 -0
  20. package/src/connectors/TronWalletConnector/TronWalletConnector.d.ts +42 -0
  21. package/src/connectors/TronWalletConnector/TronWalletConnector.js +251 -0
  22. package/src/connectors/TronWalletConnector/index.d.ts +1 -0
  23. package/src/connectors/TrustTronConnector/TrustTronConnector.cjs +20 -0
  24. package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +7 -0
  25. package/src/connectors/TrustTronConnector/TrustTronConnector.js +16 -0
  26. package/src/connectors/TrustTronConnector/index.d.ts +1 -0
  27. package/src/index.cjs +18 -0
  28. package/src/index.d.ts +6 -1
  29. package/src/index.js +14 -0
  30. package/src/types.d.ts +78 -39
  31. package/src/utils/TronUiTransaction/TronUiTransaction.cjs +113 -0
  32. package/src/utils/TronUiTransaction/TronUiTransaction.d.ts +39 -0
  33. package/src/utils/TronUiTransaction/TronUiTransaction.js +108 -0
  34. package/src/utils/TronUiTransaction/index.d.ts +1 -0
  35. package/src/utils/getDefaultTronNetworks.cjs +60 -0
  36. package/src/utils/getDefaultTronNetworks.d.ts +9 -0
  37. package/src/utils/getDefaultTronNetworks.js +53 -0
  38. package/src/utils/index.d.ts +3 -0
  39. package/src/utils/provider.cjs +59 -0
  40. package/src/utils/provider.d.ts +24 -0
  41. package/src/utils/provider.js +53 -0
  42. package/src/wallet/TronWallet.cjs +106 -0
  43. package/src/wallet/TronWallet.d.ts +22 -0
  44. package/src/wallet/TronWallet.js +102 -0
  45. package/src/wallet/index.d.ts +2 -0
  46. package/src/wallet/isTronWallet/index.d.ts +1 -0
  47. package/src/wallet/isTronWallet/isTronWallet.cjs +8 -0
  48. package/src/wallet/isTronWallet/isTronWallet.d.ts +3 -0
  49. package/src/wallet/isTronWallet/isTronWallet.js +4 -0
@@ -0,0 +1,113 @@
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
+
10
+ // 1 TRX = 1,000,000 SUN (atomic units)
11
+ const SUN_PER_TRX = 1000000;
12
+ class TronUiTransaction {
13
+ constructor({ onSubmit, from, provider }) {
14
+ this.chain = 'TRON';
15
+ this.data = undefined;
16
+ this.fee = { gas: undefined };
17
+ this.from = from;
18
+ this.onSubmit = onSubmit;
19
+ this.provider = provider;
20
+ }
21
+ fetchFee() {
22
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
23
+ if (this.fee.gas)
24
+ return;
25
+ this.fee.gas = this.nonNativeAddress ? BigInt(500000) : BigInt(270000);
26
+ });
27
+ }
28
+ parse(input) {
29
+ const numericValue = parseFloat(input);
30
+ if (isNaN(numericValue))
31
+ return BigInt(0);
32
+ return BigInt(Math.floor(numericValue * SUN_PER_TRX));
33
+ }
34
+ parseNonNativeToken(input, decimals) {
35
+ const numericValue = parseFloat(input);
36
+ if (isNaN(numericValue))
37
+ return BigInt(0);
38
+ return BigInt(Math.floor(numericValue * Math.pow(10, decimals)));
39
+ }
40
+ format(value, options) {
41
+ var _a;
42
+ const trxValue = Number(value) / SUN_PER_TRX;
43
+ return utils.formatNumberText(String(trxValue), {
44
+ precision: (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 6,
45
+ });
46
+ }
47
+ formatNonNativeToken(value, decimals) {
48
+ const tokenValue = Number(value) / Math.pow(10, decimals);
49
+ return utils.formatNumberText(String(tokenValue), {
50
+ precision: decimals > 6 ? 6 : decimals,
51
+ });
52
+ }
53
+ submit() {
54
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
55
+ if (!this.to) {
56
+ throw new Error('Destination address is required');
57
+ }
58
+ if (!this.value && !this.nonNativeValue) {
59
+ throw new Error('Transaction value is required');
60
+ }
61
+ return this.onSubmit(this);
62
+ });
63
+ }
64
+ getBalance() {
65
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ const { tronWeb } = this.provider;
68
+ if (!tronWeb)
69
+ return BigInt(0);
70
+ if (this.nonNativeAddress) {
71
+ // Get TRC20 token balance
72
+ const contract = yield tronWeb.contract().at(this.nonNativeAddress);
73
+ const balance = yield contract.balanceOf(String(this.from)).call();
74
+ return BigInt(typeof balance === 'string' ? balance : balance.toString());
75
+ }
76
+ else {
77
+ // Get native TRX balance
78
+ const balance = yield tronWeb.trx.getBalance(String(this.from));
79
+ return BigInt(String(balance));
80
+ }
81
+ }
82
+ catch (error) {
83
+ walletConnectorCore.logger.error('Error occurred while fetching TRON balance. Please try again or contact support.');
84
+ return BigInt(0);
85
+ }
86
+ });
87
+ }
88
+ validateAddressFormat(address) {
89
+ if (address === 'dyn_send_transaction.multiple_recipients') {
90
+ return true;
91
+ }
92
+ try {
93
+ const { tronWeb } = this.provider;
94
+ if (!tronWeb)
95
+ return false;
96
+ // TRON addresses start with 'T' and are 34 characters long
97
+ if (!address.startsWith('T') || address.length !== 34) {
98
+ return false;
99
+ }
100
+ // Use TronWeb's built-in address validation
101
+ return tronWeb.isAddress(address);
102
+ }
103
+ catch (_a) {
104
+ return false;
105
+ }
106
+ }
107
+ isGasSponsored() {
108
+ return false;
109
+ }
110
+ }
111
+
112
+ exports.SUN_PER_TRX = SUN_PER_TRX;
113
+ exports.TronUiTransaction = TronUiTransaction;
@@ -0,0 +1,39 @@
1
+ import { IUITransaction, IUITransactionFormatOptions } from '@dynamic-labs/types';
2
+ import type { ITronProvider } from '../../types';
3
+ export declare const SUN_PER_TRX = 1000000;
4
+ type TronUiTransactionProps = {
5
+ /** TRON Address of the sender */
6
+ from: string;
7
+ /** The TRON provider instance, needed to interact with TronWeb */
8
+ provider: ITronProvider;
9
+ /** The function to call when the transaction is submitted */
10
+ onSubmit: (transaction: TronUiTransaction) => Promise<string>;
11
+ };
12
+ export declare class TronUiTransaction implements IUITransaction {
13
+ to: string | undefined;
14
+ from: string;
15
+ value: bigint | undefined;
16
+ chain: string;
17
+ receipt: string | undefined;
18
+ data: undefined;
19
+ fee: {
20
+ gas: bigint | undefined;
21
+ };
22
+ nonNativeAddress?: string;
23
+ nonNativeDecimal?: number;
24
+ nonNativeValue?: bigint;
25
+ nativePrice?: number;
26
+ private onSubmit;
27
+ private provider;
28
+ constructor({ onSubmit, from, provider }: TronUiTransactionProps);
29
+ fetchFee(): Promise<void>;
30
+ parse(input: string): bigint;
31
+ parseNonNativeToken(input: string, decimals: number): bigint;
32
+ format(value: bigint, options?: IUITransactionFormatOptions): string;
33
+ formatNonNativeToken(value: bigint, decimals: number): string;
34
+ submit(): Promise<string>;
35
+ getBalance(): Promise<bigint>;
36
+ validateAddressFormat(address: string): boolean;
37
+ isGasSponsored(): boolean;
38
+ }
39
+ export {};
@@ -0,0 +1,108 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { formatNumberText } from '@dynamic-labs/utils';
4
+ import { logger } from '@dynamic-labs/wallet-connector-core';
5
+
6
+ // 1 TRX = 1,000,000 SUN (atomic units)
7
+ const SUN_PER_TRX = 1000000;
8
+ class TronUiTransaction {
9
+ constructor({ onSubmit, from, provider }) {
10
+ this.chain = 'TRON';
11
+ this.data = undefined;
12
+ this.fee = { gas: undefined };
13
+ this.from = from;
14
+ this.onSubmit = onSubmit;
15
+ this.provider = provider;
16
+ }
17
+ fetchFee() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ if (this.fee.gas)
20
+ return;
21
+ this.fee.gas = this.nonNativeAddress ? BigInt(500000) : BigInt(270000);
22
+ });
23
+ }
24
+ parse(input) {
25
+ const numericValue = parseFloat(input);
26
+ if (isNaN(numericValue))
27
+ return BigInt(0);
28
+ return BigInt(Math.floor(numericValue * SUN_PER_TRX));
29
+ }
30
+ parseNonNativeToken(input, decimals) {
31
+ const numericValue = parseFloat(input);
32
+ if (isNaN(numericValue))
33
+ return BigInt(0);
34
+ return BigInt(Math.floor(numericValue * Math.pow(10, decimals)));
35
+ }
36
+ format(value, options) {
37
+ var _a;
38
+ const trxValue = Number(value) / SUN_PER_TRX;
39
+ return formatNumberText(String(trxValue), {
40
+ precision: (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 6,
41
+ });
42
+ }
43
+ formatNonNativeToken(value, decimals) {
44
+ const tokenValue = Number(value) / Math.pow(10, decimals);
45
+ return formatNumberText(String(tokenValue), {
46
+ precision: decimals > 6 ? 6 : decimals,
47
+ });
48
+ }
49
+ submit() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (!this.to) {
52
+ throw new Error('Destination address is required');
53
+ }
54
+ if (!this.value && !this.nonNativeValue) {
55
+ throw new Error('Transaction value is required');
56
+ }
57
+ return this.onSubmit(this);
58
+ });
59
+ }
60
+ getBalance() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ try {
63
+ const { tronWeb } = this.provider;
64
+ if (!tronWeb)
65
+ return BigInt(0);
66
+ if (this.nonNativeAddress) {
67
+ // Get TRC20 token balance
68
+ const contract = yield tronWeb.contract().at(this.nonNativeAddress);
69
+ const balance = yield contract.balanceOf(String(this.from)).call();
70
+ return BigInt(typeof balance === 'string' ? balance : balance.toString());
71
+ }
72
+ else {
73
+ // Get native TRX balance
74
+ const balance = yield tronWeb.trx.getBalance(String(this.from));
75
+ return BigInt(String(balance));
76
+ }
77
+ }
78
+ catch (error) {
79
+ logger.error('Error occurred while fetching TRON balance. Please try again or contact support.');
80
+ return BigInt(0);
81
+ }
82
+ });
83
+ }
84
+ validateAddressFormat(address) {
85
+ if (address === 'dyn_send_transaction.multiple_recipients') {
86
+ return true;
87
+ }
88
+ try {
89
+ const { tronWeb } = this.provider;
90
+ if (!tronWeb)
91
+ return false;
92
+ // TRON addresses start with 'T' and are 34 characters long
93
+ if (!address.startsWith('T') || address.length !== 34) {
94
+ return false;
95
+ }
96
+ // Use TronWeb's built-in address validation
97
+ return tronWeb.isAddress(address);
98
+ }
99
+ catch (_a) {
100
+ return false;
101
+ }
102
+ }
103
+ isGasSponsored() {
104
+ return false;
105
+ }
106
+ }
107
+
108
+ export { SUN_PER_TRX, TronUiTransaction };
@@ -0,0 +1 @@
1
+ export { TronUiTransaction, SUN_PER_TRX } from './TronUiTransaction';
@@ -0,0 +1,60 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const TRON_MAINNET_NETWORK = {
7
+ blockExplorerUrls: ['https://tronscan.org/'],
8
+ chainId: '728126428',
9
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
10
+ name: 'Tron Mainnet',
11
+ nativeCurrency: {
12
+ decimals: 6,
13
+ name: 'Tron',
14
+ symbol: 'TRX',
15
+ },
16
+ networkId: '728126428',
17
+ rpcUrls: ['https://api.trongrid.io'],
18
+ };
19
+ const TRON_NILE_TESTNET_NETWORK = {
20
+ blockExplorerUrls: ['https://nile.tronscan.org/'],
21
+ chainId: '728126430',
22
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
23
+ isTestnet: true,
24
+ name: 'Tron Nile Testnet',
25
+ nativeCurrency: {
26
+ decimals: 6,
27
+ name: 'Tron',
28
+ symbol: 'TRX',
29
+ },
30
+ networkId: '728126430',
31
+ rpcUrls: ['https://api.nileex.io'],
32
+ };
33
+ const TRON_SHASTA_TESTNET_NETWORK = {
34
+ blockExplorerUrls: ['https://shasta.tronscan.org/'],
35
+ chainId: '728126429',
36
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
37
+ isTestnet: true,
38
+ name: 'Tron Shasta Testnet',
39
+ nativeCurrency: {
40
+ decimals: 6,
41
+ name: 'Tron',
42
+ symbol: 'TRX',
43
+ },
44
+ networkId: '728126429',
45
+ rpcUrls: ['https://api.shasta.trongrid.io'],
46
+ };
47
+ /**
48
+ * Gets the default Tron networks configuration
49
+ * @returns Array of default Tron networks
50
+ */
51
+ const getDefaultTronNetworks = () => [
52
+ TRON_MAINNET_NETWORK,
53
+ TRON_NILE_TESTNET_NETWORK,
54
+ TRON_SHASTA_TESTNET_NETWORK,
55
+ ];
56
+
57
+ exports.TRON_MAINNET_NETWORK = TRON_MAINNET_NETWORK;
58
+ exports.TRON_NILE_TESTNET_NETWORK = TRON_NILE_TESTNET_NETWORK;
59
+ exports.TRON_SHASTA_TESTNET_NETWORK = TRON_SHASTA_TESTNET_NETWORK;
60
+ exports.getDefaultTronNetworks = getDefaultTronNetworks;
@@ -0,0 +1,9 @@
1
+ import type { GenericNetwork } from '@dynamic-labs/types';
2
+ export declare const TRON_MAINNET_NETWORK: GenericNetwork;
3
+ export declare const TRON_NILE_TESTNET_NETWORK: GenericNetwork;
4
+ export declare const TRON_SHASTA_TESTNET_NETWORK: GenericNetwork;
5
+ /**
6
+ * Gets the default Tron networks configuration
7
+ * @returns Array of default Tron networks
8
+ */
9
+ export declare const getDefaultTronNetworks: () => GenericNetwork[];
@@ -0,0 +1,53 @@
1
+ 'use client'
2
+ const TRON_MAINNET_NETWORK = {
3
+ blockExplorerUrls: ['https://tronscan.org/'],
4
+ chainId: '728126428',
5
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
6
+ name: 'Tron Mainnet',
7
+ nativeCurrency: {
8
+ decimals: 6,
9
+ name: 'Tron',
10
+ symbol: 'TRX',
11
+ },
12
+ networkId: '728126428',
13
+ rpcUrls: ['https://api.trongrid.io'],
14
+ };
15
+ const TRON_NILE_TESTNET_NETWORK = {
16
+ blockExplorerUrls: ['https://nile.tronscan.org/'],
17
+ chainId: '728126430',
18
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
19
+ isTestnet: true,
20
+ name: 'Tron Nile Testnet',
21
+ nativeCurrency: {
22
+ decimals: 6,
23
+ name: 'Tron',
24
+ symbol: 'TRX',
25
+ },
26
+ networkId: '728126430',
27
+ rpcUrls: ['https://api.nileex.io'],
28
+ };
29
+ const TRON_SHASTA_TESTNET_NETWORK = {
30
+ blockExplorerUrls: ['https://shasta.tronscan.org/'],
31
+ chainId: '728126429',
32
+ iconUrls: ['https://app.dynamic.xyz/assets/networks/tron.svg'],
33
+ isTestnet: true,
34
+ name: 'Tron Shasta Testnet',
35
+ nativeCurrency: {
36
+ decimals: 6,
37
+ name: 'Tron',
38
+ symbol: 'TRX',
39
+ },
40
+ networkId: '728126429',
41
+ rpcUrls: ['https://api.shasta.trongrid.io'],
42
+ };
43
+ /**
44
+ * Gets the default Tron networks configuration
45
+ * @returns Array of default Tron networks
46
+ */
47
+ const getDefaultTronNetworks = () => [
48
+ TRON_MAINNET_NETWORK,
49
+ TRON_NILE_TESTNET_NETWORK,
50
+ TRON_SHASTA_TESTNET_NETWORK,
51
+ ];
52
+
53
+ export { TRON_MAINNET_NETWORK, TRON_NILE_TESTNET_NETWORK, TRON_SHASTA_TESTNET_NETWORK, getDefaultTronNetworks };
@@ -0,0 +1,3 @@
1
+ export { assertProvider, getCurrentAddress, isProviderReady } from './provider';
2
+ export { getDefaultTronNetworks } from './getDefaultTronNetworks';
3
+ export { TronUiTransaction, SUN_PER_TRX } from './TronUiTransaction';
@@ -0,0 +1,59 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Asserts that a provider is available and throws an error if not
8
+ * @param provider - The provider to validate
9
+ * @param providerName - Human-readable name for error messages
10
+ * @returns The validated provider
11
+ * @throws {Error} If provider is not available
12
+ */
13
+ const assertProvider = (provider, providerName) => {
14
+ if (!provider) {
15
+ throw new Error(`${providerName} provider not available`);
16
+ }
17
+ return provider;
18
+ };
19
+ /**
20
+ * Gets the current address from a Tron provider using various methods
21
+ * @param provider - The Tron provider
22
+ * @returns The current address or undefined if not available
23
+ */
24
+ const getCurrentAddress = (provider) => {
25
+ var _a, _b, _c, _d;
26
+ // Try different ways to get the address
27
+ if (provider.address) {
28
+ return provider.address;
29
+ }
30
+ if ((_b = (_a = provider.tronWeb) === null || _a === void 0 ? void 0 : _a.defaultAddress) === null || _b === void 0 ? void 0 : _b.base58) {
31
+ return provider.tronWeb.defaultAddress.base58;
32
+ }
33
+ if (typeof ((_c = provider.tronWeb) === null || _c === void 0 ? void 0 : _c.defaultAddress) === 'string') {
34
+ return provider.tronWeb.defaultAddress;
35
+ }
36
+ // Check global tronWeb
37
+ if (typeof window !== 'undefined' && ((_d = window.tronWeb) === null || _d === void 0 ? void 0 : _d.defaultAddress)) {
38
+ if (typeof window.tronWeb.defaultAddress === 'string') {
39
+ return window.tronWeb.defaultAddress;
40
+ }
41
+ if (window.tronWeb.defaultAddress.base58) {
42
+ return window.tronWeb.defaultAddress.base58;
43
+ }
44
+ }
45
+ return undefined;
46
+ };
47
+ /**
48
+ * Checks if a Tron provider is ready and connected
49
+ * @param provider - The Tron provider
50
+ * @returns True if the provider is ready and connected
51
+ */
52
+ const isProviderReady = (provider) => {
53
+ const hasAddress = getCurrentAddress(provider);
54
+ return Boolean(provider.ready !== false && (provider.isConnected || hasAddress));
55
+ };
56
+
57
+ exports.assertProvider = assertProvider;
58
+ exports.getCurrentAddress = getCurrentAddress;
59
+ exports.isProviderReady = isProviderReady;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Utility functions for Tron provider validation and error handling
3
+ */
4
+ import type { ITronProvider } from '../types';
5
+ /**
6
+ * Asserts that a provider is available and throws an error if not
7
+ * @param provider - The provider to validate
8
+ * @param providerName - Human-readable name for error messages
9
+ * @returns The validated provider
10
+ * @throws {Error} If provider is not available
11
+ */
12
+ export declare const assertProvider: <T>(provider: T | undefined, providerName: string) => T;
13
+ /**
14
+ * Gets the current address from a Tron provider using various methods
15
+ * @param provider - The Tron provider
16
+ * @returns The current address or undefined if not available
17
+ */
18
+ export declare const getCurrentAddress: (provider: ITronProvider) => string | undefined;
19
+ /**
20
+ * Checks if a Tron provider is ready and connected
21
+ * @param provider - The Tron provider
22
+ * @returns True if the provider is ready and connected
23
+ */
24
+ export declare const isProviderReady: (provider: ITronProvider) => boolean;
@@ -0,0 +1,53 @@
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 };
@@ -0,0 +1,106 @@
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;
@@ -0,0 +1,22 @@
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
+ }