Skip to content

Commit

Permalink
Infrastructure improvements for the trading competition (#523)
Browse files Browse the repository at this point in the history
* Cleaned up `MockHyperdriveScript`

* Added a mock ERC4626 contract and a new migration script

* Improved the scripts

* Removed `MockHyperdriveTestnet` in favor of `ERC4626Hyperdrive

* Build a docker image for testing

* More polishing and deleting

* More polishing

* Reverted change in `.github/workflows/docker.yml`

* Added an error decoder helper

* Improved the smoke test

* Addressed review feedback from @ControlCplusControlV and @ryangoree

* Added the forwarder factory to the devnet migration
  • Loading branch information
jalextowle committed Jul 24, 2023
1 parent 71c6688 commit a3116be
Show file tree
Hide file tree
Showing 16 changed files with 587 additions and 525 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ COPY ./test/ ./test/
COPY ./foundry.toml ./foundry.toml

# Copy the script used to run the migrations and set its permissions.
COPY ./run_migrations.sh ./run_migrations.sh
RUN chmod a+x ./run_migrations.sh
COPY ./migrate.sh ./migrate.sh
RUN chmod a+x ./migrate.sh

# Install the dependencies and compile the contracts.
RUN forge install && forge build
Expand All @@ -33,6 +33,6 @@ ENV RPC_URL=http://localhost:8545
# the post-migrations state.
RUN anvil --dump-state ./data & \
ANVIL="$!" && \
./run_migrations.sh && \
./migrate.sh && \
kill $ANVIL && \
sleep 1s # HACK(jalextowle): Ensure that "./data" is written before exiting.
98 changes: 98 additions & 0 deletions contracts/test/MockERC4626.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.19;

import { ERC20 } from "solmate/tokens/ERC20.sol";
import { ERC4626 } from "solmate/mixins/ERC4626.sol";
import { FixedPointMath } from "../src/libraries/FixedPointMath.sol";
import { ERC20Mintable } from "./ERC20Mintable.sol";

/// @author DELV
/// @title MockERC4626
/// @notice This mock yield source will accrue interest at a specified rate
/// Every stateful interaction will accrue interest, so the interest
/// accrual will approximate continuous compounding as the contract
/// is called more frequently.
/// @custom:disclaimer The language used in this code is for coding convenience
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract MockERC4626 is ERC4626 {
using FixedPointMath for uint256;

uint256 internal _rate;
uint256 internal _lastUpdated;

constructor(
ERC20Mintable _asset,
string memory _name,
string memory _symbol,
uint256 _initialRate
) ERC4626(ERC20(address(_asset)), _name, _symbol) {
_rate = _initialRate;
_lastUpdated = block.timestamp;
}

/// Overrides ///

function deposit(
uint256 _assets,
address _receiver
) public override returns (uint256) {
_accrue();
return super.deposit(_assets, _receiver);
}

function mint(
uint256 _shares,
address _receiver
) public override returns (uint256) {
_accrue();
return super.mint(_shares, _receiver);
}

function withdraw(
uint256 _assets,
address _receiver,
address _owner
) public override returns (uint256) {
_accrue();
return super.withdraw(_assets, _receiver, _owner);
}

function redeem(
uint256 _shares,
address _receiver,
address _owner
) public override returns (uint256) {
_accrue();
return super.redeem(_shares, _receiver, _owner);
}

function totalAssets() public view override returns (uint256) {
return asset.balanceOf(address(this)) + _getAccruedInterest();
}

/// Mock ///

function setRate(uint256 _rate_) external {
_accrue();
_rate = _rate_;
}

function getRate() external view returns (uint256) {
return _rate;
}

function _accrue() internal {
ERC20Mintable(address(asset)).mint(_getAccruedInterest());
_lastUpdated = block.timestamp;
}

function _getAccruedInterest() internal view returns (uint256) {
// base_balance = base_balance * (1 + r * t)
uint256 timeElapsed = (block.timestamp - _lastUpdated).divDown(
365 days
);
return
asset.balanceOf(address(this)).mulDown(_rate.mulDown(timeElapsed));
}
}
208 changes: 0 additions & 208 deletions contracts/test/MockHyperdriveTestnet.sol

This file was deleted.

5 changes: 2 additions & 3 deletions run_migrations.sh → migrate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

set -ex

# Sleep for a few seconds to allow the Ethereum service to start up.
Expand All @@ -8,8 +7,8 @@ sleep 2
# Create an artifacts directory if it doesn't already exist.
mkdir -p ./artifacts

# Deploy the MockHyperdrive instance and the MockHyperdriveMath contract.
forge script script/MockHyperdrive.s.sol:MockHyperdriveScript \
# Execute the devnet migration.
forge script script/DevnetMigration.s.sol:DevnetMigration \
--sender "${ETH_FROM}" \
--private-key "${PRIVATE_KEY}" \
--rpc-url "${RPC_URL}" \
Expand Down
6 changes: 1 addition & 5 deletions python/contract_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ def should_check_code_size(artifact):
compilation_target = get_compilation_target(artifact)
if not compilation_target:
return False
return (
"contracts/src/" in compilation_target
or "MockHyperdriveTestnet" in compilation_target
or "MockMakerDsrHyperdrive" in compilation_target
)
return "contracts/src/" in compilation_target


ARTIFACTS_PATH = sys.argv[1]
Expand Down
Loading

0 comments on commit a3116be

Please sign in to comment.