-
Notifications
You must be signed in to change notification settings - Fork 15
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: RPC call for amount_to_liquidity #3835
Conversation
PRO-111 Feature: RPC call for Amm:: liquidity_to_amounts()
Should expose liquidity_to_amounts() in the AMM as a rpc call, so front end can convert liquidity into asset amounts |
Codecov Report
@@ Coverage Diff @@
## main #3835 +/- ##
======================================
- Coverage 71% 71% -0%
======================================
Files 363 363
Lines 55659 55763 +104
Branches 55659 55763 +104
======================================
+ Hits 39397 39467 +70
- Misses 14303 14327 +24
- Partials 1959 1969 +10
... and 4 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
) | ||
.unwrap(), | ||
1u128, | ||
); |
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.
Having said all of the above, i'm not sure this test is really necessary. We don't need to ensure the accuracy of the conversion (this is, or should be tested in the amm crate).
What we really care about here is whether the rpc works as expected, for example it shouldn't panic if there is no pool, or if the user submits an invalid tick range.
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 test here only verifies that the pub function worked as intended, I'm sure the inner workings works, as it was already used and tested in the AMM.
I've tested the RPC with local testnet to ensure the RPC works and wouldn't crash when the input was invalid.
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.
What I mean is that the exact value of the output is not really relevant to this test: we don't actually require that the error is within 1 unit. 1 is an arbitary limit (why not 2 or 10?).
This test is checking the inner details of the amm crate instead of testing this 'layer' of the rpc call. What this layer actually adds is: checking that the asset is valid, and passing the args correctly to the amm, passing the result (ok/err) back up the rpc call chain. If anything we should test this.
I've tested the RPC with local testnet
Even better if we can enforce this with a unit test :)
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.
Ok I think i understand now.
Removed the test for the AMM function itself, and instead test the correct error is returned when pool doesn't exist and when tick range isn't valid
upper, | ||
SideMap::from_array([unstable_amount.into(), stable_amount.into()]), | ||
) | ||
.ok() |
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.
We just swallow the error here. We could instead return something useful. It looks like there are two possible errors, either the pool doesn't exist, or the tick range is invalid.
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 found it difficult to return the error from run time to RPC call, I tried anyhow::error, &'static str and DispatchError, none of the was very nice to use.
I ended up having a custom error message when "None" was returned from the pallet call, so it provides better information to the RPC user.
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.
We already have Error variants for all possible amm errors. I'll show you what I mean.
Ok I tried using DispatchError and I can see it's annoying! I think returning the pallet's Error<T>
type might be an option, but I played around and I think a small dedicated error enum is the simplest to work with.
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.
Yeah using a new error enum is definitely the best approach!
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 @syan095
Co-authored-by: Daniel <daniel@chainflip.io> Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
This reverts commit dbfe96a.
This reverts commit dbfe96a.
This reverts commit dbfe96a.
This reverts commit dbfe96a.
* Revert "feat: RPC call for amount_to_liquidity (#3835)" This reverts commit dbfe96a. * rename collected structures * Add PositionInfo squash * cut out inner_liquidity_to_amounts squash squash * cut out inner_amounts_to_liquidity * amm range orders mint and burn by Size * output operation liquidity delta * remove unneeded trait impls * move sqrt_price_to_price * current_price rpc * add nicer swap and position functions * remove pool rpcs * remove deser and ser impls * amm pool new function * current_price doesn't use traits * make private/hide unneeded interfaces * pub amount in PositionInfo * cutout error translation functions * desired -> maximum * rename RangeOrderSize to OldRangeOrderSize * new interfaces * new implementations * handle order ids * spelling and add safe mode checks * update bouncer for new lp-interface * bouncer linting * fix range_order bouncer command * bouncer linting * lp api returns * required asset ratio rpc * lp rpc * Use "order" not "position" * use u256 * utilities squash squash * use new utilities * pools function pool_info and pools functions * pool_orders * pool_range_order_liquidity_value * rpcs * _asset * fix * move debit down * bought_amount * LiquidityTooLarge * remove old test * remove range_order iszero check * basic comments --------- Co-authored-by: Roy Yang <roy@chainflip.io> Co-authored-by: Martin Rieke <martin@chainflip.io>
* Revert "feat: RPC call for amount_to_liquidity (#3835)" This reverts commit dbfe96a. * rename collected structures * Add PositionInfo squash * cut out inner_liquidity_to_amounts squash squash * cut out inner_amounts_to_liquidity * amm range orders mint and burn by Size * output operation liquidity delta * remove unneeded trait impls * move sqrt_price_to_price * current_price rpc * add nicer swap and position functions * remove pool rpcs * remove deser and ser impls * amm pool new function * current_price doesn't use traits * make private/hide unneeded interfaces * pub amount in PositionInfo * cutout error translation functions * desired -> maximum * rename RangeOrderSize to OldRangeOrderSize * new interfaces * new implementations * handle order ids * spelling and add safe mode checks * update bouncer for new lp-interface * bouncer linting * fix range_order bouncer command * bouncer linting * lp api returns * required asset ratio rpc * lp rpc * Use "order" not "position" * use u256 * utilities squash squash * use new utilities * pools function pool_info and pools functions * pool_orders * pool_range_order_liquidity_value * rpcs * _asset * fix * move debit down * bought_amount * LiquidityTooLarge * remove old test * remove range_order iszero check * basic comments --------- Co-authored-by: Roy Yang <roy@chainflip.io> Co-authored-by: Martin Rieke <martin@chainflip.io>
* Revert "feat: RPC call for amount_to_liquidity (#3835)" This reverts commit dbfe96a. * rename collected structures * Add PositionInfo squash * cut out inner_liquidity_to_amounts squash squash * cut out inner_amounts_to_liquidity * amm range orders mint and burn by Size * output operation liquidity delta * remove unneeded trait impls * move sqrt_price_to_price * current_price rpc * add nicer swap and position functions * remove pool rpcs * remove deser and ser impls * amm pool new function * current_price doesn't use traits * make private/hide unneeded interfaces * pub amount in PositionInfo * cutout error translation functions * desired -> maximum * rename RangeOrderSize to OldRangeOrderSize * new interfaces * new implementations * handle order ids * spelling and add safe mode checks * update bouncer for new lp-interface * bouncer linting * fix range_order bouncer command * bouncer linting * lp api returns * required asset ratio rpc * lp rpc * Use "order" not "position" * use u256 * utilities squash squash * use new utilities * pools function pool_info and pools functions * pool_orders * pool_range_order_liquidity_value * rpcs * _asset * fix * move debit down * bought_amount * LiquidityTooLarge * remove old test * remove range_order iszero check * basic comments --------- Co-authored-by: Roy Yang <roy@chainflip.io> Co-authored-by: Martin Rieke <martin@chainflip.io>
Pull Request
Closes: PRO-111
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Added RPC call for getting the amount to liquidity