Skip to content

Commit d310379

Browse files
Simple Rebalance + Tests (#2)
Rebalancing logic + test restructuring. --------- Co-authored-by: Alex Towle <[email protected]>
1 parent 19b062f commit d310379

34 files changed

+1503
-365
lines changed

Diff for: .env.sample

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MAINNET_RPC_URL=
2+
SEPOLIA_RPC_URL=

Diff for: .github/workflows/coverage.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Code Coverage
2+
3+
on:
4+
pull_request:
5+
merge_group:
6+
7+
jobs:
8+
coverage:
9+
name: coverage
10+
runs-on: ubuntu-latest
11+
env:
12+
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
13+
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
submodules: recursive
18+
19+
- name: Install Foundry
20+
uses: foundry-rs/foundry-toolchain@v1
21+
with:
22+
version: nightly
23+
cache: false
24+
25+
- name: forge version
26+
run: forge --version
27+
28+
- name: Run coverage
29+
run: |
30+
make coverage
31+
sudo apt-get install lcov
32+
lcov --remove lcov.info -o lcov.info 'test/*' 'script/*'
33+
34+
- name: Edit lcov.info
35+
run: |
36+
cat lcov.info | sed '/.*\/test\/.*/,/TN:/d' > tmp.info && mv tmp.info lcov.info
37+
38+
- name: Coveralls
39+
uses: coverallsapp/github-action@v2
40+
with:
41+
path-to-lcov: "./lcov.info"
42+
parallel: true
43+
44+
finish:
45+
needs: coverage
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Coveralls Finished
49+
uses: coverallsapp/github-action@v2
50+
with:
51+
parallel-finished: true

Diff for: .github/workflows/test.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: test
22

3-
on: workflow_dispatch
3+
on:
4+
pull_request:
5+
merge_group:
46

57
env:
68
FOUNDRY_PROFILE: ci
@@ -9,7 +11,9 @@ jobs:
911
check:
1012
strategy:
1113
fail-fast: true
12-
14+
env:
15+
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
16+
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
1317
name: Foundry project
1418
runs-on: ubuntu-latest
1519
steps:
@@ -24,11 +28,10 @@ jobs:
2428

2529
- name: Run Forge build
2630
run: |
27-
forge --version
28-
forge build --sizes
31+
make build
2932
id: build
3033

3134
- name: Run Forge tests
3235
run: |
33-
forge test -vvv
36+
make test
3437
id: test

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,9 @@ dist
131131

132132
# foundry cache
133133
forge-cache
134+
135+
# coverage
136+
lcov.info
137+
138+
# vscode workspace settings
139+
.vscode

Diff for: .solhint.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "solhint:recommended",
3+
"rules": {
4+
"func-name-mixedcase": "off",
5+
"var-name-mixedcase": "off",
6+
"no-unused-vars": "error"
7+
}
8+
}

Diff for: CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Global Code Owners
2+
* @jalextowle @jrhea @mcclurejt

Diff for: Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: build test
2+
3+
### Build ###
4+
5+
build:
6+
forge build --force --sizes
7+
8+
### Test ###
9+
10+
test:
11+
forge test
12+
13+
coverage:
14+
forge coverage --report lcov

Diff for: bun.lockb

0 Bytes
Binary file not shown.

Diff for: contracts/Admin.sol

-35
This file was deleted.

Diff for: contracts/Everlong.sol

+14-113
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity 0.8.20;
33

4-
import { Admin } from "./Admin.sol";
5-
import { ERC4626 } from "solady/tokens/ERC4626.sol";
6-
import { Positions } from "./Positions.sol";
7-
8-
import { IHyperdrive } from "hyperdrive/contracts/src/interfaces/IHyperdrive.sol";
4+
import { EverlongAdmin } from "./internal/EverlongAdmin.sol";
5+
import { EverlongBase } from "./internal/EverlongBase.sol";
6+
import { EverlongPositions } from "./internal/EverlongPositions.sol";
97

108
/// ,---..-. .-.,---. ,---. ,-. .---. .-. .-. ,--,
119
/// | .-' \ \ / / | .-' | .-.\ | | / .-. ) | \| |.' .'
@@ -57,120 +55,23 @@ import { IHyperdrive } from "hyperdrive/contracts/src/interfaces/IHyperdrive.sol
5755
// +++#####+++++++++--------------++++++++++++
5856
// #+ +++#######+++++++++++---------------+++++++++#+
5957
// ###########++++++++++++++-------------++++++++++###
60-
///
58+
//
6159
/// @author DELV
6260
/// @title Everlong
6361
/// @notice A money market powered by Hyperdrive.
6462
/// @custom:disclaimer The language used in this code is for coding convenience
6563
/// only, and is not intended to, and does not, have any
6664
/// particular legal or regulatory significance.
67-
contract Everlong is Admin, ERC4626, Positions {
68-
/// @notice Virtual shares are used to mitigate inflation attacks.
69-
bool public constant useVirtualShares = true;
70-
71-
/// @notice Used to reduce the feasibility of an inflation attack.
72-
/// TODO: Determine the appropriate value for our case. Current value
73-
/// was picked arbitrarily.
74-
uint8 public constant decimalsOffset = 3;
75-
76-
/// @notice Address of the Hyperdrive instance wrapped by Everlong.
77-
address public immutable hyperdrive;
78-
79-
/// @notice ERC20 token used for deposits, idle liquidity, and
80-
/// the purchase of bonds from the Hyperdrive instance.
81-
address internal immutable _asset;
82-
83-
/// @notice Decimals used by the `_asset`.
84-
uint8 internal immutable _decimals;
85-
86-
/// @notice Name of the Everlong token.
87-
string internal _name;
88-
89-
/// @notice Symbol of the Everlong token.
90-
string internal _symbol;
91-
65+
contract Everlong is EverlongAdmin, EverlongPositions {
9266
/// @notice Initial configuration paramters for Everlong.
93-
/// @param hyperdrive_ Address of the Hyperdrive instance wrapped by Everlong.
94-
/// @param name_ Name of the ERC20 token managed by Everlong.
95-
/// @param symbol_ Symbol of the ERC20 token managed by Everlong.
96-
/// @param asset_ ERC20 token used to purchase bonds from the Hyperdrive instance.
67+
/// @param _name Name of the ERC20 token managed by Everlong.
68+
/// @param _symbol Symbol of the ERC20 token managed by Everlong.
69+
/// @param __hyperdrive Address of the Hyperdrive instance wrapped by Everlong.
70+
/// @param __asBase Whether to use Hyperdrive's base token for bond purchases.
9771
constructor(
98-
string memory name_,
99-
string memory symbol_,
100-
address hyperdrive_,
101-
address asset_
102-
) Admin() {
103-
// Store constructor parameters.
104-
_name = name_;
105-
_symbol = symbol_;
106-
hyperdrive = hyperdrive_;
107-
_asset = asset_;
108-
109-
// Attempt to retrieve the decimals from the {_asset} contract.
110-
// If it does not implement `decimals() (uint256)`, use the default.
111-
(bool success, uint8 result) = _tryGetAssetDecimals(_asset);
112-
_decimals = success ? result : _DEFAULT_UNDERLYING_DECIMALS;
113-
}
114-
115-
/// @dev Address of the underlying Hyperdrive instance.
116-
/// @dev MUST be an ERC20 token contract.
117-
/// @dev MUST NOT revert.
118-
function asset() public view virtual override returns (address) {
119-
return _asset;
120-
}
121-
122-
/// @dev Returns the name of the Everlong token.
123-
function name() public view virtual override returns (string memory) {
124-
return _name;
125-
}
126-
127-
/// @dev Returns the symbol of the Everlong token.
128-
function symbol() public view virtual override returns (string memory) {
129-
return _symbol;
130-
}
131-
132-
/// @dev Returns the kind of the Everlong instance.
133-
function kind() public view virtual returns (string memory) {
134-
return "Everlong";
135-
}
136-
137-
/// @dev Returns the version of the Everlong instance.
138-
function version() public view virtual returns (string memory) {
139-
return "v0.0.1";
140-
}
141-
142-
/// @dev Returns whether virtual shares will be used to mitigate the inflation attack.
143-
/// @dev See: https://github.com/OpenZeppelin/openzeppelin-contracts/issues/3706
144-
/// @dev MUST NOT revert.
145-
function _useVirtualShares() internal view virtual override returns (bool) {
146-
return useVirtualShares;
147-
}
148-
149-
/// @dev Returns the number of decimals of the underlying asset.
150-
/// @dev MUST NOT revert.
151-
function _underlyingDecimals()
152-
internal
153-
view
154-
virtual
155-
override
156-
returns (uint8)
157-
{
158-
return _decimals;
159-
}
160-
161-
/// @dev A non-zero value used to make the inflation attack even more unfeasible.
162-
/// @dev MUST NOT revert.
163-
function _decimalsOffset() internal view virtual override returns (uint8) {
164-
return decimalsOffset;
165-
}
166-
167-
// TODO: Might not need this but including for convenience.
168-
function _beforeWithdraw(uint256, uint256) internal override {
169-
// revert("TODO");
170-
}
171-
172-
// TODO: Might not need this but including for convenience.
173-
function _afterDeposit(uint256, uint256) internal override {
174-
// revert("TODO");
175-
}
72+
string memory _name,
73+
string memory _symbol,
74+
address __hyperdrive,
75+
bool __asBase
76+
) EverlongBase(_name, _symbol, __hyperdrive, __asBase) {}
17677
}

Diff for: contracts/Positions.sol

-37
This file was deleted.

Diff for: contracts/interfaces/IAdmin.sol

-18
This file was deleted.

0 commit comments

Comments
 (0)