@dynamic-labs/tron 4.35.0 → 4.36.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.
- package/CHANGELOG.md +20 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -6
- package/src/utils/TronUiTransaction/TronUiTransaction.cjs +9 -1
- package/src/utils/TronUiTransaction/TronUiTransaction.js +9 -1
- package/src/utils/getTronGasEstimation.cjs +136 -0
- package/src/utils/getTronGasEstimation.d.ts +47 -0
- package/src/utils/getTronGasEstimation.js +129 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.36.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.36.0...v4.36.1) (2025-10-06)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
- Multiple internal improvements
|
|
7
|
+
|
|
8
|
+
## [4.36.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.35.0...v4.36.0) (2025-10-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add refresh/reshare settings on next login ([#9611](https://github.com/dynamic-labs/dynamic-auth/issues/9611)) ([49ce9a9](https://github.com/dynamic-labs/dynamic-auth/commit/49ce9a920bd3b4f7e7a4c3227bd8ecf2e6d0e37d))
|
|
14
|
+
* add waas mpc reshare on connectors ([#9610](https://github.com/dynamic-labs/dynamic-auth/issues/9610)) ([15394df](https://github.com/dynamic-labs/dynamic-auth/commit/15394dfb35c279b86c440066295eb8f3b8b1e342))
|
|
15
|
+
* send non-native tokens with sui sendbalance ([#9620](https://github.com/dynamic-labs/dynamic-auth/issues/9620)) ([c2c2b2b](https://github.com/dynamic-labs/dynamic-auth/commit/c2c2b2b5108933acf0858c61f96c902868531737))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* send balance input alignment ([#9617](https://github.com/dynamic-labs/dynamic-auth/issues/9617)) ([00d9f7c](https://github.com/dynamic-labs/dynamic-auth/commit/00d9f7cfd9e77660be8855367dbb14b139b6f146))
|
|
21
|
+
|
|
2
22
|
## [4.35.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.34.0...v4.35.0) (2025-10-02)
|
|
3
23
|
|
|
4
24
|
|
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.
|
|
3
|
+
"version": "4.36.1",
|
|
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,12 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.36.1",
|
|
22
22
|
"tronweb": "6.0.4",
|
|
23
|
-
"@dynamic-labs/types": "4.
|
|
24
|
-
"@dynamic-labs/utils": "4.
|
|
25
|
-
"@dynamic-labs/wallet-book": "4.
|
|
26
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
23
|
+
"@dynamic-labs/types": "4.36.1",
|
|
24
|
+
"@dynamic-labs/utils": "4.36.1",
|
|
25
|
+
"@dynamic-labs/wallet-book": "4.36.1",
|
|
26
|
+
"@dynamic-labs/wallet-connector-core": "4.36.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {}
|
|
29
29
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
7
|
var utils = require('@dynamic-labs/utils');
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
var getTronGasEstimation = require('../getTronGasEstimation.cjs');
|
|
9
10
|
|
|
10
11
|
// 1 TRX = 1,000,000 SUN (atomic units)
|
|
11
12
|
const SUN_PER_TRX = 1000000;
|
|
@@ -22,7 +23,14 @@ class TronUiTransaction {
|
|
|
22
23
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
if (this.fee.gas)
|
|
24
25
|
return;
|
|
25
|
-
this.fee.gas =
|
|
26
|
+
this.fee.gas = yield getTronGasEstimation.getTronGasEstimation({
|
|
27
|
+
from: this.from,
|
|
28
|
+
nonNativeAddress: this.nonNativeAddress,
|
|
29
|
+
nonNativeValue: this.nonNativeValue,
|
|
30
|
+
provider: this.provider,
|
|
31
|
+
to: this.to,
|
|
32
|
+
value: this.value,
|
|
33
|
+
});
|
|
26
34
|
});
|
|
27
35
|
}
|
|
28
36
|
parse(input) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { formatNumberText } from '@dynamic-labs/utils';
|
|
4
4
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { getTronGasEstimation } from '../getTronGasEstimation.js';
|
|
5
6
|
|
|
6
7
|
// 1 TRX = 1,000,000 SUN (atomic units)
|
|
7
8
|
const SUN_PER_TRX = 1000000;
|
|
@@ -18,7 +19,14 @@ class TronUiTransaction {
|
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
20
|
if (this.fee.gas)
|
|
20
21
|
return;
|
|
21
|
-
this.fee.gas =
|
|
22
|
+
this.fee.gas = yield getTronGasEstimation({
|
|
23
|
+
from: this.from,
|
|
24
|
+
nonNativeAddress: this.nonNativeAddress,
|
|
25
|
+
nonNativeValue: this.nonNativeValue,
|
|
26
|
+
provider: this.provider,
|
|
27
|
+
to: this.to,
|
|
28
|
+
value: this.value,
|
|
29
|
+
});
|
|
22
30
|
});
|
|
23
31
|
}
|
|
24
32
|
parse(input) {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Estimates gas fee for TRC20 token transfers
|
|
11
|
+
* @param params TRC20 estimation parameters
|
|
12
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
13
|
+
*/
|
|
14
|
+
const estimateTRC20Gas = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const { tronWeb, from, to, contractAddress, amount } = params;
|
|
16
|
+
try {
|
|
17
|
+
const functionSelector = 'transfer(address,uint256)';
|
|
18
|
+
const parameters = [
|
|
19
|
+
{ type: 'address', value: to },
|
|
20
|
+
{ type: 'uint256', value: amount.toString() },
|
|
21
|
+
];
|
|
22
|
+
const result = yield tronWeb.transactionBuilder.estimateEnergy(contractAddress, functionSelector, {}, parameters, from);
|
|
23
|
+
if (result === null || result === void 0 ? void 0 : result.energy_required) {
|
|
24
|
+
// Convert energy to TRX (energy cost is typically ~420 SUN per unit)
|
|
25
|
+
const estimatedFee = Math.max(result.energy_required * 420, 500000);
|
|
26
|
+
return BigInt(estimatedFee);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
walletConnectorCore.logger.error('TRC20 energy estimation failed:', error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Estimates gas fee for native TRX transfers
|
|
37
|
+
* @param params Native TRX estimation parameters
|
|
38
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
39
|
+
*/
|
|
40
|
+
const estimateNativeTRXGas = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const { tronWeb, from, to, value } = params;
|
|
42
|
+
try {
|
|
43
|
+
// Build the transaction to get accurate bandwidth cost
|
|
44
|
+
const transaction = yield tronWeb.transactionBuilder.sendTrx(to, Number(value), from);
|
|
45
|
+
// Get bandwidth cost
|
|
46
|
+
const bandwidth = transaction.raw_data_hex
|
|
47
|
+
? transaction.raw_data_hex.length / 2
|
|
48
|
+
: 200; // fallback estimate
|
|
49
|
+
// Check account resources (free bandwidth, energy, etc.)
|
|
50
|
+
let accountResources;
|
|
51
|
+
try {
|
|
52
|
+
accountResources = yield tronWeb.trx.getAccountResources(from);
|
|
53
|
+
}
|
|
54
|
+
catch (resourceError) {
|
|
55
|
+
walletConnectorCore.logger.error('Could not fetch account resources:', resourceError);
|
|
56
|
+
accountResources = null;
|
|
57
|
+
}
|
|
58
|
+
// Calculate if transaction can use free bandwidth
|
|
59
|
+
const freeNetAvailable = accountResources
|
|
60
|
+
? (accountResources.freeNetLimit || 0) -
|
|
61
|
+
(accountResources.freeNetUsed || 0)
|
|
62
|
+
: 0;
|
|
63
|
+
const delegatedNetAvailable = accountResources
|
|
64
|
+
? (accountResources.NetLimit || 0) - (accountResources.NetUsed || 0)
|
|
65
|
+
: 0;
|
|
66
|
+
const totalFreeBandwidth = freeNetAvailable + delegatedNetAvailable;
|
|
67
|
+
// If we have enough free bandwidth, the fee should be 0
|
|
68
|
+
if (bandwidth <= totalFreeBandwidth) {
|
|
69
|
+
return BigInt(0);
|
|
70
|
+
}
|
|
71
|
+
// Otherwise calculate the fee for the bandwidth we need to pay for
|
|
72
|
+
const paidBandwidth = bandwidth - totalFreeBandwidth;
|
|
73
|
+
const estimatedFee = Math.max(paidBandwidth * 1000, 0);
|
|
74
|
+
return BigInt(estimatedFee);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
walletConnectorCore.logger.error('Native TRX estimation failed:', error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Gets fallback gas fee based on transaction type
|
|
83
|
+
* @param isTokenTransfer Whether this is a token transfer
|
|
84
|
+
* @returns Fallback gas fee in SUN
|
|
85
|
+
*/
|
|
86
|
+
const getFallbackGasFee = (isTokenTransfer) => isTokenTransfer ? BigInt(500000) : BigInt(270000);
|
|
87
|
+
/**
|
|
88
|
+
* Estimates gas fees for TRON transactions
|
|
89
|
+
* @param params Transaction parameters for estimation
|
|
90
|
+
* @returns Estimated gas fee in SUN
|
|
91
|
+
*/
|
|
92
|
+
const getTronGasEstimation = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
const { provider, from, to, value, nonNativeAddress, nonNativeValue } = params;
|
|
94
|
+
try {
|
|
95
|
+
const { tronWeb } = provider;
|
|
96
|
+
if (!tronWeb) {
|
|
97
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
98
|
+
}
|
|
99
|
+
// TRC20 Token Transfer Estimation
|
|
100
|
+
if (nonNativeAddress && to && nonNativeValue) {
|
|
101
|
+
const trc20Fee = yield estimateTRC20Gas({
|
|
102
|
+
amount: nonNativeValue,
|
|
103
|
+
contractAddress: nonNativeAddress,
|
|
104
|
+
from,
|
|
105
|
+
to,
|
|
106
|
+
tronWeb,
|
|
107
|
+
});
|
|
108
|
+
if (trc20Fee) {
|
|
109
|
+
return trc20Fee;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Native TRX Transfer Estimation
|
|
113
|
+
if (to && value && value > 0) {
|
|
114
|
+
const nativeFee = yield estimateNativeTRXGas({
|
|
115
|
+
from,
|
|
116
|
+
to,
|
|
117
|
+
tronWeb,
|
|
118
|
+
value,
|
|
119
|
+
});
|
|
120
|
+
if (nativeFee) {
|
|
121
|
+
return nativeFee;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Fallback to reasonable defaults
|
|
125
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
walletConnectorCore.logger.error('Gas estimation failed:', error);
|
|
129
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
exports.estimateNativeTRXGas = estimateNativeTRXGas;
|
|
134
|
+
exports.estimateTRC20Gas = estimateTRC20Gas;
|
|
135
|
+
exports.getFallbackGasFee = getFallbackGasFee;
|
|
136
|
+
exports.getTronGasEstimation = getTronGasEstimation;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { TronWeb } from 'tronweb';
|
|
2
|
+
import type { ITronProvider } from '../types';
|
|
3
|
+
export interface TronGasEstimationParams {
|
|
4
|
+
provider: ITronProvider;
|
|
5
|
+
from: string;
|
|
6
|
+
to?: string;
|
|
7
|
+
value?: bigint;
|
|
8
|
+
nonNativeAddress?: string;
|
|
9
|
+
nonNativeValue?: bigint;
|
|
10
|
+
}
|
|
11
|
+
export interface TRC20EstimationParams {
|
|
12
|
+
tronWeb: TronWeb;
|
|
13
|
+
from: string;
|
|
14
|
+
to: string;
|
|
15
|
+
contractAddress: string;
|
|
16
|
+
amount: bigint;
|
|
17
|
+
}
|
|
18
|
+
export interface NativeTRXEstimationParams {
|
|
19
|
+
tronWeb: TronWeb;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
value: bigint;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Estimates gas fee for TRC20 token transfers
|
|
26
|
+
* @param params TRC20 estimation parameters
|
|
27
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
28
|
+
*/
|
|
29
|
+
export declare const estimateTRC20Gas: (params: TRC20EstimationParams) => Promise<bigint | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Estimates gas fee for native TRX transfers
|
|
32
|
+
* @param params Native TRX estimation parameters
|
|
33
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
34
|
+
*/
|
|
35
|
+
export declare const estimateNativeTRXGas: (params: NativeTRXEstimationParams) => Promise<bigint | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets fallback gas fee based on transaction type
|
|
38
|
+
* @param isTokenTransfer Whether this is a token transfer
|
|
39
|
+
* @returns Fallback gas fee in SUN
|
|
40
|
+
*/
|
|
41
|
+
export declare const getFallbackGasFee: (isTokenTransfer: boolean) => bigint;
|
|
42
|
+
/**
|
|
43
|
+
* Estimates gas fees for TRON transactions
|
|
44
|
+
* @param params Transaction parameters for estimation
|
|
45
|
+
* @returns Estimated gas fee in SUN
|
|
46
|
+
*/
|
|
47
|
+
export declare const getTronGasEstimation: (params: TronGasEstimationParams) => Promise<bigint>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Estimates gas fee for TRC20 token transfers
|
|
7
|
+
* @param params TRC20 estimation parameters
|
|
8
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
9
|
+
*/
|
|
10
|
+
const estimateTRC20Gas = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const { tronWeb, from, to, contractAddress, amount } = params;
|
|
12
|
+
try {
|
|
13
|
+
const functionSelector = 'transfer(address,uint256)';
|
|
14
|
+
const parameters = [
|
|
15
|
+
{ type: 'address', value: to },
|
|
16
|
+
{ type: 'uint256', value: amount.toString() },
|
|
17
|
+
];
|
|
18
|
+
const result = yield tronWeb.transactionBuilder.estimateEnergy(contractAddress, functionSelector, {}, parameters, from);
|
|
19
|
+
if (result === null || result === void 0 ? void 0 : result.energy_required) {
|
|
20
|
+
// Convert energy to TRX (energy cost is typically ~420 SUN per unit)
|
|
21
|
+
const estimatedFee = Math.max(result.energy_required * 420, 500000);
|
|
22
|
+
return BigInt(estimatedFee);
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
logger.error('TRC20 energy estimation failed:', error);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Estimates gas fee for native TRX transfers
|
|
33
|
+
* @param params Native TRX estimation parameters
|
|
34
|
+
* @returns Estimated gas fee in SUN or null if estimation fails
|
|
35
|
+
*/
|
|
36
|
+
const estimateNativeTRXGas = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const { tronWeb, from, to, value } = params;
|
|
38
|
+
try {
|
|
39
|
+
// Build the transaction to get accurate bandwidth cost
|
|
40
|
+
const transaction = yield tronWeb.transactionBuilder.sendTrx(to, Number(value), from);
|
|
41
|
+
// Get bandwidth cost
|
|
42
|
+
const bandwidth = transaction.raw_data_hex
|
|
43
|
+
? transaction.raw_data_hex.length / 2
|
|
44
|
+
: 200; // fallback estimate
|
|
45
|
+
// Check account resources (free bandwidth, energy, etc.)
|
|
46
|
+
let accountResources;
|
|
47
|
+
try {
|
|
48
|
+
accountResources = yield tronWeb.trx.getAccountResources(from);
|
|
49
|
+
}
|
|
50
|
+
catch (resourceError) {
|
|
51
|
+
logger.error('Could not fetch account resources:', resourceError);
|
|
52
|
+
accountResources = null;
|
|
53
|
+
}
|
|
54
|
+
// Calculate if transaction can use free bandwidth
|
|
55
|
+
const freeNetAvailable = accountResources
|
|
56
|
+
? (accountResources.freeNetLimit || 0) -
|
|
57
|
+
(accountResources.freeNetUsed || 0)
|
|
58
|
+
: 0;
|
|
59
|
+
const delegatedNetAvailable = accountResources
|
|
60
|
+
? (accountResources.NetLimit || 0) - (accountResources.NetUsed || 0)
|
|
61
|
+
: 0;
|
|
62
|
+
const totalFreeBandwidth = freeNetAvailable + delegatedNetAvailable;
|
|
63
|
+
// If we have enough free bandwidth, the fee should be 0
|
|
64
|
+
if (bandwidth <= totalFreeBandwidth) {
|
|
65
|
+
return BigInt(0);
|
|
66
|
+
}
|
|
67
|
+
// Otherwise calculate the fee for the bandwidth we need to pay for
|
|
68
|
+
const paidBandwidth = bandwidth - totalFreeBandwidth;
|
|
69
|
+
const estimatedFee = Math.max(paidBandwidth * 1000, 0);
|
|
70
|
+
return BigInt(estimatedFee);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger.error('Native TRX estimation failed:', error);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Gets fallback gas fee based on transaction type
|
|
79
|
+
* @param isTokenTransfer Whether this is a token transfer
|
|
80
|
+
* @returns Fallback gas fee in SUN
|
|
81
|
+
*/
|
|
82
|
+
const getFallbackGasFee = (isTokenTransfer) => isTokenTransfer ? BigInt(500000) : BigInt(270000);
|
|
83
|
+
/**
|
|
84
|
+
* Estimates gas fees for TRON transactions
|
|
85
|
+
* @param params Transaction parameters for estimation
|
|
86
|
+
* @returns Estimated gas fee in SUN
|
|
87
|
+
*/
|
|
88
|
+
const getTronGasEstimation = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const { provider, from, to, value, nonNativeAddress, nonNativeValue } = params;
|
|
90
|
+
try {
|
|
91
|
+
const { tronWeb } = provider;
|
|
92
|
+
if (!tronWeb) {
|
|
93
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
94
|
+
}
|
|
95
|
+
// TRC20 Token Transfer Estimation
|
|
96
|
+
if (nonNativeAddress && to && nonNativeValue) {
|
|
97
|
+
const trc20Fee = yield estimateTRC20Gas({
|
|
98
|
+
amount: nonNativeValue,
|
|
99
|
+
contractAddress: nonNativeAddress,
|
|
100
|
+
from,
|
|
101
|
+
to,
|
|
102
|
+
tronWeb,
|
|
103
|
+
});
|
|
104
|
+
if (trc20Fee) {
|
|
105
|
+
return trc20Fee;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Native TRX Transfer Estimation
|
|
109
|
+
if (to && value && value > 0) {
|
|
110
|
+
const nativeFee = yield estimateNativeTRXGas({
|
|
111
|
+
from,
|
|
112
|
+
to,
|
|
113
|
+
tronWeb,
|
|
114
|
+
value,
|
|
115
|
+
});
|
|
116
|
+
if (nativeFee) {
|
|
117
|
+
return nativeFee;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Fallback to reasonable defaults
|
|
121
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.error('Gas estimation failed:', error);
|
|
125
|
+
return getFallbackGasFee(Boolean(nonNativeAddress));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export { estimateNativeTRXGas, estimateTRC20Gas, getFallbackGasFee, getTronGasEstimation };
|