Keep track of outgoing/incoming settlement proposals in a hashmap inside the CFD
rocket that is available as a Rocket state in order to derive correct CfdState
for the UI.
Add placeholders for actions for accepting/rejecting settlement offers in the maker.
Also:
- rename Accept/Reject in few places to reduce ambiguity between interacting
with an order and a settlement proposal.
- allow only one in-flight settlement proposal from the taker
* Offer price based on current price
To keep it simple we set the offer price to current price + 3% spread if we have a current price and the offer's initial value is 0.
This. means we cannot set the offer price to 0 anymore, but that is OK.
Additionally, there is a refresh button so the maker can refresh the offer price (no auto-refresh for now).
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
For calculating the Profit/Loss in BTC we use a simple forumla:
- for long: `profit_btc = quantity_usd * ((1/initial_price)-(1/current_price))`.
- for short: `profit_btc = quantity_usd * ((1/current_price)-(1/initial_price))`.
We round the p/l to 6 decimal points in the UI.
P/L is easier to understand in percent. For the UI we round to 2 decimal points.
We also stopped generating random oracle-related values for the
protocol tests, greatly simplifying the test suite. This has the
side-effect that we no longer verify that _all_ CETs can be unlocked.
Re-introducing random oracle-related data in the future should be
considered.
Previously we only returned the new state, but we also have to set it internally, otherwise the cfd might be out of date.
This was a problem when getting the refund transaction from the cfd directly after a state transition to `MustRefund`.
The cfd instance had not actually transitioned to the new state, even though it was saved in the database.
1. Finalize with correct descriptor (of lock tx)
2. Restart fix: Allow retrieving the commit tx in state `PendingCommit` so we can re-publish in that state.
3. Update cfd feed after state transition to `PendingCommit` to see updated state in UI.
This should greatly improve resilience as we no longer have any
tasks within `tokio` that can fail without recovering.
Instead, we periodically ping the actor with a `Sync` message which
updates the local state of all scripts and sends out messages accordingly.
Caused trouble because of route collisions, so the integration was done now.
Required distinguishing Maker and Taker on the cfd level, which comes in handy anyway.
We distinguish by order origin, but still map to a `Role` enum (`Taker` / `Maker`) for readability.
To avoid duplication the `Role` from contract setup was moved into the model and used throughout.
The complexity of the code part was not worth the information we got out of it, so it was simplified.
Should hopefully make it a bit more readable and easier to understand.