Skip to content

Commit

Permalink
feat: oracles with firewalls on mint and burn (#105)
Browse files Browse the repository at this point in the history
* feat: oracles with firewalls on mint and burn

* feat: oracles with target value as max

* feat: fixed tests + test on mint and burn firewalls oracles

* test updateOracle

* feat: start testing deployment

* feat: start scripts

* feat: mint and burn test done

* chore: try to fix linter issues

* feat: testing done

* format: prettier contracts

* chore : add scripts to ignored files in slither

* chore: add uri env variables to ci tests

* fix: SwapTest and SavingsTest now compiles

* fix part of the stack too deep when via-ir

* chore remap import from test

* find which test files has compilation problem

* fix all compilation tests except RedeemTest

* add back the RedeemTest

* fix redeem test compilation

* chore: setup repo inside ci

* chore: move setup repo action to actions subdirectory

* start burn protection for users

* fix firewall and user protection + tests

* feat: add back burnRatio deviation user protection

* fix burnRatio protection

* return ratio

* tests fixed

* decimal issue

* working tests

* yarn prettier

* add bERNX + new target exposures

* testing after adding bERNX

* feat: change updateOracle to only trustedSeller only

* add fork block number option

* change input to secret

* revert prev change

* add space

* fix: fix install

* update vscode settings

* reduce stack too deep

* fix burn test

* revert deadline tests changes

* feat: USDA setup (#108)

* feat: usda setup

* feat: setup  script for USDA transmuter

* feat: Morpho test

* adjusting comments

* feat: put variables in constants

* feat: upgrade tests

* feat: change some stuff

* fix tests

* feat: add keyring

* feat: update sdk

* feat: change steakUSDC fees

* fix last tests

* finish usda setup

* feat: add minter flashloan

* remove flashloan

* feat: script

* fix: lint

* fix: firewall mint steakhouse

* remove variables

* Add a test on non arbitrage Mint->Burn

* update post review

* removed checks on oracle update

* compiling version

* fix tests

* fix all tests and deploy tests

* chore: review minor changes
  • Loading branch information
GuillaumeNervoXS authored Apr 2, 2024
1 parent 61d9be3 commit ec7d7ab
Show file tree
Hide file tree
Showing 55 changed files with 3,898 additions and 462 deletions.
35 changes: 35 additions & 0 deletions .github/actions/setup-repo/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Setup repo
description: Runs all steps to setup the repo (install node_modules, build, etc...)
inputs:
registry-token:
description: 'PAT to access registries'
runs:
using: 'composite'
steps:
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=version::$(yarn -v)"
- uses: actions/setup-node@v3
with:
node-version: '20'

- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
shell: bash
run: echo "//npm.pkg.github.com/:_authToken=$GH_REGISTRY_ACCESS_TOKEN" >> .npmrc && yarn install --frozen-lockfile --verbose && rm -f .npmrc
env:
GH_REGISTRY_ACCESS_TOKEN: ${{ inputs.registry-token }}
29 changes: 26 additions & 3 deletions .github/workflows/ci-deep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
node-version: 18
cache: "yarn"

- name: Setup repo
uses: ./.github/actions/setup-repo
with:
registry-token: ${{ secrets.GH_REGISTRY_ACCESS_TOKEN }}

- name: Install dependencies
run: yarn install

Expand All @@ -55,8 +60,13 @@ jobs:
with:
version: nightly

- name: Install node_modules
run: yarn install
- name: Setup repo
uses: ./.github/actions/setup-repo
with:
registry-token: ${{ secrets.GH_REGISTRY_ACCESS_TOKEN }}

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Compile foundry
run: yarn compile --sizes
Expand Down Expand Up @@ -99,6 +109,11 @@ jobs:

- name: Run Foundry tests
run: yarn test:unit
env:
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

test-invariant:
needs: ["build", "lint"]
Expand Down Expand Up @@ -127,6 +142,10 @@ jobs:
env:
FOUNDRY_INVARIANT_RUNS: ${{ github.event.inputs.invariantRuns || '300' }}
FOUNDRY_INVARIANT_DEPTH: ${{ github.event.inputs.invariantDepth || '50' }}
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

test-fuzz:
needs: ["build", "lint"]
Expand All @@ -153,4 +172,8 @@ jobs:
- name: Run Foundry tests
run: yarn test:fuzz
env:
FOUNDRY_FUZZ_RUNS: ${{ github.event.inputs.fuzzRuns || '10000' }}
FOUNDRY_FUZZ_RUNS: ${{ github.event.inputs.fuzzRuns || '10000' }}
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}
32 changes: 27 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ jobs:
node-version: 18
cache: "yarn"

- name: Install dependencies
run: yarn install
- name: Setup repo
uses: ./.github/actions/setup-repo
with:
registry-token: ${{ secrets.GH_REGISTRY_ACCESS_TOKEN }}

- name: Run solhint
run: yarn lint:check
Expand All @@ -44,8 +46,10 @@ jobs:
with:
version: nightly

- name: Install node_modules
run: yarn install
- name: Setup repo
uses: ./.github/actions/setup-repo
with:
registry-token: ${{ secrets.GH_REGISTRY_ACCESS_TOKEN }}

- name: Compile foundry
run: yarn compile --sizes
Expand Down Expand Up @@ -88,6 +92,11 @@ jobs:

- name: Run Foundry tests
run: yarn test:unit
env:
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

test-invariant:
needs: ["build", "lint"]
Expand Down Expand Up @@ -116,6 +125,10 @@ jobs:
env:
FOUNDRY_INVARIANT_RUNS: "8"
FOUNDRY_INVARIANT_DEPTH: "256"
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

test-fuzz:
needs: ["build", "lint"]
Expand Down Expand Up @@ -143,6 +156,10 @@ jobs:
run: yarn test:fuzz
env:
FOUNDRY_FUZZ_RUNS: "5000"
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

coverage:
needs: ["build", "lint"]
Expand All @@ -169,6 +186,11 @@ jobs:

- name: "Generate the coverage report using the unit and the integration tests"
run: "yarn ci:coverage"
env:
ETH_NODE_URI_POLYGON: ${{ secrets.ETH_NODE_URI_POLYGON }}
ETH_NODE_URI_ARBITRUM: ${{ secrets.ETH_NODE_URI_ARBITRUM }}
ETH_NODE_URI_OPTIMISM: ${{ secrets.ETH_NODE_URI_OPTIMISM }}
ETH_NODE_URI_MAINNET: ${{ secrets.ETH_NODE_URI_MAINNET }}

- name: "Upload coverage report to Codecov"
uses: "codecov/codecov-action@v3"
Expand Down Expand Up @@ -217,4 +239,4 @@ jobs:
- name: "Add Slither summary"
run: |
echo "## Slither result" >> $GITHUB_STEP_SUMMARY
echo "✅ Uploaded to GitHub code scanning" >> $GITHUB_STEP_SUMMARY
echo "✅ Uploaded to GitHub code scanning" >> $GITHUB_STEP_SUMMARY
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
version = v4.7.3
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
version = v4.7.3
[submodule "lib/utils"]
path = lib/utils
url = https://github.com/AngleProtocol/utils
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@angleprotocol:registry=https://npm.pkg.github.com
23 changes: 18 additions & 5 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"plugins": [
"prettier"
],
"rules": {
"max-line-length": ["error", 120],
"max-line-length": [
"error",
120
],
"avoid-call-value": "warn",
"avoid-low-level-calls": "off",
"avoid-tx-origin": "warn",
Expand All @@ -22,7 +27,15 @@
"no-inline-assembly": "off",
"no-complex-fallback": "off",
"reason-string": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"explicit-types": ["error","explicit"]
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
],
"explicit-types": [
"error",
"explicit"
]
}
}
}
24 changes: 19 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
{
"solidity.formatter": "prettier",
"[typescript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[solidity]": {
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"editor.formatOnSave": true,
"workbench.colorCustomizations": {
"diffEditor.insertedTextBackground": "#00bb0044",
"diffEditor.removedTextBackground": "#ff000044"
},
"slither.solcPath": "",
"slither.hiddenDetectors": [],
"solidity.compileUsingRemoteVersion": "v0.8.19+commit.7dd6d404"
"solidity.compileUsingRemoteVersion": "v0.8.22",
"files.insertFinalNewline": true,
"solidity.remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"stringutils/=lib/solidity-stringutils",
"contracts/=contracts/",
"test/=test/",
"interfaces/=contracts/interfaces/",
"oz/=lib/openzeppelin-contracts/contracts/",
"oz-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"mock/=test/mock/",
"prb/math/=lib/prb-math/src/",
"borrow/=lib/borrow-contracts/contracts",
"utils/=lib/utils"
]
}
1 change: 0 additions & 1 deletion contracts/helpers/Rebalancer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.19;

import { IERC20 } from "oz/interfaces/IERC20.sol";
import { IERC20Metadata } from "oz/interfaces/IERC20Metadata.sol";
import { SafeERC20 } from "oz/token/ERC20/utils/SafeERC20.sol";
import { SafeCast } from "oz/utils/math/SafeCast.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ interface IGetters {
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData
bytes memory targetData,
bytes memory hyperparameters
);

/// @notice Returns if the associated functionality is paused or not
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/ISetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ interface ISettersGovernor {
/// @notice Sets the `oracleConfig` used to read the value of `collateral` for the mint, burn and redemption
/// operations
function setOracle(address collateral, bytes memory oracleConfig) external;

/// @notice Update oracle data for a given `collateral`
function updateOracle(address collateral) external;
}

/// @title ISettersGovernor
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/ITransmuterOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ interface ITransmuterOracle {
/// @notice Reads the oracle value for asset to use in a burn transaction as well as the ratio
/// between the current price and the target price for the asset
function readBurn() external view returns (uint256 oracleValue, uint256 ratio);

/// @notice Reads the oracle value for asset
function read() external view returns (uint256);
}
9 changes: 9 additions & 0 deletions contracts/interfaces/external/morpho/IMorphoOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.5.0;

/// @title IMorphoOracle
/// @notice Interface for the oracle contracts used within Morpho
interface IMorphoOracle {
function price() external view returns (uint256);
}
Loading

0 comments on commit ec7d7ab

Please sign in to comment.