This repository contains an optimized workflow for data retrieval, fund allocation, and interaction with the MetaMorpho Protocol. It comprises Python scripts and Solidity files to fetch on-chain data, simulate vault allocations, deploy smart contracts on a mainnet fork, and securely interact with the blockchain.
File: main.py
This script:
- Fetches data from the Morpho API.
- Stores data in a local SQL server.
- Simulates fund allocation (starting with 1 million USD).
- Uses linear programming to optimize fund distribution across vaults.
- Integrates risk management strategies to avoid high-risk allocations.
Setup and Execution:
- Create a Python virtual environment:
python -m venv myenv
- Activate the environment:
source myenv/bin/activate
- Install required dependencies:
pip install -r requirements.txt
- Run the script:
python script/main.py
File: DeployMetaMorpho.s.sol
This script uses Foundry to:
- Call a contract Factory on a forked mainnet.
- Interact with the deployed MetaMorpho USDC Vault.
- Display transaction logs and details.
Setup and Execution:
- Fork the mainnet using your RPC URL:
anvil --fork-url https://mainnet.infura.io/v3/$INFURA_KEY
- Deploy the script:
forge script script/DeployMetaMorpho.s.sol:DeployMetaMorpho --fork-url https://mainnet.infura.io/v3/$INFURA_KEY --broadcast
File: Scripter.py
This script connects to the forked chain via Web3.py to:
- Ensure the chain is ready for transactions.
- Simulate a transaction to verify functionality.
- Send a signed transaction to the forked mainnet.
Setup and Execution:
- Complete the deployment step above.
- Run the script:
python script/Scripter.py
- Echidna Fuzz Testing:
EchidnaMorphoTest.sol
ensures thereallocate
function in MetaMorpho.sol is secure.
- Static Analysis:
- Security report generated using Cyfrin Aderyn static analyzer to validate contract security (see
report.md
).
- Security report generated using Cyfrin Aderyn static analyzer to validate contract security (see
script/main.py
: Python-based data pipeline and fund allocation.script/DeployMetaMorpho.s.sol
: Solidity script for mainnet fork deployment.script/Scripter.py
: Python script for Web3 interaction.script/EchidnaMorphoTest.sol
: Echidna test file for contract security.report.md
: Security analysis report.requirements.txt
: Python dependencies.
- Python 3.x
- Foundry (for mainnet fork and deployment)
- Morpho API
- Web3.py
- PuLP (for linear programming)
Install dependencies using:
pip install -r requirements.txt
- Setup the local environment or fork the mainnet as described above.
- Run the Python scripts and Foundry commands to simulate transactions.
- Review logs and transaction outputs to verify success.
- Make sure to replace
$INFURA_KEY
with your actual Infura API key. - The project has been tested with dummy data for demonstration purposes.
- Refer to the security report for detailed contract analysis.
- Advanced reallocation strategies.
- Frontend for visualization.
- Additional Foundry unit tests with coverage reports.
$ forge --help
$ anvil --help
$ cast --help