Skip to main content

KashiPairMediumRiskV1

This contract contains one of the Kashi strategies used on top of BentoBox.

You can find the full contract here.

Functions

accrue

function accrue() public

Accrues the interest on the borrowed tokens and handles the accumulation of fees.

_isSolvent

function _isSolvent(
address user,
bool open,
uint256 _exchangeRate
) internal view returns (bool)

Internal function used by the solvent modifier, it checks if the user is solvent in the closed liquidation case and returns a boolean.

Parameters

NameTypeDescription
useraddressaddress of user to check solvency for
openboolboolean determining if liquidation case is closed or not
_exchangeRateuint256the exchange rate, used to cache exchangeRate between calls

updateExchangeRate

function updateExchangeRate() public returns (bool updated, uint256 rate)

Gets the exchange rate, ie how much collateral to buy 1e18 asset. Invoked if needed since Oracle queries can be expensive.

Returns

NameTypeDescription
updatedboolboolean determining if the exchange rate has been updated yet or not
rateuint256the new exchange rate that was fetched

_addTokens

 function _addTokens(
IERC20 token,
uint256 share,
uint256 total,
bool skim
) internal

Internal helper function to move tokens.

Parameters

NameTypeDescription
tokenIERC20ERC20 token to add
shareuint256amount of ERC20 token in shares to add
totaluint256total amount to deduct from this contract's balance
skimboolif true, only does a balance check on this contract; false if tokens from msg.sender in bentoBox should be transferred

addCollateral

function addCollateral(
address to,
bool skim,
uint256 share
) public

Adds share amount of collateral from msg.sender to the account to.

Parameters

NameTypeDescription
toaddressreceiver of the tokens
skimboolamount of ERC20 token in shares to add
shareuint256amount of shares to add for to

_removeCollateral

function _removeCollateral(address to, uint256 share) internal

Internal function called by removeCollateral, it removes the amount share of collateral and transfers it to the account to.

Parameters

NameTypeDescription
toaddressreceiver of the shares
shareuint256amount of shares to send

removeCollateral

function removeCollateral(address to, uint256 share) public solvent

Calls _removeCollateral, which removes the amount share of collateral and transfers it to the account to.

Parameters

NameTypeDescription
toaddressreceiver of the shares
shareuint256amount of shares to send

_addAsset

function _addAsset(
address to,
bool skim,
uint256 share
) internal returns (uint256 fraction)

Internal function called by addAsset, it adds the given assets to the lending pair.

Parameters

NameTypeDescription
toaddressreceiver of the assets
skimbooltrue if amount should be skimmed from the deposit balance of msg.sender
shareuint256amount of shares to add

Returns

NameTypeDescription
fractionuint256total fractions added

addAsset

function addAsset(
address to,
bool skim,
uint256 share
) public returns (uint256 fraction)

Calls _addAsset, which adds the given assets to the lending pair.

Parameters

NameTypeDescription
toaddressreceiver of the assets
skimbooltrue if amount should be skimmed from the deposit balance of msg.sender
shareuint256amount of shares to add

Returns

NameTypeDescription
fractionuint256total fractions added

_removeAsset

function _removeAsset(address to, uint256 fraction) internal returns (uint256 share)

Internal function called by removeAsset, it removes an asset from msg.sender and transfers it to to.

Parameters

NameTypeDescription
toaddressreceiver of the removed assets
fractionuint256amount/fraction of assets held to remove

Returns

NameTypeDescription
shareuint256amount of shares transferred to to

removeAsset

function removeAsset(address to, uint256 fraction) public returns (uint256 share)

Calls _removeAsset, which removes an asset from msg.sender and transfers it to to.

Parameters

NameTypeDescription
toaddressreceiver of the removed assets
fractionuint256amount/fraction of assets held to remove

Returns

NameTypeDescription
shareuint256amount of shares transferred to to

_borrow

function _borrow(address to, uint256 amount) internal returns (uint256 part, uint256 share)

Internal function called by borrow, it allows the sender to borrow amount and transfer to to.

Parameters

NameTypeDescription
toaddressreceiver of the borrowed assets
amountuint256amount of assets to borrow

Returns

NameTypeDescription
partuint256total part of debt held by borrowers
shareuint256total amount in shares borrowed

borrow

function borrow(address to, uint256 amount) public solvent returns (uint256 part, uint256 share)

Calls _borrow, which allows the sender to borrow amount and transfer to to.

Parameters

NameTypeDescription
toaddressreceiver of the borrowed assets
amountuint256amount of assets to borrow

Returns

NameTypeDescription
partuint256total part of debt held by borrowers
shareuint256total amount in shares borrowed

_repay

function _repay(
address to,
bool skim,
uint256 part
) internal returns (uint256 amount)

Internal function called by repay, it repays a loan.

Parameters

NameTypeDescription
toaddressaddress of user payment should go to
skimbooltrue if amount should be skimmed from the deposit balance of msg.sender
partuint256amount to repay

Returns

NameTypeDescription
amountuint256total amount repayed

repay

function repay(
address to,
bool skim,
uint256 part
) public returns (uint256 amount)

Calls _repay, which repays a loan.

Parameters

NameTypeDescription
toaddressaddress of user payment should go to
skimbooltrue if amount should be skimmed from the deposit balance of msg.sender
partuint256amount to repay

Returns

NameTypeDescription
amountuint256total amount repayed

cook

function cook(
uint8[] calldata actions,
uint256[] calldata values,
bytes[] calldata datas
) external payable returns (uint256 value1, uint256 value2)

Executes a set of actions and allows composability (contract calls) to other contracts.

Parameters

NameTypeDescription
actionsuint8[]array with sequence of actions to execute
valuesuint256[]one-to-one mapped array to actions, ETH amounts to send along with the actions
datasbytes[]one-to-one mapped array to actions, contains abi encoded data of function arguments

Returns

NameTypeDescription
value1uint256may contain first positioned return value of last executed action (if applicable)
value2uint256may contain second positioned return value of last executed action which returns 2 values (if applicable)

liquidate

function liquidate(
address[] calldata users,
uint256[] calldata maxBorrowParts,
address to,
ISwapper swapper,
bool open
) public

Handles the liquidation of users' balances once the users' amount of collateral is too low.

Parameters

NameTypeDescription
usersaddress[]array of user addresses
maxBorrowPartsuint256[]one-to-one mapping to users, contains maximum (partial) borrow amounts (to liquidate) of the respective user
toaddressaddress of the receiver in open liquidations if swapper is zero
swapperISwappercontract address of the ISwapper implementation, swappers are restricted for closed liquidations
openbooltrue to perform an open liquidation, else false

withdrawFees

function withdrawFees() public

Withdraw the fees accumulated.

setSwapper

function setSwapper(ISwapper swapper, bool enable) public onlyOwner

Used to register and enable / disable swapper contracts used in closed liquidations. Can only be called by the owner of the contract.

Parameters

NameTypeDescription
swapperISwapperaddress of the swapper contract that conforms to ISwapper
enablebooltrue to enable the swapper, false to disable

setFeeTo

function setFeeTo(address newFeeTo) public onlyOwner

Sets the beneficiary of fees accrued in liquidations. Can only be called by the owner of the contract.

Parameters

NameTypeDescription
newFeeToaddressaddress of the beneficiary