From f826e701f7e80ecbee89730364cfbc04b4e54a61 Mon Sep 17 00:00:00 2001 From: cristovaoth Date: Tue, 1 Nov 2022 11:41:47 +0100 Subject: [PATCH 1/2] Include setMultisend on the setup stack. Remove redudant arguments on some functions used to encode transactions... --- packages/app/src/services/helpers.ts | 22 ++-- packages/app/src/services/index.ts | 108 ++++++++---------- .../CustomModule/CustomModuleModal.tsx | 6 +- .../RealityModule/service/moduleDeployment.ts | 16 ++- .../services/moduleDeploymentOld.ts | 16 ++- .../RolesModifier/RolesModifierModal.tsx | 13 +++ 6 files changed, 88 insertions(+), 93 deletions(-) diff --git a/packages/app/src/services/helpers.ts b/packages/app/src/services/helpers.ts index eb9ff091..cf798fe9 100644 --- a/packages/app/src/services/helpers.ts +++ b/packages/app/src/services/helpers.ts @@ -1,20 +1,20 @@ -import { Contract } from "ethers"; -import { abi as SafeAbi } from "@gnosis.pm/safe-deployments/dist/assets/v1.3.0/gnosis_safe_l2.json"; +import { Interface } from "@ethersproject/abi" +import { abi as SafeAbi } from "@gnosis.pm/safe-deployments/dist/assets/v1.3.0/gnosis_safe_l2.json" -export const AddressOne = "0x0000000000000000000000000000000000000001"; +export const AddressOne = "0x0000000000000000000000000000000000000001" export const buildTransaction = ( - contract: Contract, + iface: Interface, + to: string, method: string, params: any[], - value?: string + value?: string, ) => { - let data = contract.interface.encodeFunctionData(method, params); return { - to: contract.address, - data, + to, + data: iface.encodeFunctionData(method, params), value: value || "0", - }; -}; + } +} -export { SafeAbi }; +export { SafeAbi } diff --git a/packages/app/src/services/index.ts b/packages/app/src/services/index.ts index aa348c03..81e3be5d 100644 --- a/packages/app/src/services/index.ts +++ b/packages/app/src/services/index.ts @@ -1,4 +1,5 @@ import { BigNumber, Contract, ethers } from "ethers" +import { Interface } from "@ethersproject/abi" import { calculateProxyAddress, deployAndSetUpModule, @@ -53,6 +54,7 @@ interface DelayModuleParams { export interface RolesModifierParams { target: string + multisend: string } export interface AMBModuleParams { @@ -199,18 +201,16 @@ export function deployTellorModule( if (executor !== safeAddress) { const delayModule = getModuleInstance(KnownContracts.DELAY, executor, provider) - const addModuleTransaction = buildTransaction(delayModule, "enableModule", [ - daoModuleExpectedAddress, - ]) + const addModuleTransaction = buildTransaction( + delayModule.interface, + delayModule.address, + "enableModule", + [daoModuleExpectedAddress], + ) daoModuleTransactions.push(addModuleTransaction) } else { - const enableDaoModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - daoModuleExpectedAddress, - ) + const enableDaoModuleTransaction = enableModule(safeAddress, daoModuleExpectedAddress) daoModuleTransactions.push(enableDaoModuleTransaction) } @@ -238,9 +238,7 @@ export function deployDelayModule( Date.now().toString(), ) const enableDelayModuleTransaction = enableModule( - provider, safeAddress, - chainId, delayModuleExpectedAddress, ) @@ -279,12 +277,7 @@ export function deployBridgeModule( Date.now().toString(), ) - const enableModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - expectedModuleAddress, - ) + const enableModuleTransaction = enableModule(safeAddress, expectedModuleAddress) return [ { @@ -400,12 +393,7 @@ export async function deployExitModule( value: transaction.value.toString(), }) - const enableModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - expectedModuleAddress, - ) + const enableModuleTransaction = enableModule(safeAddress, expectedModuleAddress) txs.push(enableModuleTransaction) return txs @@ -421,14 +409,8 @@ export async function fetchSafeModulesAddress( return modules as string[] } -export function enableModule( - provider: JsonRpcProvider, - safeAddress: string, - chainId: number, - module: string, -) { - const safe = new Contract(safeAddress, SafeAbi, provider) - return buildTransaction(safe, "enableModule", [module]) +export function enableModule(safeAddress: string, module: string) { + return buildTransaction(new Interface(SafeAbi), safeAddress, "enableModule", [module]) } export async function disableModule( @@ -440,7 +422,6 @@ export async function disableModule( const modules = await fetchSafeModulesAddress(provider, safeAddress, chainId) if (!modules.length) throw new Error("Safe does not have enabled modules") let prevModule = AddressOne - const safe = new Contract(safeAddress, SafeAbi, provider) if (modules.length > 1) { const moduleIndex = modules.findIndex((m) => m.toLowerCase() === module.toLowerCase()) if (moduleIndex > 0) prevModule = modules[moduleIndex - 1] @@ -448,7 +429,7 @@ export async function disableModule( const params = [prevModule, module] return { params, - ...buildTransaction(safe, "disableModule", params), + ...buildTransaction(new Interface(SafeAbi), safeAddress, "disableModule", params), } } @@ -502,33 +483,40 @@ export function deployRolesModifier( chainId: number, args: RolesModifierParams, ) { - const { target } = args - const { - transaction: rolesModifierDeploymentTx, - expectedModuleAddress: rolesModifierExpectedAddress, - } = deployAndSetUpModule( + const { target, multisend } = args + const { transaction: deployAndSetupTx, expectedModuleAddress: expectedRolesAddress } = + deployAndSetUpModule( + KnownContracts.ROLES, + { + types: ["address", "address", "address"], + values: [safeAddress, safeAddress, target], + }, + provider, + chainId, + Date.now().toString(), + ) + const enableModuleTx = enableModule(safeAddress, expectedRolesAddress) + + const rolesContract = getModuleInstance( KnownContracts.ROLES, - { - types: ["address", "address", "address"], - values: [safeAddress, safeAddress, target], - }, + expectedRolesAddress, provider, - chainId, - Date.now().toString(), ) - const enableRolesModifierTransaction = enableModule( - provider, - safeAddress, - chainId, - rolesModifierExpectedAddress, + + const setMultisendTx = buildTransaction( + rolesContract.interface, + rolesContract.address, + "setMultisend", + [multisend], ) return [ { - ...rolesModifierDeploymentTx, - value: rolesModifierDeploymentTx.value.toString(), + ...deployAndSetupTx, + value: String(deployAndSetupTx.value), }, - enableRolesModifierTransaction, + enableModuleTx, + setMultisendTx, ] } @@ -567,18 +555,16 @@ export function deployOptimisticGovernorModule( if (executor !== safeAddress) { const delayModule = getModuleInstance(KnownContracts.DELAY, executor, provider) - const addModuleTransaction = buildTransaction(delayModule, "enableModule", [ - daoModuleExpectedAddress, - ]) + const addModuleTransaction = buildTransaction( + delayModule.interface, + delayModule.address, + "enableModule", + [daoModuleExpectedAddress], + ) daoModuleTransactions.push(addModuleTransaction) } else { - const enableDaoModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - daoModuleExpectedAddress, - ) + const enableDaoModuleTransaction = enableModule(safeAddress, daoModuleExpectedAddress) daoModuleTransactions.push(enableDaoModuleTransaction) } diff --git a/packages/app/src/views/AddModule/wizards/CustomModule/CustomModuleModal.tsx b/packages/app/src/views/AddModule/wizards/CustomModule/CustomModuleModal.tsx index 41b42818..b1bfdd61 100644 --- a/packages/app/src/views/AddModule/wizards/CustomModule/CustomModuleModal.tsx +++ b/packages/app/src/views/AddModule/wizards/CustomModule/CustomModuleModal.tsx @@ -11,7 +11,7 @@ import { addTransaction } from "../../../../store/transactionBuilder" import { SafeAbi } from "../../../../services/helpers" import { serializeTransaction } from "../../../../store/transactionBuilder/helpers" import { ReactComponent as ArrowUpIcon } from "../../../../assets/icons/arrow-up-icon.svg" -import useSafeAppsSDKWithProvider from "hooks/useSafeAppsSDKWithProvider" +import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk" interface AddCustomModuleProps { open: boolean @@ -36,7 +36,7 @@ const useStyles = makeStyles((theme) => ({ })) export const CustomModuleModal = ({ onSubmit, open, onClose }: AddCustomModuleProps) => { - const { sdk, safe, provider } = useSafeAppsSDKWithProvider() + const { sdk, safe } = useSafeAppsSDK() const dispatch = useRootDispatch() const classes = useStyles() @@ -55,7 +55,7 @@ export const CustomModuleModal = ({ onSubmit, open, onClose }: AddCustomModulePr } const addModule = async () => { - const tx = enableModule(provider, safe.safeAddress, safe.chainId, moduleAddress) + const tx = enableModule(safe.safeAddress, moduleAddress) try { await sdk.txs.send({ txs: [tx] }) diff --git a/packages/app/src/views/AddModule/wizards/RealityModule/service/moduleDeployment.ts b/packages/app/src/views/AddModule/wizards/RealityModule/service/moduleDeployment.ts index 96c8de3d..b3fac09b 100644 --- a/packages/app/src/views/AddModule/wizards/RealityModule/service/moduleDeployment.ts +++ b/packages/app/src/views/AddModule/wizards/RealityModule/service/moduleDeployment.ts @@ -81,18 +81,16 @@ export async function deployRealityModule( if (executor !== safeAddress) { const delayModule = getModuleInstance(KnownContracts.DELAY, executor, provider) - const addModuleTransaction = buildTransaction(delayModule, "enableModule", [ - expectedModuleAddress, - ]) + const addModuleTransaction = buildTransaction( + delayModule.interface, + delayModule.address, + "enableModule", + [expectedModuleAddress], + ) daoModuleTransactions.push(addModuleTransaction) } else { - const enableDaoModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - expectedModuleAddress, - ) + const enableDaoModuleTransaction = enableModule(safeAddress, expectedModuleAddress) daoModuleTransactions.push(enableDaoModuleTransaction) } diff --git a/packages/app/src/views/AddModule/wizards/RealityModuleOld/services/moduleDeploymentOld.ts b/packages/app/src/views/AddModule/wizards/RealityModuleOld/services/moduleDeploymentOld.ts index 5f3966ba..e247f7a8 100644 --- a/packages/app/src/views/AddModule/wizards/RealityModuleOld/services/moduleDeploymentOld.ts +++ b/packages/app/src/views/AddModule/wizards/RealityModuleOld/services/moduleDeploymentOld.ts @@ -85,18 +85,16 @@ export function deployRealityModule( if (executor !== safeAddress) { const delayModule = getModuleInstance(KnownContracts.DELAY, executor, provider) - const addModuleTransaction = buildTransaction(delayModule, "enableModule", [ - daoModuleExpectedAddress, - ]) + const addModuleTransaction = buildTransaction( + delayModule.interface, + delayModule.address, + "enableModule", + [daoModuleExpectedAddress], + ) daoModuleTransactions.push(addModuleTransaction) } else { - const enableDaoModuleTransaction = enableModule( - provider, - safeAddress, - chainId, - daoModuleExpectedAddress, - ) + const enableDaoModuleTransaction = enableModule(safeAddress, daoModuleExpectedAddress) daoModuleTransactions.push(enableDaoModuleTransaction) } diff --git a/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx b/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx index 40245472..0444e3c4 100644 --- a/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx +++ b/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx @@ -23,6 +23,8 @@ const useStyles = makeStyles((theme) => ({ }, })) +const MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761" + export const RolesModifierModal = ({ open, onClose, @@ -34,9 +36,11 @@ export const RolesModifierModal = ({ const [errors, setErrors] = useState>({ target: true, + multisend: true, }) const [params, setParams] = useState({ target: safe.safeAddress, + multisend: MULTISEND_ADDRESS, }) const isValid = Object.values(errors).every((field) => field) @@ -90,6 +94,15 @@ export const RolesModifierModal = ({ onChange={(value, valid) => onParamChange("target", value, valid)} /> + + onParamChange("target", value, valid)} + /> + ) From 9e9758c278f8c38f6e9b90f879778f5c10f33030 Mon Sep 17 00:00:00 2001 From: cristovaoth Date: Tue, 1 Nov 2022 12:00:34 +0100 Subject: [PATCH 2/2] Getting the default multisend address from safe-deployments --- .../wizards/RolesModifier/RolesModifierModal.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx b/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx index 0444e3c4..936c564a 100644 --- a/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx +++ b/packages/app/src/views/AddModule/wizards/RolesModifier/RolesModifierModal.tsx @@ -5,6 +5,11 @@ import { deployRolesModifier, RolesModifierParams } from "services" import { ParamInput } from "../../../../components/ethereum/ParamInput" import { ParamType } from "@ethersproject/abi" import useSafeAppsSDKWithProvider from "hooks/useSafeAppsSDKWithProvider" +import { SafeInfo } from "@gnosis.pm/safe-apps-sdk" +import { + networkAddresses as multisendNetworkAddresses, + defaultAddress as defaultMultisendAddress, +} from "@gnosis.pm/safe-deployments/dist/assets/v1.3.0/multi_send.json" interface RolesModifierModalProps { open: boolean @@ -23,8 +28,6 @@ const useStyles = makeStyles((theme) => ({ }, })) -const MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761" - export const RolesModifierModal = ({ open, onClose, @@ -40,7 +43,7 @@ export const RolesModifierModal = ({ }) const [params, setParams] = useState({ target: safe.safeAddress, - multisend: MULTISEND_ADDRESS, + multisend: defaultMultisend(safe), }) const isValid = Object.values(errors).every((field) => field) @@ -107,3 +110,9 @@ export const RolesModifierModal = ({ ) } + +function defaultMultisend(safeInfo: SafeInfo) { + const address = (multisendNetworkAddresses as Record)[safeInfo.chainId] + + return address || defaultMultisendAddress +}