-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate own step payout function
Before this patch, we generated a polynomial payout function which would then be transformed by `rust-dlc` into a step function. This approach was problematic because we could not trust `rust-dlc` to not mess with the intervals excessively. Specifically, any changes to the liquidation intervals could cause problems because they represent the collateral reserves, which are used to indicate available balances and are circumstantially needed to complete features such as position resizing. Now we take full control of the payout function generation, directly generating a step function that can be consumed by `rust-dlc` _without_ rounding. The payout is calculated by taking the PNL at the half-way point of the interval. It is important to emphasise that we must opt out of rounding by using a `RoundingIntervals` with a single element of the form: ```rust RoundingInterval { begin_interval: 0, rounding_mod: 1, } ``` Overall, I think the code is considerably simpler and there are fewer edge cases to handle. One important thing to consider is that we can now directly control the number of payouts we generate, which has an effect on the number of CETs that will be created. This is currently set by the constant `PAYOUT_CURVE_DISCRETIZATION_INTERVALS`, but in the future we could make it dynamic. Additionally, at the moment the majority of the intervals are of equal length in terms of price. Eventually we might want to generate more, smaller intervals around the starting price, and make the less likely intervals bigger as we approach the liquidation zones. Other notable changes --------------------- Since we had to replace a snapshot, we've introduced a dev-dependency to `insta`[^1], a library that makes it easy to write and maintain snapshot tests. There is a companion tool, `cargo-insta`[^2], which can help with this process. [^1]: https://github.com/mitsuhiko/insta. [^2]: https://github.com/mitsuhiko/insta/tree/master/cargo-insta.
- Loading branch information
Showing
9 changed files
with
5,107 additions
and
40,432 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.