From 2cbd7ce6ed872f8600cbe199e17d55cca8e608a8 Mon Sep 17 00:00:00 2001 From: Nicolas Villanueva Date: Tue, 10 Oct 2023 06:01:58 -0700 Subject: [PATCH 1/9] feat: add option to connect wallet read verified contracts requests (#38) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Add the option for connecting your MetaMask wallet when masking Read requests for verified contracts. By default, it will still use the default network Provider and behave like before, but if there's a wallet it will use its signer. ## Why ❔ This is necessary for functions that rely on `msg.sender`, so that it will be passed in correctly. ## Evidence Interacting with a `Greeter.sol` contract (with & without MetaMask wallet connected): https://github.com/matter-labs/block-explorer/assets/1890113/20bcd790-5c4f-435f-ad6d-f57ab0618cf7 https://github.com/matter-labs/block-explorer/assets/1890113/84e54a0a-95e2-4a01-a0ca-bf09e7a9cff3 Interacting with a `Characters.sol` contract that relies on `msg.sender` (with & without MetaMask wallet connected): https://github.com/matter-labs/block-explorer/assets/1890113/5b833c3c-e83e-422e-86f3-79a01d76aebc https://github.com/matter-labs/block-explorer/assets/1890113/b69ca08a-93a3-49cf-a1cc-56ca7d5af458 ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. Co-authored-by: Roman Petriv --- .../components/contract/ContractInfoTab.vue | 5 ++++- .../src/composables/useContractInteraction.ts | 6 +++++- .../useContractInteraction.spec.ts | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/app/src/components/contract/ContractInfoTab.vue b/packages/app/src/components/contract/ContractInfoTab.vue index 80a5a0eccc..fdf7c21a86 100644 --- a/packages/app/src/components/contract/ContractInfoTab.vue +++ b/packages/app/src/components/contract/ContractInfoTab.vue @@ -11,7 +11,10 @@
- {{ t("contract.abiInteraction.method.read.name") }} +
+ {{ t("contract.abiInteraction.method.read.name") }} + +
{ isRequestFailed.value = false; response.value = undefined; errorMessage.value = null; - const signer = new zkSyncSdk.Provider(context.currentNetwork.value.rpcUrl); + let signer: zkSyncSdk.Provider | zkSyncSdk.Signer = new zkSyncSdk.Provider(context.currentNetwork.value.rpcUrl); + if (walletAddress.value !== null) { + // If connected to a wallet, use the signer so 'msg.sender' is correctly populated downstream + signer = await getL2Signer(); + } const contract = new ethers.Contract(address, [abiFragment], signer!); const res = ( await contract[abiFragment.name](...Object.entries(params).map(([, inputValue]) => inputValue)).catch( diff --git a/packages/app/tests/composables/useContractInteraction.spec.ts b/packages/app/tests/composables/useContractInteraction.spec.ts index dcadd83679..d5449d5b4b 100644 --- a/packages/app/tests/composables/useContractInteraction.spec.ts +++ b/packages/app/tests/composables/useContractInteraction.spec.ts @@ -67,6 +67,27 @@ describe("useContractInteraction:", () => { expect(errorMessage.value).toEqual("An error occurred"); mock.mockRestore(); }); + it("uses Signer when wallet address is not null", async () => { + const mockGetL2Signer = vi.fn(async () => undefined); + const walletMock = useWalletMock({ + getL2Signer: mockGetL2Signer, + address: { value: "0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b" }, + }); + const { readFunction } = useContractInteraction(); + await readFunction("0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b", abiFragment, {}); + expect(mockGetL2Signer).toHaveBeenCalled(); + mockGetL2Signer.mockRestore(); + walletMock.mockRestore(); + }); + it("uses Provider when wallet address is null", async () => { + const mockGetL2Signer = vi.fn(async () => undefined); + const walletMock = useWalletMock({ getL2Signer: mockGetL2Signer }); + const { readFunction } = useContractInteraction(); + await readFunction("0x0cc725e6ba24e7db79f62f22a7994a8ee33adc1b", abiFragment, {}); + expect(mockGetL2Signer).not.toHaveBeenCalled(); + mockGetL2Signer.mockRestore(); + walletMock.mockRestore(); + }); }); describe("writeFunction:", () => { beforeEach(() => { From df0d8ecbd8483751d41a9837f28ccda4cf274e9f Mon Sep 17 00:00:00 2001 From: Vasyl Ivanchuk Date: Tue, 10 Oct 2023 21:02:24 +0300 Subject: [PATCH 2/9] fix: change docker file workdir to fix worker migrations (#47) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Fix for Block Explorer Worker migrations. ## Why ❔ Since Worker was moved to `packages/worker` folder, to make TypeOrm migrations work, the directory from where Worker is started must be changed. ## Checklist - [X] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. --- packages/api/Dockerfile | 3 ++- packages/worker/Dockerfile | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/api/Dockerfile b/packages/api/Dockerfile index 2dc91c236d..55c750f00a 100644 --- a/packages/api/Dockerfile +++ b/packages/api/Dockerfile @@ -38,5 +38,6 @@ ENV METRICS_PORT $METRICS_PORT EXPOSE $PORT $METRICS_PORT 9229 9230 USER node +WORKDIR /usr/src/app/packages/api -CMD [ "node", "packages/api/dist/main.js" ] +CMD [ "node", "dist/main.js" ] diff --git a/packages/worker/Dockerfile b/packages/worker/Dockerfile index a519806e86..7f2e8b502e 100644 --- a/packages/worker/Dockerfile +++ b/packages/worker/Dockerfile @@ -38,5 +38,6 @@ ENV PORT $PORT EXPOSE $PORT 9229 9230 USER node +WORKDIR /usr/src/app/packages/worker -CMD [ "node", "packages/worker/dist/main.js" ] +CMD [ "node", "dist/main.js" ] From 6bbb60f428e113b19b3d7208678ceafe09bc72af Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Wed, 11 Oct 2023 15:58:00 +0300 Subject: [PATCH 3/9] fix: hyperchain:configure script should build an array for app config (#48) --- scripts/setup-hyperchain-config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/setup-hyperchain-config.ts b/scripts/setup-hyperchain-config.ts index 6b5870a5da..45eccb8ef1 100644 --- a/scripts/setup-hyperchain-config.ts +++ b/scripts/setup-hyperchain-config.ts @@ -5,7 +5,7 @@ import * as dotenv from "dotenv"; import { parse as parseConnectionString } from "pg-connection-string"; const buildAppConfig = (zkSyncEnvs: { [key: string]: string }) => ({ - networks: { + networks: [{ apiUrl: "http://localhost:3020", verificationApiUrl: zkSyncEnvs.API_CONTRACT_VERIFICATION_URL || "", hostnames: ["localhost"], @@ -18,7 +18,7 @@ const buildAppConfig = (zkSyncEnvs: { [key: string]: string }) => ({ name: zkSyncEnvs.CHAIN_ETH_ZKSYNC_NETWORK || "", published: true, rpcUrl: zkSyncEnvs.API_WEB3_JSON_RPC_HTTP_URL || "", - } + }] }); const buildWorkerConfig = (zkSyncEnvs: { [key: string]: string }) => { From 9f494a5f00d8f9ca37a7ef8cfb4751f8e8c5ec55 Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Wed, 11 Oct 2023 20:40:43 +0300 Subject: [PATCH 4/9] fix: do not show tokens transferred component for transactions with no transfers having amount (#49) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ If transaction doesn't have at least one transfer with amount - we don't show tokens transferred component on transaction page. ## Why ❔ We can't show such transfers properly atm. --- .../transactions/infoTable/GeneralInfo.vue | 13 +++++++++---- .../transactions/infoTable/TransferTableCell.vue | 2 +- packages/app/src/composables/useTransaction.ts | 4 ++-- .../components/transactions/GeneralInfo.spec.ts | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/app/src/components/transactions/infoTable/GeneralInfo.vue b/packages/app/src/components/transactions/infoTable/GeneralInfo.vue index f3446f6dba..ef84402e10 100644 --- a/packages/app/src/components/transactions/infoTable/GeneralInfo.vue +++ b/packages/app/src/components/transactions/infoTable/GeneralInfo.vue @@ -105,7 +105,7 @@
- + {{ t("transactions.table.tokensTransferred") }} @@ -113,7 +113,7 @@ -
+
@@ -189,6 +189,7 @@