Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
FOUNDRY_PROFILE: ci
ETH_RPC_URL: ${{secrets.ETH_RPC_URL}}

jobs:
check:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ remappings = [
fs_permissions = [{ access = "read", path = "./addresses/"}]

[fmt]
line_length = 80
line_length = 70

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

Expand Down
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-upgradeable
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@forge-proposal-simulator=lib/forge-proposal-simulator/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
5 changes: 0 additions & 5 deletions src/examples/01/REQUIREMENTS.md

This file was deleted.

File renamed without changes.
22 changes: 13 additions & 9 deletions src/proposals/sips/SIP00.sol → src/exercises/00/SIP00.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ pragma solidity ^0.8.0;

import {GovernorBravoProposal} from
"@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol";
import {Addresses} from "@forge-proposal-simulator/addresses/Addresses.sol";
import {Addresses} from
"@forge-proposal-simulator/addresses/Addresses.sol";

import {Vault} from "src/examples/00/Vault00.sol";
import {MockToken} from "@mocks/MockToken.sol";
import {Vault} from "src/exercises/00/Vault00.sol";
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";

/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/proposals/sips/SIP00.sol:SIP00 -vvvv
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/00/SIP00.sol:SIP00 -vvvv
contract SIP00 is GovernorBravoProposal {
using ForkSelector for uint256;

constructor() {
// ETHEREUM_FORK_ID.createForksAndSelect();
primaryForkId = ETHEREUM_FORK_ID;
}

Expand All @@ -32,7 +31,12 @@ contract SIP00 is GovernorBravoProposal {
return "SIP-00 System Deploy";
}

function description() public pure override returns (string memory) {
function description()
public
pure
override
returns (string memory)
{
return name();
}

Expand All @@ -45,20 +49,20 @@ contract SIP00 is GovernorBravoProposal {
}

function deploy() public override {
if (!addresses.isAddressSet("V1_VAULT")) {
if (!addresses.isAddressSet("V0_VAULT")) {
address[] memory tokens = new address[](3);
tokens[0] = addresses.getAddress("USDC");
tokens[1] = addresses.getAddress("DAI");
tokens[2] = addresses.getAddress("USDT");

Vault vault = new Vault(tokens);

addresses.addAddress("V1_VAULT", address(vault), true);
addresses.addAddress("V0_VAULT", address(vault), true);
}
}

function validate() public view override {
Vault vault = Vault(addresses.getAddress("V1_VAULT"));
Vault vault = Vault(addresses.getAddress("V0_VAULT"));

assertEq(
vault.authorizedToken(addresses.getAddress("USDC")),
Expand Down
4 changes: 3 additions & 1 deletion src/examples/00/Vault00.sol → src/exercises/00/Vault00.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ contract Vault {

totalSupplied += amount;

IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
IERC20(token).safeTransferFrom(
msg.sender, address(this), amount
);

emit Deposit(token, msg.sender, amount);
}
Expand Down
5 changes: 5 additions & 0 deletions src/exercises/01/REQUIREMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Overview

The first round of security reviews was conducted by an external security firm. The results were pretty bad for such a simple contract. They refused to give you the findings, so you're on your own.

Good luck...
82 changes: 82 additions & 0 deletions src/exercises/01/SIP01.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

import {GovernorBravoProposal} from
"@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol";
import {Addresses} from
"@forge-proposal-simulator/addresses/Addresses.sol";

import {Vault} from "src/exercises/01/Vault01.sol";
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";

/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/01/SIP01.sol:SIP01 -vvvv
contract SIP01 is GovernorBravoProposal {
using ForkSelector for uint256;

constructor() {
primaryForkId = ETHEREUM_FORK_ID;
}

function setupProposal() public {
ETHEREUM_FORK_ID.createForksAndSelect();

string memory addressesFolderPath = "./addresses";
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = 1;

setAddresses(new Addresses(addressesFolderPath, chainIds));
}

function name() public pure override returns (string memory) {
return "SIP-01 System Deploy";
}

function description()
public
pure
override
returns (string memory)
{
return name();
}

function run() public override {
setupProposal();

setGovernor(addresses.getAddress("COMPOUND_GOVERNOR_BRAVO"));

super.run();
}

function deploy() public override {
if (!addresses.isAddressSet("V1_VAULT")) {
address[] memory tokens = new address[](2);
tokens[0] = addresses.getAddress("USDC");
tokens[1] = addresses.getAddress("USDT");

Vault vault = new Vault(tokens);

addresses.addAddress("V1_VAULT", address(vault), true);
}
}

function validate() public view override {
Vault vault = Vault(addresses.getAddress("V1_VAULT"));

assertEq(
vault.authorizedToken(addresses.getAddress("USDC")),
true,
"USDC should be authorized"
);
assertEq(
vault.authorizedToken(addresses.getAddress("USDT")),
true,
"USDT should be authorized"
);
assertEq(
vault.authorizedToken(addresses.getAddress("DAI")),
true,
"DAI should be authorized"
);
}
}
File renamed without changes.
4 changes: 3 additions & 1 deletion src/examples/01/Vault01.sol → src/exercises/01/Vault01.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ contract Vault {

totalSupplied += normalizedAmount;

IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
IERC20(token).safeTransferFrom(
msg.sender, address(this), amount
);

emit Deposit(token, msg.sender, amount);
}
Expand Down
File renamed without changes.
93 changes: 93 additions & 0 deletions src/exercises/02/SIP02.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

import {GovernorBravoProposal} from
"@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol";
import {Addresses} from
"@forge-proposal-simulator/addresses/Addresses.sol";
import {
ProxyAdmin,
TransparentUpgradeableProxy,
ITransparentUpgradeableProxy
} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ERC1967Utils} from
"@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {Vault} from "src/exercises/02/Vault02.sol";
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";

/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/02/SIP02.sol:SIP02 -vvvv
contract SIP02 is GovernorBravoProposal {
using ForkSelector for uint256;

constructor() {
primaryForkId = ETHEREUM_FORK_ID;
}

function setupProposal() public {
ETHEREUM_FORK_ID.createForksAndSelect();

string memory addressesFolderPath = "./addresses";
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = 1;

setAddresses(new Addresses(addressesFolderPath, chainIds));
}

function name() public pure override returns (string memory) {
return "SIP-02 Upgrade";
}

function description()
public
pure
override
returns (string memory)
{
return name();
}

function run() public override {
setupProposal();

setGovernor(addresses.getAddress("COMPOUND_GOVERNOR_BRAVO"));

super.run();
}

function deploy() public override {
if (!addresses.isAddressSet("V2_VAULT")) {
address[] memory tokens = new address[](3);
tokens[0] = addresses.getAddress("USDC");
tokens[1] = addresses.getAddress("DAI");
tokens[2] = addresses.getAddress("USDT");

address owner = addresses.getAddress("DEPLOYER_EOA");

address vaultImpl = address(new Vault(tokens, owner));
addresses.addAddress("V2_VAULT", vaultImpl, true);
}
}

function validate() public view override {
Vault vault = Vault(addresses.getAddress("V2_VAULT"));

assertEq(
vault.authorizedToken(addresses.getAddress("USDC")),
true,
"USDC should be authorized"
);
assertEq(
vault.authorizedToken(addresses.getAddress("DAI")),
true,
"DAI should be authorized"
);
assertEq(
vault.authorizedToken(addresses.getAddress("USDT")),
true,
"USDT should be authorized"
);
}
}
File renamed without changes.
12 changes: 9 additions & 3 deletions src/examples/02/Vault02.sol → src/exercises/02/Vault02.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ contract Vault is Ownable {

/// @notice Construct the vault with a list of authorized tokens
/// @param _tokens The list of authorized tokens
constructor(address[] memory _tokens, address _owner) Ownable(_owner) {
constructor(address[] memory _tokens, address _owner)
Ownable(_owner)
{
for (uint256 i = 0; i < _tokens.length; i++) {
require(
IERC20Metadata(_tokens[i]).decimals() <= 18,
Expand All @@ -71,7 +73,9 @@ contract Vault is Ownable {
IERC20Metadata(token).decimals() <= 18,
"Vault: unsupported decimals"
);
require(!authorizedToken[token], "Vault: token already authorized");
require(
!authorizedToken[token], "Vault: token already authorized"
);

authorizedToken[token] = true;

Expand Down Expand Up @@ -100,7 +104,9 @@ contract Vault is Ownable {

totalSupplied += normalizedAmount;

IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
IERC20(token).safeTransferFrom(
msg.sender, address(this), amount
);

emit Deposit(token, msg.sender, amount);
}
Expand Down
3 changes: 3 additions & 0 deletions src/exercises/03/REQUIREMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Overview

Make the contract upgradeable while preserving all previous functionality. Users can migrate to this contract via opt-in by removing their liquidity from the previous contract and depositing here.
Loading