Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use MultiSendCallOnly 1.3.0 for older Safes #2528

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/services/contracts/__tests__/safeContracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ImplementationVersionState } from '@safe-global/safe-gateway-typescript-sdk'
import { _getValidatedGetContractProps, isValidMasterCopy } from '../safeContracts'
import { _getValidatedGetContractProps, isValidMasterCopy, _getMinimumMultiSendCallOnlyVersion } from '../safeContracts'

describe('safeContracts', () => {
describe('isValidMasterCopy', () => {
Expand Down Expand Up @@ -53,4 +53,18 @@ describe('safeContracts', () => {
expect(() => _getValidatedGetContractProps('1', '')).toThrow(' is not a valid Safe Account version')
})
})

describe('_getMinimumMultiSendCallOnlyVersion', () => {
it('should return the initial version if the Safe version is null', () => {
expect(_getMinimumMultiSendCallOnlyVersion(null)).toBe('1.3.0')
})

it('should return the initial version if the Safe version is lower than the initial version', () => {
expect(_getMinimumMultiSendCallOnlyVersion('1.0.0')).toBe('1.3.0')
})

it('should return the Safe version if the Safe version is higher than the initial version', () => {
expect(_getMinimumMultiSendCallOnlyVersion('1.4.1')).toBe('1.4.1')
})
})
})
17 changes: 15 additions & 2 deletions src/services/contracts/safeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type CompatibilityFallbackHandlerEthersContract from '@safe-global/safe-e
import type { Web3Provider } from '@ethersproject/providers'
import type GnosisSafeContractEthers from '@safe-global/safe-ethers-lib/dist/src/contracts/GnosisSafe/GnosisSafeContractEthers'
import type EthersAdapter from '@safe-global/safe-ethers-lib'
import semver from 'semver'

// `UNKNOWN` is returned if the mastercopy does not match supported ones
// @see https://github.com/safe-global/safe-client-gateway/blob/main/src/routes/safes/handlers/safes.rs#L28-L31
Expand Down Expand Up @@ -69,24 +70,36 @@ export const getReadOnlyGnosisSafeContract = (chain: ChainInfo, safeVersion: str

// MultiSend

export const _getMinimumMultiSendCallOnlyVersion = (safeVersion: SafeInfo['version']) => {
const INITIAL_CALL_ONLY_VERSION = '1.3.0'

if (!safeVersion) {
return INITIAL_CALL_ONLY_VERSION
}

return semver.gte(safeVersion, INITIAL_CALL_ONLY_VERSION) ? safeVersion : INITIAL_CALL_ONLY_VERSION
}

export const getMultiSendCallOnlyContract = (
chainId: string,
safeVersion: SafeInfo['version'],
provider: Web3Provider,
) => {
const ethAdapter = createEthersAdapter(provider)
const multiSendVersion = _getMinimumMultiSendCallOnlyVersion(safeVersion)

return ethAdapter.getMultiSendCallOnlyContract({
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId, safeVersion),
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId, multiSendVersion),
..._getValidatedGetContractProps(chainId, safeVersion),
})
}

export const getReadOnlyMultiSendCallOnlyContract = (chainId: string, safeVersion: SafeInfo['version']) => {
const ethAdapter = createReadOnlyEthersAdapter()
const multiSendVersion = _getMinimumMultiSendCallOnlyVersion(safeVersion)

return ethAdapter.getMultiSendCallOnlyContract({
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId, safeVersion),
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId, multiSendVersion),
..._getValidatedGetContractProps(chainId, safeVersion),
})
}
Expand Down
Loading