Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cryptoguard/b1624d5a6578d8e8b73e4efafed15669 to your computer and use it in GitHub Desktop.
Save cryptoguard/b1624d5a6578d8e8b73e4efafed15669 to your computer and use it in GitHub Desktop.

Automatic Staking Reward Exchange Mechanism

What it does The automatic staking reward exchange mechanism is used to instantly exchange portions of staking rewards into other cryptocurrencies. It uses Shapeshift to make the exchange and provide liquidity.

Once a stake is awarded to a user, it is paid to an address which will automatically split it according to the user's parameters. Each portion of the stake is then sent to special PART addresses that attempt to execute a Shapeshift cryptocurrency transfer each time funds are deposited into them.

Each of these special addresses are "attached" to a different Shapeshift coin (LTC, ETH, DGD, ETC). Their purpose is very simple, every time they receive an incoming transaction, the Particl client then automatically attempts to create a Shapeshift exchange to the coin the address was "attached to".

For example, if PART address X is used for instant ETH exchange, then every single time it receives an incoming transaction, it would initiate a Shapeshift PART to ETH exchange. The Particl client then automatically fills the information required by Shapeshift per the user's own preferences.

How does a user enable the feature?

In a dedicated section in the client's settings page, a user would first need to enable the feature (probably simply checking a box). Once done, the user would then need to set up his "staking reward portfolio" preferences. This is where the user will enter all the necessary information so an automatic exchange can be initiated in the future.

What are the parameters that need to be set up?

The dedicated settings page will show up all cryptocurrencies that can be used to automatically transfer staking rewards. These should be all the coins Shapeshift trades. All the coins are unchecked by default and if a user wants to add a coin that he wishes to transfer staking rewards to, he has to check the dedicated checkbox next to the desired coin. Following this action, three additional parameters will pop up: percentage of total staking reward, output address and minimum amount to initiate withdrawal. If, for example, a user wanted to have 10% of his total staking rewards be paid in Bitcoin, then he would check the Bitcoin option, input 10 in "percentage of staking reward" and paste the Bitcoin deposit address he would like to receive the coins in into "output address".

The other preference, "minimum amount to initiate withdrawal", is used to set a minimum amount the address needs to accumulate before an automatic withdrawal is initiated. By default, its value is set to 0, meaning every time funds are transfered to this address and fully confirmed, the Particl client tries to exchange to total balance of the address into the specified coin. If a user doesn't want to transfer any funds from a given coin address until it reaches a certain amount, he can input this minimum value into the dedicated area. For example, if a user enters the value "1.2", then the Particl client WILL NOT attempt to initiate an automatic coin exchange until the balance of the address reaches 1.2 PART.

By default, there is a display which shows PART: 100% at the top, indicating 100% of the staking rewards will be paid in PARTs. As the user adds more coins he would like to automatically transfer to, and as he sets his desired percentage for each coin, the display calculates the total input percentages and automatically adjusts the PART: X% display. The user cannot apply the settings if the total percentages don't add up for a total of 100%.

NOTE: Some coins may be trickier to integrate than others, such as Monero which requires a transaction ID for Shapeshift to recognize the transaction. That would require an additional option in the Particl client's settings page to let users input this additional information. One quick solution would be to not allow all tradeable coins on Shapeshift be used for automatic exchange. The Particl team could, at first, integrate all the basic coins which only require a deposit address and leave the more complicated ones on a case-by-case implementation basis.

Here is an example of the dedicated settings page and potential inputs:

  • Total of a single staking reward in this example: 0.3 PART

  • PART (50%) = 0.15 PART transfered into regular PART address

  • BTC (10%) = 0.03 PART ...into PART address dedicated to initiate BTC exchange

  • ETH (15%) = 0.045 PART

  • DGX (10%) = 0.03 PART ---> This is a gold-backed ERC20 token

  • USDT (10%) = 0.03 PART --> 1 Tether = 1 USD

  • LTC (5%) 0.7 = 0.015 PART ---> The LTC withdrawal PART address will not initiate an automatic withdrawal until the total address balance reaches 0.7 PART

How does the automatic staking reward exchange works?

When a staking reward is awarded to a staker, it is deposited in a special PART address(1). This address is only used to receive the reward, than automatically split it according to the automatic coin exchange parameters. If the feature is disabled, then that means this address(1) sends the full amount of the stakes it receives to a final regular PART address(2).

For example, if a user sets his preferences to 50% PART, 50% USDT, then once a stake is awarded to the special PART receiving address(1), it sends 50% of the total reward to a regular PART address(2) and 50% to a special address used to initiate automatic coin exchange attempts to Shapeshift for USDT(3).

Once the special PART address used for USDT exchange on Shapeshift(3) receives the 50% stake reward, it first waits for the funds to be fully confirmed, then verify if its total balance equals or exceeds the "minimum amount to initiate withdrawal" set by the user. If it doesn't, then nothing happens and the PARTs simply sit there. If it does, than the Particl client attempts to exchange the full PART balance(3) into USDT through Shapeshift.

If the minimum amount REQUIRED BY SHAPESHIFT is included in the transaction, then the Particl client will tell Shapeshift to exchange the PARTs into USDTs and to send them to the USDT deposit address the user specified in the dedicated settings page. If the transaction is too small for Shapeshift's minimum amount of coins, Shapeshift will send an error message to the client specifying the transaction doesn't include the minimum amount of coins Shapeshift requires. Upon reception of this message, the Particl client will stop any attempt to exchange the coin until more PARTs are deposited into the PART address used for USDT conversion(3). As always, every time PARTs are deposited into this address(3) and the total balance equals or exceeds the user's minimum amount threshold, a new automatic coin exchange is attempted.

There should be a dedicated page where users can see a full logs of automatic coin exchange attempts (showing both succesfull and unsuccesfull) for easier monitoring and accounting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment