Skip to content

Commit

Permalink
feat(refactor): contractAddress calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Oct 18, 2022
1 parent 546e43b commit 2b791d5
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,9 @@ export class Account extends Provider implements AccountInterface {
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);
const chainId = await this.getChainId();

let contractAddress = ZERO.toString();

if (!providedContractAddress) {
contractAddress = calculateContractAddressFromHash(
addressSalt,
classHash,
constructorCalldata,
0
);
} else {
contractAddress = providedContractAddress;
}
const contractAddress =
providedContractAddress ??
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);

const signature = await this.signer.signDeployAccountTransaction({
classHash,
Expand Down Expand Up @@ -269,36 +259,26 @@ export class Account extends Provider implements AccountInterface {
transactionsDetail: InvocationsDetails = {}
): Promise<DeployContractResponse> {
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);
const chainId = await this.getChainId();
let maxFee: BigNumberish = '0';

const contractAddress =
providedContractAddress ??
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);

if (transactionsDetail.maxFee || transactionsDetail.maxFee === 0) {
maxFee = transactionsDetail.maxFee;
} else {
const { suggestedMaxFee } = await this.estimateAccountDeployFee(
{ addressSalt, classHash, constructorCalldata },
{ addressSalt, classHash, constructorCalldata, contractAddress },
{
nonce,
}
);
maxFee = suggestedMaxFee.toString();
}

const version = toBN(transactionVersion);
const chainId = await this.getChainId();

let contractAddress = ZERO.toString();

if (!providedContractAddress) {
contractAddress = calculateContractAddressFromHash(
addressSalt,
classHash,
constructorCalldata,
0
);
} else {
contractAddress = providedContractAddress;
}

const signature = await this.signer.signDeployAccountTransaction({
classHash,
constructorCalldata,
Expand Down

0 comments on commit 2b791d5

Please sign in to comment.