Skip to content

Commit 05e3d58

Browse files
jalextowlewakamex
andauthored
Private Testnet (#239)
* Improved the Ethereum migrations * Fixes the docker services so that migrations runs consistently * Increased the reliability of the docker images * Miscallaneous improvements to the infrastructure * Setup a github action to deploy the migrations image to the registry * Renamed the python scripts * Bump node version in CI * Cleaned up `HyperdriveMath` * Experimenting with pushing to the registry * Added submodules to the docker workflow * Changed the tagging logic in the docker github action * Revert "Changed the tagging logic in the docker github action" This reverts commit 64e00d2. * Updated tagging logic * Build the foundry code in the image * Cleanup * Added semver tagging to the github workflows * Updated docker workflow to run when tags are pushed * Use the production profile * secret sauce * Reverted to an earlier foundry version * Updated the CI * Pinned ape to a working version * Fixed the tests after foundry update * Reverted the changes to the python requirements * Log the files * Removed python cache * Updated python version * Updated the eth-ape dependency * Fixed a numerical bug in `calculateCloseShort` * Removed the deprecated ape setting * run anvil on 8549 by default * more detailed pytest * try forge install * remove unnecessary dependency line * add compile step * additional update step to ape dependencies * Pinned to the previous ape-solidity version: * install fix to eth-solidity * fix the fix * fix ape-config * remove version pin, use upstream fix * more descriptive pytest settings * try to unbreak the benchmark Revert "more descriptive pytest settings" This reverts commit 89a228f. * actually test upstream, add github tokens to avoid rate limit * more verbose pytest, for specific workflow step only * remove pytest.ini after we use it * add newline * fix pytest.ini --------- Co-authored-by: Mihai <[email protected]>
1 parent 54b5290 commit 05e3d58

23 files changed

+314
-192
lines changed

.github/workflows/benchmark.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,27 @@ jobs:
2121
- name: install node
2222
uses: actions/setup-node@v3
2323
with:
24-
node-version: 16.x
24+
node-version: 18.x
25+
2526
- name: install packages
2627
uses: borales/actions-yarn@v4
2728
with:
2829
cmd: install # will run `yarn install` command
2930
env:
3031
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # if needed
32+
3133
- name: Install Foundry
3234
uses: foundry-rs/foundry-toolchain@v1
35+
with:
36+
version: nightly
37+
3338
- uses: actions/setup-python@v4
3439
with:
3540
python-version: "3.10"
3641

3742
# Run the gas benchmark and stores the output to a json file.
3843
- name: Run benchmark
39-
run: python scripts/gas_benchmarks.py benchmarks.json
44+
run: python python/gas_benchmarks.py benchmarks.json
4045

4146
# Load the benchmarks cache. We use a different cache key for every run
4247
# because Github Actions caches are currently immutable. By specifying the

.github/workflows/coverage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: install node
2424
uses: actions/setup-node@v3
2525
with:
26-
node-version: 16.x
26+
node-version: 18.x
2727

2828
- name: install packages
2929
uses: borales/actions-yarn@v4
@@ -34,6 +34,8 @@ jobs:
3434

3535
- name: Install Foundry
3636
uses: foundry-rs/foundry-toolchain@v1
37+
with:
38+
version: nightly
3739

3840
- name: Run coverage
3941
run: |

.github/workflows/docker.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish the artifacts image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "main"
8+
tags:
9+
- "v*"
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}/migrations
14+
15+
jobs:
16+
push-image:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
submodules: recursive
26+
27+
- name: Log in to the Container registry
28+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata (tags, labels) for Docker
35+
id: meta
36+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=semver,pattern={{version}}
41+
type=sha,enable=true,prefix=nightly-,suffix=,format=long
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: install node
2424
uses: actions/setup-node@v3
2525
with:
26-
node-version: 16.x
26+
node-version: 18.x
2727

2828
- name: install packages
2929
uses: borales/actions-yarn@v4

.github/workflows/test.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ jobs:
1919
- uses: actions/checkout@v3
2020
with:
2121
submodules: recursive
22+
token: ${{ secrets.GITHUB_TOKEN }}
2223

2324
- name: install node
2425
uses: actions/setup-node@v3
2526
with:
26-
node-version: 16.x
27+
node-version: 18.x
28+
token: ${{ secrets.GITHUB_TOKEN }}
2729

2830
- name: install packages
2931
uses: borales/actions-yarn@v4
3032
with:
3133
cmd: install # will run `yarn install` command
34+
token: ${{ secrets.GITHUB_TOKEN }}
3235
env:
3336
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # if needed
3437

@@ -44,14 +47,20 @@ jobs:
4447
uses: actions/setup-python@v3
4548
with:
4649
python-version: "3.10.10"
47-
cache: "pip"
50+
cache: pip
51+
token: ${{ secrets.GITHUB_TOKEN }}
4852

4953
- name: install python dependencies
5054
run: |
5155
python -m pip install --upgrade pip
5256
python -m pip install -r requirements.txt
53-
python -m pip install eth-ape pytest
5457
ape plugins install .
58+
ape compile --force
5559
5660
- name: test python
57-
run: python -m pytest .
61+
run: |
62+
echo "[pytest]
63+
log_cli: true
64+
log_level: DEBUG" > pytest.ini
65+
python -m pytest . -r A --verbosity=2
66+
rm pytest.ini

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### Yarn Image ###
2+
3+
FROM node:lts AS yarn-builder
4+
5+
WORKDIR /src
6+
7+
COPY ./package.json ./package.json
8+
COPY ./yarn.lock ./yarn.lock
9+
10+
RUN yarn install
11+
12+
### Foundry Image ###
13+
14+
FROM ghcr.io/foundry-rs/foundry:master
15+
16+
WORKDIR /src
17+
18+
# Load the ethereum environment variables.
19+
ENV ETH_FROM=${ETH_FROM}
20+
ENV PRIVATE_KEY=${PRIVATE_KEY}
21+
ENV RPC_URL=${RPC_URL}
22+
23+
# Copy the contract dependencies required to run the migration script.
24+
COPY --from=yarn-builder /src/node_modules/@openzeppelin/ ./node_modules/@openzeppelin/
25+
COPY ./.git/ ./.git/
26+
COPY ./contracts/ ./contracts/
27+
COPY ./lib/ ./lib/
28+
COPY ./script/ ./script/
29+
COPY ./test/ ./test/
30+
COPY ./foundry.toml ./foundry.toml
31+
32+
# Build the contracts using the "production" profile.
33+
RUN FOUNDRY_PROFILE="production" forge build
34+
35+
# Copy the script used to run the migrations and set its permissions.
36+
COPY ./run_migrations.sh ./run_migrations.sh
37+
RUN chmod a+x ./run_migrations.sh
38+
39+
# Create the artifacts directory.
40+
RUN mkdir -p ./artifacts
41+
42+
ENTRYPOINT ./run_migrations.sh

ape-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ plugins:
44
- name: foundry
55

66
dependencies:
7-
- name: OpenZeppelin
8-
github: OpenZeppelin/openzeppelin-contracts
9-
version: 4.8.1
107
- name: Aave
118
github: aave/aave-v3-core
129
version: 1.17.2
10+
- name: OpenZeppelin
11+
github: OpenZeppelin/openzeppelin-contracts
12+
version: 4.8.3
1313

1414
solidity:
1515
import_remapping:
16-
- "@openzeppelin/contracts=OpenZeppelin/4.8.1"
16+
- "@openzeppelin/contracts=OpenZeppelin/4.8.3"
1717
- "@aave=Aave/1.17.2"
1818

1919
ethereum:
@@ -22,4 +22,4 @@ ethereum:
2222
default_provider: foundry
2323

2424
foundry:
25-
port: 8555
25+
host: http://localhost:8555

contracts/src/libraries/HyperdriveMath.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ library HyperdriveMath {
316316
_sharePrice
317317
);
318318

319-
if (_normalizedTimeRemaining > 0) {
320-
bondReservesDelta = _amountOut.mulDown(_normalizedTimeRemaining);
319+
bondReservesDelta = _amountOut.mulDown(_normalizedTimeRemaining);
320+
if (bondReservesDelta > 0) {
321321
shareReservesDelta = YieldSpaceMath.calculateSharesInGivenBondsOut(
322322
_shareReserves,
323323
_bondReserves,

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ cache_path = 'forge-cache'
1616
remappings = ['forge-std=lib/forge-std/src', '@openzeppelin/=node_modules/@openzeppelin', '@aave/=lib/aave-v3-core/contracts']
1717
# gas limit - max u64
1818
gas_limit = "18446744073709551615"
19+
# Allows the scripts to write the addresses to a file.
20+
fs_permissions = [{ access = "write", path = "./artifacts/script_addresses.json" }]
1921
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
2022

2123
[profile.production]

migrations/AaveFixedBorrowAction.s.sol

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)