Skip to content

Commit

Permalink
add foundry test for soil issuance update
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios committed Aug 13, 2024
1 parent 899534d commit ae649cc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
15 changes: 0 additions & 15 deletions protocol/contracts/beanstalk/silo/ConvertFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {LibConvertData} from "contracts/libraries/Convert/LibConvertData.sol";
import {Invariable} from "contracts/beanstalk/Invariable.sol";
import {LibRedundantMathSigned256} from "contracts/libraries/LibRedundantMathSigned256.sol";
import {LibPipelineConvert} from "contracts/libraries/Convert/LibPipelineConvert.sol";
import "hardhat/console.sol";

/**
* @author Publius, Brean, DeadManWalking, pizzaman1337, funderberker
Expand Down Expand Up @@ -72,13 +71,6 @@ contract ConvertFacet is Invariable, ReentrancyGuard {

LibConvert.ConvertParams memory cp = LibConvert.convert(convertData);

console.log(
"Data: decreaseBDV: %s, account: %s caller: %s",
cp.decreaseBDV,
cp.account,
msg.sender
);

// if the account is 0, set it to `LibTractor._user()`
// cp.account is only set upon a anti-lambda-lambda convert.
if (cp.account == address(0)) {
Expand All @@ -92,13 +84,6 @@ contract ConvertFacet is Invariable, ReentrancyGuard {
);
}

console.log(
"Data: decreaseBDV: %s, account: %s caller: %s",
cp.decreaseBDV,
cp.account,
msg.sender
);

require(cp.fromAmount > 0, "Convert: From amount is 0.");

LibSilo._mow(cp.account, cp.fromToken);
Expand Down
3 changes: 0 additions & 3 deletions protocol/contracts/libraries/Silo/LibTokenSilo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {LibBytes} from "contracts/libraries/LibBytes.sol";
import {LibGerminate} from "contracts/libraries/Silo/LibGerminate.sol";
import {LibWhitelistedTokens} from "contracts/libraries/Silo/LibWhitelistedTokens.sol";
import {LibTractor} from "contracts/libraries/LibTractor.sol";
import "hardhat/console.sol";

/**
* @title LibTokenSilo
Expand Down Expand Up @@ -360,8 +359,6 @@ library LibTokenSilo {

uint256 crateAmount = s.accts[account].deposits[depositId].amount;
crateBDV = s.accts[account].deposits[depositId].bdv;
console.log("Crate Amount: %s", crateAmount);
console.log("Account In remove deposit: %s", account);
require(amount <= crateAmount, "Silo: Crate balance too low.");

// Partial remove
Expand Down
42 changes: 42 additions & 0 deletions protocol/test/foundry/sun/Sun.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pragma abicoder v2;
import {TestHelper, LibTransfer, C} from "test/foundry/utils/TestHelper.sol";
import {MockSeasonFacet} from "contracts/mocks/mockFacets/MockSeasonFacet.sol";
import {IMockFBeanstalk as IBS} from "contracts/interfaces/IMockFBeanstalk.sol";
import {MockPump} from "contracts/mocks/well/MockPump.sol";
import {IWell, IERC20, Call} from "contracts/interfaces/basin/IWell.sol";
import {LibWhitelistedTokens} from "contracts/libraries/Silo/LibWhitelistedTokens.sol";
import {LibWellMinting} from "contracts/libraries/Minting/LibWellMinting.sol";

/**
* @notice Tests the functionality of the sun, the distrubution of beans and soil.
Expand Down Expand Up @@ -418,6 +422,32 @@ contract SunTest is TestHelper {
}
}

function test_soilBelowPeg() public {
// set inst reserves (instDeltaB: -1999936754446796632414)
setInstantaneousReserves(C.BEAN_WSTETH_WELL, 1000e18, 1000e18);
setInstantaneousReserves(C.BEAN_ETH_WELL, 1000e18, 1000e18);
int256 twaDeltaB = -1000;
uint32 currentSeason = bs.season();
vm.expectEmit();
// expect the minimum of the -twaDeltaB and -instDeltaB to be used.
emit Soil(currentSeason + 1, 1000);
season.sunSunrise(twaDeltaB, 1);
assertEq(bs.totalSoil(), 1000);
}

function test_soilBelowPegInstGtZero() public {
// set inst reserves (instDeltaB: +415127766016)
setInstantaneousReserves(C.BEAN_WSTETH_WELL, 10000e6, 10000000e18);
setInstantaneousReserves(C.BEAN_ETH_WELL, 100000e6, 10000000e18);
int256 twaDeltaB = -1000;
uint32 currentSeason = bs.season();
vm.expectEmit();
// expect the twaDeltaB to be used.
emit Soil(currentSeason + 1, 1000);
season.sunSunrise(twaDeltaB, 1);
assertEq(bs.totalSoil(), 1000);
}

////// HELPER FUNCTIONS //////

/**
Expand Down Expand Up @@ -447,4 +477,16 @@ contract SunTest is TestHelper {
soilIssued = (soilIssued * 1.5e18) / 1e18; // low podrate
}
}

function setInstantaneousReserves(address well, uint256 reserve0, uint256 reserve1) public {
Call[] memory pumps = IWell(well).pumps();
for (uint256 i = 0; i < pumps.length; i++) {
address pump = pumps[i].target;
// pass to the pump the reserves that we actually have in the well
uint256[] memory reserves = new uint256[](2);
reserves[0] = reserve0;
reserves[1] = reserve1;
MockPump(pump).setInstantaneousReserves(well, reserves);
}
}
}

0 comments on commit ae649cc

Please sign in to comment.