-
Notifications
You must be signed in to change notification settings - Fork 85
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
Feat/order book add fulfill order partially #1559
Conversation
1cb3ac7
to
97c6940
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.
Clean and nice and fast as always. Got some thoughts about the parameters of the call. But otherwise good.
pallets/order-book/src/lib.rs
Outdated
let partial_fulfillment = !remaining_buy_amount.is_zero(); | ||
|
||
ensure!( | ||
partial_buy_amount >= order.min_fulfillment_amount, |
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.
This would mean the min_fullfillment_amount
is not a global min but rather a min_per_buy
. I am okay with that, just wanted to channel this by you @hieronx .
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.
Please let me know if we are OK with this, otherwise we can add a check for the remaining buy amount to ensure that it doesn't go too low, even though I'm not sure if that makes sense ^^
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.
No, I was rather thinking that it is a one-time
amount. Like, I wanna get at least x
. But it is fine to go with the given solution.
97c6940
to
6c9421b
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.
I really appreciate your thoroughness, especially with the unit tests! The logic LGTM but I would like to reduce code duplication (comment). Apart from that a few minor nits which are no blocking.
order_id, | ||
placing_account: order.placing_account, | ||
fulfilling_account: ACCOUNT_1, | ||
partial_fulfillment: true, |
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.
AFAICS, the test should fail here if fulfillment_ratio
is 100%?!
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.
Yes, but it doesn't get to 100 in this test. The 100 percent case is handled separately given the different expected events.
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.
Ah dumb me forgetting that 0..100 != 0..=100
in Rust 🙈
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.
Nah, that's on me since I did not find a proper way to have a separate test for each percentage using a macro. If we get a failure here now, one would have to debug and figure out which percentage is problematic, which is awkward to say the least.
Maybe @lemunozm can help ^^
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.
IMO it's the current test is more than sane. Theoretically, you could add a debug message to the assertion(s) to populate the failure fulfillment_ratio
.
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.
Sorry, just saw this now.
Does each different value of fulfillment_ratio
use a different path in the code? Maybe it's unnecessary to test all values and only do it with corner cases, for example, with 1
, 50
, 99
.
The macro would be cool, but doesn't hurt to leave it as it is and print the ratio on each iteration. To the purists 😄, exists a catch_unwind
that can be used in these cases to add some extra information when the test fails. For example, adding the fulfillment_ratio
value in the error message used in that iteration. Maybe I will add it to the fuzzer.
… extra test setup
c6002c4
to
a9b6cfd
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! Great work 🚀
order_id, | ||
placing_account: order.placing_account, | ||
fulfilling_account: ACCOUNT_1, | ||
partial_fulfillment: true, |
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.
IMO it's the current test is more than sane. Theoretically, you could add a debug message to the assertion(s) to populate the failure fulfillment_ratio
.
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!
Description
Added a new extrinsic in the
order-book
pallet that allows for a partial order fulfillment.Checklist: