From 3983681bf2e08ad21814974693a0cd44714f3796 Mon Sep 17 00:00:00 2001 From: Boreas09 Date: Wed, 22 Oct 2025 20:25:31 +0300 Subject: [PATCH 1/2] linting fix --- .eslintrc | 10 ++++++++- src/utils/gas.ts | 14 ++++++------ src/utils/resourceBounds.ts | 6 ++--- src/utils/rosettanet.ts | 44 ++++++++++++++++++------------------- src/utils/transaction.ts | 11 +++++----- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.eslintrc b/.eslintrc index f872b6b..fc597bc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,5 +12,13 @@ ], "rules" : { "no-console": 2 // We dont want console log - } + }, + "overrides": [ + { + "files": ["e2e/**/*.ts"], + "rules": { + "no-console": "off" + } + } + ] } \ No newline at end of file diff --git a/src/utils/gas.ts b/src/utils/gas.ts index 8562bc7..46acd52 100644 --- a/src/utils/gas.ts +++ b/src/utils/gas.ts @@ -4,7 +4,7 @@ import { writeLog } from '../logger' import { isRosettaAccountDeployed } from './rosettanet' import { getConfigurationProperty } from './configReader' import { prepareRosettanetCalldataForEstimateFee } from './transaction' -import { getAccountNonce, getAccountNonceForEstimateFee } from './starknet' +import { getAccountNonceForEstimateFee } from './starknet' interface ActualFeeObject { amount: string @@ -70,7 +70,7 @@ export interface EstimateGasParameters { gas?: string; gasLimit?: bigint; gasPrice?: bigint; - nonce?: any; + nonce?: string; maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint; } @@ -92,7 +92,7 @@ export async function estimateGasCost(parameters: EstimateGasParameters): Promis }; const from = parameters.from; - + // If from address is not provided, return BASE_FEE if (!from) { return BASE_FEE; @@ -100,16 +100,16 @@ export async function estimateGasCost(parameters: EstimateGasParameters): Promis // Get Starknet account address const precalculatedStarknetAddress = await precalculateStarknetAccountAddress(from); - if(typeof precalculatedStarknetAddress !== 'string') { + if (typeof precalculatedStarknetAddress !== 'string') { writeLog(2, 'Starknet rpc error at precalculating from address at estimateGasCost') return BASE_FEE; } const isAccountDeployed = await isRosettaAccountDeployed(precalculatedStarknetAddress, getConfigurationProperty('accountClass')); - if(!isAccountDeployed) { + if (!isAccountDeployed) { totalFee = sumGas(totalFee, DEPLOYMENT_COST); - totalFee = sumGas(totalFee, {l1: 0, l1_data: 2048, l2: 100000000}); + totalFee = sumGas(totalFee, { l1: 0, l1_data: 2048, l2: 100000000 }); return roundUpGasCost(totalFee) } @@ -135,7 +135,7 @@ export async function estimateGasCost(parameters: EstimateGasParameters): Promis return 0 })(); - const inferredType: number = (parameters.maxFeePerGas != null || parameters.maxPriorityFeePerGas != null)? 2 : 0; + const inferredType: number = (parameters.maxFeePerGas != null || parameters.maxPriorityFeePerGas != null) ? 2 : 0; const maxFeePerGas: bigint = parseToBigInt(parameters.maxFeePerGas, BigInt(0)); const maxPriorityFeePerGas: bigint = parseToBigInt( diff --git a/src/utils/resourceBounds.ts b/src/utils/resourceBounds.ts index 08e68b9..fe358f0 100644 --- a/src/utils/resourceBounds.ts +++ b/src/utils/resourceBounds.ts @@ -51,13 +51,13 @@ export async function resourceBoundsFromSignedTxn(txn: SignedRawTransaction): Pr let availableGas = txn.gasLimit; - let l1_data = availableGas > BigInt(gasCost.l1_data) ? BigInt(gasCost.l1_data) : availableGas; + const l1_data = availableGas > BigInt(gasCost.l1_data) ? BigInt(gasCost.l1_data) : availableGas; availableGas = availableGas - l1_data; - let l2 = availableGas > BigInt(gasCost.l2) ? BigInt(gasCost.l2) : availableGas; + const l2 = availableGas > BigInt(gasCost.l2) ? BigInt(gasCost.l2) : availableGas; availableGas = availableGas - l2; - let l1 = availableGas > BigInt(gasCost.l1) ? BigInt(gasCost.l1) : availableGas; + const l1 = availableGas > BigInt(gasCost.l1) ? BigInt(gasCost.l1) : availableGas; availableGas = availableGas - l1; return { diff --git a/src/utils/rosettanet.ts b/src/utils/rosettanet.ts index 6683caf..c874297 100644 --- a/src/utils/rosettanet.ts +++ b/src/utils/rosettanet.ts @@ -8,7 +8,7 @@ import { } from '../types/types' import { getConfigurationProperty } from './configReader' import { isRPCResponse, isStarknetRPCError } from '../types/typeGuards' -import { addHexPrefix, hexPadding } from './padding' +import { hexPadding } from './padding' import { writeLog } from '../logger' import { safeU256ToUint256, U256ToUint256HexString } from './converters/integer' import { getDeploymentResourceBounds } from './resourceBounds' @@ -120,7 +120,7 @@ export async function deployRosettanetAccount( const rosettanet = getConfigurationProperty('rosettanet') const accountClass = getConfigurationProperty('accountClass') //const gasPrice = txn.maxFeePerGas == null ? txn.gasPrice : txn.maxFeePerGas - // const actualGasPrice = gasPrice == null ? '0x0' : gasPrice + // const actualGasPrice = gasPrice == null ? '0x0' : gasPrice //console.log('MAX FEE: ' + txn.gasLimit.toString(16)) //console.log('MAX price per unit: ' + actualGasPrice.toString(16)) //const gasObject = getGasObject(txn) @@ -225,22 +225,22 @@ export async function getRosettanetAccountNonce( export function decodeCalldataInput(rawCalldata: string[]): { selector: string, rawInput: string } { const calldataLength = Number(BigInt(rawCalldata[9])) - if(calldataLength == 0) { + if (calldataLength == 0) { return { selector: '0x', rawInput: '0x' } } const selector = hexPadding(rawCalldata[10], 8) - if(calldataLength == 1) { + if (calldataLength == 1) { return { - selector: selector, rawInput:selector + selector: selector, rawInput: selector } } let rawInput = `${selector}` for (let i = 1; i < calldataLength; i++) { - const data = U256ToUint256HexString([rawCalldata[i + 11].replace('0x',''), rawCalldata[i + 10].replace('0x','')]).replace('0x',''); + const data = U256ToUint256HexString([rawCalldata[i + 11].replace('0x', ''), rawCalldata[i + 10].replace('0x', '')]).replace('0x', ''); rawInput = rawInput + data - i +=1; + i += 1; } return { @@ -250,21 +250,21 @@ export function decodeCalldataInput(rawCalldata: string[]): { selector: string, } export function parseRosettanetRawCalldata(rawCalldata: string[]): RosettanetRawCalldata | undefined { - if(rawCalldata.length >= 10) { - const decodedCalldata = decodeCalldataInput(rawCalldata) - return { - txType: rawCalldata[0], - to: rawCalldata[1], - nonce: rawCalldata[2], - maxPriorityFeePerGas: rawCalldata[3], - maxFeePerGas: rawCalldata[4], - gasPrice: rawCalldata[5], - gasLimit: rawCalldata[6], - value: safeU256ToUint256([rawCalldata[7], rawCalldata[8]]), - selector: decodedCalldata.selector, - rawInput: decodedCalldata.rawInput - } + if (rawCalldata.length >= 10) { + const decodedCalldata = decodeCalldataInput(rawCalldata) + return { + txType: rawCalldata[0], + to: rawCalldata[1], + nonce: rawCalldata[2], + maxPriorityFeePerGas: rawCalldata[3], + maxFeePerGas: rawCalldata[4], + gasPrice: rawCalldata[5], + gasLimit: rawCalldata[6], + value: safeU256ToUint256([rawCalldata[7], rawCalldata[8]]), + selector: decodedCalldata.selector, + rawInput: decodedCalldata.rawInput } + } - return undefined + return undefined } \ No newline at end of file diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 8b29001..e06d34d 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -1,6 +1,5 @@ import { StarknetInvokeTransaction } from '../types/transactions.types' import { - EstimateFeeTransaction, PrepareCalldataError, SignedRawTransaction, } from '../types/types' @@ -11,7 +10,7 @@ import { Uint256ToU256, } from './converters/integer' import { addHexPrefix } from './padding' -import { ResourceBounds, resourceBoundsFromSignedTxn } from './resourceBounds' +import { ResourceBounds } from './resourceBounds' // Signature will be v,r,s // Deprecate this one @@ -43,12 +42,12 @@ export function prepareStarknetInvokeTransaction( return starknetTx } -export function prepareRosettanetCalldataForEstimateFee(from: string, to: string, gasLimit: bigint, data: string, value: bigint, nonce: number, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint, gasPrice: bigint , type: number): string[] { +export function prepareRosettanetCalldataForEstimateFee(from: string, to: string, gasLimit: bigint, data: string, value: bigint, nonce: number, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint, gasPrice: bigint, type: number): string[] { const targetFunctionSelector: string | null = - getFunctionSelectorFromCalldata(data); + getFunctionSelectorFromCalldata(data); const calldata = [] - if(type == 2) { - if(targetFunctionSelector == null) { + if (type == 2) { + if (targetFunctionSelector == null) { calldata.push(addHexPrefix(type.toString(16))) calldata.push(to) calldata.push(addHexPrefix(nonce.toString(16))) From ac609e5182181676dae419dab0b9dbf9005960f4 Mon Sep 17 00:00:00 2001 From: Boreas09 Date: Wed, 22 Oct 2025 20:28:27 +0300 Subject: [PATCH 2/2] type fix --- src/utils/gas.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/gas.ts b/src/utils/gas.ts index 46acd52..8d46e2e 100644 --- a/src/utils/gas.ts +++ b/src/utils/gas.ts @@ -70,7 +70,7 @@ export interface EstimateGasParameters { gas?: string; gasLimit?: bigint; gasPrice?: bigint; - nonce?: string; + nonce?: number | string; maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint; }