Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
L1TokenFacet
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 100 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
/**
* SPDX-License-Identifier: MIT
**/
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import "contracts/interfaces/IERC1155Receiver.sol";
import "contracts/beanstalk/migration/L1Libraries/LibTransfer.sol";
import "contracts/beanstalk/migration/L1Libraries/LibWeth.sol";
import "contracts/beanstalk/migration/L1Libraries/LibEth.sol";
import "contracts/beanstalk/migration/L1Libraries/LibTokenApprove.sol";
import "contracts/beanstalk/migration/L1AppStorage.sol";
import "contracts/beanstalk/migration/L1ReentrancyGuard.sol";
import {LibRedundantMath256} from "contracts/libraries/LibRedundantMath256.sol";
/**
* @author Publius
* @title L1TokenFacet updates the TokenFacet functions due to the L2 Migration.
* @dev Beanstalk cannot assume that all tokens in Farm Balances can be transferred to
* an L2. Addditionally, given that Beans will be re-issued on L2, Beanstalk will need to
* restrict the transfer of beans and bean assets.Permit removed from farm balances due to it
* being unwidely used and not necessary for the migration.
*/
contract L1TokenFacet is IERC1155Receiver, ReentrancyGuard {
struct Balance {
uint256 internalBalance;
uint256 externalBalance;
uint256 totalBalance;
}
using SafeERC20 for IERC20;
using LibRedundantMath256 for uint256;
event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);
event TokenApproval(
address indexed owner,
address indexed spender,
IERC20 token,
uint256 amount
);
// Blacklisted tokens that cannot be removed.
address internal constant BEAN = 0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab;
address internal constant CURVE_BEAN_METAPOOL = 0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49;
address internal constant BEAN_ETH_WELL = 0xBEA0e11282e2bB5893bEcE110cF199501e872bAd;
address internal constant BEAN_WSTETH_WELL = 0xBeA0000113B0d182f4064C86B71c315389E4715D;
//////////////////////// Transfer ////////////////////////
/**
* @notice transfers a token from msg.sender to `recipient`.
* @dev enables transfers between internal and external balances.
*
* @param token The token to transfer.
* @param recipient The recipient of the transfer.
* @param amount The amount to transfer.
* @param fromMode The source of token from the sender. See {LibTransfer.From}.
* @param toMode The destination of token to the recipient. See {LibTransfer.To}.
*/
function transferToken(
IERC20 token,
address recipient,
uint256 amount,
LibTransfer.From fromMode,
LibTransfer.To toMode
) external payable {
checkBeanAsset(address(token));
LibTransfer.transferToken(token, msg.sender, recipient, amount, fromMode, toMode);
}
/**
* @notice transfers a token from `sender` to an `recipient` Internal balance.
* @dev differs from transferToken as it does not use msg.sender.
*/
function transferInternalTokenFrom(
IERC20 token,
address sender,
address recipient,
uint256 amount,
LibTransfer.To toMode
) external payable nonReentrant {
LibTransfer.transferToken(
token,
sender,
recipient,
amount,
LibTransfer.From.INTERNAL,
toMode
);
if (sender != msg.sender) {
LibTokenApprove.spendAllowance(sender, msg.sender, token, amount);
}
}
//////////////////////// Transfer ////////////////////////
/**
* @notice approves a token for a spender.
* @dev this approves a token for both internal and external balances.
*/
function approveToken(
address spender,
IERC20 token,
uint256 amount
) external payable nonReentrant {
LibTokenApprove.approve(msg.sender, spender, token, amount);
}
/**
* @notice increases approval for a token for a spender.
*/
function increaseTokenAllowance(
address spender,
IERC20 token,
uint256 addedValue
) public virtual nonReentrant returns (bool) {
LibTokenApprove.approve(
msg.sender,
spender,
token,
LibTokenApprove.allowance(msg.sender, spender, token).add(addedValue)
);
return true;
}
/**
* @notice decreases approval for a token for a spender.
*/
function decreaseTokenAllowance(
address spender,
IERC20 token,
uint256 subtractedValue
) public virtual nonReentrant returns (bool) {
uint256 currentAllowance = LibTokenApprove.allowance(msg.sender, spender, token);
require(currentAllowance >= subtractedValue, "Silo: decreased allowance below zero");
LibTokenApprove.approve(msg.sender, spender, token, currentAllowance.sub(subtractedValue));
return true;
}
/**
* @notice returns the allowance for a token for a spender.
*/
function tokenAllowance(
address account,
address spender,
IERC20 token
) public view virtual returns (uint256) {
return LibTokenApprove.allowance(account, spender, token);
}
//////////////////////// ERC1155Receiver ////////////////////////
/**
* @notice ERC1155Receiver function that allows the silo to receive ERC1155 tokens.
*
* @dev as ERC1155 deposits are not accepted yet,
* this function will revert.
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
revert("Silo: ERC1155 deposits are not accepted yet.");
}
/**
* @notice onERC1155BatchReceived function that allows the silo to receive ERC1155 tokens.
*
* @dev as ERC1155 deposits are not accepted yet,
* this function will revert.
*/
function onERC1155BatchReceived(
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
) external pure override returns (bytes4) {
revert("Silo: ERC1155 deposits are not accepted yet.");
}
//////////////////////// WETH ////////////////////////
/**
* @notice wraps ETH into WETH.
*/
function wrapEth(uint256 amount, LibTransfer.To mode) external payable {
LibWeth.wrap(amount, mode);
LibEth.refundEth();
}
/**
* @notice unwraps WETH into ETH.
*/
function unwrapEth(uint256 amount, LibTransfer.From mode) external payable {
LibWeth.unwrap(amount, mode);
}
//////////////////////// GETTERS ////////////////////////
/**
* @notice returns the internal balance of a token for an account.
*/
function getInternalBalance(
address account,
IERC20 token
) public view returns (uint256 balance) {
balance = LibBalance.getInternalBalance(account, token);
}
/**
* @notice returns the internal balances of tokens for an account.
*/
function getInternalBalances(
address account,
IERC20[] memory tokens
) external view returns (uint256[] memory balances) {
balances = new uint256[](tokens.length);
for (uint256 i; i < tokens.length; ++i) {
balances[i] = getInternalBalance(account, tokens[i]);
}
}
// External
/**
* @notice returns the external balance of a token for an account.
*/
function getExternalBalance(
address account,
IERC20 token
) public view returns (uint256 balance) {
balance = token.balanceOf(account);
}
/**
* @notice returns the external balances of tokens for an account.
*/
function getExternalBalances(
address account,
IERC20[] memory tokens
) external view returns (uint256[] memory balances) {
balances = new uint256[](tokens.length);
for (uint256 i; i < tokens.length; ++i) {
balances[i] = getExternalBalance(account, tokens[i]);
}
}
/**
* @notice returns the total balance (internal and external)
* of a token
*/
function getBalance(address account, IERC20 token) public view returns (uint256 balance) {
balance = LibBalance.getBalance(account, token);
}
/**
* @notice returns the total balances (internal and external)
* of a token for an account.
*/
function getBalances(
address account,
IERC20[] memory tokens
) external view returns (uint256[] memory balances) {
balances = new uint256[](tokens.length);
for (uint256 i; i < tokens.length; ++i) {
balances[i] = getBalance(account, tokens[i]);
}
}
/**
* @notice returns the total balance (internal and external)
* of a token, in a balance struct (internal, external, total).
*/
function getAllBalance(address account, IERC20 token) public view returns (Balance memory b) {
b.internalBalance = getInternalBalance(account, token);
b.externalBalance = getExternalBalance(account, token);
b.totalBalance = b.internalBalance.add(b.externalBalance);
}
/**
* @notice returns the total balance (internal and external)
* of a token, in a balance struct (internal, external, total).
*/
function getAllBalances(
address account,
IERC20[] memory tokens
) external view returns (Balance[] memory balances) {
balances = new Balance[](tokens.length);
for (uint256 i; i < tokens.length; ++i) {
balances[i] = getAllBalance(account, tokens[i]);
}
}
/**
* @notice verifies that the token is not a Bean asset.
* @dev bean assets on L1 will be migrated onto L2,
* and thus requires that these tokens are not transferred.
*/
function checkBeanAsset(address token) internal pure {
require(token != address(BEAN), "TokenFacet: Beans cannot be transferred.");
require(
token != address(BEAN_ETH_WELL),
"TokenFacet: BeanEth Well Tokens cannot be transferred."
);
require(
token != address(BEAN_WSTETH_WELL),
"TokenFacet: BeanwstEth Well Tokens cannot be transferred."
);
require(
token != address(CURVE_BEAN_METAPOOL),
"TokenFacet: Bean3crv Well Tokens cannot be transferred."
);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
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.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such 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 SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import "contracts/interfaces/IDiamondCut.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title Account
* @author Publius
* @notice Stores Farmer-level Beanstalk state.
* @dev {Account.State} is the primary struct that is referenced from {Storage.State}.
* All other structs in {Account} are referenced in {Account.State}. Each unique
* Ethereum address is a Farmer.
*/
contract Account {
/**
* @notice Stores a Farmer's Plots and Pod allowances.
* @param plots A Farmer's Plots. Maps from Plot index to Pod amount.
* @param podAllowances An allowance mapping for Pods similar to that of the ERC-20 standard. Maps from spender address to allowance amount.
*/
struct Field {
mapping(uint256 => uint256) plots;
mapping(address => uint256) podAllowances;
}
/**
* @notice Stores a Farmer's Deposits and Seeds per Deposit, and formerly stored Withdrawals.
* @param withdrawals DEPRECATED: Silo V1 Withdrawals are no longer referenced.
* @param deposits Unripe Bean/LP Deposits (previously Bean/LP Deposits).
* @param depositSeeds BDV of Unripe LP Deposits / 4 (previously # of Seeds in corresponding LP Deposit).
*/
struct AssetSilo {
mapping(uint32 => uint256) withdrawals;
mapping(uint32 => uint256) deposits;
mapping(uint32 => uint256) depositSeeds;
}
/**
* @notice Represents a Deposit of a given Token in the Silo at a given Season.
* @param amount The amount of Tokens in the Deposit.
* @param bdv The Bean-denominated value of the total amount of Tokens in the Deposit.
* @dev `amount` and `bdv` are packed as uint128 to save gas.
*/
struct Deposit {
uint128 amount; // ───┐ 16
uint128 bdv; // ──────┘ 16 (32/32)
}
/**
* @notice Stores a Farmer's Stalk and Seeds balances.
* @param stalk Balance of the Farmer's Stalk.
* @param seeds DEPRECATED – Balance of the Farmer's Seeds. Seeds are no longer referenced as of Silo V3.
*/
struct Silo {
uint256 stalk;
uint256 seeds;
}
/**
* @notice Stores a Farmer's germinating stalk.
* @param odd - stalk from assets deposited in odd seasons.
* @param even - stalk from assets deposited in even seasons.
*/
struct FarmerGerminatingStalk {
uint128 odd;
uint128 even;
}
/**
* @notice This struct stores the mow status for each Silo-able token, for each farmer.
* This gets updated each time a farmer mows, or adds/removes deposits.
* @param lastStem The last cumulative grown stalk per bdv index at which the farmer mowed.
* @param bdv The bdv of all of a farmer's deposits of this token type.
*
*/
struct MowStatus {
int96 lastStem; // ───┐ 12
uint128 bdv; // ──────┘ 16 (28/32)
}
/**
* @notice Stores a Farmer's Season of Plenty (SOP) balances.
* @param roots The number of Roots a Farmer had when it started Raining.
* @param plentyPerRoot The global Plenty Per Root index at the last time a Farmer updated their Silo.
* @param plenty The balance of a Farmer's plenty. Plenty can be claimed directly for 3CRV.
*/
struct SeasonOfPlenty {
uint256 roots;
uint256 plentyPerRoot;
uint256 plenty;
}
/**
* @notice Defines the state object for a Farmer.
* @param field A Farmer's Field storage.
* @param bean A Farmer's Unripe Bean Deposits only as a result of Replant (previously held the V1 Silo Deposits/Withdrawals for Beans).
* @param lp A Farmer's Unripe LP Deposits as a result of Replant of BEAN:ETH Uniswap v2 LP Tokens (previously held the V1 Silo Deposits/Withdrawals for BEAN:ETH Uniswap v2 LP Tokens).
* @param s A Farmer's Silo storage.
* @param deprecated_votedUntil DEPRECATED – Replant removed on-chain governance including the ability to vote on BIPs.
* @param lastUpdate The Season in which the Farmer last updated their Silo.
* @param lastSop The last Season that a SOP occured at the time the Farmer last updated their Silo.
* @param lastRain The last Season that it started Raining at the time the Farmer last updated their Silo.
* @param deprecated_deltaRoots DEPRECATED – BIP-39 introduced germination.
* @param deprecated_lastSIs DEPRECATED – In Silo V1.2, the Silo reward mechanism was updated to no longer need to store the number of the Supply Increases at the time the Farmer last updated their Silo.
* @param deprecated_proposedUntil DEPRECATED – Replant removed on-chain governance including the ability to propose BIPs.
* @param deprecated_sop DEPRECATED – Replant reset the Season of Plenty mechanism
* @param roots A Farmer's Root balance.
* @param deprecated_wrappedBeans DEPRECATED – Replant generalized Internal Balances. Wrapped Beans are now stored at the AppStorage level.
* @param legacyV2Deposits DEPRECATED - SiloV2 was retired in favor of Silo V3. A Farmer's Silo Deposits stored as a map from Token address to Season of Deposit to Deposit.
* @param withdrawals Withdraws were removed in zero withdraw upgrade - A Farmer's Withdrawals from the Silo stored as a map from Token address to Season the Withdrawal becomes Claimable to Withdrawn amount of Tokens.
* @param sop A Farmer's Season of Plenty storage.
* @param depositAllowances A mapping of `spender => Silo token address => amount`.
* @param tokenAllowances Internal balance token allowances.
* @param depositPermitNonces A Farmer's current deposit permit nonce
* @param tokenPermitNonces A Farmer's current token permit nonce
* @param legacyV3Deposits DEPRECATED: Silo V3 deposits. Deprecated in favor of SiloV3.1 mapping from depositId to Deposit.
* @param mowStatuses A mapping of Silo-able token address to MowStatus.
* @param isApprovedForAll A mapping of ERC1155 operator to approved status. ERC1155 compatability.
* @param farmerGerminating A Farmer's germinating stalk. Seperated into odd and even stalk.
* @param deposits SiloV3.1 deposits. A mapping from depositId to Deposit. SiloV3.1 introduces greater precision for deposits.
*/
struct State {
Field field; // A Farmer's Field storage.
/*
* @dev (Silo V1) A Farmer's Unripe Bean Deposits only as a result of Replant
*
* Previously held the V1 Silo Deposits/Withdrawals for Beans.
* NOTE: While the Silo V1 format is now deprecated, this storage slot is used for gas
* efficiency to store Unripe BEAN deposits. See {LibUnripeSilo} for more.
*/
AssetSilo bean;
/*
* @dev (Silo V1) Unripe LP Deposits as a result of Replant.
*
* Previously held the V1 Silo Deposits/Withdrawals for BEAN:ETH Uniswap v2 LP Tokens.
*
* BEAN:3CRV and BEAN:LUSD tokens prior to Replant were stored in the Silo V2
* format in the `s.a[account].legacyV2Deposits` mapping.
*
* NOTE: While the Silo V1 format is now deprecated, unmigrated Silo V1 deposits are still
* stored in this storage slot. See {LibUnripeSilo} for more.
*
*/
AssetSilo lp;
/*
* @dev Holds Silo specific state for each account.
*/
Silo s;
uint32 votedUntil; // DEPRECATED – Replant removed on-chain governance including the ability to vote on BIPs.
uint32 lastUpdate; // The Season in which the Farmer last updated their Silo.
uint32 lastSop; // The last Season that a SOP occured at the time the Farmer last updated their Silo.
uint32 lastRain; // The last Season that it started Raining at the time the Farmer last updated their Silo.
uint128 deprecated_deltaRoots; // DEPRECATED - BIP-39 introduced germination.
SeasonOfPlenty deprecated; // DEPRECATED – Replant reset the Season of Plenty mechanism
uint256 roots; // A Farmer's Root balance.
uint256 deprecated_wrappedBeans; // DEPRECATED – Replant generalized Internal Balances. Wrapped Beans are now stored at the AppStorage level.
mapping(address => mapping(uint32 => Deposit)) legacyV2Deposits; // Legacy Silo V2 Deposits stored as a map from Token address to Season of Deposit to Deposit. NOTE: While the Silo V2 format is now deprecated, unmigrated Silo V2 deposits are still stored in this mapping.
mapping(address => mapping(uint32 => uint256)) withdrawals; // Zero withdraw eliminates a need for withdraw mapping, but is kept for legacy
SeasonOfPlenty sop; // A Farmer's Season Of Plenty storage.
mapping(address => mapping(address => uint256)) depositAllowances; // Spender => Silo Token
mapping(address => mapping(IERC20 => uint256)) tokenAllowances; // Token allowances
uint256 depositPermitNonces; // A Farmer's current deposit permit nonce
uint256 tokenPermitNonces; // A Farmer's current token permit nonce
mapping(uint256 => Deposit) legacyV3Deposits; // NOTE: Legacy SiloV3 Deposits stored as a map from uint256 to Deposit. This is an concat of the token address and the CGSPBDV for a ERC20 deposit.
mapping(address => MowStatus) mowStatuses; // Store a MowStatus for each Whitelisted Silo token
mapping(address => bool) isApprovedForAll; // ERC1155 isApprovedForAll mapping
// Germination
FarmerGerminatingStalk farmerGerminating; // A Farmer's germinating stalk.
// Silo v3.1
mapping(uint256 => Deposit) deposits; // Silo v3.1 Deposits stored as a map from uint256 to Deposit. This is an concat of the token address and the stem for a ERC20 deposit.
}
}
/**
* @title Storage
* @author Publius
* @notice Stores system-level Beanstalk state.
*/
contract Storage {
/**
* @notice DEPRECATED: System-level contract addresses.
* @dev After Replant, Beanstalk stores Token addresses as constants to save gas.
*/
struct Contracts {
address bean;
address pair;
address pegPair;
address weth;
}
/**
* @notice System-level Field state variables.
* @param soil The number of Soil currently available. Adjusted during {Sun.stepSun}.
* @param beanSown The number of Bean sown within the current Season. Reset during {Weather.calcCaseId}.
* @param pods The pod index; the total number of Pods ever minted.
* @param harvested The harvested index; the total number of Pods that have ever been Harvested.
* @param harvestable The harvestable index; the total number of Pods that have ever been Harvestable. Included previously Harvested Beans.
*/
struct Field {
uint128 soil; // ──────┐ 16
uint128 beanSown; // ──┘ 16 (32/32)
uint256 pods;
uint256 harvested;
uint256 harvestable;
}
/**
* @notice DEPRECATED: Contained data about each BIP (Beanstalk Improvement Proposal).
* @dev Replant moved governance off-chain. This struct is left for future reference.
*
*/
struct Bip {
address proposer; // ───┐ 20
uint32 start; // │ 4 (24)
uint32 period; // │ 4 (28)
bool executed; // ──────┘ 1 (29/32)
int pauseOrUnpause;
uint128 timestamp;
uint256 roots;
uint256 endTotalRoots;
}
/**
* @notice DEPRECATED: Contained data for the DiamondCut associated with each BIP.
* @dev Replant moved governance off-chain. This struct is left for future reference.
* @dev {Storage.DiamondCut} stored DiamondCut-related data for each {Bip}.
*/
struct DiamondCut {
IDiamondCut.FacetCut[] diamondCut;
address initAddress;
bytes initData;
}
/**
* @notice DEPRECATED: Contained all governance-related data, including a list of BIPs, votes for each BIP, and the DiamondCut needed to execute each BIP.
* @dev Replant moved governance off-chain. This struct is left for future reference.
* @dev {Storage.Governance} stored all BIPs and Farmer voting information.
*/
struct Governance {
uint32[] activeBips;
uint32 bipIndex;
mapping(uint32 => DiamondCut) diamondCuts;
mapping(uint32 => mapping(address => bool)) voted;
mapping(uint32 => Bip) bips;
}
/**
* @notice System-level Silo state; contains deposit and withdrawal data for a particular whitelisted Token.
* @param deposited The total amount of this Token currently Deposited in the Silo.
* @param depositedBdv The total bdv of this Token currently Deposited in the Silo.
* @param withdrawn The total amount of this Token currently Withdrawn From the Silo.
* @dev {Storage.State} contains a mapping from Token address => AssetSilo.
* Currently, the bdv of deposits are asynchronous, and require an on-chain transaction to update.
* Thus, the total bdv of deposits cannot be calculated, and must be stored and updated upon a bdv change.
*
*
* Note that "Withdrawn" refers to the amount of Tokens that have been Withdrawn
* but not yet Claimed. This will be removed in a future BIP.
*/
struct AssetSilo {
uint128 deposited;
uint128 depositedBdv;
uint256 withdrawn;
}
/**
* @notice Whitelist Status a token that has been Whitelisted before.
* @param token the address of the token.
* @param a whether the address is whitelisted.
* @param isWhitelistedLp whether the address is a whitelisted LP token.
* @param isWhitelistedWell whether the address is a whitelisted Well token.
*/
struct WhitelistStatus {
address token;
bool isWhitelisted;
bool isWhitelistedLp;
bool isWhitelistedWell;
}
/**
* @notice System-level Silo state variables.
* @param stalk The total amount of active Stalk (including Earned Stalk, excluding Grown Stalk).
* @param deprecated_seeds DEPRECATED: The total amount of active Seeds (excluding Earned Seeds).
* @dev seeds are no longer used internally. Balance is wiped to 0 from the mayflower update. see {mowAndMigrate}.
* @param roots The total amount of Roots.
*/
struct Silo {
uint256 stalk;
uint256 deprecated_seeds;
uint256 roots;
}
/**
* @notice System-level Curve Metapool Oracle state variables.
* @param initialized True if the Oracle has been initialzed. It needs to be initialized on Deployment and re-initialized each Unpause.
* @param startSeason The Season the Oracle started minting. Used to ramp up delta b when oracle is first added.
* @param balances The cumulative reserve balances of the pool at the start of the Season (used for computing time weighted average delta b).
* @param timestamp DEPRECATED: The timestamp of the start of the current Season. `LibCurveMinting` now uses `s.season.timestamp` instead of storing its own for gas efficiency purposes.
* @dev Currently refers to the time weighted average deltaB calculated from the BEAN:3CRV pool.
*/
struct CurveMetapoolOracle {
bool initialized; // ────┐ 1
uint32 startSeason; // ──┘ 4 (5/32)
uint256[2] balances;
uint256 timestamp;
}
/**
* @notice System-level Rain balances. Rain occurs when P > 1 and the Pod Rate Excessively Low.
* @dev The `raining` storage variable is stored in the Season section for a gas efficient read operation.
* @param deprecated Previously held Rain start and Rain status variables. Now moved to Season struct for gas efficiency.
* @param pods The number of Pods when it last started Raining.
* @param roots The number of Roots when it last started Raining.
*/
struct Rain {
uint256 deprecated;
uint256 pods;
uint256 roots;
}
/**
* @notice System-level Season state variables.
* @param current The current Season in Beanstalk.
* @param lastSop The Season in which the most recent consecutive series of Seasons of Plenty started.
* @param withdrawSeasons The number of Seasons required to Withdraw a Deposit.
* @param lastSopSeason The Season in which the most recent consecutive series of Seasons of Plenty ended.
* @param rainStart Stores the most recent Season in which Rain started.
* @param raining True if it is Raining (P > 1, Pod Rate Excessively Low).
* @param fertilizing True if Beanstalk has Fertilizer left to be paid off.
* @param sunriseBlock The block of the start of the current Season.
* @param abovePeg Boolean indicating whether the previous Season was above or below peg.
* @param stemStartSeason // season in which the stem storage method was introduced.
* @param stemScaleSeason // season in which the stem v1.1 was introduced, where stems are not truncated anymore.
* @param beanEthStartMintingSeason // Season to start minting in Bean:Eth pool after migrating liquidity out of the pool to protect against Pump failure.
* This allows for greater precision of stems, and requires a soft migration (see {LibTokenSilo.removeDepositFromAccount})
* @param start The timestamp of the Beanstalk deployment rounded down to the nearest hour.
* @param period The length of each season in Beanstalk in seconds.
* @param timestamp The timestamp of the start of the current Season.
*/
struct Season {
uint32 current; // ─────────────────┐ 4
uint32 lastSop; // │ 4 (8)
uint8 withdrawSeasons; // │ 1 (9)
uint32 lastSopSeason; // │ 4 (13)
uint32 rainStart; // │ 4 (17)
bool raining; // │ 1 (18)
bool fertilizing; // │ 1 (19)
uint32 sunriseBlock; // │ 4 (23)
bool abovePeg; // | 1 (24)
uint16 stemStartSeason; // | 2 (26)
uint16 stemScaleSeason; // | 2 (28/32)
uint32 beanEthStartMintingSeason; //┘ 4 (32/32) NOTE: Reset and delete after Bean:wStEth migration has been completed.
uint256 start;
uint256 period;
uint256 timestamp;
}
/**
* @notice System-level Weather state variables.
* @param deprecated 2 slots that were previously used.
* @param lastDSoil Delta Soil; the number of Soil purchased last Season.
* @param lastSowTime The number of seconds it for Soil to sell out last Season.
* @param thisSowTime The number of seconds it for Soil to sell out this Season.
* @param t The Temperature; the maximum interest rate during the current Season for sowing Beans in Soil. Adjusted each Season.
*/
struct Weather {
uint256[2] deprecated;
uint128 lastDSoil; // ───┐ 16 (16)
uint32 lastSowTime; // │ 4 (20)
uint32 thisSowTime; // │ 4 (24)
uint32 t; // ─────────────┘ 4 (28/32)
}
/**
* @notice Describes a Fundraiser.
* @param payee The address to be paid after the Fundraiser has been fully funded.
* @param token The token address that used to raise funds for the Fundraiser.
* @param total The total number of Tokens that need to be raised to complete the Fundraiser.
* @param remaining The remaining number of Tokens that need to to complete the Fundraiser.
* @param start The timestamp at which the Fundraiser started (Fundraisers cannot be started and funded in the same block).
*/
struct Fundraiser {
address payee;
address token;
uint256 total;
uint256 remaining;
uint256 start;
}
/**
* @notice Describes the settings for each Token that is Whitelisted in the Silo.
* @param selector The encoded BDV function selector for the token that pertains to
* an external view Beanstalk function with the following signature:
* ```
* function tokenToBdv(uint256 amount) external view returns (uint256);
* ```
* It is called by `LibTokenSilo` through the use of `delegatecall`
* to calculate a token's BDV at the time of Deposit.
* @param stalkEarnedPerSeason represents how much Stalk one BDV of the underlying deposited token
* grows each season. In the past, this was represented by seeds. This is stored as 1e6, plus stalk is stored
* as 1e10, so 1 legacy seed would be 1e6 * 1e10.
* @param stalkIssuedPerBdv The Stalk Per BDV that the Silo grants in exchange for Depositing this Token.
* previously called stalk.
* @param milestoneSeason The last season in which the stalkEarnedPerSeason for this token was updated.
* @param milestoneStem The cumulative amount of grown stalk per BDV for this token at the last stalkEarnedPerSeason update.
* @param encodeType determine the encoding type of the selector.
* a encodeType of 0x00 means the selector takes an input amount.
* 0x01 means the selector takes an input amount and a token.
* @param gpSelector The encoded gaugePoint function selector for the token that pertains to
* an external view Beanstalk function with the following signature:
* ```
* function gaugePoints(
* uint256 currentGaugePoints,
* uint256 optimalPercentDepositedBdv,
* uint256 percentOfDepositedBdv
* ) external view returns (uint256);
* ```
* @param lwSelector The encoded liquidityWeight function selector for the token that pertains to
* an external view Beanstalk function with the following signature `function liquidityWeight()`
* @param optimalPercentDepositedBdv The target percentage of the total LP deposited BDV for this token. 6 decimal precision.
* @param gaugePoints the amount of Gauge points this LP token has in the LP Gauge. Only used for LP whitelisted assets.
* GaugePoints has 18 decimal point precision (1 Gauge point = 1e18).
* @dev A Token is considered Whitelisted if there exists a non-zero {SiloSettings} selector.
*/
struct SiloSettings {
bytes4 selector; // ────────────────────┐ 4
uint32 stalkEarnedPerSeason; // │ 4 (8)
uint32 stalkIssuedPerBdv; // │ 4 (12)
uint32 milestoneSeason; // │ 4 (16)
int96 milestoneStem; // │ 12 (28)
bytes1 encodeType; // │ 1 (29)
int24 deltaStalkEarnedPerSeason; // ────┘ 3 (32)
bytes4 gpSelector; // ────────────────┐ 4
bytes4 lwSelector; // │ 4 (8)
uint128 gaugePoints; // │ 16 (24)
uint64 optimalPercentDepositedBdv; // ──┘ 8 (32)
}
/**
* @notice Describes the settings for each Unripe Token in Beanstalk.
* @param underlyingToken The address of the Token underlying the Unripe Token.
* @param balanceOfUnderlying The number of Tokens underlying the Unripe Tokens (redemption pool).
* @param merkleRoot The Merkle Root used to validate a claim of Unripe Tokens.
* @dev An Unripe Token is a vesting Token that is redeemable for a a pro rata share
* of the `balanceOfUnderlying`, subject to a penalty based on the percent of
* Unfertilized Beans paid back.
*
* There were two Unripe Tokens added at Replant:
* - Unripe Bean, with its `underlyingToken` as BEAN;
* - Unripe LP, with its `underlyingToken` as BEAN:3CRV LP.
*
* Unripe Tokens are initially distributed through the use of a `merkleRoot`.
*
* The existence of a non-zero {UnripeSettings} implies that a Token is an Unripe Token.
*/
struct UnripeSettings {
address underlyingToken;
uint256 balanceOfUnderlying;
bytes32 merkleRoot;
}
/**
* @notice System level variables used in the seed Gauge System.
* @param averageGrownStalkPerBdvPerSeason The average Grown Stalk Per BDV
* that beanstalk issues each season.
* @param beanToMaxLpGpPerBdvRatio a scalar of the gauge points(GP) per bdv
* issued to the largest LP share and Bean. 6 decimal precision.
* @dev a beanToMaxLpGpPerBdvRatio of 0 means LP should be incentivized the most,
* and that beans will have the minimum seeds ratio. see {LibGauge.getBeanToMaxLpGpPerBdvRatioScaled}
*/
struct SeedGauge {
uint128 averageGrownStalkPerBdvPerSeason;
uint128 beanToMaxLpGpPerBdvRatio;
}
/**
* @notice Stores the twaReserves for each well during the sunrise function.
*/
struct TwaReserves {
uint128 reserve0;
uint128 reserve1;
}
/**
* @notice Stores the total germination amounts for each whitelisted token.
*/
struct Deposited {
uint128 amount;
uint128 bdv;
}
/**
* @notice Stores the system level germination data.
*/
struct TotalGerminating {
mapping(address => Deposited) deposited;
}
struct Sr {
uint128 stalk;
uint128 roots;
}
}
/**
* @title AppStorage
* @author Publius
* @notice Defines the state object for Beanstalk.
* @param deprecated_index DEPRECATED: Was the index of the BEAN token in the BEAN:ETH Uniswap V2 pool.
* @param deprecated_cases DEPRECATED: The 24 Weather cases used in cases V1 (array has 32 items, but caseId = 3 (mod 4) are not cases)
* @param paused True if Beanstalk is Paused.
* @param pausedAt The timestamp at which Beanstalk was last paused.
* @param season Storage.Season
* @param c Storage.Contracts
* @param f Storage.Field
* @param g Storage.Governance
* @param co Storage.CurveMetapoolOracle
* @param r Storage.Rain
* @param s Storage.Silo
* @param reentrantStatus An intra-transaction state variable to protect against reentrance.
* @param w Storage.Weather
* @param earnedBeans The number of Beans distributed to the Silo that have not yet been Deposited as a result of the Earn function being called.
* @param deprecated DEPRECATED - 14 slots that used to store state variables which have been deprecated through various updates. Storage slots can be left alone or reused.
* @param a mapping (address => Account.State)
* @param deprecated_bip0Start DEPRECATED - bip0Start was used to aid in a migration that occured alongside BIP-0.
* @param deprecated_hotFix3Start DEPRECATED - hotFix3Start was used to aid in a migration that occured alongside HOTFIX-3.
* @param fundraisers A mapping from Fundraiser ID to Storage.Fundraiser.
* @param fundraiserIndex The number of Fundraisers that have occured.
* @param deprecated_isBudget DEPRECATED - Budget Facet was removed in BIP-14.
* @param podListings A mapping from Plot Index to the hash of the Pod Listing.
* @param podOrders A mapping from the hash of a Pod Order to the amount of Pods that the Pod Order is still willing to buy.
* @param siloBalances A mapping from Token address to Silo Balance storage (amount deposited and withdrawn).
* @param ss A mapping from Token address to Silo Settings for each Whitelisted Token. If a non-zero storage exists, a Token is whitelisted.
* @param deprecated2 DEPRECATED - 2 slots that used to store state variables which have been deprecated through various updates. Storage slots can be left alone or reused.
* @param deprecated_newEarnedStalk the amount of earned stalk issued this season. Since 1 stalk = 1 bean, it represents the earned beans as well.
* @param sops A mapping from Season to Plenty Per Root (PPR) in that Season. Plenty Per Root is 0 if a Season of Plenty did not occur.
* @param internalTokenBalance A mapping from Farmer address to Token address to Internal Balance. It stores the amount of the Token that the Farmer has stored as an Internal Balance in Beanstalk.
* @param unripeClaimed True if a Farmer has Claimed an Unripe Token. A mapping from Farmer to Unripe Token to its Claim status.
* @param u Unripe Settings for a given Token address. The existence of a non-zero Unripe Settings implies that the token is an Unripe Token. The mapping is from Token address to Unripe Settings.
* @param fertilizer A mapping from Fertilizer Id to the supply of Fertilizer for each Id.
* @param nextFid A linked list of Fertilizer Ids ordered by Id number. Fertilizer Id is the Beans Per Fertilzer level at which the Fertilizer no longer receives Beans. Sort in order by which Fertilizer Id expires next.
* @param activeFertilizer The number of active Fertilizer.
* @param fertilizedIndex The total number of Fertilizer Beans.
* @param unfertilizedIndex The total number of Unfertilized Beans ever.
* @param fFirst The lowest active Fertilizer Id (start of linked list that is stored by nextFid).
* @param fLast The highest active Fertilizer Id (end of linked list that is stored by nextFid).
* @param bpf The cumulative Beans Per Fertilizer (bfp) minted over all Season.
* @param deprecated_vestingPeriodRoots deprecated - removed in BIP-39 in favor of germination.
* @param recapitalized The number of USDC that has been recapitalized in the Barn Raise.
* @param isFarm Stores whether the function is wrapped in the `farm` function (1 if not, 2 if it is).
* @param ownerCandidate Stores a candidate address to transfer ownership to. The owner must claim the ownership transfer.
* @param wellOracleSnapshots A mapping from Well Oracle address to the Well Oracle Snapshot.
* @param deprecated_beanEthPrice DEPRECATED - The price of bean:eth, originally used to calculate the incentive reward. Deprecated in favor of calculating using twaReserves.
* @param twaReserves A mapping from well to its twaReserves. Stores twaReserves during the sunrise function. Returns 1 otherwise for each asset. Currently supports 2 token wells.
* @param migratedBdvs Stores the total migrated BDV since the implementation of the migrated BDV counter. See {LibLegacyTokenSilo.incrementMigratedBdv} for more info.
* @param usdEthPrice Stores the usdEthPrice during the sunrise() function. Returns 1 otherwise.
* @param seedGauge Stores the seedGauge.
* @param casesV2 Stores the 144 Weather and seedGauge cases.
* @param oddGerminating Stores germinating data during odd seasons.
* @param evenGerminating Stores germinating data during even seasons.
* @param whitelistedStatues Stores a list of Whitelist Statues for all tokens that have been Whitelisted and have not had their Whitelist Status manually removed.
* @param sopWell Stores the well that will be used upon a SOP. Unintialized until a SOP occurs, and is kept constant afterwards.
* @param barnRaiseWell Stores the well that the Barn Raise adds liquidity to.
*/
struct AppStorage {
uint8 deprecated_index;
int8[32] deprecated_cases;
bool paused; // ────────┐ 1
uint128 pausedAt; // ───┘ 16 (17/32)
Storage.Season season;
Storage.Contracts c;
Storage.Field f;
Storage.Governance g;
Storage.CurveMetapoolOracle co;
Storage.Rain r;
Storage.Silo s;
uint256 reentrantStatus;
Storage.Weather w;
uint256 earnedBeans;
uint256[14] deprecated;
mapping(address => Account.State) a;
uint32 deprecated_bip0Start; // ─────┐ 4
uint32 deprecated_hotFix3Start; // ──┘ 4 (8/32)
mapping(uint32 => Storage.Fundraiser) fundraisers;
uint32 fundraiserIndex; // 4 (4/32)
mapping(address => bool) deprecated_isBudget;
mapping(uint256 => bytes32) podListings;
mapping(bytes32 => uint256) podOrders;
mapping(address => Storage.AssetSilo) siloBalances;
mapping(address => Storage.SiloSettings) ss;
uint256[2] deprecated2;
uint128 deprecated_newEarnedStalk; // ──────┐ 16
uint128 deprecated_vestingPeriodRoots; // ──┘ 16 (32/32)
mapping(uint32 => uint256) sops;
// Internal Balances
mapping(address => mapping(IERC20 => uint256)) internalTokenBalance;
// Unripe
mapping(address => mapping(address => bool)) unripeClaimed;
mapping(address => Storage.UnripeSettings) u;
// Fertilizer
mapping(uint128 => uint256) fertilizer;
mapping(uint128 => uint128) nextFid;
uint256 activeFertilizer;
uint256 fertilizedIndex;
uint256 unfertilizedIndex;
uint128 fFirst;
uint128 fLast;
uint128 bpf;
uint256 recapitalized;
// Farm
uint256 isFarm;
// Ownership
address ownerCandidate;
// Well
mapping(address => bytes) wellOracleSnapshots;
uint256 deprecated_beanEthPrice;
// Silo V3 BDV Migration
mapping(address => uint256) migratedBdvs;
// Well/Curve + USD Price Oracle
mapping(address => Storage.TwaReserves) twaReserves;
mapping(address => uint256) usdTokenPrice;
// Seed Gauge
Storage.SeedGauge seedGauge;
bytes32[144] casesV2;
// Germination
Storage.TotalGerminating oddGerminating;
Storage.TotalGerminating evenGerminating;
// mapping from season => unclaimed germinating stalk and roots
mapping(uint32 => Storage.Sr) unclaimedGerminating;
Storage.WhitelistStatus[] whitelistStatuses;
address sopWell;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {LibRedundantMath256} from "contracts/libraries/LibRedundantMath256.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {AppStorage, LibAppStorage} from "./LibL1AppStorage.sol";
/**
* @title LibInternalBalance
* @author LeoFib, Publius
* @notice Handles internal read/write functions for Internal User Balances.
* Largely inspired by Balancer's Vault.
*/
library LibBalance {
using SafeERC20 for IERC20;
using LibRedundantMath256 for uint256;
using SafeCast for uint256;
/**
* @notice Emitted when an account's Internal Balance changes.
* @param account The account whose balance changed.
* @param token Which token balance changed.
* @param delta The amount the balance increased (if positive) or decreased (if negative).
*/
event InternalBalanceChanged(address indexed account, IERC20 indexed token, int256 delta);
/**
* @dev Returns the sum of `account`'s Internal and External (ERC20) balance of `token`
*/
function getBalance(address account, IERC20 token) internal view returns (uint256 balance) {
balance = token.balanceOf(account).add(getInternalBalance(account, token));
return balance;
}
/**
* @dev Increases `account`'s Internal Balance of `token` by `amount`.
*/
function increaseInternalBalance(address account, IERC20 token, uint256 amount) internal {
uint256 currentBalance = getInternalBalance(account, token);
uint256 newBalance = currentBalance.add(amount);
setInternalBalance(account, token, newBalance, amount.toInt256());
}
/**
* @dev Decreases `account`'s Internal Balance of `token` by `amount`. If `allowPartial` is true, this function
* doesn't revert if `account` doesn't have enough balance, and sets it to zero and returns the deducted amount
* instead.
*/
function decreaseInternalBalance(
address account,
IERC20 token,
uint256 amount,
bool allowPartial
) internal returns (uint256 deducted) {
uint256 currentBalance = getInternalBalance(account, token);
require(
allowPartial || (currentBalance >= amount),
"Balance: Insufficient internal balance"
);
deducted = Math.min(currentBalance, amount);
// By construction, `deducted` is lower or equal to `currentBalance`,
// so we don't need to use checked arithmetic.
uint256 newBalance = currentBalance - deducted;
setInternalBalance(account, token, newBalance, -(deducted.toInt256()));
}
/**
* @dev Sets `account`'s Internal Balance of `token` to `newBalance`.
*
* Emits an {InternalBalanceChanged} event. This event includes `delta`, which is the amount the balance increased
* (if positive) or decreased (if negative). To avoid reading the current balance in order to compute the delta,
* this function relies on the caller providing it directly.
*/
function setInternalBalance(
address account,
IERC20 token,
uint256 newBalance,
int256 delta
) private {
AppStorage storage s = LibAppStorage.diamondStorage();
s.internalTokenBalance[account][token] = newBalance;
emit InternalBalanceChanged(account, token, delta);
}
/**
* @dev Returns `account`'s Internal Balance of `token`.
*/
function getInternalBalance(
address account,
IERC20 token
) internal view returns (uint256 balance) {
AppStorage storage s = LibAppStorage.diamondStorage();
balance = s.internalTokenBalance[account][token];
}
}/*
SPDX-License-Identifier: MIT
*/
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import "./LibL1AppStorage.sol";
/**
* @author Publius
* @title LibEth
**/
library LibEth {
function refundEth() internal {
AppStorage storage s = LibAppStorage.diamondStorage();
if (address(this).balance > 0 && s.isFarm != 2) {
(bool success, ) = msg.sender.call{value: address(this).balance}(new bytes(0));
require(success, "Eth transfer Failed.");
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
// Import all of AppStorage to give importers of LibAppStorage access to {Account}, etc.
import "../L1AppStorage.sol";
/**
* @title LibAppStorage
* @author Publius
* @notice Allows libaries to access Beanstalk's state.
*/
library LibAppStorage {
function diamondStorage() internal pure returns (AppStorage storage ds) {
assembly {
ds.slot := 0
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {AppStorage, LibAppStorage} from "./LibL1AppStorage.sol";
/**
* @title LibTokenApprove
* @author Publius
*/
library LibTokenApprove {
event TokenApproval(
address indexed owner,
address indexed spender,
IERC20 token,
uint256 amount
);
function approve(address account, address spender, IERC20 token, uint256 amount) internal {
AppStorage storage s = LibAppStorage.diamondStorage();
s.a[account].tokenAllowances[spender][token] = amount;
emit TokenApproval(account, spender, token, amount);
}
function allowance(
address account,
address spender,
IERC20 token
) internal view returns (uint256) {
AppStorage storage s = LibAppStorage.diamondStorage();
return s.a[account].tokenAllowances[spender][token];
}
function spendAllowance(address owner, address spender, IERC20 token, uint256 amount) internal {
uint256 currentAllowance = allowance(owner, spender, token);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "Token: insufficient allowance");
approve(owner, spender, token, currentAllowance - amount);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {LibRedundantMath256} from "contracts/libraries/LibRedundantMath256.sol";
import "./LibBalance.sol";
import {IBean} from "contracts/interfaces/IBean.sol";
/**
* @title LibTransfer
* @author Publius
* @notice Handles the recieving and sending of Tokens to/from internal Balances.
*/
library LibTransfer {
using SafeERC20 for IERC20;
using LibRedundantMath256 for uint256;
enum From {
EXTERNAL,
INTERNAL,
EXTERNAL_INTERNAL,
INTERNAL_TOLERANT
}
enum To {
EXTERNAL,
INTERNAL
}
function transferToken(
IERC20 token,
address sender,
address recipient,
uint256 amount,
From fromMode,
To toMode
) internal returns (uint256 transferredAmount) {
if (fromMode == From.EXTERNAL && toMode == To.EXTERNAL) {
uint256 beforeBalance = token.balanceOf(recipient);
token.safeTransferFrom(sender, recipient, amount);
return token.balanceOf(recipient).sub(beforeBalance);
}
amount = receiveToken(token, amount, sender, fromMode);
sendToken(token, amount, recipient, toMode);
return amount;
}
function receiveToken(
IERC20 token,
uint256 amount,
address sender,
From mode
) internal returns (uint256 receivedAmount) {
if (amount == 0) return 0;
if (mode != From.EXTERNAL) {
receivedAmount = LibBalance.decreaseInternalBalance(
sender,
token,
amount,
mode != From.INTERNAL
);
if (amount == receivedAmount || mode == From.INTERNAL_TOLERANT) return receivedAmount;
}
uint256 beforeBalance = token.balanceOf(address(this));
token.safeTransferFrom(sender, address(this), amount - receivedAmount);
return receivedAmount.add(token.balanceOf(address(this)).sub(beforeBalance));
}
function sendToken(IERC20 token, uint256 amount, address recipient, To mode) internal {
if (amount == 0) return;
if (mode == To.INTERNAL) LibBalance.increaseInternalBalance(recipient, token, amount);
else token.safeTransfer(recipient, amount);
}
function burnToken(
IBean token,
uint256 amount,
address sender,
From mode
) internal returns (uint256 burnt) {
// burnToken only can be called with Unripe Bean, Unripe Bean:3Crv or Bean token, which are all Beanstalk tokens.
// Beanstalk's ERC-20 implementation uses OpenZeppelin's ERC20Burnable
// which reverts if burnFrom function call cannot burn full amount.
if (mode == From.EXTERNAL) {
token.burnFrom(sender, amount);
burnt = amount;
} else {
burnt = LibTransfer.receiveToken(token, amount, sender, mode);
token.burn(burnt);
}
}
function mintToken(IBean token, uint256 amount, address recipient, To mode) internal {
if (mode == To.EXTERNAL) {
token.mint(recipient, amount);
} else {
token.mint(address(this), amount);
LibTransfer.sendToken(token, amount, recipient, mode);
}
}
}/*
SPDX-License-Identifier: MIT
*/
pragma solidity ^0.8.20;
import "contracts/interfaces/IWETH.sol";
import "contracts/beanstalk/migration/L1Libraries/LibTransfer.sol";
/**
* @author publius
* @title LibWeth handles wrapping and unwrapping Weth
* Largely inspired by Balancer's Vault
**/
library LibWeth {
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
function wrap(uint256 amount, LibTransfer.To mode) internal {
deposit(amount);
LibTransfer.sendToken(IERC20(WETH), amount, msg.sender, mode);
}
function unwrap(uint256 amount, LibTransfer.From mode) internal {
amount = LibTransfer.receiveToken(IERC20(WETH), amount, msg.sender, mode);
withdraw(amount);
(bool success, ) = msg.sender.call{value: amount}(new bytes(0));
require(success, "Weth: unwrap failed");
}
function deposit(uint256 amount) private {
IWETH(WETH).deposit{value: amount}();
}
function withdraw(uint256 amount) private {
IWETH(WETH).withdraw(amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
pragma experimental ABIEncoderV2;
import "./L1AppStorage.sol";
/**
* @author Beanstalk Farms
* @title Variation of Oepn Zeppelins reentrant guard to include Silo Update
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts%2Fsecurity%2FReentrancyGuard.sol
**/
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
AppStorage internal s;
modifier nonReentrant() {
require(s.reentrantStatus != _ENTERED, "ReentrancyGuard: reentrant call");
s.reentrantStatus = _ENTERED;
_;
s.reentrantStatus = _NOT_ENTERED;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
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);
}// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; /******************************************************************************\ * Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) /******************************************************************************/ interface IDiamondCut { enum FacetCutAction { Add, Replace, Remove } struct FacetCut { address facetAddress; FacetCutAction action; bytes4[] functionSelectors; } /// @notice Add/replace/remove any number of functions and optionally execute /// a function with delegatecall /// @param _diamondCut Contains the facet addresses and function selectors /// @param _init The address of the contract or facet to execute _calldata /// @param _calldata A function call, including function selector and arguments /// _calldata is executed with delegatecall on _init function diamondCut( FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata ) external; event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); }
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
/**
* @notice Duplicate of OpenZeppelin's IERC1155Receiver with the IERC165 inheritance removed.
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}/*
SPDX-License-Identifier: MIT
*/
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @author Publius
* @title WETH Interface
**/
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @author Publius, funderbrker
* @title LibRedundantMath variation of Open Zeppelin's Safe Math library for uint256.
* @dev Newly developed code should not use this library. Instead opt for native arithmetic operators.
*
* This library replicates the behavior of 0.7 SafeMath libraries for 0.8. Safe math is unnecessary
* in solidity ^0.8, so the functionality here is mostly redundant with default arithmetic
* operators. However, manually updating over 1000 math operations throughout the repo was
* deemed too likely to introduce logic errors. Instead, the original syntax was kept
* and the underlying logic updated to be 0.8 appropriate.
**/
library LibRedundantMath256 {
/**
* @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) {
return a + b;
}
/**
* @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) {
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) {
return a * b;
}
/**
* @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) {
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) {
return a % b;
}
}{
"optimizer": {
"enabled": true,
"runs": 100
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintToInt","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"int256","name":"delta","type":"int256"}],"name":"InternalBalanceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"int256","name":"delta","type":"int256"}],"name":"InternalBalanceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenApproval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenApproval","type":"event"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approveToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseTokenAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getAllBalance","outputs":[{"components":[{"internalType":"uint256","name":"internalBalance","type":"uint256"},{"internalType":"uint256","name":"externalBalance","type":"uint256"},{"internalType":"uint256","name":"totalBalance","type":"uint256"}],"internalType":"struct L1TokenFacet.Balance","name":"b","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"getAllBalances","outputs":[{"components":[{"internalType":"uint256","name":"internalBalance","type":"uint256"},{"internalType":"uint256","name":"externalBalance","type":"uint256"},{"internalType":"uint256","name":"totalBalance","type":"uint256"}],"internalType":"struct L1TokenFacet.Balance[]","name":"balances","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"getBalances","outputs":[{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getExternalBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"getExternalBalances","outputs":[{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getInternalBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"getInternalBalances","outputs":[{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseTokenAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"tokenAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum LibTransfer.To","name":"toMode","type":"uint8"}],"name":"transferInternalTokenFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum LibTransfer.From","name":"fromMode","type":"uint8"},{"internalType":"enum LibTransfer.To","name":"toMode","type":"uint8"}],"name":"transferToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum LibTransfer.From","name":"mode","type":"uint8"}],"name":"unwrapEth","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum LibTransfer.To","name":"mode","type":"uint8"}],"name":"wrapEth","outputs":[],"stateMutability":"payable","type":"function"}]Contract Creation Code
6080604052348015600f57600080fd5b50611d588061001f6000396000f3fe6080604052600436106100e95760003560e01c8063b6fc38f911610085578063b6fc38f914610226578063bc197c8114610253578063bd32fac31461028c578063c37147231461029f578063d3f4ec6f146102bf578063d4fac45d146102d2578063da3e3397146102f2578063f23a6e6114610305578063fdb288111461032057600080fd5b80630bc33ce4146100ee5780631c059365146101235780634667fa3d146101385780636204aa43146101665780636a385ae9146101795780638a65d2e0146101a65780638e8758d8146101c6578063a98edb17146101e6578063b39062e614610206575b600080fd5b3480156100fa57600080fd5b5061010e61010936600461168e565b61034d565b60405190151581526020015b60405180910390f35b6101366101313660046116de565b610412565b005b34801561014457600080fd5b5061015861015336600461170a565b610428565b60405190815260200161011a565b610136610174366004611752565b61049f565b34801561018557600080fd5b506101996101943660046117ca565b6104be565b60405161011a91906118a3565b3480156101b257600080fd5b506101586101c136600461170a565b610560565b3480156101d257600080fd5b506101586101e13660046118e7565b61056c565b3480156101f257600080fd5b506101996102013660046117ca565b610581565b34801561021257600080fd5b5061010e61022136600461168e565b61061c565b34801561023257600080fd5b506102466102413660046117ca565b610670565b60405161011a9190611932565b34801561025f57600080fd5b5061027361026e366004611a14565b610737565b6040516001600160e01b0319909116815260200161011a565b61013661029a366004611ad2565b610797565b3480156102ab57600080fd5b506101996102ba3660046117ca565b6107a1565b6101366102cd366004611af5565b61083c565b3480156102de57600080fd5b506101586102ed36600461170a565b61089c565b61013661030036600461168e565b6108a8565b34801561031157600080fd5b5061027361026e366004611b4d565b34801561032c57600080fd5b5061034061033b36600461170a565b6108e6565b60405161011a9190611bc8565b601e546000906001190161037c5760405162461bcd60e51b815260040161037390611be9565b60405180910390fd5b6002601e55600061038e33868661093d565b9050828110156103ec5760405162461bcd60e51b8152602060048201526024808201527f53696c6f3a2064656372656173656420616c6c6f77616e63652062656c6f77206044820152637a65726f60e01b6064820152608401610373565b6104013386866103fc8588610976565b610988565b60019150506001601e559392505050565b61041c8282610a06565b610424610a2f565b5050565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190610457908690600401611c20565b602060405180830381865afa158015610474573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104989190611c34565b9392505050565b6104a885610af8565b6104b6853386868686610d1e565b505050505050565b606081516001600160401b038111156104d9576104d96117b4565b604051908082528060200260200182016040528015610502578160200160208202803683370190505b50905060005b8251811015610559576105348484838151811061052757610527611c4d565b602002602001015161089c565b82828151811061054657610546611c4d565b6020908102919091010152600101610508565b5092915050565b60006104988383610e83565b600061057984848461093d565b949350505050565b606081516001600160401b0381111561059c5761059c6117b4565b6040519080825280602002602001820160405280156105c5578160200160208202803683370190505b50905060005b8251811015610559576105f7848483815181106105ea576105ea611c4d565b6020026020010151610560565b82828151811061060957610609611c4d565b60209081029190910101526001016105cb565b601e54600090600119016106425760405162461bcd60e51b815260040161037390611be9565b6002601e556106623385856103fc8661065c85858561093d565b90610eae565b50600180601e559392505050565b606081516001600160401b0381111561068b5761068b6117b4565b6040519080825280602002602001820160405280156106e057816020015b6106cd60405180606001604052806000815260200160008152602001600081525090565b8152602001906001900390816106a95790505b50905060005b8251811015610559576107128484838151811061070557610705611c4d565b60200260200101516108e6565b82828151811061072457610724611c4d565b60209081029190910101526001016106e6565b60405162461bcd60e51b815260206004820152602c60248201527f53696c6f3a2045524331313535206465706f7369747320617265206e6f74206160448201526b31b1b2b83a32b2103cb2ba1760a11b6064820152600090608401610373565b6104248282610eba565b606081516001600160401b038111156107bc576107bc6117b4565b6040519080825280602002602001820160405280156107e5578160200160208202803683370190505b50905060005b8251811015610559576108178484838151811061080a5761080a611c4d565b6020026020010151610428565b82828151811061082957610829611c4d565b60209081029190910101526001016107eb565b601e546001190161085f5760405162461bcd60e51b815260040161037390611be9565b6002601e5561087385858585600186610d1e565b506001600160a01b03841633146108905761089084338785610f94565b50506001601e55505050565b60006104988383611013565b601e54600119016108cb5760405162461bcd60e51b815260040161037390611be9565b6002601e556108dc33848484610988565b50506001601e5550565b61090a60405180606001604052806000815260200160008152602001600081525090565b6109148383610560565b81526109208383610428565b60208201819052815161093291610eae565b604082015292915050565b6001600160a01b039283166000908152603160209081526040808320948616835260169094018152838220929094168152925290205490565b60006104988284611c79565b92915050565b6001600160a01b03848116600081815260316020908152604080832088861680855260169091018352818420958816808552958352818420879055815195865291850186905291939092917f2c6e87be19eb54f68d01e25832a3ea2b8247b5cc92fcc754d67e161193a154f591015b60405180910390a35050505050565b610a0f8261108f565b61042473c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28333846110f2565b60008047118015610a4557508060490154600214155b15610af5576040805160008082526020820190925233904790604051610a6b9190611c8c565b60006040518083038185875af1925050503d8060008114610aa8576040519150601f19603f3d011682016040523d82523d6000602084013e610aad565b606091505b50509050806104245760405162461bcd60e51b815260206004820152601460248201527322ba34103a3930b739b332b9102330b4b632b21760611b6044820152606401610373565b50565b73bea0000029ad1c77d3d5d23ba2d8893db9d1efaa196001600160a01b03821601610b765760405162461bcd60e51b815260206004820152602860248201527f546f6b656e46616365743a204265616e732063616e6e6f74206265207472616e60448201526739b332b93932b21760c11b6064820152608401610373565b73bea0e11282e2bb5893bece110cf199501e872bac196001600160a01b03821601610c025760405162461bcd60e51b815260206004820152603660248201527f546f6b656e46616365743a204265616e4574682057656c6c20546f6b656e732060448201527531b0b73737ba103132903a3930b739b332b93932b21760511b6064820152608401610373565b73bea0000113b0d182f4064c86b71c315389e4715c196001600160a01b03821601610c915760405162461bcd60e51b815260206004820152603960248201527f546f6b656e46616365743a204265616e7773744574682057656c6c20546f6b6560448201527837399031b0b73737ba103132903a3930b739b332b93932b21760391b6064820152608401610373565b73c9c32cd16bf7efb85ff14e0c8603cc90f6f2ee48196001600160a01b03821601610af55760405162461bcd60e51b815260206004820152603760248201527f546f6b656e46616365743a204265616e336372762057656c6c20546f6b656e736044820152761031b0b73737ba103132903a3930b739b332b93932b21760491b6064820152608401610373565b600080836003811115610d3357610d33611cbb565b148015610d5157506000826001811115610d4f57610d4f611cbb565b145b15610e5c576040516370a0823160e01b81526000906001600160a01b038916906370a0823190610d85908990600401611c20565b602060405180830381865afa158015610da2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc69190611c34565b9050610ddd6001600160a01b03891688888861113b565b610e5481896001600160a01b03166370a08231896040518263ffffffff1660e01b8152600401610e0d9190611c20565b602060405180830381865afa158015610e2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4e9190611c34565b90610976565b915050610e79565b610e68878588866111a2565b9350610e76878587856110f2565b50825b9695505050505050565b6001600160a01b039182166000908152603e6020908152604080832093909416825291909152205490565b60006104988284611cd1565b610eda73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28333846111a2565b9150610ee5826112e1565b6040805160008082526020820190925233908490604051610f069190611c8c565b60006040518083038185875af1925050503d8060008114610f43576040519150601f19603f3d011682016040523d82523d6000602084013e610f48565b606091505b5050905080610f8f5760405162461bcd60e51b815260206004820152601360248201527215d95d1a0e881d5b9ddc985c0819985a5b1959606a1b6044820152606401610373565b505050565b6000610fa185858561093d565b9050600019811461100c5781811015610ffc5760405162461bcd60e51b815260206004820152601d60248201527f546f6b656e3a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610373565b61100c8585856103fc8686611c79565b5050505050565b60006104986110228484610e83565b6040516370a0823160e01b81526001600160a01b038516906370a082319061104e908890600401611c20565b602060405180830381865afa15801561106b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065c9190611c34565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156110de57600080fd5b505af11580156104b6573d6000803e3d6000fd5b821561113557600181600181111561110c5761110c611cbb565b036111215761111c828585611342565b611135565b6111356001600160a01b0385168385611372565b50505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526111359186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506113a3565b6000836000036111b457506000610579565b60008260038111156111c8576111c8611cbb565b14611214576111ee83868660018660038111156111e7576111e7611cbb565b14156113fd565b90508084148061120f5750600382600381111561120d5761120d611cbb565b145b610579575b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190611243903090600401611c20565b602060405180830381865afa158015611260573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112849190611c34565b90506112a784306112958589611c79565b6001600160a01b038a1692919061113b565b610e796112da82886001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610e0d9190611c20565b8390610eae565b604051632e1a7d4d60e01b81526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b15801561132e57600080fd5b505af115801561100c573d6000803e3d6000fd5b600061134e8484610e83565b9050600061135c8284610eae565b905061100c85858361136d876114af565b6114e0565b6040516001600160a01b03838116602483015260448201839052610f8f91859182169063a9059cbb90606401611170565b60006113b86001600160a01b0384168361153b565b905080516000141580156113dd5750808060200190518101906113db9190611ce4565b155b15610f8f5782604051635274afe760e01b81526004016103739190611c20565b60008061140a8686610e83565b905082806114185750838110155b6114735760405162461bcd60e51b815260206004820152602660248201527f42616c616e63653a20496e73756666696369656e7420696e7465726e616c2062604482015265616c616e636560d01b6064820152608401610373565b61147d8185611549565b9150600061148b8383611c79565b90506114a587878361149c876114af565b61136d90611d06565b5050949350505050565b60006001600160ff1b038211156114dc5760405163123baf0360e11b815260048101839052602401610373565b5090565b6001600160a01b038481166000818152603e6020908152604080832094881680845294825280832087905551858152919392917f18e1ea4139e68413d7d08aa752e71568e36b2c5bf940893314c2c5b01eaa0c4291016109f7565b60606104988383600061155f565b60008183106115585781610498565b5090919050565b606081471015611584573060405163cd78605960e01b81526004016103739190611c20565b600080856001600160a01b031684866040516115a09190611c8c565b60006040518083038185875af1925050503d80600081146115dd576040519150601f19603f3d011682016040523d82523d6000602084013e6115e2565b606091505b5091509150610e79868383606082611602576115fd82611640565b610498565b815115801561161957506001600160a01b0384163b155b156116395783604051639996b31560e01b81526004016103739190611c20565b5080610498565b8051156116505780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114610af557600080fd5b803561168981611669565b919050565b6000806000606084860312156116a357600080fd5b83356116ae81611669565b925060208401356116be81611669565b929592945050506040919091013590565b80356002811061168957600080fd5b600080604083850312156116f157600080fd5b82359150611701602084016116cf565b90509250929050565b6000806040838503121561171d57600080fd5b823561172881611669565b9150602083013561173881611669565b809150509250929050565b80356004811061168957600080fd5b600080600080600060a0868803121561176a57600080fd5b853561177581611669565b9450602086013561178581611669565b93506040860135925061179a60608701611743565b91506117a8608087016116cf565b90509295509295909350565b634e487b7160e01b600052604160045260246000fd5b600080604083850312156117dd57600080fd5b82356117e881611669565b91506020838101356001600160401b038082111561180557600080fd5b818601915086601f83011261181957600080fd5b81358181111561182b5761182b6117b4565b8060051b604051601f19603f83011681018181108582111715611850576118506117b4565b60405291825284820192508381018501918983111561186e57600080fd5b938501935b82851015611893576118848561167e565b84529385019392850192611873565b8096505050505050509250929050565b6020808252825182820181905260009190848201906040850190845b818110156118db578351835292840192918401916001016118bf565b50909695505050505050565b6000806000606084860312156118fc57600080fd5b833561190781611669565b9250602084013561191781611669565b9150604084013561192781611669565b809150509250925092565b6020808252825182820181905260009190848201906040850190845b818110156118db576119758385518051825260208082015190830152604090810151910152565b928401926060929092019160010161194e565b60008083601f84011261199a57600080fd5b5081356001600160401b038111156119b157600080fd5b6020830191508360208260051b85010111156119cc57600080fd5b9250929050565b60008083601f8401126119e557600080fd5b5081356001600160401b038111156119fc57600080fd5b6020830191508360208285010111156119cc57600080fd5b60008060008060008060008060a0898b031215611a3057600080fd5b8835611a3b81611669565b97506020890135611a4b81611669565b965060408901356001600160401b0380821115611a6757600080fd5b611a738c838d01611988565b909850965060608b0135915080821115611a8c57600080fd5b611a988c838d01611988565b909650945060808b0135915080821115611ab157600080fd5b50611abe8b828c016119d3565b999c989b5096995094979396929594505050565b60008060408385031215611ae557600080fd5b8235915061170160208401611743565b600080600080600060a08688031215611b0d57600080fd5b8535611b1881611669565b94506020860135611b2881611669565b93506040860135611b3881611669565b9250606086013591506117a8608087016116cf565b60008060008060008060a08789031215611b6657600080fd5b8635611b7181611669565b95506020870135611b8181611669565b9450604087013593506060870135925060808701356001600160401b03811115611baa57600080fd5b611bb689828a016119d3565b979a9699509497509295939492505050565b81518152602080830151908201526040808301519082015260608101610982565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b0391909116815260200190565b600060208284031215611c4657600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561098257610982611c63565b6000825160005b81811015611cad5760208186018101518583015201611c93565b506000920191825250919050565b634e487b7160e01b600052602160045260246000fd5b8082018082111561098257610982611c63565b600060208284031215611cf657600080fd5b8151801515811461049857600080fd5b6000600160ff1b8201611d1b57611d1b611c63565b506000039056fea264697066735822122069f37d952b5e9264a542f6fea1b436b676d761ab174a3a6d4226dcb72721d8de64736f6c63430008190033
Deployed Bytecode
0x6080604052600436106100e95760003560e01c8063b6fc38f911610085578063b6fc38f914610226578063bc197c8114610253578063bd32fac31461028c578063c37147231461029f578063d3f4ec6f146102bf578063d4fac45d146102d2578063da3e3397146102f2578063f23a6e6114610305578063fdb288111461032057600080fd5b80630bc33ce4146100ee5780631c059365146101235780634667fa3d146101385780636204aa43146101665780636a385ae9146101795780638a65d2e0146101a65780638e8758d8146101c6578063a98edb17146101e6578063b39062e614610206575b600080fd5b3480156100fa57600080fd5b5061010e61010936600461168e565b61034d565b60405190151581526020015b60405180910390f35b6101366101313660046116de565b610412565b005b34801561014457600080fd5b5061015861015336600461170a565b610428565b60405190815260200161011a565b610136610174366004611752565b61049f565b34801561018557600080fd5b506101996101943660046117ca565b6104be565b60405161011a91906118a3565b3480156101b257600080fd5b506101586101c136600461170a565b610560565b3480156101d257600080fd5b506101586101e13660046118e7565b61056c565b3480156101f257600080fd5b506101996102013660046117ca565b610581565b34801561021257600080fd5b5061010e61022136600461168e565b61061c565b34801561023257600080fd5b506102466102413660046117ca565b610670565b60405161011a9190611932565b34801561025f57600080fd5b5061027361026e366004611a14565b610737565b6040516001600160e01b0319909116815260200161011a565b61013661029a366004611ad2565b610797565b3480156102ab57600080fd5b506101996102ba3660046117ca565b6107a1565b6101366102cd366004611af5565b61083c565b3480156102de57600080fd5b506101586102ed36600461170a565b61089c565b61013661030036600461168e565b6108a8565b34801561031157600080fd5b5061027361026e366004611b4d565b34801561032c57600080fd5b5061034061033b36600461170a565b6108e6565b60405161011a9190611bc8565b601e546000906001190161037c5760405162461bcd60e51b815260040161037390611be9565b60405180910390fd5b6002601e55600061038e33868661093d565b9050828110156103ec5760405162461bcd60e51b8152602060048201526024808201527f53696c6f3a2064656372656173656420616c6c6f77616e63652062656c6f77206044820152637a65726f60e01b6064820152608401610373565b6104013386866103fc8588610976565b610988565b60019150506001601e559392505050565b61041c8282610a06565b610424610a2f565b5050565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190610457908690600401611c20565b602060405180830381865afa158015610474573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104989190611c34565b9392505050565b6104a885610af8565b6104b6853386868686610d1e565b505050505050565b606081516001600160401b038111156104d9576104d96117b4565b604051908082528060200260200182016040528015610502578160200160208202803683370190505b50905060005b8251811015610559576105348484838151811061052757610527611c4d565b602002602001015161089c565b82828151811061054657610546611c4d565b6020908102919091010152600101610508565b5092915050565b60006104988383610e83565b600061057984848461093d565b949350505050565b606081516001600160401b0381111561059c5761059c6117b4565b6040519080825280602002602001820160405280156105c5578160200160208202803683370190505b50905060005b8251811015610559576105f7848483815181106105ea576105ea611c4d565b6020026020010151610560565b82828151811061060957610609611c4d565b60209081029190910101526001016105cb565b601e54600090600119016106425760405162461bcd60e51b815260040161037390611be9565b6002601e556106623385856103fc8661065c85858561093d565b90610eae565b50600180601e559392505050565b606081516001600160401b0381111561068b5761068b6117b4565b6040519080825280602002602001820160405280156106e057816020015b6106cd60405180606001604052806000815260200160008152602001600081525090565b8152602001906001900390816106a95790505b50905060005b8251811015610559576107128484838151811061070557610705611c4d565b60200260200101516108e6565b82828151811061072457610724611c4d565b60209081029190910101526001016106e6565b60405162461bcd60e51b815260206004820152602c60248201527f53696c6f3a2045524331313535206465706f7369747320617265206e6f74206160448201526b31b1b2b83a32b2103cb2ba1760a11b6064820152600090608401610373565b6104248282610eba565b606081516001600160401b038111156107bc576107bc6117b4565b6040519080825280602002602001820160405280156107e5578160200160208202803683370190505b50905060005b8251811015610559576108178484838151811061080a5761080a611c4d565b6020026020010151610428565b82828151811061082957610829611c4d565b60209081029190910101526001016107eb565b601e546001190161085f5760405162461bcd60e51b815260040161037390611be9565b6002601e5561087385858585600186610d1e565b506001600160a01b03841633146108905761089084338785610f94565b50506001601e55505050565b60006104988383611013565b601e54600119016108cb5760405162461bcd60e51b815260040161037390611be9565b6002601e556108dc33848484610988565b50506001601e5550565b61090a60405180606001604052806000815260200160008152602001600081525090565b6109148383610560565b81526109208383610428565b60208201819052815161093291610eae565b604082015292915050565b6001600160a01b039283166000908152603160209081526040808320948616835260169094018152838220929094168152925290205490565b60006104988284611c79565b92915050565b6001600160a01b03848116600081815260316020908152604080832088861680855260169091018352818420958816808552958352818420879055815195865291850186905291939092917f2c6e87be19eb54f68d01e25832a3ea2b8247b5cc92fcc754d67e161193a154f591015b60405180910390a35050505050565b610a0f8261108f565b61042473c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28333846110f2565b60008047118015610a4557508060490154600214155b15610af5576040805160008082526020820190925233904790604051610a6b9190611c8c565b60006040518083038185875af1925050503d8060008114610aa8576040519150601f19603f3d011682016040523d82523d6000602084013e610aad565b606091505b50509050806104245760405162461bcd60e51b815260206004820152601460248201527322ba34103a3930b739b332b9102330b4b632b21760611b6044820152606401610373565b50565b73bea0000029ad1c77d3d5d23ba2d8893db9d1efaa196001600160a01b03821601610b765760405162461bcd60e51b815260206004820152602860248201527f546f6b656e46616365743a204265616e732063616e6e6f74206265207472616e60448201526739b332b93932b21760c11b6064820152608401610373565b73bea0e11282e2bb5893bece110cf199501e872bac196001600160a01b03821601610c025760405162461bcd60e51b815260206004820152603660248201527f546f6b656e46616365743a204265616e4574682057656c6c20546f6b656e732060448201527531b0b73737ba103132903a3930b739b332b93932b21760511b6064820152608401610373565b73bea0000113b0d182f4064c86b71c315389e4715c196001600160a01b03821601610c915760405162461bcd60e51b815260206004820152603960248201527f546f6b656e46616365743a204265616e7773744574682057656c6c20546f6b6560448201527837399031b0b73737ba103132903a3930b739b332b93932b21760391b6064820152608401610373565b73c9c32cd16bf7efb85ff14e0c8603cc90f6f2ee48196001600160a01b03821601610af55760405162461bcd60e51b815260206004820152603760248201527f546f6b656e46616365743a204265616e336372762057656c6c20546f6b656e736044820152761031b0b73737ba103132903a3930b739b332b93932b21760491b6064820152608401610373565b600080836003811115610d3357610d33611cbb565b148015610d5157506000826001811115610d4f57610d4f611cbb565b145b15610e5c576040516370a0823160e01b81526000906001600160a01b038916906370a0823190610d85908990600401611c20565b602060405180830381865afa158015610da2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc69190611c34565b9050610ddd6001600160a01b03891688888861113b565b610e5481896001600160a01b03166370a08231896040518263ffffffff1660e01b8152600401610e0d9190611c20565b602060405180830381865afa158015610e2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4e9190611c34565b90610976565b915050610e79565b610e68878588866111a2565b9350610e76878587856110f2565b50825b9695505050505050565b6001600160a01b039182166000908152603e6020908152604080832093909416825291909152205490565b60006104988284611cd1565b610eda73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28333846111a2565b9150610ee5826112e1565b6040805160008082526020820190925233908490604051610f069190611c8c565b60006040518083038185875af1925050503d8060008114610f43576040519150601f19603f3d011682016040523d82523d6000602084013e610f48565b606091505b5050905080610f8f5760405162461bcd60e51b815260206004820152601360248201527215d95d1a0e881d5b9ddc985c0819985a5b1959606a1b6044820152606401610373565b505050565b6000610fa185858561093d565b9050600019811461100c5781811015610ffc5760405162461bcd60e51b815260206004820152601d60248201527f546f6b656e3a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610373565b61100c8585856103fc8686611c79565b5050505050565b60006104986110228484610e83565b6040516370a0823160e01b81526001600160a01b038516906370a082319061104e908890600401611c20565b602060405180830381865afa15801561106b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065c9190611c34565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156110de57600080fd5b505af11580156104b6573d6000803e3d6000fd5b821561113557600181600181111561110c5761110c611cbb565b036111215761111c828585611342565b611135565b6111356001600160a01b0385168385611372565b50505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526111359186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506113a3565b6000836000036111b457506000610579565b60008260038111156111c8576111c8611cbb565b14611214576111ee83868660018660038111156111e7576111e7611cbb565b14156113fd565b90508084148061120f5750600382600381111561120d5761120d611cbb565b145b610579575b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190611243903090600401611c20565b602060405180830381865afa158015611260573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112849190611c34565b90506112a784306112958589611c79565b6001600160a01b038a1692919061113b565b610e796112da82886001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610e0d9190611c20565b8390610eae565b604051632e1a7d4d60e01b81526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b15801561132e57600080fd5b505af115801561100c573d6000803e3d6000fd5b600061134e8484610e83565b9050600061135c8284610eae565b905061100c85858361136d876114af565b6114e0565b6040516001600160a01b03838116602483015260448201839052610f8f91859182169063a9059cbb90606401611170565b60006113b86001600160a01b0384168361153b565b905080516000141580156113dd5750808060200190518101906113db9190611ce4565b155b15610f8f5782604051635274afe760e01b81526004016103739190611c20565b60008061140a8686610e83565b905082806114185750838110155b6114735760405162461bcd60e51b815260206004820152602660248201527f42616c616e63653a20496e73756666696369656e7420696e7465726e616c2062604482015265616c616e636560d01b6064820152608401610373565b61147d8185611549565b9150600061148b8383611c79565b90506114a587878361149c876114af565b61136d90611d06565b5050949350505050565b60006001600160ff1b038211156114dc5760405163123baf0360e11b815260048101839052602401610373565b5090565b6001600160a01b038481166000818152603e6020908152604080832094881680845294825280832087905551858152919392917f18e1ea4139e68413d7d08aa752e71568e36b2c5bf940893314c2c5b01eaa0c4291016109f7565b60606104988383600061155f565b60008183106115585781610498565b5090919050565b606081471015611584573060405163cd78605960e01b81526004016103739190611c20565b600080856001600160a01b031684866040516115a09190611c8c565b60006040518083038185875af1925050503d80600081146115dd576040519150601f19603f3d011682016040523d82523d6000602084013e6115e2565b606091505b5091509150610e79868383606082611602576115fd82611640565b610498565b815115801561161957506001600160a01b0384163b155b156116395783604051639996b31560e01b81526004016103739190611c20565b5080610498565b8051156116505780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114610af557600080fd5b803561168981611669565b919050565b6000806000606084860312156116a357600080fd5b83356116ae81611669565b925060208401356116be81611669565b929592945050506040919091013590565b80356002811061168957600080fd5b600080604083850312156116f157600080fd5b82359150611701602084016116cf565b90509250929050565b6000806040838503121561171d57600080fd5b823561172881611669565b9150602083013561173881611669565b809150509250929050565b80356004811061168957600080fd5b600080600080600060a0868803121561176a57600080fd5b853561177581611669565b9450602086013561178581611669565b93506040860135925061179a60608701611743565b91506117a8608087016116cf565b90509295509295909350565b634e487b7160e01b600052604160045260246000fd5b600080604083850312156117dd57600080fd5b82356117e881611669565b91506020838101356001600160401b038082111561180557600080fd5b818601915086601f83011261181957600080fd5b81358181111561182b5761182b6117b4565b8060051b604051601f19603f83011681018181108582111715611850576118506117b4565b60405291825284820192508381018501918983111561186e57600080fd5b938501935b82851015611893576118848561167e565b84529385019392850192611873565b8096505050505050509250929050565b6020808252825182820181905260009190848201906040850190845b818110156118db578351835292840192918401916001016118bf565b50909695505050505050565b6000806000606084860312156118fc57600080fd5b833561190781611669565b9250602084013561191781611669565b9150604084013561192781611669565b809150509250925092565b6020808252825182820181905260009190848201906040850190845b818110156118db576119758385518051825260208082015190830152604090810151910152565b928401926060929092019160010161194e565b60008083601f84011261199a57600080fd5b5081356001600160401b038111156119b157600080fd5b6020830191508360208260051b85010111156119cc57600080fd5b9250929050565b60008083601f8401126119e557600080fd5b5081356001600160401b038111156119fc57600080fd5b6020830191508360208285010111156119cc57600080fd5b60008060008060008060008060a0898b031215611a3057600080fd5b8835611a3b81611669565b97506020890135611a4b81611669565b965060408901356001600160401b0380821115611a6757600080fd5b611a738c838d01611988565b909850965060608b0135915080821115611a8c57600080fd5b611a988c838d01611988565b909650945060808b0135915080821115611ab157600080fd5b50611abe8b828c016119d3565b999c989b5096995094979396929594505050565b60008060408385031215611ae557600080fd5b8235915061170160208401611743565b600080600080600060a08688031215611b0d57600080fd5b8535611b1881611669565b94506020860135611b2881611669565b93506040860135611b3881611669565b9250606086013591506117a8608087016116cf565b60008060008060008060a08789031215611b6657600080fd5b8635611b7181611669565b95506020870135611b8181611669565b9450604087013593506060870135925060808701356001600160401b03811115611baa57600080fd5b611bb689828a016119d3565b979a9699509497509295939492505050565b81518152602080830151908201526040808301519082015260608101610982565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b0391909116815260200190565b600060208284031215611c4657600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561098257610982611c63565b6000825160005b81811015611cad5760208186018101518583015201611c93565b506000920191825250919050565b634e487b7160e01b600052602160045260246000fd5b8082018082111561098257610982611c63565b600060208284031215611cf657600080fd5b8151801515811461049857600080fd5b6000600160ff1b8201611d1b57611d1b611c63565b506000039056fea264697066735822122069f37d952b5e9264a542f6fea1b436b676d761ab174a3a6d4226dcb72721d8de64736f6c63430008190033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.