Skip to content
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

Ensure that trade_preimage will not succeed on input that will fail on buy/sell/setprice #937

Merged
merged 6 commits into from
May 10, 2021

Conversation

sergeyboyko0791
Copy link

  • GenerateTxError::OutputValueLessThanDust converts to TradePreimageError::InternalError the value is upper bound
  • Fix invalid required field in NotSufficientBalance error generated by calc_max_maker_vol

…n setprice

* Add balance checking on trade_preimage::method = setprice
* Add an additional params checking using MakerOrderBuilder
* Fix broken tests, add red test_trade_preimage_additional_validation test
…n sell/buy

* Add balance checking on trade_preimage::method = sell/buy
* Add an additional params checking using TakerOrderBuilder
* Make the test_trade_preimage_additional_validation test green
* Extend test_trade_preimage_not_sufficient_balance
… calc_max_maker_vol

* Fix broken tests
* Extend the test_trade_preimage_not_sufficient_balance test
* Add the test_trade_preimage_deduct_fee_from_output_failed test
* GenerateTxError::OutputValueLessThanDust converts to TradePreimageError::InternalError the value is upper bound
price: actual.to_decimal(),
threshold: threshold.to_decimal(),
},
MakerOrderBuildError::RelVolTooLow { actual, threshold } => TradePreimageRpcError::VolumeIsTooSmall {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is a bit complicated to separate the TradePreimageRpcError::VolumeIsTooSmall to TradePreimageRpcError::BaseVolumeIsTooSmall and TradePreimageRpcError::RelVolumeIsTooSmall.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why that is. Can't we just have two different errors for BaseVolumeIsTooSmall and RelVolumeIsTooSmall here instead of one
https://github.com/KomodoPlatform/atomicDEX-API/blob/30d962c392293a470f97ace63f079953f9db297c/mm2src/lp_swap/trade_preimage.rs#L213
Just to be known what is meant by the threshold because for rel volume it also depends on the price.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be known what is meant by the threshold because for rel volume it also depends on the price.

Great point! threshold is a minimum rel coin volume. The threshold price can be calculated by:
threshold_price = threshold / base_coin_volume, if method is buy

Copy link
Author

@sergeyboyko0791 sergeyboyko0791 May 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just have two different errors

Please see where the CheckBalanceError::from_trade_preimage_error function is called. For example, here. We should pass an additional parameter indicating which coin is base and which is rel. And it will only be used to construct either BaseVolumeIsTooLow or RelVolumeIsTooLow.

But you are right, it's better to separate the TradePreimageRpcError::VolumeIsTooLow into BaseVolumeIsTooLow and RelVolumeIsTooLow, because I didn't even think how the user would calculate the threshold price.
So I think there is no problem in that some functions will have one more argument.

I'll do it tomorrow or Monday.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckBalanceError::from_trade_preimage_error is called also at the start of the taker swap. But at this point, there is no information about which coin was base and which is rel. So as we discussed with @yurii-khi, it would be convenient for both MarketMaker and GUI to handle an error like
VolumeTooLow { volume: BigDecimal, threshold: BigDecimal, coin: String }. It will allow us to determine if it was a base coin volume or a rel coin volume.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckBalanceError::from_trade_preimage_error is called also at the start of the taker swap. But at this point, there is no information about which coin was base and which is rel. So as we discussed with @yurii-khi, it would be convenient for both MarketMaker and GUI to handle an error like
VolumeTooLow { volume: BigDecimal, threshold: BigDecimal, coin: String }. It will allow us to determine if it was a base coin volume or a rel coin volume.

Is it possible to have some json example in case of error ? so i can start adding the data structure in cpp in my case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shamardy, could you please recheck the last changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have some json example in case of error ? so i can start adding the data structure in cpp in my case

I'm working on docs right now. Please wait until I finished :)

Copy link
Author

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pay attention to my comment above.

* Rename 'TradePreimageRpcError::VolumeIsTooSmall' to 'TradePreimageRpcError::VolumeTooLow'
* Add the 'coin' field to 'TradePreimageRpcError::VolumeTooLow'
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a single comment 🙂

mm2src/lp_swap/trade_preimage.rs Show resolved Hide resolved
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@artemii235 artemii235 merged commit 73875fd into dev May 10, 2021
@artemii235 artemii235 deleted the improve-trade-preimage-error branch May 10, 2021 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure that trade_preimage will not succeed on input that will fail on buy/sell/setprice.
4 participants