Skip to content

Commit

Permalink
Added coverage and removed viaIR compilation (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic-O-Mhuiris authored Feb 14, 2023
1 parent bbc3ff8 commit 7658bcc
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 161 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on: ["push", "pull_request"]

name: hyperdrive

jobs:
test:
name: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: install node
uses: actions/setup-node@v3
with:
node-version: 14.x

- name: install packages
uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # if needed

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run coverage
run: |
forge coverage --report lcov
sudo apt-get install lcov
lcov --remove lcov.info -o lcov.info 'test/*' 'script/*'
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "./lcov.info"
parallel: true

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
on: [push]
on: ["push", "pull_request"]

name: lint
name: hyperdrive

jobs:
build:
name: solidity
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
on: [push]
on: ["push", "pull_request"]

name: test
name: hyperdrive

jobs:
check:
name: solidity
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ forge-cache/
node_modules/
yarn-error.log

# nix/shell extension - https://direnv.net/
.direnv

# code coverage
lcov.info
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Tests](https://github.com/element-fi/hyperdrive/actions/workflows/test.yml/badge.svg)](https://github.com/element-fi/hyperdrive/actions/workflows/test.yml)
[![Coverage](https://coveralls.io/repos/github/element-fi/hyperdrive/badge.svg?t=US78Aq)](https://coveralls.io/github/element-fi/hyperdrive)

# Hyperdrive

Hyperdrive is an automated market maker that enables fixed-rate markets to be
Expand Down
51 changes: 33 additions & 18 deletions contracts/libraries/HyperdriveMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,20 @@ library HyperdriveMath {
// timeRemaining*amountIn shares to purchase newly minted bonds on a
// YieldSpace curve configured to timeRemaining = 1.
uint256 curveIn = _amountIn.mulDown(_timeRemaining);

// TODO: Revisit this assumption. It seems like LPs can bake this into the
// fee schedule rather than adding a hidden fee.
//
// Calculate the curved part of the trade assuming that the flat part of
// the trade was applied to the share and bond reserves.
_shareReserves = _shareReserves.add(flat);
_bondReserves = _bondReserves.sub(flat.mulDown(_sharePrice));
uint256 curveOut = YieldSpaceMath.calculateOutGivenIn(
// Credit the share reserves by the flat trade.
_shareReserves.add(flat),
// Debit the bond reserves by the flat trade.
_bondReserves.sub(flat.mulDown(_sharePrice)),
_shareReserves,
_bondReserves,
_bondReserveAdjustment,
curveIn,
FixedPointMath.ONE_18,
_timeStretch,
FixedPointMath.ONE_18.sub(_timeStretch),
_sharePrice,
_initialSharePrice,
_isBondOut
Expand All @@ -162,15 +167,20 @@ library HyperdriveMath {
uint256 curveIn = _amountIn.mulDown(_timeRemaining).divDown(
_sharePrice
);

// TODO: Revisit this assumption. It seems like LPs can bake this into the
// fee schedule rather than adding a hidden fee.
//
// Calculate the curved part of the trade assuming that the flat part of
// the trade was applied to the share and bond reserves.
_shareReserves = _shareReserves.sub(flat);
_bondReserves = _bondReserves.add(flat.mulDown(_sharePrice));
uint256 curveOut = YieldSpaceMath.calculateOutGivenIn(
// Debit the share reserves by the flat trade.
_shareReserves.sub(flat),
// Credit the bond reserves by the flat trade.
_bondReserves.add(flat.mulDown(_sharePrice)),
_shareReserves,
_bondReserves,
_bondReserveAdjustment,
curveIn,
FixedPointMath.ONE_18,
_timeStretch,
FixedPointMath.ONE_18.sub(_timeStretch),
_sharePrice,
_initialSharePrice,
_isBondOut
Expand Down Expand Up @@ -230,15 +240,20 @@ library HyperdriveMath {
uint256 curveOut = _amountOut.mulDown(_timeRemaining).divDown(
_sharePrice
);

// TODO: Revisit this assumption. It seems like LPs can bake this into the
// fee schedule rather than adding a hidden fee.
//
// Calculate the curved part of the trade assuming that the flat part of
// the trade was applied to the share and bond reserves.
_shareReserves = _shareReserves.add(flat);
_bondReserves = _bondReserves.sub(flat.mulDown(_sharePrice));
uint256 curveIn = YieldSpaceMath.calculateInGivenOut(
// Credit the share reserves by the flat trade.
_shareReserves.add(flat),
// Debit the bond reserves by the flat trade.
_bondReserves.sub(flat.mulDown(_sharePrice)),
_shareReserves,
_bondReserves,
_bondReserveAdjustment,
curveOut,
FixedPointMath.ONE_18,
_timeStretch,
FixedPointMath.ONE_18.sub(_timeStretch),
_sharePrice,
_initialSharePrice,
false
Expand Down
Loading

0 comments on commit 7658bcc

Please sign in to comment.