Skip to content

Commit

Permalink
fix(protocol-kit): consider SafeVersion <= 1.3.0 in the `isL1Contra…
Browse files Browse the repository at this point in the history
…ct` check in `SafeBaseContract` (#878)

* fix isL1Contract check in SafeBaseContract

---------

Co-authored-by: Yago Pérez Vázquez <[email protected]>
  • Loading branch information
DaniSomoza and yagopv authored Jun 21, 2024
1 parent f752f52 commit 5176837
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/protocol-kit/src/contracts/Safe/SafeBaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { SafeVersion } from '@safe-global/safe-core-sdk-types'
import BaseContract from '@safe-global/protocol-kit/contracts/BaseContract'
import { contractName, safeDeploymentsL1ChainIds } from '@safe-global/protocol-kit/contracts/config'
import { SAFE_FEATURES, hasSafeFeature } from '@safe-global/protocol-kit/utils'

/**
* Abstract class SafeBaseContract extends BaseContract to specifically integrate with the Safe contract.
Expand Down Expand Up @@ -48,7 +49,11 @@ abstract class SafeBaseContract<
customContractAddress?: string,
customContractAbi?: SafeContractAbiType
) {
const isL1Contract = safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton
const isL1Contract =
safeDeploymentsL1ChainIds.includes(chainId) ||
isL1SafeSingleton ||
!hasSafeFeature(SAFE_FEATURES.SAFE_L2_CONTRACTS, safeVersion)

const contractName = isL1Contract ? 'safeSingletonVersion' : 'safeSingletonL2Version'

super(
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol-kit/src/utils/safeVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export enum SAFE_FEATURES {
ETH_SIGN = 'ETH_SIGN',
ACCOUNT_ABSTRACTION = 'ACCOUNT_ABSTRACTION',
REQUIRED_TXGAS = 'REQUIRED_TXGAS',
SIMULATE_AND_REVERT = 'SIMULATE_AND_REVERT'
SIMULATE_AND_REVERT = 'SIMULATE_AND_REVERT',
SAFE_L2_CONTRACTS = 'SAFE_L2_CONTRACTS'
}

const SAFE_FEATURES_BY_VERSION: Record<SAFE_FEATURES, string> = {
Expand All @@ -23,7 +24,8 @@ const SAFE_FEATURES_BY_VERSION: Record<SAFE_FEATURES, string> = {
[SAFE_FEATURES.ETH_SIGN]: '>=1.1.0',
[SAFE_FEATURES.ACCOUNT_ABSTRACTION]: '>=1.3.0',
[SAFE_FEATURES.REQUIRED_TXGAS]: '<=1.2.0',
[SAFE_FEATURES.SIMULATE_AND_REVERT]: '>=1.3.0'
[SAFE_FEATURES.SIMULATE_AND_REVERT]: '>=1.3.0',
[SAFE_FEATURES.SAFE_L2_CONTRACTS]: '>=1.3.0'
}

export const hasSafeFeature = (feature: SAFE_FEATURES, version: string): boolean => {
Expand Down
11 changes: 11 additions & 0 deletions packages/protocol-kit/tests/e2e/safeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ describe('Safe contracts', () => {
.to.be.eq('0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552')
})

it('should return an L1 Safe contract from safe-deployments when the safeVersion is < 1.3.0', async () => {
const safeProvider = getSafeProviderFromNetwork('gnosis')
const safeVersion: SafeVersion = '1.1.1'
const safeContract = await safeProvider.getSafeContract({
safeVersion
})
chai
.expect(await safeContract.getAddress())
.to.be.eq('0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F')
})

it('should return a Safe contract from the custom addresses', async () => {
const { contractNetworks, chainId, provider } = await setupTests()
const safeProvider = new SafeProvider({ provider })
Expand Down

0 comments on commit 5176837

Please sign in to comment.