From 3b455b565d9f87e13eedd1afcc96a5cf5d9d308b Mon Sep 17 00:00:00 2001 From: Nima Rasooli Date: Mon, 20 Jan 2025 21:39:11 +0400 Subject: [PATCH] docs: deployment guide --- ARCHITECTURE.md | 66 -------------------------------- deploy.sh | 16 -------- ir_manager/README.md | 90 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 82 deletions(-) delete mode 100644 ARCHITECTURE.md delete mode 100755 deploy.sh create mode 100644 ir_manager/README.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md deleted file mode 100644 index f0a5b07..0000000 --- a/ARCHITECTURE.md +++ /dev/null @@ -1,66 +0,0 @@ -# Architecture - -This document provides a high-level overview of the architecture of the BOLD Interest Rate Manager project, outlining the structure of the repository and the responsibilities of each major component. - -## Project Structure - -### 1. `assets/` -- **Contents**: Contains visual assets, such as diagrams and images. -- **Purpose**: This directory holds visual aids used in documentation, like the `Recharge_flow.png`, which illustrates the recharge flow of the system. - -### 2. `build.sh` -- **Purpose**: A shell script responsible for automating the build process of the project. It typically compiles the code, runs tests, and prepares the project for deployment. - -### 3. `Cargo.toml` -- **Purpose**: The main configuration file for Rust projects. It specifies the dependencies, project metadata, and build settings for the `ir_manager` Rust canister. - -### 4. `contracts/` -- **Purpose**: This directory contains the Solidity smart contracts used in the project. These contracts are integral to managing interactions on the Ethereum blockchain, particularly within the Liquity Protocol v2 ecosystem. - -#### Key Subdirectories and Files: -- **`foundry.toml`**: Configuration file for the Foundry toolchain, which is used for Solidity development and testing. -- **`remappings.txt`**: Defines import remappings, allowing the project to resolve Solidity dependencies correctly. -- **`script/`**: Contains deployment and interaction scripts, such as `Counter.s.sol`, which may be used for testing or initializing smart contracts. - -- **`src/`** - - **Purpose**: The primary source directory for the Solidity smart contracts. - - - **`BatchManager.sol`**: The main contract responsible for managing batches of operations related to the adjustment of interest rates and handling of Ethereum assets within the protocol. - - **`Dependencies/`**: Contains external contract interfaces like `AggregatorV3Interface.sol`, which are dependencies required by the main contracts. - - **`Interfaces/`**: Houses interfaces that define interactions with Liquity v2 smart contracts. These interfaces include contracts such as `IActivePool.sol`, `IBoldToken.sol`, `ITroveManager.sol`, and others that facilitate communication between the Batch Manager and the Liquity Protocol. - - **`Types/`**: Defines custom Solidity types used within the contracts, such as `BatchId.sol`, `LatestBatchData.sol`, `LatestTroveData.sol`, and `TroveChange.sol`. - -### 5. `dfx.json` -- **Purpose**: Configuration file for the DFINITY Internet Computer development environment. It defines settings for canister deployment, building, and managing Internet Computer projects. - -### 6. `fix_and_fmt.sh` -- **Purpose**: A shell script used to format and fix code issues in the project. - -### 7. `ir_manager/` -- **Purpose**: This directory contains the source code and configuration for the BOLD IR Manager canister. This canister runs on the Internet Computer and is responsible for managing interest rates, interacting with Ethereum, and handling other core functions. - -#### Key Files: -- **`candid.did`**: Defines the interface of the canister in the Candid language, which is used for specifying and interacting with Internet Computer services. -- **`Cargo.toml`**: The configuration file for the Rust project, specifying dependencies and settings specific to the IR Manager canister. - -- **`src/`** - - **Purpose**: Contains the Rust source code for the IR Manager canister. - - - **`canister.rs`**: The main file for canister-related logic, defining the core functionality and API exposed by the IR Manager canister. - - **`charger.rs`**: Manages the logic for recharging the canister's cycles and ckETH balance, ensuring that the canister has sufficient resources for ongoing operations. - - **`evm_rpc.rs`**: Handles communication with Ethereum via Remote Procedure Calls (RPC), facilitating transactions, balance checks, and other Ethereum interactions. - - **`exchange.rs`**: Contains DFINITY's exchange rates canister's types. - - **`gas.rs`**: Manages the gas estimation and usage for transactions. - - **`main.rs`**: The entry point for the canister, initializing the canister state and starting the main event loop. - - **`signer.rs`**: Implements tECDSA signature generation and signing logic, allowing the canister to securely authorize Ethereum transactions. - - **`state.rs`**: Manages the internal state of the canister, including tracking strategies and configuration settings. - - **`strategy.rs`**: Defines the strategies for adjusting interest rates, including the logic for evaluating and executing these strategies. - - **`types.rs`**: Defines custom types used within the Rust code, providing clear and structured data handling across the canister's logic. - - **`utils.rs`**: A utility module that provides common helper functions used across the canister's codebase. - -### 8. `README.md` -- **Purpose**: Provides an overview of the project, including the purpose, functionality, and usage instructions for the BOLD Interest Rate Manager. This file serves as the primary documentation for users and developers interacting with the project. - -## Summary - -The BOLD Interest Rate Manager project is organized into distinct directories and files that each play a critical role in the operation and management of interest rates within the Liquity Protocol v2. The `contracts` directory handles the Ethereum smart contract logic, while the `ir_manager` directory manages the Internet Computer canister responsible for interacting with these contracts and performing automated tasks. Scripts and configuration files like `build.sh`, `dfx.json`, and `Cargo.toml` ensure that the project is easy to build, deploy, and maintain. This architecture allows for a seamless integration between decentralized finance on Ethereum and the powerful computation capabilities of the Internet Computer. \ No newline at end of file diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index d326118..0000000 --- a/deploy.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -dfx canister start --ic ir_manager -dfx deploy --ic ir_manager --mode=reinstall - -MARKET_0_RATE=400100000000000000 -MARKET_1_RATE=780100000000000000 -MARKET_2_RATE=551000000000000000 - -dfx canister call --ic ir_manager mint_strategy 'record { key=0; manager="0x70fa06222e169329f7a2f386ed70ad69a61228a5"; rpc_principal=principal "7hfb6-caaaa-aaaar-qadga-cai"; hint_helper="0x71d43e3ce3c8c593773dd9b843e9db949384adc7"; collateral_index=0; multi_trove_getter="0xd55dbe705404242cda541390361ce28ce7f50b95"; upfront_fee_period=60840; target_min=500000000000000000; collateral_registry="0xec0f62913efa850bf7fab03663ef7364afa9e481" }' -dfx canister call --ic ir_manager mint_strategy 'record { key=1; manager="0x71aca0d1c8ad87ced23d5816c2988d8d8a912ac3"; rpc_principal=principal "7hfb6-caaaa-aaaar-qadga-cai"; hint_helper="0x71d43e3ce3c8c593773dd9b843e9db949384adc7"; collateral_index=1; multi_trove_getter="0xd55dbe705404242cda541390361ce28ce7f50b95"; upfront_fee_period=60840; target_min=500000000000000000; collateral_registry="0xec0f62913efa850bf7fab03663ef7364afa9e481" }' -dfx canister call --ic ir_manager mint_strategy 'record { key=2; manager="0xa8a2446696d9f3f49c39f020a5d6d34cbf3d81f4"; rpc_principal=principal "7hfb6-caaaa-aaaar-qadga-cai"; hint_helper="0x71d43e3ce3c8c593773dd9b843e9db949384adc7"; collateral_index=2; multi_trove_getter="0xd55dbe705404242cda541390361ce28ce7f50b95"; upfront_fee_period=60840; target_min=500000000000000000; collateral_registry="0xec0f62913efa850bf7fab03663ef7364afa9e481" }' -dfx canister call --ic ir_manager set_batch_manager "(0, \"0x9fAFA680723C09b7e06C7eC4e21A39377CCE8185\", $MARKET_0_RATE)" -dfx canister call --ic ir_manager set_batch_manager "(1, \"0x20a700e8c44067993905C4353472A4C69c26DD6c\", $MARKET_1_RATE)" -dfx canister call --ic ir_manager set_batch_manager "(2, \"0xF81b73cFfBb63811C95Ef0b2f25C057d23cBD053\", $MARKET_2_RATE)" - -dfx canister call --ic ir_manager start_timers \ No newline at end of file diff --git a/ir_manager/README.md b/ir_manager/README.md new file mode 100644 index 0000000..4cc90db --- /dev/null +++ b/ir_manager/README.md @@ -0,0 +1,90 @@ +# Interest Rate Manager Canister + +## Deployment Guide + +This guide outlines the steps required to deploy and configure the canister and associated batch managers. + +### Step 1: Deploy the Canister on ICP + +Use `dfx` to deploy the canister on the Internet Computer: + +```bash +dfx deploy --network ic +``` + +Ensure you have the correct canister ID and the canister is successfully deployed before proceeding. + +### Step 2: Mint Strategies in the Canister + +Mint a new strategy using the `mint_strategy` function. Replace the placeholders in the command with your strategy-specific values. + +```bash +dfx canister call ir_manager mint_strategy '( + { + key = ; + target_min = ; + manager = ""; + multi_trove_getter = ""; + collateral_index = ; + rpc_principal = principal ""; + upfront_fee_period = ; + collateral_registry = ""; + hint_helper = ""; + } +)' +``` + +Immediately after minting each strategy, a new Ethereum Externally Owned Account (EOA) address is generated. This address should be used as the `batch_manager_eoa` of the strategy in the subsequent steps. + +### Step 3: Deploy Batch Manager Contracts on Ethereum + +For each strategy, deploy a batch manager contract using Foundry. Replace the placeholders with appropriate values and use the EOA address generated after minting the strategy as `batch_manager_eoa`. + +```bash +forge create --rpc-url --private-key BatchManager --constructor-args \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + +``` + +Repeat this step for every strategy you need to configure. + + +### Step 4: Set Batch Manager Addresses for Strategies + +Set the Ethereum batch manager address for each minted strategy using the `set_batch_manager` function. + +```bash +dfx canister call ir_manager set_batch_manager '( + , + "", + +)' +``` + +Ensure this is done for all strategies minted in Step 2. + + +### Step 5: Start Timers + +Initialize the timers for strategy execution and maintenance tasks. + +```bash +dfx canister call ir_manager start_timers +``` + +This step ensures all system tasks are set up and ready to execute. + + +### Step 6: Blackhole the Canister + +Once all configurations are complete and the canister is operational, make it immutable by blackholing it. This step ensures that no further updates or changes can be made. \ No newline at end of file