Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
13 changes: 7 additions & 6 deletions src/logic/contracts/safeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,25 @@ export const getSafeMasterContract = async () => {
return safeMaster
}

export const getSafeDeploymentTransaction = (safeAccounts, numConfirmations) => {
export const getSafeDeploymentTransaction = (safeAccounts: string[], numConfirmations: number, safeCreationSalt: number) => {
const gnosisSafeData = safeMaster.methods
.setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS)
.encodeABI()

return proxyFactoryMaster.methods.createProxy(safeMaster.options.address, gnosisSafeData)
return proxyFactoryMaster.methods.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
Copy link
Contributor

Choose a reason for hiding this comment

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

DO you know if all the proxyFactory versions have this method implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmm I'm not sure, @rmeissner could you confirm please?

Copy link
Contributor

@fernandomg fernandomg Nov 18, 2020

Choose a reason for hiding this comment

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

We are getting that info from the @gnosis.pm/safe-contracts package. I think it's safe to assume that that method will be available.

Copy link
Contributor

Choose a reason for hiding this comment

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

our proxy factory always exposes this method ;)

}

export const estimateGasForDeployingSafe = async (
safeAccounts,
numConfirmations,
userAccount,
safeAccounts: string[],
numConfirmations: number,
userAccount: string,
safeCreationSalt: number
) => {
const gnosisSafeData = await safeMaster.methods
.setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS)
.encodeABI()
const proxyFactoryData = proxyFactoryMaster.methods
.createProxy(safeMaster.options.address, gnosisSafeData)
.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
.encodeABI()
const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.options.address)
const gasPrice = await calculateGasPrice()
Expand Down
10 changes: 6 additions & 4 deletions src/routes/open/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import Block from 'src/components/layout/Block'
import Heading from 'src/components/layout/Heading'
import Row from 'src/components/layout/Row'
import { initContracts } from 'src/logic/contracts/safeContracts'
import Review from 'src/routes/open/components/ReviewInformation'
import { Review } from 'src/routes/open/components/ReviewInformation'
import SafeNameField from 'src/routes/open/components/SafeNameForm'
import { SafeOwnersPage } from 'src/routes/open/components/SafeOwnersConfirmationsForm'
import {
FIELD_CONFIRMATIONS,
FIELD_CREATION_PROXY_SALT,
FIELD_SAFE_NAME,
getOwnerAddressBy,
getOwnerNameBy,
Expand Down Expand Up @@ -40,6 +41,7 @@ type InitialValuesForm = {
owner0Name?: string
confirmations: string
safeName?: string
safeCreationSalt: number
}

const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): InitialValuesForm => {
Expand All @@ -51,6 +53,7 @@ const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): Initi
[getOwnerNameBy(0)]: ownerName || 'My Wallet',
[getOwnerAddressBy(0)]: userAccount,
[FIELD_CONFIRMATIONS]: '1',
[FIELD_CREATION_PROXY_SALT]: Date.now(),
}
}
let obj = {}
Expand All @@ -68,6 +71,7 @@ const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): Initi
...obj,
[FIELD_CONFIRMATIONS]: threshold || '1',
[FIELD_SAFE_NAME]: name,
[FIELD_CREATION_PROXY_SALT]: Date.now(),
}
}

Expand All @@ -92,7 +96,7 @@ type LayoutProps = {
safeProps?: SafeProps
}

const Layout = (props: LayoutProps): React.ReactElement => {
export const Layout = (props: LayoutProps): React.ReactElement => {
const { onCallSafeContractSubmit, safeProps } = props

const provider = useSelector(providerNameSelector)
Expand Down Expand Up @@ -139,5 +143,3 @@ const Layout = (props: LayoutProps): React.ReactElement => {
</>
)
}

export default Layout
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason to remove default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, I disagreed with some points and some others are interesting.
But I think we should all agreed on this because right now almost all the project is making use of default export.

If we define to start using named exports always, we should define a linter rule. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep it's a good idea for me

13 changes: 7 additions & 6 deletions src/routes/open/components/ReviewInformation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Row from 'src/components/layout/Row'
import OpenPaper from 'src/components/Stepper/OpenPaper'
import { estimateGasForDeployingSafe } from 'src/logic/contracts/safeContracts'
import { formatAmount } from 'src/logic/tokens/utils/formatAmount'
import { getAccountsFrom, getNamesFrom } from 'src/routes/open/utils/safeDataExtractor'
import { getAccountsFrom, getNamesFrom, getSafeCreationSaltFrom } from 'src/routes/open/utils/safeDataExtractor'

import { FIELD_CONFIRMATIONS, FIELD_NAME, getNumOwnersFrom } from '../fields'
import { useStyles } from './styles'
Expand All @@ -33,20 +33,23 @@ const ReviewComponent = ({ userAccount, values }: ReviewComponentProps) => {
const names = getNamesFrom(values)
const addresses = getAccountsFrom(values)
const numOwners = getNumOwnersFrom(values)
const safeCreationSalt = getSafeCreationSaltFrom(values)

useEffect(() => {
const estimateGas = async () => {
if (!addresses.length || !numOwners || !userAccount) {
return
}
const estimatedGasCosts = (await estimateGasForDeployingSafe(addresses, numOwners, userAccount)).toString()
const estimatedGasCosts = (
await estimateGasForDeployingSafe(addresses, numOwners, userAccount, safeCreationSalt)
).toString()
const gasCosts = fromTokenUnit(estimatedGasCosts, nativeCoin.decimals)
const formattedGasCosts = formatAmount(gasCosts)
setGasCosts(formattedGasCosts)
}

estimateGas()
}, [addresses, numOwners, userAccount])
}, [addresses, numOwners, safeCreationSalt, userAccount])

return (
<>
Expand Down Expand Up @@ -140,7 +143,7 @@ const ReviewComponent = ({ userAccount, values }: ReviewComponentProps) => {
)
}

const Review = () =>
export const Review = () =>
function ReviewPage(controls, props): React.ReactElement {
return (
<>
Expand All @@ -150,5 +153,3 @@ const Review = () =>
</>
)
}

export default Review
1 change: 1 addition & 0 deletions src/routes/open/components/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const FIELD_NAME = 'name'
export const FIELD_CONFIRMATIONS = 'confirmations'
export const FIELD_OWNERS = 'owners'
export const FIELD_SAFE_NAME = 'safeName'
export const FIELD_CREATION_PROXY_SALT = 'safeCreationSalt'

export const getOwnerNameBy = (index) => `owner${index}Name`
export const getOwnerAddressBy = (index) => `owner${index}Address`
Expand Down
6 changes: 4 additions & 2 deletions src/routes/open/container/Open.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import React, { useEffect, useState } from 'react'
import ReactGA from 'react-ga'
import { useDispatch, useSelector } from 'react-redux'
import Opening from 'src/routes/opening'
import Layout from 'src/routes/open/components/Layout'
import { Layout } from 'src/routes/open/components/Layout'
import Page from 'src/components/layout/Page'
import { getSafeDeploymentTransaction } from 'src/logic/contracts/safeContracts'
import { checkReceiptStatus } from 'src/logic/wallets/ethTransactions'
import {
getAccountsFrom,
getNamesFrom,
getOwnersFrom,
getSafeCreationSaltFrom,
getSafeNameFrom,
getThresholdFrom,
} from 'src/routes/open/utils/safeDataExtractor'
Expand Down Expand Up @@ -58,8 +59,9 @@ export const createSafe = (values, userAccount) => {
const name = getSafeNameFrom(values)
const ownersNames = getNamesFrom(values)
const ownerAddresses = getAccountsFrom(values)
const safeCreationSalt = getSafeCreationSaltFrom(values)

const deploymentTx = getSafeDeploymentTransaction(ownerAddresses, confirmations)
const deploymentTx = getSafeDeploymentTransaction(ownerAddresses, confirmations, safeCreationSalt)

const promiEvent = deploymentTx.send({ from: userAccount })

Expand Down
2 changes: 2 additions & 0 deletions src/routes/open/utils/safeDataExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const getOwnersFrom = (names, addresses): List<SafeOwner> => {
export const getThresholdFrom = (values) => Number(values.confirmations)

export const getSafeNameFrom = (values) => values.name

export const getSafeCreationSaltFrom = (values) => values.safeCreationSalt
2 changes: 1 addition & 1 deletion src/test/safe.dom.create.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
import * as React from 'react'
import { } from 'redux'
import { render, fireEvent, act } from '@testing-library/react'
Expand Down