Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@
],
"rules" : {
"no-console": 2 // We dont want console log
}
},
"overrides": [
{
"files": ["e2e/**/*.ts"],
"rules": {
"no-console": "off"
}
}
]
}
14 changes: 7 additions & 7 deletions src/utils/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,7 +70,7 @@ export interface EstimateGasParameters {
gas?: string;
gasLimit?: bigint;
gasPrice?: bigint;
nonce?: any;
nonce?: number | string;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
}
Expand All @@ -92,24 +92,24 @@ 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;
}

// 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, <GasCost> {l1: 0, l1_data: 2048, l2: 100000000});
totalFee = sumGas(totalFee, <GasCost>{ l1: 0, l1_data: 2048, l2: 100000000 });
return roundUpGasCost(totalFee)
}

Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/utils/resourceBounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ResourceBounds> {
Expand Down
44 changes: 22 additions & 22 deletions src/utils/rosettanet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
11 changes: 5 additions & 6 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StarknetInvokeTransaction } from '../types/transactions.types'
import {
EstimateFeeTransaction,
PrepareCalldataError,
SignedRawTransaction,
} from '../types/types'
Expand All @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
Loading