From 067fce8c736b76a5d73e73a500fe1b1d1b00c7cd Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 27 Mar 2023 08:16:40 +0100 Subject: [PATCH 1/2] fix: gaslimit (#254) --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/rpc/estimateMessageGas.ts | 4 +--- packages/snap/src/rpc/signMessage.ts | 2 +- packages/snap/test/unit/rpc/signMessage.test.ts | 6 ++---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 5b13f6a..bb68b31 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/Chainsafe/filsnap.git" }, "source": { - "shasum": "8Vx7jaoJt4mO71SjaNMmmlINtDrBOS6mVxskBxMw4sg=", + "shasum": "Z7lh6iD1yjfKES/WutUyxepg5Dgp8Xjo3kivsz9vpwc=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/rpc/estimateMessageGas.ts b/packages/snap/src/rpc/estimateMessageGas.ts index 4acf5e8..85f9c90 100644 --- a/packages/snap/src/rpc/estimateMessageGas.ts +++ b/packages/snap/src/rpc/estimateMessageGas.ts @@ -24,8 +24,6 @@ export async function estimateMessageGas( method: 0, // code for basic transaction nonce: 0, // dummy nonce just for gas calculation }; - // estimate gas usage - const gasLimit = await api.gasEstimateGasLimit(message, null); // set max fee to 0.1 FIL if not set const maxFeeAttoFil = maxFee ? maxFee @@ -37,7 +35,7 @@ export async function estimateMessageGas( ); return { gasfeecap: messageEstimate.GasFeeCap, - gaslimit: gasLimit, + gaslimit: messageEstimate.GasLimit, gaspremium: messageEstimate.GasPremium, maxfee: maxFeeAttoFil, }; diff --git a/packages/snap/src/rpc/signMessage.ts b/packages/snap/src/rpc/signMessage.ts index 5681edc..d373abb 100644 --- a/packages/snap/src/rpc/signMessage.ts +++ b/packages/snap/src/rpc/signMessage.ts @@ -59,12 +59,12 @@ export async function signMessage( message.gasfeecap === "0" && message.gaspremium === "0" ) { - message.gaslimit = await api.gasEstimateGasLimit(message, null); const messageEstimate = await api.gasEstimateMessageGas( message, { MaxFee: "0" }, null ); + message.gaslimit = messageEstimate.GasLimit; message.gaspremium = messageEstimate.GasPremium; message.gasfeecap = messageEstimate.GasFeeCap; } diff --git a/packages/snap/test/unit/rpc/signMessage.test.ts b/packages/snap/test/unit/rpc/signMessage.test.ts index a019028..8e5ffbd 100644 --- a/packages/snap/test/unit/rpc/signMessage.test.ts +++ b/packages/snap/test/unit/rpc/signMessage.test.ts @@ -49,10 +49,10 @@ describe("Test rpc handler function: signMessage", function () { walletStub.prepareFoKeyPair(); apiStub.mpoolGetNonce.returns("0"); - apiStub.gasEstimateGasLimit.returns(1000); apiStub.gasEstimateMessageGas.returns({ GasPremium: "10", GasFeeCap: "10", + GasLimit: 1000, }); const response = await signMessage(walletStub, apiStub, messageRequest); @@ -61,7 +61,6 @@ describe("Test rpc handler function: signMessage", function () { expect(walletStub.rpcStubs.snap_getBip44Entropy).to.have.been.calledOnce; expect(walletStub.rpcStubs.snap_manageState).to.have.been.calledOnce; expect(apiStub.mpoolGetNonce).to.have.been.calledOnce; - expect(apiStub.gasEstimateGasLimit).to.have.been.calledOnce; expect(apiStub.gasEstimateMessageGas).to.have.been.calledOnce; expect(response.signedMessage.message).to.be.deep.eq(fullMessage); expect(response.signedMessage.signature.data).to.not.be.empty; @@ -103,10 +102,10 @@ describe("Test rpc handler function: signMessage", function () { walletStub.rpcStubs.snap_confirm.resolves(true); walletStub.prepareFoKeyPair(); apiStub.mpoolGetNonce.returns("0"); - apiStub.gasEstimateGasLimit.returns(1000); apiStub.gasEstimateMessageGas.returns({ GasFeeCap: "10", GasPremium: "10", + GasLimit: 1000, }); const messageRequestWithCustomParams: MessageRequest = { @@ -123,7 +122,6 @@ describe("Test rpc handler function: signMessage", function () { expect(walletStub.rpcStubs.snap_getBip44Entropy).to.have.been.calledOnce; expect(walletStub.rpcStubs.snap_manageState).to.have.been.calledOnce; expect(apiStub.mpoolGetNonce).to.have.been.calledOnce; - expect(apiStub.gasEstimateGasLimit).to.have.been.calledOnce; expect(apiStub.gasEstimateMessageGas).to.have.been.calledOnce; expect(response.signedMessage.message).to.be.deep.eq(paramsMessage); expect(response.signedMessage.signature.data).to.not.be.empty; From 428fc47428099f1134fe7c0c1d3be4b71e6458fb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:36:41 +0100 Subject: [PATCH 2/2] chore: release master (#255) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- packages/snap/CHANGELOG.md | 7 +++++++ packages/snap/package.json | 2 +- packages/snap/snap.manifest.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b66228b..34a3c91 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,5 +1,5 @@ { - "packages/snap": "2.3.12", + "packages/snap": "2.3.13", "packages/types": "2.1.3", "packages/adapter": "2.1.3" } \ No newline at end of file diff --git a/packages/snap/CHANGELOG.md b/packages/snap/CHANGELOG.md index a89249d..e2b9ba8 100644 --- a/packages/snap/CHANGELOG.md +++ b/packages/snap/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.3.13](https://github.com/ChainSafe/filsnap/compare/filsnap-v2.3.12...filsnap-v2.3.13) (2023-03-27) + + +### Bug Fixes + +* gaslimit ([#254](https://github.com/ChainSafe/filsnap/issues/254)) ([067fce8](https://github.com/ChainSafe/filsnap/commit/067fce8c736b76a5d73e73a500fe1b1d1b00c7cd)) + ## [2.3.12](https://github.com/ChainSafe/filsnap/compare/filsnap-v2.3.11...filsnap-v2.3.12) (2023-03-03) diff --git a/packages/snap/package.json b/packages/snap/package.json index f533b13..a13c1ed 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -1,6 +1,6 @@ { "name": "@chainsafe/filsnap", - "version": "2.3.12", + "version": "2.3.13", "license": "(Apache-2.0 AND MIT)", "description": "Filsnap - Metamask snap to interact with Filecoin dapps.", "main": "build/index.js", diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index bb68b31..cdf2952 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -1,5 +1,5 @@ { - "version": "2.3.12", + "version": "2.3.13", "proposedName": "Filsnap", "description": "The Filecoin snap.", "repository": {