Skip to content

Commit

Permalink
Feat: enable Safe version 1.4.1 (#3209)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Feb 14, 2024
1 parent 558d48e commit 0ff4d1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/components/new-safe/create/logic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { showNotification } from '@/store/notificationsSlice'
import { SafeFactory } from '@safe-global/protocol-kit'
import type Safe from '@safe-global/protocol-kit'
import type { DeploySafeProps } from '@safe-global/protocol-kit'
import { createEthersAdapter } from '@/hooks/coreSDK/safeCoreSDK'
import { createEthersAdapter, isValidSafeVersion } from '@/hooks/coreSDK/safeCoreSDK'

import { backOff } from 'exponential-backoff'
import { LATEST_SAFE_VERSION } from '@/config/constants'
Expand Down Expand Up @@ -57,6 +57,18 @@ export const getSafeDeployProps = async (
}
}

const getSafeFactory = async (
ethersProvider: BrowserProvider,
safeVersion = LATEST_SAFE_VERSION,
): Promise<SafeFactory> => {
if (!isValidSafeVersion(safeVersion)) {
throw new Error('Invalid Safe version')
}
const ethAdapter = await createEthersAdapter(ethersProvider)
const safeFactory = await SafeFactory.create({ ethAdapter, safeVersion })
return safeFactory
}

/**
* Create a Safe creation transaction via Core SDK and submits it to the wallet
*/
Expand All @@ -65,9 +77,7 @@ export const createNewSafe = async (
props: DeploySafeProps,
safeVersion?: SafeVersion,
): Promise<Safe> => {
const ethAdapter = await createEthersAdapter(ethersProvider)

const safeFactory = await SafeFactory.create({ ethAdapter, safeVersion })
const safeFactory = await getSafeFactory(ethersProvider, safeVersion)
return safeFactory.deploySafe(props)
}

Expand All @@ -78,9 +88,7 @@ export const computeNewSafeAddress = async (
ethersProvider: BrowserProvider,
props: DeploySafeProps,
): Promise<string> => {
const ethAdapter = await createEthersAdapter(ethersProvider)

const safeFactory = await SafeFactory.create({ ethAdapter })
const safeFactory = await getSafeFactory(ethersProvider)
return safeFactory.predictSafeAddress(props.safeAccountConfig, props.saltNonce)
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/coreSDK/safeCoreSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const isLegacyVersion = (safeVersion: string): boolean => {
}

export const isValidSafeVersion = (safeVersion?: SafeInfo['version']): safeVersion is SafeVersion => {
const SAFE_VERSIONS: SafeVersion[] = ['1.3.0', '1.2.0', '1.1.1', '1.0.0']
const SAFE_VERSIONS: SafeVersion[] = ['1.4.1', '1.3.0', '1.2.0', '1.1.1', '1.0.0']
return !!safeVersion && SAFE_VERSIONS.some((version) => semverSatisfies(safeVersion, version))
}

Expand Down

0 comments on commit 0ff4d1a

Please sign in to comment.