From ed21579097d0a964013ab4dc87cd57dce4d7a616 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 27 Jun 2023 10:08:17 -0700 Subject: [PATCH] refactor: each bid written to a separate node --- .../inter-protocol/src/auction/auctionBook.js | 52 +++-- .../inter-protocol/src/auction/auctioneer.js | 14 +- .../inter-protocol/src/auction/offerBook.js | 178 ++++++++++----- .../snapshots/test-auctionContract.js.md | 213 +++++++++--------- .../test/auction/test-auctionBook.js | 57 +---- .../test/auction/test-auctionContract.js | 62 +---- 6 files changed, 270 insertions(+), 306 deletions(-) diff --git a/packages/inter-protocol/src/auction/auctionBook.js b/packages/inter-protocol/src/auction/auctionBook.js index 4b157405d9b..5c5e701ba3a 100644 --- a/packages/inter-protocol/src/auction/auctionBook.js +++ b/packages/inter-protocol/src/auction/auctionBook.js @@ -3,8 +3,8 @@ import '@agoric/zoe/exported.js'; import '@agoric/zoe/src/contracts/exported.js'; import { AmountMath } from '@agoric/ertp'; -import { mustMatch } from '@agoric/store'; -import { M, prepareExoClassKit } from '@agoric/vat-data'; +import { mustMatch, makeScalarMapStore } from '@agoric/store'; +import { M, prepareExoClassKit, provide } from '@agoric/vat-data'; import { assertAllDefined, makeTracer } from '@agoric/internal'; import { @@ -18,6 +18,7 @@ import { } from '@agoric/zoe/src/contractSupport/index.js'; import { E } from '@endo/captp'; import { observeNotifier } from '@agoric/notifier'; +import { ToFarFunction } from '@endo/marshal'; import { makeNatAmountShape } from '../contractSupport.js'; import { preparePriceBook, prepareScaledBidBook } from './offerBook.js'; @@ -106,7 +107,7 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => { * * @property {Ratio} bidScaling * @property {Amount<'nat'>} wanted - * @property {Boolean} exitAfterBuy + * @property {boolean} exitAfterBuy */ /** @@ -114,7 +115,7 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => { * * @property {Ratio} price * @property {Amount<'nat'>} wanted - * @property {Boolean} exitAfterBuy + * @property {boolean} exitAfterBuy */ /** @@ -130,8 +131,11 @@ 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 bidDataKits = provide(baggage, 'bidDataKits', () => + makeScalarMapStore('BidDataKits'), + ); + const makeScaledBidBook = prepareScaledBidBook(baggage, makeRecorderKit); + const makePriceBook = preparePriceBook(baggage, makeRecorderKit); const AuctionBookStateShape = harden({ collateralBrand: M.any(), @@ -143,7 +147,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { priceAuthority: M.any(), updatingOracleQuote: M.any(), bookDataKit: M.any(), - bidDataKit: M.any(), + bidDataKits: M.any(), + bidsDataKit: M.any(), priceBook: M.any(), scaledBidBook: M.any(), startCollateral: M.any(), @@ -161,7 +166,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { * @param {Brand<'nat'>} bidBrand * @param {Brand<'nat'>} collateralBrand * @param {PriceAuthority} pAuthority - * @param {Array} nodes + * @param {Array>} nodes */ (bidBrand, collateralBrand, pAuthority, nodes) => { assertAllDefined({ bidBrand, collateralBrand, pAuthority }); @@ -177,27 +182,35 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { // returned to the funders. const { zcfSeat: collateralSeat } = zcf.makeEmptySeatKit(); const { zcfSeat: bidHoldingSeat } = zcf.makeEmptySeatKit(); + const [scheduleNode, bidsNode] = nodes; const bidAmountShape = makeNatAmountShape(bidBrand); const collateralAmountShape = makeNatAmountShape(collateralBrand); + const makeBidNode = ToFarFunction('makeBidNode', bidId => + E(bidsNode).makeChildNode(`bids${bidId}`), + ); + const scaledBidBook = makeScaledBidBook( makeBrandedRatioPattern(bidAmountShape, bidAmountShape), collateralBrand, + makeBidNode, ); const priceBook = makePriceBook( makeBrandedRatioPattern(bidAmountShape, collateralAmountShape), collateralBrand, + makeBidNode, ); - const [scheduleNode, bidsNode] = nodes; const bookDataKit = makeRecorderKit( + // @ts-expect-error ERef should be acceptable scheduleNode, /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher} */ ( M.any() ), ); - const bidDataKit = makeRecorderKit( + const bidsDataKit = makeRecorderKit( + // @ts-expect-error ERef should be acceptable bidsNode, /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher} */ ( M.any() @@ -216,7 +229,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { updatingOracleQuote: zeroRatio, bookDataKit, - bidDataKit, + bidDataKits, + bidsDataKit, priceBook, scaledBidBook, @@ -479,19 +493,15 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { exitAfterBuy, timestamp, ); - helper.publishBidData(); + void helper.publishBidData(); } void helper.publishBookData(); }, publishBidData() { const { state } = this; - // XXX should this be compressed somewhat? lots of redundant brands. - state.bidDataKit.recorder.write({ - scaledBids: state.scaledBidBook.publishOffers(), - // @ts-expect-error how to convince TS these ratios are non-null? - pricedBids: state.priceBook.publishOffers(), - }); + state.scaledBidBook.publishOffers(); + state.priceBook.publishOffers(); }, publishBookData() { const { state } = this; @@ -511,6 +521,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { collateralAvailable, currentPriceLevel: state.curAuctionPrice, }); + return state.bookDataKit.recorder.write(bookData); }, }, @@ -761,16 +772,13 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => { getDataUpdates() { return this.state.bookDataKit.subscriber; }, - getBidDataUpdates() { - return this.state.bidDataKit.subscriber; - }, getPublicTopics() { return { bookData: makeRecorderTopic( 'Auction schedule', this.state.bookDataKit, ), - bids: makeRecorderTopic('Auction Bids', this.state.bidDataKit), + bids: makeRecorderTopic('Auction Bids', this.state.bidsDataKit), }; }, }, diff --git a/packages/inter-protocol/src/auction/auctioneer.js b/packages/inter-protocol/src/auction/auctioneer.js index 83c62ca5fa8..52b27bb7ece 100644 --- a/packages/inter-protocol/src/auction/auctioneer.js +++ b/packages/inter-protocol/src/auction/auctioneer.js @@ -650,9 +650,6 @@ export const start = async (zcf, privateArgs, baggage) => { getBookDataUpdates(brand) { return books.get(brand).getDataUpdates(); }, - getBidDataUpdates(brand) { - return books.get(brand).getBidDataUpdates(); - }, getPublicTopics(brand) { if (brand) { return books.get(brand).getPublicTopics(); @@ -693,17 +690,16 @@ export const start = async (zcf, privateArgs, baggage) => { const bookId = `book${bookCounter}`; bookCounter += 1; - const bNode = E(privateArgs.storageNode).makeChildNode(bookId); - const nodes = await Promise.all([ - E(bNode).makeChildNode('schedule'), - E(bNode).makeChildNode('bids'), - ]); + + const bookNode = E(privateArgs.storageNode).makeChildNode(bookId); + const scheduleNode = E(bookNode).makeChildNode('schedule'); + const bidsNode = E(bookNode).makeChildNode('bids'); const newBook = await makeAuctionBook( brands.Bid, brand, priceAuthority, - nodes, + [scheduleNode, bidsNode], ); // These three store.init() calls succeed or fail atomically diff --git a/packages/inter-protocol/src/auction/offerBook.js b/packages/inter-protocol/src/auction/offerBook.js index 14b303d6c13..ffa88c3cfb1 100644 --- a/packages/inter-protocol/src/auction/offerBook.js +++ b/packages/inter-protocol/src/auction/offerBook.js @@ -3,7 +3,11 @@ import { AmountMath } from '@agoric/ertp'; import { M, mustMatch } from '@agoric/store'; -import { makeScalarBigMapStore, prepareExoClass } from '@agoric/vat-data'; +import { + makeScalarBigMapStore, + prepareExoClass, + provide, +} from '@agoric/vat-data'; import { toBidScalingComparator, @@ -14,12 +18,11 @@ import { /** @typedef {import('@agoric/vat-data').Baggage} Baggage */ -// multiple offers might be provided at the same time (since the time -// granularity is limited to blocks), so we increment a sequenceNumber with each -// offer for uniqueness. -let latestSequenceNumber = 0n; -const nextSequenceNumber = () => { +/** @type {(baggage: Baggage) => bigint} */ +const nextSequenceNumber = baggage => { + let latestSequenceNumber = provide(baggage, 'sequenceNumber', () => 1000n); latestSequenceNumber += 1n; + baggage.set('sequenceNumber', latestSequenceNumber); return latestSequenceNumber; }; @@ -38,6 +41,7 @@ const ScaledBidBookStateShape = harden({ bidScalingPattern: M.any(), collateralBrand: M.any(), records: M.any(), + makeBidNode: M.any(), }); /** @@ -45,9 +49,16 @@ const ScaledBidBookStateShape = harden({ * snapshot taken when the auction started. .4 is 60% off. 1.1 is 10% above par. * * @param {Baggage} baggage + * @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit */ -export const prepareScaledBidBook = baggage => - prepareExoClass( +export const prepareScaledBidBook = (baggage, makeRecorderKit) => { + // multiple offers might be provided at the same timestamp (since timestamp + // granularity is limited to blocks), so we increment a sequenceNumber with + // each offer for uniqueness. + + const bidDataKits = baggage.get('bidDataKits'); + + return prepareExoClass( baggage, 'scaledBidBook', undefined, @@ -55,12 +66,14 @@ export const prepareScaledBidBook = baggage => * * @param {Pattern} bidScalingPattern * @param {Brand} collateralBrand + * @param {(BigInteger) => Promise} makeBidNode */ - (bidScalingPattern, collateralBrand) => ({ + (bidScalingPattern, collateralBrand, makeBidNode) => ({ bidScalingPattern, collateralBrand, /** @type {MapStore} */ records: makeScalarBigMapStore('scaledBidRecords', { durable: true }), + makeBidNode, }), { /** @@ -71,11 +84,17 @@ export const prepareScaledBidBook = baggage => * @param {Timestamp} timestamp */ add(seat, bidScaling, wanted, exitAfterBuy, timestamp) { - const { bidScalingPattern, collateralBrand, records } = this.state; + const { bidScalingPattern, collateralBrand, records, makeBidNode } = + this.state; mustMatch(bidScaling, bidScalingPattern); - const seqNum = nextSequenceNumber(); + const seqNum = nextSequenceNumber(baggage); const key = toScaledRateOfferKey(bidScaling, seqNum); + + // @ts-expect-error makeRecorderKit accepts ERef + const bidDataKit = makeRecorderKit(makeBidNode(seqNum), M.any()); + bidDataKits.init(key, bidDataKit); + const empty = AmountMath.makeEmpty(collateralBrand); /** @type {BidderRecord} */ const bidderRecord = { @@ -89,6 +108,7 @@ export const prepareScaledBidBook = baggage => timestamp, }; records.init(key, harden(bidderRecord)); + bidDataKits.init(seqNum); return key; }, /** @param {Ratio} bidScaling */ @@ -96,18 +116,26 @@ export const prepareScaledBidBook = baggage => const { records } = this.state; return [...records.entries(M.gte(toBidScalingComparator(bidScaling)))]; }, + publishOffer(record) { + const key = toScaledRateOfferKey(record.bidScaling, record.seqNum); + + bidDataKits.get(key).recorder.write( + harden({ + bidScaling: record.bidScaling, + wanted: record.wanted, + exitAfterBuy: record.exitAfterBuy, + timestamp: record.timestamp, + balance: record.seat.getCurrentAllocation().Bid, + sequence: record.seqNum, + }), + ); + }, publishOffers() { const { records } = this.state; - return [...records.values()].map(r => { - return harden({ - bidScaling: r.bidScaling, - wanted: r.wanted, - exitAfterBuy: r.exitAfterBuy, - timestamp: r.timestamp, - balance: r.seat.getCurrentAllocation().Bid, - sequence: r.seqNum, - }); - }); + + for (const r of records.values()) { + this.self.publishOffer(r); + } }, hasOrders() { const { records } = this.state; @@ -115,24 +143,25 @@ export const prepareScaledBidBook = baggage => }, delete(key) { const { records } = this.state; + bidDataKits.delete(key); records.delete(key); }, updateReceived(key, sold) { const { records } = this.state; const oldRec = records.get(key); - records.set( - key, - harden({ - ...oldRec, - received: AmountMath.add(oldRec.received, sold), - }), - ); + const newRecord = harden({ + ...oldRec, + received: AmountMath.add(oldRec.received, sold), + }); + records.set(key, newRecord); + this.self.publishOffer(newRecord); }, exitAllSeats() { const { records } = this.state; for (const [key, { seat }] of records.entries()) { if (!seat.hasExited()) { seat.exit(); + bidDataKits.delete(key); records.delete(key); } } @@ -142,11 +171,13 @@ export const prepareScaledBidBook = baggage => stateShape: ScaledBidBookStateShape, }, ); +}; const PriceBookStateShape = harden({ priceRatioPattern: M.any(), collateralBrand: M.any(), records: M.any(), + makeBidNode: M.any(), }); /** @@ -154,9 +185,12 @@ const PriceBookStateShape = harden({ * and collateral amount. * * @param {Baggage} baggage + * @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit */ -export const preparePriceBook = baggage => - prepareExoClass( +export const preparePriceBook = (baggage, makeRecorderKit) => { + const bidDataKits = baggage.get('bidDataKits'); + + return prepareExoClass( baggage, 'priceBook', undefined, @@ -164,12 +198,14 @@ export const preparePriceBook = baggage => * * @param {Pattern} priceRatioPattern * @param {Brand} collateralBrand + * @param {(BigInteger) => Promise} makeBidNode */ - (priceRatioPattern, collateralBrand) => ({ + (priceRatioPattern, collateralBrand, makeBidNode) => ({ priceRatioPattern, collateralBrand, /** @type {MapStore} */ records: makeScalarBigMapStore('scaledBidRecords', { durable: true }), + makeBidNode, }), { /** @@ -180,42 +216,58 @@ export const preparePriceBook = baggage => * @param {Timestamp} timestamp */ add(seat, price, wanted, exitAfterBuy, timestamp) { - const { priceRatioPattern, collateralBrand, records } = this.state; + const { priceRatioPattern, collateralBrand, records, makeBidNode } = + this.state; mustMatch(price, priceRatioPattern); - const seqNum = nextSequenceNumber(); + const seqNum = nextSequenceNumber(baggage); const key = toPriceOfferKey(price, seqNum); + + // @ts-expect-error makeRecorderKit accepts ERef + const bidDataKit = makeRecorderKit(makeBidNode(seqNum), M.any()); + bidDataKits.init(key, bidDataKit); + const empty = AmountMath.makeEmpty(collateralBrand); - /** @type {BidderRecord} */ - const bidderRecord = { - bidScaling: undefined, - price, - received: empty, - seat, - seqNum, - wanted, - exitAfterBuy, - timestamp, - }; - records.init(key, harden(bidderRecord)); + records.init( + key, + harden({ + bidScaling: undefined, + price, + received: empty, + seat, + seqNum, + wanted, + exitAfterBuy, + timestamp, + }), + ); + + bidDataKits.init(seqNum); return key; }, offersAbove(price) { const { records } = this.state; return [...records.entries(M.gte(toPartialOfferKey(price)))]; }, + publishOffer(record) { + const key = toPriceOfferKey(record.price, record.seqNum); + + bidDataKits.get(key).recorder.write( + harden({ + price: record.price, + wanted: record.wanted, + exitAfterBuy: record.exitAfterBuy, + timestamp: record.timestamp, + balance: record.seat.getCurrentAllocation().Bid, + sequence: record.seqNum, + }), + ); + }, publishOffers() { const { records } = this.state; - return [...records.values()].map(r => { - return harden({ - price: r.price, - wanted: r.wanted, - exitAfterBuy: r.exitAfterBuy, - timestamp: r.timestamp, - balance: r.seat.getCurrentAllocation().Bid, - sequence: r.seqNum, - }); - }); + for (const r of records.values()) { + this.self.publishOffer(r); + } }, hasOrders() { const { records } = this.state; @@ -223,24 +275,25 @@ export const preparePriceBook = baggage => }, delete(key) { const { records } = this.state; + bidDataKits.delete(key); records.delete(key); }, updateReceived(key, sold) { const { records } = this.state; const oldRec = records.get(key); - records.set( - key, - harden({ - ...oldRec, - received: AmountMath.add(oldRec.received, sold), - }), - ); + const newRecord = harden({ + ...oldRec, + received: AmountMath.add(oldRec.received, sold), + }); + records.set(key, newRecord); + this.self.publishOffer(newRecord); }, exitAllSeats() { const { records } = this.state; for (const [key, { seat }] of records.entries()) { if (!seat.hasExited()) { seat.exit(); + bidDataKits.delete(key); records.delete(key); } } @@ -250,3 +303,4 @@ export const preparePriceBook = baggage => stateShape: PriceBookStateShape, }, ); +}; diff --git a/packages/inter-protocol/test/auction/snapshots/test-auctionContract.js.md b/packages/inter-protocol/test/auction/snapshots/test-auctionContract.js.md index c2fc4da9821..c9eaedc9624 100644 --- a/packages/inter-protocol/test/auction/snapshots/test-auctionContract.js.md +++ b/packages/inter-protocol/test/auction/snapshots/test-auctionContract.js.md @@ -13,116 +13,119 @@ Generated by [AVA](https://avajs.dev). [ [ - 'published.auction.book0.bids', + 'published.auction.book0.bids.bids1001', { - pricedBids: [ - { - balance: { - brand: Object @Alleged: Bid brand {}, - value: 200n, - }, - exitAfterBuy: false, - price: { - denominator: { - brand: Object @Alleged: Collateral brand {}, - value: 250n, - }, - numerator: { - brand: Object @Alleged: Bid brand {}, - value: 200n, - }, - }, - sequence: 2n, - timestamp: { - absValue: 167n, - timerBrand: Object @Alleged: timerBrand {}, - }, - wanted: { - brand: Object @Alleged: Collateral brand {}, - value: 250n, - }, + balance: { + brand: Object @Alleged: Bid brand {}, + value: 134n, + }, + exitAfterBuy: false, + price: { + denominator: { + brand: Object @Alleged: Collateral brand {}, + value: 200n, }, - { - balance: { - brand: Object @Alleged: Bid brand {}, - value: 134n, - }, - exitAfterBuy: false, - price: { - denominator: { - brand: Object @Alleged: Collateral brand {}, - value: 200n, - }, - numerator: { - brand: Object @Alleged: Bid brand {}, - value: 250n, - }, - }, - sequence: 1n, - timestamp: { - absValue: 167n, - timerBrand: Object @Alleged: timerBrand {}, - }, - wanted: { - brand: Object @Alleged: Collateral brand {}, - value: 200n, - }, + numerator: { + brand: Object @Alleged: Bid brand {}, + value: 250n, }, - ], - scaledBids: [ - { - balance: { - brand: Object @Alleged: Bid brand {}, - value: 20n, - }, - bidScaling: { - denominator: { - brand: Object @Alleged: Bid brand {}, - value: 100n, - }, - numerator: { - brand: Object @Alleged: Bid brand {}, - value: 50n, - }, - }, - exitAfterBuy: false, - sequence: 3n, - timestamp: { - absValue: 170n, - timerBrand: Object @Alleged: timerBrand {}, - }, - wanted: { - brand: Object @Alleged: Collateral brand {}, - value: 200n, - }, + }, + sequence: 1001n, + timestamp: { + absValue: 167n, + timerBrand: Object @Alleged: timerBrand {}, + }, + wanted: { + brand: Object @Alleged: Collateral brand {}, + value: 200n, + }, + }, + ], + [ + 'published.auction.book0.bids.bids1002', + { + balance: { + brand: Object @Alleged: Bid brand {}, + value: 200n, + }, + exitAfterBuy: false, + price: { + denominator: { + brand: Object @Alleged: Collateral brand {}, + value: 250n, }, - { - balance: { - brand: Object @Alleged: Bid brand {}, - value: 40n, - }, - bidScaling: { - denominator: { - brand: Object @Alleged: Bid brand {}, - value: 100n, - }, - numerator: { - brand: Object @Alleged: Bid brand {}, - value: 80n, - }, - }, - exitAfterBuy: false, - sequence: 4n, - timestamp: { - absValue: 170n, - timerBrand: Object @Alleged: timerBrand {}, - }, - wanted: { - brand: Object @Alleged: Collateral brand {}, - value: 2000n, - }, + numerator: { + brand: Object @Alleged: Bid brand {}, + value: 200n, }, - ], + }, + sequence: 1002n, + timestamp: { + absValue: 167n, + timerBrand: Object @Alleged: timerBrand {}, + }, + wanted: { + brand: Object @Alleged: Collateral brand {}, + value: 250n, + }, + }, + ], + [ + 'published.auction.book0.bids.bids1003', + { + balance: { + brand: Object @Alleged: Bid brand {}, + value: 20n, + }, + bidScaling: { + denominator: { + brand: Object @Alleged: Bid brand {}, + value: 100n, + }, + numerator: { + brand: Object @Alleged: Bid brand {}, + value: 50n, + }, + }, + exitAfterBuy: false, + sequence: 1003n, + timestamp: { + absValue: 170n, + timerBrand: Object @Alleged: timerBrand {}, + }, + wanted: { + brand: Object @Alleged: Collateral brand {}, + value: 200n, + }, + }, + ], + [ + 'published.auction.book0.bids.bids1004', + { + balance: { + brand: Object @Alleged: Bid brand {}, + value: 40n, + }, + bidScaling: { + denominator: { + brand: Object @Alleged: Bid brand {}, + value: 100n, + }, + numerator: { + brand: Object @Alleged: Bid brand {}, + value: 80n, + }, + }, + exitAfterBuy: false, + sequence: 1004n, + timestamp: { + absValue: 170n, + timerBrand: Object @Alleged: timerBrand {}, + }, + wanted: { + brand: Object @Alleged: Collateral brand {}, + value: 2000n, + }, }, ], [ diff --git a/packages/inter-protocol/test/auction/test-auctionBook.js b/packages/inter-protocol/test/auction/test-auctionBook.js index ba5eedb145d..afc7d9777fc 100644 --- a/packages/inter-protocol/test/auction/test-auctionBook.js +++ b/packages/inter-protocol/test/auction/test-auctionBook.js @@ -14,11 +14,9 @@ import { makeOffer } from '@agoric/zoe/test/unitTests/makeOffer.js'; import { setup } from '@agoric/zoe/test/unitTests/setupBasicMints.js'; import { setupZCFTest } from '@agoric/zoe/test/unitTests/zcf/setupZcfTest.js'; import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js'; -import { subscribeEach } from '@agoric/notifier'; import { makeMockChainStorageRoot } from '../supports.js'; import { prepareAuctionBook } from '../../src/auction/auctionBook.js'; -import { subscriptionTracker } from '../metrics.js'; const buildManualPriceAuthority = initialPrice => makeManualPriceAuthority({ @@ -126,14 +124,6 @@ test('simple addOffer', async t => { ); const { pa, book } = await assembleAuctionBook(basics); pa.setPrice(makeRatioFromAmounts(moola(11n), simoleans(10n))); - const bidTracker = await subscriptionTracker( - t, - subscribeEach(book.getBidDataUpdates()), - ); - await bidTracker.assertInitial({ - pricedBids: [], - scaledBids: [], - }); await eventLoopIteration(); book.addAssets(AmountMath.make(simoleanKit.brand, 123n), donorSeat); @@ -148,19 +138,11 @@ test('simple addOffer', async t => { }), zcfSeat, true, + 0n, ); t.true(book.hasOrders()); book.exitAllSeats(); - await bidTracker.assertChange({ - pricedBids: { - 0: { - price: tenFor100, - exitAfterBuy: false, - wanted: simoleans(50n), - }, - }, - }); t.false(book.hasOrders()); }); @@ -169,14 +151,6 @@ test('getOffers to a price limit', async t => { const basics = await setupBasics(); const { moolaKit, moola, simoleanKit, simoleans, zcf, zoe } = basics; const { pa, book } = await assembleAuctionBook(basics); - const bidTracker = await subscriptionTracker( - t, - subscribeEach(book.getBidDataUpdates()), - ); - await bidTracker.assertInitial({ - pricedBids: [], - scaledBids: [], - }); const donorSeat = await makeSeatWithAssets( zoe, @@ -208,18 +182,10 @@ test('getOffers to a price limit', async t => { }), zcfSeat, true, + 0n, ); t.true(book.hasOrders()); - await bidTracker.assertChange({ - scaledBids: { - 0: { - bidScaling: tenPercent, - exitAfterBuy: false, - wanted: simoleans(50n), - }, - }, - }); book.exitAllSeats(); t.false(book.hasOrders()); @@ -262,6 +228,7 @@ test('Bad keyword', async t => { }), zcfSeat, true, + 0n, ), { message: /give must include "Bid".*/ }, ); @@ -286,14 +253,6 @@ test('getOffers w/discount', async t => { book.captureOraclePriceForRound(); book.setStartingRate(makeRatio(50n, moolaKit.brand, 100n)); - const bidTracker = await subscriptionTracker( - t, - subscribeEach(book.getBidDataUpdates()), - ); - await bidTracker.assertInitial({ - pricedBids: [], - scaledBids: [], - }); const zcfSeat = await makeSeatWithAssets( zoe, @@ -311,16 +270,8 @@ test('getOffers w/discount', async t => { }), zcfSeat, true, + 0n, ); - await bidTracker.assertChange({ - scaledBids: { - 0: { - bidScaling: tenPercent, - exitAfterBuy: false, - wanted: simoleans(50n), - }, - }, - }); t.true(book.hasOrders()); }); diff --git a/packages/inter-protocol/test/auction/test-auctionContract.js b/packages/inter-protocol/test/auction/test-auctionContract.js index 9285f620d8c..53bf706b24a 100644 --- a/packages/inter-protocol/test/auction/test-auctionContract.js +++ b/packages/inter-protocol/test/auction/test-auctionContract.js @@ -320,11 +320,6 @@ const makeAuctionDriver = async (t, params = defaultParams) => { subscriptionTracker(t, subscribeEach(subscription)), ); }, - getBidTracker(brand) { - return E.when(E(publicFacet).getBidDataUpdates(brand), subscription => - subscriptionTracker(t, subscribeEach(subscription)), - ); - }, getReserveBalance(keyword) { const reserveCF = E.get(reserveKit).creatorFacet; return E.get(E(reserveCF).getAllocations())[keyword]; @@ -968,17 +963,17 @@ test.serial('onDeadline exit, with chainStorage RPC snapshot', async t => { t.is(await E(exitingSeat).getOfferResult(), 'Your bid has been accepted'); t.false(await E(exitingSeat).hasExited()); - const pricedSeat = await driver.bidForCollateralSeat( + await driver.bidForCollateralSeat( bid.make(200n), collateral.make(250n), undefined, ); - const discountSeat1 = driver.bidForCollateralSeat( + driver.bidForCollateralSeat( bid.make(20n), collateral.make(200n), makeRatioFromAmounts(bid.make(50n), bid.make(100n)), ); - const discountSeat2 = driver.bidForCollateralSeat( + driver.bidForCollateralSeat( bid.make(40n), collateral.make(2000n), makeRatioFromAmounts(bid.make(80n), bid.make(100n)), @@ -993,6 +988,7 @@ test.serial('onDeadline exit, with chainStorage RPC snapshot', async t => { await driver.advanceTo(170n, 'wait'); await bookTracker.assertChange({}); + await bookTracker.assertChange({}); await bookTracker.assertChange({ collateralAvailable: { value: 0n }, @@ -1009,6 +1005,8 @@ test.serial('onDeadline exit, with chainStorage RPC snapshot', async t => { await scheduleTracker.assertChange({ nextDescendingStepTime: { absValue: 180n }, }); + await bookTracker.assertChange({}); + await bookTracker.assertChange({}); await bookTracker.assertChange({ currentPriceLevel: { numerator: { value: 9_350_000_000_000n } }, }); @@ -1211,10 +1209,6 @@ test.serial('multiple collaterals', async t => { asset, asset.make(500n), ); - const collatBidTracker = await driver.getBidTracker(collateral.brand); - await collatBidTracker.assertInitial({ pricedBids: [], scaledBids: [] }); - const assetBidTracker = await driver.getBidTracker(asset.brand); - await assetBidTracker.assertInitial({ pricedBids: [], scaledBids: [] }); t.is(await E(collatLiqSeat).getOfferResult(), 'deposited'); t.is(await E(assetLiqSeat).getOfferResult(), 'deposited'); @@ -1234,17 +1228,7 @@ test.serial('multiple collaterals', async t => { price, ); t.is(await E(bidderSeat1C).getOfferResult(), 'Your bid has been accepted'); - const timestamp = driver.getTimerService().getCurrentTimestamp(); - collatBidTracker.assertChange({ - pricedBids: { - 0: { - exitAfterBuy: false, - wanted: collateral.make(300n), - price, - timestamp, - }, - }, - }); + driver.getTimerService().getCurrentTimestamp(); // offers up to 500 for 2000 at 1.1 * 75%, so will trigger at second discount step const scale2C = makeRatioFromAmounts(bid.make(75n), bid.make(100n)); @@ -1254,16 +1238,6 @@ test.serial('multiple collaterals', async t => { scale2C, ); t.is(await E(bidderSeat2C).getOfferResult(), 'Your bid has been accepted'); - collatBidTracker.assertChange({ - scaledBids: { - 0: { - exitAfterBuy: false, - wanted: collateral.make(2000n), - bidScaling: scale2C, - timestamp, - }, - }, - }); // offers 50 for 200 at .25 * 50% discount, so triggered at third step const scale1A = makeRatioFromAmounts(bid.make(50n), bid.make(100n)); @@ -1273,16 +1247,6 @@ test.serial('multiple collaterals', async t => { scale1A, ); t.is(await E(bidderSeat1A).getOfferResult(), 'Your bid has been accepted'); - assetBidTracker.assertChange({ - scaledBids: { - 0: { - exitAfterBuy: false, - wanted: asset.make(200n), - bidScaling: scale1A, - timestamp, - }, - }, - }); // offers 100 for 300 at .25 * 33%, so triggered at fourth step const price2A = makeRatioFromAmounts(bid.make(100n), asset.make(1000n)); @@ -1292,16 +1256,6 @@ test.serial('multiple collaterals', async t => { price2A, ); t.is(await E(bidderSeat2A).getOfferResult(), 'Your bid has been accepted'); - assetBidTracker.assertChange({ - pricedBids: { - 0: { - exitAfterBuy: false, - wanted: asset.make(300n), - timestamp, - price: price2A, - }, - }, - }); const schedules = await driver.getSchedule(); t.is(schedules.nextAuctionSchedule?.startTime.absValue, 170n); @@ -1309,8 +1263,6 @@ test.serial('multiple collaterals', async t => { await driver.advanceTo(150n); await driver.advanceTo(170n, 'wait'); await driver.advanceTo(175n); - assetBidTracker.assertChange({}); - collatBidTracker.assertChange({}); t.true(await E(bidderSeat1C).hasExited());