Skip to main content

BentoBoxV1

BoringCrypto, Keno

BentoBox

The BentoBox is a vault for tokens. The stored tokens can be flash loaned and used in strategies. Yield from this will go to the token depositors. Rebasing tokens ARE NOT supported and WILL cause loss of funds. Any funds transfered directly onto the BentoBox will be lost, use the deposit function instead.

Methods

DOMAIN_SEPARATOR

function DOMAIN_SEPARATOR() external view returns (bytes32)

Returns

NameTypeDescription
_0bytes32undefined

balanceOf

function balanceOf(contract IERC20, address) external view returns (uint256)

Parameters

NameTypeDescription
_0contract IERC20undefined
_1addressundefined

Returns

NameTypeDescription
_0uint256undefined

batch

function batch(bytes[] calls, bool revertOnFail) external payable returns (bool[] successes, bytes[] results)

Allows batched call to self (this contract).

Parameters

NameTypeDescription
callsbytes[]An array of inputs for each call.
revertOnFailboolIf True then reverts after a failed call and stops doing further calls.

Returns

NameTypeDescription
successesbool[]An array indicating the success of a call, mapped one-to-one to calls.
resultsbytes[]An array with the returned data of each function call, mapped one-to-one to calls.

batchFlashLoan

function batchFlashLoan(contract IBatchFlashBorrower borrower, address[] receivers, contract IERC20[] tokens, uint256[] amounts, bytes data) external nonpayable

Support for batched flashloans. Useful to request multiple different tokens in a single transaction.

Parameters

NameTypeDescription
borrowercontract IBatchFlashBorrowerThe address of the contract that implements and conforms to IBatchFlashBorrower and handles the flashloan.
receiversaddress[]An array of the token receivers. A one-to-one mapping with tokens and amounts.
tokenscontract IERC20[]The addresses of the tokens.
amountsuint256[]of the tokens for each receiver.
databytesThe calldata to pass to the borrower contract.

claimOwnership

function claimOwnership() external nonpayable

Needs to be called by pendingOwner to claim ownership.

deploy

function deploy(address masterContract, bytes data, bool useCreate2) external payable returns (address cloneAddress)

Deploys a given master Contract as a clone. Any ETH transferred with this call is forwarded to the new clone. Emits LogDeploy.

Parameters

NameTypeDescription
masterContractaddressThe address of the contract to clone.
databytesAdditional abi encoded calldata that is passed to the new clone via IMasterContract.init.
useCreate2boolCreates the clone by using the CREATE2 opcode, in this case data will be used as salt.

Returns

NameTypeDescription
cloneAddressaddressAddress of the created clone contract.

deposit

function deposit(contract IERC20 token_, address from, address to, uint256 amount, uint256 share) external payable returns (uint256 amountOut, uint256 shareOut)

Deposit an amount of token represented in either amount or share.

Parameters

NameTypeDescription
token_contract IERC20The ERC-20 token to deposit.
fromaddresswhich account to pull the tokens.
toaddresswhich account to push the tokens.
amountuint256Token amount in native representation to deposit.
shareuint256Token amount represented in shares to deposit. Takes precedence over amount.

Returns

NameTypeDescription
amountOutuint256The amount deposited.
shareOutuint256The deposited amount repesented in shares.

flashLoan

function flashLoan(contract IFlashBorrower borrower, address receiver, contract IERC20 token, uint256 amount, bytes data) external nonpayable

Flashloan ability.

Parameters

NameTypeDescription
borrowercontract IFlashBorrowerThe address of the contract that implements and conforms to IFlashBorrower and handles the flashloan.
receiveraddressAddress of the token receiver.
tokencontract IERC20The address of the token to receive.
amountuint256of the tokens to receive.
databytesThe calldata to pass to the borrower contract.

harvest

function harvest(contract IERC20 token, bool balance, uint256 maxChangeAmount) external nonpayable

The actual process of yield farming. Executes the strategy of token. Optionally does housekeeping if balance is true. maxChangeAmount is relevant for skimming or withdrawing if balance is true.

Parameters

NameTypeDescription
tokencontract IERC20The address of the token for which a strategy is deployed.
balanceboolTrue if housekeeping should be done.
maxChangeAmountuint256The maximum amount for either pulling or pushing from/to the IStrategy contract.

masterContractApproved

function masterContractApproved(address, address) external view returns (bool)

masterContract to user to approval state

Parameters

NameTypeDescription
_0addressundefined
_1addressundefined

Returns

NameTypeDescription
_0boolundefined

masterContractOf

function masterContractOf(address) external view returns (address)

Mapping from clone contracts to their masterContract.

Parameters

NameTypeDescription
_0addressundefined

Returns

NameTypeDescription
_0addressundefined

nonces

function nonces(address) external view returns (uint256)

user nonces for masterContract approvals

Parameters

NameTypeDescription
_0addressundefined

Returns

NameTypeDescription
_0uint256undefined

owner

function owner() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

pendingOwner

function pendingOwner() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

pendingStrategy

function pendingStrategy(contract IERC20) external view returns (contract IStrategy)

Parameters

NameTypeDescription
_0contract IERC20undefined

Returns

NameTypeDescription
_0contract IStrategyundefined

permitToken

function permitToken(contract IERC20 token, address from, address to, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable

Call wrapper that performs ERC20.permit on token. Lookup IERC20.permit.

Parameters

NameTypeDescription
tokencontract IERC20undefined
fromaddressundefined
toaddressundefined
amountuint256undefined
deadlineuint256undefined
vuint8undefined
rbytes32undefined
sbytes32undefined

registerProtocol

function registerProtocol() external nonpayable

Other contracts need to register with this master contract so that users can approve them for the BentoBox.

setMasterContractApproval

function setMasterContractApproval(address user, address masterContract, bool approved, uint8 v, bytes32 r, bytes32 s) external nonpayable

Approves or revokes a masterContract access to user funds.

Parameters

NameTypeDescription
useraddressThe address of the user that approves or revokes access.
masterContractaddressThe address who gains or loses access.
approvedboolIf True approves access. If False revokes access.
vuint8Part of the signature. (See EIP-191)
rbytes32Part of the signature. (See EIP-191)
sbytes32Part of the signature. (See EIP-191)

setStrategy

function setStrategy(contract IERC20 token, contract IStrategy newStrategy) external nonpayable

Sets the contract address of a new strategy that conforms to IStrategy for token. Must be called twice with the same arguments. A new strategy becomes pending first and can be activated once STRATEGY_DELAY is over.

Only the owner of this contract is allowed to change this.

Parameters

NameTypeDescription
tokencontract IERC20The address of the token that maps to a strategy to change.
newStrategycontract IStrategyThe address of the contract that conforms to IStrategy.

setStrategyTargetPercentage

function setStrategyTargetPercentage(contract IERC20 token, uint64 targetPercentage_) external nonpayable

Sets the target percentage of the strategy for token.

Only the owner of this contract is allowed to change this.

Parameters

NameTypeDescription
tokencontract IERC20The address of the token that maps to a strategy to change.
targetPercentage_uint64The new target in percent. Must be lesser or equal to MAX_TARGET_PERCENTAGE.

strategy

function strategy(contract IERC20) external view returns (contract IStrategy)

Parameters

NameTypeDescription
_0contract IERC20undefined

Returns

NameTypeDescription
_0contract IStrategyundefined

strategyData

function strategyData(contract IERC20) external view returns (uint64 strategyStartDate, uint64 targetPercentage, uint128 balance)

Parameters

NameTypeDescription
_0contract IERC20undefined

Returns

NameTypeDescription
strategyStartDateuint64undefined
targetPercentageuint64undefined
balanceuint128undefined

toAmount

function toAmount(contract IERC20 token, uint256 share, bool roundUp) external view returns (uint256 amount)

Helper function represent shares back into the token amount.

Parameters

NameTypeDescription
tokencontract IERC20The ERC-20 token.
shareuint256The amount of shares.
roundUpboolIf the result should be rounded up.

Returns

NameTypeDescription
amountuint256The share amount back into native representation.

toShare

function toShare(contract IERC20 token, uint256 amount, bool roundUp) external view returns (uint256 share)

Helper function to represent an amount of token in shares.

Parameters

NameTypeDescription
tokencontract IERC20The ERC-20 token.
amountuint256The token amount.
roundUpboolIf the result share should be rounded up.

Returns

NameTypeDescription
shareuint256The token amount represented in shares.

totals

function totals(contract IERC20) external view returns (uint128 elastic, uint128 base)

Parameters

NameTypeDescription
_0contract IERC20undefined

Returns

NameTypeDescription
elasticuint128undefined
baseuint128undefined

transfer

function transfer(contract IERC20 token, address from, address to, uint256 share) external nonpayable

Transfer shares from a user account to another one.

Parameters

NameTypeDescription
tokencontract IERC20The ERC-20 token to transfer.
fromaddresswhich user to pull the tokens.
toaddresswhich user to push the tokens.
shareuint256The amount of token in shares.

transferMultiple

function transferMultiple(contract IERC20 token, address from, address[] tos, uint256[] shares) external nonpayable

Transfer shares from a user account to multiple other ones.

Parameters

NameTypeDescription
tokencontract IERC20The ERC-20 token to transfer.
fromaddresswhich user to pull the tokens.
tosaddress[]The receivers of the tokens.
sharesuint256[]The amount of token in shares for each receiver in tos.

transferOwnership

function transferOwnership(address newOwner, bool direct, bool renounce) external nonpayable

Transfers ownership to newOwner. Either directly or claimable by the new pending owner. Can only be invoked by the current owner.

Parameters

NameTypeDescription
newOwneraddressAddress of the new owner.
directboolTrue if newOwner should be set immediately. False if newOwner needs to use claimOwnership.
renounceboolAllows the newOwner to be address(0) if direct and renounce is True. Has no effect otherwise.

whitelistMasterContract

function whitelistMasterContract(address masterContract, bool approved) external nonpayable

Enables or disables a contract for approval without signed message.

Parameters

NameTypeDescription
masterContractaddressundefined
approvedboolundefined

whitelistedMasterContracts

function whitelistedMasterContracts(address) external view returns (bool)

masterContract to whitelisted state for approval without signed message

Parameters

NameTypeDescription
_0addressundefined

Returns

NameTypeDescription
_0boolundefined

withdraw

function withdraw(contract IERC20 token_, address from, address to, uint256 amount, uint256 share) external nonpayable returns (uint256 amountOut, uint256 shareOut)

Withdraws an amount of token from a user account.

Parameters

NameTypeDescription
token_contract IERC20The ERC-20 token to withdraw.
fromaddresswhich user to pull the tokens.
toaddresswhich user to push the tokens.
amountuint256of tokens. Either one of amount or share needs to be supplied.
shareuint256Like above, but share takes precedence over amount.

Returns

NameTypeDescription
amountOutuint256undefined
shareOutuint256undefined

Events

LogDeploy

event LogDeploy(address indexed masterContract, bytes data, address indexed cloneAddress)

Parameters

NameTypeDescription
masterContract indexedaddressundefined
databytesundefined
cloneAddress indexedaddressundefined

LogDeposit

event LogDeposit(contract IERC20 indexed token, address indexed from, address indexed to, uint256 amount, uint256 share)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
from indexedaddressundefined
to indexedaddressundefined
amountuint256undefined
shareuint256undefined

LogFlashLoan

event LogFlashLoan(address indexed borrower, contract IERC20 indexed token, uint256 amount, uint256 feeAmount, address indexed receiver)

Parameters

NameTypeDescription
borrower indexedaddressundefined
token indexedcontract IERC20undefined
amountuint256undefined
feeAmountuint256undefined
receiver indexedaddressundefined

LogRegisterProtocol

event LogRegisterProtocol(address indexed protocol)

Parameters

NameTypeDescription
protocol indexedaddressundefined

LogSetMasterContractApproval

event LogSetMasterContractApproval(address indexed masterContract, address indexed user, bool approved)

Parameters

NameTypeDescription
masterContract indexedaddressundefined
user indexedaddressundefined
approvedboolundefined

LogStrategyDivest

event LogStrategyDivest(contract IERC20 indexed token, uint256 amount)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
amountuint256undefined

LogStrategyInvest

event LogStrategyInvest(contract IERC20 indexed token, uint256 amount)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
amountuint256undefined

LogStrategyLoss

event LogStrategyLoss(contract IERC20 indexed token, uint256 amount)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
amountuint256undefined

LogStrategyProfit

event LogStrategyProfit(contract IERC20 indexed token, uint256 amount)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
amountuint256undefined

LogStrategyQueued

event LogStrategyQueued(contract IERC20 indexed token, contract IStrategy indexed strategy)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
strategy indexedcontract IStrategyundefined

LogStrategySet

event LogStrategySet(contract IERC20 indexed token, contract IStrategy indexed strategy)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
strategy indexedcontract IStrategyundefined

LogStrategyTargetPercentage

event LogStrategyTargetPercentage(contract IERC20 indexed token, uint256 targetPercentage)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
targetPercentageuint256undefined

LogTransfer

event LogTransfer(contract IERC20 indexed token, address indexed from, address indexed to, uint256 share)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
from indexedaddressundefined
to indexedaddressundefined
shareuint256undefined

LogWhiteListMasterContract

event LogWhiteListMasterContract(address indexed masterContract, bool approved)

Parameters

NameTypeDescription
masterContract indexedaddressundefined
approvedboolundefined

LogWithdraw

event LogWithdraw(contract IERC20 indexed token, address indexed from, address indexed to, uint256 amount, uint256 share)

Parameters

NameTypeDescription
token indexedcontract IERC20undefined
from indexedaddressundefined
to indexedaddressundefined
amountuint256undefined
shareuint256undefined

OwnershipTransferred

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)

Parameters

NameTypeDescription
previousOwner indexedaddressundefined
newOwner indexedaddressundefined