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: multisend verification only worked for the latest contract version #2439

Merged
merged 6 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion src/components/transactions/TxDetails/TxData/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import DecodedData from '@/components/transactions/TxDetails/TxData/DecodedData'
import TransferTxInfo from '@/components/transactions/TxDetails/TxData/Transfer'
import useChainId from '@/hooks/useChainId'
import { MultiSendTxInfo } from '@/components/transactions/TxDetails/TxData/MultiSendTxInfo'
import useSafeInfo from '@/hooks/useSafeInfo'

const TxData = ({ txDetails }: { txDetails: TransactionDetails }): ReactElement => {
const chainId = useChainId()
const { safe } = useSafeInfo()
const txInfo = txDetails.txInfo

if (isTransferTxInfo(txInfo)) {
Expand All @@ -36,7 +38,7 @@ const TxData = ({ txDetails }: { txDetails: TransactionDetails }): ReactElement
return <RejectionTxInfo nonce={txDetails.detailedExecutionInfo?.nonce} isTxExecuted={!!txDetails.executedAt} />
}

if (isSupportedMultiSendAddress(txInfo, chainId) && isMultiSendTxInfo(txInfo)) {
if (isSupportedMultiSendAddress(txInfo, chainId, safe.version) && isMultiSendTxInfo(txInfo)) {
return <MultiSendTxInfo txInfo={txInfo} />
}

Expand Down
16 changes: 9 additions & 7 deletions src/components/transactions/TxDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type TxDetailsProps = {

const TxDetailsBlock = ({ txSummary, txDetails }: TxDetailsProps): ReactElement => {
const chainId = useChainId()
const { safe } = useSafeInfo()
const isPending = useIsPending(txSummary.id)
const isQueue = isTxQueued(txSummary.txStatus)
const awaitingExecution = isAwaitingExecution(txSummary.txStatus)
Expand Down Expand Up @@ -89,13 +90,14 @@ const TxDetailsBlock = ({ txSummary, txDetails }: TxDetailsProps): ReactElement
<Summary txDetails={txDetails} />
</div>

{isSupportedMultiSendAddress(txDetails.txInfo, chainId) && isMultiSendTxInfo(txDetails.txInfo) && (
<div className={`${css.multiSend}`}>
<ErrorBoundary fallback={<div>Error parsing data</div>}>
<Multisend txData={txDetails.txData} />
</ErrorBoundary>
</div>
)}
{isSupportedMultiSendAddress(txDetails.txInfo, chainId, safe.version) &&
isMultiSendTxInfo(txDetails.txInfo) && (
<div className={`${css.multiSend}`}>
<ErrorBoundary fallback={<div>Error parsing data</div>}>
<Multisend txData={txDetails.txData} />
</ErrorBoundary>
</div>
)}
</div>

{/* Signers */}
Expand Down
4 changes: 3 additions & 1 deletion src/components/transactions/TxInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { ellipsis, shortenAddress } from '@/utils/formatters'
import { useCurrentChain } from '@/hooks/useChains'
import useChainId from '@/hooks/useChainId'
import useSafeInfo from '@/hooks/useSafeInfo'

export const TransferTx = ({
info,
Expand Down Expand Up @@ -99,12 +100,13 @@ const SettingsChangeTx = ({ info }: { info: SettingsChange }): ReactElement => {

const TxInfo = ({ info, ...rest }: { info: TransactionInfo; omitSign?: boolean; withLogo?: boolean }): ReactElement => {
const chainId = useChainId()
const { safe } = useSafeInfo()

if (isSettingsChangeTxInfo(info)) {
return <SettingsChangeTx info={info} />
}

if (isSupportedMultiSendAddress(info, chainId) && isMultiSendTxInfo(info)) {
if (isSupportedMultiSendAddress(info, chainId, safe.version) && isMultiSendTxInfo(info)) {
return <MultiSendTx info={info} />
}

Expand Down
26 changes: 8 additions & 18 deletions src/services/contracts/safeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,16 @@ export const getReadOnlyGnosisSafeContract = (chain: ChainInfo, safeVersion: str

// MultiSend

const getMultiSendContractDeployment = (chainId: string) => {
return getMultiSendDeployment({ network: chainId }) || getMultiSendDeployment()
}

export const getMultiSendContractAddress = (chainId: string): string | undefined => {
const deployment = getMultiSendContractDeployment(chainId)

return deployment?.networkAddresses[chainId]
export const getMultiSendContractAddress = (network: string, version: string): string | undefined => {
const deployment = getMultiSendDeployment({ network, version })
return deployment?.networkAddresses[network]
}

// MultiSendCallOnly

const getMultiSendCallOnlyContractDeployment = (chainId: string) => {
return getMultiSendCallOnlyDeployment({ network: chainId }) || getMultiSendCallOnlyDeployment()
}

export const getMultiSendCallOnlyContractAddress = (chainId: string): string | undefined => {
const deployment = getMultiSendCallOnlyContractDeployment(chainId)

return deployment?.networkAddresses[chainId]
export const getMultiSendCallOnlyContractAddress = (network: string, version: string): string | undefined => {
const deployment = getMultiSendCallOnlyDeployment({ network, version })
return deployment?.networkAddresses[network]
}

export const getMultiSendCallOnlyContract = (
Expand All @@ -132,7 +122,7 @@ export const getMultiSendCallOnlyContract = (
const ethAdapter = createEthersAdapter(provider)

return ethAdapter.getMultiSendCallOnlyContract({
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId),
singletonDeployment: getMultiSendCallOnlyDeployment({ network: chainId, version: safeVersion || undefined }),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is also an important fix, because it was getting 1.3.0 multisend by default which would break any time.

..._getValidatedGetContractProps(chainId, safeVersion),
})
}
Expand All @@ -144,7 +134,7 @@ export const getReadOnlyMultiSendCallOnlyContract = (
const ethAdapter = createReadOnlyEthersAdapter()

return ethAdapter.getMultiSendCallOnlyContract({
singletonDeployment: getMultiSendCallOnlyContractDeployment(chainId),
singletonDeployment: getMultiSendCallOnlyDeployment({ network: chainId, version: safeVersion || undefined }),
..._getValidatedGetContractProps(chainId, safeVersion),
})
}
Expand Down
13 changes: 10 additions & 3 deletions src/utils/transaction-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ export const isCustomTxInfo = (value: TransactionInfo): value is Custom => {
return value.type === TransactionInfoType.CUSTOM
}

export const isSupportedMultiSendAddress = (txInfo: TransactionInfo, chainId: string): boolean => {
export const isSupportedMultiSendAddress = (
txInfo: TransactionInfo,
chainId: string,
version: string | null,
): boolean => {
// Safe version can be null when a Safe is being loaded
katspaugh marked this conversation as resolved.
Show resolved Hide resolved
if (version == null) return false

const toAddress = isCustomTxInfo(txInfo) ? txInfo.to.value : ''
const multiSendAddress = getMultiSendContractAddress(chainId)
const multiSendCallOnlyAddress = getMultiSendCallOnlyContractAddress(chainId)
const multiSendAddress = getMultiSendContractAddress(chainId, version)
const multiSendCallOnlyAddress = getMultiSendCallOnlyContractAddress(chainId, version)

return sameAddress(multiSendAddress, toAddress) || sameAddress(multiSendCallOnlyAddress, toAddress)
}
Expand Down
Loading