(Feature) - Replaces createProxy with createProxyWithNonce method no safe creation (#1630)

* Replaces createProxy with createProxyWithNonce method no safe creation

* Updates estimationGas method

* Moves safeCreationSalt as a parameter

* Fix default export

Co-authored-by: nicolas <nicosampler@users.noreply.github.com>
This commit is contained in:
Agustin Pane 2020-11-19 09:19:31 -03:00 committed by GitHub
parent 8876469166
commit 486bb4b203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 19 deletions

View File

@ -74,24 +74,25 @@ export const getSafeMasterContract = async () => {
return safeMaster return safeMaster
} }
export const getSafeDeploymentTransaction = (safeAccounts, numConfirmations) => { export const getSafeDeploymentTransaction = (safeAccounts: string[], numConfirmations: number, safeCreationSalt: number) => {
const gnosisSafeData = safeMaster.methods const gnosisSafeData = safeMaster.methods
.setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS) .setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS)
.encodeABI() .encodeABI()
return proxyFactoryMaster.methods.createProxy(safeMaster.options.address, gnosisSafeData) return proxyFactoryMaster.methods.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
} }
export const estimateGasForDeployingSafe = async ( export const estimateGasForDeployingSafe = async (
safeAccounts, safeAccounts: string[],
numConfirmations, numConfirmations: number,
userAccount, userAccount: string,
safeCreationSalt: number
) => { ) => {
const gnosisSafeData = await safeMaster.methods const gnosisSafeData = await safeMaster.methods
.setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS) .setup(safeAccounts, numConfirmations, ZERO_ADDRESS, '0x', DEFAULT_FALLBACK_HANDLER_ADDRESS, ZERO_ADDRESS, 0, ZERO_ADDRESS)
.encodeABI() .encodeABI()
const proxyFactoryData = proxyFactoryMaster.methods const proxyFactoryData = proxyFactoryMaster.methods
.createProxy(safeMaster.options.address, gnosisSafeData) .createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
.encodeABI() .encodeABI()
const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.options.address) const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.options.address)
const gasPrice = await calculateGasPrice() const gasPrice = await calculateGasPrice()

View File

@ -7,11 +7,12 @@ import Block from 'src/components/layout/Block'
import Heading from 'src/components/layout/Heading' import Heading from 'src/components/layout/Heading'
import Row from 'src/components/layout/Row' import Row from 'src/components/layout/Row'
import { initContracts } from 'src/logic/contracts/safeContracts' 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 SafeNameField from 'src/routes/open/components/SafeNameForm'
import { SafeOwnersPage } from 'src/routes/open/components/SafeOwnersConfirmationsForm' import { SafeOwnersPage } from 'src/routes/open/components/SafeOwnersConfirmationsForm'
import { import {
FIELD_CONFIRMATIONS, FIELD_CONFIRMATIONS,
FIELD_CREATION_PROXY_SALT,
FIELD_SAFE_NAME, FIELD_SAFE_NAME,
getOwnerAddressBy, getOwnerAddressBy,
getOwnerNameBy, getOwnerNameBy,
@ -40,6 +41,7 @@ type InitialValuesForm = {
owner0Name?: string owner0Name?: string
confirmations: string confirmations: string
safeName?: string safeName?: string
safeCreationSalt: number
} }
const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): InitialValuesForm => { const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): InitialValuesForm => {
@ -51,6 +53,7 @@ const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): Initi
[getOwnerNameBy(0)]: ownerName || 'My Wallet', [getOwnerNameBy(0)]: ownerName || 'My Wallet',
[getOwnerAddressBy(0)]: userAccount, [getOwnerAddressBy(0)]: userAccount,
[FIELD_CONFIRMATIONS]: '1', [FIELD_CONFIRMATIONS]: '1',
[FIELD_CREATION_PROXY_SALT]: Date.now(),
} }
} }
let obj = {} let obj = {}
@ -68,6 +71,7 @@ const useInitialValuesFrom = (userAccount: string, safeProps?: SafeProps): Initi
...obj, ...obj,
[FIELD_CONFIRMATIONS]: threshold || '1', [FIELD_CONFIRMATIONS]: threshold || '1',
[FIELD_SAFE_NAME]: name, [FIELD_SAFE_NAME]: name,
[FIELD_CREATION_PROXY_SALT]: Date.now(),
} }
} }
@ -92,7 +96,7 @@ type LayoutProps = {
safeProps?: SafeProps safeProps?: SafeProps
} }
const Layout = (props: LayoutProps): React.ReactElement => { export const Layout = (props: LayoutProps): React.ReactElement => {
const { onCallSafeContractSubmit, safeProps } = props const { onCallSafeContractSubmit, safeProps } = props
const provider = useSelector(providerNameSelector) const provider = useSelector(providerNameSelector)
@ -139,5 +143,3 @@ const Layout = (props: LayoutProps): React.ReactElement => {
</> </>
) )
} }
export default Layout

View File

@ -13,7 +13,7 @@ import Row from 'src/components/layout/Row'
import OpenPaper from 'src/components/Stepper/OpenPaper' import OpenPaper from 'src/components/Stepper/OpenPaper'
import { estimateGasForDeployingSafe } from 'src/logic/contracts/safeContracts' import { estimateGasForDeployingSafe } from 'src/logic/contracts/safeContracts'
import { formatAmount } from 'src/logic/tokens/utils/formatAmount' 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 { FIELD_CONFIRMATIONS, FIELD_NAME, getNumOwnersFrom } from '../fields'
import { useStyles } from './styles' import { useStyles } from './styles'
@ -33,20 +33,23 @@ const ReviewComponent = ({ userAccount, values }: ReviewComponentProps) => {
const names = getNamesFrom(values) const names = getNamesFrom(values)
const addresses = getAccountsFrom(values) const addresses = getAccountsFrom(values)
const numOwners = getNumOwnersFrom(values) const numOwners = getNumOwnersFrom(values)
const safeCreationSalt = getSafeCreationSaltFrom(values)
useEffect(() => { useEffect(() => {
const estimateGas = async () => { const estimateGas = async () => {
if (!addresses.length || !numOwners || !userAccount) { if (!addresses.length || !numOwners || !userAccount) {
return 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 gasCosts = fromTokenUnit(estimatedGasCosts, nativeCoin.decimals)
const formattedGasCosts = formatAmount(gasCosts) const formattedGasCosts = formatAmount(gasCosts)
setGasCosts(formattedGasCosts) setGasCosts(formattedGasCosts)
} }
estimateGas() estimateGas()
}, [addresses, numOwners, userAccount]) }, [addresses, numOwners, safeCreationSalt, userAccount])
return ( return (
<> <>
@ -140,7 +143,7 @@ const ReviewComponent = ({ userAccount, values }: ReviewComponentProps) => {
) )
} }
const Review = () => export const Review = () =>
function ReviewPage(controls, props): React.ReactElement { function ReviewPage(controls, props): React.ReactElement {
return ( return (
<> <>
@ -150,5 +153,3 @@ const Review = () =>
</> </>
) )
} }
export default Review

View File

@ -2,6 +2,7 @@ export const FIELD_NAME = 'name'
export const FIELD_CONFIRMATIONS = 'confirmations' export const FIELD_CONFIRMATIONS = 'confirmations'
export const FIELD_OWNERS = 'owners' export const FIELD_OWNERS = 'owners'
export const FIELD_SAFE_NAME = 'safeName' export const FIELD_SAFE_NAME = 'safeName'
export const FIELD_CREATION_PROXY_SALT = 'safeCreationSalt'
export const getOwnerNameBy = (index) => `owner${index}Name` export const getOwnerNameBy = (index) => `owner${index}Name`
export const getOwnerAddressBy = (index) => `owner${index}Address` export const getOwnerAddressBy = (index) => `owner${index}Address`

View File

@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { useDispatch, useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
import Opening from 'src/routes/opening' 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 Page from 'src/components/layout/Page'
import { getSafeDeploymentTransaction } from 'src/logic/contracts/safeContracts' import { getSafeDeploymentTransaction } from 'src/logic/contracts/safeContracts'
import { checkReceiptStatus } from 'src/logic/wallets/ethTransactions' import { checkReceiptStatus } from 'src/logic/wallets/ethTransactions'
@ -12,6 +12,7 @@ import {
getAccountsFrom, getAccountsFrom,
getNamesFrom, getNamesFrom,
getOwnersFrom, getOwnersFrom,
getSafeCreationSaltFrom,
getSafeNameFrom, getSafeNameFrom,
getThresholdFrom, getThresholdFrom,
} from 'src/routes/open/utils/safeDataExtractor' } from 'src/routes/open/utils/safeDataExtractor'
@ -58,8 +59,9 @@ export const createSafe = (values, userAccount) => {
const name = getSafeNameFrom(values) const name = getSafeNameFrom(values)
const ownersNames = getNamesFrom(values) const ownersNames = getNamesFrom(values)
const ownerAddresses = getAccountsFrom(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 }) const promiEvent = deploymentTx.send({ from: userAccount })

View File

@ -28,3 +28,5 @@ export const getOwnersFrom = (names, addresses): List<SafeOwner> => {
export const getThresholdFrom = (values) => Number(values.confirmations) export const getThresholdFrom = (values) => Number(values.confirmations)
export const getSafeNameFrom = (values) => values.name export const getSafeNameFrom = (values) => values.name
export const getSafeCreationSaltFrom = (values) => values.safeCreationSalt