@agoric/inter-protocol 0.16.2-other-dev-8f8782b.0 → 0.16.2-other-dev-fbe72e7.0.fbe72e7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/package.json +46 -39
- package/scripts/build-bundles.js +5 -21
- package/src/auction/auctionBook.d.ts +147 -0
- package/src/auction/auctionBook.d.ts.map +1 -0
- package/src/auction/auctionBook.js +182 -151
- package/src/auction/auctionMath.d.ts +17 -0
- package/src/auction/auctionMath.d.ts.map +1 -0
- package/src/auction/auctionMath.js +81 -0
- package/src/auction/auctioneer.d.ts +70 -0
- package/src/auction/auctioneer.d.ts.map +1 -0
- package/src/auction/auctioneer.js +72 -59
- package/src/auction/offerBook.d.ts +46 -0
- package/src/auction/offerBook.d.ts.map +1 -0
- package/src/auction/offerBook.js +17 -12
- package/src/auction/params.d.ts +145 -0
- package/src/auction/params.d.ts.map +1 -0
- package/src/auction/params.js +11 -9
- package/src/auction/scheduleMath.d.ts +5 -0
- package/src/auction/scheduleMath.d.ts.map +1 -0
- package/src/auction/scheduleMath.js +18 -16
- package/src/auction/scheduler.d.ts +50 -0
- package/src/auction/scheduler.d.ts.map +1 -0
- package/src/auction/scheduler.js +53 -47
- package/src/auction/sortedOffers.d.ts +8 -0
- package/src/auction/sortedOffers.d.ts.map +1 -0
- package/src/auction/sortedOffers.js +10 -9
- package/src/auction/util.d.ts +31 -0
- package/src/auction/util.d.ts.map +1 -0
- package/src/auction/util.js +12 -6
- package/src/clientSupport.d.ts +168 -0
- package/src/clientSupport.d.ts.map +1 -0
- package/src/clientSupport.js +161 -98
- package/src/collectFees.d.ts +2 -0
- package/src/collectFees.d.ts.map +1 -0
- package/src/contractSupport.d.ts +28 -0
- package/src/contractSupport.d.ts.map +1 -0
- package/src/contractSupport.js +19 -13
- package/src/econCommitteeCharter.d.ts +43 -0
- package/src/econCommitteeCharter.d.ts.map +1 -0
- package/src/econCommitteeCharter.js +25 -20
- package/src/feeDistributor.d.ts +224 -0
- package/src/feeDistributor.d.ts.map +1 -0
- package/src/feeDistributor.js +41 -33
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +1 -0
- package/src/interest-math.d.ts +4 -0
- package/src/interest-math.d.ts.map +1 -0
- package/src/interest-math.js +5 -1
- package/src/interest.d.ts +30 -0
- package/src/interest.d.ts.map +1 -0
- package/src/interest.js +25 -23
- package/src/price/README.md +14 -1
- package/src/price/fluxAggregatorContract.d.ts +71 -0
- package/src/price/fluxAggregatorContract.d.ts.map +1 -0
- package/src/price/fluxAggregatorContract.js +64 -55
- package/src/price/fluxAggregatorKit.d.ts +104 -0
- package/src/price/fluxAggregatorKit.d.ts.map +1 -0
- package/src/price/fluxAggregatorKit.js +55 -42
- package/src/price/priceOracleKit.d.ts +39 -0
- package/src/price/priceOracleKit.d.ts.map +1 -0
- package/src/price/priceOracleKit.js +17 -15
- package/src/price/roundsManager.d.ts +204 -0
- package/src/price/roundsManager.d.ts.map +1 -0
- package/src/price/roundsManager.js +132 -85
- package/src/proposals/README.md +2 -3
- package/src/proposals/add-auction.js +285 -0
- package/src/proposals/addAssetToVault.js +192 -40
- package/src/proposals/committee-proposal.js +25 -31
- package/src/proposals/core-proposal.js +9 -11
- package/src/proposals/deploy-price-feeds.js +341 -0
- package/src/proposals/econ-behaviors.js +84 -49
- package/src/proposals/price-feed-proposal.js +109 -51
- package/src/proposals/replace-fee-distributor.js +198 -0
- package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
- package/src/proposals/replaceElectorate.js +610 -0
- package/src/proposals/startEconCommittee.js +2 -2
- package/src/proposals/startPSM.js +44 -29
- package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
- package/src/proposals/upgrade-vaults.js +207 -0
- package/src/proposals/utils.d.ts +21 -0
- package/src/proposals/utils.d.ts.map +1 -0
- package/src/proposals/utils.js +66 -9
- package/src/proposals/withdraw-reserve-proposal.js +63 -0
- package/src/provisionPool.d.ts +69 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +138 -0
- package/src/provisionPoolKit.d.ts +129 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +608 -0
- package/src/psm/psm.d.ts +133 -0
- package/src/psm/psm.d.ts.map +1 -0
- package/src/psm/psm.js +85 -79
- package/src/psm/types-ambient.d.ts +2 -0
- package/src/psm/types-ambient.d.ts.map +1 -0
- package/src/psm/types-ambient.js +3 -0
- package/src/reserve/assetReserve.d.ts +58 -0
- package/src/reserve/assetReserve.d.ts.map +1 -0
- package/src/reserve/assetReserve.js +42 -34
- package/src/reserve/assetReserveKit.d.ts +103 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -0
- package/src/reserve/assetReserveKit.js +134 -32
- package/src/reserve/params.d.ts +16 -0
- package/src/reserve/params.d.ts.map +1 -0
- package/src/reserve/params.js +8 -2
- package/src/tokens.d.ts +3 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +5 -0
- package/src/vaultFactory/burn.d.ts +2 -0
- package/src/vaultFactory/burn.d.ts.map +1 -0
- package/src/vaultFactory/burn.js +1 -1
- package/src/vaultFactory/liquidation.d.ts +25 -0
- package/src/vaultFactory/liquidation.d.ts.map +1 -0
- package/src/vaultFactory/liquidation.js +37 -24
- package/src/vaultFactory/math.d.ts +11 -0
- package/src/vaultFactory/math.d.ts.map +1 -0
- package/src/vaultFactory/math.js +11 -10
- package/src/vaultFactory/orderedVaultStore.d.ts +94 -0
- package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
- package/src/vaultFactory/orderedVaultStore.js +9 -10
- package/src/vaultFactory/params.d.ts +143 -0
- package/src/vaultFactory/params.d.ts.map +1 -0
- package/src/vaultFactory/params.js +56 -25
- package/src/vaultFactory/prioritizedVaults.d.ts +280 -0
- package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
- package/src/vaultFactory/prioritizedVaults.js +7 -4
- package/src/vaultFactory/proceeds.d.ts +35 -0
- package/src/vaultFactory/proceeds.d.ts.map +1 -0
- package/src/vaultFactory/proceeds.js +26 -18
- package/src/vaultFactory/storeUtils.d.ts +25 -0
- package/src/vaultFactory/storeUtils.d.ts.map +1 -0
- package/src/vaultFactory/storeUtils.js +10 -12
- package/src/vaultFactory/types-ambient.d.ts +137 -0
- package/src/vaultFactory/types-ambient.d.ts.map +1 -0
- package/src/vaultFactory/{types.js → types-ambient.js} +47 -44
- package/src/vaultFactory/vault.d.ts +344 -0
- package/src/vaultFactory/vault.d.ts.map +1 -0
- package/src/vaultFactory/vault.js +107 -100
- package/src/vaultFactory/vaultDirector.d.ts +347 -0
- package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
- package/src/vaultFactory/vaultDirector.js +94 -64
- package/src/vaultFactory/vaultFactory.d.ts +250 -0
- package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
- package/src/vaultFactory/vaultFactory.js +56 -33
- package/src/vaultFactory/vaultHolder.d.ts +170 -0
- package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
- package/src/vaultFactory/vaultHolder.js +14 -15
- package/src/vaultFactory/vaultKit.d.ts +33 -0
- package/src/vaultFactory/vaultKit.d.ts.map +1 -0
- package/src/vaultFactory/vaultKit.js +9 -4
- package/src/vaultFactory/vaultManager.d.ts +676 -0
- package/src/vaultFactory/vaultManager.d.ts.map +1 -0
- package/src/vaultFactory/vaultManager.js +286 -167
- package/CHANGELOG.md +0 -1041
- package/exported.js +0 -2
- package/scripts/add-collateral-core.js +0 -112
- package/scripts/deploy-contracts.js +0 -100
- package/scripts/init-core.js +0 -198
- package/scripts/invite-committee-core.js +0 -42
- package/scripts/manual-price-feed.js +0 -117
- package/scripts/price-feed-core.js +0 -104
- package/scripts/start-local-chain.sh +0 -84
- package/src/psm/types.js +0 -3
- package/src/typeGuards.js +0 -13
- package/src/vaultFactory/type-imports.js +0 -4
package/src/auction/params.js
CHANGED
|
@@ -6,14 +6,17 @@ import {
|
|
|
6
6
|
import { TimeMath, RelativeTimeRecordShape } from '@agoric/time';
|
|
7
7
|
import { M } from '@agoric/store';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @import {AsyncSpecTuple} from '@agoric/governance/src/contractGovernance/typedParamManager.js';
|
|
11
|
+
* @import {SyncSpecTuple} from '@agoric/governance/src/contractGovernance/typedParamManager.js';
|
|
12
|
+
* @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
|
|
13
|
+
*/
|
|
11
14
|
|
|
12
15
|
// TODO duplicated with zoe/src/TypeGuards.js
|
|
13
16
|
export const InvitationShape = M.remotable('Invitation');
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
* In seconds, how often to start an auction.
|
|
19
|
+
* In seconds, how often to start an auction. The auction will start at
|
|
17
20
|
* AUCTION_START_DELAY seconds after a multiple of START_FREQUENCY, with the
|
|
18
21
|
* price at STARTING_RATE_BP. Every CLOCK_STEP, the price will be reduced by
|
|
19
22
|
* DISCOUNT_STEP_BP, as long as the rate is at or above LOWEST_RATE_BP, or until
|
|
@@ -70,12 +73,10 @@ export const auctioneerParamTypes = harden({
|
|
|
70
73
|
* @property {bigint} DiscountStep
|
|
71
74
|
* @property {RelativeTime} AuctionStartDelay
|
|
72
75
|
* @property {RelativeTime} PriceLockPeriod
|
|
73
|
-
* @property {import('@agoric/time
|
|
76
|
+
* @property {import('@agoric/time').TimerBrand} TimerBrand
|
|
74
77
|
*/
|
|
75
78
|
|
|
76
|
-
/**
|
|
77
|
-
* @param {AuctionParams} initial
|
|
78
|
-
*/
|
|
79
|
+
/** @param {AuctionParams} initial */
|
|
79
80
|
export const makeAuctioneerParams = ({
|
|
80
81
|
ElectorateInvitationAmount,
|
|
81
82
|
StartFrequency,
|
|
@@ -146,10 +147,11 @@ export const makeAuctioneerParamManager = (publisherKit, zcf, initial) => {
|
|
|
146
147
|
);
|
|
147
148
|
};
|
|
148
149
|
harden(makeAuctioneerParamManager);
|
|
150
|
+
/** @typedef {ReturnType<typeof makeAuctioneerParams>} AuctionParamRecord */
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
|
-
* @param {{storageNode: ERef<StorageNode
|
|
152
|
-
* @param {ERef<
|
|
153
|
+
* @param {{ storageNode: ERef<StorageNode>; marshaller: ERef<Marshaller> }} caps
|
|
154
|
+
* @param {ERef<import('@agoric/time').TimerService>} timer
|
|
153
155
|
* @param {ERef<PriceAuthority>} priceAuthority
|
|
154
156
|
* @param {ERef<AssetReservePublicFacet>} reservePublicFacet
|
|
155
157
|
* @param {AuctionParams} params
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function computeRoundTiming(params: Awaited<import("./params.js").AuctionParamManager>, baseTime: TimestampRecord): import("./scheduler.js").Schedule;
|
|
2
|
+
export function nextDescendingStepTime(liveSchedule: import("./scheduler.js").Schedule | null, nextSchedule: import("./scheduler.js").Schedule | null, now: Timestamp): Timestamp | null;
|
|
3
|
+
export function timeVsSchedule(time: Timestamp, schedule: import("./scheduler.js").Schedule): "before" | "during" | "endExactly" | "after";
|
|
4
|
+
import type { TimestampRecord } from '@agoric/time';
|
|
5
|
+
//# sourceMappingURL=scheduleMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduleMath.d.ts","sourceRoot":"","sources":["scheduleMath.js"],"names":[],"mappings":"AA0CO,2CAJI,OAAO,CAAC,OAAO,aAAa,EAAE,mBAAmB,CAAC,YAClD,eAAe,GACb,OAAO,gBAAgB,EAAE,QAAQ,CAqE7C;AAcM,qDALI,OAAO,gBAAgB,EAAE,QAAQ,GAAG,IAAI,gBACxC,OAAO,gBAAgB,EAAE,QAAQ,GAAG,IAAI,OACxC,SAAS,GACP,SAAS,GAAG,IAAI,CAuB5B;AAQM,qCAJI,SAAS,YACT,OAAO,gBAAgB,EAAE,QAAQ,GAC/B,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,CAiBxD;qCAhKkC,cAAc"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
+
import { Fail } from '@endo/errors';
|
|
3
4
|
import { TimeMath } from '@agoric/time';
|
|
4
5
|
import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
|
|
5
6
|
import { assertAllDefined, makeTracer } from '@agoric/internal';
|
|
6
7
|
|
|
8
|
+
/** @import {TimestampRecord} from '@agoric/time'; */
|
|
9
|
+
|
|
7
10
|
const { subtract, multiply, floorDivide } = natSafeMath;
|
|
8
|
-
const { Fail } = assert;
|
|
9
11
|
|
|
10
12
|
const trace = makeTracer('SMath', true);
|
|
11
13
|
|
|
@@ -18,23 +20,24 @@ const subtract1 = relTime =>
|
|
|
18
20
|
/**
|
|
19
21
|
* The length of the auction has to be inferred from the governed params.
|
|
20
22
|
*
|
|
21
|
-
* 1. The auction starts by offering collateral at a `StartingRate` (e.g., 105%)
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* 1. The auction starts by offering collateral at a `StartingRate` (e.g., 105%) of
|
|
24
|
+
* the market price at auction start, and continues until it reaches (or
|
|
25
|
+
* would exceed on its next step) LowestRate (e.g., 65%)
|
|
24
26
|
* 2. The offer price changes every `ClockStep` seconds
|
|
25
|
-
* 3. The offer price changes by `DiscountStep` amount (e.g., 5%) each step So
|
|
26
|
-
*
|
|
27
|
-
*
|
|
27
|
+
* 3. The offer price changes by `DiscountStep` amount (e.g., 5%) each step So it
|
|
28
|
+
* must run however many `ClockSteps` are required to get from `StartingRate`
|
|
29
|
+
* to `LowestRate` changing by `DiscountStep` each time.
|
|
28
30
|
*
|
|
29
|
-
* Therefore, the duration is `(StartingRate - LowestRate) / DiscountStep *
|
|
31
|
+
* Therefore, the duration is `(StartingRate - LowestRate) / DiscountStep *
|
|
32
|
+
* ClockStep`.
|
|
30
33
|
*
|
|
31
|
-
* Note that this is what's
|
|
34
|
+
* Note that this is what's _scheduled_. More than one auction can be running
|
|
32
35
|
* simultaneously, and some conditions can cause some of the auctions to stop
|
|
33
36
|
* selling early (e.g. reaching their target debt to raise or selling all of
|
|
34
37
|
* their collateral).
|
|
35
38
|
*
|
|
36
39
|
* @param {Awaited<import('./params.js').AuctionParamManager>} params
|
|
37
|
-
* @param {
|
|
40
|
+
* @param {TimestampRecord} baseTime
|
|
38
41
|
* @returns {import('./scheduler.js').Schedule}
|
|
39
42
|
*/
|
|
40
43
|
export const computeRoundTiming = (params, baseTime) => {
|
|
@@ -82,7 +85,7 @@ export const computeRoundTiming = (params, baseTime) => {
|
|
|
82
85
|
// computed start is `startDelay + baseTime + freq - (baseTime mod freq)`.
|
|
83
86
|
// That is, if there are hourly starts, we add an hour to the time, and
|
|
84
87
|
// subtract baseTime mod freq. Then we add the delay.
|
|
85
|
-
/** @type {
|
|
88
|
+
/** @type {TimestampRecord} */
|
|
86
89
|
const startTime = TimeMath.addAbsRel(
|
|
87
90
|
TimeMath.addAbsRel(
|
|
88
91
|
baseTime,
|
|
@@ -108,10 +111,10 @@ export const computeRoundTiming = (params, baseTime) => {
|
|
|
108
111
|
harden(computeRoundTiming);
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
|
-
* Calculate when the next descending step will start. If we're between
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* the
|
|
114
|
+
* Calculate when the next descending step will start. If we're between auctions
|
|
115
|
+
* (i.e. liveSchedule is undefined), or the last step of the current auction has
|
|
116
|
+
* started, then it'll be nextSchedule.startTime. Otherwise, it's the start of
|
|
117
|
+
* the step following the current step.
|
|
115
118
|
*
|
|
116
119
|
* @param {import('./scheduler.js').Schedule | null} liveSchedule
|
|
117
120
|
* @param {import('./scheduler.js').Schedule | null} nextSchedule
|
|
@@ -143,7 +146,6 @@ export const nextDescendingStepTime = (liveSchedule, nextSchedule, now) => {
|
|
|
143
146
|
harden(nextDescendingStepTime);
|
|
144
147
|
|
|
145
148
|
/**
|
|
146
|
-
*
|
|
147
149
|
* @param {Timestamp} time
|
|
148
150
|
* @param {import('./scheduler.js').Schedule} schedule
|
|
149
151
|
* @returns {'before' | 'during' | 'endExactly' | 'after'}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function makeScheduler(auctionDriver: AuctionDriver, timer: import("@agoric/time").TimerService, params: Awaited<import("./params.js").AuctionParamManager>, timerBrand: import("@agoric/time").TimerBrand, scheduleRecorder: import("@agoric/zoe/src/contractSupport/recorder.js").Recorder<ScheduleNotification>, paramUpdateSubscription: StoredSubscription<GovernanceSubscriptionState>): Promise<{
|
|
2
|
+
getSchedule: () => {
|
|
3
|
+
liveAuctionSchedule: Schedule | null;
|
|
4
|
+
nextAuctionSchedule: Schedule | null;
|
|
5
|
+
};
|
|
6
|
+
getAuctionState: () => AuctionState;
|
|
7
|
+
} & RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
8
|
+
getSchedule: () => {
|
|
9
|
+
liveAuctionSchedule: Schedule | null;
|
|
10
|
+
nextAuctionSchedule: Schedule | null;
|
|
11
|
+
};
|
|
12
|
+
getAuctionState: () => AuctionState;
|
|
13
|
+
}>>;
|
|
14
|
+
export type AuctionDriver = {
|
|
15
|
+
reducePriceAndTrade: () => void;
|
|
16
|
+
finalize: () => void;
|
|
17
|
+
startRound: () => void;
|
|
18
|
+
capturePrices: () => void;
|
|
19
|
+
};
|
|
20
|
+
export type ScheduleNotification = {
|
|
21
|
+
/**
|
|
22
|
+
* start time of current auction if
|
|
23
|
+
* auction is active
|
|
24
|
+
*/
|
|
25
|
+
activeStartTime: Timestamp | null;
|
|
26
|
+
/**
|
|
27
|
+
* start time of next auction
|
|
28
|
+
*/
|
|
29
|
+
nextStartTime: Timestamp | null;
|
|
30
|
+
/**
|
|
31
|
+
* when the next descending
|
|
32
|
+
* step will take place
|
|
33
|
+
*/
|
|
34
|
+
nextDescendingStepTime: Timestamp | null;
|
|
35
|
+
};
|
|
36
|
+
export type Schedule = {
|
|
37
|
+
startTime: import("@agoric/time").TimestampRecord;
|
|
38
|
+
endTime: import("@agoric/time").TimestampRecord;
|
|
39
|
+
steps: NatValue;
|
|
40
|
+
endRate: NatValue;
|
|
41
|
+
startDelay: RelativeTime;
|
|
42
|
+
clockStep: RelativeTime;
|
|
43
|
+
lockTime?: Timestamp | undefined;
|
|
44
|
+
};
|
|
45
|
+
export type FullSchedule = {
|
|
46
|
+
nextAuctionSchedule: Schedule | null;
|
|
47
|
+
liveAuctionSchedule: Schedule | null;
|
|
48
|
+
};
|
|
49
|
+
import { AuctionState } from './util.js';
|
|
50
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["scheduler.js"],"names":[],"mappings":"AA8EO,6CAPI,aAAa,SACb,OAAO,cAAc,EAAE,YAAY,UACnC,OAAO,CAAC,OAAO,aAAa,EAAE,mBAAmB,CAAC,cAClD,OAAO,cAAc,EAAE,UAAU,oBACjC,OAAO,6CAA6C,EAAE,QAAQ,CAAC,oBAAoB,CAAC,2BACpF,kBAAkB,CAAC,2BAA2B,CAAC;;;;;;;;;;;;IA0RzD;;yBA3Ta,MAAM,IAAI;cACV,MAAM,IAAI;gBACV,MAAM,IAAI;mBACV,MAAM,IAAI;;;;;;;qBAKV,SAAS,GAAG,IAAI;;;;mBAEhB,SAAS,GAAG,IAAI;;;;;4BAChB,SAAS,GAAG,IAAI;;;eAoThB,OAAO,cAAc,EAAE,eAAe;aACtC,OAAO,cAAc,EAAE,eAAe;WACtC,QAAQ;aACR,QAAQ;gBACR,YAAY;eACZ,YAAY;;;;yBAMZ,QAAQ,GAAG,IAAI;yBACf,QAAQ,GAAG,IAAI;;6BA/WsB,WAAW"}
|
package/src/auction/scheduler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { X, Fail, q, makeError } from '@endo/errors';
|
|
1
2
|
import { E } from '@endo/eventual-send';
|
|
2
|
-
import { TimeMath } from '@agoric/time';
|
|
3
3
|
import { Far } from '@endo/marshal';
|
|
4
|
+
import { TimeMath } from '@agoric/time';
|
|
4
5
|
import { makeTracer } from '@agoric/internal';
|
|
5
6
|
import { observeIteration, subscribeEach } from '@agoric/notifier';
|
|
6
7
|
|
|
@@ -11,8 +12,6 @@ import {
|
|
|
11
12
|
timeVsSchedule,
|
|
12
13
|
} from './scheduleMath.js';
|
|
13
14
|
|
|
14
|
-
const { details: X, Fail, quote: q } = assert;
|
|
15
|
-
|
|
16
15
|
const trace = makeTracer('SCHED', true);
|
|
17
16
|
|
|
18
17
|
// If the startAuction wakeup is no more than 5 minutes late, go ahead with it.
|
|
@@ -20,21 +19,22 @@ const MAX_LATE_TICK = 300n;
|
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @file The scheduler is presumed to be quiescent between auction rounds. Each
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Auction round consists of a sequence of steps with decreasing prices. There
|
|
23
|
+
* should always be a next schedule, but between rounds, liveSchedule is
|
|
24
|
+
* null.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* changed.
|
|
26
|
+
* The lock period that the liquidators use might start before the previous
|
|
27
|
+
* round has finished, so we need to schedule the next round each time an
|
|
28
|
+
* auction starts. This means if the scheduling parameters change, it'll be a
|
|
29
|
+
* full cycle before we switch. Otherwise, the vaults wouldn't know when to
|
|
30
|
+
* start their lock period. If the lock period for the next auction hasn't
|
|
31
|
+
* started when each aucion ends, we recalculate it, in case the parameters
|
|
32
|
+
* have changed.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* If the clock skips forward (because of a chain halt, for instance), the
|
|
35
|
+
* scheduler will try to cleanly and quickly finish any round already in
|
|
36
|
+
* progress. It would take additional work on the manual timer to test this
|
|
37
|
+
* thoroughly.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
const makeCancelToken = makeCancelTokenMaker('scheduler');
|
|
@@ -49,12 +49,11 @@ const makeCancelToken = makeCancelTokenMaker('scheduler');
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* @typedef {object} ScheduleNotification
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* auction if auction is active
|
|
52
|
+
* @property {Timestamp | null} activeStartTime start time of current auction if
|
|
53
|
+
* auction is active
|
|
55
54
|
* @property {Timestamp | null} nextStartTime start time of next auction
|
|
56
|
-
* @property {Timestamp | null} nextDescendingStepTime when the next descending
|
|
57
|
-
*
|
|
55
|
+
* @property {Timestamp | null} nextDescendingStepTime when the next descending
|
|
56
|
+
* step will take place
|
|
58
57
|
*/
|
|
59
58
|
|
|
60
59
|
const safelyComputeRoundTiming = (params, baseTime) => {
|
|
@@ -71,9 +70,9 @@ const nominalStartTime = nextSchedule =>
|
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
72
|
* @param {AuctionDriver} auctionDriver
|
|
74
|
-
* @param {import('@agoric/time
|
|
73
|
+
* @param {import('@agoric/time').TimerService} timer
|
|
75
74
|
* @param {Awaited<import('./params.js').AuctionParamManager>} params
|
|
76
|
-
* @param {import('@agoric/time
|
|
75
|
+
* @param {import('@agoric/time').TimerBrand} timerBrand
|
|
77
76
|
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<ScheduleNotification>} scheduleRecorder
|
|
78
77
|
* @param {StoredSubscription<GovernanceSubscriptionState>} paramUpdateSubscription
|
|
79
78
|
*/
|
|
@@ -92,7 +91,7 @@ export const makeScheduler = async (
|
|
|
92
91
|
*/
|
|
93
92
|
let liveSchedule = null;
|
|
94
93
|
|
|
95
|
-
/** @returns {Promise<{ now: Timestamp
|
|
94
|
+
/** @returns {Promise<{ now: Timestamp; nextSchedule: Schedule | null }>} */
|
|
96
95
|
const initializeNextSchedule = async () => {
|
|
97
96
|
return E.when(
|
|
98
97
|
// XXX manualTimer returns a bigint, not a timeRecord.
|
|
@@ -114,7 +113,7 @@ export const makeScheduler = async (
|
|
|
114
113
|
|
|
115
114
|
const stepCancelToken = makeCancelToken();
|
|
116
115
|
|
|
117
|
-
/** @type {
|
|
116
|
+
/** @type {AuctionState} */
|
|
118
117
|
let auctionState = AuctionState.WAITING;
|
|
119
118
|
|
|
120
119
|
/**
|
|
@@ -149,18 +148,7 @@ export const makeScheduler = async (
|
|
|
149
148
|
auctionState = AuctionState.WAITING;
|
|
150
149
|
auctionDriver.finalize();
|
|
151
150
|
|
|
152
|
-
if (nextSchedule) {
|
|
153
|
-
// only recalculate the next schedule at this point if the lock time has
|
|
154
|
-
// not been reached.
|
|
155
|
-
const nextLock = nextSchedule.lockTime;
|
|
156
|
-
if (nextLock && TimeMath.compareAbs(now, nextLock) < 0) {
|
|
157
|
-
const afterNow = TimeMath.addAbsRel(
|
|
158
|
-
now,
|
|
159
|
-
TimeMath.coerceRelativeTimeRecord(1n, timerBrand),
|
|
160
|
-
);
|
|
161
|
-
nextSchedule = safelyComputeRoundTiming(params, afterNow);
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
151
|
+
if (!nextSchedule) {
|
|
164
152
|
console.error(
|
|
165
153
|
'🛠️ finishAuctionRound without scheduling the next; repair with new auctioneer params',
|
|
166
154
|
);
|
|
@@ -233,9 +221,13 @@ export const makeScheduler = async (
|
|
|
233
221
|
liveSchedule.clockStep,
|
|
234
222
|
Far('PriceStepWaker', {
|
|
235
223
|
wake(time) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
224
|
+
try {
|
|
225
|
+
setTimeMonotonically(time);
|
|
226
|
+
trace('wake step', now);
|
|
227
|
+
clockTick(liveSchedule);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
console.error(`⚠️ Auction threw ${e}. Caught in PriceStepWaker.`);
|
|
230
|
+
}
|
|
239
231
|
},
|
|
240
232
|
}),
|
|
241
233
|
stepCancelToken,
|
|
@@ -249,10 +241,13 @@ export const makeScheduler = async (
|
|
|
249
241
|
start,
|
|
250
242
|
Far('SchedulerWaker', {
|
|
251
243
|
wake(time) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
244
|
+
try {
|
|
245
|
+
setTimeMonotonically(time);
|
|
246
|
+
auctionDriver.capturePrices();
|
|
247
|
+
return startAuction();
|
|
248
|
+
} catch (e) {
|
|
249
|
+
console.error(`⚠️ Auction threw ${e}. Caught in SchedulerWaker.`);
|
|
250
|
+
}
|
|
256
251
|
},
|
|
257
252
|
}),
|
|
258
253
|
);
|
|
@@ -266,7 +261,7 @@ export const makeScheduler = async (
|
|
|
266
261
|
|
|
267
262
|
if (!nextSchedule) {
|
|
268
263
|
console.error(
|
|
269
|
-
|
|
264
|
+
makeError(X`tried to start auction when none is scheduled`),
|
|
270
265
|
);
|
|
271
266
|
return;
|
|
272
267
|
}
|
|
@@ -333,7 +328,18 @@ export const makeScheduler = async (
|
|
|
333
328
|
// NB: may be fired with the initial params as well
|
|
334
329
|
async updateState(_newState) {
|
|
335
330
|
trace('received param update', _newState);
|
|
331
|
+
await null;
|
|
332
|
+
|
|
333
|
+
let fixableSchedule;
|
|
336
334
|
if (!nextSchedule) {
|
|
335
|
+
fixableSchedule = true;
|
|
336
|
+
} else {
|
|
337
|
+
now = await E(timer).getCurrentTimestamp();
|
|
338
|
+
fixableSchedule =
|
|
339
|
+
TimeMath.compareAbs(nextSchedule.startTime, now) < 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (fixableSchedule) {
|
|
337
343
|
trace('repairing nextSchedule and restarting');
|
|
338
344
|
({ nextSchedule } = await initializeNextSchedule());
|
|
339
345
|
startSchedulingFromScratch();
|
|
@@ -354,8 +360,8 @@ export const makeScheduler = async (
|
|
|
354
360
|
|
|
355
361
|
/**
|
|
356
362
|
* @typedef {object} Schedule
|
|
357
|
-
* @property {import('@agoric/time
|
|
358
|
-
* @property {import('@agoric/time
|
|
363
|
+
* @property {import('@agoric/time').TimestampRecord} startTime
|
|
364
|
+
* @property {import('@agoric/time').TimestampRecord} endTime
|
|
359
365
|
* @property {NatValue} steps
|
|
360
366
|
* @property {NatValue} endRate
|
|
361
367
|
* @property {RelativeTime} startDelay
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function toPartialOfferKey(offerPrice: Ratio): string;
|
|
2
|
+
export function toPriceOfferKey(offerPrice: Ratio, sequenceNumber: bigint): string;
|
|
3
|
+
export function fromPriceOfferKey(key: string, numBrand: Brand<"nat">, denomBrand: Brand<"nat">, useDecimals: number): [normalizedPrice: Ratio, sequenceNumber: bigint];
|
|
4
|
+
/** @type {(rate: Ratio) => string} */
|
|
5
|
+
export const toBidScalingComparator: (rate: Ratio) => string;
|
|
6
|
+
export function toScaledRateOfferKey(rate: Ratio, sequenceNumber: bigint): string;
|
|
7
|
+
export function fromScaledRateOfferKey(key: string, brand: Brand, useDecimals: number): [normalizedPrice: Ratio, sequenceNumber: bigint];
|
|
8
|
+
//# sourceMappingURL=sortedOffers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortedOffers.d.ts","sourceRoot":"","sources":["sortedOffers.js"],"names":[],"mappings":"AA6BO,8CAFI,KAAK,UAMf;AAUM,4CALI,KAAK,kBACL,MAAM,GACJ,MAAM,CAWlB;AAqCM,uCANI,MAAM,YACN,KAAK,CAAC,KAAK,CAAC,cACZ,KAAK,CAAC,KAAK,CAAC,eACZ,MAAM,GACJ,CAAC,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAS5D;AAED,sCAAsC;AACtC,qCADW,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAKhC;AAUK,2CALI,KAAK,kBACL,MAAM,GACJ,MAAM,CAWlB;AAUM,4CALI,MAAM,SACN,KAAK,eACL,MAAM,GACJ,CAAC,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAQ5D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
+
import { Fail } from '@endo/errors';
|
|
3
4
|
import {
|
|
4
5
|
makeRatio,
|
|
5
6
|
ratioToNumber,
|
|
@@ -9,16 +10,15 @@ import { RatioShape } from '@agoric/ertp';
|
|
|
9
10
|
|
|
10
11
|
import { decodeData, encodeData } from '../vaultFactory/storeUtils.js';
|
|
11
12
|
|
|
12
|
-
const { Fail } = assert;
|
|
13
|
-
|
|
14
13
|
/**
|
|
15
14
|
* @file we use a floating point representation of the price or rate as the
|
|
16
|
-
*
|
|
17
|
-
* the bid, but it doesn't matter for sorting. When we retrieve multiple
|
|
18
|
-
* it's only by bid value, so we don't care how the sequence numbers
|
|
15
|
+
* first part of the key in the store. The second part is the sequence number
|
|
16
|
+
* of the bid, but it doesn't matter for sorting. When we retrieve multiple
|
|
17
|
+
* bids, it's only by bid value, so we don't care how the sequence numbers
|
|
18
|
+
* sort.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* We take advantage of the fact that encodeData takes a passable and turns it
|
|
21
|
+
* into a sort key. Arrays of passable data sort like composite keys.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -39,7 +39,7 @@ export const toPartialOfferKey = offerPrice => {
|
|
|
39
39
|
* @param {Ratio} offerPrice IST/collateral
|
|
40
40
|
* @param {bigint} sequenceNumber
|
|
41
41
|
* @returns {string} lexically sortable string in which highest price is first,
|
|
42
|
-
*
|
|
42
|
+
* ties will be broken by sequenceNumber of offer
|
|
43
43
|
*/
|
|
44
44
|
export const toPriceOfferKey = (offerPrice, sequenceNumber) => {
|
|
45
45
|
mustMatch(offerPrice, RatioShape);
|
|
@@ -87,6 +87,7 @@ const bidScalingRatioFromKey = (bidScaleFloat, numBrand, useDecimals) => {
|
|
|
87
87
|
* @returns {[normalizedPrice: Ratio, sequenceNumber: bigint]}
|
|
88
88
|
*/
|
|
89
89
|
export const fromPriceOfferKey = (key, numBrand, denomBrand, useDecimals) => {
|
|
90
|
+
// @ts-expect-error XXX
|
|
90
91
|
const [pricePart, sequenceNumberPart] = decodeData(key);
|
|
91
92
|
return [
|
|
92
93
|
priceRatioFromFloat(pricePart, numBrand, denomBrand, useDecimals),
|
|
@@ -107,7 +108,7 @@ export const toBidScalingComparator = rate => {
|
|
|
107
108
|
* @param {Ratio} rate discount/markup rate expressed as a ratio IST/IST
|
|
108
109
|
* @param {bigint} sequenceNumber
|
|
109
110
|
* @returns {string} lexically sortable string in which highest price is first,
|
|
110
|
-
*
|
|
111
|
+
* ties will be broken by sequenceNumber of offer
|
|
111
112
|
*/
|
|
112
113
|
export const toScaledRateOfferKey = (rate, sequenceNumber) => {
|
|
113
114
|
mustMatch(rate, RatioShape);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Auction State.
|
|
3
|
+
*/
|
|
4
|
+
export type AuctionState = (typeof AuctionState)[keyof typeof AuctionState];
|
|
5
|
+
export namespace AuctionState {
|
|
6
|
+
let ACTIVE: "active";
|
|
7
|
+
let WAITING: "waiting";
|
|
8
|
+
}
|
|
9
|
+
export function makeBrandedRatioPattern(numeratorAmountShape: {
|
|
10
|
+
brand: Brand;
|
|
11
|
+
value: Pattern;
|
|
12
|
+
}, denominatorAmountShape: {
|
|
13
|
+
brand: Brand;
|
|
14
|
+
value: Pattern;
|
|
15
|
+
}): {
|
|
16
|
+
numerator: {
|
|
17
|
+
brand: Brand;
|
|
18
|
+
value: Pattern;
|
|
19
|
+
};
|
|
20
|
+
denominator: {
|
|
21
|
+
brand: Brand;
|
|
22
|
+
value: Pattern;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export function isScaledBidPriceHigher(bidScaling: Ratio, currentPrice: Ratio, oraclePrice: Ratio): boolean;
|
|
26
|
+
/** @type {(quote: PriceQuote) => Ratio} */
|
|
27
|
+
export const priceFrom: (quote: PriceQuote) => Ratio;
|
|
28
|
+
export function makeCancelTokenMaker(name: any): () => RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
|
|
29
|
+
import type { Pattern } from '@endo/patterns';
|
|
30
|
+
import type { PriceQuote } from '@agoric/zoe/tools/types.js';
|
|
31
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["util.js"],"names":[],"mappings":";;;2BAiBU,CAAC,OAAO,YAAY,EAAE,MAAM,OAAO,YAAY,CAAC;;;;;AAYnD,8DAHI;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,0BAChC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE;;eADvB,KAAK;eAAS,OAAO;;;eACrB,KAAK;eAAS,OAAO;;EAUxC;AASM,mDANI,KAAK,gBACL,KAAK,eACL,KAAK,GACH,OAAO,CAI6C;AAEjE,2CAA2C;AAC3C,wBADW,CAAC,KAAK,EAAE,UAAU,KAAK,KAAK,CAKnC;AAEG,oJAIN;6BAlD8B,gBAAgB;gCAC8C,4BAA4B"}
|
package/src/auction/util.js
CHANGED
|
@@ -7,19 +7,25 @@ import {
|
|
|
7
7
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
8
8
|
import { Far } from '@endo/marshal';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
12
|
+
* @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
|
|
13
|
+
*/
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Constants for Auction State.
|
|
12
17
|
*
|
|
13
|
-
* @
|
|
18
|
+
* @enum {(typeof AuctionState)[keyof typeof AuctionState]}
|
|
14
19
|
*/
|
|
15
|
-
export const AuctionState = {
|
|
20
|
+
export const AuctionState = /** @type {const} */ ({
|
|
16
21
|
ACTIVE: 'active',
|
|
17
22
|
WAITING: 'waiting',
|
|
18
|
-
};
|
|
23
|
+
});
|
|
24
|
+
harden(AuctionState);
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
|
-
* @param {{ brand: Brand
|
|
22
|
-
* @param {{ brand: Brand
|
|
27
|
+
* @param {{ brand: Brand; value: Pattern }} numeratorAmountShape
|
|
28
|
+
* @param {{ brand: Brand; value: Pattern }} denominatorAmountShape
|
|
23
29
|
*/
|
|
24
30
|
export const makeBrandedRatioPattern = (
|
|
25
31
|
numeratorAmountShape,
|
|
@@ -36,7 +42,7 @@ export const makeBrandedRatioPattern = (
|
|
|
36
42
|
* @param {Ratio} currentPrice
|
|
37
43
|
* @param {Ratio} oraclePrice
|
|
38
44
|
* @returns {boolean} TRUE iff the discount(/markup) applied to the price is
|
|
39
|
-
*
|
|
45
|
+
* higher than the quote.
|
|
40
46
|
*/
|
|
41
47
|
export const isScaledBidPriceHigher = (bidScaling, currentPrice, oraclePrice) =>
|
|
42
48
|
ratioGTE(multiplyRatios(oraclePrice, bidScaling), currentPrice);
|