Redeeming RIFPros
Last updated
Last updated
The RIF On Chain's Smart Contract suite is in control of the redeeming of its tokens, including the RIFPro token. This means that the return of RIFPros is controlled programmatically by said suite. A user can "sell" their RIFPro back to the contract and recover the corresponding amount of RIF.
This means that to redeem RIFPros you must interact with the suite. The entry point are the same as explained in .
In this tutorial the method (or function) that is of interest to us is function redeemRiskProVendors(uint256 riskProAmount, address vendorAccount) public
NOTE: there is a retrocompatibility function called function redeemRiskPro(uint256 riskProAmount)
which is suitable for those who are already integrated to RoC platform and are not ready to use vendor functionality. In the future we are planning to deprecate this method.
It is the amount that the contract will use to redeem RIFPros and to calculate commissions. All of these funds will be transformed exclusively into RIF.
This parameter uses a precision of the type reservePrecision that contains 18 decimal places and is defined in MoCLibConnection contract.
RIF On Chain is a dynamic system that allows you to redeem a maximum amount of RIFPros and can be obtained by calling the absoluteMaxRiskPro()
view of the MocState contract.
The redeeming process is divided into 4 parts:
The first part transforms the amount riskProAmount into an RIF amount, but 3 things can happen:
The amount entered in riskProAmount must not exceed the user's balance in RIFPros. If this occurs then the user’s balance will be used to calculate the value in RIF.
The userAmount must not exceed the absolute maximum amount of RIFPros. If this occurs then absoluteMaxRiskPro will be used to transform it to RIF.
The third part returns the amount in RIF discounting the previously calculated commissions.
These two values are a parameter of the transaction, this is not used in the contract and is generally managed by your wallet (you should read about them if you are developing and do not know exactly what they are), but you should take them into account when trying to redeem some RIFPros.
This operation may fail if one of the following scenarios occurs:
If the gas limit sent is not enough to run all the code needed to execute the transaction, the transaction will revert (again, returning all your funds except the fee paid to the network). This may return an "out of gas" error or simply a "revert" error because of the usage of the proxy pattern.
In the following sections we will give some code on how this can be done through a Smart Contract or directly, with a console or with an app.
To run a local blockchain you can use
To deploy the contracts you can use
Having done that lets you use our contract as a dependency to your contract. For this let's suppose you are doing some kind of contract that when executing a certain task charges a fixed commission. Now let's suppose that the commission is sent in RIFs because it is easier for the user but actually you want some RIFPros. The good news is that you can do this instantly just by minting them. The code necessary to do this is actually pretty simple. You just have to import the contract
Receive the address in the constructor in order to be able to interact with it later, and the vendorAccount address needed to do the operation
And redeem some RIFPros:
You can send it immediately to you so you can start using it right away. In order to do this you should add a few more lines similar to the ones before, only that you will have to use the RIFPro token. This will leave you with a contract similar to the following
The second part will be used to pay the commission, this part is a percentage of the previous part. The commission fees are explained in section.
The third part corresponds to the vendor markup, which refers to the fee a vendor will receive from this transaction and is a percentage of the first part. The vendor markup is explained in section.
All the needed calculations for the second and third parts are explained in more detail .
In the extraneous case where a coverage that barely covers the stable tokens funds is reached, the contract will liquidate all of its assets. If this state occurs, no more RIFPros will be available for redeeming. The condition is the same as that explained in.
If the system suffers some type of attack, the contract can be paused so that operations cannot be done and the risk of the users losing their funds with the operation can be minimized. The condition is the same as that explained in .
To create a new Smart Contract that uses the RIF On Chain platform, you can use any language and IDE you want. In this tutorial, we will show you how to do it using , and . Truffle framework offers some template projects that you can use to develop applications that use smart contracts. You can get more information . Assuming you already have your project up and running (if you don't, please follow ) the only extra thing you need to do is to install our repo as a dependency in your NPM project. In order you need to do this you just need to run the following command.
And that is it, the only thing left to do is to add in the scripts the address to MoC and RiskPro when deploying YourRedeemingRiskProContract and you are done.