From e3c4c7661d4eb909a78601d7d566cee32ac7fc97 Mon Sep 17 00:00:00 2001 From: apanizo Date: Wed, 16 May 2018 16:06:39 +0200 Subject: [PATCH] WA-238 adapt safeContracts> initContracts and code when creating safe to new safe-contracts --- .../safe/component/Withdrawn/withdrawn.js | 4 +-- src/wallets/safeContracts.js | 35 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/routes/safe/component/Withdrawn/withdrawn.js b/src/routes/safe/component/Withdrawn/withdrawn.js index 1c06658e..ad958b48 100644 --- a/src/routes/safe/component/Withdrawn/withdrawn.js +++ b/src/routes/safe/component/Withdrawn/withdrawn.js @@ -1,7 +1,7 @@ // @flow import { getWeb3 } from '~/wallets/getWeb3' import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts' -import { type DailyLimitProps } from '~/routes/safe/store/model/safe' +import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit' export const LIMIT_POSITION = 0 export const SPENT_TODAY_POS = 1 @@ -23,7 +23,7 @@ const getDailyLimitModuleFrom = async (safeAddress) => { return dailyLimitModule } -export const getDailyLimitFrom = async (safeAddress, tokenAddress): DailyLimitProps => { +export const getDailyLimitFrom = async (safeAddress: string, tokenAddress: number): Promise => { const web3 = getWeb3() const dailyLimitModule = await getDailyLimitModuleFrom(safeAddress) diff --git a/src/wallets/safeContracts.js b/src/wallets/safeContracts.js index 243e2276..65a516c3 100644 --- a/src/wallets/safeContracts.js +++ b/src/wallets/safeContracts.js @@ -5,14 +5,31 @@ import { ensureOnce } from '~/utils/singleton' import { getWeb3 } from '~/wallets/getWeb3' import GnosisSafeSol from '#/GnosisSafeTeamEdition.json' import ProxyFactorySol from '#/ProxyFactory.json' -import CreateAndAddModule from '#/CreateAndAddModule.json' +import CreateAndAddModules from '#/CreateAndAddModules.json' import DailyLimitModule from '#/DailyLimitModule.json' let proxyFactoryMaster -let createAndAddExtensionMaster +let createAndAddModuleMaster let safeMaster let dailyLimitMaster +const createModuleDataWrapper = () => { + const web3 = getWeb3() + // eslint-disable-next-line + return web3.eth.contract([{"constant":false,"inputs":[{"name":"data","type":"bytes"}],"name":"setup","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]) +} + +const getModuleDataWrapper = ensureOnce(createModuleDataWrapper) + +function createAndAddModulesData(dataArray) { + const ModuleDataWrapper = getModuleDataWrapper() + + const mw = ModuleDataWrapper.at(1) + // Remove method id (10) and position of data in payload (64) + return dataArray.reduce((acc, data) => acc + mw.setup.getData(data).substr(74), '0x') +} + + const createGnosisSafeContract = (web3: any) => { const gnosisSafe = contract(GnosisSafeSol) gnosisSafe.setProvider(web3.currentProvider) @@ -28,7 +45,7 @@ const createProxyFactoryContract = (web3: any) => { } const createAddExtensionContract = (web3: any) => { - const createAndAddModule = contract(CreateAndAddModule) + const createAndAddModule = contract(CreateAndAddModules) createAndAddModule.setProvider(web3.currentProvider) return createAndAddModule @@ -62,9 +79,9 @@ const createMasterCopies = async () => { // Create AddExtension Master Copy const CreateAndAddExtension = getCreateAddExtensionContract(web3) try { - createAndAddExtensionMaster = await CreateAndAddExtension.deployed() + createAndAddModuleMaster = await CreateAndAddExtension.deployed() } catch (err) { - createAndAddExtensionMaster = await CreateAndAddExtension.new({ from: userAccount, gas: '5000000' }) + createAndAddModuleMaster = await CreateAndAddExtension.new({ from: userAccount, gas: '5000000' }) } // Initialize safe master copy @@ -95,11 +112,13 @@ const getSafeDataBasedOn = async (accounts, numConfirmations, dailyLimitInEth) = const proxyFactoryData = await proxyFactoryMaster.contract.createProxy .getData(dailyLimitMaster.address, moduleData) - const createAndAddExtensionData = createAndAddExtensionMaster.contract.createAndAddModule - .getData(proxyFactoryMaster.address, proxyFactoryData) + const modulesCreationData = createAndAddModulesData([proxyFactoryData]) + + const createAndAddModuleData = createAndAddModuleMaster.contract.createAndAddModules + .getData(proxyFactoryMaster.address, modulesCreationData) return safeMaster.contract.setup - .getData(accounts, numConfirmations, createAndAddExtensionMaster.address, createAndAddExtensionData) + .getData(accounts, numConfirmations, createAndAddModuleMaster.address, createAndAddModuleData) } export const deploySafeContract = async (