@@ -50,16 +50,10 @@ import {
50
50
EMTPY_UNCLES ,
51
51
EMTPY_UNCLE_HASH ,
52
52
ERROR_PATTERN ,
53
- GAS_LIMIT_CHUNK ,
54
- GAS_MASK ,
55
53
LOCAL_MODE_MSG ,
56
- MAX_GAS_LIMIT_CC ,
57
54
ONE_HUNDRED_GWEI ,
58
55
PROD_MODE_MSG ,
59
56
SAFE_MODE_WARNING_MSG ,
60
- STORAGE_MASK ,
61
- TEN_GWEI ,
62
- U32_MAX ,
63
57
ZERO ,
64
58
ZERO_BLOCK_HASH ,
65
59
} from './consts' ;
@@ -75,8 +69,8 @@ import {
75
69
checkEvmExecutionError ,
76
70
computeDefaultEvmAddress ,
77
71
computeDefaultSubstrateAddress ,
72
+ decodeEthGas ,
78
73
encodeGasLimit ,
79
- ethToNativeDecimal ,
80
74
filterLog ,
81
75
filterLogByTopics ,
82
76
getAllReceiptsAtBlock ,
@@ -1228,10 +1222,12 @@ export abstract class BaseProvider extends AbstractProvider {
1228
1222
accessList : AccessList ;
1229
1223
v2 : boolean ;
1230
1224
} => {
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
+ } ;
1235
1231
let v2 = false ;
1236
1232
1237
1233
if ( ethTx . type === 96 ) {
@@ -1241,10 +1237,12 @@ export abstract class BaseProvider extends AbstractProvider {
1241
1237
if ( ! ethTx . validUntil ) return logger . throwError ( 'expect validUntil' ) ;
1242
1238
if ( ! ethTx . tip ) return logger . throwError ( 'expect priorityFee (tip)' ) ;
1243
1239
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
+ } ;
1248
1246
} else if (
1249
1247
ethTx . type === undefined || // legacy
1250
1248
ethTx . type === null || // legacy
@@ -1253,48 +1251,34 @@ export abstract class BaseProvider extends AbstractProvider {
1253
1251
try {
1254
1252
const { storageDepositPerByte, txFeePerGas } = this . _getGasConsts ( ) ;
1255
1253
1256
- const params = calcSubstrateTransactionParams ( {
1254
+ const { gasLimit , validUntil , storageLimit } = calcSubstrateTransactionParams ( {
1257
1255
txGasPrice : ethTx . maxFeePerGas || ethTx . gasPrice || '0' ,
1258
1256
txGasLimit : ethTx . gasLimit || '0' ,
1259
1257
storageByteDeposit : storageDepositPerByte ,
1260
1258
txFeePerGas : txFeePerGas ,
1261
1259
} ) ;
1262
1260
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 ) ) {
1269
1262
throw new Error ( ) ;
1270
1263
}
1264
+
1265
+ substrateParams = {
1266
+ gasLimit : gasLimit . toBigInt ( ) ,
1267
+ validUntil : validUntil . toBigInt ( ) ,
1268
+ storageLimit : storageLimit . toBigInt ( ) ,
1269
+ tip : 0n ,
1270
+ } ;
1271
1271
} catch ( error ) {
1272
1272
// v2
1273
1273
v2 = true ;
1274
1274
1275
1275
if ( ! ethTx . gasLimit ) return logger . throwError ( 'expect gasLimit' ) ;
1276
1276
if ( ! ethTx . gasPrice ) return logger . throwError ( 'expect gasPrice' ) ;
1277
1277
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
+ } ) ;
1298
1282
}
1299
1283
} else if ( ethTx . type === 1 || ethTx . type === 2 ) {
1300
1284
return logger . throwError (
@@ -1308,10 +1292,7 @@ export abstract class BaseProvider extends AbstractProvider {
1308
1292
}
1309
1293
1310
1294
return {
1311
- gasLimit,
1312
- storageLimit,
1313
- validUntil,
1314
- tip,
1295
+ ...substrateParams ,
1315
1296
accessList : ethTx . accessList ?? [ ] ,
1316
1297
v2,
1317
1298
} ;
0 commit comments