@dynamic-labs/tron 4.45.1 → 4.45.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 +10 -0
- package/README.md +1 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -6
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs +2 -1
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.js +2 -1
- package/src/utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.cjs +19 -0
- package/src/utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.d.ts +2 -0
- package/src/utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.js +15 -0
- package/src/utils/getBackwardsCompatibilityTronNetworks/index.d.ts +1 -0
- package/src/utils/getTronGasEstimation/getTronGasEstimation.cjs +47 -10
- package/src/utils/getTronGasEstimation/getTronGasEstimation.js +47 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.45.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.1...v4.45.2) (2025-11-17)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* assert global wallet url format ([#9876](https://github.com/dynamic-labs/dynamic-auth/issues/9876)) ([6362577](https://github.com/dynamic-labs/dynamic-auth/commit/6362577a37a3e38f94c57e42789798521490cf1a))
|
|
8
|
+
* correct tron testnet chain IDs ([#9872](https://github.com/dynamic-labs/dynamic-auth/issues/9872)) ([98e324f](https://github.com/dynamic-labs/dynamic-auth/commit/98e324f329ba868bd60192edf013ff33dca46d4e))
|
|
9
|
+
* dont send trc20 tokens when calculating gas estimates ([#9880](https://github.com/dynamic-labs/dynamic-auth/issues/9880)) ([ab4edcf](https://github.com/dynamic-labs/dynamic-auth/commit/ab4edcf15567096032fbcd7b1fcb59909adfaecb))
|
|
10
|
+
* **react-native:** register and authenticate with passkey ([#9875](https://github.com/dynamic-labs/dynamic-auth/issues/9875)) ([c6128da](https://github.com/dynamic-labs/dynamic-auth/commit/c6128da4852239bd6ecdc0e8ff97327cc7260a08))
|
|
11
|
+
|
|
2
12
|
### [4.45.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.0...v4.45.1) (2025-11-14)
|
|
3
13
|
|
|
4
14
|
|
package/README.md
CHANGED
|
@@ -320,7 +320,7 @@ This package is written in TypeScript and provides full type definitions. Enable
|
|
|
320
320
|
|
|
321
321
|
## License
|
|
322
322
|
|
|
323
|
-
This package is part of the Dynamic SDK and follows the same licensing terms. See [LICENSE](../../LICENSE) for details
|
|
323
|
+
This package is part of the Dynamic SDK and follows the same licensing terms. See [LICENSE](../../LICENSE) for details
|
|
324
324
|
|
|
325
325
|
---
|
|
326
326
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/tron",
|
|
3
|
-
"version": "4.45.
|
|
3
|
+
"version": "4.45.2",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.45.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.45.2",
|
|
22
22
|
"@tronweb3/tronwallet-abstract-adapter": "1.1.9",
|
|
23
23
|
"@tronweb3/tronwallet-adapters": "1.2.14",
|
|
24
24
|
"tronweb": "6.0.4",
|
|
25
|
-
"@dynamic-labs/types": "4.45.
|
|
26
|
-
"@dynamic-labs/utils": "4.45.
|
|
27
|
-
"@dynamic-labs/wallet-book": "4.45.
|
|
28
|
-
"@dynamic-labs/wallet-connector-core": "4.45.
|
|
25
|
+
"@dynamic-labs/types": "4.45.2",
|
|
26
|
+
"@dynamic-labs/utils": "4.45.2",
|
|
27
|
+
"@dynamic-labs/wallet-book": "4.45.2",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "4.45.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {}
|
|
31
31
|
}
|
|
@@ -10,6 +10,7 @@ var utils = require('@dynamic-labs/utils');
|
|
|
10
10
|
var TronWallet = require('../../wallet/TronWallet/TronWallet.cjs');
|
|
11
11
|
var TronUiTransaction = require('../../utils/TronUiTransaction/TronUiTransaction.cjs');
|
|
12
12
|
var convertChainIdToDecimal = require('../../utils/convertChainIdToDecimal/convertChainIdToDecimal.cjs');
|
|
13
|
+
var getBackwardsCompatibilityTronNetworks = require('../../utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.cjs');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Registry mapping wallet keys to their adapter classes
|
|
@@ -46,7 +47,7 @@ class TronWalletAdapterConnector extends walletConnectorCore.WalletConnectorBase
|
|
|
46
47
|
this.adapter = undefined;
|
|
47
48
|
this.balanceCache = new Map();
|
|
48
49
|
this.networkCache = null;
|
|
49
|
-
this.tronNetworks = opts.tronNetworks;
|
|
50
|
+
this.tronNetworks = getBackwardsCompatibilityTronNetworks.getBackwardsCompatibilityTronNetworks(opts.tronNetworks);
|
|
50
51
|
this.overrideKey = opts.overrideKey || 'tronwallet';
|
|
51
52
|
}
|
|
52
53
|
confirmTransactionStatus() {
|
|
@@ -6,6 +6,7 @@ import { DynamicError } from '@dynamic-labs/utils';
|
|
|
6
6
|
import { TronWallet } from '../../wallet/TronWallet/TronWallet.js';
|
|
7
7
|
import { TronUiTransaction } from '../../utils/TronUiTransaction/TronUiTransaction.js';
|
|
8
8
|
import { convertChainIdToDecimal } from '../../utils/convertChainIdToDecimal/convertChainIdToDecimal.js';
|
|
9
|
+
import { getBackwardsCompatibilityTronNetworks } from '../../utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Registry mapping wallet keys to their adapter classes
|
|
@@ -42,7 +43,7 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
42
43
|
this.adapter = undefined;
|
|
43
44
|
this.balanceCache = new Map();
|
|
44
45
|
this.networkCache = null;
|
|
45
|
-
this.tronNetworks = opts.tronNetworks;
|
|
46
|
+
this.tronNetworks = getBackwardsCompatibilityTronNetworks(opts.tronNetworks);
|
|
46
47
|
this.overrideKey = opts.overrideKey || 'tronwallet';
|
|
47
48
|
}
|
|
48
49
|
confirmTransactionStatus() {
|
package/src/utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const getBackwardsCompatibilityTronNetworks = (networks) => networks.reduce((acc, network) => {
|
|
7
|
+
if (network.chainId === '728126429') {
|
|
8
|
+
acc.push(Object.assign(Object.assign({}, network), { chainId: '2494104990', networkId: '2494104990' }));
|
|
9
|
+
}
|
|
10
|
+
else if (network.chainId === '728126430') {
|
|
11
|
+
acc.push(Object.assign(Object.assign({}, network), { chainId: '3448148188', networkId: '3448148188' }));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
acc.push(network);
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
exports.getBackwardsCompatibilityTronNetworks = getBackwardsCompatibilityTronNetworks;
|
package/src/utils/getBackwardsCompatibilityTronNetworks/getBackwardsCompatibilityTronNetworks.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const getBackwardsCompatibilityTronNetworks = (networks) => networks.reduce((acc, network) => {
|
|
3
|
+
if (network.chainId === '728126429') {
|
|
4
|
+
acc.push(Object.assign(Object.assign({}, network), { chainId: '2494104990', networkId: '2494104990' }));
|
|
5
|
+
}
|
|
6
|
+
else if (network.chainId === '728126430') {
|
|
7
|
+
acc.push(Object.assign(Object.assign({}, network), { chainId: '3448148188', networkId: '3448148188' }));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
acc.push(network);
|
|
11
|
+
}
|
|
12
|
+
return acc;
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
export { getBackwardsCompatibilityTronNetworks };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getBackwardsCompatibilityTronNetworks } from './getBackwardsCompatibilityTronNetworks';
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var TronUiTransaction = require('../TronUiTransaction/TronUiTransaction.cjs');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Extract fee from transaction data
|
|
@@ -40,6 +41,45 @@ const hasAvailableBandwidth = (from, tronWeb) => _tslib.__awaiter(void 0, void 0
|
|
|
40
41
|
const freeNetUsed = (accountResources === null || accountResources === void 0 ? void 0 : accountResources.freeNetUsed) || 0;
|
|
41
42
|
return freeNetUsed < freeNetLimit;
|
|
42
43
|
});
|
|
44
|
+
/**
|
|
45
|
+
* Get energy price from chain (in SUN per energy unit)
|
|
46
|
+
* Defaults to 420 SUN per energy if not available
|
|
47
|
+
*/
|
|
48
|
+
const getEnergyPrice = (tronWeb) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
try {
|
|
51
|
+
const chainParameters = yield tronWeb.trx.getChainParameters();
|
|
52
|
+
const energyPrice = (_a = chainParameters === null || chainParameters === void 0 ? void 0 : chainParameters.find((param) => param.key === 'getEnergyFee')) === null || _a === void 0 ? void 0 : _a.value;
|
|
53
|
+
return energyPrice || 420; // Default to 420 SUN per energy
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
walletConnectorCore.logger.debug('Failed to get energy price, using default:', error);
|
|
57
|
+
return 420; // Default to 420 SUN per energy
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const getTrc20EnergyEstimationUsingTronWebApi = (from, to, nonNativeAddress, nonNativeValue, tronWeb) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const functionSelector = 'transfer(address,uint256)';
|
|
62
|
+
const parameter = [
|
|
63
|
+
{ type: 'address', value: to },
|
|
64
|
+
{ type: 'uint256', value: nonNativeValue.toString() },
|
|
65
|
+
];
|
|
66
|
+
try {
|
|
67
|
+
const est = yield tronWeb.transactionBuilder.estimateEnergy(nonNativeAddress, functionSelector, {}, // options for call value, etc.
|
|
68
|
+
parameter, from);
|
|
69
|
+
const energyRequired = est.energy_required;
|
|
70
|
+
const energyPrice = yield getEnergyPrice(tronWeb);
|
|
71
|
+
const feeInSun = energyRequired * energyPrice;
|
|
72
|
+
const feeInTrx = feeInSun / TronUiTransaction.SUN_PER_TRX;
|
|
73
|
+
return {
|
|
74
|
+
energy: energyRequired,
|
|
75
|
+
feeInTrx,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
walletConnectorCore.logger.debug('TRC20 energy estimation failed, using conservative estimate:', error);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
43
83
|
/**
|
|
44
84
|
* Estimate TRC20 token transfer fees
|
|
45
85
|
* @param from - The sender's address
|
|
@@ -55,17 +95,14 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
|
|
|
55
95
|
if (yield hasAvailableEnergy(from, tronWeb)) {
|
|
56
96
|
return BigInt(0);
|
|
57
97
|
}
|
|
58
|
-
//
|
|
98
|
+
// Calculate TRC20 energy estimate for transfer and return fee in TRX
|
|
59
99
|
try {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
const fee = extractFeeFromTransaction(transaction);
|
|
68
|
-
return BigInt(fee);
|
|
100
|
+
const energyEstimate = yield getTrc20EnergyEstimationUsingTronWebApi(from, to, nonNativeAddress, nonNativeValue, tronWeb);
|
|
101
|
+
if (energyEstimate) {
|
|
102
|
+
// Convert TRX to SUN for return value (maintaining API compatibility)
|
|
103
|
+
return BigInt(Math.ceil(energyEstimate.feeInTrx * TronUiTransaction.SUN_PER_TRX));
|
|
104
|
+
}
|
|
105
|
+
return BigInt(1000000); // ~1 TRX max (in SUN)
|
|
69
106
|
}
|
|
70
107
|
catch (contractError) {
|
|
71
108
|
walletConnectorCore.logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { SUN_PER_TRX } from '../TronUiTransaction/TronUiTransaction.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Extract fee from transaction data
|
|
@@ -36,6 +37,45 @@ const hasAvailableBandwidth = (from, tronWeb) => __awaiter(void 0, void 0, void
|
|
|
36
37
|
const freeNetUsed = (accountResources === null || accountResources === void 0 ? void 0 : accountResources.freeNetUsed) || 0;
|
|
37
38
|
return freeNetUsed < freeNetLimit;
|
|
38
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Get energy price from chain (in SUN per energy unit)
|
|
42
|
+
* Defaults to 420 SUN per energy if not available
|
|
43
|
+
*/
|
|
44
|
+
const getEnergyPrice = (tronWeb) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
var _a;
|
|
46
|
+
try {
|
|
47
|
+
const chainParameters = yield tronWeb.trx.getChainParameters();
|
|
48
|
+
const energyPrice = (_a = chainParameters === null || chainParameters === void 0 ? void 0 : chainParameters.find((param) => param.key === 'getEnergyFee')) === null || _a === void 0 ? void 0 : _a.value;
|
|
49
|
+
return energyPrice || 420; // Default to 420 SUN per energy
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
logger.debug('Failed to get energy price, using default:', error);
|
|
53
|
+
return 420; // Default to 420 SUN per energy
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const getTrc20EnergyEstimationUsingTronWebApi = (from, to, nonNativeAddress, nonNativeValue, tronWeb) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
const functionSelector = 'transfer(address,uint256)';
|
|
58
|
+
const parameter = [
|
|
59
|
+
{ type: 'address', value: to },
|
|
60
|
+
{ type: 'uint256', value: nonNativeValue.toString() },
|
|
61
|
+
];
|
|
62
|
+
try {
|
|
63
|
+
const est = yield tronWeb.transactionBuilder.estimateEnergy(nonNativeAddress, functionSelector, {}, // options for call value, etc.
|
|
64
|
+
parameter, from);
|
|
65
|
+
const energyRequired = est.energy_required;
|
|
66
|
+
const energyPrice = yield getEnergyPrice(tronWeb);
|
|
67
|
+
const feeInSun = energyRequired * energyPrice;
|
|
68
|
+
const feeInTrx = feeInSun / SUN_PER_TRX;
|
|
69
|
+
return {
|
|
70
|
+
energy: energyRequired,
|
|
71
|
+
feeInTrx,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.debug('TRC20 energy estimation failed, using conservative estimate:', error);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
39
79
|
/**
|
|
40
80
|
* Estimate TRC20 token transfer fees
|
|
41
81
|
* @param from - The sender's address
|
|
@@ -51,17 +91,14 @@ const estimateTRC20Fees = (from, to, nonNativeAddress, nonNativeValue, tronWeb)
|
|
|
51
91
|
if (yield hasAvailableEnergy(from, tronWeb)) {
|
|
52
92
|
return BigInt(0);
|
|
53
93
|
}
|
|
54
|
-
//
|
|
94
|
+
// Calculate TRC20 energy estimate for transfer and return fee in TRX
|
|
55
95
|
try {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
const fee = extractFeeFromTransaction(transaction);
|
|
64
|
-
return BigInt(fee);
|
|
96
|
+
const energyEstimate = yield getTrc20EnergyEstimationUsingTronWebApi(from, to, nonNativeAddress, nonNativeValue, tronWeb);
|
|
97
|
+
if (energyEstimate) {
|
|
98
|
+
// Convert TRX to SUN for return value (maintaining API compatibility)
|
|
99
|
+
return BigInt(Math.ceil(energyEstimate.feeInTrx * SUN_PER_TRX));
|
|
100
|
+
}
|
|
101
|
+
return BigInt(1000000); // ~1 TRX max (in SUN)
|
|
65
102
|
}
|
|
66
103
|
catch (contractError) {
|
|
67
104
|
logger.debug('TRC20 contract estimation failed, using conservative estimate:', contractError);
|