-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Make the auction schedule robust when adding collateral types #8301
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fad96bb
fix: Make the auction schedule robust when adding collateral types
Chris-Hibbert 59a5370
refactor: clean up timestamp await, and add test.
Chris-Hibbert 88083f9
chore: make error message more visible when quote is missing
Chris-Hibbert cb813c2
test: drop skipped test, included for review purposes
Chris-Hibbert b009af1
Merge branch 'master' into 8296-auctionFix
Chris-Hibbert e43c818
chore: restore ts-expect-error that is still needed
Chris-Hibbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import { assertPayoutAmount } from '@agoric/zoe/test/zoeTestHelpers.js'; | |
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js'; | ||
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js'; | ||
import { E } from '@endo/eventual-send'; | ||
import { NonNullish } from '@agoric/assert'; | ||
|
||
import { | ||
setupReserve, | ||
|
@@ -110,6 +111,11 @@ export const setupServices = async (t, params = defaultParams) => { | |
const space = await setupBootstrap(t, timer); | ||
installPuppetGovernance(zoe, space.installation.produce); | ||
|
||
t.context.puppetGovernors = { | ||
auctioneer: E.get(space.consume.auctioneerKit).governorCreatorFacet, | ||
vaultFactory: E.get(space.consume.vaultFactoryKit).governorCreatorFacet, | ||
}; | ||
|
||
// @ts-expect-error not all installs are needed for auctioneer. | ||
produceInstallations(space, t.context.installs); | ||
|
||
|
@@ -309,6 +315,15 @@ const makeAuctionDriver = async (t, params = defaultParams) => { | |
await eventLoopIteration(); | ||
} | ||
}, | ||
|
||
setGovernedParam: (name, newValue) => { | ||
trace(t, 'setGovernedParam', name); | ||
const auctionGov = NonNullish(t.context.puppetGovernors.auctioneer); | ||
return E(auctionGov).changeParams( | ||
harden({ changes: { [name]: newValue } }), | ||
); | ||
}, | ||
|
||
async updatePriceAuthority(newPrice) { | ||
priceAuthorities.get(newPrice.denominator.brand).setPrice(newPrice); | ||
await eventLoopIteration(); | ||
|
@@ -1408,3 +1423,153 @@ 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 timerBrand = await E(driver.getTimerService()).getTimerBrand(); | ||
|
||
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()); | ||
|
||
const scheduleTracker = await driver.getScheduleTracker(); | ||
await scheduleTracker.assertInitial({ | ||
activeStartTime: TimeMath.coerceTimestampRecord(170n, timerBrand), | ||
nextDescendingStepTime: TimeMath.coerceTimestampRecord(170n, timerBrand), | ||
nextStartTime: TimeMath.coerceTimestampRecord(210n, timerBrand), | ||
}); | ||
|
||
await driver.advanceTo(170n, 'wait'); | ||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 175n }, | ||
}); | ||
|
||
await driver.advanceTo(175n, 'wait'); | ||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 180n }, | ||
}); | ||
|
||
// before the fix for #8296 in AuctionBook, this broke the ongoing auction. | ||
await driver.setupCollateralAuction(asset, asset.make(500n)); | ||
|
||
await driver.advanceTo(180n, 'wait'); | ||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 185n }, | ||
}); | ||
|
||
await driver.advanceTo(185n, 'wait'); | ||
|
||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 190n }, | ||
}); | ||
|
||
t.true(await E(seat).hasExited()); | ||
await assertPayouts(t, seat, bid, collateral, 0n, 200n); | ||
|
||
await driver.advanceTo(210n, 'wait'); | ||
|
||
t.true(await E(liqSeat).hasExited()); | ||
await assertPayouts(t, liqSeat, bid, collateral, 231n, 800n); | ||
|
||
await scheduleTracker.assertChange({ | ||
activeStartTime: null, | ||
nextDescendingStepTime: { absValue: 210n }, | ||
}); | ||
}); | ||
|
||
// serial because dynamicConfig is shared across tests | ||
// This test reproduces bug #8296. Now its expectations don't match the behavior | ||
test.serial.skip( | ||
'late priceAuthority breaks auction; cannot recover via governance', | ||
async t => { | ||
const { collateral, bid } = t.context; | ||
const driver = await makeAuctionDriver(t); | ||
const asset = withAmountUtils(makeIssuerKit('Asset')); | ||
const timerBrand = await E(driver.getTimerService()).getTimerBrand(); | ||
|
||
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()); | ||
|
||
const scheduleTracker = await driver.getScheduleTracker(); | ||
await scheduleTracker.assertInitial({ | ||
activeStartTime: TimeMath.coerceTimestampRecord(170n, timerBrand), | ||
nextDescendingStepTime: TimeMath.coerceTimestampRecord(170n, timerBrand), | ||
nextStartTime: TimeMath.coerceTimestampRecord(210n, timerBrand), | ||
}); | ||
|
||
await driver.advanceTo(170n, 'wait'); | ||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 175n }, | ||
}); | ||
|
||
await driver.advanceTo(175n, 'wait'); | ||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 180n }, | ||
}); | ||
|
||
// before the fix for #8296 in AuctionBook, this broke the ongoing auction. | ||
await driver.setupCollateralAuction(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); | ||
|
||
await driver.advanceTo(210n, 'wait'); | ||
await driver.advanceTo(220n, 'wait'); | ||
await driver.advanceTo(250n, 'wait'); | ||
|
||
// before the fix for #8296 in scheduler, this didn't repair the problem. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK |
||
driver.setGovernedParam('DiscountStep', 2000n); | ||
|
||
await driver.advanceTo(300n, 'wait'); | ||
|
||
await scheduleTracker.assertChange({ | ||
nextDescendingStepTime: { absValue: 330n }, | ||
nextStartTime: { absValue: 330n }, | ||
}); | ||
|
||
await driver.advanceTo(330n, 'wait'); | ||
}, | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from throw to warn… is it not an error to start the auction without a price feed?
agoric-sdk/packages/inter-protocol/src/vaultFactory/vaultManager.js
Lines 749 to 751 in fb2e7f5
maybe not. I suppose we have decided it is part of the spec that the auction skips if there's no feed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an error, but it should only affect the auction for that collateral. Throwing is an over-reaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly throwing is an over-reaction. My question was about how to log.
Then should it be
console.error
? Consider also⚠️
in the message to draw attention to it in log output. I think "🚨" would be too severe as this is a known possible state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with error, though I haven't seen any evidence that it increases visibility.
I had intended to add a glyph, but forgot. Thanks for the reminder.