Skip to content

Commit

Permalink
fix: Make the auction schedule robust when adding collateral types
Browse files Browse the repository at this point in the history
fixes: 8296
  • Loading branch information
Chris-Hibbert committed Sep 2, 2023
1 parent 52bc8ec commit c350319
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,12 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {

trace(this.state.collateralBrand, 'settleAtNewRate', reduction);
const { capturedPriceForRound, priceBook, scaledBidBook } = state;
capturedPriceForRound !== null ||
Fail`price must be captured before auction starts`;
assert(capturedPriceForRound);
if (!capturedPriceForRound) {
console.warn(
`No price for ${this.state.collateralBrand}, skipping auction.`,
);
return;
}

state.curAuctionPrice = multiplyRatios(
reduction,
Expand Down
47 changes: 47 additions & 0 deletions packages/inter-protocol/test/auction/test-auctionContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,3 +1408,50 @@ test.serial('time jumps forward', async t => {
t.is(schedules.liveAuctionSchedule?.startTime.absValue, 1530n);
t.is(schedules.liveAuctionSchedule?.endTime.absValue, 1550n);
});

// serial because dynamicConfig is shared across tests
test.serial('add collateral type during auction', async t => {
const { collateral, bid } = t.context;
const driver = await makeAuctionDriver(t);
const asset = withAmountUtils(makeIssuerKit('Asset'));

const liqSeat = await driver.setupCollateralAuction(
collateral,
collateral.make(1000n),
);
await driver.updatePriceAuthority(
makeRatioFromAmounts(bid.make(11n), collateral.make(10n)),
);

const result = await E(liqSeat).getOfferResult();
t.is(result, 'deposited');

await driver.advanceTo(167n);
const seat = await driver.bidForCollateralSeat(
// 1.1 * 1.05 * 200
bid.make(231n),
collateral.make(200n),
);
t.is(await E(seat).getOfferResult(), 'Your bid has been accepted');
t.false(await E(seat).hasExited());

await driver.advanceTo(170n, 'wait');
await driver.advanceTo(175n, 'wait');

// before the fix for #8296, this broke the ongoing auction.
const assetLiqSeat = await driver.setupCollateralAuction(

Check failure on line 1442 in packages/inter-protocol/test/auction/test-auctionContract.js

View workflow job for this annotation

GitHub Actions / lint-primary

'assetLiqSeat' is assigned a value but never used. Allowed unused vars must match /^_/u
asset,
asset.make(500n),
);

await driver.advanceTo(180n, 'wait');
await driver.advanceTo(185n, 'wait');

t.true(await E(seat).hasExited());

await assertPayouts(t, seat, bid, collateral, 0n, 200n);
t.false(await E(liqSeat).hasExited());
await E(liqSeat).tryExit();

await assertPayouts(t, liqSeat, bid, collateral, 0n, 0n);
});

0 comments on commit c350319

Please sign in to comment.