Skip to content

Commit

Permalink
fix: overestimate fee when using nonce (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet authored Apr 29, 2024
1 parent 71ab67a commit 76f59c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-onions-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@snapshot-labs/sx": patch
---

overestimate fee when using nonce in StarknetTx client
11 changes: 7 additions & 4 deletions packages/sx.js/src/clients/starknet/starknet-tx/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, CallData, shortString, uint256, hash } from 'starknet';
import { stark, Account, CallData, shortString, uint256, hash } from 'starknet';
import { ContractFactory } from '@ethersproject/contracts';
import { Signer } from '@ethersproject/abstract-signer';
import { poseidonHashMany } from 'micro-starknet';
Expand Down Expand Up @@ -204,7 +204,8 @@ export class StarknetTx {
const calls = [call];

const fee = opts?.nonce ? await account.estimateFee(calls) : null;
return account.execute(calls, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
const maxFee = fee ? stark.estimatedFeeToMaxFee(fee.suggestedMaxFee, 1.5) : undefined;
return account.execute(calls, undefined, fee ? { maxFee } : undefined);
}

async updateProposal(account: Account, envelope: Envelope<UpdateProposal>, opts?: Opts) {
Expand All @@ -226,7 +227,8 @@ export class StarknetTx {
});

const fee = opts?.nonce ? await account.estimateFee(call) : null;
return account.execute(call, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
const maxFee = fee ? stark.estimatedFeeToMaxFee(fee.suggestedMaxFee, 1.5) : undefined;
return account.execute(call, undefined, fee ? { maxFee } : undefined);
}

async vote(account: Account, envelope: Envelope<Vote>, opts?: Opts) {
Expand Down Expand Up @@ -254,7 +256,8 @@ export class StarknetTx {
});

const fee = opts?.nonce ? await account.estimateFee(call) : null;
return account.execute(call, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
const maxFee = fee ? stark.estimatedFeeToMaxFee(fee.suggestedMaxFee, 1.5) : undefined;
return account.execute(call, undefined, fee ? { maxFee } : undefined);
}

execute({
Expand Down

0 comments on commit 76f59c6

Please sign in to comment.