Skip to content

Commit

Permalink
update gauge tests, update oracle depoyer
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Aug 18, 2024
1 parent c03c684 commit 63027b1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 56 deletions.
12 changes: 5 additions & 7 deletions protocol/contracts/ecosystem/oracles/LSDChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ contract LSDChainlinkOracle {
address ethChainlinkOracle,
uint256 ethTimeout,
address xEthChainlinkOracle,
uint256 xEthTimeout,
address token
uint256 xEthTimeout
)
{
(ethChainlinkOracle, ethTimeout, xEthChainlinkOracle, xEthTimeout, token) = abi.decode(
(ethChainlinkOracle, ethTimeout, xEthChainlinkOracle, xEthTimeout) = abi.decode(
data,
(address, uint256, address, uint256, address)
(address, uint256, address, uint256)
);
}

Expand All @@ -53,9 +52,8 @@ contract LSDChainlinkOracle {
address ethChainlinkOracle,
uint256 ethTimeout,
address xEthChainlinkOracle,
uint256 xEthTimeout,
address token
) = abi.decode(data, (address, uint256, address, uint256, address));
uint256 xEthTimeout
) = abi.decode(data, (address, uint256, address, uint256));

// get the price of xETH/ETH or ETH/xETH, depending on decimals.
uint256 xEthEthPrice = LibChainlinkOracle.getTokenPrice(
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/libraries/LibLockedUnderlying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ 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: 2 additions & 0 deletions protocol/contracts/libraries/LibUnripe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 @@ -205,6 +206,7 @@ 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
28 changes: 4 additions & 24 deletions protocol/test/foundry/silo/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,11 @@ contract OracleTest is TestHelper {
// deploy new staking eth derivative.
address token = address(new MockToken("StakingETH2", "stETH2"));

// deploy new staking eth oracle contract
address oracleAddress = address(new LSDChainlinkOracle());

address _ethChainlinkOracle = C.ETH_USD_CHAINLINK_PRICE_AGGREGATOR;
uint256 _ethTimeout = 3600 * 4;
address _xEthChainlinkOracle = address(oracle);
uint256 _xEthTimeout = 3600 * 4;
address _token = token;

// add oracle implementation to beanstalk:
vm.prank(BEANSTALK);
bs.updateOracleImplementationForToken(
token,
IMockFBeanstalk.Implementation(
oracleAddress,
LSDChainlinkOracle.getPrice.selector,
bytes1(0x00),
abi.encode(
_ethChainlinkOracle,
_ethTimeout,
_xEthChainlinkOracle,
_xEthTimeout,
_token
)
)
setupLSDChainlinkOracleForToken(
token, // staking eth 2
address(oracle), // mock chainlink aggregator
3600 * 4 // 4 hours
);
return token;
}
Expand Down
16 changes: 8 additions & 8 deletions protocol/test/foundry/sun/Gauge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,22 @@ contract GaugeTest is TestHelper {
function test_lockedBeansSupply10Million(uint256 burntBeans) public {
initializeLockedBeans();
// initial supply is 20 million urBean.
// deduct 10m < x< 15m and verify that locked beans amount are within a range.
burntBeans = bound(burntBeans, 10000000e6 + 1e6, 15000000e6 - 1e6);
// deduct 0 < x< 10m and verify that locked beans amount are within a range.
burntBeans = bound(burntBeans, 0, 10000000e6 - 1e6);
uint256 lockedBeansPercent = burnBeansAndCheckLockedBeans(burntBeans);
// 1e-12% precision.
assertApproxEqRel(lockedBeansPercent, 0.5156047910307769e18, 1e6); // see {LibLockedUnderlying}
assertApproxEqRel(lockedBeansPercent, 0.4587658968e18, 1e6); // see {LibLockedUnderlying}
}

function test_lockedBeansSupply5Million(uint256 burntBeans) public {
initializeLockedBeans();

// initial supply is 20 million urBean.
// deduct 15m < x< 19m and verify that locked beans amount are within a range.
burntBeans = bound(burntBeans, 15000000e6 + 1e6, 19000000e6 - 1e6);
// deduct 10m < x< 19m and verify that locked beans amount are within a range.
burntBeans = bound(burntBeans, 10000000e6 + 1e6, 19000000e6 - 1e6);
uint256 lockedBeansPercent = burnBeansAndCheckLockedBeans(burntBeans);
// 1e-12% precision.
assertApproxEqRel(lockedBeansPercent, 0.5795008171102514e18, 1e6); // see {LibLockedUnderlying}
assertApproxEqRel(lockedBeansPercent, 0.460273768141e18, 1e6); // see {LibLockedUnderlying}
}

/**
Expand Down Expand Up @@ -642,8 +642,8 @@ contract GaugeTest is TestHelper {
// mint 20m unripe LP, add 20m beans worth of underlying:
addUnderlyingToUnripeLP(20000000e6, 2000000e6);

// set s.recapitalized to 100, and 1000 sprouts fertilized:
bs.setPenaltyParams(100e6, 1000e6);
// set s.recapitalized to 4032696.8e6 (10612360000000 * 0.38), and 1000 sprouts fertilized:
bs.setPenaltyParams(4032696.8e6, 1000e6);
}

function addUnderlyingToUnripeBean(
Expand Down
48 changes: 31 additions & 17 deletions protocol/test/foundry/utils/OracleDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ contract OracleDeployer is Utils {
// oracles must be initalized at some price. Assumes index matching with pools.
uint256[][] public priceData = [[uint256(1e18), 18], [uint256(500e6), 8]];

// new custom oracle implmenetations should be added here.
address lsdChainlinkOracle; // LSD Chainlink Oracle

/**
* @notice initializes chainlink oracles.
* @dev oracles are mocked, and thus require initalization/updates.
Expand Down Expand Up @@ -162,17 +165,30 @@ contract OracleDeployer is Utils {
}

function initWhitelistOracles(bool verbose) internal {
// deploy LSD Chainlink Oracle
lsdChainlinkOracle = address(new LSDChainlinkOracle());
vm.label(lsdChainlinkOracle, "LSD Chainlink Oracle");
// new custom oracles should be added here.

// init ETH:USD oracle
updateOracleImplementationForTokenUsingChainlinkAggregator(
C.WETH,
C.ETH_USD_CHAINLINK_PRICE_AGGREGATOR
C.ETH_USD_CHAINLINK_PRICE_AGGREGATOR,
verbose
);

// init wsteth oracle.
setupLSDChainlinkOracleForToken(
C.WSTETH,
C.WSTETH_ETH_CHAINLINK_PRICE_AGGREGATOR,
FOUR_HOUR_TIMEOUT
);
setupWstethOracleImplementation();
}

function updateOracleImplementationForTokenUsingChainlinkAggregator(
address token,
address oracleAddress
address oracleAddress,
bool verbose
) internal {
IMockFBeanstalk.Implementation memory oracleImplementation = IMockFBeanstalk.Implementation(
oracleAddress,
Expand All @@ -184,32 +200,30 @@ contract OracleDeployer is Utils {
vm.prank(BEANSTALK);
bs.updateOracleImplementationForToken(token, oracleImplementation);

console.log("Updated oracle implementation for token: ", token, " to: ", oracleAddress);
if (verbose)
console.log("Updated oracle implementation for token: ", token, " to: ", oracleAddress);
}

function setupWstethOracleImplementation() internal {
// deploy new staking eth oracle contract
address oracleAddress = address(new LSDChainlinkOracle());

function setupLSDChainlinkOracleForToken(
address token,
address tokenChainlinkOracle,
uint256 tokenTimeout
) internal {
address _ethChainlinkOracle = C.ETH_USD_CHAINLINK_PRICE_AGGREGATOR;
uint256 _ethTimeout = 3600 * 4;
address _xEthChainlinkOracle = C.WSTETH_ETH_CHAINLINK_PRICE_AGGREGATOR;
uint256 _xEthTimeout = 3600 * 4;
address _token = C.WSTETH;

vm.prank(BEANSTALK);
bs.updateOracleImplementationForToken(
_token,
token,
IMockFBeanstalk.Implementation(
oracleAddress,
lsdChainlinkOracle,
LSDChainlinkOracle.getPrice.selector,
bytes1(0x00),
abi.encode(
_ethChainlinkOracle,
_ethTimeout,
_xEthChainlinkOracle,
_xEthTimeout,
_token
tokenChainlinkOracle,
tokenTimeout,
token
)
)
);
Expand Down

0 comments on commit 63027b1

Please sign in to comment.