Skip to content

Commit

Permalink
✂️ remove edge case docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD authored and MerlinEgalite committed May 28, 2022
1 parent 50823bc commit e3ed4c4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 185 deletions.
130 changes: 0 additions & 130 deletions edge-cases-docs/PROTOCOL.md

This file was deleted.

53 changes: 0 additions & 53 deletions edge-cases-docs/SCENARIO.md

This file was deleted.

6 changes: 6 additions & 0 deletions test-foundry/compound/TestBorrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./setup/TestSetup.sol";
contract TestBorrow is TestSetup {
using CompoundMath for uint256;

// The borrower tries to borrow more than his collateral allows, the transaction reverts.
function testBorrow1() public {
uint256 usdcAmount = to6Decimals(10_000 ether);

Expand All @@ -18,6 +19,7 @@ contract TestBorrow is TestSetup {
borrower1.borrow(cDai, borrowable + 1e12);
}

// There are no available suppliers: all of the borrowed amount is `onPool`.
function testBorrow2() public {
uint256 amount = 10000 ether;

Expand All @@ -33,6 +35,7 @@ contract TestBorrow is TestSetup {
assertEq(inP2P, 0);
}

// There is 1 available supplier, he matches 100% of the borrower liquidity, everything is `inP2P`.
function testBorrow3() public {
uint256 amount = 10_000 ether;

Expand Down Expand Up @@ -66,6 +69,7 @@ contract TestBorrow is TestSetup {
testEquality(inP2P, expectedBorrowInP2P, "Borrower1 in peer-to-peer");
}

// There is 1 available supplier, he doesn't match 100% of the borrower liquidity. Borrower `inP2P` is equal to the supplier previous amount `onPool`, the rest is set `onPool`.
function testBorrow4() public {
uint256 amount = 10_000 ether;

Expand All @@ -92,6 +96,7 @@ contract TestBorrow is TestSetup {
testEquality(onPool, expectedBorrowOnPool, "Borrower1 on pool");
}

// There are NMAX (or less) supplier that match the borrowed amount, everything is `inP2P` after NMAX (or less) match.
function testBorrow5() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down Expand Up @@ -150,6 +155,7 @@ contract TestBorrow is TestSetup {
assertEq(onPool, 0, "Borrower1 on pool");
}

// The NMAX biggest supplier don't match all of the borrowed amount, after NMAX match, the rest is borrowed and set `onPool`. ⚠️ most gas expensive borrow scenario.
function testBorrow6() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down
4 changes: 2 additions & 2 deletions test-foundry/compound/TestLiquidate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./setup/TestSetup.sol";
contract TestLiquidate is TestSetup {
using CompoundMath for uint256;

// 5.1 - A user liquidates a borrower that has enough collateral to cover for his debt, the transaction reverts.
// A user liquidates a borrower that has enough collateral to cover for his debt, the transaction reverts.
function testShouldNotBePossibleToLiquidateUserAboveWater() public {
uint256 amount = 10_000 ether;
uint256 collateral = 2 * amount;
Expand All @@ -24,7 +24,7 @@ contract TestLiquidate is TestSetup {
liquidator.liquidate(cDai, cUsdc, address(borrower1), toRepay);
}

// 5.2 - A user liquidates a borrower that has not enough collateral to cover for his debt.
// A user liquidates a borrower that has not enough collateral to cover for his debt.
function testShouldLiquidateUser() public {
uint256 collateral = 100_000 ether;

Expand Down
5 changes: 5 additions & 0 deletions test-foundry/compound/TestRepay.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./setup/TestSetup.sol";
contract TestRepay is TestSetup {
using CompoundMath for uint256;

// The borrower repays no more than his `onPool` balance. The liquidity is repaid on his `onPool` balance.
function testRepay1() public {
uint256 amount = 10_000 ether;
uint256 collateral = 2 * amount;
Expand Down Expand Up @@ -43,6 +44,7 @@ contract TestRepay is TestSetup {
testEquality(balanceBefore - balanceAfter, amount);
}

// There is a borrower `onPool` available to replace him `inP2P`. First, his debt `onPool` is repaid, his matched debt is replaced by the available borrower up to his repaid amount.
function testRepay2_1() public {
uint256 suppliedAmount = 10000 ether;
uint256 borrowedAmount = 2 * suppliedAmount;
Expand Down Expand Up @@ -115,6 +117,7 @@ contract TestRepay is TestSetup {
assertEq(onPoolSupplier, 0, "supplier on pool 2");
}

// There are NMAX (or less) borrowers `onPool` available to replace him `inP2P`, they borrow enough to cover for the repaid liquidity. First, his debt `onPool` is repaid, his matched liquidity is replaced by NMAX (or less) borrowers up to his repaid amount.
function testRepay2_2() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down Expand Up @@ -220,6 +223,7 @@ contract TestRepay is TestSetup {
}
}

// There are no borrowers `onPool` to replace him `inP2P`. After repaying the amount `onPool`, his P2P credit line will be broken and the corresponding supplier(s) will be unmatched, and placed on pool.
function testRepay2_3() public {
uint256 suppliedAmount = 10_000 ether;
uint256 borrowedAmount = 2 * suppliedAmount;
Expand Down Expand Up @@ -287,6 +291,7 @@ contract TestRepay is TestSetup {
assertEq(onPoolSupplier, expectedSupplyBalanceOnPool, "supplier on pool 2");
}

// The borrower is matched to 2 x NMAX suppliers. There are NMAX borrowers `onPool` available to replace him `inP2P`, they don't supply enough to cover for the repaid liquidity. First, the `onPool` liquidity is repaid, then we proceed to NMAX `match borrower`. Finally, we proceed to NMAX `unmatch supplier` for an amount equal to the remaining to withdraw.
function testRepay2_4() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down
5 changes: 5 additions & 0 deletions test-foundry/compound/TestSupply.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./setup/TestSetup.sol";
contract TestSupply is TestSetup {
using CompoundMath for uint256;

// There are no available borrowers: all of the supplied amount is supplied to the pool and set `onPool`.
function testSupply1() public {
uint256 amount = 10000 ether;

Expand All @@ -23,6 +24,7 @@ contract TestSupply is TestSetup {
assertEq(inP2P, 0, "in peer-to-peer");
}

// There is 1 available borrower, he matches 100% of the supplier liquidity, everything is `inP2P`.
function testSupply2() public {
uint256 amount = 10_000 ether;

Expand Down Expand Up @@ -61,6 +63,7 @@ contract TestSupply is TestSetup {
assertEq(inP2PBorrower, expectedBorrowBalanceInP2P, "borrower in P2P");
}

// There is 1 available borrower, he doesn't match 100% of the supplier liquidity. Supplier's balance `inP2P` is equal to the borrower previous amount `onPool`, the rest is set `onPool`.
function testSupply3() public {
uint256 amount = 10_000 ether;

Expand Down Expand Up @@ -91,6 +94,7 @@ contract TestSupply is TestSetup {
assertEq(inP2PBorrower, expectedInP2P, "in peer-to-peer borrower");
}

// There are NMAX (or less) borrowers that match the supplied amount, everything is `inP2P` after NMAX (or less) match.
function testSupply4() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down Expand Up @@ -138,6 +142,7 @@ contract TestSupply is TestSetup {
assertEq(onPool, 0, "on pool");
}

// The NMAX biggest borrowers don't match all of the supplied amount, after NMAX match, the rest is supplied and set `onPool`. ⚠️ most gas expensive supply scenario.
function testSupply5() public {
setDefaultMaxGasForMatchingHelper(
type(uint64).max,
Expand Down
Loading

0 comments on commit e3ed4c4

Please sign in to comment.