diff --git a/packages/inter-protocol/src/auction/auctionBook.js b/packages/inter-protocol/src/auction/auctionBook.js index 508f15840d6..6af7805c275 100644 --- a/packages/inter-protocol/src/auction/auctionBook.js +++ b/packages/inter-protocol/src/auction/auctionBook.js @@ -59,6 +59,29 @@ const trace = makeTracer('AucBook', false); * offerBidScaling: Ratio, * })} BidSpec */ +/** + * + * @param {Brand<'nat'>} currencyBrand + * @param {Brand<'nat'>} collateralBrand + */ +export const makeBidSpecShape = (currencyBrand, collateralBrand) => { + const currencyAmountShape = { brand: currencyBrand, value: M.nat() }; + const collateralAmountShape = { brand: collateralBrand, value: M.nat() }; + return M.splitRecord( + { want: collateralAmountShape }, + { + // xxx should have exactly one of these properties + offerPrice: makeBrandedRatioPattern( + currencyAmountShape, + collateralAmountShape, + ), + offerBidScaling: makeBrandedRatioPattern( + currencyAmountShape, + currencyAmountShape, + ), + }, + ); +}; /** @typedef {import('@agoric/vat-data').Baggage} Baggage */ @@ -145,6 +168,7 @@ export const makeAuctionBook = async ( let curAuctionPrice = zeroRatio; + // FIXME the maker callbacks return a non-durable object const scaledBidBook = provide(baggage, 'scaledBidBook', () => { const ratioPattern = makeBrandedRatioPattern( currencyAmountShape, diff --git a/packages/inter-protocol/src/auction/auctioneer.js b/packages/inter-protocol/src/auction/auctioneer.js index 06332a6daaf..955f7d9c69a 100644 --- a/packages/inter-protocol/src/auction/auctioneer.js +++ b/packages/inter-protocol/src/auction/auctioneer.js @@ -23,7 +23,7 @@ import { makeTracer, BASIS_POINTS } from '@agoric/internal'; import { FullProposalShape } from '@agoric/zoe/src/typeGuards.js'; import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js'; import { mustMatch } from '@agoric/store'; -import { makeAuctionBook } from './auctionBook.js'; +import { makeAuctionBook, makeBidSpecShape } from './auctionBook.js'; import { AuctionState } from './util.js'; import { makeScheduler } from './scheduler.js'; import { auctioneerParamTypes } from './params.js'; @@ -268,6 +268,16 @@ export const start = async (zcf, privateArgs, baggage) => { M.splitRecord({ give: { Collateral: AmountShape } }), ); + const bidProposalShape = M.splitRecord( + { + give: { Currency: { brand: brands.Currency, value: M.nat() } }, + }, + { + want: M.or({ Collateral: AmountShape }, {}), + exit: FullProposalShape.exit, + }, + ); + const publicFacet = augmentPublicFacet( harden({ /** @param {Brand<'nat'>} collateralBrand */ @@ -275,24 +285,18 @@ export const start = async (zcf, privateArgs, baggage) => { mustMatch(collateralBrand, BrandShape); books.has(collateralBrand) || Fail`No book for brand ${collateralBrand}`; + const bidSpecShape = makeBidSpecShape(brands.Currency, collateralBrand); /** * @param {ZCFSeat} zcfSeat * @param {import('./auctionBook.js').BidSpec} bidSpec */ const newBidHandler = (zcfSeat, bidSpec) => { + // xxx consider having Zoe guard the offerArgs with a provided shape + mustMatch(bidSpec, bidSpecShape); const auctionBook = books.get(collateralBrand); auctionBook.addOffer(bidSpec, zcfSeat, isActive()); return 'Your offer has been received'; }; - const bidProposalShape = M.splitRecord( - { - give: { Currency: { brand: brands.Currency, value: M.nat() } }, - }, - { - want: M.or({ Collateral: AmountShape }, {}), - exit: FullProposalShape.exit, - }, - ); return zcf.makeInvitation( newBidHandler,