diff --git a/src/logic/contracts/safeContracts.js b/src/logic/contracts/safeContracts.js index 9645a849..f7997e5c 100644 --- a/src/logic/contracts/safeContracts.js +++ b/src/logic/contracts/safeContracts.js @@ -75,7 +75,7 @@ export const deploySafeContract = async (safeAccounts: string[], numConfirmation export const getGnosisSafeInstanceAt = async (safeAddress: string) => { const web3 = getWeb3() - const GnosisSafe = await getGnosisSafeContract(web3) + const GnosisSafe = getGnosisSafeContract(web3) const gnosisSafe = await GnosisSafe.at(safeAddress) return gnosisSafe diff --git a/src/logic/safe/safeBlockchainOperations.js b/src/logic/safe/safeBlockchainOperations.js index a52de339..7fb87683 100644 --- a/src/logic/safe/safeBlockchainOperations.js +++ b/src/logic/safe/safeBlockchainOperations.js @@ -2,7 +2,7 @@ import { List } from 'immutable' import { calculateGasOf, checkReceiptStatus, calculateGasPrice } from '~/logic/wallets/ethTransactions' import { type Operation, submitOperation } from '~/logic/safe/safeTxHistory' -import { getSafeEthereumInstance } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { buildSignaturesFrom } from '~/logic/safe/safeTxSigner' import { generateMetamaskSignature, generateTxGasEstimateFrom, estimateDataGas } from '~/logic/safe/safeTxSignerEIP712' import { storeSignature, getSignaturesFrom } from '~/utils/storage/signatures' @@ -21,7 +21,7 @@ export const approveTransaction = async ( if (signaturesViaMetamask()) { // return executeTransaction(safeAddress, to, valueInWei, data, operation, nonce, sender) - const safe = await getSafeEthereumInstance(safeAddress) + const safe = await getGnosisSafeInstanceAt(safeAddress) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) const signature = await generateMetamaskSignature( safe, @@ -39,7 +39,7 @@ export const approveTransaction = async ( return undefined } - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const contractTxHash = await gnosisSafe.getTransactionHash(to, valueInWei, data, operation, 0, 0, 0, 0, 0, nonce) const approveData = gnosisSafe.contract.methods.approveHash(contractTxHash).encodeABI() @@ -67,7 +67,7 @@ export const executeTransaction = async ( const gasPrice = await calculateGasPrice() if (signaturesViaMetamask()) { - const safe = await getSafeEthereumInstance(safeAddress) + const safe = await getGnosisSafeInstanceAt(safeAddress) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) const signature = await generateMetamaskSignature( safe, @@ -120,7 +120,7 @@ export const executeTransaction = async ( return txHash } - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const signatures = buildSignaturesFrom(ownersWhoHasSigned, sender) const txExecutionData = gnosisSafe.contract.methods .execTransaction(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures) diff --git a/src/logic/safe/safeFrontendOperations.js b/src/logic/safe/safeFrontendOperations.js index 8a3cfc57..699b94d2 100644 --- a/src/logic/safe/safeFrontendOperations.js +++ b/src/logic/safe/safeFrontendOperations.js @@ -5,7 +5,6 @@ import { executeTransaction, approveTransaction } from '~/logic/safe/safeBlockch import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { getWeb3 } from '~/logic/wallets/getWeb3' import { type Safe } from '~/routes/safe/store/models/safe' -import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' import { storeSubject } from '~/utils/storage/transactions' export const TX_NAME_PARAM = 'txName' @@ -23,13 +22,6 @@ const hasOneOwner = (safe: Safe) => { return owners.count() === 1 } -export const getSafeEthereumInstance = async (safeAddress: string) => { - const web3 = getWeb3() - const GnosisSafe = await getGnosisSafeContract(web3) - const safeInstance = await GnosisSafe.at(safeAddress) - return safeInstance -} - export const createTransaction = async ( safe: Safe, name: string, diff --git a/src/logic/safe/safeTxHistory.js b/src/logic/safe/safeTxHistory.js index 631ba995..7dd6ae84 100644 --- a/src/logic/safe/safeTxHistory.js +++ b/src/logic/safe/safeTxHistory.js @@ -1,7 +1,7 @@ // @flow import { getWeb3 } from '~/logic/wallets/getWeb3' import { getTxServiceUriFrom, getTxServiceHost } from '~/config' -import { getSafeEthereumInstance } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' export type TxServiceType = 'confirmation' | 'execution' | 'initialised' export type Operation = 0 | 1 | 2 @@ -17,7 +17,7 @@ const calculateBodyFrom = async ( sender: string, type: TxServiceType, ) => { - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const contractTransactionHash = await gnosisSafe.getTransactionHash( to, valueInWei, diff --git a/src/routes/open/container/Open.jsx b/src/routes/open/container/Open.jsx index 4a66d5be..7d65b08f 100644 --- a/src/routes/open/container/Open.jsx +++ b/src/routes/open/container/Open.jsx @@ -5,8 +5,7 @@ import Page from '~/components/layout/Page' import { getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom, } from '~/routes/open/utils/safeDataExtractor' -import { getWeb3 } from '~/logic/wallets/getWeb3' -import { getGnosisSafeContract, deploySafeContract, initContracts } from '~/logic/contracts/safeContracts' +import { getGnosisSafeInstanceAt, deploySafeContract, initContracts } from '~/logic/contracts/safeContracts' import { checkReceiptStatus } from '~/logic/wallets/ethTransactions' import { history } from '~/store' import { OPENING_ADDRESS, stillInOpeningView, SAFELIST_ADDRESS } from '~/routes/routes' @@ -30,15 +29,12 @@ export const createSafe = async (values: Object, userAccount: string, addSafe: A const name = getSafeNameFrom(values) const owners = getNamesFrom(values) - const web3 = getWeb3() - const GnosisSafe = getGnosisSafeContract(web3) - await initContracts() const safe = await deploySafeContract(accounts, numConfirmations, userAccount) - checkReceiptStatus(safe.tx) + await checkReceiptStatus(safe.tx) - const param = safe.logs[0].args.proxy - const safeContract = await GnosisSafe.at(param) + const safeAddress = safe.logs[0].args.proxy + const safeContract = await getGnosisSafeInstanceAt(safeAddress) addSafe(name, safeContract.address, numConfirmations, owners, accounts) diff --git a/src/routes/safe/components/AddOwner/index.jsx b/src/routes/safe/components/AddOwner/index.jsx index 533039a2..920f056e 100644 --- a/src/routes/safe/components/AddOwner/index.jsx +++ b/src/routes/safe/components/AddOwner/index.jsx @@ -6,7 +6,8 @@ import { connect } from 'react-redux' import { type Safe } from '~/routes/safe/store/models/safe' import { type Owner, makeOwner } from '~/routes/safe/store/models/owner' import { setOwners } from '~/logic/safe/utils' -import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations' +import { createTransaction } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import AddOwnerForm, { NAME_PARAM, OWNER_ADDRESS_PARAM, INCREASE_PARAM } from './AddOwnerForm' import Review from './Review' import selector, { type SelectorProps } from './selector' @@ -36,7 +37,7 @@ const getOwnerAddressesFrom = (owners: List) => { export const addOwner = async (values: Object, safe: Safe, threshold: number, executor: string) => { const safeAddress = safe.get('address') - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const nonce = await gnosisSafe.nonce() const newThreshold = values[INCREASE_PARAM] ? threshold + 1 : threshold diff --git a/src/routes/safe/components/RemoveOwner/index.jsx b/src/routes/safe/components/RemoveOwner/index.jsx index 001860ec..d82592ab 100644 --- a/src/routes/safe/components/RemoveOwner/index.jsx +++ b/src/routes/safe/components/RemoveOwner/index.jsx @@ -3,7 +3,8 @@ import * as React from 'react' import Stepper from '~/components/Stepper' import { connect } from 'react-redux' import { type Safe } from '~/routes/safe/store/models/safe' -import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations' +import { createTransaction } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import RemoveOwnerForm, { DECREASE_PARAM } from './RemoveOwnerForm' import Review from './Review' import selector, { type SelectorProps } from './selector' @@ -42,7 +43,7 @@ export const removeOwner = async ( executor: string, ) => { const safeAddress = safe.get('address') - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const nonce = await gnosisSafe.nonce() const newThreshold = values[DECREASE_PARAM] ? threshold - 1 : threshold const storedOwners = await gnosisSafe.getOwners() diff --git a/src/routes/safe/components/SendToken/index.jsx b/src/routes/safe/components/SendToken/index.jsx index 06adea87..84899436 100644 --- a/src/routes/safe/components/SendToken/index.jsx +++ b/src/routes/safe/components/SendToken/index.jsx @@ -10,7 +10,8 @@ import { type Token } from '~/logic/tokens/store/model/token' import { isEther } from '~/logic/tokens/utils/tokenHelpers' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { toNative } from '~/logic/wallets/tokens' -import { createTransaction, getSafeEthereumInstance } from '~/logic/safe/safeFrontendOperations' +import { createTransaction } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import actions, { type Actions } from './actions' import selector, { type SelectorProps } from './selector' import SendTokenForm, { TKN_DESTINATION_PARAM, TKN_VALUE_PARAM } from './SendTokenForm' @@ -40,7 +41,7 @@ const getTransferData = async (tokenAddress: string, to: string, amount: BigNumb const processTokenTransfer = async (safe: Safe, token: Token, to: string, amount: string, userAddress: string) => { const safeAddress = safe.get('address') - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const nonce = await gnosisSafe.nonce() const symbol = token.get('symbol') const name = `Send ${amount} ${symbol} to ${to}` diff --git a/src/routes/safe/components/Threshold/index.jsx b/src/routes/safe/components/Threshold/index.jsx index 3b5a18e2..1f698aa2 100644 --- a/src/routes/safe/components/Threshold/index.jsx +++ b/src/routes/safe/components/Threshold/index.jsx @@ -2,7 +2,8 @@ import * as React from 'react' import Stepper from '~/components/Stepper' import { connect } from 'react-redux' -import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations' +import { createTransaction } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { type Safe } from '~/routes/safe/store/models/safe' import ThresholdForm, { THRESHOLD_PARAM } from './ThresholdForm' import selector, { type SelectorProps } from './selector' @@ -35,7 +36,7 @@ class Threshold extends React.PureComponent { const { safe, userAddress, fetchTransactions } = this.props // , fetchThreshold } = this.props const newThreshold = values[THRESHOLD_PARAM] const safeAddress = safe.get('address') - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const nonce = await gnosisSafe.nonce() const data = gnosisSafe.contract.changeThreshold(newThreshold).encodeABI() await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safeAddress, '0', nonce, userAddress, data) diff --git a/src/routes/safe/store/actions/fetchSafe.js b/src/routes/safe/store/actions/fetchSafe.js index ffb800a0..83fd2774 100644 --- a/src/routes/safe/store/actions/fetchSafe.js +++ b/src/routes/safe/store/actions/fetchSafe.js @@ -6,8 +6,8 @@ import { makeOwner } from '~/routes/safe/store/models/owner' import type { SafeProps } from '~/routes/safe/store/models/safe' import { addSafe } from '~/routes/safe/store/actions/addSafe' import { getOwners, getSafeName } from '~/logic/safe/utils' -import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' -import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' +import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import updateSafe from '~/routes/safe/store/actions/updateSafe' const buildOwnersFrom = ( @@ -19,9 +19,7 @@ const buildOwnersFrom = ( }) export const buildSafe = async (safeAddress: string, safeName: string) => { - const web3 = getWeb3() - const SafeContract = await getGnosisSafeContract(web3) - const gnosisSafe = await SafeContract.at(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const ethBalance = await getBalanceInEtherOf(safeAddress) const threshold = Number(await gnosisSafe.getThreshold()) diff --git a/src/routes/safe/test/Safe.threshold.test.js b/src/routes/safe/test/Safe.threshold.test.js index 63d8dbd9..33632e2c 100644 --- a/src/routes/safe/test/Safe.threshold.test.js +++ b/src/routes/safe/test/Safe.threshold.test.js @@ -15,7 +15,7 @@ import { import { getTransactionFromReduxStore } from '~/routes/safe/test/testMultisig' import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps' import { createTransaction } from '~/wallets/createTransactions' -import { getGnosisSafeContract } from '~/wallets/safeContracts' +import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' */ describe('React DOM TESTS > Change threshold', () => { @@ -32,9 +32,7 @@ describe('React DOM TESTS > Change threshold', () => { const match: Match = buildMathPropsFrom(address) const safe = safeSelector(store.getState(), { match }) if (!safe) throw new Error() - const web3 = getWeb3() - const GnosisSafe = await getGnosisSafeContract(web3) - const gnosisSafe = GnosisSafe.at(address) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) // WHEN const nonce = Date.now() @@ -79,9 +77,7 @@ describe('React DOM TESTS > Change threshold', () => { const match: Match = buildMathPropsFrom(address) const safe = safeSelector(store.getState(), { match }) if (!safe) throw new Error() - const web3 = getWeb3() - const GnosisSafe = await getGnosisSafeContract(web3) - const gnosisSafe = GnosisSafe.at(address) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) // WHEN const nonce = Date.now() diff --git a/src/test/safe.redux.transactions.test.js b/src/test/safe.redux.transactions.test.js index 1809e816..272b1178 100644 --- a/src/test/safe.redux.transactions.test.js +++ b/src/test/safe.redux.transactions.test.js @@ -1,6 +1,7 @@ // @flow import { List } from 'immutable' -import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations' +import { createTransaction } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { type Safe } from '~/routes/safe/store/models/safe' import { makeOwner } from '~/routes/safe/store/models/owner' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' @@ -29,7 +30,7 @@ describe('Transactions Suite', () => { it('retrieves tx info from service having subject available', async () => { let safe: Safe = getSafeFrom(store.getState(), safeAddress) - const gnosisSafe = await getSafeEthereumInstance(safeAddress) + const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const firstTxData = gnosisSafe.contract.methods.addOwnerWithThreshold(accounts[1], 2).encodeABI() const executor = accounts[0] const nonce = await gnosisSafe.nonce() diff --git a/src/test/utils/ethereumErrors.js b/src/test/utils/ethereumErrors.js index e1d10f57..f4f0cd43 100644 --- a/src/test/utils/ethereumErrors.js +++ b/src/test/utils/ethereumErrors.js @@ -6,7 +6,7 @@ import abi from 'ethereumjs-abi' console.log(`to[${to}] \n\n valieInWei[${valueInWei}] \n\n data[${data}] \n\n operation[${operation}] \n\n sigs[${sigs}]`) -const gnosisSafe = await getSafeEthereumInstance(address) +const gnosisSafe = await getGnosisSafeInstanceAt(address) await printOutApprove("Remove owner 3", address, await gnosisSafe.getOwners(), tx.get('data'), tx.get('nonce')) const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(address, 0, tx.get('data'), 0, tx.get('nonce'))