WARNING: The following procedure is advised for emergency use ONLY!
*Any mistakes in the following steps could result in irreversible loss of your funds!
If any government, an accident or a seizure takes down the site of Sovryn, we can still interact with the Sovryn contract set, so please, don't panic: all Sovryn contracts are in the RSK blockchian and all the storage is safe inside them. Here is how we can proceed, step by step in such an emergency case.
In this article we are going to address the case in which we want to save our margin positions by adding collateral or in which we decide to close them.
Please, be aware that if you decide to close any LONG position when the price of the asset is BELOW the one the time you oppened it, you will lose some money; if you decide to close your SHORT position when the price of the asset is ABOVE, you will lose money as well. However if you decide to top-up your position you can improve your liquidation price, and avoid liquidations. But if you don't have enough funds to top-up your position, it may be better to lose some money than the big loss that can happen if you're liquidated.
Go to MyCrypto Wallet download site, and download the installer of this wallet. Then istall this software on your desk device. Using a desk computer is the safest way to do these steps. Please be sure that these is no snoopers around you.
The installer is a file that weighs around 100 Mb. So please, be patient.
Once you install the software, open it and switch the wallet to sintonize the RSK chain.
If you’re not connected to the RSK network, please, hit “Change Network” and select RSK. Then go back:
Go to “contracts” and put in “Contract Address” the sovrynProtocol contract address: 0x5a0d867e0d70fcc6ade25c3f1b89d618b5b4eaa7:
Now we have to provide the logic we desire to interact with. In order to do that we need the ABI of the LoanMaintenance contract.
We can verify the address of this contract here. Then we can see that contract in the RSK explorer. We can easily find the ABI in the “code” tab. Then we hit “copy”:
However, in case the RSK explorer is also down, dont panic, the ABI of this logic is here. Just copy and paste it in the "ABI / JSON interface" field of MyCrypto wallet, and then click on “ACCESS”:
The "ABI" content is a special data format and it lets the wallet communicate with the given logic of the sovrynProtocol contract. Please, Check that there are no missing characters at copy/pasting the data, or else the wallet won't let you access the contract.
Go to the section “Read/Write Contract” and scroll down until see depositCollateral and choose that function.
Then it will appear the parameters to supply to the contract which are the loanId, that is a bytes data, and depositAmount which must be supplied in rootstock-WEIS. The loanId is a unique identifier for the funds you took borrow in order to open your margin position:
But how to know what is your “loanId”?: You can check it using a block explorer.
In the extreme case that all block explorers for RSK were down in the same moment Sovryn dApp is also down, we still have the web3 package, so you can ask in our Sovryn discord or telegram for any of our developers to help you in cases like these. More details about this in the last section of this article.
To find the loanId parameter you’ll need to open the transaction you created by opening your margin position, in the explorer. To find that transaction you'll need to look into your wallet history.
Again, in the extreme case that Sovryn website is down AND also you can't find your margin opening transaction, you at least will need to know what is your RSK address and go to the last section of this article. In our example we suppose you are using a Metamask wallet:
Then the transaction will be shown in the explorer. There are several ways in which the internal strucutre of the transaction will be seen. There can be cases in which the transaction will have 16 internal steps, others in which the transaction will have 24 steps. In this case we have a transaction with 19 internal steps. Hit the tab that say “Logs”:
Then you will see a sequence of internal steps. Choose THE LAST ONE (which is sequentially the first one executed):
Then the details of that internal step will be shown. Look into the “TOPICS” data and select the fourth parameter. That's your loanId!
In our example, the loanId is: 0x5df10c38780cd0d7fc3e94228e1e859f128c95daff22e738de00363e5379d665
Let's suppose that we are trying to supply a top-up of 0.025 rBTC. This amount expressed in WEIS is: 25000000000000000.
So the parameters supplied to “MyCrypto” wallet will be:
Next, the wallet will ask you “How would you access your wallet”. The easiest way is with your private key. Of course, you must do this in a private environment.
This option appears because when you "top-up" your position, you are writing data in the contract and you will change the state of the RSK world, so you need to provide the signature, and to calculate it the wallet will need your private-key.
This will be different according to the wallet you used, but if it was MetaMask, you will need to hit the ellipsis (the three dots), and then "Account details":
Then you hit the tab indicating “Export Private Key”, then the wallet will ask your password, type it in the required field and hit “Confirm”. Your private key will be shown. Hit “Copy” and go back to MwCrypto wallet to paste that private key:
Paste your private key in the field of “Unlock your Private Key”, and hit “Unlock”. Now your wallet is ready to receive the specifications of your transaction.
You now need to supply the values for the parameters: “Value”, “Gas price” and “Gas Limit” of your transaction:
In the first place, the “Value” field must be filled if the asset you supply to the position is rBTC. In our case if we are supplying 0.025 rBTC (25000000000000000 WEIs) you will need to put 0.025 as value in the “Value” field. However if the asset you supply to the position is other than rBTC, like e.g.: “BPro”, you must leave that field of “Value” with ZERO: 0 rBTC.
Next, you will ned to uncheck the the field “Automatically Calculate Gas Limit”. MyCrypto wallet is better tuned to calculate these parameters for the Ethereum network, but for RSK you must indicate these parameters with the right values or you will end up loosing money!
In “Gas Price” you must define: “0.06”; And for this specific transaction in the “Gas Limit” field you must indicate “250000”. The “Nonce” parameter is automatically calculated in the right way.
Then you can hit “WRITE”.
If everything goes well, if you have the enough funds in your wallet to pay the value and the gas fees, the “Sign Transaction” tab will change color, ready to be hit:
Then the signed transaction with all its details will be shown. All you will need to do will be hit “Send Transaction”.
You have broadcast succesfully your TOP-UP transaction to save your margin position without the need of the Sovryn UI.
WARNING: This procedure is ONLY advised in case of emergency. If you make any mistakes in these steps, you could irreversibly lose your money!
Go to MyCrypto Wallet download site, and download the installer of this wallet. Then istall this software on your desk device. Using a desk computer is the safest way to do these steps. Please be sure that these is no snoopers around you.
The installer is a file that weighs around 100 Mb. So please, be patient.
Once you install the software, open it and switch the wallet to sintonize the RSK chain.
If you’re not connected to the RSK network, please, hit “Change Network” and select RSK. Then go back:
Go to “contracts” and put in “Contract Address” the sovrynProtocol contract address: 0x5a0d867e0d70fcc6ade25c3f1b89d618b5b4eaa7:
In this case the logic of the sovrynProtocol contract to be accessed is diferent and corresponds to the LoanClosingsWith contract.
We can see in this link the ABI of the contract. Just copy the ABI and paste it in the "ABI / JSON interface" field of MyCrypto wallet, and then click on “ACCESS”:
Also, we can verify the address of the LoanClosingsWith contract here. We can see in this link a flatenized version of the contract.
The "ABI" content is a special data format and it lets the wallet communicate with the given logic of the sovrynProtocol contract. Please, Check that there are no missing characters at copy/pasting the data, or else the wallet won't let you access the contract.
Go to the section “Read/Write Contract” and scroll down until see closeWithSwap and choose that function.
Then it will appear the parameters to supply to the contract which are:
i.- The loanId; the unique identifier of the loan you took at the moment of the opening of the margin position. This is a “bytes” data.
ii.- Te address of the receiver of the funds.
iii.- The swapAmount which is a numerical parameter. This is the amount of assets of your positions to be converted into the assets of your debt, then the protocol pays the debt and the difference will be yours. Don't worry if in that moment you don't remember or don't know this figure. You can round up the figure. If the amount expressed is grated than the collateral that you really have, then the protocol will assing the value of the total collateral to that parameter in order to close your whole position.
iv.- The logical value returnTokenIsCollateral; you must put just “true” or “false”. This parameter indicates if you want to receive your reimbursement in terms of the asset you took borrowed or in terms of the asset yuo had as collateral in your margin position.
v.- The data parameter Input. This actually is a non used parameter, and you will have to put there the exact experssion “0x”.
But how to know what is your “loanId”?: You can check it using a block explorer.
In the extreme case that all block explorers for RSK were down in the same moment Sovryn dApp is also down, we still have the web3 package, so you can ask in our Sovryn discord or telegram for any of our developers to help you in cases like these. More details about this in the last section of this article.
To find the loanId parameter you’ll need to open the transaction you created by opening your margin position, in the explorer. To find that transaction you'll need to look into your wallet history.
Again, in the extreme case that Sovryn website is down AND also you can't find your margin opening transaction, you at least will need to know what is your RSK address and go to the last section of this article. In our example we suppose you are using a Metamask wallet:
Then the transaction will be shown in the explorer. There are several ways in which the internal strucutre of the transaction will be seen. There can be cases in which the transaction will have 16 internal steps, others in which the transaction will have 24 steps. In this case we have a transaction with 19 internal steps. Hit the tab that say “Logs”:
Then you will see a sequence of internal steps. Choose THE LAST ONE (which is sequentially the first one executed):
Then the details of that internal step will be shown. Look into the “TOPICS” data and select the fourth parameter. That's your loanId!
In our example, the loanId is: 0x5df10c38780cd0d7fc3e94228e1e859f128c95daff22e738de00363e5379d665
Let's suppose that the address in which you wish to receive your reimbursement (at closing the position) were: 0xca4e16b9541860b1d639634aef38aa380b05e0c3.
It is always convenient to have your address data with all letters lowercased. You can use a online tool like this.
Let's suppose that we are trying to close a position which has in total a collateral of around 0.02 rBTC. E.g.: The position in total, what you supplied as collateral plus the funds you took borrowed are in total around of 0.02 rBTC. But you are not sure. So, to be sure you will close the whole position, if you choose to put in this field 0.025 rBTC there will be no problem. This amount expressed in WEIS is: 25000000000000000.
Next, the parameter returnTokenIsCollateral is boolean. The wallet will let you choose between “false” and “true”. If you choose “true” you will receive your reimbursement in terms of the collateral asset. If you choose “false” you will receive your reimbursement in terms of the borrowed asset. For the purposes of this example we choose “true”.
Finally the Input parameter doesn't need any value; but you must put there the exact expression “0x”:
Next, the wallet will ask you “How would you access your wallet”. The easiest way is with your private key. Of course, you must do this in a private environment.
This option appears because when you "close" your margin position, you are writing data in the contract and you will change the state of the RSK world, so you need to provide the signature, and to calculate it the wallet will need your private-key.
This will be different according to the wallet you used, but if it was MetaMask, you will need to hit the ellipsis (the three dots), and then "Account details":
Then you hit the tab indicating “Export Private Key”, then the wallet will ask your password, type it in the required field and hit “Confirm”. Your private key will be shown. Hit “Copy” and go back to MwCrypto wallet to paste that private key:
Paste your private key in the field of “Unlock your Private Key”, and hit “Unlock”. Now your wallet is ready to receive the specifications of your transaction.
You now need to supply the values for the parameters: “Value”, “Gas price” and “Gas Limit” of your transaction:
In the first place, the “Value” field must be left with 0 rBTC.
Next, you will ned to uncheck the the field “Automatically Calculate Gas Limit”. MyCrypto wallet is better tuned to calculate these parameters for the Ethereum network, but for RSK you must indicate these parameters with the right values or you will end up loosing money!
In “Gas Price” you must define: “0.06”; And for this specific transaction in the “Gas Limit” field you must indicate “750000”. The “Nonce” parameter is automatically calculated in the right way.
Then you can hit “WRITE”.
If everything goes well, if you have the enough funds in your wallet to pay the gas fees, the “Sign Transaction” tab will change color, ready to be hit:
Then the signed transaction with all its details will be shown. All you will need to do will be hit “Send Transaction”.
You have broadcast succesfully your CLOSING transaction to retrieve what is left in your margin position without the need of the Sovryn UI.
You will need a proper installation of NODEJS and web3 in your desktop.
In this link you will find the script you need to run to find all your loanId's and the details of such loanId's.