The implementation could roughly look as follows:
- When calling magic("Do something") (ignore the function names), this will use ffi to run a script that uses an AI to generate a Solidity smart contract, it will compile it and return its bytecode. Then, the function will also deploy the bytecode and perform a delegatecall to it so that everything is done in the context of the caller.
- The contract generated by the AI needs to have a fallback function where everything happens (the delegatecall will use empty data). We can also have a template contract with a bunch of stuff that would be available to the generated contract, such as hevm opcodes, common interfaces, etc, and we would inform this to the model.