interledger / rafiki

An open-source, comprehensive Interledger service for wallet providers, enabling them to provide Interledger functionality to their users.
https://rafiki.dev/
Apache License 2.0
234 stars 83 forks source link

Fix minimum delivery amounts #2770

Closed mkurapov closed 3 months ago

mkurapov commented 3 months ago

Context

We are able to get "unrealistic" minimum delivery amounts when we are getting quotes .

For example, if we are sending between a RON (scale 2) wallet address to a USD (scale 2) wallet address, where the exchange rate is 1 RON = 0.2 USD, we can set debitAmount to 0.02 RON and get back a quote for 0.01 USD, even though, because of the exchange rate, the outgoing payment will never actually go through, since 0.02 RON * 0.2 = 0.004 USD, which is under a single unit of value of 0.01 USD. This is caused by the way that the ILP pay rounding works.

Example of behaviour

So even though you can create the quote (and corresponding outgoing payment) for a debitAmount that will clearly not deliver the minimum unit of the receiving asset, the payment will fail when trying to send.

I set up a scenario, sending from RON (scale 2) to USD (scale 2), where 1 USD = 20 RON (ie 1 RON = 0.05 USD). First attempt, you can create a fixed-send 0.02 RON quote that results in 0.01 USD delivery. The outgoing payment can be created from the quote, but it fails when sending.

Second attempt, 0.19 RON quote results in a 0.01 USD delivery. The outgoing payment can be created, but still fails when sending.

Final attempt, trying to send 0.20 RON results in a 0.01 USD delivery. The outgoing payment can be created and is successful. This means, even though the quoting works in all 3 scenarios, the payment will only be completed when the correct delivery amount is reached, in our case, when at least 0.20 RON is sent, which is good. This means there are no ILP pay "issues" or "money making" during actual payment.

https://github.com/interledger/rafiki/assets/15069181/702d7a98-fa85-4577-95e3-ee997aad614d

Slack threads:

Todos

mkurapov commented 3 months ago

Update 20-06

Following up, so even though you can create the outgoing payment, it will fail when trying to send.

I set up a scenario, sending from RON (scale 2) to USD (scale 2), where 1 USD = 20 RON (ie 1 RON = 0.05 USD).

First attempt, you can create a fixed-send 0.02 RON quote that results in 0.01 USD delivery. The outgoing payment can be created, but fails when sending. Second attempt, 0.19 RON quote results in a 0.01 USD delivery. The outgoing payment can be created, but still fails when sending. Final attempt, trying to send 0.20 RON results in a 0.01 USD delivery. The outgoing payment can be created and is successful.

This means, even though the quoting works in all 3 scenarios, the payment will only be completed when the correct delivery amount is reached, in our case, when at least 0.20 RON is sent, which is good. This means there are no ILP pay "issues" or "money making" during actual payment.

The only thing we need to decide on is whether we allow quotes and outgoing payments to be created in Rafiki in the scenarios where we for sure know that the payment will not succeed (like the attempts in 1 & 2)