From 9c721dbeeb68d6fadc7226ec32508dd4e9cef9ac Mon Sep 17 00:00:00 2001 From: pizzaman1337 Date: Fri, 20 Sep 2024 13:39:09 -0600 Subject: [PATCH 1/5] Test removing all deposits --- .../beanstalk/silo/SiloFacet/SiloGettersFacet.sol | 9 +++++++++ protocol/contracts/interfaces/IMockFBeanstalk.sol | 2 ++ protocol/test/foundry/Migration/ReseedState.t.sol | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/protocol/contracts/beanstalk/silo/SiloFacet/SiloGettersFacet.sol b/protocol/contracts/beanstalk/silo/SiloFacet/SiloGettersFacet.sol index b14d6245c..f3e62cf03 100644 --- a/protocol/contracts/beanstalk/silo/SiloFacet/SiloGettersFacet.sol +++ b/protocol/contracts/beanstalk/silo/SiloFacet/SiloGettersFacet.sol @@ -175,6 +175,15 @@ contract SiloGettersFacet is ReentrancyGuard { return LibBytes.packAddressAndStem(token, stem); } + /** + * @notice outputs the token and stem given a depositId. + */ + function getAddressAndStem( + uint256 depositId + ) external pure returns (address token, int96 stem) { + return LibBytes.unpackAddressAndStem(depositId); + } + /** * @notice returns the bean denominated value ("bdv") of a token amount. */ diff --git a/protocol/contracts/interfaces/IMockFBeanstalk.sol b/protocol/contracts/interfaces/IMockFBeanstalk.sol index 638a26ea7..7f59db547 100644 --- a/protocol/contracts/interfaces/IMockFBeanstalk.sol +++ b/protocol/contracts/interfaces/IMockFBeanstalk.sol @@ -991,6 +991,8 @@ interface IMockFBeanstalk { function getActiveFertilizer() external view returns (uint256); + function getAddressAndStem(uint256 depositId) external pure returns (address token, int96 stem); + function getAllBalance(address account, address token) external view returns (Balance memory b); function getAllBalances( diff --git a/protocol/test/foundry/Migration/ReseedState.t.sol b/protocol/test/foundry/Migration/ReseedState.t.sol index a9994b73c..c6cd972db 100644 --- a/protocol/test/foundry/Migration/ReseedState.t.sol +++ b/protocol/test/foundry/Migration/ReseedState.t.sol @@ -85,6 +85,7 @@ contract ReseedStateTest is TestHelper { function setUp() public { // parse accounts and populate the accounts.txt file // the number of accounts to parse, for testing purposes + // the total number of accounts is 3665 uint256 numAccounts = 10; accountNumber = parseAccounts(numAccounts); console.log("Number of accounts: ", accountNumber); @@ -338,6 +339,7 @@ contract ReseedStateTest is TestHelper { //////////////////// Account Deposits //////////////////// function test_AccountDeposits() public { + vm.pauseGasMetering(); address[] memory tokens = l2Beanstalk.getWhitelistedTokens(); // for every account @@ -375,6 +377,19 @@ contract ReseedStateTest is TestHelper { accountDepositsStorage[j].tokenDeposits[k].bdv, accountDepositsJson[j].tokenDeposits[k].bdv ); + + (address token, int96 stem) = l2Beanstalk.getAddressAndStem( + accountDepositsStorage[j].depositIds[k] + ); + + // withdraw deposit + vm.prank(account); + l2Beanstalk.withdrawDeposit( + accountDepositsStorage[j].token, + stem, + accountDepositsStorage[j].tokenDeposits[k].amount, + 0 + ); } } } From 15863c80b9533e5af3b84cdaafd3295f67768ea8 Mon Sep 17 00:00:00 2001 From: pizzaman1337 Date: Fri, 20 Sep 2024 15:30:00 -0600 Subject: [PATCH 2/5] Ensure stalk/roots/etc all zero after full removal --- .../test/foundry/Migration/ReseedState.t.sol | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/protocol/test/foundry/Migration/ReseedState.t.sol b/protocol/test/foundry/Migration/ReseedState.t.sol index c6cd972db..7bfaf4edf 100644 --- a/protocol/test/foundry/Migration/ReseedState.t.sol +++ b/protocol/test/foundry/Migration/ReseedState.t.sol @@ -86,7 +86,7 @@ contract ReseedStateTest is TestHelper { // parse accounts and populate the accounts.txt file // the number of accounts to parse, for testing purposes // the total number of accounts is 3665 - uint256 numAccounts = 10; + uint256 numAccounts = 10000; accountNumber = parseAccounts(numAccounts); console.log("Number of accounts: ", accountNumber); l2Beanstalk = IMockFBeanstalk(L2_BEANSTALK); @@ -393,6 +393,41 @@ contract ReseedStateTest is TestHelper { } } } + + // check system level stalk and roots + // todo: capture stalk/root ratio before and after + // call sunrise and see that the average grown stalk per season is updated? + + uint256 totalStalk = l2Beanstalk.totalStalk(); + assertEq(totalStalk, 0); + + uint256 totalRoots = l2Beanstalk.totalRoots(); + assertEq(totalRoots, 0); + + uint256 totalRainRoots = l2Beanstalk.totalRainRoots(); + assertEq(totalRainRoots, 0); + + uint256 getTotalBdv = l2Beanstalk.getTotalBdv(); + assertEq(getTotalBdv, 0); + + uint256[] memory depositedAmounts = l2Beanstalk.getTotalSiloDeposited(); + for (uint256 i = 0; i < depositedAmounts.length; i++) { + assertEq(depositedAmounts[i], 0); + } + + uint256[] memory depositedBdvs = l2Beanstalk.getTotalSiloDepositedBdv(); + for (uint256 i = 0; i < depositedBdvs.length; i++) { + assertEq(depositedBdvs[i], 0); + } + + // loop through whitelisted tokens + for (uint256 i = 0; i < tokens.length; i++) { + address token = whitelistedTokens[i]; + uint256 totalDeposited = l2Beanstalk.getTotalDeposited(token); + assertEq(totalDeposited, 0); + uint256 totalDepositedBdv = l2Beanstalk.getTotalDepositedBdv(token); + assertEq(totalDepositedBdv, 0); + } } //////////////////// Fertilizer //////////////////// From ec8ffac7bb743eb01ef7c84e3697f77662f48792 Mon Sep 17 00:00:00 2001 From: pizzaman1337 Date: Fri, 20 Sep 2024 17:31:00 -0600 Subject: [PATCH 3/5] Verify stalk:roots ratio is 1:1 upon reseed --- protocol/test/foundry/Migration/ReseedState.t.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/protocol/test/foundry/Migration/ReseedState.t.sol b/protocol/test/foundry/Migration/ReseedState.t.sol index 7bfaf4edf..9d5bde749 100644 --- a/protocol/test/foundry/Migration/ReseedState.t.sol +++ b/protocol/test/foundry/Migration/ReseedState.t.sol @@ -340,6 +340,16 @@ contract ReseedStateTest is TestHelper { function test_AccountDeposits() public { vm.pauseGasMetering(); + + uint256 totalStalkBefore = l2Beanstalk.totalStalk(); + assertGt(totalStalkBefore, 0); + + uint256 totalRootsBefore = l2Beanstalk.totalRoots(); + assertGt(totalRootsBefore, 0); + + // verify ratio is 1:1 on reseed + assertEq(totalStalkBefore * 1e12, totalRootsBefore); + address[] memory tokens = l2Beanstalk.getWhitelistedTokens(); // for every account From 72494bc2e3b7fb99c37974845f8346839bde146b Mon Sep 17 00:00:00 2001 From: pizzaman1337 Date: Fri, 20 Sep 2024 21:19:56 -0600 Subject: [PATCH 4/5] Plot test --- protocol/test/foundry/Migration/ReseedState.t.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protocol/test/foundry/Migration/ReseedState.t.sol b/protocol/test/foundry/Migration/ReseedState.t.sol index 9d5bde749..12ac599a5 100644 --- a/protocol/test/foundry/Migration/ReseedState.t.sol +++ b/protocol/test/foundry/Migration/ReseedState.t.sol @@ -303,6 +303,7 @@ contract ReseedStateTest is TestHelper { function test_AccountPlots() public { // test the L2 Beanstalk string memory account; + uint256 totalPlotsAmount; // for every account for (uint256 i = 0; i < accountNumber; i++) { account = vm.readLine(ACCOUNTS_PATH); @@ -332,8 +333,10 @@ contract ReseedStateTest is TestHelper { // compare the plot amount and index assertEq(accountPlotAmountJsonDecoded, plots[j].pods); assertEq(plotindexesJsonDecoded[j], plots[j].index); + totalPlotsAmount += plots[j].pods; } } + console.log("total plots amount:", totalPlotsAmount); } //////////////////// Account Deposits //////////////////// From 88c7e5a988e5c43eac005ab63994cd850e511b12 Mon Sep 17 00:00:00 2001 From: pizzaman1337 Date: Sun, 22 Sep 2024 11:53:27 -0600 Subject: [PATCH 5/5] Update comments --- protocol/test/foundry/Migration/ReseedState.t.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/protocol/test/foundry/Migration/ReseedState.t.sol b/protocol/test/foundry/Migration/ReseedState.t.sol index 12ac599a5..9fb2e4c75 100644 --- a/protocol/test/foundry/Migration/ReseedState.t.sol +++ b/protocol/test/foundry/Migration/ReseedState.t.sol @@ -407,10 +407,6 @@ contract ReseedStateTest is TestHelper { } } - // check system level stalk and roots - // todo: capture stalk/root ratio before and after - // call sunrise and see that the average grown stalk per season is updated? - uint256 totalStalk = l2Beanstalk.totalStalk(); assertEq(totalStalk, 0);