-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
marczeller
committed
Jul 21, 2024
1 parent
3f1981f
commit 1cba80a
Showing
8 changed files
with
310 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Private key (NEVER COMMIT YOUR PRIVATE KEY FRENS) | ||
PRIVATE_KEY=your_private_key_here | ||
SENDER=YOUR_ADDRESS | ||
|
||
# RPC Endpoints (Replace with your own endpoints if necessary) | ||
RPC_MAINNET=http://your_mainnet_rpc_endpoint | ||
RPC_AVALANCHE=https://api.avax.network/ext/bc/C/rpc | ||
RPC_OPTIMISM=https://opt-mainnet.g.alchemy.com/v2/your_alchemy_key | ||
RPC_POLYGON=https://polygon-mainnet.g.alchemy.com/v2/your_alchemy_key | ||
RPC_ARBITRUM=https://arb-mainnet.g.alchemy.com/v2/your_alchemy_key | ||
RPC_FANTOM=https://rpc.ftm.tools | ||
RPC_HARMONY=https://api.harmony.one | ||
RPC_METIS=https://andromeda.metis.io/?owner=1088 | ||
RPC_BASE=https://base-mainnet.g.alchemy.com/v2/your_alchemy_key | ||
RPC_GNOSIS=https://rpc.ankr.com/gnosis/your_ankr_key | ||
RPC_BNB=https://your_bnb_rpc_endpoint | ||
RPC_SCROLL=https://scroll.blockpi.network/v1/rpc/public | ||
|
||
# Pool Addresses | ||
# Mainnet pools | ||
MAINNET_MAIN_POOL=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 | ||
MAINNET_LIDO_POOL=0x4e033931ad43597d96D6bcc25c280717730B58B1 | ||
|
||
# Other network pools | ||
AVALANCHE_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
OPTIMISM_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
POLYGON_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
ARBITRUM_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
FANTOM_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
HARMONY_MAIN_POOL=0x794a61358D6845594F94dc1DB02A252b5b4814aD | ||
METIS_MAIN_POOL=0x90df02551bB792286e8D4f13E0e357b4Bf1D6a57 | ||
BASE_MAIN_POOL=0xA238Dd80C259a72e81d7e4664a9801593F98d1c5 | ||
GNOSIS_MAIN_POOL=0xb50201558B00496A145fE76f7424749556E326D8 | ||
BNB_MAIN_POOL=0x6807dc923806fE8Fd134338EABCA509979a7e0cB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
# Compiler files | ||
# Environment variables | ||
.env | ||
|
||
# Foundry build artifacts | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
# Logs | ||
logs/ | ||
|
||
# Docs | ||
docs/ | ||
# Node modules (if you're using any npm packages) | ||
node_modules/ | ||
|
||
# Dotenv file | ||
.env | ||
# MacOS system files | ||
.DS_Store | ||
|
||
# Editor files | ||
*.swp | ||
*.swo | ||
.vscode/ | ||
.idea/ | ||
|
||
# Temporary files | ||
*.tmp | ||
*.temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Makefile for Dolce Vita Collector | ||
|
||
include .env | ||
|
||
# Scripts | ||
FETCH_RESERVES_SCRIPT := script/FetchReserves.s.sol | ||
MINT_TO_TREASURY_SCRIPT := script/MintToTreasury.s.sol | ||
|
||
# Log directory | ||
LOG_DIR := ./logs | ||
|
||
# Determine if it's a dry run | ||
ifneq ($(dry),) | ||
PRIVATE_KEY_ARG := --sender 0x3Cbded22F878aFC8d39dCD744d3Fe62086B76193 | ||
EXTRA_ARGS := -vvvv | ||
else | ||
PRIVATE_KEY_ARG := --private-key ${PRIVATE_KEY} | ||
EXTRA_ARGS := --broadcast -vvvv | ||
endif | ||
|
||
.PHONY: fetch-reserves mint-to-treasury run-all clean | ||
|
||
$(LOG_DIR): | ||
@mkdir -p $(LOG_DIR) | ||
|
||
fetch-reserves: $(LOG_DIR) | ||
@echo "Fetching reserves list for all networks..." | ||
@forge script ${FETCH_RESERVES_SCRIPT} -vvvv | ||
|
||
mint-to-treasury: $(LOG_DIR) | ||
@echo "Minting to treasury on ${NETWORK} ${POOL}..." | ||
@RESERVES=$$(cat $(LOG_DIR)/reserves.json); \ | ||
NETWORK=${NETWORK} POOL=${POOL} forge script ${MINT_TO_TREASURY_SCRIPT} \ | ||
--sig "run(string)" "$$RESERVES" \ | ||
--rpc-url ${RPC_${NETWORK}} \ | ||
${PRIVATE_KEY_ARG} \ | ||
${EXTRA_ARGS} | ||
|
||
run-all: fetch-reserves | ||
@echo "Running mint-to-treasury for all networks and pools with reserves..." | ||
@RESERVES=$$(cat $(LOG_DIR)/reserves.json); \ | ||
for network in $$(echo "$$RESERVES" | jq -r 'keys[]'); do \ | ||
for pool in $$(echo "$$RESERVES" | jq -r ".[\"$$network\"] | keys[]"); do \ | ||
echo "Processing $$network $$pool"; \ | ||
$(MAKE) mint-to-treasury NETWORK=$$network POOL=$$pool; \ | ||
done; \ | ||
done | ||
|
||
clean: | ||
@rm -rf $(LOG_DIR) broadcast cache out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,48 @@ | ||
## Foundry | ||
# ACI's Dolce Vita Collector | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
This project automates the process of minting to treasury for various Aave Pools across multiple networks. | ||
|
||
Foundry consists of: | ||
## Setup | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
1. Clone the repository: | ||
``` | ||
git clone https://github.com/yourusername/dolce_vita_collector.git | ||
cd dolce_vita_collector | ||
``` | ||
|
||
## Documentation | ||
2. Install Foundry if you haven't already: | ||
``` | ||
curl -L https://foundry.paradigm.xyz | bash | ||
foundryup | ||
``` | ||
|
||
https://book.getfoundry.sh/ | ||
3. Copy `.env.example` to `.env` and fill in your private key and any other necessary details: | ||
``` | ||
cp .env.example .env | ||
``` | ||
|
||
## Usage | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
|
||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
|
||
### Format | ||
4. Build the project: | ||
``` | ||
forge build | ||
``` | ||
|
||
```shell | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Snapshots | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
|
||
### Anvil | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
|
||
### Deploy | ||
## Usage | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
- To fetch reserves for all networks: | ||
``` | ||
make fetch-reserves | ||
``` | ||
|
||
### Cast | ||
- To mint to treasury for a specific network and pool: | ||
``` | ||
make mint-to-treasury NETWORK=MAINNET POOL=MAIN | ||
``` | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
- To run the entire process (fetch reserves and mint for all networks): | ||
``` | ||
make run-all | ||
``` | ||
|
||
### Help | ||
## License | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` | ||
This project is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
interface IPool { | ||
function getReservesList() external view returns (address[] memory); | ||
} | ||
|
||
struct NetworkConfig { | ||
string name; | ||
string[] poolNames; | ||
} | ||
|
||
contract FetchReservesScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
NetworkConfig[] memory networks = getNetworkConfigs(); | ||
|
||
string memory jsonOutput = "{"; | ||
string memory logContent = ""; | ||
bool isFirstNetwork = true; | ||
|
||
for (uint i = 0; i < networks.length; i++) { | ||
NetworkConfig memory network = networks[i]; | ||
string memory rpc = vm.envString(string(abi.encodePacked("RPC_", network.name))); | ||
|
||
if (!isFirstNetwork) jsonOutput = string(abi.encodePacked(jsonOutput, ",")); | ||
isFirstNetwork = false; | ||
jsonOutput = string(abi.encodePacked(jsonOutput, '"', network.name, '":{')); | ||
|
||
bool isFirstPool = true; | ||
for (uint j = 0; j < network.poolNames.length; j++) { | ||
string memory poolName = network.poolNames[j]; | ||
address poolAddress = vm.envAddress(string(abi.encodePacked(network.name, "_", poolName, "_POOL"))); | ||
|
||
logContent = string(abi.encodePacked(logContent, "Fetching reserves for ", network.name, " ", poolName, "\n")); | ||
|
||
try vm.createSelectFork(rpc) returns (uint256) { | ||
IPool pool = IPool(poolAddress); | ||
address[] memory reserves; | ||
|
||
try pool.getReservesList() returns (address[] memory _reserves) { | ||
reserves = _reserves; | ||
if (reserves.length > 0) { | ||
logContent = string(abi.encodePacked(logContent, "Successfully fetched ", vm.toString(reserves.length), " reserves for ", network.name, " ", poolName, "\n")); | ||
|
||
if (!isFirstPool) jsonOutput = string(abi.encodePacked(jsonOutput, ",")); | ||
isFirstPool = false; | ||
jsonOutput = string(abi.encodePacked(jsonOutput, '"', poolName, '":[')); | ||
for (uint k = 0; k < reserves.length; k++) { | ||
if (k > 0) jsonOutput = string(abi.encodePacked(jsonOutput, ",")); | ||
jsonOutput = string(abi.encodePacked(jsonOutput, '"', vm.toString(reserves[k]), '"')); | ||
} | ||
jsonOutput = string(abi.encodePacked(jsonOutput, "]")); | ||
} else { | ||
logContent = string(abi.encodePacked(logContent, "No reserves found for ", network.name, " ", poolName, ". Skipping.\n")); | ||
} | ||
} catch { | ||
logContent = string(abi.encodePacked(logContent, "Failed to fetch reserves for ", network.name, " ", poolName, "\n")); | ||
} | ||
} catch { | ||
logContent = string(abi.encodePacked(logContent, "Failed to connect to ", network.name, " RPC\n")); | ||
} | ||
} | ||
jsonOutput = string(abi.encodePacked(jsonOutput, "}")); | ||
} | ||
|
||
jsonOutput = string(abi.encodePacked(jsonOutput, "}")); | ||
|
||
// Write JSON output to file | ||
vm.writeFile("./logs/reserves.json", jsonOutput); | ||
|
||
// Write log to file | ||
vm.writeFile("./logs/fetch_reserves_detail.log", logContent); | ||
|
||
console.log("Reserves fetched and written to ./logs/reserves.json"); | ||
console.log("Detailed log written to ./logs/fetch_reserves_detail.log"); | ||
} | ||
|
||
function getNetworkConfigs() internal pure returns (NetworkConfig[] memory) { | ||
NetworkConfig[] memory configs = new NetworkConfig[](11); | ||
|
||
string[] memory mainnetPools = new string[](2); | ||
mainnetPools[0] = "MAIN"; | ||
mainnetPools[1] = "LIDO"; | ||
configs[0] = NetworkConfig("MAINNET", mainnetPools); | ||
|
||
string[] memory singlePool = new string[](1); | ||
singlePool[0] = "MAIN"; | ||
|
||
configs[1] = NetworkConfig("AVALANCHE", singlePool); | ||
configs[2] = NetworkConfig("OPTIMISM", singlePool); | ||
configs[3] = NetworkConfig("POLYGON", singlePool); | ||
configs[4] = NetworkConfig("ARBITRUM", singlePool); | ||
configs[5] = NetworkConfig("FANTOM", singlePool); | ||
configs[6] = NetworkConfig("HARMONY", singlePool); | ||
configs[7] = NetworkConfig("METIS", singlePool); | ||
configs[8] = NetworkConfig("BASE", singlePool); | ||
configs[9] = NetworkConfig("GNOSIS", singlePool); | ||
configs[10] = NetworkConfig("BNB", singlePool); | ||
|
||
return configs; | ||
} | ||
} |
Oops, something went wrong.