Skip to content

Commit

Permalink
Merge pull request #839 from morpho-org/merge/main-dev-2
Browse files Browse the repository at this point in the history
Sync `dev`
  • Loading branch information
Rubilmax authored May 15, 2023
2 parents affa6a6 + ae333a1 commit 95a79d0
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 438 deletions.
63 changes: 15 additions & 48 deletions .github/workflows/forge-doc.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,32 @@
name: Forge docs
name: Autogenerated documentation

on:
push:
branches:
- main

jobs:
forge-doc:
name: Generation
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
ssh-key: ${{ secrets.MACHINE_USER_PRIVATE_KEY }}

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Generate docs
run: forge doc --build
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: docs-foundry
path: docs/book/

deploy:
needs: forge-doc

name: Deployment
jobs:
forge-docs:
runs-on: ubuntu-latest

environment:
name: docs
url: https://developers-aavev3.morpho.xyz

steps:
- name: Download docs
uses: actions/download-artifact@v3
- uses: actions/checkout@v3
with:
name: docs-foundry
path: docs/
submodules: recursive

- name: Setup AWS credentials
uses: aws-actions/configure-aws-credentials@v2
- name: Generate & upload forge docs
uses: morpho-labs/[email protected]
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-s3-bucket: ${{ secrets.AWS_S3_BUCKET }}
aws-cloudfront-distribution-id: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ vars.AWS_SESSION_NAME }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Upload docs to S3
run: aws s3 sync ./docs s3://$BUCKET --delete --acl public-read
env:
BUCKET: ${{ secrets.AWS_S3_BUCKET }}

- name: Invalidate CloudFront cache
run: aws cloudfront create-invalidation --distribution-id $DISTRIBUTION --paths "/*"
env:
DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
s3-acl: private
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ You can also send an email to [[email protected]](mailto:[email protected])

### Morpho-Aave-V3 (Ethereum)

- Morpho Proxy:
- Morpho Implementation:
- PositionsManager:
- Morpho Proxy: [0x33333aea097c193e66081e930c33020272b33333](https://etherscan.io/address/0x33333aea097c193e66081e930c33020272b33333)
- Morpho Implementation: [0xcb5309bdda3463ece2d020c9d0564a95c5a90b53](https://etherscan.io/address/0xcb5309bdda3463ece2d020c9d0564a95c5a90b53)
- PositionsManager: [0x4592e45e0c5DbEe94a135720cCfF2e4353dAc6De](https://etherscan.io/address/0x4592e45e0c5DbEe94a135720cCfF2e4353dAc6De)

### Common (Ethereum)

Expand Down
5 changes: 0 additions & 5 deletions config/ConfigLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ library ConfigLib {
string internal constant LSD_NATIVES_PATH = "$.lsdNatives";
string internal constant MARKETS_PATH = "$.markets";
string internal constant MORPHO_DAO_PATH = "$.morphoDao";
string internal constant REWARDS_CONTROLLER_PATH = "$.rewardsController";

function getAddress(Config storage config, string memory key) internal returns (address) {
return config.json.readAddress(string.concat("$.", key));
Expand Down Expand Up @@ -50,10 +49,6 @@ library ConfigLib {
return config.json.readAddress(MORPHO_DAO_PATH);
}

function getRewardsController(Config storage config) internal returns (address) {
return config.json.readAddress(REWARDS_CONTROLLER_PATH);
}

function getWrappedNative(Config storage config) internal returns (address) {
return getAddress(config, config.json.readString(WRAPPED_NATIVE_PATH));
}
Expand Down
1 change: 0 additions & 1 deletion config/avalanche-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"rpcAlias": "avalanche",
"forkBlockNumber": 24800000,
"addressesProvider": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
"rewardsController": "0x929EC64c34a17401F460460D4B9390518E5B473e",
"morphoDao": "0x0000000000000000000000000000000000000000",
"DAI": "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
"USDC": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
"postinstall": "husky install"
},
"devDependencies": {
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"husky": "8.0.2",
"lint-staged": "^13.1.0",
"prettier": "^2.8.1"
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8"
},
"lint-staged": {
"*.sol": "forge fmt",
"*.json": "yarn prettier",
"*.yml": "yarn prettier"
"*.json": "prettier",
"*.yml": "prettier"
},
"commitlint": {
"extends": [
Expand Down
14 changes: 6 additions & 8 deletions test/helpers/ForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configurati
import {PermitHash} from "@permit2/libraries/PermitHash.sol";
import {IAllowanceTransfer, AllowanceTransfer} from "@permit2/AllowanceTransfer.sol";

import {RewardsControllerMock} from "test/mocks/RewardsControllerMock.sol";
import {PriceOracleSentinelMock} from "test/mocks/PriceOracleSentinelMock.sol";
import {AaveOracleMock} from "test/mocks/AaveOracleMock.sol";
import {PoolAdminMock} from "test/mocks/PoolAdminMock.sol";
Expand Down Expand Up @@ -62,14 +61,16 @@ contract ForkTest is BaseTest, Configured {
IACLManager internal aclManager;
IPoolConfigurator internal poolConfigurator;
IPoolDataProvider internal poolDataProvider;
IRewardsController internal rewardsController;
IPoolAddressesProvider internal addressesProvider;
address internal morphoDao;

address internal morphoDao;
address internal aclAdmin;
address internal emissionManager;

AaveOracleMock internal oracle;
PoolAdminMock internal poolAdmin;
PriceOracleSentinelMock internal oracleSentinel;
IRewardsController internal rewardsController;

uint256 internal snapshotId = type(uint256).max;

Expand All @@ -80,7 +81,6 @@ contract ForkTest is BaseTest, Configured {
_mockPoolAdmin();
_mockOracle();
_mockOracleSentinel();
_mockRewardsController();

deal(address(this), type(uint128).max);
_setBalances(address(this), type(uint96).max);
Expand All @@ -104,6 +104,8 @@ contract ForkTest is BaseTest, Configured {
aclManager = IACLManager(addressesProvider.getACLManager());
poolConfigurator = IPoolConfigurator(addressesProvider.getPoolConfigurator());
poolDataProvider = IPoolDataProvider(addressesProvider.getPoolDataProvider());
rewardsController = IRewardsController(addressesProvider.getAddress(keccak256("INCENTIVES_CONTROLLER")));
emissionManager = rewardsController.getEmissionManager();
}

function _label() internal virtual {
Expand Down Expand Up @@ -148,10 +150,6 @@ contract ForkTest is BaseTest, Configured {
addressesProvider.setPriceOracleSentinel(address(oracleSentinel));
}

function _mockRewardsController() internal {
rewardsController = IRewardsController(new RewardsControllerMock());
}

function _setBalances(address user, uint256 balance) internal {
for (uint256 i; i < allUnderlyings.length; ++i) {
address underlying = allUnderlyings[i];
Expand Down
14 changes: 13 additions & 1 deletion test/helpers/IntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,21 @@ contract IntegrationTest is ForkTest {
address onBehalf,
address receiver,
uint256 maxIterations
) internal returns (uint256 borrowed) {
) internal returns (uint256) {
oracle.setAssetPrice(market.underlying, 0);

return _borrowPriceZero(borrower, market, amount, onBehalf, receiver, maxIterations);
}

/// @dev Borrows a zero-priced asset from `user` on behalf of `onBehalf`.
function _borrowPriceZero(
address borrower,
TestMarket storage market,
uint256 amount,
address onBehalf,
address receiver,
uint256 maxIterations
) internal returns (uint256 borrowed) {
vm.prank(borrower);
borrowed = morpho.borrow(market.underlying, amount, onBehalf, receiver, maxIterations);

Expand Down
10 changes: 8 additions & 2 deletions test/helpers/InternalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ contract InternalTest is ForkTest, Morpho {
using ConfigLib for Config;

address internal constant POSITIONS_MANAGER = address(0xCA11);
bytes32 internal constant INITIALIZED_SLOT = bytes32(uint256(57));
bytes32 internal initializedSlot;

constructor() Morpho() {
assembly {
sstore(initializedSlot.slot, sub(_pool.slot, 151)) // All other storage variables are private and their storage slot thus cannot be dynamically accessed.
}
}

function setUp() public virtual override {
super.setUp();

vm.store(address(this), INITIALIZED_SLOT, 0); // Re-enable initialization.
vm.store(address(this), initializedSlot, 0); // Re-enable initialization.
this.initialize(
config.getAddressesProvider(),
uint8(vm.envOr("E_MODE_CATEGORY_ID", uint256(0))),
Expand Down
34 changes: 21 additions & 13 deletions test/integration/TestIntegrationBorrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowPool(market, amount, onBehalf, receiver, test);

Expand All @@ -167,6 +168,8 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.SupplyPositionUpdated(address(promoter1), market.underlying, 0, 0);

Expand All @@ -176,8 +179,7 @@ contract TestIntegrationBorrow is IntegrationTest {
vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowP2P(market, amount, onBehalf, receiver, test);
}
Expand All @@ -198,6 +200,8 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, true, address(morpho));
emit Events.IdleSupplyUpdated(market.underlying, 0);

Expand All @@ -207,8 +211,7 @@ contract TestIntegrationBorrow is IntegrationTest {
vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowP2P(market, amount, onBehalf, receiver, test);
}
Expand All @@ -232,11 +235,12 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowPool(market, amount, onBehalf, receiver, test);

Expand All @@ -259,6 +263,8 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.P2PSupplyDeltaUpdated(market.underlying, 0);

Expand All @@ -268,8 +274,7 @@ contract TestIntegrationBorrow is IntegrationTest {
vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowP2P(market, amount, onBehalf, receiver, test);
}
Expand Down Expand Up @@ -298,11 +303,12 @@ contract TestIntegrationBorrow is IntegrationTest {

test.balanceBefore = ERC20(market.underlying).balanceOf(receiver);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.Borrowed(address(user), onBehalf, receiver, market.underlying, 0, 0, 0);

test.borrowed =
_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);
test.borrowed = _borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS);

test = _assertBorrowPool(market, amount, onBehalf, receiver, test);

Expand Down Expand Up @@ -442,10 +448,12 @@ contract TestIntegrationBorrow is IntegrationTest {

Types.Indexes256 memory futureIndexes = morpho.updatedIndexes(market.underlying);

oracle.setAssetPrice(market.underlying, 0);

vm.expectEmit(true, true, true, false, address(morpho));
emit Events.IndexesUpdated(market.underlying, 0, 0, 0, 0);

_borrowWithoutCollateral(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS); // 100% pool.
_borrowPriceZero(address(user), market, amount, onBehalf, receiver, DEFAULT_MAX_ITERATIONS); // 100% pool.

_assertMarketUpdatedIndexes(morpho.market(market.underlying), futureIndexes);
}
Expand Down
Loading

0 comments on commit 95a79d0

Please sign in to comment.