Skip to content

Commit

Permalink
add reserve length check, update forge test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Aug 18, 2024
1 parent 63027b1 commit dc494e2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
5 changes: 0 additions & 5 deletions protocol/contracts/libraries/LibLockedUnderlying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {LibRedundantMath256} from "contracts/libraries/LibRedundantMath256.sol";
import {AppStorage, LibAppStorage} from "./LibAppStorage.sol";
import {console} from "forge-std/console.sol";

/**
* @title LibLockedUnderlying
Expand All @@ -27,9 +26,6 @@ library LibLockedUnderlying {
uint256 recapPercentPaid
) external view returns (uint256 lockedUnderlying) {
AppStorage storage s = LibAppStorage.diamondStorage();
console.log("getLockedUnderlying");
console.log(s.sys.silo.unripeSettings[unripeToken].balanceOfUnderlying);
console.log(getPercentLockedUnderlying(unripeToken, recapPercentPaid));
return
s
.sys
Expand Down Expand Up @@ -67,7 +63,6 @@ library LibLockedUnderlying {
uint256 recapPercentPaid
) private view returns (uint256 percentLockedUnderlying) {
uint256 unripeSupply = IERC20(unripeToken).totalSupply().div(DECIMALS);
console.log(unripeSupply);
if (unripeSupply < 1_000_000) return 0; // If < 1_000_000 Assume all supply is unlocked.
if (unripeSupply > 90_000_000) {
if (recapPercentPaid > 0.1e6) {
Expand Down
2 changes: 0 additions & 2 deletions protocol/contracts/libraries/LibUnripe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {Call, IWell} from "contracts/interfaces/basin/IWell.sol";
import {IWellFunction} from "contracts/interfaces/basin/IWellFunction.sol";
import {LibLockedUnderlying} from "./LibLockedUnderlying.sol";
import {LibFertilizer} from "./LibFertilizer.sol";
import {console} from "forge-std/console.sol";

/**
* @title LibUnripe
Expand Down Expand Up @@ -206,7 +205,6 @@ library LibUnripe {
if (totalUsdNeeded == 0) {
return 1e6; // if zero usd needed, full recap has happened
}
console.log("total usd needed:", totalUsdNeeded);
return s.sys.fert.recapitalized.mul(DECIMALS).div(totalUsdNeeded);
}

Expand Down
4 changes: 4 additions & 0 deletions protocol/contracts/libraries/Minting/LibWellMinting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ library LibWellMinting {
try
IInstantaneousPump(pumps[0].target).readInstantaneousReserves(well, pumps[0].data)
returns (uint[] memory instReserves) {
// if well is not initialized, return 0.
if (instReserves.length == 0) {
return 0;
}
// well, reserves, snapshot, lookback
(int256 deltaB, , , ) = getDeltaBInfoFromWell(well, instReserves, new bytes(0), 0);
return (deltaB);
Expand Down
7 changes: 2 additions & 5 deletions protocol/test/foundry/silo/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,20 @@ contract OracleTest is TestHelper {
_ethChainlinkOracle,
_ethTimeout,
_xEthChainlinkOracle,
_xEthTimeout,
_token
_xEthTimeout
);

(
address ethChainlinkOracle,
uint256 ethTimeout,
address xEthChainlinkOracle,
uint256 xEthTimeout,
address token
uint256 xEthTimeout
) = deployedOracle.decodeData(data);

assertEq(ethChainlinkOracle, _ethChainlinkOracle);
assertEq(ethTimeout, _ethTimeout);
assertEq(xEthChainlinkOracle, _xEthChainlinkOracle);
assertEq(xEthTimeout, _xEthTimeout);
assertEq(token, _token);
}

function testGetOracleImplementationForToken() public {
Expand Down
4 changes: 2 additions & 2 deletions protocol/test/foundry/sun/Gauge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ contract GaugeTest is TestHelper {
uint256 totalUnderlying = bs.getTotalUnderlying(C.UNRIPE_BEAN);
assertEq(
bs.getLockedBeansUnderlyingUnripeBean(),
(totalUnderlying * 0.4363321054081788e18) / 1e18
(totalUnderlying * 0.4587658967980477e18) / 1e18
);
}

Expand All @@ -314,7 +314,7 @@ contract GaugeTest is TestHelper {
burntBeans = bound(burntBeans, 0, 10000000e6 - 1e6);
uint256 lockedBeansPercent = burnBeansAndCheckLockedBeans(burntBeans);
// 1e-12% precision.
assertApproxEqRel(lockedBeansPercent, 0.4587658968e18, 1e6); // see {LibLockedUnderlying}
assertApproxEqRel(lockedBeansPercent, 0.458765896798e18, 1e6); // see {LibLockedUnderlying}
}

function test_lockedBeansSupply5Million(uint256 burntBeans) public {
Expand Down
6 changes: 5 additions & 1 deletion protocol/test/foundry/utils/BasinDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {C} from "contracts/C.sol";
////// INTERFACES //////
import {Call, IAquifer} from "contracts/interfaces/basin/IAquifer.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {MockPump} from "contracts/mocks/well/MockPump.sol";

/**
* @title TestHelper
* @title BasinDeployer
* @author Brean
* @notice Test helper contract for Beanstalk tests.
*/
Expand Down Expand Up @@ -216,6 +217,9 @@ contract BasinDeployer is Utils {
address[2] memory wellAddressAndNonBeanToken,
address pump
) internal returns (address) {
// initialize pump with 0 values.
uint256[] memory _init0 = new uint256[](2);
MockPump(pump).updateNoBytes(wellAddressAndNonBeanToken[0], _init0);
return
deployWellAtAddressNoData(
wellAddressAndNonBeanToken[0],
Expand Down

0 comments on commit dc494e2

Please sign in to comment.