@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.
Files changed (63) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +264 -20
  3. package/package.cjs +1 -1
  4. package/package.js +1 -1
  5. package/package.json +8 -6
  6. package/src/connectors/BitgetTronConnector/BitgetTronConnector.cjs +5 -5
  7. package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +4 -4
  8. package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +5 -5
  9. package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +5 -5
  10. package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +4 -4
  11. package/src/connectors/OKXTronConnector/OKXTronConnector.js +5 -5
  12. package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs +5 -13
  13. package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.d.ts +4 -4
  14. package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.js +5 -13
  15. package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs +304 -0
  16. package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.d.ts +107 -0
  17. package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.js +300 -0
  18. package/src/connectors/TronWalletAdapterConnector/index.d.ts +1 -0
  19. package/src/connectors/TrustTronConnector/TrustTronConnector.cjs +5 -16
  20. package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +4 -4
  21. package/src/connectors/TrustTronConnector/TrustTronConnector.js +5 -16
  22. package/src/index.cjs +2 -3
  23. package/src/index.d.ts +5 -4
  24. package/src/index.js +1 -2
  25. package/src/types.d.ts +11 -181
  26. package/src/utils/TronUiTransaction/TronUiTransaction.cjs +67 -26
  27. package/src/utils/TronUiTransaction/TronUiTransaction.d.ts +38 -5
  28. package/src/utils/TronUiTransaction/TronUiTransaction.js +67 -26
  29. package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.cjs +16 -0
  30. package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.d.ts +9 -0
  31. package/src/utils/convertChainIdToDecimal/convertChainIdToDecimal.js +12 -0
  32. package/src/utils/convertChainIdToDecimal/index.d.ts +1 -0
  33. package/src/utils/getTronGasEstimation/getTronGasEstimation.cjs +162 -0
  34. package/src/utils/getTronGasEstimation/getTronGasEstimation.d.ts +49 -0
  35. package/src/utils/getTronGasEstimation/getTronGasEstimation.js +158 -0
  36. package/src/utils/getTronGasEstimation/index.d.ts +1 -0
  37. package/src/wallet/TronWallet/TronWallet.cjs +124 -0
  38. package/src/wallet/TronWallet/TronWallet.d.ts +51 -0
  39. package/src/wallet/TronWallet/TronWallet.js +120 -0
  40. package/src/wallet/TronWallet/index.d.ts +1 -0
  41. package/src/connectors/BybitTronConnector/BybitTronConnector.d.ts +0 -7
  42. package/src/connectors/BybitTronConnector/index.d.ts +0 -1
  43. package/src/connectors/TronWalletConnector/TronWalletConnector.cjs +0 -255
  44. package/src/connectors/TronWalletConnector/TronWalletConnector.d.ts +0 -42
  45. package/src/connectors/TronWalletConnector/TronWalletConnector.js +0 -251
  46. package/src/connectors/TronWalletConnector/index.d.ts +0 -1
  47. package/src/utils/detectTronNetworkFromProvider.cjs +0 -67
  48. package/src/utils/detectTronNetworkFromProvider.d.ts +0 -30
  49. package/src/utils/detectTronNetworkFromProvider.js +0 -62
  50. package/src/utils/getDefaultTronNetworks.cjs +0 -60
  51. package/src/utils/getDefaultTronNetworks.d.ts +0 -9
  52. package/src/utils/getDefaultTronNetworks.js +0 -53
  53. package/src/utils/getTronGasEstimation.cjs +0 -136
  54. package/src/utils/getTronGasEstimation.d.ts +0 -47
  55. package/src/utils/getTronGasEstimation.js +0 -129
  56. package/src/utils/index.d.ts +0 -4
  57. package/src/utils/provider.cjs +0 -59
  58. package/src/utils/provider.d.ts +0 -24
  59. package/src/utils/provider.js +0 -53
  60. package/src/wallet/TronWallet.cjs +0 -106
  61. package/src/wallet/TronWallet.d.ts +0 -22
  62. package/src/wallet/TronWallet.js +0 -102
  63. package/src/wallet/index.d.ts +0 -2
@@ -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
- }
@@ -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 };
@@ -1,2 +0,0 @@
1
- export { TronWallet } from './TronWallet';
2
- export { isTronWallet } from './isTronWallet';