From 84945f8ebc2ca1f08e9dc39edd76881924f611d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Mon, 8 Jan 2024 19:16:41 +0100 Subject: [PATCH] feat: accept providedNonce (#247) * feat: accept providedNonce * feat: ignore nonce for estimateFee call --- src/clients/starknet/starknet-tx/index.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/clients/starknet/starknet-tx/index.ts b/src/clients/starknet/starknet-tx/index.ts index 966c8e7..d33faca 100644 --- a/src/clients/starknet/starknet-tx/index.ts +++ b/src/clients/starknet/starknet-tx/index.ts @@ -45,6 +45,10 @@ type UpdateSettingsInput = { votingStrategyMetadataUrisToAdd?: string[]; }; +type Opts = { + nonce?: string; +}; + const NO_UPDATE_U32 = '0xf2cda9b1'; const NO_UPDATE_ADDRESS = '0xf2cda9b13ed04e585461605c0d6e804933ca828111bd94d4e6a96c75e8b048'; const NO_UPDATE_STRING = 'No update'; @@ -133,7 +137,7 @@ export class StarknetTx { ); } - async propose(account: Account, envelope: Envelope) { + async propose(account: Account, envelope: Envelope, opts?: Opts) { const authorAddress = envelope.signatureData?.address || account.address; const authenticator = getAuthenticator(envelope.data.authenticator, this.config.networkConfig); @@ -163,10 +167,11 @@ export class StarknetTx { const calls = [call]; - return account.execute(calls); + const fee = await account.estimateFee(calls); + return account.execute(calls, undefined, { ...opts, maxFee: fee.suggestedMaxFee }); } - async updateProposal(account: Account, envelope: Envelope) { + async updateProposal(account: Account, envelope: Envelope, opts?: Opts) { const authorAddress = envelope.signatureData?.address || account.address; const authenticator = getAuthenticator(envelope.data.authenticator, this.config.networkConfig); @@ -186,10 +191,11 @@ export class StarknetTx { const calls = [call]; - return account.execute(calls); + const fee = await account.estimateFee(calls); + return account.execute(calls, undefined, { ...opts, maxFee: fee.suggestedMaxFee }); } - async vote(account: Account, envelope: Envelope) { + async vote(account: Account, envelope: Envelope, opts?: Opts) { const voterAddress = envelope.signatureData?.address || account.address; const authenticator = getAuthenticator(envelope.data.authenticator, this.config.networkConfig); @@ -213,7 +219,8 @@ export class StarknetTx { metadataUri: '' }); - return account.execute(call); + const fee = await account.estimateFee(call); + return account.execute(call, undefined, { ...opts, maxFee: fee.suggestedMaxFee }); } execute({