From ae303e1d15ee467876f708d8d91b6cd7d5d4e640 Mon Sep 17 00:00:00 2001 From: Kate Sills Date: Wed, 26 Aug 2020 20:27:37 -0700 Subject: [PATCH] feat: add want, exit to empty seat (#1584) --- .../zoe/src/contractFacet/contractFacet.js | 28 ++++++++++++------- .../src/contracts/multipoolAutoswap/pool.js | 2 +- packages/zoe/src/internal-types.js | 9 +++--- packages/zoe/src/types.js | 2 +- packages/zoe/src/zoeService/zoe.js | 12 ++++++-- packages/zoe/src/zoeService/zoeSeat.js | 12 ++------ 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/packages/zoe/src/contractFacet/contractFacet.js b/packages/zoe/src/contractFacet/contractFacet.js index 4fc2b5cd483..64f6e71d84c 100644 --- a/packages/zoe/src/contractFacet/contractFacet.js +++ b/packages/zoe/src/contractFacet/contractFacet.js @@ -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} */ 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, @@ -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 }; }, diff --git a/packages/zoe/src/contracts/multipoolAutoswap/pool.js b/packages/zoe/src/contracts/multipoolAutoswap/pool.js index 33ec0c7aebf..1808eab6b38 100644 --- a/packages/zoe/src/contracts/multipoolAutoswap/pool.js +++ b/packages/zoe/src/contracts/multipoolAutoswap/pool.js @@ -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); diff --git a/packages/zoe/src/internal-types.js b/packages/zoe/src/internal-types.js index ca6be3a8d8f..fd4e2d79f89 100644 --- a/packages/zoe/src/internal-types.js +++ b/packages/zoe/src/internal-types.js @@ -37,8 +37,8 @@ * @param {InstanceAdmin} instanceAdmin * @param {ProposalRecord} proposal * @param {WeakStore>} brandToPurse + * @param {ERef} exitObj * @param {ERef=} offerResult - * @param {ERef=} exitObj * @returns {ZoeSeatAdminKit} * * @typedef {Object} ZoeSeatAdmin @@ -122,7 +122,7 @@ * keyword: Keyword * ) => Promise} saveIssuer * @property {MakeZoeMint} makeZoeMint - * @property {MakeOfferlessSeat} makeOfferlessSeat + * @property {MakeNoEscrowSeat} makeNoEscrowSeat * @property {ReplaceAllocations} replaceAllocations */ @@ -134,9 +134,10 @@ */ /** - * @callback MakeOfferlessSeat + * @callback MakeNoEscrowSeat * @param {Allocation} initialAllocation * @param {ProposalRecord} proposal + * @param {ExitObj} exitObj * @param {SeatHandle} seatHandle * @returns {ZoeSeatAdminKit} */ @@ -187,7 +188,7 @@ /** * @callback MakeExitObj * @param {ProposalRecord} proposal - * @param {ZoeSeatAdmin} zoeSeatAdmin + * @param {ERef} zoeSeatAdmin * @param {ZCFSeatAdmin} zcfSeatAdmin */ diff --git a/packages/zoe/src/types.js b/packages/zoe/src/types.js index b45e3c13bcb..dd85386402b 100644 --- a/packages/zoe/src/types.js +++ b/packages/zoe/src/types.js @@ -208,7 +208,7 @@ * @property {(brand: Brand) => Issuer} getIssuerForBrand * @property {GetAmountMath} getAmountMath * @property {MakeZCFMint} makeZCFMint - * @property {() => ZcfSeatKit} makeEmptySeatKit + * @property {(exit: ExitRule= }) => ZcfSeatKit} makeEmptySeatKit */ /** diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index 7f35fe90c1b..53217ed8a99 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -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); @@ -394,8 +400,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) { instanceAdmin, proposal, brandToPurse, - offerResultPromiseKit.promise, exitObjPromiseKit.promise, + offerResultPromiseKit.promise, ); seatHandleToZoeSeatAdmin.init(seatHandle, zoeSeatAdmin); diff --git a/packages/zoe/src/zoeService/zoeSeat.js b/packages/zoe/src/zoeService/zoeSeat.js index 5e499675e1e..f00c872cfa4 100644 --- a/packages/zoe/src/zoeService/zoeSeat.js +++ b/packages/zoe/src/zoeService/zoeSeat.js @@ -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. @@ -35,8 +27,8 @@ export const makeZoeSeatAdminKit = ( instanceAdmin, proposal, brandToPurse, - offerResult = undefined, - exitObj = defaultExitObj, + exitObj, + offerResult, ) => { const payoutPromiseKit = makePromiseKit(); const { notifier, updater } = makeNotifierKit();