Entrypoints
All the entrypoints can be broken down into three categories:
- User entrypoints. With their help funds are invested into deposits and farms.
- Admin entrypoints. They are used for managing contracts and can only be called by the Admin.
- Supplementary entrypoints. Utilized during internal operations. In most cases, these entrypoints can only be called by the contract itself.
depositLending โ used for filling the deposit up with funds. For xtz-contract this sum is determined by the number of xtz transferred upon the callback. For BTC-contracts there is a special parameter for determining this number - shares. Thus, you need to first summon approve for the same number of tokens.
redeemLending โ employed for withdrawing funds from a deposit. The amount of withdrawn funds is determined by the parameters amount ( for xtz-contracts) or shares (for BTC-contracts). In case there is an attempt to withdraw more funds than there are available on an account an error message 'too much amount' is displayed.
investLB โ invests in lb-Farm, while almost always summoning additional funds from deposits, and thus borrowing funds from lenders. While the currency of the contract may differ (xtz in xzt-contract and tzBTC in BTC-contract) the user always brings with himself only xtz. The leverage one can obtain this way is limited from above. This is the most computationally complex parameter and it was designed this way to save on gas.
redeemLB โ unwinds lb-Farm, and returns all the proceeds (minus the borrowed amount) to the Farmer. A farm can only be unwound completely. To control for slippage one may specify the minTokensWithdrawn parameter. For ะTC-contract you additionally need to specify xtz_to_token_amount , to ensure that the debt gets repaid in full.
updateIndexes โ initiates the computation process for all three indices. Necessary for ensuring the regularity of this process by allowing any interested party to initiate this process with minimal transaction costs. liquidateLB โ starts a forced buyout of a Farm, for which the collateral value gets dangerously close to the borrowed amount. Value of the Farm is in this case deteremined by the oracle. Partial buyout is also possible.
In the event of being called by a user without admin rights will display error message โForbidden.'
liquidateOnchainLB โ a mechanism for forced Farm closure in cases when the collateral value starts approaching the borrowed amount at a dangerously close level. Farm value is determined through the complete sale of its lb-tokens. A part of collateral premium over the borrowed amount goes to Admin while the remaining difference gets assigned to Lender accounts proportionally to their deposit sizes.
disableOnchainLiquidation โ disables liquidation mechanism (liquidateOnchainLB). Once terminated, it cannot be reactivated.
setIsWorkingStatus โ used for powering on and off the contract. The powered-off contract differs from the โpluged-inโ one: all of the interest from Farms goes to Admin and none gets assigned to the Lenders. Admin can always power up a โshutdownโ contract again.
setUpfrontCommission โ sets the upfront-fee size. It should be less than 2%.
setDelegate (xtz-contract only) โ delegates the xtz remains from the contract to the liquiditiy baker. Baker rewards are shared among Lenders proportionally to their deposit sizes.
withdrawCommission โ sends all of the accumulated commission since the last time this entry was called to the Admin.
setRateParams โ sets parameters for calculation of base interest rate using utilization rate.
setLeverageParams โ sets parameters for investing in Farms and liquidating them. Such as, for example, maximum allowed leverage or liquidation commission for both types of liquidations.
These entries can only be initiated during scenarios described in the contracts.
default โ entry required to obtain xtz from dex-contract. In xtz-contract it is also responsible for obtaining token rewards for liquidity baking.
investLBFinalize โ ends an investLB call.
redeemLBFinalize โ ends a redeemLBcall.
liquidateLBFinalize โ ends a liquidateLB call.
liquidateOnchainLBFinalize โ terminates liquidateOnchainLB call.
sendBalance (BTC-contract only) โ sends all xtz on contractโs balance to a chosen address.
sellXtz (BTC-contract only) โ exchanges all xtz on the contractโs balance for tzBTC.
These 4 callback entries are for refreshing the storage values and one โ for selling funds:
updateTzBTCCallback (BTC-contract only) โ refreshes tzBTC_shares value in storage.
sellTzBTC (xtz-contract only) โ exchanges all tzBTC tokens for xtz. This entry is also a callback one.
updateLBCallback โ updates lb_shares value in storage.
updateTzbtcPoolCallback โ updates local_params.tzbtc_pool value in storage.
updateLqtTotalCallback โ updates local_params.lqt_total value in storage.