Skip to content

Commit

Permalink
Update list of markets and fix failure detection in test script
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 12, 2023
1 parent e220a1f commit 6370597
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 37 deletions.
92 changes: 80 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This repository contains smart contracts for the Aloe II Protocol.

## Bug Bounty

Contracts in this repository will soon be included in Aloe Labs' Immunefi bug bounty program. In the meantime,
if you find a critical vulnerability, please reach out to us on Discord.
Certain contracts in this repository are covered in Aloe Labs'
[Immunefi bug bounty program](https://immunefi.com/bounty/aloeprotocol/).

## Disclaimer

Expand All @@ -14,6 +14,8 @@ warranties** and **will not be liable for any loss incurred** through any use of

## Usage

This is just a snippet. See [here](https://github.com/aloelabs/aloe-ii-examples) for further examples.

```bash
forge install aloelabs/aloe-ii
```
Expand All @@ -23,15 +25,24 @@ import {Borrower, IManager} from "aloe-ii-core/Borrower.sol";
import {zip} from "aloe-ii-core/libraries/Positions.sol";
contract MyManager is IManager {
Borrower immutable account;
constructor(Borrower account_) {
account = account_;
}
function callback(bytes calldata data) external returns (uint144 positions) {
require(msg.sender == address(account));
/**
* @notice An example of what you can do with a `Borrower` - in this case,
* borrowing both pair assets and creating a Uniswap V3 position.
* @dev To trigger this callback, you'd create a `Borrower` and call
* `yourBorrower.modify(this, "", 1 << 32)`. Within this callback, you
* have full control of the `Borrower` and its assets.
* @param data Encoded parameters that were passed to `Borrower.modify`
* @param owner The owner of the `Borrower` (NOT to be trusted unless you verify that the caller
* is, in fact, a `Borrower` using `factory.isBorrower(msg.sender)`)
* @param positions The `Borrower`'s current Uniswap positions. You can convert them to an array using
* `Positions.extract`
* @return Updated positions, encoded using `Positions.zip`. Return 0 if you don't wish to make any changes.
*/
function callback(
bytes calldata data,
address owner,
uint208 positions
) external returns (uint208) {
account.borrow(1e18, 1500e6, msg.sender);
account.uniswapDeposit(202650, 202660, uint128(99999999));
Expand All @@ -40,6 +51,11 @@ contract MyManager is IManager {
}
```

> [!NOTE]
> For some reason, certain versions of Foundry fail to auto-detect our `solady`
> remapping. To fix this, add `'solady/=lib/aloe-ii/core/lib/solady/src'` to your
> remappings list in `foundry.toml`
## Contracts

```
Expand All @@ -55,20 +71,72 @@ libraries
|-- Constants -- "Defines important protocol parameters"
|-- Q -- "Defines Q numbers"
|-- BalanceSheet -- "Provides functions for computing a Borrower's health"
|-- Exp -- "Exponential function (e^x)"
|-- LiquidityAmounts -- "Translates liquidity to amounts or vice versa"
|-- Log2 -- "Logarithm and exponentiation in base 2"
|-- MulDiv -- "Multiply and divide with 512 bit precision"
|-- Oracle -- "Provides functions to integrate with Uniswap V3 oracle"
|-- Positions -- "Packs Uniswap positions into Borrower's storage efficiently"
|-- SafeCastLib
|-- Rewards -- "Implements logic for staking rewards"
|-- TickMath -- "Translates ticks to prices or vice versa"
|-- Volatility -- "Computes implied volatility from observed swap fee earnings"
```

## Development

We recommend the following extensions in VS Code:

- Solidity _by Nomic Foundation_
- Solidity Language & Themes _by tintinweb_
- TODO Highlight _by Wayou Liu_ (use custom settings to highlight "NOTE"s as well as "TODO"s)
- Coverage Gutters _by ryanluker_ (to see code coverage)
- SARIF Viewer _by Microsoft DevLabs_ (to see Slither output)

### Solidity

If you don't have Foundry installed, follow the instructions [here](https://book.getfoundry.sh/getting-started/installation).

```bash
git clone https://github.com/aloelabs/aloe-ii.git
cd aloe-ii
git submodule update --init --recursive

cd core # or periphery
forge build

# For gas snapshots (results in .gas-snapshot)
./snapshot.sh
# For storage layout (results in .storage-layout.md)
./layout.sh
# For gambit mutation testing
./gambit.sh
# For slither code analysis (run, then cmd+shift+p > SARIF: Show Panel)
./slither.sh
# For code coverage (run, then cmd+shift+p > Coverage Gutters: Display Coverage)
./test.sh
```

> [!NOTE]
> LiquidityAmounts.t.sol does differential testing using Python and `--ffi`. Borrower.t.sol uses tmux, anvil,
> and `--ffi` to do fuzz testing without burning through RPC credits. To avoid these and just run the basic
> test suite, use:
> ```bash
> forge test -vv --no-match-contract ".*Gas|BorrowerTest" --no-match-test "historical|Ffi"
> ```
### Linting
```bash
yarn install
yarn lint
```
### Documentation

Generated docs for master are available [here](https://aloelabs.github.io/aloe-ii/). If you want to build locally, you'll
need to [install mdBook](https://rust-lang.github.io/mdBook/guide/installation.html), then:

```bash
./docs.sh
mdbook serve docs
```
66 changes: 43 additions & 23 deletions core/script/CreateMarkets.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,75 @@ import "forge-std/Script.sol";

import {Factory, IUniswapV3Pool} from "../src/Factory.sol";

Factory constant FACTORY = Factory(0x0000000000000000000000000000000000000000);

contract CreateMarketsScript is Script {
address[] poolsMainnet = [
0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640, // USDC/WETH 0.05%
0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0, // WBTC/WETH 0.05%
0x3416cF6C708Da44DB2624D63ea0AAef7113527C6, // USDC/USDT 0.01%
0x11b815efB8f581194ae79006d24E0d814B7697F6, // WETH/USDT 0.05%
0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa, // wstETH/WETH 0.01%
0xa6Cc3C2531FdaA6Ae1A3CA84c2855806728693e8, // LINK/WETH 0.30%
0x60594a405d53811d3BC4766596EFD80fd545A270, // DAI/WETH 0.05%
0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168, // DAI/USDC 0.01%
0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35, // WBTC/USDC 0.30%
0xe8c6c9227491C0a8156A0106A0204d881BB7E531, // MKR/WETH 0.30%
0xa3f558aebAecAf0e11cA4b2199cC5Ed341edfd74, // LDO/WETH 0.30%
0x1d42064Fc4Beb5F8aAF85F4617AE8b3b5B8Bd801, // UNI/WETH 0.30%
0x290A6a7460B308ee3F19023D2D00dE604bcf5B42, // MATIC/WETH 0.30%
0xe42318eA3b998e8355a3Da364EB9D48eC725Eb45, // WETH/RPL 0.30%
0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF // APE/WETH 30%
];

address[] poolsOptimism = [
0x68F5C0A2DE713a54991E01858Fd27a3832401849, // WETH/OP
0xbf16ef186e715668AA29ceF57e2fD7f9D48AdFE6, // USDC/DAI
0x85149247691df622eaF1a8Bd0CaFd40BC45154a9, // WETH/USDC
0x4a5a2A152e985078e1A4AA9C3362c412B7dd0a86, // wstETH/WETH
0x03aF20bDAaFfB4cC0A521796a223f7D85e2aAc31, // WETH/DAI
0x73B14a78a0D396C521f954532d43fd5fFe385216, // WETH/WBTC
0x1C3140aB59d6cAf9fa7459C6f83D4B52ba881d36, // OP/USDC
0xF334F6104A179207DdaCfb41FA3567FEea8595C2, // WETH/LYRA
0x535541F1aa08416e69Dc4D610131099FA2Ae7222, // WETH/PERP
0x98D9aE198f2018503791D1cAf23c6807C135bB6b, // FRAX/USDC
0xAD4c666fC170B468B19988959eb931a3676f0e9F, // WETH/UNI
0xF1F199342687A7d78bCC16fce79fa2665EF870E1 // USDC/USDT
0x68F5C0A2DE713a54991E01858Fd27a3832401849, // WETH/OP 0.30%
0x85149247691df622eaF1a8Bd0CaFd40BC45154a9, // WETH/USDC 0.05%
0xF1F199342687A7d78bCC16fce79fa2665EF870E1, // USDC/USDT 0.01%
0x85C31FFA3706d1cce9d525a00f1C7D4A2911754c, // WETH/WBTC 0.05%
0xbf16ef186e715668AA29ceF57e2fD7f9D48AdFE6, // USDC/DAI 0.01%
0x1C3140aB59d6cAf9fa7459C6f83D4B52ba881d36, // OP/USDC 0.30%
0x535541F1aa08416e69Dc4D610131099FA2Ae7222 // WETH/PERP 0.30%
];

address[] poolsArbitrum = [
0x80A9ae39310abf666A87C743d6ebBD0E8C42158E, // WETH/GMX
0xC31E54c7a869B9FcBEcc14363CF510d1c41fa443, // WETH/USDC
0x27807dD7ADF218e1f4d885d54eD51C70eFb9dE50, // USDT/MIM
0x2f5e87C9312fa29aed5c179E456625D79015299c, // WBTC/WETH
0x2039f8c9cd32Ba9cD2Ea7e575d5B1ABeA93f7527, // GMX/USDC
0x7e7FB3CCEcA5F2ac952eDF221fd2a9f62E411980, // MAGIC/WETH
0x92c63d0e701CAAe670C9415d91C474F686298f00 // WETH/ARB
0xC31E54c7a869B9FcBEcc14363CF510d1c41fa443, // WETH/USDC.e 0.05%
0xC6962004f452bE9203591991D15f6b388e09E8D0, // WETH/USDC 0.05%
0xC6F780497A95e246EB9449f5e4770916DCd6396A, // WETH/ARB 0.05%
0xcDa53B1F66614552F834cEeF361A8D12a0B8DaD8 // ARB/USDC 0.05%
];

address[] poolsBase = [
0x10648BA41B8565907Cfa1496765fA4D95390aa0d // cbETH/WETH
0x4C36388bE6F416A29C8d8Eee81C771cE6bE14B18, // WETH/USDbC 0.05%
0x10648BA41B8565907Cfa1496765fA4D95390aa0d // cbETH/WETH 0.05%
];

function run() external {
vm.createSelectFork(vm.rpcUrl("mainnet"));
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
for (uint256 i = 0; i < poolsMainnet.length; i++) {
FACTORY.createMarket(IUniswapV3Pool(poolsMainnet[i]));
}
vm.stopBroadcast();

vm.createSelectFork(vm.rpcUrl("optimism"));
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
for (uint256 i = 0; i < poolsOptimism.length; i++) {
Factory(0x95110C9806833d3D3C250112fac73c5A6f631E80).createMarket(IUniswapV3Pool(poolsOptimism[i]));
FACTORY.createMarket(IUniswapV3Pool(poolsOptimism[i]));
}
vm.stopBroadcast();

vm.createSelectFork(vm.rpcUrl("arbitrum"));
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
for (uint256 i = 0; i < poolsArbitrum.length; i++) {
Factory(0x95110C9806833d3D3C250112fac73c5A6f631E80).createMarket(IUniswapV3Pool(poolsArbitrum[i]));
FACTORY.createMarket(IUniswapV3Pool(poolsArbitrum[i]));
}
vm.stopBroadcast();

vm.createSelectFork(vm.rpcUrl("base"));
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
for (uint256 i = 0; i < poolsBase.length; i++) {
Factory(0xA56eA45565478Fcd131AEccaB2FE934F23BAD8dc).createMarket(IUniswapV3Pool(poolsBase[i]));
FACTORY.createMarket(IUniswapV3Pool(poolsBase[i]));
}
vm.stopBroadcast();
}
Expand Down
10 changes: 8 additions & 2 deletions core/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ fi
# Run forge tests
if [ "$CHECK_FORGE_TESTS" = true ]; then
if [ "$CI" = true ]; then
forge test -vv --no-match-contract ".*Gas|BorrowerTest" --no-match-test "historical|Ffi"
(forge test -vv --no-match-contract ".*Gas|BorrowerTest" --no-match-test "historical|Ffi")
else
forge test -vv --no-match-contract ".*Gas" --no-match-test "historical|Ffi" --ffi
(forge test -vv --no-match-contract ".*Gas" --no-match-test "historical|Ffi" --ffi)
fi

tests_pass=$?
if [ "${tests_pass}" != "0" ]; then
echo "❌ forge tests failed" >> $GITHUB_STEP_SUMMARY
exit 1
fi

echo "✅ forge tests pass" >> $GITHUB_STEP_SUMMARY
Expand Down

0 comments on commit 6370597

Please sign in to comment.