-
Notifications
You must be signed in to change notification settings - Fork 23
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
Reintroduce position resizing #2359
Conversation
b7d2e15
to
0c4a9c5
Compare
5e6dd19
to
10e0cee
Compare
0c4a9c5
to
c377373
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
coordinator/migrations/2024-03-18-083352_add_order_matching_fees_to_position/up.sql
Outdated
Show resolved
Hide resolved
@@ -218,6 +219,11 @@ class _WelcomeScreenState extends State<WelcomeScreen> { | |||
void initState() { | |||
super.initState(); | |||
|
|||
if (Environment.parse().network == "regtest") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
coordinator/src/trade/mod.rs
Outdated
.await | ||
.context("Could not propose DLC channel update")?; | ||
|
||
// TODO: Shouldn't we include actually starting the DLC protocol in the DB transaction in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we use different transactional systems, postgres and sled I think it doesn't matter. But once we are also using postgres that would be great. As we could atomically execute both rust dlc and 10101 changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I've removed the TODO.
I think what confuses me is the name. It is surprising that start_dlc_protocol
, called on the ProtocolExecutor
, only interfaces with the database.
event::publish(&EventInternal::PositionUpdateNotification(position)); | ||
// Assume that if there is an order in filling we are dealing with position resizing. | ||
// | ||
// TODO: This is garbage as we very well know. Any other ideas? We could generate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bonomat and I were talking before, that it would probably make sense to add a custom message to wrap the renew protocol for rollover, resizing and async matching.. and enrich the message with some 10101 meta data. that would also allow us to get rid of the ugly websocket communication to send over some additional data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good, but I think that belongs in a different PR. Given your approval, I assume you are okay with not tackling this TODO right now.
0f0ae67
to
b3b29bd
Compare
At this stage it is only informative[^1], and `docker-compose` gives me a warning about it. [^1]: https://docs.docker.com/compose/compose-file/04-version-and-name/#version-top-level-element-optional.
The order-matching fee will accumulate all the order-matching fees for a given position: opening order-matching fee; arbitrarily many resize order-matching fees; and closing order-matching fee. This information can be used to compute the collateral reserve when resizing the position. The accumulated order-matching fee will be the lower bound for the coordinator's collateral reserve.
The production coordinator does not have any instances of `PositionState::ResizeProposed` and `PositionState::Resizing`, since they correspond to _subchannel_ resizing protocols. We still keep `PositionState::Resizing` around since we can reuse the type for the new DLC channel resizing protocol.
This saves me a few seconds every time I start a fresh `regtest` app.
By default, we now use a fixed price of $50k. This applies to CI too. This is useful if we want to assert on specific values in the e2e tests. Instructions to use the binary ------------------------------ 1. Use a $50k fixed price: ``` $ cargo run --bin dev-maker ``` or ``` $ just maker ``` 2. Use a historic price feed: ``` $ cargo run --bin dev-maker -- historic ``` or ``` $ just maker historic ``` 3. Use a custom fixed price e.g $100k: ``` $ cargo run --bin dev-maker -- fixed 100000 ``` or ``` $ just maker "fixed 100000" ```
385db6e
to
11b0cfc
Compare
Queuing this up because I can't face another rebase that breaks another test. I will tackle any review comments in a separate PR. |
11b0cfc
to
a19cab9
Compare
- I fixed calculation bugs in our original implementation of position resizing that we used for LN-DLC channels. This is why some assert values changed. - I reintroduced the resizing e2e tests, which are now much more helpful because they assert on the specific values of position and trade for the app. This can be further improved by asserting on the coordinator side. The same pattern should eventually be applied to most e2e tests. - I had to add an `is_complete` column to the coordinator's `trade` table to be able to record the `trader_realized_pnl_sat` ahead of time. Limitations: - The app must have an order in `Filling` to be able to update the position after we get a resizing channel renewal offer. This pattern has caused problems in the past. We will probably fix this my sending extra metadata with the `rust-dlc` offer message.
A trade only has a collateral associated with it once it's applied to a position. Since it's not used for anything, we remove it.
Already fixed.
a19cab9
to
7681b79
Compare
.expect("to fit"), | ||
order_matching_fee, | ||
trader_realized_pnl_sat: realized_pnl.map(SignedAmount::to_sat), | ||
is_complete: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 It looks to me the only reason why you'd have to create the trade already here is because of the trader_realized_pnl_sat
. Why not simply add that to the trade_params
table which is anyways just temporary and intended to remember the state from when the protocol starts to when it ends.
I dislike the is_complete
flag because
- It introduces a state on the trade.
- It is not consistent with the rest of the implementation. e.g. if we want to keep the
is_complete
flag there is no reason for a technicaltrade_params
table. We could remove it and create the trade immediately with the required data and set it to "incomplete"
I am not saying we have to stay with the trade_params
but mixing the two concepts feels wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be right.
It seemed wrong to use the trade_params
table because the PNL is not a trade parameter. It's the result of applying the trade to a position.
I agree that it is inconsistent. I can try to fix it, but the priority for me is fairly low.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it anyway: #2394.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
It seemed wrong to use the trade_params table because the PNL is not a trade parameter. It's the result of applying the trade to a position.
Maybe renaming the table would help, but I can't think of a better name 🙈
Fixes #1791.
position-resizing-v2.mp4
I fixed calculation bugs in our original implementation of position resizing that we used for LN-DLC channels. This is why some assert values changed.
I reintroduced the resizing e2e tests, which are now much more helpful because they assert on the specific values of position and trade for the app. This can be further improved by asserting on the coordinator side. The same pattern should eventually be applied to most e2e tests.
I had to add an
is_complete
column to the coordinator'strade
table to be able to record thetrader_realized_pnl_sat
ahead of time.Limitations:
Filling
to be able to update the position after we get a resizing channel renewal offer. This pattern has caused problems in the past. We will probably fix this my sending extra metadata with therust-dlc
offer message.