Skip to content

Commit

Permalink
Merge branch 'main' into matt/total_assets_with_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal authored Jun 12, 2024
2 parents d1514d5 + 69d794a commit cbd0e30
Show file tree
Hide file tree
Showing 67 changed files with 3,650 additions and 459 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/devnet_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- "main"
tags:
- "v*"
pull_request:
branches:
- "main"

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -53,12 +56,13 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
ADMIN=${{ vars.DEVNET_ADMIN }}
FACTORY_MIN_CURVE_FEE=0
FACTORY_MIN_FLAT_FEE=0
FACTORY_MIN_GOVERNANCE_LP_FEE=0
FACTORY_MIN_GOVERNANCE_ZOMBIE_FEE=0
FACTORY_MAX_CURVE_FEE=1000000000000000000
FACTORY_MAX_FLAT_FEE=1000000000000000000
FACTORY_MAX_GOVERNANCE_LP_FEE=1000000000000000000
FACTORY_MAX_GOVERNANCE_ZOMBIE_FEE=1000000000000000000
FACTORY_MIN_POSITION_DURATION=86400
DEPLOYER_PRIVATE_KEY=${{ vars.DEVNET_ADMIN_PRIVATE_KEY }}
FACTORY_MIN_CURVE_FEE=0 # 0%
FACTORY_MIN_FLAT_FEE=0 # 0%
FACTORY_MIN_GOVERNANCE_LP_FEE=0 # 0%
FACTORY_MIN_GOVERNANCE_ZOMBIE_FEE=0 # 0%
FACTORY_MAX_CURVE_FEE=1 # 100%
FACTORY_MAX_FLAT_FEE=1 # 100%
FACTORY_MAX_GOVERNANCE_LP_FEE=1 # 100%
FACTORY_MAX_GOVERNANCE_ZOMBIE_FEE=1 # 100%
FACTORY_MIN_POSITION_DURATION=1 # 1 Day (in seconds)
57 changes: 0 additions & 57 deletions .github/workflows/mainnet_fork_docker.yml

This file was deleted.

20 changes: 12 additions & 8 deletions .github/workflows/testnet_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- "main"
tags:
- "v*"
pull_request:
branches:
- "main"

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -53,16 +56,17 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
ADMIN=${{ vars.TESTNET_ADMIN }}
DEPLOYER_PRIVATE_KEY=${{ vars.TESTNET_ADMIN_PRIVATE_KEY }}
IS_COMPETITION_MODE=true
BASE_TOKEN_NAME=Multi Collateral DAI
BASE_TOKEN_SYMBOL=DAI
VAULT_NAME=sDai
VAULT_SYMBOL=SDAI
VAULT_STARTING_RATE=50000000000000000 # 5% APR
LIDO_STARTING_RATE=35000000000000000 # 3.5% APR
ERC4626_HYPERDRIVE_POSITION_DURATION=31536000 # 1 year in seconds
ERC4626_HYPERDRIVE_CHECKPOINT_DURATION=86400 # 1 day in seconds
ERC4626_HYPERDRIVE_FLAT_FEE=500000000000000 # 0.05% APR
STETH_HYPERDRIVE_POSITION_DURATION=31536000 # 1 year in seconds
STETH_HYPERDRIVE_CHECKPOINT_DURATION=86400 # 1 day in seconds
STETH_HYPERDRIVE_FLAT_FEE=500000000000000 # 0.05% APR
VAULT_STARTING_RATE=0.05 # 5% APR
LIDO_STARTING_RATE=0.035 # 3.5% APR
ERC4626_HYPERDRIVE_POSITION_DURATION=365 # 1 year in seconds
ERC4626_HYPERDRIVE_CHECKPOINT_DURATION=1 # 1 day in seconds
ERC4626_HYPERDRIVE_FLAT_FEE=0.0005 # 0.05% APR
STETH_HYPERDRIVE_POSITION_DURATION=365 # 1 year in seconds
STETH_HYPERDRIVE_CHECKPOINT_DURATION=1 # 1 day in seconds
STETH_HYPERDRIVE_FLAT_FEE=0.0005 # 0.05% APR
48 changes: 19 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# NOTE: The `latest` version of foundry does not include arm64 as a build platform,
# but tagged versions do. Using an arm64-compatible image enables developers to
# NOTE: The `latest` version of foundry does not include arm64 as a build platform,
# but tagged versions do. Using an arm64-compatible image enables developers to
# locally rebuild this image with different arguments for debugging/testing purposes.
#
FROM ghcr.io/foundry-rs/foundry@sha256:4606590c8f3cef6a8cba4bdf30226cedcdbd9f1b891e2bde17b7cf66c363b2b3 AS base
RUN apk add --no-cache npm jq make && \
npm install -g yarn

# Use a dedicated stage to generate node_modules.
# Since only package.json and yarn.lock are copied, it's likely this layer will stay cached.
FROM ghcr.io/foundry-rs/foundry@sha256:4606590c8f3cef6a8cba4bdf30226cedcdbd9f1b891e2bde17b7cf66c363b2b3 AS node-builder
RUN apk add --no-cache npm && \
npm install -g yarn
WORKDIR /app
FROM base AS node-modules-builder
WORKDIR /src
COPY ./package.json ./package.json
COPY ./yarn.lock ./yarn.lock
RUN yarn install --immutable
RUN yarn install --immutable && yarn cache clean

# Deploy the contracts to an Anvil node and save the node's state to a file.
# By storing the freshly-deployed state, resetting the chain to that point is
# far simpler and faster.
#
# Build args are used to define the parameters for the deployment.
# These can be overridden at build time to debug generate different hyperdrive configurations.
FROM ghcr.io/foundry-rs/foundry@sha256:4606590c8f3cef6a8cba4bdf30226cedcdbd9f1b891e2bde17b7cf66c363b2b3 as builder
RUN apk add --no-cache npm jq make && \
npm install -g yarn
FROM base
WORKDIR /src
COPY --from=node-builder /app/node_modules/ node_modules/
COPY --from=node-modules-builder /src/node_modules/ /src/node_modules/
COPY . .
ENV NETWORK=anvil
ENV HYPERDRIVE_ETHEREUM_URL=http://127.0.0.1:8545
ARG NETWORK=anvil
ARG HYPERDRIVE_ETHEREUM_URL=http://127.0.0.1:8545
ARG ADMIN=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
ENV DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ARG DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ARG IS_COMPETITION_MODE=false
ARG BASE_TOKEN_NAME=Base
ARG BASE_TOKEN_SYMBOL=BASE
Expand All @@ -40,7 +39,7 @@ ARG FACTORY_CHECKPOINT_DURATION=1
ARG FACTORY_MIN_CHECKPOINT_DURATION=1
ARG FACTORY_MAX_CHECKPOINT_DURATION=24
ARG FACTORY_MIN_POSITION_DURATION=7
ARG FACTORY_MAX_POSITION_DURATION=36500
ARG FACTORY_MAX_POSITION_DURATION=365
ARG FACTORY_MIN_CIRCUIT_BREAKER_DELTA=0.15
ARG FACTORY_MAX_CIRCUIT_BREAKER_DELTA=2
ARG FACTORY_MIN_FIXED_APR=0.01
Expand Down Expand Up @@ -81,20 +80,11 @@ ARG STETH_HYPERDRIVE_GOVERNANCE_LP_FEE=0.15
ARG STETH_HYPERDRIVE_GOVERNANCE_ZOMBIE_FEE=0.03
RUN anvil --dump-state ./data & ANVIL="$!" && \
sleep 2 && \
# PERF: The deploy step comprises ~90% of cached build time due to a solc download
# on the first compiler run. Running `npx hardhat compile` in the node-builder stage
# would fix the issue, but also require defining all build args in that stage
# as well as defining them without defaults in this stage 🤮.
npx hardhat fork:mint-eth --address ${ADMIN} --amount 10 --network ${NETWORK} --config "hardhat.config.${NETWORK}.ts" && \
make deploy && \
npx hardhat registry:add --name ERC4626_HYPERDRIVE --value 1 --network anvil && \
npx hardhat registry:add --name STETH_HYPERDRIVE --value 1 --network anvil && \
npx hardhat registry:update-governance --address ${ADMIN} --network anvil && \
npx hardhat registry:add --name ERC4626_HYPERDRIVE --value 1 --network ${NETWORK} --config "hardhat.config.${NETWORK}.ts" && \
npx hardhat registry:add --name STETH_HYPERDRIVE --value 1 --network ${NETWORK} --config "hardhat.config.${NETWORK}.ts" && \
npx hardhat registry:update-governance --address ${ADMIN} --network ${NETWORK} --config "hardhat.config.${NETWORK}.ts" && \
./scripts/format-devnet-addresses.sh && \
kill $ANVIL && sleep 1s

# Copy over only the stored chain data and list of contract addresses to minimize image size.
FROM ghcr.io/foundry-rs/foundry@sha256:4606590c8f3cef6a8cba4bdf30226cedcdbd9f1b891e2bde17b7cf66c363b2b3
WORKDIR /src
COPY --from=builder /src/data /src/data
COPY --from=builder /src/artifacts/addresses.json /src/artifacts/addresses.json
COPY --from=builder /src/deployments.local.json /src/deployments.local.json
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ deploy:

generate-deploy:
./scripts/generate-deploy-config.sh

deploy-fork:
./scripts/deploy-fork.sh
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ To deploy the smart contracts, run:
NETWORK=<hardhat|anvil|sepolia|mainnet> make deploy
```

To deploy the smart contracts to a mainnet fork environment, run:

```sh
make deploy-fork
```

### Generate Deploy Configurations

Factory, coordinator, and instance deploy configurations can be generated via templates.
Expand Down
75 changes: 45 additions & 30 deletions contracts/src/factory/HyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ contract HyperdriveFactory is IHyperdriveFactory {
/// by governance.
mapping(address => bool) public isDeployerCoordinator;

/// @notice A mapping from deployed Hyperdrive instances to the deployer
/// coordinator that deployed them. This is useful for verifying
/// the bytecode that was used to deploy the instance.
/// @dev A mapping from deployed Hyperdrive instances to the deployer
/// coordinator that deployed them. This is useful for verifying the
/// bytecode that was used to deploy the instance.
mapping(address instance => address deployCoordinator)
public instancesToDeployerCoordinators;
public _instancesToDeployerCoordinators;

/// @dev Array of all instances deployed by this factory.
address[] internal _instances;
Expand Down Expand Up @@ -760,7 +760,7 @@ contract HyperdriveFactory is IHyperdriveFactory {

// Add this instance to the registry and emit an event with the
// deployment configuration.
instancesToDeployerCoordinators[
_instancesToDeployerCoordinators[
address(hyperdrive)
] = _deployerCoordinator;
_config.governance = hyperdriveGovernance;
Expand Down Expand Up @@ -883,33 +883,35 @@ contract HyperdriveFactory is IHyperdriveFactory {
}

/// @notice Gets the instance at the specified index.
/// @param index The index of the instance to get.
/// @param _index The index of the instance to get.
/// @return The instance at the specified index.
function getInstanceAtIndex(uint256 index) external view returns (address) {
return _instances[index];
function getInstanceAtIndex(
uint256 _index
) external view returns (address) {
return _instances[_index];
}

/// @notice Returns the _instances array according to specified indices.
/// @param startIndex The starting index of the instances to get.
/// @param endIndex The ending index of the instances to get.
/// @param _startIndex The starting index of the instances to get (inclusive).
/// @param _endIndex The ending index of the instances to get (exclusive).
/// @return range The resulting custom portion of the _instances array.
function getInstancesInRange(
uint256 startIndex,
uint256 endIndex
uint256 _startIndex,
uint256 _endIndex
) external view returns (address[] memory range) {
// If the indexes are malformed, revert.
if (startIndex > endIndex) {
if (_startIndex >= _endIndex) {
revert IHyperdriveFactory.InvalidIndexes();
}
if (endIndex >= _instances.length) {
if (_endIndex > _instances.length) {
revert IHyperdriveFactory.EndIndexTooLarge();
}

// Return the range of instances.
range = new address[](endIndex - startIndex + 1);
for (uint256 i = startIndex; i <= endIndex; i++) {
range = new address[](_endIndex - _startIndex);
for (uint256 i = _startIndex; i < _endIndex; i++) {
unchecked {
range[i - startIndex] = _instances[i];
range[i - _startIndex] = _instances[i];
}
}
}
Expand All @@ -922,40 +924,53 @@ contract HyperdriveFactory is IHyperdriveFactory {
}

/// @notice Gets the deployer coordinator at the specified index.
/// @param index The index of the deployer coordinator to get.
/// @param _index The index of the deployer coordinator to get.
/// @return The deployer coordinator at the specified index.
function getDeployerCoordinatorAtIndex(
uint256 index
uint256 _index
) external view returns (address) {
return _deployerCoordinators[index];
return _deployerCoordinators[_index];
}

/// @notice Returns the deployer coordinators with an index between the
/// starting and ending indexes (inclusive).
/// @param startIndex The starting index (inclusive).
/// @param endIndex The ending index (inclusive).
/// starting and ending indexes.
/// @param _startIndex The starting index (inclusive).
/// @param _endIndex The ending index (exclusive).
/// @return range The deployer coordinators within the specified range.
function getDeployerCoordinatorsInRange(
uint256 startIndex,
uint256 endIndex
uint256 _startIndex,
uint256 _endIndex
) external view returns (address[] memory range) {
// If the indexes are malformed, revert.
if (startIndex > endIndex) {
if (_startIndex >= _endIndex) {
revert IHyperdriveFactory.InvalidIndexes();
}
if (endIndex >= _deployerCoordinators.length) {
if (_endIndex > _deployerCoordinators.length) {
revert IHyperdriveFactory.EndIndexTooLarge();
}

// Return the range of instances.
range = new address[](endIndex - startIndex + 1);
for (uint256 i = startIndex; i <= endIndex; i++) {
range = new address[](_endIndex - _startIndex);
for (uint256 i = _startIndex; i < _endIndex; i++) {
unchecked {
range[i - startIndex] = _deployerCoordinators[i];
range[i - _startIndex] = _deployerCoordinators[i];
}
}
}

/// @notice Gets the deployer coordinators that deployed a list of instances.
/// @param __instances The instances.
/// @return coordinators The deployer coordinators.
function getDeployerCoordinatorByInstances(
address[] calldata __instances
) external view returns (address[] memory coordinators) {
coordinators = new address[](_instances.length);
for (uint256 i = 0; i < __instances.length; i++) {
coordinators[i] = _instancesToDeployerCoordinators[__instances[i]];
}
return coordinators;
}

/// @dev Overrides the config values to the default values set by
/// governance. In the process of overriding these parameters, this
/// verifies that the specified config is valid.
Expand Down
Loading

0 comments on commit cbd0e30

Please sign in to comment.