Skip to content

Commit

Permalink
refactor: add type to bid record kit; move type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jul 24, 2023
1 parent 45fe766 commit ec9fcec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
34 changes: 8 additions & 26 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
BidDataNotificationShape,
preparePriceBook,
prepareScaledBidBook,
} from './offerBook.js';
import {
isScaledBidPriceHigher,
makeBrandedRatioPattern,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -226,6 +205,9 @@ 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<BidDataNotification>} */ (
Expand Down
32 changes: 31 additions & 1 deletion packages/inter-protocol/src/auction/offerBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ 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 = {
scaledBids: M.arrayOf(M.any()),
pricedBids: M.arrayOf(M.any()),
};
harden(BidDataNotificationShape);

/**
* 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
Expand Down Expand Up @@ -134,7 +160,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<BidDataNotification>} */
(BidDataNotificationShape),
);
bidDataKits.init(key, recorderKit);
bidDataKitP.resolve(recorderKit);
bidDataKitPromises.delete(key);
Expand Down

0 comments on commit ec9fcec

Please sign in to comment.