Skip to content

Commit

Permalink
feat - add contract devops/config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dvisacker committed Sep 29, 2024
1 parent 57edc3c commit 96615a5
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.env
.env
./contracts/broadcast/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "contracts/lib/foundry-devops"]
path = contracts/lib/foundry-devops
url = https://github.com/Cyfrin/foundry-devops
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ FORGE := forge
BINDINGS_DIR := bindings
CONTRACTS_DIR := contracts

# Environment variables (with default values)
MAINNET_RPC_URL ?= $(shell grep MAINNET_RPC_URL .env | cut -d '=' -f2)
ARBITRUM_RPC_URL ?= $(shell grep ARBITRUM_RPC_URL .env | cut -d '=' -f2)
PRIVATE_KEY ?= $(shell grep PRIVATE_KEY .env | cut -d '=' -f2)
DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
NETWORK_ARGS := --rpc-url http://localhost:8545 --private-key $(DEFAULT_ANVIL_KEY) --broadcast

# Rust commands
rust-build:
@echo "Building Rust bindings..."
Expand All @@ -30,10 +37,39 @@ sol-test:
@echo "Running Solidity tests..."
@cd $(CONTRACTS_DIR) && $(FORGE) test

# This command will generate an error (no cargo.toml) that can be ignored because we are generating the bindings in a subcrate of the src folder
sol-bind:
@echo "Generating Rust bindings for Solidity contracts..."
@cd $(CONTRACTS_DIR) && forge bind --alloy --bindings-path ../src/bindings --crate-name bindings --alloy-version 0.3.3 --module

deploy:
@echo "Deploying AaveLooper..."
@cd $(CONTRACTS_DIR) && forge script script/DeployAaveLooper.s.sol:DeployAaveLooper $(NETWORK_ARGS)

deploy_local:
@echo "Deploying AaveLooper on Local..."
NETWORK_ARGS := --rpc-url http://localhost:8545 --private-key $(DEFAULT_ANVIL_KEY) --broadcast
@cd $(CONTRACTS_DIR) && forge script script/DeployAaveLooper.s.sol:DeployAaveLooper $(NETWORK_ARGS)

deploy-sepolia:
@echo "Deploying AaveLooper on Sepolia..."
NETWORK_ARGS := --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
@cd $(CONTRACTS_DIR) && forge script script/DeployAaveLooper.s.sol:DeployAaveLooper $(NETWORK_ARGS)

deploy-arbitrum:
@echo "Deploying AaveLooper on Arbitrum..."
NETWORK_ARGS := --rpc-url $(ARBITRUM_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --arbiscan-api-key $(ARBISCAN_API_KEY) -vvvv
@cd $(CONTRACTS_DIR) && forge script script/DeployAaveLooper.s.sol:DeployAaveLooper $(NETWORK_ARGS)

deploy-mainnet:
j@echo "Deploying AaveLooper on Mainnet..."
NETWORK_ARGS := --rpc-url $(MAINNET_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
@cd $(CONTRACTS_DIR) && forge script script/DeployAaveLooper.s.sol:DeployAaveLooper $(NETWORK_ARGS)

enter-aave-position:
@echo "Entering Aave position..."
@cd $(CONTRACTS_DIR) && forge script script/EnterAavePosition.s.sol:EnterAavePosition $(NETWORK_ARGS)

# Combined commands
build: rust-build sol-build

Expand Down
1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ out/
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
/broadcast/

# Docs
docs/
Expand Down
5 changes: 5 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ src = "src"
out = "out"
libs = ["lib"]

fs_permissions = [
{ access = "read", path = "./broadcast"},
{ access = "read", path = "./reports"},
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions contracts/lib/foundry-devops
Submodule foundry-devops added at 47393d
37 changes: 37 additions & 0 deletions contracts/script/DeployAaveLooper.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Script} from "forge-std/Script.sol";
import {AaveLooper} from "../src/AaveLooper.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {console2} from "forge-std/console2.sol";

contract DeployAaveLooper is Script {
address owner;
address lendingPool;
address incentives;

function run() external {
HelperConfig helperConfig = new HelperConfig();
HelperConfig.NetworkConfig memory networkConfig = helperConfig.getActiveNetworkConfig();

owner = networkConfig.deployerAddress;
lendingPool = networkConfig.aaveLendingPool;
incentives = networkConfig.aaveIncentives;

require(owner != address(0), "Owner address not set");
require(lendingPool != address(0), "Lending Pool address not set");
require(incentives != address(0), "Incentives Controller address not set");

// Start broadcasting transactions
vm.startBroadcast();

// Deploy the AaveLooper contract
AaveLooper looper = new AaveLooper(owner, lendingPool, incentives);

console2.log("AaveLooper deployed at:", address(looper));

// Stop broadcasting transactions
vm.stopBroadcast();
}
}
34 changes: 34 additions & 0 deletions contracts/script/EnterAavePosition.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Script} from "forge-std/Script.sol";
import {AaveLooper} from "../src/AaveLooper.sol";
import {ERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {console2} from "forge-std/console2.sol";
import {DevOpsTools} from "../lib/foundry-devops/src/DevOpsTools.sol";
import {HelperConfig} from "./HelperConfig.s.sol";

contract EnterAavePosition is Script {
HelperConfig helperConfig = new HelperConfig();
address aaveLooper = DevOpsTools.get_most_recent_deployment("AaveLooper", block.chainid);
address supplyAsset;
address borrowAsset;
uint256 initialAmount;
uint256 iterations;

function run() external {
HelperConfig.NetworkConfig memory networkConfig = helperConfig.getActiveNetworkConfig();
supplyAsset = vm.envOr("SUPPLY_ASSET", networkConfig.usdc);
borrowAsset = vm.envOr("BORROW_ASSET", networkConfig.usdt);
initialAmount = vm.envOr("INITIAL_AMOUNT", uint256(1000000000000000000));
iterations = vm.envOr("ITERATIONS", uint256(1));
AaveLooper looper = AaveLooper(aaveLooper);

vm.startBroadcast();
ERC20(supplyAsset).approve(aaveLooper, initialAmount);
uint256 liquidity = looper.enterPosition(supplyAsset, borrowAsset, initialAmount, iterations);
vm.stopBroadcast();

console2.log("Entered position. Final liquidity:", liquidity);
}
}
68 changes: 68 additions & 0 deletions contracts/script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Script} from "forge-std/Script.sol";
import {AaveLooper} from "../src/AaveLooper.sol";
import {console2} from "forge-std/console2.sol";

contract HelperConfig is Script {
NetworkConfig public activeNetworkConfig;

struct NetworkConfig {
uint256 deployerKey;
address deployerAddress;
address aaveLendingPool;
address aaveIncentives;
address usdc;
address usdt;
address dai;
address weth;
}

constructor() {
if (block.chainid == 42161) {
uint256 deployerKey = vm.envUint("PRIVATE_KEY");
activeNetworkConfig = NetworkConfig({
deployerKey: deployerKey,
deployerAddress: vm.addr(deployerKey),
aaveLendingPool: 0x794a61358D6845594F94dc1DB02A252b5b4814aD,
aaveIncentives: 0x929EC64c34a17401F460460D4B9390518E5B473e,
usdc: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831,
usdt: 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9,
dai: 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1,
weth: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
});
} else if (block.chainid == 1) {
uint256 deployerKey = vm.envUint("PRIVATE_KEY");
activeNetworkConfig = NetworkConfig({
deployerKey: deployerKey,
deployerAddress: vm.addr(deployerKey),
aaveLendingPool: 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9,
aaveIncentives: 0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb,
usdc: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
usdt: 0xdAC17F958D2ee523a2206206994597C13D831ec7,
dai: 0x6B175474E89094C44Da98b954EedeAC495271d0F,
weth: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
});
// sepolia
} else if (block.chainid == 11155111) {
uint256 deployerKey = vm.envUint("PRIVATE_KEY");
activeNetworkConfig = NetworkConfig({
deployerKey: deployerKey,
deployerAddress: vm.addr(deployerKey),
aaveLendingPool: 0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951,
aaveIncentives: 0x4DA5c4da71C5a167171cC839487536d86e083483,
usdc: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8,
usdt: 0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0,
dai: 0xFF34B3d4Aee8ddCd6F9AFFFB6Fe49bD371b8a357,
weth: 0xC558DBdd856501FCd9aaF1E62eae57A9F0629a3c
});
} else {
revert("Unsupported network");
}
}

function getActiveNetworkConfig() public view returns (NetworkConfig memory) {
return activeNetworkConfig;
}
}
2 changes: 2 additions & 0 deletions contracts/src/IAggregatorContractV5.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pragma solidity ^0.8.26;

import "../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "../lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

Expand Down
12 changes: 12 additions & 0 deletions src/addressbook.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"arbitrum": {
"aave_lending_pool": "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
"aave_incentives": "0x929EC64c34a17401F460460D4B9390518E5B473e",
"tokens": {
"USDC": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
"USDT": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
Expand All @@ -10,11 +11,22 @@
},
"mainnet": {
"aave_lending_pool": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9",
"aave_incentives": "0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb",
"tokens": {
"USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
}
},
"sepolia": {
"aave_lending_pool": "0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951",
"aave_incentives": "0x4DA5c4da71C5a167171cC839487536d86e083483",
"tokens": {
"USDC": "0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8",
"DAI": "0xFF34B3d4Aee8ddCd6F9AFFFB6Fe49bD371b8a357",
"USDT": "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0",
"WETH": "0xC558DBdd856501FCd9aaF1E62eae57A9F0629a3c"
}
}
}

0 comments on commit 96615a5

Please sign in to comment.