diff --git a/packages/inter-protocol/src/auction/auctionBook.js b/packages/inter-protocol/src/auction/auctionBook.js index 3ab63294f12..3a617d75128 100644 --- a/packages/inter-protocol/src/auction/auctionBook.js +++ b/packages/inter-protocol/src/auction/auctionBook.js @@ -24,7 +24,11 @@ import { E } from '@endo/captp'; import { observeNotifier } from '@agoric/notifier'; import { makeNatAmountShape } from '../contractSupport.js'; -import { preparePriceBook, prepareScaledBidBook } from './offerBook.js'; +import { + BidsDataNotificationShape, + preparePriceBook, + prepareScaledBidBook, +} from './offerBook.js'; import { isScaledBidPriceHigher, makeBrandedRatioPattern, @@ -123,31 +127,6 @@ export const BookDataNotificationShape = M.splitRecord( ); harden(BookDataNotificationShape); -/** - * @typedef {object} ScaledBidData - * @property {Ratio} bidScaling - * @property {Amount<'nat'>} wanted - * @property {boolean} exitAfterBuy - */ - -/** - * @typedef {object} PricedBidData - * @property {Ratio} price - * @property {Amount<'nat'>} wanted - * @property {boolean} exitAfterBuy - */ - -/** - * @typedef {object} BidDataNotification - * @property {ScaledBidData[]} scaledBids - * @property {PricedBidData[]} pricedBids - */ -export const BidDataNotificationShape = { - scaledBids: M.arrayOf(M.any()), - pricedBids: M.arrayOf(M.any()), -}; -harden(BidDataNotificationShape); - /** * @param {Baggage} baggage * @param {ZCF} zcf @@ -226,10 +205,13 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { BookDataNotificationShape ), ); + + /** @typedef {import('./offerBook.js').BidDataNotification} BidDataNotification */ + const bidsDataKit = makeRecorderKit( bidsNode, /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher} */ ( - BidDataNotificationShape + BidsDataNotificationShape ), ); diff --git a/packages/inter-protocol/src/auction/offerBook.js b/packages/inter-protocol/src/auction/offerBook.js index 0facad2ef58..3a318e4f044 100644 --- a/packages/inter-protocol/src/auction/offerBook.js +++ b/packages/inter-protocol/src/auction/offerBook.js @@ -2,7 +2,7 @@ // discount/markup from the current oracle price. import { E } from '@endo/captp'; -import { AmountMath, BrandShape } from '@agoric/ertp'; +import { AmountMath, BrandShape, AmountShape, RatioShape } from '@agoric/ertp'; import { StorageNodeShape } from '@agoric/internal'; import { M, mustMatch } from '@agoric/store'; import { @@ -12,6 +12,7 @@ import { provide, } from '@agoric/vat-data'; import { makePromiseKit } from '@endo/promise-kit'; +import { TimestampShape } from '@agoric/time'; import { toBidScalingComparator, @@ -78,6 +79,56 @@ const makeGetBidDataRecorder = (bidDataKits, bidDataKitPromises) => { * >} RecorderKit */ +/** + * @typedef {object} ScaledBidData + * @property {Ratio} bidScaling + * @property {Amount<'nat'>} wanted + * @property {boolean} exitAfterBuy + */ + +/** + * @typedef {object} PricedBidData + * @property {Ratio} price + * @property {Amount<'nat'>} wanted + * @property {boolean} exitAfterBuy + */ + +/** + * @typedef {object} BidDataNotification + * @property {ScaledBidData[]} scaledBids + * @property {PricedBidData[]} pricedBids + */ + +export const BidDataNotificationShape = M.or( + { + price: RatioShape, + originalWant: AmountShape, + remainingWant: AmountShape, + exitAfterBuy: M.boolean(), + timestamp: TimestampShape, + balance: AmountShape, + sequence: M.bigint(), + }, + { + bidScaling: RatioShape, + originalWant: AmountShape, + remainingWant: AmountShape, + exitAfterBuy: M.boolean(), + timestamp: TimestampShape, + balance: AmountShape, + sequence: M.bigint(), + }, + // XXX for deletion. Should go away when we can actually delete + M.string(), +); +harden(BidDataNotificationShape); + +export const BidsDataNotificationShape = { + scaledBids: M.arrayOf(BidDataNotificationShape), + pricedBids: M.arrayOf(BidDataNotificationShape), +}; +harden(BidsDataNotificationShape); + /** * Prices in this book are expressed as percentage of the full oracle price * snapshot taken when the auction started. .4 is 60% off. 1.1 is 10% above @@ -134,7 +185,11 @@ export const prepareScaledBidBook = (baggage, makeRecorderKit) => { const bidDataKitP = makePromiseKit(); bidDataKitPromises.init(key, bidDataKitP.promise); E.when(makeBidNode(bidsNode, seqNum), childBidNode => { - const recorderKit = makeRecorderKit(childBidNode); + const recorderKit = makeRecorderKit( + childBidNode, + /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher} */ + (BidDataNotificationShape), + ); bidDataKits.init(key, recorderKit); bidDataKitP.resolve(recorderKit); bidDataKitPromises.delete(key); @@ -281,7 +336,11 @@ export const preparePriceBook = (baggage, makeRecorderKit) => { const bidDataKitP = makePromiseKit(); bidDataKitPromises.init(key, bidDataKitP.promise); E.when(makeBidNode(bidsNode, seqNum), childBidNode => { - const recorderKit = makeRecorderKit(childBidNode); + const recorderKit = makeRecorderKit( + childBidNode, + /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher} */ + (BidDataNotificationShape), + ); bidDataKits.init(key, recorderKit); bidDataKitP.resolve(recorderKit); bidDataKitPromises.delete(key);