Skip to content

Commit

Permalink
[Multichain] fix: Pass options for safe creation [SW-199] (#4234)
Browse files Browse the repository at this point in the history
* fix: Pass options for safe creation

* fix: Don't spread newSafeProps
  • Loading branch information
usame-algan committed Sep 23, 2024
1 parent 357fc85 commit caf5b96
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/components/new-safe/create/logic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ export const createNewSafe = async (
undeployedSafeProps: UndeployedSafeProps,
safeVersion: SafeVersion,
chain: ChainInfo,
options: DeploySafeProps['options'],
callback: (txHash: string) => void,
isL1SafeSingleton?: boolean,
): Promise<void> => {
const safeFactory = await getSafeFactory(provider, safeVersion, isL1SafeSingleton)

if (isPredictedSafeProps(undeployedSafeProps)) {
await safeFactory.deploySafe({ ...undeployedSafeProps, callback })
await safeFactory.deploySafe({ ...undeployedSafeProps, options, callback })
} else {
const txResponse = await activateReplayedSafe(chain, undeployedSafeProps, createWeb3(provider))
const txResponse = await activateReplayedSafe(chain, undeployedSafeProps, createWeb3(provider), options)
callback(txResponse.hash)
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/components/new-safe/create/steps/ReviewStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
const [isCreating, setIsCreating] = useState<boolean>(false)
const [submitError, setSubmitError] = useState<string>()
const isCounterfactualEnabled = useHasFeature(FEATURES.COUNTERFACTUAL)
const isMultiChainDeploymentEnabled = useHasFeature(FEATURES.MULTI_CHAIN_SAFE_CREATION)
const isEIP1559 = chain && hasFeature(chain, FEATURES.EIP1559)

const ownerAddresses = useMemo(() => data.owners.map((owner) => owner.address), [data.owners])
Expand All @@ -166,11 +165,17 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
[chain, data.owners, data.safeVersion, data.threshold],
)

const safePropsForGasEstimation = useMemo(() => {
return newSafeProps
? {
...newSafeProps,
saltNonce: Date.now().toString(),
}
: undefined
}, [newSafeProps])

// We estimate with a random nonce as we'll just slightly overestimates like this
const { gasLimit } = useEstimateSafeCreationGas(
newSafeProps ? { ...newSafeProps, saltNonce: Date.now().toString() } : undefined,
data.safeVersion,
)
const { gasLimit } = useEstimateSafeCreationGas(safePropsForGasEstimation, data.safeVersion)

const maxFeePerGas = gasPrice?.maxFeePerGas
const maxPriorityFeePerGas = gasPrice?.maxPriorityFeePerGas
Expand Down Expand Up @@ -281,6 +286,7 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
props,
data.safeVersion,
chain,
options,
(txHash) => {
onSubmitCallback(undefined, txHash)
},
Expand Down
4 changes: 2 additions & 2 deletions src/features/counterfactual/ActivateAccountFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ const ActivateAccountFlow = () => {

if (!undeployedSafe || !undeployedSafeSetup) return null

const { owners, threshold } = undeployedSafeSetup
const { saltNonce, safeVersion } = undeployedSafeSetup
const { owners, threshold, safeVersion } = undeployedSafeSetup

const onSubmit = (txHash?: string) => {
trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.activate_without_tx })
Expand Down Expand Up @@ -128,6 +127,7 @@ const ActivateAccountFlow = () => {
undeployedSafe.props,
safeVersion ?? getLatestSafeVersion(chain),
chain,
options,
onSubmit,
isMultichainSafe ? true : undefined,
)
Expand Down
10 changes: 8 additions & 2 deletions src/features/counterfactual/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,16 @@ export const extractCounterfactualSafeSetup = (
}
}

export const activateReplayedSafe = async (chain: ChainInfo, props: ReplayedSafeProps, provider: BrowserProvider) => {
const data = await encodeSafeCreationTx(props, chain)
export const activateReplayedSafe = async (
chain: ChainInfo,
props: ReplayedSafeProps,
provider: BrowserProvider,
options: DeploySafeProps['options'],
) => {
const data = encodeSafeCreationTx(props, chain)

return (await provider.getSigner()).sendTransaction({
...options,
to: props.factoryAddress,
data,
value: '0',
Expand Down

0 comments on commit caf5b96

Please sign in to comment.