contract-proxy-kit
contract-proxy-kit copied to clipboard
Allow creation and setup of modules on proxy deployment.
Some applications (like Gelato) require to send transactions on behalf of the user under certain conditions. This can be done by deploying and registering Safe modules. The CPK should allow developers to easily add the required transactions to the deployment transaction. An example should be added to the documentation.
Copying over a convo I had with a user on our Discord about this with some notes
... [The tests for normal recovery modules use] the to and data params in the setup method of the Safe to make a delegatecall to the CreateAndAddModules "library" (really a contract which is intended to be delegatecalled and not directly called), which then executes the constructor bytecode of the module, deploying the module (where the deployer is the Safe and not the library), and then calls enableModule while executing as the Safe with the newly created module.
You have a couple of options. If your module is modeled after the example recovery modules, then with the CPK, you can essentially achieve the same thing using execTransactions, with the operation being a CPK.DELEGATECALL, to being the address of the CreateAndAddModules library, and data being analogous to createAndAddModulesData in the tests.
There are some modules which have a different architecture where they actually have a "global" module instance which is shared by all Safes. If your module follows this pattern, or if you have already a module deployed somewhere that you want to use directly, or if you just want to use a different deployment flow, you can execTransactions with a normal CPK.CALL, except to is the address of the proxy itself cpk.address, and data is the encoded calldata for a call to enableModule.
Fundamentally, you will want to have an instance of a Module, and you will also want to enableModule that module. You could potentially do construction and enableModule-ing of multiple modules with the CreateAndAddModules library, but you don't need to use that library.