Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/add-eip1193-provider' into …
Browse files Browse the repository at this point in the history
…fix/protocol-kit/getModulesPaginated
  • Loading branch information
leonardotc committed Apr 30, 2024
2 parents 8756018 + 4641a8e commit 6b430c1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/protocol-kit-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
yarn build
- name: Test ${{ matrix.provider }} - Safe ${{ matrix.contract-version }}
run: |
cd packages/protocol-kit
cd packages/protocol-kit
yarn test:hardhat:${{ matrix.provider }}:${{ matrix.contract-version }}
5 changes: 4 additions & 1 deletion packages/protocol-kit/src/contracts/BaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class BaseContract<ContractAbiType extends InterfaceAbi & Abi> {
) {
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`)
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol-kit/src/utils/memoized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export function createMemoizedFunction<T extends (...args: Parameters<T>) => Ret
callback: T,
cache: Record<string, ReturnType<T>> = {}
) {
const replacer = createBigIntSerializerReplacer()
return (...args: Parameters<T>): ReturnType<T> => {
const key = JSON.stringify(args, bigIntSerializerReplacer)
const key = JSON.stringify(args, replacer)

cache[key] = cache[key] || callback(...args)

Expand All @@ -12,7 +13,7 @@ export function createMemoizedFunction<T extends (...args: Parameters<T>) => 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) => {
Expand Down
12 changes: 11 additions & 1 deletion packages/protocol-kit/src/utils/transactions/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions packages/protocol-kit/tests/e2e/utilsContracts.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand All @@ -28,7 +28,7 @@ async function deploySafe(
): Promise<Safe> {
const safeFactory = await SafeFactory.create({
provider,
signerAddress,
signer: signerAddress,
safeVersion: safeVersionDeployed,
contractNetworks
})
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 6b430c1

Please sign in to comment.