From 26e5fff1c1de73adb07f0fd1eb60379ef736b973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Mon, 29 Apr 2024 17:29:07 +0200 Subject: [PATCH 1/9] Fix BaseContract not selecting specific chain deployments --- packages/protocol-kit/src/contracts/BaseContract.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol-kit/src/contracts/BaseContract.ts b/packages/protocol-kit/src/contracts/BaseContract.ts index 2da1efa92..3e553421e 100644 --- a/packages/protocol-kit/src/contracts/BaseContract.ts +++ b/packages/protocol-kit/src/contracts/BaseContract.ts @@ -58,7 +58,10 @@ class BaseContract { ) { const deployment = getContractDeployment(safeVersion, chainId, contractName) - const contractAddress = customContractAddress || deployment?.defaultAddress + const contractAddress = + customContractAddress || + deployment?.networkAddresses[chainId.toString()] || + deployment?.defaultAddress if (!contractAddress) { throw new Error(`Invalid ${contractName.replace('Version', '')} contract address`) From 707c1ec45ea6775870bd453a6826db9601346964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Mon, 29 Apr 2024 17:30:13 +0200 Subject: [PATCH 2/9] Fix deploySafe --- packages/protocol-kit/tests/e2e/utilsContracts.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts index cdd2d9bf3..92c7e8e5f 100644 --- a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts +++ b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts @@ -1,6 +1,5 @@ import chai from 'chai' import { deployments } from 'hardhat' -import { Eip1193Provider } from '@safe-global/safe-core-sdk-types' import { getAccounts } from './utils/setupTestNetwork' import { getContractNetworks } from './utils/setupContractNetworks' import { getDefaultCallbackHandler } from './utils/setupContracts' @@ -13,7 +12,8 @@ import { safeVersionDeployed } from '@safe-global/protocol-kit/hardhat/deploy/de import { SafeDeploymentConfig, SafeAccountConfig, - ContractNetworksConfig + ContractNetworksConfig, + Eip1193Provider } from '@safe-global/protocol-kit/types' import Safe, { SafeFactory, DeploySafeProps } from '@safe-global/protocol-kit/index' import SafeProvider from '@safe-global/protocol-kit/SafeProvider' @@ -28,7 +28,7 @@ async function deploySafe( ): Promise { const safeFactory = await SafeFactory.create({ provider, - signerAddress, + signer: signerAddress, safeVersion: safeVersionDeployed, contractNetworks }) From 9090d939c118079f1f2bb51b1b1e0aaa24398a5a Mon Sep 17 00:00:00 2001 From: Daniel Somoza Date: Mon, 29 Apr 2024 17:41:04 +0200 Subject: [PATCH 3/9] Fix safeTxGas estimation for viem --- packages/protocol-kit/src/utils/transactions/gas.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/protocol-kit/src/utils/transactions/gas.ts b/packages/protocol-kit/src/utils/transactions/gas.ts index 420d673be..dff83c07b 100644 --- a/packages/protocol-kit/src/utils/transactions/gas.ts +++ b/packages/protocol-kit/src/utils/transactions/gas.ts @@ -400,7 +400,11 @@ function decodeSafeTxGas(encodedDataResponse: string): string { type GnosisChainEstimationError = { info: { error: { data: string | { data: string } } } } type EthersEstimationError = { data: string } -type EstimationError = Error & EthersEstimationError & GnosisChainEstimationError +type ViemEstimationError = { info: { error: { message: string } } } +type EstimationError = Error & + EthersEstimationError & + GnosisChainEstimationError & + ViemEstimationError /** * Parses the SafeTxGas estimation response from different providers. @@ -417,6 +421,12 @@ function parseSafeTxGasErrorResponse(error: EstimationError) { return decodeSafeTxGas(ethersData) } + // viem + const viemError = error?.info?.error?.message + if (viemError) { + return decodeSafeTxGas(viemError) + } + // gnosis-chain const gnosisChainProviderData = error?.info?.error?.data From 595dc90226e3bc8cd7ddc7e6717bbc1f81e0d2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 09:05:55 +0200 Subject: [PATCH 4/9] Update contracts being memoized in the dev branch. Now seems to be working --- packages/protocol-kit/tests/e2e/utilsContracts.test.ts | 6 +++--- yarn.lock | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts index 92c7e8e5f..f2a6cdf0e 100644 --- a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts +++ b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts @@ -658,10 +658,10 @@ describe('Contract utils', () => { safeDeploymentConfig: safeDeploymentConfig }) - const expectedGnosisSafeAddress = '0x30421B2bE26942448CD6C690f21F551BF6C8A45F' + const expectedGnosisSafeAddress = '0x39aC50A7B35c43429397D0481EBa8769B5e4b9a6' const expectedSkSyncSafeAddress = '0x4680B7AC23A98d5D68c21e3d6F8cBC9576A5920A' - const expectedSepoliaSafeAddress = '0x7f44E49C9E4C7D19fA2A704c2E66527Bd4688f99' - const expectedMainnetSafeAddress = '0x9C1C8c37a68242cEC6d68Ab091583c81FBF479C0' + const expectedSepoliaSafeAddress = '0x643bD5C3Fd6c546c1452A16f978C350F8a0A2a8D' + const expectedMainnetSafeAddress = '0x22b257EABfA3B8BC9e0C5f6BA03400933834675B' // returns the correct predicted address for each chain chai.expect(gnosisPredictedSafeAddress).to.be.equal(expectedGnosisSafeAddress) diff --git a/yarn.lock b/yarn.lock index fbcfdcf08..b610f419c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1250,10 +1250,10 @@ semver "^7.5.4" superstruct "^1.0.3" -"@monerium/sdk@^2.9.0": - version "2.9.0" - resolved "https://registry.yarnpkg.com/@monerium/sdk/-/sdk-2.9.0.tgz#ec7296623853acd0b7477b1b088f8c8fae42f197" - integrity sha512-6tr1fWau5tca2xjgIB/7NLJQFoVLcRvGQh6gqzgPJZCS9kRIVlupGk1MaejFdGWOmoEqJSFVUzi0TGhEJK+VcA== +"@monerium/sdk@^2.12.0": + version "2.12.0" + resolved "https://registry.yarnpkg.com/@monerium/sdk/-/sdk-2.12.0.tgz#57ccc1668a354c28d083c29928690f15fe11c479" + integrity sha512-tZxQNAlUpCbVkZfWIVB2yWYjyYZGKckEfzUZbWQyDdxUo487iNJQRr1Z64MZofJ/gKCPfOPJbiZzUGWbl8eLQA== dependencies: crypto-js "^4.2.0" From 80b80e7f5ac4d2e88420a1462c3f68f185c7ce8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 09:19:15 +0200 Subject: [PATCH 5/9] Remove memoization resolver --- packages/protocol-kit/src/utils/memoized.ts | 22 +-------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/packages/protocol-kit/src/utils/memoized.ts b/packages/protocol-kit/src/utils/memoized.ts index 7e107b5e8..757707cd9 100644 --- a/packages/protocol-kit/src/utils/memoized.ts +++ b/packages/protocol-kit/src/utils/memoized.ts @@ -3,30 +3,10 @@ export function createMemoizedFunction) => Ret cache: Record> = {} ) { return (...args: Parameters): ReturnType => { - const key = JSON.stringify(args, bigIntSerializerReplacer) + const key = JSON.stringify(args) cache[key] = cache[key] || callback(...args) return cache[key] } } - -// EIP1193 providers from web3.currentProvider and hre.network.provider fail to serialize BigInts -function bigIntSerializerReplacer() { - const seen = new Set() - - return (_: string, value: unknown) => { - if (typeof value === 'object' && value !== null) { - if (seen.has(value)) { - return undefined - } - seen.add(value) - } - - if (typeof value === 'bigint') { - return value.toString() - } - - return value - } -} From 783abf4dbfbc60bbf08eea22f53e082d590038a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 09:45:55 +0200 Subject: [PATCH 6/9] Add memoize again --- packages/protocol-kit/src/utils/memoized.ts | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/protocol-kit/src/utils/memoized.ts b/packages/protocol-kit/src/utils/memoized.ts index 757707cd9..7e107b5e8 100644 --- a/packages/protocol-kit/src/utils/memoized.ts +++ b/packages/protocol-kit/src/utils/memoized.ts @@ -3,10 +3,30 @@ export function createMemoizedFunction) => Ret cache: Record> = {} ) { return (...args: Parameters): ReturnType => { - const key = JSON.stringify(args) + const key = JSON.stringify(args, bigIntSerializerReplacer) cache[key] = cache[key] || callback(...args) return cache[key] } } + +// EIP1193 providers from web3.currentProvider and hre.network.provider fail to serialize BigInts +function bigIntSerializerReplacer() { + const seen = new Set() + + return (_: string, value: unknown) => { + if (typeof value === 'object' && value !== null) { + if (seen.has(value)) { + return undefined + } + seen.add(value) + } + + if (typeof value === 'bigint') { + return value.toString() + } + + return value + } +} From 9d832253737d3b09132aa6ab6229687eab1485c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 09:54:13 +0200 Subject: [PATCH 7/9] Fix replacer --- packages/protocol-kit/src/utils/memoized.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/protocol-kit/src/utils/memoized.ts b/packages/protocol-kit/src/utils/memoized.ts index 7e107b5e8..201e81547 100644 --- a/packages/protocol-kit/src/utils/memoized.ts +++ b/packages/protocol-kit/src/utils/memoized.ts @@ -2,8 +2,9 @@ export function createMemoizedFunction) => Ret callback: T, cache: Record> = {} ) { + const replacer = createBigIntSerializerReplacer() return (...args: Parameters): ReturnType => { - const key = JSON.stringify(args, bigIntSerializerReplacer) + const key = JSON.stringify(args, replacer) cache[key] = cache[key] || callback(...args) @@ -12,7 +13,7 @@ export function createMemoizedFunction) => Ret } // EIP1193 providers from web3.currentProvider and hre.network.provider fail to serialize BigInts -function bigIntSerializerReplacer() { +function createBigIntSerializerReplacer() { const seen = new Set() return (_: string, value: unknown) => { From 46b05156c4851132ddcb15262251ff9eb42cfeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 10:10:34 +0200 Subject: [PATCH 8/9] Allow tests to continue on error to see all the errors in the actions --- .github/workflows/protocol-kit-e2e-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/protocol-kit-e2e-test.yml b/.github/workflows/protocol-kit-e2e-test.yml index bddd20660..2d2b5b028 100644 --- a/.github/workflows/protocol-kit-e2e-test.yml +++ b/.github/workflows/protocol-kit-e2e-test.yml @@ -24,6 +24,7 @@ jobs: yarn install --frozen-lockfile yarn build - name: Test ${{ matrix.provider }} - Safe ${{ matrix.contract-version }} + continue-on-error: true run: | - cd packages/protocol-kit + cd packages/protocol-kit yarn test:hardhat:${{ matrix.provider }}:${{ matrix.contract-version }} From 4641a8e5aaeb8df32049d31c908bf6090011df6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Tue, 30 Apr 2024 10:28:34 +0200 Subject: [PATCH 9/9] Remove continue-onerror --- .github/workflows/protocol-kit-e2e-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/protocol-kit-e2e-test.yml b/.github/workflows/protocol-kit-e2e-test.yml index 2d2b5b028..3b321bd0a 100644 --- a/.github/workflows/protocol-kit-e2e-test.yml +++ b/.github/workflows/protocol-kit-e2e-test.yml @@ -24,7 +24,6 @@ jobs: yarn install --frozen-lockfile yarn build - name: Test ${{ matrix.provider }} - Safe ${{ matrix.contract-version }} - continue-on-error: true run: | cd packages/protocol-kit yarn test:hardhat:${{ matrix.provider }}:${{ matrix.contract-version }}