-
Notifications
You must be signed in to change notification settings - Fork 217
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
Simplify AMM Swap API #4856
Comments
I'm not getting it yet. Are you proposing that there be just one operation |
I updated the description such that it should now answer your question here. |
That's clear, thanks. It doesn't let someone express what That's good enough for what we want when liquidating, but I'm not yet convinced that there aren't use cases for the current API. I think I'd be happier with |
It supports the current const proposal = { give: { In: collateral }, want: { Out: debt } };
E(zcf).offer(
E(amm).makeSwapInvitation(),
proposal,
payments,
{ maxOut: debt },
); The |
I don't understand the pseudo-code well enough to tell if it does what I want. I don't see that it calculates a trade based on the 'Out' price when maxOut is specified. What I'd expect This is not the same as calculating a swap based on the If soda is 6$/bottle swapIn($20) ==> 3 bottles, $18 swapOut($20, 4 bottles) ==> no trade I think we want liquidate(3 bottles, $15) ==> 3 bottles, $18 |
Closed via #5125 |
What is the Problem Being Solved?
Supporting both "swapIn" and "swapOut" in the contract API increases the complexity of the contract while narrowing its use cases. This is because the
swapOut
cases uses thewant
in the proposal as both the limit and as the sale target. Thus for example, clients cannot express the requirement from liquidation of "purchase up to a limit but no more", because a want expresses "at least" not "at most".Description of the Design
Replace
swapIn
andswapOut
with a singleswap
operation that takes an additionalmaxOut
offer argument that is not thewant
amount. ThemaxOut
argument, if present, specifies that the most that the client needs back.swapIn
operation would simply be a deprecated alias forswap
.swapOut
operation would invokeswap
withmaxOut
as theOut
amount from thewant
.The pseudo code for the logic of the swap operation is (with conveniently sloppy fee compute):
Note that this also returns an
X
that is the minimum requiredIn
to purchase the resultingY
Security Considerations
With this change, the
want
becomes exclusively a safety mechanism, which should make it more useful.Test Plan
swapOut
tests to use the new API directly insteadmaxOut
to be higher thanwant.Out
refs: #4321
The text was updated successfully, but these errors were encountered: