Technical documentation
Entrypoints
8min
entrypoint description all the entrypoints can be broken down into four categories user entrypoints with their help, funds are invested into deposits and farms admin entrypoints used for managing contracts and can only be called by the admin supplementary entrypoints utilized during internal operations usually, these entrypoints can only be called by the contract itself f12 exterior entrypoints, description f12 https //gitlab com/tezos/tzip/ /blob/master/proposals/tzip 7/tzip 7 md user entries depositlending – used for filling the deposit up with funds, where sp amount (is the amount of xtz that is supposed to be deposited) or shares (the amount of tzbtc tokens that are supposed to be deposited in this case, to invest, you must first call approve for the required number of tokens ) mindepositshares the minimum expected amount of tokens to be received deadline the time limit for sending transactions, equal to now + one second redeemlending – used to withdraw funds from a deposit errors display as codes https //gitlab com/l3544/levered farming contracts/ /blob/main/src/errors py shares (only in btc contract) the amount of tzbtc tokens that are supposed to be withdrawn from the deposit amount (xtz contract only) the amount of xtz to be withdrawn from the deposit deadline the timestamp until which the transaction remains valid, equal to now + one second investlb – invests in lb farm, while almost always summoning additional funds from deposits, 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 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 amount2tzbtc the amount of xtz to be exchanged for tzbtc mintzbtctokensbought the minimum number of learned tzbtc tokens it is needed to control slippage tzbtc2xtz (only in btc contract) the number of tzbtc tokens to be exchanged for xtz minxtzbought (only in btc contract) the minimum amount of xtz learned it was needed to control slippage amount2lqt the amount of xtz invested in the lb farm minlqtminted is the minimum number of learned lb tokens it is needed to control slippage tzbtcshares (xtz contract only) investor's tzbtc tokens not taken into account when calculating collateral sp amount the investor's xtz it should take into account the upfront commission maxtzbtcshares the maximum tzbtc shares added to liquidity deadline the timestamp until which the transaction remains valid, equal to now + one second investbalancedlb (xtz contract only) creates a farm in about 200% of the collateral, where tzbtc is taken from the client, and xtz is borrowed from the contract thus, the client doesn't need a double exchange of tzbtc, unlike investlb using the method, you can create a farm with a large coverage (cratio<200%) by transferring additional funds in the entry point, but the commission will be taken for a farm of 200% amount2lqt the xtz amount converted to lb tokens minlqtminted the minimum lb tokens to mint maxtzbtcshares the maximum number of tzbtc shares provided by the client deadline the timestamp until which the transaction remains valid, equal to now + one second redeemlb – closes lb farm, and returns all the proceeds (minus the borrowed amount) to the farmer a farm can be unwound wholly and partly the debt is written off in proportion to the burnt sirs tokens mintokenswithdrawn the minimum amount of tzbtc to be received when selling a farm needed to control slippage xtz to token amount (btc contract only) the amount of xtz to be sold the amount of tzbtc received from the operation and tzbtc received from the sale of lb tokens should cover the debt lqtburned lb shares to burn minxtzwithdrawn (only in the xtz contract) the minimum xtz to get after burning lb tokens mintokensbought (btc contract only) the minimum tzbtc to buy in the second trade sell remaining tzbtc the flag that determines whether or not to sell remaining tzbtc shares minxtzbought (only in the xtz contract) the minimum xtz to buy in the second trade send tzbtc (only in the xtz contract) the tzbtc shares to send directly to the client deadline the timestamp until which the transaction remains valid, equal to now + one second updateindexes – initiates the computation process for all three indices necessary to ensure the regularity of this process by allowing any interested party to start 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 the value of the farm is, in this case, determined by the oracle a partial buyout is also possible address the address of the contract to be liquidated payment shares (only in the btc contract) the number of tzbtc tokens for which the farm's lb tokens are supposed to be redeemed in this case, to invest, you must first call approve for the required number of tokens sp amount (only in the xtz contract) the amount of xtz for which the farm's lb tokens are supposed to be redeemed deadline the timestamp until which the transaction remains valid, equal to now + one second min expected sirs minimal amount of sirs the user expects to receive returndebt allows a direct return of loan for a given farm address the address of the farm, to which the debt user wants to return shares (btc contract only) the amount of tzbtc shares that need to be returned (in the xtz contract, this value is set via sp amount ) minreturnedgrosscredit min amount of debt to be redeemed deadline the time limit for sending transactions, equal to now + one second flashloan entrypoints related to flash loan functionality flash loans allow you to borrow any available amount of xtz or tzbtc without collateral as long as the liquidity is returned to the protocol within one block transaction flashloan lends funds (tezos in the xtz contract and tzbtc in the btc contract) callback and amount (xtz) or shares (btc) calls this callback and transfers the amount or shares of funds to the account flashloanfinalize if the client did not return the funds taken in flashloan, along with interest, it falls callback ( mutez for xtz contract, nat for btc) the amount of funds to be returned flashloanreturn (only in the xtz contract) returns a debt admin entries in the event of being called by a user without admin rights will display the error message "forbidden" setadmincandidate adding a candidate to become an admin, and it can only be interacted by an admin admin candidate address of a candidate approveadmincandidate approving candidate it can only be interacted with by a candidate (from the admin candidate address) after the interaction, the candidate becomes the admin the admin address in the administrator storage becomes admin candidate ; admin candidate remains the same liquidateonchainlb a mechanism of forced close a close to debt farm farm value is determined through the complete sale of its lb tokens a part of the collateral premium over the borrowed amount goes to admin, while the remaining difference gets assigned to lender's accounts proportionally to their deposit sizes deadline the time limit for sending transactions; is equal to now + one second address the address to liquidate minxtzwithdrawn the minimum xtz to get after burning lb tokens mintokenswithdrawn the minimum tzbtc to get after burning lb tokens mintokensbought (btc contract only) the minimum tzbtc to buy in secondary trade minxtzbought (xtz contract only) the minimum xtz to buy in secondary trade disableonchainliquidation disables the liquidateonchainlb liquidation mechanism it can be turned off only once setdexcontract sets the dex contract (lb contract by default) for exchanging xtz for tzbtc and vice versa setflashloanparams sets flashloan parameters flashloan admin commission admin commission flashloan deposit commission commission for depositors flashloan available sets if flashloan is enabled or not setdelegate (xtz contract only) delegates the xtz remains from the contract to the liquidity baker baker rewards are shared among lenders proportionally to their deposit sizes setisworkingstatus – used for powering on and off the contract when the contract is powered off, all of the interest from farms goes to admin, and none gets assigned to the lenders; entrypoints depositlending and investlb cannot interact; funds withdrawal is available only investbalancedlb (in xtz contract) is also disabled admin can always power up a “shutdown” contract again setlbpricechangerate changes the value of lb price change rate , which is used in oracle's clamp function setleverageparams – sets parameters for investing in farms and liquidation — for example, the maximum allowed leverage or liquidation commission for both types of liquidations setoracletocfmmmaxdiff sets the value of oracle to cfmm max diff in storage in units of 10^ 5 the value is used to check the exchanging cfmm price with the oracle price for xtz and tzbtc during investing in a farm prices must not differ by more than (1 + oracle to cfmm max diff ) times setpause pauses the contract setrateparams sets parameters for calculating the base interest rate using the utilization rate setupfrontcommission sets the upfront fee size it should be less than 2% withdrawcommission sends the admin all of the accumulated commission since the last time this entry interacted addorremoveupfrontfree add or remove an address from a unique set of clients who don't pay upfront fees when investing in a farm address the address of some client if it is in this set, then it is removed from it, and if not, then it is added supplementary entries these entries can only be initiated during scenarios described in the contracts default – entry required to obtain xtz from dex contract in the xtz contract, it is also responsible for obtaining token rewards for liquidity baking the baking reward is divided evenly among all depositors investlbfinalize – ends an investlb and investbalancedlb (in xtz contract) call redeemlbfinalize – ends a redeemlb call liquidatelbfinalize – ends a liquidatelb call liquidateonchainlbfinalize – terminates liquidateonchainlb call sendbalance (btc contract only) – sends all xtz on the contract’s balance to a chosen address sellxtz (btc contract only) – exchanges all xtz on the contract’s balance for tzbtc calculatelbprice calculates the current price of a sirs token (sirs lb) based on the clamp function these three callback entries are for refreshing the storage values and one – for selling funds 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 (btc contract only) – updates local params tzbtc pool and tzbtc shares value in storage updatelqttotalcallback – updates local params lqt total value in storage fa12 the description can be found on a web page standard fa12 entrypoints approve getallowance getbalance gettotalsupply transfer non standard fa12 entrypoints getadministrator returns admin's address update metadata updates metadata