Skip to content

Commit

Permalink
Morpho - Add missing tokens to deployment and expand unit tests (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr authored Aug 1, 2023
1 parent e92b43a commit 3c20f04
Show file tree
Hide file tree
Showing 18 changed files with 2,239 additions and 1,778 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn devchain &
env:
MAINNET_RPC_URL: https://eth-mainnet.alchemyapi.io/v2/${{ secrets.ALCHEMY_MAINNET_KEY }}
Expand All @@ -37,7 +36,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn lint

plugin-tests:
Expand All @@ -50,7 +48,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:plugins
- name: 'Cache hardhat network fork'
uses: actions/cache@v3
Expand All @@ -76,7 +73,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:p0
env:
NODE_OPTIONS: '--max-old-space-size=8192'
Expand All @@ -91,7 +87,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:p1
env:
NODE_OPTIONS: '--max-old-space-size=8192'
Expand All @@ -106,7 +101,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:scenario
env:
NODE_OPTIONS: '--max-old-space-size=8192'
Expand All @@ -121,7 +115,6 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:extreme
- name: 'Cache hardhat network fork'
uses: actions/cache@v3
Expand Down Expand Up @@ -157,7 +150,6 @@ jobs:
hardhat-network-fork-${{ runner.os }}-
hardhat-network-fork-
- run: yarn install --immutable
- run: yarn compile
- run: yarn test:integration
env:
NODE_OPTIONS: '--max-old-space-size=8192'
Expand Down
3 changes: 3 additions & 0 deletions common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export interface ITokens {
maUSDC?: string
maUSDT?: string
maDAI?: string
maWBTC?: string
maWETH?: string
maStETH?: string
}

export interface IFeeds {
Expand Down
6 changes: 3 additions & 3 deletions contracts/facade/FacadeRead.sol
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ contract FacadeRead is IFacadeRead {
uint192 uoaHeldInBaskets; // {UoA}
{
(address[] memory basketERC20s, uint256[] memory quantities) = rToken
.main()
.basketHandler()
.quote(basketsNeeded, FLOOR);
.main()
.basketHandler()
.quote(basketsNeeded, FLOOR);

IAssetRegistry reg = rToken.main().assetRegistry();
IBackingManager bm = rToken.main().backingManager();
Expand Down
2 changes: 1 addition & 1 deletion contracts/p0/BackingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract BackingManagerP0 is TradingP0, IBackingManager {

BasketRange memory basketsHeld = main.basketHandler().basketsHeldBy(address(this));
(bool doTrade, TradeRequest memory req, TradePrices memory prices) = TradingLibP0
.prepareRecollateralizationTrade(this, basketsHeld);
.prepareRecollateralizationTrade(this, basketsHeld);

if (doTrade) {
// Seize RSR if needed
Expand Down
4 changes: 2 additions & 2 deletions contracts/p0/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {

// {tok} = {BU} * {ref/BU} / {ref/tok}
quantities[i] = amount
.safeMulDiv(refAmtsAll[i], collsAll[i].refPerTok(), FLOOR)
.shiftl_toUint(int8(collsAll[i].erc20Decimals()), FLOOR);
.safeMulDiv(refAmtsAll[i], collsAll[i].refPerTok(), FLOOR)
.shiftl_toUint(int8(collsAll[i].erc20Decimals()), FLOOR);
// marginally more penalizing than its sibling calculation that uses _quantity()
// because does not intermediately CEIL as part of the division
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/p0/RToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ contract RTokenP0 is ComponentP0, ERC20PermitUpgradeable, IRToken {
}

(address[] memory erc20s, uint256[] memory amounts) = main
.basketHandler()
.quoteCustomRedemption(basketNonces, portions, basketsRedeemed);
.basketHandler()
.quoteCustomRedemption(basketNonces, portions, basketsRedeemed);

// === Save initial recipient balances ===

Expand Down
17 changes: 7 additions & 10 deletions contracts/p1/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,8 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler {

// {qTok} = {tok/BU} * {BU} * {tok} * {qTok/tok}
quantities[i] = _quantity(basket.erc20s[i], coll)
.safeMul(amount, rounding)
.shiftl_toUint(
int8(IERC20Metadata(address(basket.erc20s[i])).decimals()),
rounding
);
.safeMul(amount, rounding)
.shiftl_toUint(int8(IERC20Metadata(address(basket.erc20s[i])).decimals()), rounding);
}
}

Expand Down Expand Up @@ -461,8 +458,8 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler {

// {tok} = {BU} * {ref/BU} / {ref/tok}
quantities[i] = amount
.safeMulDiv(refAmtsAll[i], collsAll[i].refPerTok(), FLOOR)
.shiftl_toUint(int8(collsAll[i].erc20Decimals()), FLOOR);
.safeMulDiv(refAmtsAll[i], collsAll[i].refPerTok(), FLOOR)
.shiftl_toUint(int8(collsAll[i].erc20Decimals()), FLOOR);
// marginally more penalizing than its sibling calculation that uses _quantity()
// because does not intermediately CEIL as part of the division
}
Expand Down Expand Up @@ -608,9 +605,9 @@ contract BasketHandlerP1 is ComponentP1, IBasketHandler {

// {tok} = {BU} * {ref/BU} / {ref/tok}
quantities[i] = b
.refAmts[erc20s[i]]
.safeDiv(ICollateral(address(asset)).refPerTok(), FLOOR)
.shiftl_toUint(int8(asset.erc20Decimals()), FLOOR);
.refAmts[erc20s[i]]
.safeDiv(ICollateral(address(asset)).refPerTok(), FLOOR)
.shiftl_toUint(int8(asset.erc20Decimals()), FLOOR);
} catch (bytes memory errData) {
// untested:
// OOG pattern tested in other contracts, cost to test here is high
Expand Down
2 changes: 1 addition & 1 deletion contracts/plugins/assets/OracleLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library OracleLib {
returns (uint192)
{
(uint80 roundId, int256 p, , uint256 updateTime, uint80 answeredInRound) = chainlinkFeed
.latestRoundData();
.latestRoundData();

if (updateTime == 0 || answeredInRound < roundId) {
revert StalePrice();
Expand Down
9 changes: 6 additions & 3 deletions contracts/plugins/assets/morpho-aave/MorphoFiatCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { shiftl_toFix, FIX_ONE } from "../../../libraries/Fixed.sol";
contract MorphoFiatCollateral is AppreciatingFiatCollateral {
using OracleLib for AggregatorV3Interface;

MorphoTokenisedDeposit public immutable vault;
uint256 private immutable oneShare;
int8 private immutable refDecimals;

Expand All @@ -29,13 +28,17 @@ contract MorphoFiatCollateral is AppreciatingFiatCollateral {
AppreciatingFiatCollateral(config, revenueHiding)
{
require(address(config.erc20) != address(0), "missing erc20");
vault = MorphoTokenisedDeposit(address(config.erc20));
MorphoTokenisedDeposit vault = MorphoTokenisedDeposit(address(config.erc20));
oneShare = 10**vault.decimals();
refDecimals = int8(uint8(IERC20Metadata(vault.asset()).decimals()));
}

/// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens
function _underlyingRefPerTok() internal view override returns (uint192) {
return shiftl_toFix(vault.convertToAssets(oneShare), -refDecimals);
return
shiftl_toFix(
MorphoTokenisedDeposit(address(erc20)).convertToAssets(oneShare),
-refDecimals
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract MorphoNonFiatCollateral is MorphoFiatCollateral {
uint192 pegPrice
)
{
// {tar/ref} Get current market peg ({btc/wbtc})
// {tar/ref} Get current market peg
pegPrice = targetUnitChainlinkFeed.price(targetUnitOracleTimeout);

// {UoA/tok} = {UoA/ref} * {ref/tok}
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const config: HardhatUserConfig = {
mocha: {
timeout: TIMEOUT,
slow: 1000,
retries: 3
},
contractSizer: {
alphaSort: false,
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"test:extreme:integration": "FORK=1 EXTREME=1 PROTO_IMPL=1 npx hardhat test test/integration/**/*.test.ts",
"test:unit": "yarn test:plugins && yarn test:p0 && yarn test:p1",
"test:fast": "bash tools/fast-test.sh",
"test:p0": "PROTO_IMPL=0 hardhat test test/*.test.ts",
"test:p1": "PROTO_IMPL=1 hardhat test test/*.test.ts",
"test:plugins": "hardhat test test/{libraries,plugins}/*.test.ts",
"test:p0": "PROTO_IMPL=0 hardhat test test/*.test.ts --parallel",
"test:p1": "PROTO_IMPL=1 hardhat test test/*.test.ts --parallel",
"test:plugins": "hardhat test test/{libraries,plugins}/*.test.ts --parallel",
"test:plugins:integration": "PROTO_IMPL=1 FORK=1 hardhat test test/plugins/individual-collateral/**/*.test.ts",
"test:integration": "PROTO_IMPL=1 FORK=1 hardhat test test/integration/**/*.test.ts",
"test:scenario": "PROTO_IMPL=1 hardhat test test/scenario/*.test.ts",
"test:integration": "PROTO_IMPL=1 FORK=1 hardhat test test/integration/**/*.test.ts --parallel",
"test:scenario": "PROTO_IMPL=1 hardhat test test/scenario/*.test.ts --parallel",
"test:gas": "yarn test:gas:protocol && yarn test:gas:integration",
"test:gas:protocol": "REPORT_GAS=1 PROTO_IMPL=1 hardhat test test/{libraries,plugins,scenario}/*.test.ts test/*.test.ts",
"test:gas:integration": "FORK=1 REPORT_GAS=1 PROTO_IMPL=1 hardhat test test/integration/**/*.test.ts",
Expand Down Expand Up @@ -68,21 +68,21 @@
"@types/lodash": "^4.14.177",
"@types/mocha": "^9.0.0",
"@types/node": "^12.20.37",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@typescript-eslint/eslint-plugin": "5.17.0",
"@typescript-eslint/parser": "5.17.0",
"axios": "^0.24.0",
"bignumber.js": "^9.1.1",
"caip": "^1.1.0",
"chai": "^4.3.4",
"decimal.js": "^10.4.3",
"dotenv": "^16.0.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint": "8.14.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-promise": "6.0.0",
"eth-permit": "^0.2.1",
"ethers": "^5.7.2",
"fast-check": "^2.24.0",
Expand All @@ -96,9 +96,9 @@
"lodash.get": "^4.4.2",
"mocha-chai-jest-snapshot": "^1.1.3",
"prettier": "2.5.1",
"prettier-plugin-solidity": "^1.0.0-beta.13",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5",
"prettier-plugin-solidity": "1.0.0-beta.13",
"solhint": "3.3.6",
"solhint-plugin-prettier": "0.0.5",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.4.0",
"tsconfig-paths": "^4.1.0",
Expand Down
Loading

0 comments on commit 3c20f04

Please sign in to comment.