Skip to content

Commit

Permalink
feat(account): adding new transaction version for fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
MilGard91 committed Apr 7, 2022
1 parent d63deb2 commit 2f7cb3f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { sign } from '../utils/ellipticCurve';
import {
computeHashOnElements,
feeTransactionVersion,
getSelectorFromName,
transactionPrefix,
transactionVersion,
Expand Down Expand Up @@ -56,10 +57,12 @@ export class Account extends Provider implements AccountInterface {
): Promise<EstimateFeeResponse> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = providedNonce ?? (await this.getNonce());
const version = toBN(feeTransactionVersion);
const signerDetails = {
walletAddress: this.address,
nonce: toBN(nonce),
maxFee: toBN('0'),
txVersion: version,
};
const signature = await this.signer.signTransaction(transactions, signerDetails);

Expand All @@ -71,6 +74,7 @@ export class Account extends Provider implements AccountInterface {
contract_address: this.address,
entry_point_selector: getSelectorFromName('__execute__'),
calldata,
version: toHex(version),
signature: bigNumberishArrayToDecimalStringArray(signature),
}
);
Expand All @@ -97,6 +101,7 @@ export class Account extends Provider implements AccountInterface {
walletAddress: this.address,
nonce,
maxFee,
txVersion: toBN(transactionVersion),
};

const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
Expand Down
3 changes: 2 additions & 1 deletion src/signer/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class Signer implements SignerInterface {
transactionsDetail.walletAddress,
transactions,
transactionsDetail.nonce.toString(),
transactionsDetail.maxFee.toString()
transactionsDetail.maxFee.toString(),
transactionsDetail.txVersion.toString()
);

return sign(this.keyPair, msgHash);
Expand Down
1 change: 1 addition & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type InvokeFunctionTransaction = {
calldata?: RawCalldata;
nonce?: BigNumberish;
max_fee?: BigNumberish;
version?: BigNumberish;
};

export type InvokeFunctionTrace = {
Expand Down
1 change: 1 addition & 0 deletions src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Call = Omit<Invocation, 'signature'>;
export type InvocationsDetails = {
nonce?: BigNumberish;
maxFee?: BigNumberish;
txVersion?: BigNumberish;
};

export type Status =
Expand Down
6 changes: 4 additions & 2 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { encodeShortString } from './shortString';

export const transactionPrefix = encodeShortString('StarkNet Transaction');
export const transactionVersion = 0;
export const feeTransactionVersion = toBN(2).pow(toBN(128)).add(toBN(transactionVersion));

function keccakHex(value: string): string {
return addHexPrefix(buf2hex(keccak256(utf8ToArray(value))));
Expand Down Expand Up @@ -68,7 +69,8 @@ export function hashMulticall(
account: string,
transactions: Call[],
nonce: string,
maxFee: string
maxFee: string,
txVersion: string | number = transactionVersion
) {
const hashArray = transactions
.map(({ contractAddress, entrypoint, calldata }) => [
Expand All @@ -85,6 +87,6 @@ export function hashMulticall(
computeHashOnElements(hashArray),
nonce,
maxFee,
transactionVersion,
txVersion,
]);
}

0 comments on commit 2f7cb3f

Please sign in to comment.