diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..815f236ed --- /dev/null +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 60a67ac8e..cf523f2df 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 258a72fb0..ebcd80cd3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 4bb3c375a..5adde47b4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ forge-cache/ node_modules/ yarn-error.log +# nix/shell extension - https://direnv.net/ .direnv + +# code coverage +lcov.info diff --git a/README.md b/README.md index e2d0bd5d9..5a6ea4b94 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/contracts/libraries/HyperdriveMath.sol b/contracts/libraries/HyperdriveMath.sol index da701b202..50e0bd04a 100644 --- a/contracts/libraries/HyperdriveMath.sol +++ b/contracts/libraries/HyperdriveMath.sol @@ -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 @@ -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 @@ -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 diff --git a/contracts/libraries/YieldSpaceMath.sol b/contracts/libraries/YieldSpaceMath.sol index fde9abcb4..04153fe62 100644 --- a/contracts/libraries/YieldSpaceMath.sol +++ b/contracts/libraries/YieldSpaceMath.sol @@ -15,141 +15,156 @@ library YieldSpaceMath { using FixedPointMath for uint256; /// Calculates the amount of bond a user would get for given amount of shares. - /// @param shareReserves yield bearing vault shares reserve amount, unit is shares - /// @param bondReserves bond reserves amount, unit is the face value in underlying - /// @param bondReserveAdjustment An optional adjustment to the reserve which MUST have units of underlying. - /// @param amountIn amount to be traded, if bonds in the unit is underlying, if shares in the unit is shares - /// @param t time till maturity in seconds - /// @param s time stretch coefficient. e.g. 25 years in seconds - /// @param c price of shares in terms of their base - /// @param mu Normalization factor -- starts as c at initialization - /// @param isBondOut determines if the output is bond or shares - /// @return result the amount of shares a user would get for given amount of bond + /// @param _shareReserves yield bearing vault shares reserve amount, unit is shares + /// @param _bondReserves bond reserves amount, unit is the face value in underlying + /// @param _bondReserveAdjustment An optional adjustment to the reserve which MUST have units of underlying. + /// @param _amountIn amount to be traded, if bonds in the unit is underlying, if shares in the unit is shares + /// @param _stretchedTimeElapsed Amount of time elapsed since term start + /// @param _c price of shares in terms of their base + /// @param _mu Normalization factor -- starts as c at initialization + /// @param _isBondOut determines if the output is bond or shares + /// @return Amount of shares/bonds function calculateOutGivenIn( - uint256 shareReserves, - uint256 bondReserves, - uint256 bondReserveAdjustment, - uint256 amountIn, - uint256 t, - uint256 s, - uint256 c, - uint256 mu, - bool isBondOut - ) internal pure returns (uint256 result) { - uint256 outReserves; - uint256 rhs; - // Notes: 1 >= 1-st >= 0 - uint256 oneMinusT = FixedPointMath.ONE_18.sub(s.mulDown(t)); - // c/mu - uint256 cDivMu = c.divDown(mu); - // Adjust the bond reserve, optionally shifts the curve around the inflection point - uint256 modifiedBondReserves = bondReserves.add(bondReserveAdjustment); - // c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - uint256 k = cDivMu - .mulDown(mu.mulDown(shareReserves).pow(oneMinusT)) - .add(modifiedBondReserves.pow(oneMinusT)); + uint256 _shareReserves, + uint256 _bondReserves, + uint256 _bondReserveAdjustment, + uint256 _amountIn, + uint256 _stretchedTimeElapsed, + uint256 _c, + uint256 _mu, + bool _isBondOut + ) internal pure returns (uint256) { + // c / mu + uint256 cDivMu = _c.divDown(_mu); + // Adjust the bond reserve, optionally shifts the curve around the + // inflection point + _bondReserves = _bondReserves.add(_bondReserveAdjustment); + // (c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) + uint256 k = _k( + cDivMu, + _mu, + _shareReserves, + _stretchedTimeElapsed, + _bondReserves + ); - if (isBondOut) { - // bondOut = bondReserves - ( c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - c/mu * (mu*(shareReserves + shareIn))^(1-t) )^(1 / (1 - t)) - outReserves = modifiedBondReserves; - // (mu*(shareReserves + amountIn))^(1-t) - uint256 newScaledShareReserves = mu - .mulDown(shareReserves.add(amountIn)) - .pow(oneMinusT); - // c/mu * (mu*(shareReserves + amountIn))^(1-t) - newScaledShareReserves = cDivMu.mulDown(newScaledShareReserves); - // Notes: k - newScaledShareReserves >= 0 to avoid a complex number - // ( c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - c/mu * (mu*(shareReserves + amountIn))^(1-t) )^(1 / (1 - t)) - rhs = k.sub(newScaledShareReserves).pow( - FixedPointMath.ONE_18.divDown(oneMinusT) + if (_isBondOut) { + // (mu * (shareReserves + amountIn))^(1 - tau) + _shareReserves = _mu.mulDown(_shareReserves.add(_amountIn)).pow( + _stretchedTimeElapsed + ); + // (c / mu) * (mu * (shareReserves + amountIn))^(1 - tau) + _shareReserves = cDivMu.mulDown(_shareReserves); + // NOTE: k - shareReserves >= 0 to avoid a complex number + // ((c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (c / mu) * (mu * (shareReserves + amountIn))^(1 - tau))^(1 / (1 - tau))) + uint256 newBondReserves = k.sub(_shareReserves).pow( + FixedPointMath.ONE_18.divDown(_stretchedTimeElapsed) ); + // NOTE: bondReserves - newBondReserves >= 0, but I think avoiding a complex number in the step above ensures this never happens + // bondsOut = bondReserves - ( (c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (c / mu) * (mu * (shareReserves + shareIn))^(1 - tau))^(1 / (1 - tau))) + return _bondReserves.sub(newBondReserves); } else { - // shareOut = shareReserves - [ ( c/mu * (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves + bondIn)^(1-t) ) / c/u ]^(1 / (1 - t)) / mu - outReserves = shareReserves; - // (bondReserves + bondIn)^(1-t) - uint256 newScaledBondReserves = modifiedBondReserves - .add(amountIn) - .pow(oneMinusT); - // Notes: k - newScaledBondReserves >= 0 to avoid a complex number - // [( (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves + bondIn)^(1-t) ) / c/u ]^(1 / (1 - t)) - rhs = k.sub(newScaledBondReserves).divDown(cDivMu).pow( - FixedPointMath.ONE_18.divDown(oneMinusT) + // (bondReserves + amountIn)^(1 - tau) + _bondReserves = _bondReserves.add(_amountIn).pow( + _stretchedTimeElapsed ); - // [( (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves + bondIn)^(1-t) ) / c/u ]^(1 / (1 - t)) / mu - rhs = rhs.divDown(mu); + // NOTE: k - bondReserves >= 0 to avoid a complex number + // (((mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves + amountIn)^(1 - tau)) / (c / mu))^(1 / (1 - tau))) + uint256 newShareReserves = k.sub(_bondReserves).divDown(cDivMu).pow( + FixedPointMath.ONE_18.divDown(_stretchedTimeElapsed) + ); + // (((mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves + bondIn)^(1 - tau) ) / (c / mu))^(1 / (1 - tau))) / mu + newShareReserves = newShareReserves.divDown(_mu); + // NOTE: shareReserves - sharesOut >= 0, but I think avoiding a complex number in the step above ensures this never happens + // sharesOut = shareReserves - (((c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves + bondIn)^(1 - tau) ) / (c / mu))^(1 / (1 - tau))) / mu + return _shareReserves.sub(newShareReserves); } - // Notes: outReserves - rhs >= 0, but i think avoiding a complex number in the step above ensures this never happens - result = outReserves.sub(rhs); } /// @dev Calculates the amount of an asset that will be received given a /// specified amount of the other asset given the current AMM reserves. - /// @param shareReserves yield bearing vault shares reserve amount, unit is shares - /// @param bondReserves bond reserves amount, unit is the face value in underlying - /// @param bondReserveAdjustment An optional adjustment to the reserve which MUST have units of underlying. - /// @param amountOut amount to be received, if bonds in the unit is underlying, if shares in the unit is shares - /// @param t time till maturity in seconds - /// @param s time stretch coefficient. e.g. 25 years in seconds - /// @param c price of shares in terms of their base - /// @param mu Normalization factor -- starts as c at initialization - /// @param isBondIn determines if the input is bond or shares - /// @return result the amount of shares a user would get for given amount of bond + /// @param _shareReserves yield bearing vault shares reserve amount, unit is shares + /// @param _bondReserves bond reserves amount, unit is the face value in underlying + /// @param _bondReserveAdjustment An optional adjustment to the reserve which MUST have units of underlying. + /// @param _amountOut amount to be received, if bonds in the unit is underlying, if shares in the unit is shares + /// @param _stretchedTimeElapsed Amount of time elapsed since term start + /// @param _c price of shares in terms of their base + /// @param _mu Normalization factor -- starts as c at initialization + /// @param _isBondIn determines if the input is bond or shares + /// @return Amount of shares/bonds function calculateInGivenOut( - uint256 shareReserves, - uint256 bondReserves, - uint256 bondReserveAdjustment, - uint256 amountOut, - uint256 t, - uint256 s, - uint256 c, - uint256 mu, - bool isBondIn - ) internal pure returns (uint256 result) { - uint256 inReserves; - uint256 rhs; - // Notes: 1 >= 1-st >= 0 - uint256 oneMinusT = FixedPointMath.ONE_18.sub(s.mulDown(t)); - // c/mu - uint256 cDivMu = c.divDown(mu); + uint256 _shareReserves, + uint256 _bondReserves, + uint256 _bondReserveAdjustment, + uint256 _amountOut, + uint256 _stretchedTimeElapsed, + uint256 _c, + uint256 _mu, + bool _isBondIn + ) internal pure returns (uint256) { + // c / mu + uint256 cDivMu = _c.divDown(_mu); // Adjust the bond reserve, optionally shifts the curve around the inflection point - uint256 modifiedBondReserves = bondReserves.add(bondReserveAdjustment); - // c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - uint256 k = cDivMu - .mulDown(mu.mulDown(shareReserves).pow(oneMinusT)) - .add(modifiedBondReserves.pow(oneMinusT)); - - if (isBondIn) { - // bondIn = ( c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - c/mu * (mu*(shareReserves - shareOut))^(1-t) )^(1 / (1 - t)) - bond_reserves - inReserves = modifiedBondReserves; - // (mu*(shareReserves - amountOut))^(1-t) - uint256 newScaledShareReserves = mu - .mulDown(shareReserves.sub(amountOut)) - .pow(oneMinusT); - // c/mu * (mu*(shareReserves - amountOut))^(1-t) - newScaledShareReserves = cDivMu.mulDown(newScaledShareReserves); - // Notes: k - newScaledShareReserves >= 0 to avoid a complex number - // ( c/mu * (mu*shareReserves)^(1-t) + bondReserves^(1-t) - c/mu * (mu*(shareReserves - amountOut))^(1-t) )^(1 / (1 - t)) - rhs = k.sub(newScaledShareReserves).pow( - FixedPointMath.ONE_18.divDown(oneMinusT) + _bondReserves = _bondReserves.add(_bondReserveAdjustment); + // (c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) + uint256 k = _k( + cDivMu, + _mu, + _shareReserves, + _stretchedTimeElapsed, + _bondReserves + ); + if (_isBondIn) { + // (mu * (shareReserves - amountOut))^(1 - tau) + _shareReserves = _mu.mulDown(_shareReserves.sub(_amountOut)).pow( + _stretchedTimeElapsed ); + // (c / mu) * (mu * (shareReserves - amountOut))^(1 - tau) + _shareReserves = cDivMu.mulDown(_shareReserves); + // NOTE: k - shareReserves >= 0 to avoid a complex number + // ((c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (c / mu) * (mu*(shareReserves - amountOut))^(1 - tau))^(1 / (1 - tau))) + uint256 newBondReserves = k.sub(_shareReserves).pow( + FixedPointMath.ONE_18.divDown(_stretchedTimeElapsed) + ); + // NOTE: newBondReserves - bondReserves >= 0, but I think avoiding a complex number in the step above ensures this never happens + // bondIn = ((c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (c / mu) * (mu * (shareReserves - shareOut))^(1 - tau))^(1 / (1 - tau))) - bondReserves + return newBondReserves.sub(_bondReserves); } else { - // shareOut = [ ( c/mu * (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves - bondOut)^(1-t) ) / c/u ]^(1 / (1 - t)) / mu - share_reserves - inReserves = shareReserves; - // (bondReserves - amountOut)^(1-t) - uint256 newScaledBondReserves = modifiedBondReserves - .sub(amountOut) - .pow(oneMinusT); - // Notes: k - newScaledBondReserves >= 0 to avoid a complex number - // [( (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves - amountOut)^(1-t) ) / c/u ]^(1 / (1 - t)) - rhs = k.sub(newScaledBondReserves).divDown(cDivMu).pow( - FixedPointMath.ONE_18.divDown(oneMinusT) + // (bondReserves - amountOut)^(1 - tau) + _bondReserves = _bondReserves.sub(_amountOut).pow( + _stretchedTimeElapsed + ); + // NOTE: k - newScaledBondReserves >= 0 to avoid a complex number + // (((mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves - amountOut)^(1 - tau) ) / (c / mu))^(1 / (1 - tau))) + uint256 newShareReserves = k.sub(_bondReserves).divDown(cDivMu).pow( + FixedPointMath.ONE_18.divDown(_stretchedTimeElapsed) ); - // [( (mu * shareReserves)^(1-t) + bondReserves^(1-t) - (bondReserves - amountOut)^(1-t) ) / c/u ]^(1 / (1 - t)) / mu - rhs = rhs.divDown(mu); + // (((mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves - amountOut)^(1 - tau) ) / (c / mu))^(1 / (1 - tau))) / mu + newShareReserves = newShareReserves.divDown(_mu); + // NOTE: newShareReserves - shareReserves >= 0, but I think avoiding a complex number in the step above ensures this never happens + // sharesIn = (((c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) - (bondReserves - bondOut)^(1 - tau) ) / (c / mu))^(1 / (1 - tau))) / mu - shareReserves + return newShareReserves.sub(_shareReserves); } - // TODO: Double check this. - // - // Notes: rhs - inReserves >= 0, but i think avoiding a complex number in the step above ensures this never happens - result = rhs.sub(inReserves); + } + + /// @dev Helper function to derive invariant constant k + /// @param _cDivMu Normalized price of shares in terms of base + /// @param _mu Normalization factor -- starts as c at initialization + /// @param _shareReserves Yield bearing vault shares reserve amount, unit is shares + /// @param _stretchedTimeElapsed Amount of time elapsed since term start + /// @param _bondReserves Bond reserves amount, unit is the face value in underlying + /// returns k + function _k( + uint256 _cDivMu, + uint256 _mu, + uint256 _shareReserves, + uint256 _stretchedTimeElapsed, + uint256 _bondReserves + ) private pure returns (uint256) { + /// k = (c / mu) * (mu * shareReserves)^(1 - tau) + bondReserves^(1 - tau) + return + _cDivMu + .mulDown(_mu.mulDown(_shareReserves).pow(_stretchedTimeElapsed)) + .add(_bondReserves.pow(_stretchedTimeElapsed)); } } diff --git a/flake.lock b/flake.lock index 69cc47dfe..8f52bb094 100644 --- a/flake.lock +++ b/flake.lock @@ -21,16 +21,15 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1672936714, - "narHash": "sha256-MaW0kIQH9Ns17vYGsUBYGkdR6GYCLd0Rzjznf0zUsVU=", + "lastModified": 1676365777, + "narHash": "sha256-vtZFb/F01q2CqogrWaIEv//g3Dm6R3QuuTKS+TrbSTo=", "owner": "shazow", "repo": "foundry.nix", - "rev": "e1a08c5650e0aa82b5de659827a8881b1ff79e55", + "rev": "b3ff192f7e19785781670f7d2365bb0ad097116d", "type": "github" }, "original": { "owner": "shazow", - "ref": "monthly", "repo": "foundry.nix", "type": "github" } @@ -74,11 +73,11 @@ }, "utils": { "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 41f94c930..f3dbc7553 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; utils.url = "github:numtide/flake-utils"; - foundry.url = "github:shazow/foundry.nix/monthly"; + foundry.url = "github:shazow/foundry.nix"; }; outputs = inputs@{ self, nixpkgs, foundry, utils }: utils.lib.eachDefaultSystem (system: @@ -17,7 +17,7 @@ devShell = with pkgs; mkShell { SOLHINT_PATH = "$HOME/.solhint.json"; - SOLC_VERSION = "0.8.15"; + SOLC_VERSION = "0.8.18"; buildInputs = [ foundry.defaultPackage.${system} solc-select yarn nodejs-14_x ]; shellHook = '' diff --git a/foundry.toml b/foundry.toml index df0b7e6b4..16fcc9adc 100644 --- a/foundry.toml +++ b/foundry.toml @@ -16,7 +16,7 @@ optimizer = true # The number of optimizer runs optimizer_runs = 7500 # Whether or not to use the Yul intermediate representation compilation pipeline -via_ir = true +via_ir = false remappings = ['forge-std=lib/forge-std/src', '@openzeppelin/=node_modules/@openzeppelin'] # gas limit - max u64 diff --git a/test/YieldSpaceMath.t.sol b/test/YieldSpaceMath.t.sol index eaf5a113e..5a49d0726 100644 --- a/test/YieldSpaceMath.t.sol +++ b/test/YieldSpaceMath.t.sol @@ -5,32 +5,28 @@ import { Test } from "forge-std/Test.sol"; import { YieldSpaceMath } from "contracts/libraries/YieldSpaceMath.sol"; contract YieldSpaceMathTest is Test { - function test__calculateOutGivenIn_1() public { + function test__calculateOutGivenIn() public { assertEq( YieldSpaceMath.calculateOutGivenIn( 56.79314253e18, // shareReserves 62.38101813e18, // bondReserves 119.1741606776616e18, // bondReserveAdjustment 5.03176076e18, // amountOut - 0.08065076081220067e18, // t - 1e18, // s + 1e18 - 0.08065076081220067e18, // stretchedTimeElapsed 1e18, // c 1e18, // mu true // isBondIn ), 5.500250311701939082e18 ); - } - function test__calculateOutGivenIn_2() public { assertEq( YieldSpaceMath.calculateOutGivenIn( 61.824903300361854e18, // shareReserves 56.92761678068477e18, // bondReserves 119.1741606776616e18, // bondReserveAdjustment 5.500250311701939e18, // amountOut - 0.08065076081220067e18, // t - 1e18, // s + 1e18 - 0.08065076081220067e18, // stretchedTimeElapsed 1e18, // c 1e18, // mu false // isBondIn