Skip to content

Commit

Permalink
chore(auction): shapes for recorders
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg authored and Chris-Hibbert committed Jul 13, 2023
1 parent 6d1bd7f commit 7dc1a87
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 20 additions & 3 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '@agoric/governance/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';

import { AmountMath } from '@agoric/ertp';
import { AmountMath, AmountShape, RatioShape } from '@agoric/ertp';
import { mustMatch } from '@agoric/store';
import {
M,
Expand Down Expand Up @@ -104,6 +104,18 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => {
* added in.)
* @property {Amount<'nat'> | null} collateralAvailable The amount of collateral remaining
*/
export const BookDataNotificationShape = M.splitRecord(
{
startPrice: M.or(RatioShape, null),
currentPriceLevel: M.or(RatioShape, null),
startCollateral: AmountShape,
collateralAvailable: M.or(AmountShape, null),
},
{
proceedsRaised: AmountShape,
},
);
harden(BookDataNotificationShape);

/**
* @typedef {object} ScaledBidData
Expand All @@ -127,6 +139,11 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => {
* @property {Array<ScaledBidData>} scaledBids
* @property {Array<PricedBidData>} pricedBids
*/
export const BidDataNotificationShape = {
scaledBids: M.arrayOf(M.any()),
pricedBids: M.arrayOf(M.any()),
};
harden(BidDataNotificationShape);

/**
* @param {Baggage} baggage
Expand Down Expand Up @@ -203,13 +220,13 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
const bookDataKit = makeRecorderKit(
bookNode,
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<BookDataNotification>} */ (
M.any()
BookDataNotificationShape
),
);
const bidsDataKit = makeRecorderKit(
bidsNode,
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<BidDataNotification>} */ (
M.any()
BidDataNotificationShape
),
);

Expand Down
6 changes: 3 additions & 3 deletions packages/inter-protocol/src/auction/auctioneer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
makeRatioFromAmounts,
makeRecorderTopic,
natSafeMath,
offerTo,
prepareRecorder,
provideEmptySeat,
offerTo,
} from '@agoric/zoe/src/contractSupport/index.js';
import { FullProposalShape } from '@agoric/zoe/src/typeGuards.js';
import { E } from '@endo/eventual-send';
Expand All @@ -32,7 +32,7 @@ import { Far } from '@endo/marshal';
import { makeNatAmountShape } from '../contractSupport.js';
import { makeOfferSpecShape, prepareAuctionBook } from './auctionBook.js';
import { auctioneerParamTypes } from './params.js';
import { makeScheduler } from './scheduler.js';
import { makeScheduler, ScheduleNotificationShape } from './scheduler.js';
import { AuctionState } from './util.js';

/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
Expand Down Expand Up @@ -428,7 +428,7 @@ export const start = async (zcf, privateArgs, baggage) => {
const scheduleKit = makeERecorderKit(
E(privateArgs.storageNode).makeChildNode('schedule'),
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<import('./scheduler.js').ScheduleNotification>} */ (
M.any()
ScheduleNotificationShape
),
);

Expand Down
9 changes: 8 additions & 1 deletion packages/inter-protocol/src/auction/scheduler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { E } from '@endo/eventual-send';
import { TimeMath } from '@agoric/time';
import { TimeMath, TimestampShape } from '@agoric/time';
import { Far } from '@endo/marshal';
import { makeTracer } from '@agoric/internal';
import { observeIteration, subscribeEach } from '@agoric/notifier';

import { M } from '@agoric/store';
import { AuctionState, makeCancelTokenMaker } from './util.js';
import {
computeRoundTiming,
Expand Down Expand Up @@ -56,6 +57,12 @@ const makeCancelToken = makeCancelTokenMaker('scheduler');
* @property {Timestamp | null} nextDescendingStepTime when the next descending step
* will take place
*/
export const ScheduleNotificationShape = {
activeStartTime: M.or(null, TimestampShape),
nextStartTime: M.or(null, TimestampShape),
nextDescendingStepTime: M.or(null, TimestampShape),
};
harden(ScheduleNotificationShape);

const safelyComputeRoundTiming = (params, baseTime) => {
try {
Expand Down

0 comments on commit 7dc1a87

Please sign in to comment.