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

[Multichain] fix: Pass options for safe creation [SW-199] #4234

Merged
merged 4 commits into from
Sep 23, 2024
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
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
Loading