Skip to content

Instantly share code, notes, and snippets.

@tranvictor
Last active November 26, 2018 12:59
Show Gist options
  • Save tranvictor/526f791408002a1ba1e65f3758337b2b to your computer and use it in GitHub Desktop.
Save tranvictor/526f791408002a1ba1e65f3758337b2b to your computer and use it in GitHub Desktop.
Proposed workflow for kotocrypto to use kyber protocol to enable erc20 support

First scenario: A user wants to buy ERC20 (the one that kyber supports) using fiat

  1. Tokocrypto keeps monitoring ETH-ERC20 rate on Kyber using either Kyber's trading APIs or reading it directly on Ethereum blockchain, Kyber provides the rates here.
  2. Tokocrypto displays the rate in the way you want (rate to fiat calculation and fee calculation can be done here)
  3. The user submits an order to buy ERC20 using fiat according to the rate Tokocrypto shows, lets say the rate is R (mean he needs to spend R amount of fiat A in order to buy 1 token B)
  4. Up to now, his order is pending
  5. Tokocrypto do balance lockup (for example deduct fiat balance, increase locked balance of token B...)
  6. Tokocrypto do a transaction to Kyber's smart contract in order to convert necessary amount of eth to token B (at this step, there are several things you can do like specifying which address you will receive the tokens, which rate you want to proceed and will you still want to proceed if the rate goes down but lets discuss on this after we are clear about the overal flow)
  7. Tokocrypt monitors the tx to see if it is successful or failed (this would take up a minute)
  8. If it is successful, unlock the balance of token B, change order status and notify users
  9. If it is not, wipe out the locked balance of token B, change order status refund fiat balancee and notify users.

Note 1: This is the overall full flow that i can imagine, those steps in bold are the steps that need integration between Tokocrypto and Kyber

Note 2: On step 5, about balance lockup, there are 2 transactions involved in the settlement, 1 is fiat to eth, 1 is eth to erc20, both of them need time to process and especially the transaction to convert eth to erc20 takes around 16s-1min to be mined.

Second scenario: A user wants to sell ERC20 (the one that kyber supports) to fiat

The basic flow is the same to the first scenario except that at step 1, 3, and 6, Tokocrypto should monitor ERC20-ETH rate and do a transaction with kyber in order to convert erc20 to eth.

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