Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs - 12-prices.md #276

Merged
merged 3 commits into from
Nov 21, 2022
Merged

Update docs - 12-prices.md #276

merged 3 commits into from
Nov 21, 2022

Conversation

okada-blue
Copy link
Contributor

What does this PR do?

Update Learn RoboSats documentation for "Prices"

Checklist before merging

  • [ X ] If it's a frontend feature, I have ran prettier cd frontend; npm run format. If it's a mobile app feature I ran cd mobile; npm run format.

I noticed the "<!-- Cover>" verbiage, How should I expand on this item: "...how trade_amount sats is converted into payout_amount and escrow_amount applying the fee factors"?

@redphix
Copy link
Contributor

redphix commented Oct 10, 2022

@okada-blue

I noticed the "<!-- Cover>" verbiage, How should I expand on this item: "...how trade_amount sats is converted into payout_amount and escrow_amount applying the fee factors"?

I have roughly tried to jot down what goes according to what I understood (@Reckless-Satoshi please correct me if I got something wrong). You can include this in the docs by making them a little more readable/presentable.

  1. Before the taker bond is locked, if the order is relatively priced, due to CEX price changes, the last_satoshis (or satoshis_now; I'll call it trade_sats - the sats to be traded from here on) keep changing. In case of explicit pricing, sats to be traded are fixed, and the premium in turn keeps changing with respect to CEX price changes.
  2. When the taker bond is locked, in case of relative pricing, the satoshis to be traded are locked (i.e they no more change with change in CEX price). On the other hand, in case of explicit pricing, the satoshis to be traded were always fixed, so in a sense the sats to be traded were locked from the very beginning.
  3. satoshis to be traded is calculated as follows (only for relative pricing):
    premium_rate = CEX_rate * (1 + (premium/100))
    trade_sats = amount / premium_rate
    
    • trade_sats = last_satoshis = satoshis_now = satoshis to be traded.
    • premium is what the order maker set when they created the order.
  4. Fees are to be calculated on trade_sats
    • For maker
      fee_fraction = 0.002 * 0.125
                   = 0.00025 (i.e 0.025 %)
      fee_sats = trade_sats * fee_fraction
      
    • For taker
      fee_fraction = 0.002 * (1 - 0.125)
                   = 0.002 * (0.875)
                   = 0.00175 (i.e 0.175 %)
      fee_sats = trade_sats * fee_fraction
      
    The taker pays more fee split (0.175% of trade_sats) compared to maker (0.025% of trade_sats). This is mainly to encourage more makers and increase available liquidity on the exchange.
  5. Finally Robosats collects fees during escrow_amount and payout_amount calculation
    • For seller
      escrow_amount = trade_sats + fee_sats
      
    • For buyer
      payout_amount = trade_sats - fee_sats
      
    In essence RoboSats adds to escrow_amount and deducts from the payout_amount. Now, depending on whether you are the taker or the maker the appropriate fees are calculated and added/reduced from your escrow_amount/invoice_amount.

@Reckless-Satoshi
Copy link
Collaborator

Reckless-Satoshi commented Oct 10, 2022

Hey Okada, this PR reads just perfect. It looks good to be merged. 🚀

Indeed, I had in mind to add a small explanation on how the fees are deducted. Possibly best to leave it for /docs/fees and include the full explanation of @redphix that is 100% accurate.

We should aim to use global variables for all of the hardcoded values as often as possible. These variables are set in _config.yml
https://github.com/Reckless-Satoshi/robosats/blob/936d19c6fcaf937f49f86036401fe91aeea2f396/docs/_config.yml#L32-L45

New variables can be created any time. These can be used in any markdown file by simply typing {{site.robosats.VARIABLE_NAME}}. That way, if we change any parameter in the future, we do not need to manually look for all occurrences and edit all of the documentation pages. Sorry that I had forgotten to mention this before, it would be nice to implement these variables on /docs/swaps /docs/on-chain-payouts/, /docs/bonds, etc . Most often, any number that was decided arbitrarily, should be turned into one of these global variables for re-usability.

You can see an example of how many of these variables are used in the "how to guide" https://github.com/Reckless-Satoshi/robosats/blob/main/docs/_pages/tutorials/read/how-to-use.md

Please submit an invoice for 20K from a proxy wallet as usual 😄

@okada-blue
Copy link
Contributor Author

okada-blue commented Nov 19, 2022

Please submit an invoice for 20K from a proxy wallet as usual 😄

Heh, better later than never, I suppose! lnbc200u1p3h4dvcpp5ws3fgglj03c7cs5pd6l3erynrwmzgl0krlajejvng325zfjtlmgqdqu2askcmr9wssx7e3q2dshgmmndp5scqzpgxqyz5vqsp5e6hmx28n5paxnxnq2l9k55g97hdgwupna54fqgmfqg45nq2qzceq9qyyssqx8wsxwfc2efq7px7dhvr789jnhd6ag9vm9nmmydwt5v8k8g7mepjtxgcqj7ys0h76lhzfee03demc58l745t8k9stkkqqj3a83hsnlsqh6gg8x

I've updated the PR with the requested changes. Please review and double check my verbiage!

Great job @redphix for the breakdown, I'll look to do that more often and encourage more comments! Makes the explanation 10x clearer.

And I'll work to update the other docs with the _config.yml information

@Reckless-Satoshi
Copy link
Collaborator

lnbc200u1p3h4dvcpp5ws3fgglj03c7cs5pd6l3erynrwmzgl0krlajejvng325zfjtlmgqdqu2askcmr9wssx7e3q2dshgmmndp5scqzpgxqyz5vqsp5e6hmx28n5paxnxnq2l9k55g97hdgwupna54fqgmfqg45nq2qzceq9qyyssqx8wsxwfc2efq7px7dhvr789jnhd6ag9vm9nmmydwt5v8k8g7mepjtxgcqj7ys0h76lhzfee03demc58l745t8k9stkkqqj3a83hsnlsqh6gg8x

eec0685d7097ff1727bb821210844e9993db928afe0e4c58fe016c8355bde450

Great work! Merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants