|
1 |
| -## Smart Contract Infrastructure |
| 1 | +# Smart Contract Infrastructure |
| 2 | + |
| 3 | +This repository provides the deployment scripts and tooling for smart contracts and governance processes. It covers |
| 4 | +one-off deploys (via Foundry) for core contracts—such as the token allowlist, CoWSwapGuard, and TradingModule |
| 5 | +mastercopy—as well as day-to-day operations for users and agents. |
| 6 | + |
| 7 | +## Getting Started |
| 8 | + |
| 9 | +1. **Install dependencies:** |
| 10 | + |
| 11 | + ```bash |
| 12 | + bun i |
| 13 | + ``` |
| 14 | + |
| 15 | +2. **Compile Smart Contracts:** |
| 16 | + |
| 17 | + ```bash |
| 18 | + bun run build |
| 19 | + ``` |
| 20 | + |
| 21 | +## Smart Contracts Overview |
| 22 | + |
| 23 | +- **TokenAllowlist ([TokenAllowlist.sol](./src/TokenAllowlist.sol)):** |
| 24 | + Enables the contract owner to manage a list of approved tokens. It provides functions to add or remove tokens and |
| 25 | + check if a token is allowed, ensuring that trading is confined to community-vetted assets. |
| 26 | + |
| 27 | +- **TradingModule ([TradingModule.sol](./src/TradingModule.sol)):** |
| 28 | + A Zodiac Guardable Module that allows an AI trading agent to transact on behalf of a Safe. It enforces trading rules |
| 29 | + by verifying that only tokens on the allowlist are used and that trades execute exclusively on CoWSwap. Additionally, |
| 30 | + it sets a pre-signature on orders to make them tradeable and includes a pause mechanism—letting the owner disable |
| 31 | + trading when needed. |
| 32 | + |
| 33 | +- **CoWSwapGuard ([CoWSwapGuard.sol](./src/CoWSwapGuard.sol)):** |
| 34 | + Implements guard checks to ensure that trades adhere to community-defined rules. It restricts trading to approved |
| 35 | + token pairs and parameters, acting as an additional security layer to prevent unauthorized or unsafe trading actions. |
| 36 | + |
| 37 | +## Deployment Overview |
| 38 | + |
| 39 | +### Foundry Deploy Scripts (One-Off Deploys) |
| 40 | + |
| 41 | +These scripts deploy core contracts per chain. For example, on Gnosis Chain, the following addresses have been deployed: |
| 42 | + |
| 43 | +- **Allowlist:** `0xE0CBa604f8be035a80D21b49C67BdcE59Bba9d76` |
| 44 | +- **Guard:** `0xF67966246d72fC124d19B7F2d03DD690B756De88` |
| 45 | +- **TradingModule MasterCopy:** `0xDdd11DC80A25563Cb416647821f3BC5Ad75fF1BA` |
| 46 | + |
| 47 | +Foundry deploy scripts include: |
| 48 | + |
| 49 | +- `script/01_Deploy_Allowlist.s.sol` |
| 50 | +- `script/02_Deploy_CoWSwapGuard.s.sol` |
| 51 | +- `script/03_Deploy_MasterCopy.s.sol` |
| 52 | + |
| 53 | +**Token Configuration Script:** |
| 54 | + |
| 55 | +- `script/01A_AddTokens_Allowlist.s.sol` |
| 56 | + This script configures the allowlist with the GNO, WXDAI, and COW tokens. |
| 57 | + |
| 58 | +### Bun Deploy Scripts for Users/Agents |
| 59 | + |
| 60 | +These scripts provide two deployment options: |
| 61 | + |
| 62 | +- **Bring Your Own (BYO) Safe and TradingModule Proxy:** If you already have a Safe and proxy deployed, set the required |
| 63 | + environment variables and run: |
| 64 | + |
| 65 | + ```bash |
| 66 | + bun run script/safe/module-config.ts |
| 67 | + bun run script/safe/enable-module.ts |
| 68 | + ``` |
| 69 | + |
| 70 | + These commands will: |
| 71 | + |
| 72 | + - Enable the module on your existing Safe. |
| 73 | + - Configure the module by setting the required guard. |
| 74 | + - Register your account (private key) as an allowed trader. |
| 75 | + |
| 76 | +- **Deploy a New Safe and TradingModule Proxy:** If you don't have a Safe and TradingModule already deployed, run: |
| 77 | + ```bash |
| 78 | + bun run script/safe/deploy-all.ts |
| 79 | + ``` |
| 80 | + This deploys a new Safe, a new TradingModule proxy, and then automatically configures them as above. |
| 81 | + |
| 82 | +## Additional Information |
| 83 | + |
| 84 | +- **Configuration Files:** |
| 85 | + This repo includes configuration files for Prettier, Solhint, Foundry, and others to streamline development and |
| 86 | + deployment. |
| 87 | + |
| 88 | +- **Contract Address Resolution:** |
| 89 | + Contract addresses can be configured through environment variables. If not set, the scripts will default to values |
| 90 | + from the deployments (Foundry) configuration. |
| 91 | + |
| 92 | +## Safety |
| 93 | + |
| 94 | +This software is experimental and provided on an "as-is" and "as available" basis. The team makes no warranties, express |
| 95 | +or implied, and will not be liable for any losses or damages incurred through its use. It is crucial that you perform |
| 96 | +your own thorough tests to ensure compatibility and correct behavior with your code. |
| 97 | + |
| 98 | +## Future Work |
| 99 | + |
| 100 | +- Develop a helper script to build Tenderly transactions for the CoW DAO Governance mechanism. |
| 101 | +- Implement a comprehensive test suite based on the Branching Tree Technique |
| 102 | + ([BTT](https://github.com/paulber19/branching-tree-testing)). |
0 commit comments