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

Can we consolidate trade and swap into one helper? #1531

Closed
erights opened this issue Aug 17, 2020 · 2 comments · Fixed by #1667
Closed

Can we consolidate trade and swap into one helper? #1531

erights opened this issue Aug 17, 2020 · 2 comments · Fixed by #1667
Assignees
Labels
Zoe package: Zoe

Comments

@erights
Copy link
Member

erights commented Aug 17, 2020

I wonder if we really need trade and swap as distinct abstractions. Swap begins by checking if keepSeat has exited. However, it should also error if trySeat has exited. trade should also error if either has exited, so both checks could be moved into trade.

Looking at the callers of trade, a major reason they can't use swap is that the keepSeat remains open. They all do exit the trySeat.

Looking at the callers of swap, since swap throws on failure and only closes the keepSeat on success, it would not be an undue burden for swap's callers to exit the keepSeat after the call to swap. Since we did presciently call it the keepSeat, it would also not be surprising for swap itself not to close it.

_Originally posted by @erights in #1414 (comment)

@katelynsills katelynsills added the Zoe package: Zoe label Aug 17, 2020
@katelynsills
Copy link
Contributor

Let's look into checking whether the seats have exited and otherwise making the two functions more uniform but let's make sure to keep swap for the specialized use cases. Open issue in documentation to clarify use cases for each.

@katelynsills katelynsills self-assigned this Aug 31, 2020
@katelynsills
Copy link
Contributor

Just as a study of how we use swap, we currently use it in 3 contracts:

const matchingSeatOfferHandler = matchingSeat => {
const swapResult = swap(zcf, firstSeat, matchingSeat);
zcf.shutdown();
return swapResult;

const rejectMsg = `The covered call option is expired.`;
const exerciseOption = exerciserSeat => {
const swapResult = swap(zcf, sellerSeat, exerciserSeat, rejectMsg);
zcf.shutdown();
return swapResult;

function swapIfCanTrade(offers, seat) {
for (const offer of offers) {
const satisfiedBy = (xSeat, ySeat) =>
satisfies(zcf, xSeat, ySeat.getCurrentAllocation());
if (satisfiedBy(offer, seat) && satisfiedBy(seat, offer)) {
swap(zcf, seat, offer);
// return handle to remove
return offer;
}
}
return undefined;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Zoe package: Zoe
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants