-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fix: FI swap correclty with asymmetric ratios #1746
Conversation
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 have a question about the new 2 FI tests. Code looks great as always!
util::fulfill_last_swap(Action::Investment, foreign_to_pool(3 * AMOUNT / 4)); | ||
|
||
assert_eq!( | ||
ForeignInvestmentInfo::<Runtime>::get(&USER, INVESTMENT_ID), | ||
None, | ||
); | ||
assert_eq!(ForeignInvestment::investment(&USER, INVESTMENT_ID), Ok(0)); | ||
assert_eq!(MockInvestment::investment(&USER, INVESTMENT_ID), Ok(0)); |
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.
Why does the foreign investment vanish when we fulfill only 3/4 of the order? Shouldn't there be 1/4 left?
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.
Note that we only fulfill the swap with the amount that was previously swapped in the opposite direction, which is 3/4. The 1/4 left has never been swapped, so when we decrease, such 1/4 is canceled.
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 yes of course, thanks for the explanation!
util::fulfill_last_swap( | ||
Action::Investment, | ||
foreign_to_pool(3 * AMOUNT / 4) * MULTIPLIER, | ||
); | ||
|
||
assert_eq!( | ||
ForeignInvestmentInfo::<Runtime>::get(&USER, INVESTMENT_ID), | ||
None, | ||
); | ||
assert_eq!(ForeignInvestment::investment(&USER, INVESTMENT_ID), Ok(0)); | ||
assert_eq!(MockInvestment::investment(&USER, INVESTMENT_ID), Ok(0)); |
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.
Same question here.
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.
The same applies here
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.
Clear as a crystal ball!
* fix by cancellation * noop if currencies are different * fix typos
Description
Description
The issue is described in this thread
How it works
Now
pallet-swaps
offer a new methodcancel_swap()
which allows to cancel partially a pending amount. This way, we can cancel an inverse swap (in its currency out denomination) before applying the new swap (in the other currency denomination). Saving us from usingconvert_by_market()
in the opposite direction.