Skip to content

Commit

Permalink
feat: use a sub-baggage for each auctionBook
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 4, 2024
1 parent a12a965 commit b68ac12
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Fail } from '@endo/errors';
import { E } from '@endo/captp';
import { AmountMath, RatioShape } from '@agoric/ertp';
import { mustMatch } from '@agoric/store';
import { M, prepareExoClassKit } from '@agoric/vat-data';
import {
M,
prepareExoClassKit,
provideDurableMapStore,
} from '@agoric/vat-data';

import { assertAllDefined, makeTracer } from '@agoric/internal';
import {
Expand Down Expand Up @@ -117,8 +121,9 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => {
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
*/
export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
const makeScaledBidBook = prepareScaledBidBook(baggage);
const makePriceBook = preparePriceBook(baggage);
const subBaggage = provideDurableMapStore(baggage, 'bookBaggage');
const makeScaledBidBook = prepareScaledBidBook(subBaggage);
const makePriceBook = preparePriceBook(subBaggage);

const AuctionBookStateShape = harden({
collateralBrand: M.any(),
Expand All @@ -140,7 +145,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
});

const makeAuctionBookKit = prepareExoClassKit(
baggage,
subBaggage,
'AuctionBook',
undefined,
/**
Expand Down Expand Up @@ -462,10 +467,10 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
const { state, facets } = this;
const { collateralBrand, bidBrand, priceAuthority } = state;

if (baggage.has(QUOTE_NOTIFIER)) {
if (subBaggage.has(QUOTE_NOTIFIER)) {
return;
}
baggage.set(QUOTE_NOTIFIER, true);
subBaggage.set(QUOTE_NOTIFIER, true);
trace('observing');

const quoteNotifierP = E(priceAuthority).makeQuoteNotifier(
Expand All @@ -491,21 +496,21 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
);
// lack of quote will trigger restart
state.updatingOracleQuote = null;
baggage.delete(QUOTE_NOTIFIER);
subbaggage.delete(QUOTE_NOTIFIER);
},
finish: done => {
trace(
`quoteNotifier invoked finish(${done}). setting quote to null`,
);
// lack of quote will trigger restart
state.updatingOracleQuote = null;
baggage.delete(QUOTE_NOTIFIER);
subbaggage.delete(QUOTE_NOTIFIER);
},
}),
e => {
trace('makeQuoteNotifier failed, resetting', e);
state.updatingOracleQuote = null;
baggage.delete(QUOTE_NOTIFIER);
subbaggage.delete(QUOTE_NOTIFIER);
},
);

Expand Down

0 comments on commit b68ac12

Please sign in to comment.