@@ -50,16 +50,10 @@ import {
5050 EMTPY_UNCLES ,
5151 EMTPY_UNCLE_HASH ,
5252 ERROR_PATTERN ,
53- GAS_LIMIT_CHUNK ,
54- GAS_MASK ,
5553 LOCAL_MODE_MSG ,
56- MAX_GAS_LIMIT_CC ,
5754 ONE_HUNDRED_GWEI ,
5855 PROD_MODE_MSG ,
5956 SAFE_MODE_WARNING_MSG ,
60- STORAGE_MASK ,
61- TEN_GWEI ,
62- U32_MAX ,
6357 ZERO ,
6458 ZERO_BLOCK_HASH ,
6559} from './consts' ;
@@ -75,8 +69,8 @@ import {
7569 checkEvmExecutionError ,
7670 computeDefaultEvmAddress ,
7771 computeDefaultSubstrateAddress ,
72+ decodeEthGas ,
7873 encodeGasLimit ,
79- ethToNativeDecimal ,
8074 filterLog ,
8175 filterLogByTopics ,
8276 getAllReceiptsAtBlock ,
@@ -1228,10 +1222,12 @@ export abstract class BaseProvider extends AbstractProvider {
12281222 accessList : AccessList ;
12291223 v2 : boolean ;
12301224 } => {
1231- let gasLimit = 0n ;
1232- let storageLimit = 0n ;
1233- let validUntil = 0n ;
1234- let tip = 0n ;
1225+ let substrateParams : {
1226+ gasLimit : bigint ,
1227+ storageLimit : bigint ,
1228+ validUntil : bigint ,
1229+ tip : bigint ,
1230+ } ;
12351231 let v2 = false ;
12361232
12371233 if ( ethTx . type === 96 ) {
@@ -1241,10 +1237,12 @@ export abstract class BaseProvider extends AbstractProvider {
12411237 if ( ! ethTx . validUntil ) return logger . throwError ( 'expect validUntil' ) ;
12421238 if ( ! ethTx . tip ) return logger . throwError ( 'expect priorityFee (tip)' ) ;
12431239
1244- gasLimit = ethTx . gasLimit . toBigInt ( ) ;
1245- storageLimit = BigInt ( ethTx . storageLimit . toString ( ) ) ;
1246- validUntil = BigInt ( ethTx . validUntil . toString ( ) ) ;
1247- tip = BigInt ( ethTx . tip . toString ( ) ) ;
1240+ substrateParams = {
1241+ gasLimit : ethTx . gasLimit . toBigInt ( ) ,
1242+ storageLimit : BigInt ( ethTx . storageLimit . toString ( ) ) ,
1243+ validUntil : BigInt ( ethTx . validUntil . toString ( ) ) ,
1244+ tip : BigInt ( ethTx . tip . toString ( ) ) ,
1245+ } ;
12481246 } else if (
12491247 ethTx . type === undefined || // legacy
12501248 ethTx . type === null || // legacy
@@ -1253,48 +1251,34 @@ export abstract class BaseProvider extends AbstractProvider {
12531251 try {
12541252 const { storageDepositPerByte, txFeePerGas } = this . _getGasConsts ( ) ;
12551253
1256- const params = calcSubstrateTransactionParams ( {
1254+ const { gasLimit , validUntil , storageLimit } = calcSubstrateTransactionParams ( {
12571255 txGasPrice : ethTx . maxFeePerGas || ethTx . gasPrice || '0' ,
12581256 txGasLimit : ethTx . gasLimit || '0' ,
12591257 storageByteDeposit : storageDepositPerByte ,
12601258 txFeePerGas : txFeePerGas ,
12611259 } ) ;
12621260
1263- gasLimit = params . gasLimit . toBigInt ( ) ;
1264- validUntil = params . validUntil . toBigInt ( ) ;
1265- storageLimit = params . storageLimit . toBigInt ( ) ;
1266- tip = ( ethTx . maxPriorityFeePerGas ?. toBigInt ( ) || 0n ) * gasLimit ;
1267-
1268- if ( gasLimit < 0n || validUntil < 0n || storageLimit < 0n ) {
1261+ if ( gasLimit . lt ( 0 ) || validUntil . lt ( 0 ) || storageLimit . lt ( 0 ) ) {
12691262 throw new Error ( ) ;
12701263 }
1264+
1265+ substrateParams = {
1266+ gasLimit : gasLimit . toBigInt ( ) ,
1267+ validUntil : validUntil . toBigInt ( ) ,
1268+ storageLimit : storageLimit . toBigInt ( ) ,
1269+ tip : 0n ,
1270+ } ;
12711271 } catch ( error ) {
12721272 // v2
12731273 v2 = true ;
12741274
12751275 if ( ! ethTx . gasLimit ) return logger . throwError ( 'expect gasLimit' ) ;
12761276 if ( ! ethTx . gasPrice ) return logger . throwError ( 'expect gasPrice' ) ;
12771277
1278- const bbbcc = ethTx . gasLimit . mod ( GAS_MASK ) ;
1279- const encodedGasLimit = bbbcc . div ( STORAGE_MASK ) ; // bbb
1280- const encodedStorageLimit = bbbcc . mod ( STORAGE_MASK ) ; // cc
1281-
1282- let gasPrice = ethTx . gasPrice ;
1283- const tipNumber = gasPrice . div ( TEN_GWEI ) . sub ( 10 ) ;
1284- if ( tipNumber . gt ( 0 ) ) {
1285- gasPrice = gasPrice . sub ( tipNumber . mul ( TEN_GWEI ) ) ;
1286- const ethTip = gasPrice . mul ( ethTx . gasLimit ) . mul ( tipNumber ) . div ( 10 ) ;
1287- tip = ethToNativeDecimal ( ethTip ) . toBigInt ( ) ;
1288- }
1289-
1290- validUntil = gasPrice . sub ( ONE_HUNDRED_GWEI ) . toBigInt ( ) ;
1291- if ( validUntil > U32_MAX ) {
1292- validUntil = U32_MAX ;
1293- }
1294- gasLimit = encodedGasLimit . mul ( GAS_LIMIT_CHUNK ) . toBigInt ( ) ;
1295- storageLimit = BigNumber . from ( 2 )
1296- . pow ( encodedStorageLimit . gt ( MAX_GAS_LIMIT_CC ) ? MAX_GAS_LIMIT_CC : encodedStorageLimit )
1297- . toBigInt ( ) ;
1278+ substrateParams = decodeEthGas ( {
1279+ gasLimit : ethTx . gasLimit ,
1280+ gasPrice : ethTx . gasPrice ,
1281+ } ) ;
12981282 }
12991283 } else if ( ethTx . type === 1 || ethTx . type === 2 ) {
13001284 return logger . throwError (
@@ -1308,10 +1292,7 @@ export abstract class BaseProvider extends AbstractProvider {
13081292 }
13091293
13101294 return {
1311- gasLimit,
1312- storageLimit,
1313- validUntil,
1314- tip,
1295+ ...substrateParams ,
13151296 accessList : ethTx . accessList ?? [ ] ,
13161297 v2,
13171298 } ;
0 commit comments