Verified contractExactMIT
LibIncentive
Address0x9d5e1f29abc45205cf95161dee74c1df95e11052
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.7.6
- Same code
Only this contract
Details
- Compiler
- solc 0.7.6+commit.7338295f
- Language
- solidity
- Optimization
- Yes, 100 runs
- EVM version
- istanbul
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 20,384,334
- Creation transaction
- 0x5119487eda…50c43841f1
11 files
- contracts/libraries/LibIncentive.solmain9.69 KB
- @openzeppelin/contracts/math/Math.sol809 B
- @openzeppelin/contracts/math/SafeMath.sol7.23 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.7 KB
- contracts/C.sol6.8 KB
- contracts/interfaces/IBean.sol512 B
- contracts/interfaces/IBlockBasefee.sol229 B
- contracts/interfaces/ICurve.sol4.53 KB
- contracts/interfaces/IFertilizer.sol855 B
- contracts/interfaces/IProxyAdmin.sol186 B
- contracts/libraries/Decimal.sol4.92 KB
contracts/libraries/LibIncentive.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
import {IBlockBasefee} from "../interfaces/IBlockBasefee.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "../C.sol";
/**
* @title LibIncentive
* @author Publius, Chaikitty, Brean
* @notice Calculates the reward offered for calling Sunrise, adjusts for current gas & ETH prices,
* and scales the reward up when the Sunrise is called late.
*/
library LibIncentive {
using SafeMath for uint256;
/**
* @notice Emitted when Beanstalk pays `beans` to `account` as a reward for calling `sunrise()`.
* @param account The address to which the reward Beans were sent
* @param beans The amount of Beans paid as a reward
*/
event Incentivization(address indexed account, uint256 beans);
/// @dev The time range over which to consult the Uniswap V3 ETH:USDC pool oracle. Measured in seconds.
uint32 internal constant PERIOD = 1800; // 30 minutes
/// @dev The Sunrise reward reaches its maximum after this many blocks elapse.
uint256 internal constant MAX_BLOCKS_LATE = 25;
/// @dev Base BEAN reward to cover cost of operating a bot.
uint256 internal constant BASE_REWARD = 3e6; // 3 BEAN
/// @dev Max BEAN reward for calling Sunrise.
uint256 internal constant MAX_REWARD = 250e6; // 250 BEAN
/// @dev Wei buffer to account for the priority fee.
uint256 internal constant PRIORITY_FEE_BUFFER = 5e9; // 5e9 wei = 5 gwei
/// @dev The maximum gas which Beanstalk will pay for a Sunrise transaction.
uint256 internal constant MAX_SUNRISE_GAS = 500_000; // 500k gas
/// @dev Accounts for extra gas overhead for completing a Sunrise tranasaction.
// 21k gas (base cost for a transction) + ~29 gas for other overhead
uint256 internal constant SUNRISE_GAS_OVERHEAD = 50_000; // 50k gas
/// @dev Use external contract for block.basefee as to avoid upgrading existing contracts to solidity v8
address private constant BASE_FEE_CONTRACT = 0x84292919cB64b590C0131550483707E43Ef223aC;
/// @dev `sunriseReward` is precomputed in {fracExp} using this precision.
uint256 private constant FRAC_EXP_PRECISION = 1e18;
//////////////////// CALCULATE REWARD ////////////////////
/**
* @param initialGasLeft The amount of gas left at the start of the transaction
* @param blocksLate The number of blocks late that {sunrise()} was called.
* @param beanEthPrice The Bean:Eth price calculated by the Minting Well. The amount of Beans per ETH.
* @dev Calculates Sunrise incentive amount based on current gas prices and a computed
* BEAN:ETH price. This function is called at the end of {sunriseTo()} after all
* "step" functions have been executed.
*/
function determineReward(uint256 initialGasLeft, uint256 blocksLate, uint256 beanEthPrice)
external
view
returns (uint256)
{
// Cap the maximum number of blocks late. If the sunrise is later than
// this, Beanstalk will pay the same amount. Prevents unbounded return value.
if (blocksLate > MAX_BLOCKS_LATE) {
blocksLate = MAX_BLOCKS_LATE;
}
// If the Bean Eth pool couldn't calculate a valid price, use the max reward value.
if (beanEthPrice <= 1) {
return fracExp(MAX_REWARD, blocksLate);
}
// Sunrise gas overhead includes:
// - 21K for base transaction cost
// - 29K for calculations following the below line, like {fracExp}
// Max gas which Beanstalk will pay for = 500K.
uint256 gasUsed = Math.min(initialGasLeft.sub(gasleft()) + SUNRISE_GAS_OVERHEAD, MAX_SUNRISE_GAS);
// Calculate the current cost in Wei of `gasUsed` gas.
// {block_basefee()} returns the base fee of the current block in Wei.
// Adds a buffer for priority fee.
uint256 gasCostWei = IBlockBasefee(BASE_FEE_CONTRACT).block_basefee().add(PRIORITY_FEE_BUFFER).mul(gasUsed); // (BASE_FEE
// + PRIORITY_FEE_BUFFER)
// * GAS_USED
// Calculates the Sunrise reward to pay in BEAN.
uint256 sunriseReward = Math.min(
BASE_REWARD + gasCostWei.mul(beanEthPrice).div(1e18), // divide by 1e18 to convert wei to eth
MAX_REWARD
);
// Scale the reward up as the number of blocks after expected sunrise increases.
// `sunriseReward * (1 + 1/100)^(blocks late * seconds per block)`
// NOTE: 1.01^(25 * 12) = 19.78, This is the maximum multiplier.
return fracExp(sunriseReward, blocksLate);
}
//////////////////// MATH UTILITIES ////////////////////
/**
* @dev fraxExp scales up the bean reward based on the blocks late.
* the formula is beans * (1.01)^(Blocks Late * 12 second block time).
* since block time is capped at 25 blocks,
* we only need to check cases 0 - 25
*/
function fracExp(uint256 beans, uint256 blocksLate) internal pure returns (uint256 scaledSunriseReward) {
// check most likely case first
if (blocksLate == 0) {
return beans;
}
// Binary Search
if (blocksLate < 13) {
if (blocksLate < 7) {
if (blocksLate < 4) {
if (blocksLate < 2) {
// blocksLate == 0 is already checked, thus
// blocksLate = 1, 1.01^(1*12)
return _scaleReward(beans, 1_126_825_030_131_969_720);
}
if (blocksLate == 2) {
// 1.01^(2*12)
return _scaleReward(beans, 1_269_734_648_531_914_468);
} else {
// blocksLate == 3, 1.01^(3*12)
return _scaleReward(beans, 1_430_768_783_591_580_504);
}
}
if (blocksLate < 6) {
if (blocksLate == 4) {
return _scaleReward(beans, 1_612_226_077_682_464_366);
} else {
// blocksLate == 5
return _scaleReward(beans, 1_816_696_698_564_090_264);
}
} else {
// blocksLate == 6
return _scaleReward(beans, 2_047_099_312_100_130_925);
}
}
if (blocksLate < 10) {
if (blocksLate < 9) {
if (blocksLate == 7) {
return _scaleReward(beans, 2_306_722_744_040_364_517);
} else {
// blocksLate == 8
return _scaleReward(beans, 2_599_272_925_559_383_624);
}
} else {
// blocksLate == 9
return _scaleReward(beans, 2_928_925_792_664_665_541);
}
}
if (blocksLate < 12) {
if (blocksLate == 10) {
return _scaleReward(beans, 3_300_386_894_573_665_047);
} else {
// blocksLate == 11
return _scaleReward(beans, 3_718_958_561_925_128_091);
}
} else {
// blocksLate == 12
return _scaleReward(beans, 4_190_615_593_600_829_241);
}
}
if (blocksLate < 19) {
if (blocksLate < 16) {
if (blocksLate < 15) {
if (blocksLate == 13) {
return _scaleReward(beans, 4_722_090_542_530_756_587);
} else {
// blocksLate == 14
return _scaleReward(beans, 5_320_969_817_873_109_037);
}
} else {
// blocksLate == 15
return _scaleReward(beans, 5_995_801_975_356_167_528);
}
}
if (blocksLate < 18) {
if (blocksLate == 16) {
return _scaleReward(beans, 6_756_219_741_546_037_047);
} else {
// blocksLate == 17
return _scaleReward(beans, 7_613_077_513_845_821_874);
}
}
return _scaleReward(beans, 8_578_606_298_936_339_361); // blocksLate == 18
}
if (blocksLate < 22) {
if (blocksLate < 21) {
if (blocksLate == 19) {
return _scaleReward(beans, 9_666_588_301_289_245_846);
} else {
// blocksLate == 20
return _scaleReward(beans, 10_892_553_653_873_600_447);
}
}
return _scaleReward(beans, 12_274_002_099_240_216_703); // blocksLate == 21
}
if (blocksLate <= 23) {
if (blocksLate == 22) {
return _scaleReward(beans, 13_830_652_785_316_216_792);
} else {
// blocksLate == 23
return _scaleReward(beans, 15_584_725_741_558_756_931);
}
}
if (blocksLate >= 25) {
// block rewards are capped at 25 (MAX_BLOCKS_LATE)
return _scaleReward(beans, 19_788_466_261_924_388_319);
} else {
// blocksLate == 24
return _scaleReward(beans, 17_561_259_053_330_430_428);
}
}
function _scaleReward(uint256 beans, uint256 scaler) private pure returns (uint256) {
return beans.mul(scaler).div(FRAC_EXP_PRECISION);
}
}
@openzeppelin/contracts/math/Math.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}
@openzeppelin/contracts/math/SafeMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contracts/C.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
import "./interfaces/IBean.sol";
import "./interfaces/ICurve.sol";
import "./interfaces/IFertilizer.sol";
import "./interfaces/IProxyAdmin.sol";
import "./libraries/Decimal.sol";
/**
* @title C
* @author Publius
* @notice Contains constants used throughout Beanstalk.
*/
library C {
using Decimal for Decimal.D256;
using SafeMath for uint256;
//////////////////// Globals ////////////////////
uint256 internal constant PRECISION = 1e18;
uint256 private constant CHAIN_ID = 1;
bytes constant BYTES_ZERO = new bytes(0);
/// @dev The block time for the chain in seconds.
uint256 internal constant BLOCK_LENGTH_SECONDS = 12;
//////////////////// Season ////////////////////
/// @dev The length of a Season meaured in seconds.
uint256 private constant CURRENT_SEASON_PERIOD = 3600; // 1 hour
uint256 internal constant SOP_PRECISION = 1e24;
//////////////////// Silo ////////////////////
uint256 internal constant SEEDS_PER_BEAN = 2;
uint256 internal constant STALK_PER_BEAN = 10000;
uint256 private constant ROOTS_BASE = 1e12;
//////////////////// Exploit Migration ////////////////////
uint256 private constant UNRIPE_LP_PER_DOLLAR = 1884592; // 145_113_507_403_282 / 77_000_000
uint256 private constant ADD_LP_RATIO = 866616;
uint256 private constant INITIAL_HAIRCUT = 185564685220298701;
//////////////////// Contracts ////////////////////
address internal constant BEAN = 0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab;
address internal constant CURVE_BEAN_METAPOOL = 0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49;
address internal constant UNRIPE_BEAN = 0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449;
address internal constant UNRIPE_LP = 0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D;
address private constant CURVE_3_POOL = 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7;
address private constant THREE_CRV = 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490;
address private constant FERTILIZER = 0x402c84De2Ce49aF88f5e2eF3710ff89bFED36cB6;
address private constant FERTILIZER_ADMIN = 0xfECB01359263C12Aa9eD838F878A596F0064aa6e;
address private constant TRI_CRYPTO = 0xc4AD29ba4B3c580e6D59105FFf484999997675Ff;
address private constant TRI_CRYPTO_POOL = 0xD51a44d3FaE010294C616388b506AcdA1bfAAE46;
address private constant CURVE_ZAP = 0xA79828DF1850E8a3A3064576f380D90aECDD3359;
address private constant UNRIPE_CURVE_BEAN_LUSD_POOL = 0xD652c40fBb3f06d6B58Cb9aa9CFF063eE63d465D;
address private constant UNRIPE_CURVE_BEAN_METAPOOL = 0x3a70DfA7d2262988064A2D051dd47521E43c9BdD;
address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant WSTETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;
// Use external contract for block.basefee as to avoid upgrading existing contracts to solidity v8
address private constant BASE_FEE_CONTRACT = 0x84292919cB64b590C0131550483707E43Ef223aC;
//////////////////// Well ////////////////////
uint256 internal constant WELL_MINIMUM_BEAN_BALANCE = 1000_000_000; // 1,000 Beans
address internal constant BEAN_ETH_WELL = 0xBEA0e11282e2bB5893bEcE110cF199501e872bAd;
address internal constant BEAN_WSTETH_WELL = 0xBeA0000113B0d182f4064C86B71c315389E4715D;
// The index of the Bean and Weth token addresses in all BEAN/ETH Wells.
uint256 internal constant BEAN_INDEX = 0;
uint256 internal constant ETH_INDEX = 1;
function getSeasonPeriod() internal pure returns (uint256) {
return CURRENT_SEASON_PERIOD;
}
function getBlockLengthSeconds() internal pure returns (uint256) {
return BLOCK_LENGTH_SECONDS;
}
function getChainId() internal pure returns (uint256) {
return CHAIN_ID;
}
function getSeedsPerBean() internal pure returns (uint256) {
return SEEDS_PER_BEAN;
}
function getStalkPerBean() internal pure returns (uint256) {
return STALK_PER_BEAN;
}
function getRootsBase() internal pure returns (uint256) {
return ROOTS_BASE;
}
/**
* @dev The pre-exploit BEAN:3CRV Curve metapool address.
*/
function unripeLPPool1() internal pure returns (address) {
return UNRIPE_CURVE_BEAN_METAPOOL;
}
/**
* @dev The pre-exploit BEAN:LUSD Curve plain pool address.
*/
function unripeLPPool2() internal pure returns (address) {
return UNRIPE_CURVE_BEAN_LUSD_POOL;
}
function unripeBean() internal pure returns (IERC20) {
return IERC20(UNRIPE_BEAN);
}
function unripeLP() internal pure returns (IERC20) {
return IERC20(UNRIPE_LP);
}
function bean() internal pure returns (IBean) {
return IBean(BEAN);
}
function usdc() internal pure returns (IERC20) {
return IERC20(USDC);
}
function curveMetapool() internal pure returns (ICurvePool) {
return ICurvePool(CURVE_BEAN_METAPOOL);
}
function curve3Pool() internal pure returns (I3Curve) {
return I3Curve(CURVE_3_POOL);
}
function curveZap() internal pure returns (ICurveZap) {
return ICurveZap(CURVE_ZAP);
}
function curveZapAddress() internal pure returns (address) {
return CURVE_ZAP;
}
function curve3PoolAddress() internal pure returns (address) {
return CURVE_3_POOL;
}
function threeCrv() internal pure returns (IERC20) {
return IERC20(THREE_CRV);
}
function fertilizer() internal pure returns (IFertilizer) {
return IFertilizer(FERTILIZER);
}
function fertilizerAddress() internal pure returns (address) {
return FERTILIZER;
}
function fertilizerAdmin() internal pure returns (IProxyAdmin) {
return IProxyAdmin(FERTILIZER_ADMIN);
}
function triCryptoPoolAddress() internal pure returns (address) {
return TRI_CRYPTO_POOL;
}
function triCrypto() internal pure returns (IERC20) {
return IERC20(TRI_CRYPTO);
}
function unripeLPPerDollar() internal pure returns (uint256) {
return UNRIPE_LP_PER_DOLLAR;
}
function dollarPerUnripeLP() internal pure returns (uint256) {
return 1e12/UNRIPE_LP_PER_DOLLAR;
}
function exploitAddLPRatio() internal pure returns (uint256) {
return ADD_LP_RATIO;
}
function precision() internal pure returns (uint256) {
return PRECISION;
}
function initialRecap() internal pure returns (uint256) {
return INITIAL_HAIRCUT;
}
}contracts/interfaces/IBean.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title IBean
* @author Publius
* @notice Bean Interface
*/
abstract contract IBean is IERC20 {
function burn(uint256 amount) public virtual;
function burnFrom(address account, uint256 amount) public virtual;
function mint(address account, uint256 amount) public virtual;
function symbol() public view virtual returns (string memory);
}
contracts/interfaces/IBlockBasefee.sol
// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity =0.7.6;
interface IBlockBasefee {
// Returns the base fee of this block in wei
function block_basefee() external view returns (uint256);
}contracts/interfaces/ICurve.sol
// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity =0.7.6;
interface ICurvePool {
function A_precise() external view returns (uint256);
function get_balances() external view returns (uint256[2] memory);
function totalSupply() external view returns (uint256);
function add_liquidity(uint256[2] memory amounts, uint256 min_mint_amount) external returns (uint256);
function remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 min_amount) external returns (uint256);
function balances(int128 i) external view returns (uint256);
function fee() external view returns (uint256);
function coins(uint256 i) external view returns (address);
function get_virtual_price() external view returns (uint256);
function calc_token_amount(uint256[2] calldata amounts, bool deposit) external view returns (uint256);
function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external view returns (uint256);
function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external returns (uint256);
function exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy) external returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
}
interface ICurveZap {
function add_liquidity(address _pool, uint256[4] memory _deposit_amounts, uint256 _min_mint_amount) external returns (uint256);
function calc_token_amount(address _pool, uint256[4] memory _amounts, bool _is_deposit) external returns (uint256);
}
interface ICurvePoolR {
function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy, address receiver) external returns (uint256);
function exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy, address receiver) external returns (uint256);
function remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 min_amount, address receiver) external returns (uint256);
}
interface ICurvePool2R {
function add_liquidity(uint256[2] memory amounts, uint256 min_mint_amount, address reciever) external returns (uint256);
function remove_liquidity(uint256 _burn_amount, uint256[2] memory _min_amounts, address reciever) external returns (uint256[2] calldata);
function remove_liquidity_imbalance(uint256[2] memory _amounts, uint256 _max_burn_amount, address reciever) external returns (uint256);
}
interface ICurvePool3R {
function add_liquidity(uint256[3] memory amounts, uint256 min_mint_amount, address reciever) external returns (uint256);
function remove_liquidity(uint256 _burn_amount, uint256[3] memory _min_amounts, address reciever) external returns (uint256[3] calldata);
function remove_liquidity_imbalance(uint256[3] memory _amounts, uint256 _max_burn_amount, address reciever) external returns (uint256);
}
interface ICurvePool4R {
function add_liquidity(uint256[4] memory amounts, uint256 min_mint_amount, address reciever) external returns (uint256);
function remove_liquidity(uint256 _burn_amount, uint256[4] memory _min_amounts, address reciever) external returns (uint256[4] calldata);
function remove_liquidity_imbalance(uint256[4] memory _amounts, uint256 _max_burn_amount, address reciever) external returns (uint256);
}
interface I3Curve {
function get_virtual_price() external view returns (uint256);
}
interface ICurveFactory {
function get_coins(address _pool) external view returns (address[4] calldata);
function get_underlying_coins(address _pool) external view returns (address[8] calldata);
}
interface ICurveCryptoFactory {
function get_coins(address _pool) external view returns (address[8] calldata);
}
interface ICurvePoolC {
function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external returns (uint256);
}
interface ICurvePoolNoReturn {
function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external;
function add_liquidity(uint256[3] memory amounts, uint256 min_mint_amount) external;
function remove_liquidity(uint256 _burn_amount, uint256[3] memory _min_amounts) external;
function remove_liquidity_imbalance(uint256[3] memory _amounts, uint256 _max_burn_amount) external;
function remove_liquidity_one_coin(uint256 _token_amount, uint256 i, uint256 min_amount) external;
}
interface ICurvePoolNoReturn128 {
function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external;
function remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 min_amount) external;
}
contracts/interfaces/IFertilizer.sol
// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity =0.7.6;
interface IFertilizer {
struct Balance {
uint128 amount;
uint128 lastBpf;
}
function beanstalkUpdate(
address account,
uint256[] memory ids,
uint128 bpf
) external returns (uint256);
function beanstalkMint(address account, uint256 id, uint128 amount, uint128 bpf) external;
function balanceOfFertilized(address account, uint256[] memory ids) external view returns (uint256);
function balanceOfUnfertilized(address account, uint256[] memory ids) external view returns (uint256);
function lastBalanceOf(address account, uint256 id) external view returns (Balance memory);
function lastBalanceOfBatch(address[] memory account, uint256[] memory id) external view returns (Balance[] memory);
}contracts/interfaces/IProxyAdmin.sol
// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity =0.7.6;
interface IProxyAdmin {
function upgrade(address proxy, address implementation) external;
}
contracts/libraries/Decimal.sol
/*
SPDX-License-Identifier: MIT
*/
pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
/**
* @title Decimal
* @author dYdX
*
* Library that defines a fixed-point number with 18 decimal places.
*/
library Decimal {
using SafeMath for uint256;
// ============ Constants ============
uint256 constant BASE = 10**18;
// ============ Structs ============
struct D256 {
uint256 value;
}
// ============ Static Functions ============
function zero()
internal
pure
returns (D256 memory)
{
return D256({ value: 0 });
}
function one()
internal
pure
returns (D256 memory)
{
return D256({ value: BASE });
}
function from(
uint256 a
)
internal
pure
returns (D256 memory)
{
return D256({ value: a.mul(BASE) });
}
function ratio(
uint256 a,
uint256 b
)
internal
pure
returns (D256 memory)
{
return D256({ value: getPartial(a, BASE, b) });
}
// ============ Self Functions ============
function add(
D256 memory self,
uint256 b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.add(b.mul(BASE)) });
}
function sub(
D256 memory self,
uint256 b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.sub(b.mul(BASE)) });
}
function sub(
D256 memory self,
uint256 b,
string memory reason
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.sub(b.mul(BASE), reason) });
}
function mul(
D256 memory self,
uint256 b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.mul(b) });
}
function div(
D256 memory self,
uint256 b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.div(b) });
}
function pow(
D256 memory self,
uint256 b
)
internal
pure
returns (D256 memory)
{
if (b == 0) {
return one();
}
D256 memory temp = D256({ value: self.value });
for (uint256 i = 1; i < b; ++i) {
temp = mul(temp, self);
}
return temp;
}
function add(
D256 memory self,
D256 memory b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.add(b.value) });
}
function sub(
D256 memory self,
D256 memory b
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.sub(b.value) });
}
function sub(
D256 memory self,
D256 memory b,
string memory reason
)
internal
pure
returns (D256 memory)
{
return D256({ value: self.value.sub(b.value, reason) });
}
function mul(
D256 memory self,
D256 memory b
)
internal
pure
returns (D256 memory)
{
return D256({ value: getPartial(self.value, b.value, BASE) });
}
function div(
D256 memory self,
D256 memory b
)
internal
pure
returns (D256 memory)
{
return D256({ value: getPartial(self.value, BASE, b.value) });
}
function equals(D256 memory self, D256 memory b) internal pure returns (bool) {
return self.value == b.value;
}
function greaterThan(D256 memory self, D256 memory b) internal pure returns (bool) {
return compareTo(self, b) == 2;
}
function lessThan(D256 memory self, D256 memory b) internal pure returns (bool) {
return compareTo(self, b) == 0;
}
function greaterThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) {
return compareTo(self, b) > 0;
}
function lessThanOrEqualTo(D256 memory self, D256 memory b) internal pure returns (bool) {
return compareTo(self, b) < 2;
}
function isZero(D256 memory self) internal pure returns (bool) {
return self.value == 0;
}
function asUint256(D256 memory self) internal pure returns (uint256) {
return self.value.div(BASE);
}
// ============ Core Methods ============
function getPartial(
uint256 target,
uint256 numerator,
uint256 denominator
)
private
pure
returns (uint256)
{
return target.mul(numerator).div(denominator);
}
function compareTo(
D256 memory a,
D256 memory b
)
private
pure
returns (uint256)
{
if (a.value == b.value) {
return 1;
}
return a.value > b.value ? 2 : 0;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 100,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.