Skip to content

Commit

Permalink
fix version loading
Browse files Browse the repository at this point in the history
  • Loading branch information
devanoneth committed Apr 24, 2024
1 parent 337396b commit 0e78f1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/hooks/loadables/useLoadSafeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { POLLING_INTERVAL } from '@/config/constants'
import { isLegacyVersion, useSafeImplementation, useSafeSDK } from '@/hooks/coreSDK/safeCoreSDK'
import { addressEx } from '@/utils/addresses'
import type Safe from '@safe-global/safe-core-sdk'
import { _safeDeployments } from '@safe-global/safe-deployments'
import { _safeDeployments, _safeL2Deployments } from '@safe-global/safe-deployments'

const isKnownContract = (address: string): boolean => {
return _safeDeployments.some((deployment) => Object.values(deployment.networkAddresses).includes(address))
return _safeDeployments
.concat(_safeL2Deployments)
.some((deployment) => Object.values(deployment.networkAddresses).includes(address))
}

export const getSafeInfo = async (sdk: Safe, implementation: string): Promise<SafeInfo> => {
Expand Down
23 changes: 4 additions & 19 deletions src/utils/safe-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { hasSafeFeature as sdkHasSafeFeature } from '@safe-global/safe-core-sdk-
import type { SAFE_FEATURES } from '@safe-global/safe-core-sdk-utils'
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { Provider } from '@ethersproject/providers'
import { isValidSafeVersion, type ModernSafeVersion } from '@/hooks/coreSDK/safeCoreSDK'
import { LATEST_SAFE_VERSION } from '@/config/constants'
import { isValidSafeVersion } from '@/hooks/coreSDK/safeCoreSDK'

import { Gnosis_safe__factory as Gnosis_safe__factory111 } from '@/types/contracts/factories/@safe-global/safe-deployments/dist/assets/v1.1.1'
import { Gnosis_safe__factory as Gnosis_safe__factory120 } from '@/types/contracts/factories/@safe-global/safe-deployments/dist/assets/v1.2.0'
Expand All @@ -25,10 +24,8 @@ export const hasSafeFeature = (feature: SAFE_FEATURES, version: SafeInfo['versio
}

function getSafeFactory(safeVersion: string | null) {
const isL2 = safeVersion?.endsWith('L2') ?? false
if (!isValidSafeVersion(safeVersion)) return

const version: ModernSafeVersion = safeVersion ?? LATEST_SAFE_VERSION
const [version, isL2] = (safeVersion ?? '').split('+')
if (!isValidSafeVersion(version)) return

const factories = {
'1.1.1': Gnosis_safe__factory111,
Expand All @@ -45,17 +42,5 @@ export const getSafeABI = (safeVersion: string | null) => {
}

export const getSafeContract = (safeAddress: string, safeVersion: string | null, provider: Provider) => {
const isL2 = safeVersion?.endsWith('L2') ?? false
if (!isValidSafeVersion(safeVersion)) return

const version: ModernSafeVersion = safeVersion ?? LATEST_SAFE_VERSION

const factories = {
'1.1.1': Gnosis_safe__factory111,
'1.2.0': Gnosis_safe__factory120,
'1.3.0': isL2 ? Gnosis_safe_l2__factory130 : Gnosis_safe__factory130,
'1.4.1': isL2 ? Safe_l2__factory141 : Safe__factory141,
}

return factories[version].connect(safeAddress, provider)
return getSafeFactory(safeVersion)?.connect(safeAddress, provider)
}

1 comment on commit 0e78f1c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 74.44% 6114/8213
🔴 Branches 51.06% 1353/2650
🔴 Functions 56.22% 895/1592
🟡 Lines 76.54% 5480/7160

Test suite run success

761 tests passing in 120 suites.

Report generated by 🧪jest coverage report action from 0e78f1c

Please sign in to comment.