diff --git a/packages/inter-protocol/src/econCommitteeCharter.js b/packages/inter-protocol/src/econCommitteeCharter.js index 05c90553d75..de3b0866cd4 100644 --- a/packages/inter-protocol/src/econCommitteeCharter.js +++ b/packages/inter-protocol/src/econCommitteeCharter.js @@ -24,17 +24,15 @@ export const INVITATION_MAKERS_DESC = 'charter member invitation'; * @property {Record} params * @property {{paramPath: { key: string }}} [path] */ -const ParamChangesOfferArgsShape = harden( - M.split( - { - deadline: TimestampShape, - instance: InstanceHandleShape, - params: M.recordOf(M.string(), M.any()), - }, - M.partial({ - path: { paramPath: { key: M.any() } }, - }), - ), +const ParamChangesOfferArgsShape = M.splitRecord( + { + deadline: TimestampShape, + instance: InstanceHandleShape, + params: M.recordOf(M.string(), M.any()), + }, + { + path: { paramPath: { key: M.any() } }, + }, ); /** diff --git a/packages/inter-protocol/src/stakeFactory/types.js b/packages/inter-protocol/src/stakeFactory/types.js index 4c66aa5d403..5bef7f1b2ac 100644 --- a/packages/inter-protocol/src/stakeFactory/types.js +++ b/packages/inter-protocol/src/stakeFactory/types.js @@ -8,9 +8,9 @@ * @typedef AttestationTool * @property {(amountToLien: Amount<'nat'>) => Promise} makeAttestation * @property {() => Promise} getAccountState + * @property {() => Promise} makeReturnAttInvitation Make an invitation for returning an attestation. * @property {(lienedAmount: Amount<'nat'>) => Amount<'copyBag'>} wrapLienedAmount * @property {(attAmount: Amount<'copyBag'>) => Amount<'nat'>} unwrapLienedAmount - * @property {() => Promise} makeReturnAttInvitation Make an invitation for returning an attestation. */ /** diff --git a/packages/vat-data/src/index.js b/packages/vat-data/src/index.js index 7af54bf663f..4bff2886698 100644 --- a/packages/vat-data/src/index.js +++ b/packages/vat-data/src/index.js @@ -1,6 +1,32 @@ /// -export * from './vat-data-bindings.js'; -export * from './kind-utils.js'; +export { + M, + makeScalarMapStore, + makeScalarWeakMapStore, + makeScalarSetStore, + makeScalarWeakSetStore, +} from '@agoric/store'; +export { + makeKindHandle, + providePromiseWatcher, + watchPromise, + makeScalarBigMapStore, + makeScalarBigWeakMapStore, + makeScalarBigSetStore, + makeScalarBigWeakSetStore, + canBeDurable, + pickFacet, + partialAssign, + provide, + provideDurableMapStore, + provideDurableWeakMapStore, + provideDurableSetStore, + // deprecated + defineKind, + defineKindMulti, + defineDurableKind, + defineDurableKindMulti, +} from './vat-data-bindings.js'; export { defineVirtualExoClass, defineVirtualExoClassKit, @@ -9,7 +35,20 @@ export { prepareExoClass, prepareExoClassKit, prepareExo, + // deorecated prepareSingleton, } from './exo-utils.js'; +/** @typedef {import('./types.js').Baggage} Baggage */ +/** @typedef {import('./types.js').DurableKindHandle} DurableKindHandle */ /** @template T @typedef {import('./types.js').DefineKindOptions} DefineKindOptions */ + +// //////////////////////////// deprecated ///////////////////////////////////// + +export { + // deprecated + ignoreContext, + provideKindHandle, + prepareKind, + prepareKindMulti, +} from './kind-utils.js'; diff --git a/packages/vat-data/src/vat-data-bindings.js b/packages/vat-data/src/vat-data-bindings.js index b375892b054..afc044adfc6 100644 --- a/packages/vat-data/src/vat-data-bindings.js +++ b/packages/vat-data/src/vat-data-bindings.js @@ -1,22 +1,7 @@ /* global globalThis */ import { assert } from '@agoric/assert'; -import { - M, - makeScalarMapStore, - makeScalarWeakMapStore, - makeScalarSetStore, - makeScalarWeakSetStore, - provideLazy, -} from '@agoric/store'; - -export { - M, - makeScalarMapStore, - makeScalarWeakMapStore, - makeScalarSetStore, - makeScalarWeakSetStore, -}; +import { provideLazy } from '@agoric/store'; /** @type {import('./types').VatData} */ let VatDataGlobal; diff --git a/packages/zoe/src/contractFacet/zcfSeat.js b/packages/zoe/src/contractFacet/zcfSeat.js index a3a35f14069..13da3e141b2 100644 --- a/packages/zoe/src/contractFacet/zcfSeat.js +++ b/packages/zoe/src/contractFacet/zcfSeat.js @@ -4,8 +4,8 @@ import { provideDurableMapStore, provideDurableWeakMapStore, prepareExoClassKit, - prepareKind, provide, + prepareExoClass, } from '@agoric/vat-data'; import { E } from '@endo/eventual-send'; import { AmountMath } from '@agoric/ertp'; @@ -17,7 +17,7 @@ import { addToAllocation, subtractFromAllocation } from './allocationMath.js'; import { coerceAmountKeywordRecord } from '../cleanProposal.js'; import { AmountKeywordRecordShape, - ProposalShape, + SeatDataShape, SeatShape, } from '../typeGuards.js'; @@ -135,29 +135,37 @@ export const createSeatManager = ( } }; - const makeZCFSeatInternal = prepareKind( + const ZCFSeatI = M.interface('ZCFSeat', {}, { sloppy: true }); + + const makeZCFSeatInternal = prepareExoClass( zcfBaggage, 'zcfSeat', + ZCFSeatI, proposal => ({ proposal }), { - getSubscriber: ({ self }) => { + getSubscriber() { + const { self } = this; return E(zoeInstanceAdmin).getExitSubscriber( zcfSeatToSeatHandle.get(self), ); }, - getProposal: ({ state }) => state.proposal, - exit: ({ self }, completion) => { + getProposal() { + const { state } = this; + return state.proposal; + }, + exit(completion) { + const { self } = this; assertActive(self); assertNoStagedAllocation(self); doExitSeat(self); E(zoeInstanceAdmin).exitSeat(zcfSeatToSeatHandle.get(self), completion); }, - fail: ( - { self }, + fail( reason = new Error( 'Seat exited with failure. Please check the log for more information.', ), - ) => { + ) { + const { self } = this; if (typeof reason === 'string') { reason = Error(reason); assert.note( @@ -174,9 +182,13 @@ export const createSeatManager = ( } return reason; }, - hasExited: ({ self }) => hasExited(self), + hasExited() { + const { self } = this; + return hasExited(self); + }, - getAmountAllocated: ({ self }, keyword, brand) => { + getAmountAllocated(keyword, brand) { + const { self } = this; assertActive(self); const currentAllocation = getCurrentAllocation(self); if (currentAllocation[keyword] !== undefined) { @@ -189,9 +201,16 @@ export const createSeatManager = ( const assetKind = getAssetKindByBrand(brand); return AmountMath.makeEmpty(brand, assetKind); }, - getCurrentAllocation: ({ self }) => getCurrentAllocation(self), - getStagedAllocation: ({ self }) => getStagedAllocation(self), - isOfferSafe: ({ state, self }, newAllocation) => { + getCurrentAllocation() { + const { self } = this; + return getCurrentAllocation(self); + }, + getStagedAllocation() { + const { self } = this; + return getStagedAllocation(self); + }, + isOfferSafe(newAllocation) { + const { state, self } = this; assertActive(self); const currentAllocation = getCurrentAllocation(self); const reallocation = harden({ @@ -201,7 +220,8 @@ export const createSeatManager = ( return isOfferSafe(state.proposal, reallocation); }, - incrementBy: ({ self }, amountKeywordRecord) => { + incrementBy(amountKeywordRecord) { + const { self } = this; assertActive(self); amountKeywordRecord = coerceAmountKeywordRecord( amountKeywordRecord, @@ -213,7 +233,8 @@ export const createSeatManager = ( ); return amountKeywordRecord; }, - decrementBy: ({ self }, amountKeywordRecord) => { + decrementBy(amountKeywordRecord) { + const { self } = this; assertActive(self); amountKeywordRecord = coerceAmountKeywordRecord( amountKeywordRecord, @@ -228,12 +249,16 @@ export const createSeatManager = ( ); return amountKeywordRecord; }, - clear: ({ self }) => { + clear() { + const { self } = this; if (zcfSeatToStagedAllocations.has(self)) { zcfSeatToStagedAllocations.delete(self); } }, - hasStagedAllocation: ({ self }) => hasStagedAllocation(self), + hasStagedAllocation() { + const { self } = this; + return hasStagedAllocation(self); + }, }, ); @@ -245,14 +270,7 @@ export const createSeatManager = ( const ZcfSeatManagerIKit = harden({ seatManager: M.interface('ZcfSeatManager', { - makeZCFSeat: M.call( - M.partial({ - proposal: ProposalShape, - initialAllocation: AmountKeywordRecordShape, - seatHandle: SeatShape, - offerArgs: M.any(), - }), - ).returns(M.remotable('zcfSeat')), + makeZCFSeat: M.call(SeatDataShape).returns(M.remotable('zcfSeat')), reallocate: M.call(M.remotable('zcfSeat'), M.remotable('zcfSeat')) .rest(M.arrayOf(M.remotable('zcfSeat'))) .returns(), diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 6fa6660a31e..ebe62753850 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -9,7 +9,7 @@ import { makeScalarBigMapStore, provideDurableMapStore, prepareExo, - prepareKind, + prepareExoClass, } from '@agoric/vat-data'; import { cleanProposal } from '../cleanProposal.js'; @@ -27,7 +27,7 @@ import '../internal-types.js'; import './internal-types.js'; import '@agoric/swingset-vat/src/types-ambient.js'; -import { InvitationHandleShape } from '../typeGuards.js'; +import { HandleOfferI, InvitationHandleShape } from '../typeGuards.js'; const { Fail } = assert; @@ -154,12 +154,14 @@ export const makeZCFZygote = async ( // handleOfferObject gives Zoe the ability to notify ZCF when a new seat is // added in offer(). ZCF responds with the exitObj and offerResult. - const makeHandleOfferObj = prepareKind( + const makeHandleOfferObj = prepareExoClass( zcfBaggage, 'handleOfferObj', + HandleOfferI, offerHandlerTaker => ({ offerHandlerTaker }), { - handleOffer: ({ state }, invitationHandle, seatData) => { + handleOffer(invitationHandle, seatData) { + const { state } = this; const zcfSeat = seatManager.makeZCFSeat(seatData); // TODO: provide a details that's a better diagnostic for the // ephemeral offerHandler that did not survive upgrade. diff --git a/packages/zoe/src/contracts/coveredCall-durable.js b/packages/zoe/src/contracts/coveredCall-durable.js index b0d764064e5..0be4288eaa6 100644 --- a/packages/zoe/src/contracts/coveredCall-durable.js +++ b/packages/zoe/src/contracts/coveredCall-durable.js @@ -1,7 +1,7 @@ import { mustMatch, M } from '@agoric/store'; -import { prepareKind, prepareSingleton } from '@agoric/vat-data'; +import { prepareExo, prepareExoClass } from '@agoric/vat-data'; import { swapExact } from '../contractSupport/index.js'; -import { isAfterDeadlineExitRule } from '../typeGuards.js'; +import { isAfterDeadlineExitRule, OfferHandlerI } from '../typeGuards.js'; const { Fail } = assert; @@ -32,12 +32,16 @@ const start = async (zcf, _privateArgs, instanceBaggage) => { // XXX the exerciseOption offer handler that this makes is an object rather // than a function for now only because we do not yet support durable // functions. - const makeExerciser = prepareKind( + const makeExerciser = prepareExoClass( instanceBaggage, 'makeExerciserKindHandle', + OfferHandlerI, sellSeat => ({ sellSeat }), { - handle: ({ state: { sellSeat } }, buySeat) => { + handle(buySeat) { + const { + state: { sellSeat }, + } = this; assert(!sellSeat.hasExited(), sellSeatExpiredMsg); try { swapExact(zcf, sellSeat, buySeat); @@ -78,9 +82,20 @@ const start = async (zcf, _privateArgs, instanceBaggage) => { return zcf.makeInvitation(exerciseOption, 'exerciseOption', customProps); }; - const creatorFacet = prepareSingleton(instanceBaggage, 'creatorFacet', { - makeInvitation: () => zcf.makeInvitation(makeOption, 'makeCallOption'), + const CoveredCallCratorFacetI = M.interface('CoveredCallCratorFacet', { + makeInvitation: M.call().returns(M.promise()), }); + + const creatorFacet = prepareExo( + instanceBaggage, + 'creatorFacet', + CoveredCallCratorFacetI, + { + makeInvitation() { + return zcf.makeInvitation(makeOption, 'makeCallOption'); + }, + }, + ); return harden({ creatorFacet }); }; diff --git a/packages/zoe/src/typeGuards.js b/packages/zoe/src/typeGuards.js index 80844cbad2e..65ab061c033 100644 --- a/packages/zoe/src/typeGuards.js +++ b/packages/zoe/src/typeGuards.js @@ -347,16 +347,21 @@ export const AdminFacetI = M.interface('ZcfAdminFacet', { upgradeContract: M.call(M.string()).optional(M.any()).returns(M.promise()), }); -export const SeatDataShape = harden({ - proposal: ProposalShape, - initialAllocation: AmountKeywordRecordShape, - seatHandle: SeatShape, -}); +export const SeatDataShape = M.splitRecord( + { + proposal: ProposalShape, + initialAllocation: AmountKeywordRecordShape, + seatHandle: SeatShape, + }, + { + offerArgs: M.any(), + }, +); export const HandleOfferI = M.interface('HandleOffer', { handleOffer: M.call(InvitationHandleShape, SeatDataShape).returns({ offerResultPromise: M.promise(), - exitObj: ExitObjectI, + exitObj: ExitObjectShape, }), }); diff --git a/packages/zoe/src/zoeService/feeMint.js b/packages/zoe/src/zoeService/feeMint.js index 97d3beaa9ad..7090845d403 100644 --- a/packages/zoe/src/zoeService/feeMint.js +++ b/packages/zoe/src/zoeService/feeMint.js @@ -2,12 +2,14 @@ import { makeDurableIssuerKit, AssetKind, prepareIssuerKit, + IssuerShape, + BrandShape, } from '@agoric/ertp'; -import { initEmpty } from '@agoric/store'; +import { initEmpty, M } from '@agoric/store'; import { - prepareKindMulti, provideDurableMapStore, provide, + prepareExoClassKit, } from '@agoric/vat-data'; const FEE_MINT_KIT = 'FeeMintKit'; @@ -41,24 +43,42 @@ const prepareFeeMint = (zoeBaggage, feeIssuerConfig, shutdownZoeVat) => { prepareIssuerKit(mintBaggage, shutdownZoeVat); } - const getFeeIssuerKit = ({ facets }, allegedFeeMintAccess) => { - assert( - facets.feeMintAccess === allegedFeeMintAccess, - 'The object representing access to the fee brand mint was not provided', - ); - return mintBaggage.get(FEE_MINT_KIT); - }; + const FeeMintIKit = harden({ + feeMint: M.interface('FeeMint', { + getFeeIssuerKit: M.call(M.remotable('FeeMintAccess')).returns(M.record()), + getFeeIssuer: M.call().returns(IssuerShape), + getFeeBrand: M.call().returns(BrandShape), + }), + feeMintAccess: M.interface('FeeMintAccess', {}), + }); - const makeFeeMintKit = prepareKindMulti(mintBaggage, 'FeeMint', initEmpty, { - feeMint: { - getFeeIssuerKit, - getFeeIssuer: () => mintBaggage.get(FEE_MINT_KIT).issuer, - getFeeBrand: () => mintBaggage.get(FEE_MINT_KIT).brand, + const makeFeeMintKit = prepareExoClassKit( + mintBaggage, + 'FeeMint', + FeeMintIKit, + initEmpty, + { + feeMint: { + getFeeIssuerKit(allegedFeeMintAccess) { + const { facets } = this; + assert( + facets.feeMintAccess === allegedFeeMintAccess, + 'The object representing access to the fee brand mint was not provided', + ); + return mintBaggage.get(FEE_MINT_KIT); + }, + getFeeIssuer() { + return mintBaggage.get(FEE_MINT_KIT).issuer; + }, + getFeeBrand() { + return mintBaggage.get(FEE_MINT_KIT).brand; + }, + }, + // feeMintAccess is an opaque durable object representing the right to get + // the fee mint. + feeMintAccess: {}, }, - // feeMintAccess is an opaque durable object representing the right to get - // the fee mint. - feeMintAccess: {}, - }); + ); return provide(zoeBaggage, 'theFeeMint', () => makeFeeMintKit()); };