Skip to main content

KashiPair

KashiPair is a masterContract for BentoBox that provides functionality for supplying an asset, borrowing that asset by supplying capital, and links to an oracle for the exchange rate.

Functions

init

function init(bytes calldata data) public payable override

This function serves as the constructor for clone contracts, as the clones can't have a regular constructor.

Parameters

NameTypeDescription
databytesabi-encoded collateral, asset, oracle, oracleData

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.

Parameters

NameTypeDescription
useraddressuser address
openboolliquidation case open or closed
_exchangeRateuint256exchange rate

updateExchangeRate

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

Gets the exchange rate and returns it.

Returns

NameTypeDescription
updatedboolupdated yes or no
rateuint256exchange rate

_addTokens

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

Internal helper function to move tokens.

Parameters

NameTypeDescription
tokenIERC20token to add
shareuint256amount in shares to add
totaluint256total amount to deduct from this contract's balance
skimboolif true, only does a balance check on this contract

addCollateral

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

Adds collateral from msg.sender to the account to.

Parameters

NameTypeDescription
toaddressrecipient address
skimbooltrue if the amount should be skimmed from the deposit balance of msg.sender
shareuint256amount of shares to add for to

_removeCollateral

function _removeCollateral(address to, uint256 share) internal

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

Parameters

NameTypeDescription
toaddressrecipient address
shareuint256amount of shares to remove

removeCollateral

function removeCollateral(address to, uint256 share) public solvent

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

Parameters

NameTypeDescription
toaddressrecipient address
shareuint256amount of shares to remove

_addAsset

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

Internal function called by addAsset, it adds assets to the lending pair and returns the total fractions added.

Parameters

NameTypeDescription
toaddressrecipient address
skimbooltrue if the 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 assets to the lending pair and returns the total fractions added.

Parameters

NameTypeDescription
toaddressrecipient address
skimbooltrue if the 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
toaddressrecipient address
fractionuint256amount/fraction of assets held to remove

Returns

NameTypeDescription
shareuint256amount of shares that were transferred

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
toaddressrecipient address
fractionuint256amount/fraction of assets held to remove

Returns

NameTypeDescription
shareuint256amount of shares that were transferred

_borrow

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

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

Parameters

NameTypeDescription
toaddressrecipient address
amountuint256amount 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 sender to borrow amount and transfers it to the account to.

Parameters

NameTypeDescription
toaddressrecipient address
amountuint256amount 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 and returns the total amount paid.

Parameters

NameTypeDescription
toaddressrecipient address
skimbooltrue if the amount should be skimmed from the deposit balance of msg.sender
partuint256amount to repay

Returns

NameTypeDescription
amountuint256total amount repaid

repay

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

Calls _repay, which repays a loan and returns the total amount paid.

Parameters

NameTypeDescription
toaddressrecipient address
skimbooltrue if the amount should be skimmed from the deposit balance of msg.sender
partuint256amount to repay

Returns

NameTypeDescription
amountuint256total amount repaid

_bentoDeposit

function _bentoDeposit(
bytes memory data,
uint256 value,
uint256 value1,
uint256 value2
) internal returns (uint256, uint256)

Internal helper function for depositing into bentoBox.

Parameters

NameTypeDescription
databytesabi-encoded data
valueuint256value
value1uint256value1
value2uint256value2

_bentoWithdraw

function _bentoWithdraw(
bytes memory data,
uint256 value1,
uint256 value2
) internal returns (uint256, uint256)

Internal helper function for withdrawing from bentoBox.

Parameters

NameTypeDescription
databytesabi-encoded data
valueuint256value
value1uint256value1
value2uint256value2

_call

function _call(
uint256 value,
bytes memory data,
uint256 value1,
uint256 value2
) internal returns (bytes memory, uint8)

Internal helper function for performing a contract call and eventually extracting revert messages on failure.

Parameters

NameTypeDescription
databytesabi-encoded data
valueuint256value
value1uint256value1
value2uint256value2

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 a sequence of actions to execute
valuesuint256[]mapped array to actions, ETH amounts to send along with actions
datasbytes[]mapped array to actions, abi-encoded data of function arguments

Returns

NameTypeDescription
value1uint256first positioned return value of the last executed action, if applicable
value2uint256second positioned return value of the 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[]mapped array to users, contains maximum borrow amounts to liquidate of the respective user
toaddressaddress of receiver in open liquidations
swapperISwapperswapper contract address
openbooltrue to perform an open liquidation, else false

withdrawFees

function withdrawFees() public

Withdraws the fees accumulated.

setSwapper

function setSwapper(ISwapper swapper, bool enable) public onlyOwner

Registers and enables / disables swapper contracts used in closed liquidations. Can only be called by the owner of the contract.

Parameters

NameTypeDescription
swapperISwapperswapper contract address
enablebooltrue to enable 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
newFeeToaddressnew beneficiary address