Skip to content

Commit

Permalink
feat: add want, exit to empty seat (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills authored Aug 27, 2020
1 parent ac0e760 commit ae303e1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
28 changes: 18 additions & 10 deletions packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,15 @@ export function buildRootObject() {
// Shutdown the entire vat and give payouts
shutdown: () => E(zoeInstanceAdmin).shutdown(),
makeZCFMint,
makeEmptySeatKit: () => {
makeEmptySeatKit: (exit = undefined) => {
const initialAllocation = harden({});
const proposal = cleanProposal(getAmountMath, harden({}));
const proposal = cleanProposal(getAmountMath, harden({ exit }));
const { notifier, updater } = makeNotifierKit();
/** @type {PromiseRecord<ZoeSeatAdmin>} */
const zoeSeatAdminPromiseKit = makePromiseKit();
const userSeatPromiseKit = makePromiseKit();
const seatHandle = makeHandle('SeatHandle');

E(zoeInstanceAdmin)
.makeOfferlessSeat(initialAllocation, proposal, seatHandle)
.then(({ zoeSeatAdmin, notifier: zoeNotifier, userSeat }) => {
updateFromNotifier(updater, zoeNotifier);
zoeSeatAdminPromiseKit.resolve(zoeSeatAdmin);
userSeatPromiseKit.resolve(userSeat);
});

const seatData = harden({
proposal,
initialAllocation,
Expand All @@ -326,6 +319,21 @@ export function buildRootObject() {
);
zcfSeatToZCFSeatAdmin.init(zcfSeat, zcfSeatAdmin);
zcfSeatToSeatHandle.init(zcfSeat, seatHandle);

const exitObj = makeExitObj(
seatData.proposal,
zoeSeatAdminPromiseKit.promise,
zcfSeatAdmin,
);

E(zoeInstanceAdmin)
.makeNoEscrowSeat(initialAllocation, proposal, exitObj, seatHandle)
.then(({ zoeSeatAdmin, notifier: zoeNotifier, userSeat }) => {
updateFromNotifier(updater, zoeNotifier);
zoeSeatAdminPromiseKit.resolve(zoeSeatAdmin);
userSeatPromiseKit.resolve(userSeat);
});

return { zcfSeat, userSeat: userSeatPromiseKit.promise };
},

Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/contracts/multipoolAutoswap/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const makeAddPool = (zcf, isSecondary, initPool, centralBrand) => {
await zcf.saveIssuer(secondaryIssuer, keyword);
assertUsesNatMath(zcf, secondaryBrand);
const liquidityZCFMint = await zcf.makeZCFMint(liquidityKeyword);
const { zcfSeat: poolSeatP } = zcf.makeEmptySeatKit(zcf);
const { zcfSeat: poolSeatP } = zcf.makeEmptySeatKit();
const poolSeat = await poolSeatP;
const pool = makePool(liquidityZCFMint, poolSeat, secondaryBrand);
initPool(secondaryBrand, pool);
Expand Down
9 changes: 5 additions & 4 deletions packages/zoe/src/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* @param {InstanceAdmin} instanceAdmin
* @param {ProposalRecord} proposal
* @param {WeakStore<Brand, ERef<Purse>>} brandToPurse
* @param {ERef<ExitObj>} exitObj
* @param {ERef<OfferResult>=} offerResult
* @param {ERef<ExitObj>=} exitObj
* @returns {ZoeSeatAdminKit}
*
* @typedef {Object} ZoeSeatAdmin
Expand Down Expand Up @@ -122,7 +122,7 @@
* keyword: Keyword
* ) => Promise<void>} saveIssuer
* @property {MakeZoeMint} makeZoeMint
* @property {MakeOfferlessSeat} makeOfferlessSeat
* @property {MakeNoEscrowSeat} makeNoEscrowSeat
* @property {ReplaceAllocations} replaceAllocations
*/

Expand All @@ -134,9 +134,10 @@
*/

/**
* @callback MakeOfferlessSeat
* @callback MakeNoEscrowSeat
* @param {Allocation} initialAllocation
* @param {ProposalRecord} proposal
* @param {ExitObj} exitObj
* @param {SeatHandle} seatHandle
* @returns {ZoeSeatAdminKit}
*/
Expand Down Expand Up @@ -187,7 +188,7 @@
/**
* @callback MakeExitObj
* @param {ProposalRecord} proposal
* @param {ZoeSeatAdmin} zoeSeatAdmin
* @param {ERef<ZoeSeatAdmin>} zoeSeatAdmin
* @param {ZCFSeatAdmin} zcfSeatAdmin
*/

Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
* @property {(brand: Brand) => Issuer} getIssuerForBrand
* @property {GetAmountMath} getAmountMath
* @property {MakeZCFMint} makeZCFMint
* @property {() => ZcfSeatKit} makeEmptySeatKit
* @property {(exit: ExitRule= }) => ZcfSeatKit} makeEmptySeatKit
*/

/**
Expand Down
12 changes: 9 additions & 3 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,19 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
}
return undefined;
})),
// A Seat requested by the contract without an offer
makeOfferlessSeat: (initialAllocation, proposal, seatHandle) => {
// A Seat requested by the contract without any payments to escrow
makeNoEscrowSeat: (
initialAllocation,
proposal,
exitObj,
seatHandle,
) => {
const { userSeat, notifier, zoeSeatAdmin } = makeZoeSeatAdminKit(
initialAllocation,
instanceAdmin,
proposal,
brandToPurse,
exitObj,
);
instanceAdmin.addZoeSeatAdmin(zoeSeatAdmin);
seatHandleToZoeSeatAdmin.init(seatHandle, zoeSeatAdmin);
Expand Down Expand Up @@ -394,8 +400,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
instanceAdmin,
proposal,
brandToPurse,
offerResultPromiseKit.promise,
exitObjPromiseKit.promise,
offerResultPromiseKit.promise,
);

seatHandleToZoeSeatAdmin.init(seatHandle, zoeSeatAdmin);
Expand Down
12 changes: 2 additions & 10 deletions packages/zoe/src/zoeService/zoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ import { objectMap } from '../objArrayConversion';
import '../types';
import '../internal-types';

// Offerless seat case

const defaultExitObj = harden({
exit: () => {
throw new Error(`Offerless seats may not be exited`);
},
});

/**
* makeZoeSeatAdminKit makes an object that manages the state of a seat
* participating in a Zoe contract and return its two facets.
Expand All @@ -35,8 +27,8 @@ export const makeZoeSeatAdminKit = (
instanceAdmin,
proposal,
brandToPurse,
offerResult = undefined,
exitObj = defaultExitObj,
exitObj,
offerResult,
) => {
const payoutPromiseKit = makePromiseKit();
const { notifier, updater } = makeNotifierKit();
Expand Down

0 comments on commit ae303e1

Please sign in to comment.