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

Pay order-matching fee on the app #863

Merged
merged 7 commits into from
Jul 5, 2023
Merged

Pay order-matching fee on the app #863

merged 7 commits into from
Jul 5, 2023

Conversation

luckysori
Copy link
Contributor

@luckysori luckysori commented Jun 29, 2023

Fixes #8381.
Fixes https://github.com/get10101/meta/issues/170.
Fixes https://github.com/get10101/meta/issues/171.
Fixes #884.

We keep it simple for now: the coordinator returns an invoice and we trust the app to pay for it.

Invoice generation rationale

We choose to let the coordinator generate
an invoice rather than send an spontaneous payment from the app so that we can more easily update the coordinator fees without having to release a new version of the app.

Payment timing rationale

In patch 7c6a4bb the app was paying the invoice as soon as possible, but this had two downsides:

  1. The app could end up paying for a trade that didn't come to fruition.
  2. Updating the LN-DLC channel from the rust-dlc side and rust-lightning side simultaneously is not currently supported, so we could run into channel-breaking issues.

As such, we eventually opted for the simple 74a0acf. The solution is not perfect and it assumes that the app will not be rebooted until the payment is sent, but it should be good enough for now.

Other thoughts

Eventually, the order-matching fee could be included in the payout curve or, perhaps even better, as a separate static output on the buffer transaction (this is currently not supported).


These are some TODOs that could be tackled here or in follow-ups:

Footnotes

  1. Given that we can only charge taker fees for now. We should create a separate ticket for the maker once it's possible to do so.

@luckysori
Copy link
Contributor Author

With 4a18708 it looks like this:

image

(Ignore the overflow warnings, those are already happening on native.)

@da-kami
Copy link
Contributor

da-kami commented Jun 30, 2023

Verify that the app can actually pay for both executing the trade and the order-matching fee before executing the trade.

Not sure we have to - we can never really guarantee this completely because:

  • we have market orders and we cannot guarantee the execution price
  • The user might send funds out (we could block that, but that might also be hard.

I think the better solution will be:

  1. The app (user) fails to pay the invoice for the order
  2. The coordinator pushes a notification to the app, this will display a warning to the user that the invoice has to be paid otherwise consecutive orders will fail.
  3. The coordinator has to keep record of the paymnets in association with the order. We could allow that the user pays the invoice from a different wallet to avoid being blacklisted (...)

@da-kami
Copy link
Contributor

da-kami commented Jun 30, 2023

Tell the user about the estimated fee to be charged before they create the order.

In my opinion we should do this before we release this feature, otherwise it's not transparent enough.

@luckysori
Copy link
Contributor Author

Verify that the app can actually pay for both executing the trade and the order-matching fee before executing the trade.

Not sure we have to - we can never really guarantee this completely because:

* we have market orders and we cannot guarantee the execution price

* The user might send funds out (we could block that, but that might also be hard.

I think the better solution will be:

1. The app (user) fails to pay the invoice for the order

2. The coordinator pushes a notification to the app, this will display a warning to the user that the invoice has to be paid otherwise consecutive orders will fail.

3. The coordinator has to keep record of the paymnets in association with the order. We could allow that the user pays the invoice from a different wallet to avoid being blacklisted (...)

Thanks for your thoughts on this.

I agree that we won't be able to fully guarantee that the taker (app) will be able to pay for both executing the trade and the fee invoice.

Since we want this to be atomic anyway and we know that we will eventually do so, I would advocate for keeping it as simple as possible for this non-atomic version. As such I would hesitate to add any complex logic around the current flow.

Given the current state of the project, I still advocate for a very crude check before letting the user place the order because:

  1. We can take a reasonable estimate of the order-matching fee client-side, even if the price might fluctuate. We could be conservative and assume that the price might end up being 100 dollars worse, for example.
  2. Fees should only be a small number of sats (given the trade sizes we are going for atm), so it's unlikely that we block a valid trade by mistake.

@da-kami
Copy link
Contributor

da-kami commented Jun 30, 2023

[snip]

Given the current state of the project, I still advocate for a very crude check before letting the user place the order because:

1. We can take a reasonable estimate of the order-matching fee client-side, even if the price might fluctuate. We could be conservative and assume that the price might end up being 100 dollars worse, for example.

2. Fees should only be a small number of sats (given the trade sizes we are going for atm), so it's unlikely that we block a valid trade by mistake.

I'm happy with the crude check for now; given that we want to display the fee it should be part of the calculation anyway. (sorry, could have pointed that out)
As long as we are aware that we will need some tracking on the coordinator side at some point later, because we cannot guarantee the fee will get paid, that;s fine.

Copy link
Contributor

@da-kami da-kami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment, I am OK with merging this version, hence the approval, but I think changing it to pay after Finalized (upon updating the order to Filled) would be better.

We can also opt to experiment how often the user is charge without the execution succeeding, and if users actually complain.

mobile/native/src/ln_dlc/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@holzeis holzeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

bors bot added a commit that referenced this pull request Jul 3, 2023
864: feat: charge fee when opening a jit channel r=holzeis a=holzeis

fixes #577 

- The payment of the fee is not yet depicted as a special payment. This will be covered in a follow up PR after aligning with #863
- The funding transaction is only cached in memory

TODOs that will be covered in follow up tickets.
- [ ] https://github.com/get10101/meta/issues/172
- [ ] #873
- [ ] #883

![Simulator Screenshot - iPhone 14 Pro - 2023-06-30 at 11 34 28](https://github.com/get10101/10101/assets/382048/d22e680c-889a-4dd4-9e3f-c6d0d84a53ea)


Co-authored-by: Richard Holzeis <[email protected]>
@luckysori
Copy link
Contributor Author

I already had approvals before and now I've tackled the extra TODOs. Do take a look at the updated PR, @holzeis and @da-kami if you have time.

I'm merging for now. Any new feedback can be addressed in follow-ups.

bors r+

bors bot added a commit that referenced this pull request Jul 5, 2023
863: Pay order-matching fee on the app r=luckysori a=luckysori

Fixes #838[^1].
Fixes https://github.com/get10101/meta/issues/170.
Fixes https://github.com/get10101/meta/issues/171.
Fixes #884.

We keep it simple for now: the coordinator returns an invoice and we trust the app to pay for it.

Invoice generation rationale
----------------------------
We choose to let the coordinator generate
an invoice rather than send an spontaneous payment from the app so that we can more easily update the coordinator fees without having to release a new version of the app.

Payment timing rationale
------------------------

In patch 7c6a4bb the app was paying the invoice as soon as possible, but this had two downsides:

1. The app could end up paying for a trade that didn't come to fruition.
2. Updating the LN-DLC channel from the `rust-dlc` side and `rust-lightning` side simultaneously is not currently supported, so we could run into channel-breaking issues.

As such, we eventually opted for the simple 74a0acf. The solution is not perfect and it assumes that the app will not be rebooted until the payment is sent, but it should be good enough for now.

Other thoughts
--------------

Eventually, the order-matching fee could be included in the payout curve or, perhaps even better, as a separate static output on the buffer transaction (this is currently not supported).

---

These are some TODOs that could be tackled here or in follow-ups:

- [x] Verify that the app can actually pay for both executing the trade and the order-matching fee _before_ executing the trade.
- [x] Only claim the order-matching fee once the trade has been executed. #884
- [x] Tell the user about the estimated fee to be charged before they create the order. https://github.com/get10101/meta/issues/170
- [x] Show the user the charged fee on the success screen after executing the order. https://github.com/get10101/meta/issues/171


[^1]: Given that we can only charge taker fees for now. We should create a separate ticket for the maker once it's possible to do so.

Co-authored-by: Lucas Soriano del Pino <[email protected]>
We keep it simple for now: the coordinator returns an invoice and we
trust the app to pay for it.

Invoice generation rationale
----------------------------
We choose to let the coordinator generate
an invoice rather than send an spontaneous payment from the app so
that we can more easily update the coordinator fees without having to
release a new version of the app.

Payment timing rationale
------------------------

The app pays the invoice as soon as the coordinator responds to the
trade request successfully. For now we let the coordinator claim the
payment immediately, but we could wait until the trade has actually
been executed to _claim_ the payment.

Claiming the payment later should be simple enough: let the
coordinator remember the `PaymentHash` of the order-matching fee
invoice when generating it and do not claim it automatically when
receiving the corresponding `PaymentClaimable` event (store the
preimage instead). Once the trade has been executed, look for the
invoice in storage and finally claim the funds.

Other thoughts
--------------

Eventually, the order-matching fee could be included in the payout
curve or, perhaps even better, as a separate static output on the
buffer transaction (this is currently not supported).
This patch includes an explicit sleep that should be removed once we
understand why we can fail to emit the `PaymentClaimable` event in the
coordinator and we implement a fix.

Another caveat is that the order-matching fee invoice is stored in
memory, so we could theoretically end up closing the app before the
payment goes through.
@bors
Copy link
Contributor

bors bot commented Jul 5, 2023

Canceled.

@luckysori
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 5, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit dadbc4b into main Jul 5, 2023
7 checks passed
@bors bors bot deleted the feat/taker-fee branch July 5, 2023 13:36
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.

Only claim the order-matching fee once the trade has been executed Order matching fees
4 participants