This PR does a few things:
* cleans up the SQL to make the queries clearer in terms of intent, as well as eliminating the use of an extra transaction in some write queries.
* adds some additional testing
* (mostly) eliminates the use of `serde_json::to_string()`, making the data columns behave in a more sane manner
We almost always have the entire `Cfd` available when we call this
function. It is therefore much easier to simply pass the entire
`Cfd` in instead of selective data.
Upon rejection, we always have to remove the order on the maker side, otherwise a taker cannot re-try taking (with e.g. a different amount) because there is already a rejected cfd in the taker database.
331: Fix default quantity in UI r=bonomat a=bonomat
`@thomaseizinger` : I'm not sure if I understand it correctly. Can I do ed2ec8eb49 or is this not allowed because I change the variable independent of what is in the state?
Alternative solution is the second commit ac8d6e191cresolves#330
Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
333: Use `MessageChannel` in `maker_routes` r=luckysori a=luckysori
More work towards #231.
Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
322: Cleanup in Cfd actors r=klochowicz a=klochowicz
I started out trying to fix a common gotcha (forgetting to refresh Cfd feed),
and then realised that I was not far off of addressing a bunch of TODOs in the code
Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
332: Provide margin of counterparty r=bonomat a=bonomat
Very useful for the maker.
Not shown in the UI for now.
Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
329: Set default log level for whole crate r=da-kami a=bonomat
Resolves#325
We were setting a filter for the binaries only and the rest was on INFO.
```
2021-10-15 08:47:06 WARN (post_cfd_action) POST /api/cfd/<id>/<action>
2021-10-15 08:47:06 WARN 🥅 Catchers:
2021-10-15 08:47:06 WARN (unauthorized) 401
2021-10-15 08:47:06 WARN (unauthorized) /api 401
2021-10-15 08:47:06 WARN 📡 Fairings:
2021-10-15 08:47:06 WARN Shield (liftoff, response, singleton)
2021-10-15 08:47:06 WARN SQL migrations (ignite)
2021-10-15 08:47:06 WARN 'maker' Database Pool (ignite)
2021-10-15 08:47:06 WARN Create actors (ignite)
2021-10-15 08:47:06 INFO 🛡️ Shield:
2021-10-15 08:47:06 WARN 🚀 Rocket has launched from http://127.0.0.1:8001
2021-10-15 08:47:06 INFO New taker 0f54e159-75ac-4d65-9d9f-e37847e88572 connected on 127.0.0.1:64286
2021-10-15 08:47:13 INFO POST /api/order/sell application/json:
2021-10-15 08:47:13 DEBUG Received new order
2021-10-15 08:47:14 INFO GET /api/feed text/event-stream:
2021-10-15 08:47:16 INFO POST /api/order/sell application/json:
2021-10-15 08:47:16 DEBUG Received new order
2021-10-15 08:47:21 DEBUG Taker wants to take an order taker_id=0f54e159-75ac-4d65-9d9f-e37847e88572 quantity=0 order_id=ed6dfa48-275e-4eae-b2f5-5c3ad154eda4
2021-10-15 08:48:06 DEBUG Fetching announcement for /x/BitMEX/BXBT/2021-10-15T22:00:00.price?n=20
2021-10-15 08:48:34 INFO POST /api/order/sell application/json:
2021-10-15 08:48:34 DEBUG Received new order
2021-10-15 08:48:41 DEBUG Taker wants to take an order taker_id=0f54e159-75ac-4d65-9d9f-e37847e88572 quantity=11 order_id=7bbd174b-10a2-4776-9d00-afa41a8077ae
2021-10-15 08:48:45 INFO POST /api/cfd/7bbd174b-10a2-4776-9d00-afa41a8077ae/acceptOrder:
2021-10-15 08:48:45 DEBUG Maker accepts an order order_id=7bbd174b-10a2-4776-9d00-afa41a8077ae
2021-10-15 08:49:06 DEBUG Fetching announcement for /x/BitMEX/BXBT/2021-10-15T22:00:00.price?n=20
2021-10-15 08:49:38 INFO Lock transaction published with txid 09fdafb1125295ea66401e1160542fa39d5695d61d64255bb94431275f892cb4
2021-10-15 08:49:45 DEBUG Found relevant Bitcoin transaction txid=09fdafb1125295ea66401e1160542fa39d5695d61d64255bb94431275f892cb4 status=in mempool
```
Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
321: Use `MessageChannels` in `maker_inc_connections::Actor` r=luckysori a=luckysori
We would have liked to attach the stream of `TakerStreamMessage`s directly to the `MessageChannel`, but we failed and instead decided to let the `maker_inc_connections::Actor` send these messages to itself and then forward them to the `maker_cfd::Actor`.
---
I wasted a lot of time trying to send the message directly to the `maker_cfd::Actor`. I trust that `@thomaseizinger` can find a way, but I had to give up 😞
Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
We would have liked to attach the stream of `TakerStreamMessage`s
directly to the `MessageChannel`, but we failed and instead decided to
let the `maker_inc_connections::Actor` send these messages to itself
and then forward them to the `maker_cfd::Actor`.
Inserting cfd or updating its state requires a follow-up update on the Cfd feed
sent to the UI. Encapsulate the behaviour in functions that are shared
across Cfd actors.
307: Setting boundaries r=bonomat a=bonomat
This improves the UX slightly as the user knows what is the min and max amount.
The UI will default to min amount.
Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
318: Introduce a `fan_out::Actor` instead of iterating in the `oracle::Actor` r=thomaseizinger a=thomaseizinger
A fan-out actor takes an incoming message and forwards it to a set
of actors. This allows our `oracle::Actor` to be unaware, how many
other actors are interested in the attestation, thus simplifying it.
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
315: Lock in profit on collaborative close price r=da-kami a=da-kami
fixes#312
Once we have collaborative close present in the state(s) we lock in the profit based on the price of the collaborative close.
Note: Currently no automated validation on the maker side if the given amounts and price of collaborative settlement are sane.
Co-authored-by: Daniel Karzel <daniel@comit.network>
Once we have collaborative close present in the state(s) we lock in the profit based on the price of the collaborative close.
Note: Currently no automated validation on the maker side if the given amounts and price of collaborative settlement are sane.
316: Provide more feedback to the user during collaborative settlement r=klochowicz a=klochowicz
Fixes#309
Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
Simplify model's state machine as PendingClose only matters for the UI
(for user feedback & available actions).
Disallow proposing another settlement if one was already signed.
295: Db refactor r=thomaseizinger a=DeliciousHair
DB code refactoring for #88
The primary goal was to remove all of the calls to `serde_json::to_string()` for the data-handling, thus enabling us to do (more or less):
```rust
Order {
row.column,
...
}
```
as well as clean up the SQL for easier reading. This has mostly been accomplished, with further refinements easily accomplished once the upstream issues in `sqlx` are addressed. See #314 for issues we are tracking.
Co-authored-by: DelicioiusHair <mshepit@gmail.com>
The primary goal was to remove all of the calls to `serde_json::to_string()`
for the data-handling, thus enabling us to do (more or less):
```rust
Order {
row.column,
...
}
```
as well as clean up the SQL for easier reading. This has mostly been
accomplished, with further refinements easily accomplished once the
upstream issues in `sqlx` are addressed. See #314 for issues we are
tracking.
A fan-out actor takes an incoming message and forwards it to a set
of actors. This allows our `oracle::Actor` to be unaware, how many
other actors are interested in the attestation, thus simplifying it.