@agoric/inter-protocol 0.16.2-dev-ecf2d8e.0 → 0.16.2-other-dev-70beeb7.0
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/CHANGELOG.md +1041 -0
- package/package.json +30 -33
- package/scripts/add-collateral-core.js +112 -0
- package/scripts/build-bundles.js +21 -5
- package/scripts/deploy-contracts.js +100 -0
- package/scripts/init-core.js +198 -0
- package/scripts/invite-committee-core.js +42 -0
- package/scripts/manual-price-feed.js +117 -0
- package/scripts/price-feed-core.js +104 -0
- package/scripts/start-local-chain.sh +84 -0
- package/src/auction/auctionBook.js +59 -74
- package/src/auction/auctioneer.js +44 -56
- package/src/auction/offerBook.js +11 -12
- package/src/auction/params.js +5 -3
- package/src/auction/scheduleMath.js +13 -13
- package/src/auction/scheduler.js +32 -32
- package/src/auction/sortedOffers.js +7 -8
- package/src/auction/util.js +4 -4
- package/src/clientSupport.js +96 -152
- package/src/contractSupport.js +5 -5
- package/src/econCommitteeCharter.js +17 -18
- package/src/feeDistributor.js +33 -34
- package/src/interest.js +14 -20
- package/src/price/fluxAggregatorContract.js +45 -51
- package/src/price/fluxAggregatorKit.js +33 -48
- package/src/price/priceOracleKit.js +13 -11
- package/src/price/roundsManager.js +64 -52
- package/src/proposals/addAssetToVault.js +6 -15
- package/src/proposals/committee-proposal.js +27 -21
- package/src/proposals/core-proposal.js +7 -7
- package/src/proposals/econ-behaviors.js +32 -57
- package/src/proposals/price-feed-proposal.js +34 -66
- package/src/proposals/startEconCommittee.js +1 -1
- package/src/proposals/startPSM.js +22 -32
- package/src/proposals/utils.js +7 -26
- package/src/psm/psm.js +63 -69
- package/src/reserve/assetReserve.js +18 -27
- package/src/reserve/assetReserveKit.js +22 -14
- package/src/typeGuards.js +13 -0
- package/src/vaultFactory/liquidation.js +17 -30
- package/src/vaultFactory/math.js +9 -8
- package/src/vaultFactory/orderedVaultStore.js +9 -6
- package/src/vaultFactory/params.js +18 -24
- package/src/vaultFactory/prioritizedVaults.js +2 -2
- package/src/vaultFactory/proceeds.js +18 -24
- package/src/vaultFactory/storeUtils.js +12 -8
- package/src/vaultFactory/types.js +28 -38
- package/src/vaultFactory/vault.js +89 -88
- package/src/vaultFactory/vaultDirector.js +44 -35
- package/src/vaultFactory/vaultFactory.js +26 -33
- package/src/vaultFactory/vaultHolder.js +13 -8
- package/src/vaultFactory/vaultKit.js +2 -3
- package/src/vaultFactory/vaultManager.js +120 -138
- package/src/auction/auctionBook.d.ts +0 -83
- package/src/auction/auctionBook.d.ts.map +0 -1
- package/src/auction/auctioneer.d.ts +0 -75
- package/src/auction/auctioneer.d.ts.map +0 -1
- package/src/auction/offerBook.d.ts +0 -72
- package/src/auction/offerBook.d.ts.map +0 -1
- package/src/auction/params.d.ts +0 -142
- package/src/auction/params.d.ts.map +0 -1
- package/src/auction/scheduleMath.d.ts +0 -4
- package/src/auction/scheduleMath.d.ts.map +0 -1
- package/src/auction/scheduler.d.ts +0 -49
- package/src/auction/scheduler.d.ts.map +0 -1
- package/src/auction/sortedOffers.d.ts +0 -8
- package/src/auction/sortedOffers.d.ts.map +0 -1
- package/src/auction/util.d.ts +0 -30
- package/src/auction/util.d.ts.map +0 -1
- package/src/clientSupport.d.ts +0 -167
- package/src/clientSupport.d.ts.map +0 -1
- package/src/collectFees.d.ts +0 -2
- package/src/collectFees.d.ts.map +0 -1
- package/src/contractSupport.d.ts +0 -33
- package/src/contractSupport.d.ts.map +0 -1
- package/src/econCommitteeCharter.d.ts +0 -41
- package/src/econCommitteeCharter.d.ts.map +0 -1
- package/src/feeDistributor.d.ts +0 -212
- package/src/feeDistributor.d.ts.map +0 -1
- package/src/index.d.ts +0 -2
- package/src/index.d.ts.map +0 -1
- package/src/interest-math.d.ts +0 -3
- package/src/interest-math.d.ts.map +0 -1
- package/src/interest.d.ts +0 -29
- package/src/interest.d.ts.map +0 -1
- package/src/price/fluxAggregatorContract.d.ts +0 -112
- package/src/price/fluxAggregatorContract.d.ts.map +0 -1
- package/src/price/fluxAggregatorKit.d.ts +0 -155
- package/src/price/fluxAggregatorKit.d.ts.map +0 -1
- package/src/price/priceOracleKit.d.ts +0 -52
- package/src/price/priceOracleKit.d.ts.map +0 -1
- package/src/price/roundsManager.d.ts +0 -330
- package/src/price/roundsManager.d.ts.map +0 -1
- package/src/proposals/addAssetToVault.d.ts +0 -143
- package/src/proposals/addAssetToVault.d.ts.map +0 -1
- package/src/proposals/committee-proposal.d.ts +0 -113
- package/src/proposals/committee-proposal.d.ts.map +0 -1
- package/src/proposals/core-proposal.d.ts +0 -149
- package/src/proposals/core-proposal.d.ts.map +0 -1
- package/src/proposals/econ-behaviors.d.ts +0 -201
- package/src/proposals/econ-behaviors.d.ts.map +0 -1
- package/src/proposals/price-feed-proposal.d.ts +0 -82
- package/src/proposals/price-feed-proposal.d.ts.map +0 -1
- package/src/proposals/startEconCommittee.d.ts +0 -34
- package/src/proposals/startEconCommittee.d.ts.map +0 -1
- package/src/proposals/startPSM.d.ts +0 -61
- package/src/proposals/startPSM.d.ts.map +0 -1
- package/src/proposals/utils.d.ts +0 -15
- package/src/proposals/utils.d.ts.map +0 -1
- package/src/provisionPool.d.ts +0 -165
- package/src/provisionPool.d.ts.map +0 -1
- package/src/provisionPool.js +0 -119
- package/src/provisionPoolKit.d.ts +0 -379
- package/src/provisionPoolKit.d.ts.map +0 -1
- package/src/provisionPoolKit.js +0 -461
- package/src/psm/psm.d.ts +0 -178
- package/src/psm/psm.d.ts.map +0 -1
- package/src/psm/types.d.ts +0 -2
- package/src/psm/types.d.ts.map +0 -1
- package/src/reserve/assetReserve.d.ts +0 -44
- package/src/reserve/assetReserve.d.ts.map +0 -1
- package/src/reserve/assetReserveKit.d.ts +0 -114
- package/src/reserve/assetReserveKit.d.ts.map +0 -1
- package/src/reserve/params.d.ts +0 -10
- package/src/reserve/params.d.ts.map +0 -1
- package/src/tokens.d.ts +0 -3
- package/src/tokens.d.ts.map +0 -1
- package/src/tokens.js +0 -5
- package/src/vaultFactory/burn.d.ts +0 -2
- package/src/vaultFactory/burn.d.ts.map +0 -1
- package/src/vaultFactory/liquidation.d.ts +0 -24
- package/src/vaultFactory/liquidation.d.ts.map +0 -1
- package/src/vaultFactory/math.d.ts +0 -10
- package/src/vaultFactory/math.d.ts.map +0 -1
- package/src/vaultFactory/orderedVaultStore.d.ts +0 -94
- package/src/vaultFactory/orderedVaultStore.d.ts.map +0 -1
- package/src/vaultFactory/params.d.ts +0 -159
- package/src/vaultFactory/params.d.ts.map +0 -1
- package/src/vaultFactory/prioritizedVaults.d.ts +0 -279
- package/src/vaultFactory/prioritizedVaults.d.ts.map +0 -1
- package/src/vaultFactory/proceeds.d.ts +0 -34
- package/src/vaultFactory/proceeds.d.ts.map +0 -1
- package/src/vaultFactory/storeUtils.d.ts +0 -25
- package/src/vaultFactory/storeUtils.d.ts.map +0 -1
- package/src/vaultFactory/type-imports.d.ts +0 -2
- package/src/vaultFactory/type-imports.d.ts.map +0 -1
- package/src/vaultFactory/types.d.ts +0 -137
- package/src/vaultFactory/types.d.ts.map +0 -1
- package/src/vaultFactory/vault.d.ts +0 -529
- package/src/vaultFactory/vault.d.ts.map +0 -1
- package/src/vaultFactory/vaultDirector.d.ts +0 -560
- package/src/vaultFactory/vaultDirector.d.ts.map +0 -1
- package/src/vaultFactory/vaultFactory.d.ts +0 -162
- package/src/vaultFactory/vaultFactory.d.ts.map +0 -1
- package/src/vaultFactory/vaultHolder.d.ts +0 -201
- package/src/vaultFactory/vaultHolder.d.ts.map +0 -1
- package/src/vaultFactory/vaultKit.d.ts +0 -32
- package/src/vaultFactory/vaultKit.d.ts.map +0 -1
- package/src/vaultFactory/vaultManager.d.ts +0 -554
- package/src/vaultFactory/vaultManager.d.ts.map +0 -1
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* @file Use-object for the owner of a vault
|
|
3
|
+
*/
|
|
2
4
|
import { AmountShape } from '@agoric/ertp';
|
|
3
5
|
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
4
6
|
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
|
|
5
|
-
import { UnguardedHelperI } from '
|
|
7
|
+
import { UnguardedHelperI } from '../typeGuards.js';
|
|
6
8
|
|
|
7
9
|
const { Fail } = assert;
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* @typedef {{
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* topicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<VaultNotification>,
|
|
14
|
+
* vault: Vault | null,
|
|
13
15
|
* }} State
|
|
14
16
|
*/
|
|
15
17
|
|
|
@@ -23,7 +25,7 @@ const HolderI = M.interface('holder', {
|
|
|
23
25
|
makeTransferInvitation: M.call().returns(M.promise()),
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
/** @type {{ [name: string]: [description: string, valueShape: Pattern] }} */
|
|
28
|
+
/** @type {{ [name: string]: [ description: string, valueShape: Pattern ] }} */
|
|
27
29
|
const PUBLIC_TOPICS = {
|
|
28
30
|
vault: ['Vault holder status', M.any()],
|
|
29
31
|
};
|
|
@@ -46,6 +48,7 @@ export const prepareVaultHolder = (baggage, makeRecorderKit) => {
|
|
|
46
48
|
}),
|
|
47
49
|
},
|
|
48
50
|
/**
|
|
51
|
+
*
|
|
49
52
|
* @param {Vault} vault
|
|
50
53
|
* @param {StorageNode} storageNode
|
|
51
54
|
* @returns {State}
|
|
@@ -58,7 +61,9 @@ export const prepareVaultHolder = (baggage, makeRecorderKit) => {
|
|
|
58
61
|
},
|
|
59
62
|
{
|
|
60
63
|
helper: {
|
|
61
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* @throws if this holder no longer owns the vault
|
|
66
|
+
*/
|
|
62
67
|
owned() {
|
|
63
68
|
const { vault } = this.state;
|
|
64
69
|
if (!vault) {
|
|
@@ -99,8 +104,8 @@ export const prepareVaultHolder = (baggage, makeRecorderKit) => {
|
|
|
99
104
|
return this.facets.helper.owned().makeCloseInvitation();
|
|
100
105
|
},
|
|
101
106
|
/**
|
|
102
|
-
* Starting a transfer revokes the vault holder. The associated updater
|
|
103
|
-
*
|
|
107
|
+
* Starting a transfer revokes the vault holder. The associated updater will
|
|
108
|
+
* get a special notification that the vault is being transferred.
|
|
104
109
|
*/
|
|
105
110
|
makeTransferInvitation() {
|
|
106
111
|
const vault = this.facets.helper.owned();
|
|
@@ -8,8 +8,7 @@ import { prepareVaultHolder } from './vaultHolder.js';
|
|
|
8
8
|
const trace = makeTracer('VK', true);
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Wrap the VaultHolder duration object in a record suitable for the result of
|
|
12
|
-
* an invitation.
|
|
11
|
+
* Wrap the VaultHolder duration object in a record suitable for the result of an invitation.
|
|
13
12
|
*
|
|
14
13
|
* @param {import('@agoric/ertp').Baggage} baggage
|
|
15
14
|
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
|
|
@@ -44,4 +43,4 @@ export const prepareVaultKit = (baggage, makeRecorderKit) => {
|
|
|
44
43
|
return makeVaultKit;
|
|
45
44
|
};
|
|
46
45
|
|
|
47
|
-
/** @typedef {ReturnType<ReturnType<typeof prepareVaultKit>>} VaultKit */
|
|
46
|
+
/** @typedef {(ReturnType<ReturnType<typeof prepareVaultKit>>)} VaultKit */
|
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @file Vault Manager object manages vault-based debts for a collateral type.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* The responsibilities include:
|
|
6
|
+
* - opening a new vault backed by the collateral
|
|
7
|
+
* - publishing metrics on the vault economy for that collateral
|
|
8
|
+
* - charging interest on all active vaults
|
|
9
|
+
* - liquidating active vaults that have exceeded the debt ratio
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - liquidating active vaults that have exceeded the debt ratio
|
|
11
|
+
* Once a vault is settled (liquidated or closed) it can still be used, traded,
|
|
12
|
+
* etc. but is no longer the concern of the manager. It can't be liquidated,
|
|
13
|
+
* have interest charged, or be counted in the metrics.
|
|
11
14
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* have interest charged, or be counted in the metrics.
|
|
15
|
-
*
|
|
16
|
-
* Undercollateralized vaults can have their assets sent to the auctioneer to be
|
|
17
|
-
* liquidated. If the auction is unsuccessful, the liquidation may be
|
|
18
|
-
* reverted.
|
|
15
|
+
* Undercollateralized vaults can have their assets sent to the auctioneer to be
|
|
16
|
+
* liquidated. If the auction is unsuccessful, the liquidation may be reverted.
|
|
19
17
|
*/
|
|
20
18
|
import '@agoric/zoe/exported.js';
|
|
21
19
|
|
|
@@ -75,102 +73,93 @@ const trace = makeTracer('VM');
|
|
|
75
73
|
// Metrics naming scheme: nouns are present values; past-participles are accumulative.
|
|
76
74
|
/**
|
|
77
75
|
* @typedef {object} MetricsNotification
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @property {number}
|
|
82
|
-
* @property {number}
|
|
83
|
-
* @property {Amount<'nat'>}
|
|
84
|
-
*
|
|
85
|
-
* @property {Amount<'nat'>}
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @property {Amount<'nat'>}
|
|
92
|
-
*
|
|
93
|
-
* @property {Amount<'nat'>}
|
|
94
|
-
*
|
|
95
|
-
* @property {
|
|
96
|
-
* central received greater than debt
|
|
97
|
-
* @property {Amount<'nat'>} totalProceedsReceived running sum of minted
|
|
98
|
-
* received from liquidation
|
|
99
|
-
* @property {Amount<'nat'>} totalShortfallReceived running sum of shortfalls,
|
|
100
|
-
* minted received less than debt
|
|
101
|
-
* @property {number} numLiquidationsCompleted running count of liquidated
|
|
102
|
-
* vaults
|
|
103
|
-
* @property {number} numLiquidationsAborted running count of vault liquidations
|
|
104
|
-
* that were reverted.
|
|
76
|
+
*
|
|
77
|
+
* @property {Ratio | null} lockedQuote priceQuote that will be used for liquidation.
|
|
78
|
+
* Non-null from priceLock time until liquidation has taken place.
|
|
79
|
+
* @property {number} numActiveVaults present count of vaults
|
|
80
|
+
* @property {number} numLiquidatingVaults present count of liquidating vaults
|
|
81
|
+
* @property {Amount<'nat'>} totalCollateral present sum of collateral across all vaults
|
|
82
|
+
* @property {Amount<'nat'>} totalDebt present sum of debt across all vaults
|
|
83
|
+
* @property {Amount<'nat'>} retainedCollateral collateral held as a result of not returning excess refunds
|
|
84
|
+
* to owners of vaults liquidated with shortfalls
|
|
85
|
+
* @property {Amount<'nat'>} liquidatingCollateral present sum of collateral in vaults sent for liquidation
|
|
86
|
+
* @property {Amount<'nat'>} liquidatingDebt present sum of debt in vaults sent for liquidation
|
|
87
|
+
*
|
|
88
|
+
* @property {Amount<'nat'>} totalCollateralSold running sum of collateral sold in liquidation
|
|
89
|
+
* @property {Amount<'nat'>} totalOverageReceived running sum of overages, central received greater than debt
|
|
90
|
+
* @property {Amount<'nat'>} totalProceedsReceived running sum of minted received from liquidation
|
|
91
|
+
* @property {Amount<'nat'>} totalShortfallReceived running sum of shortfalls, minted received less than debt
|
|
92
|
+
* @property {number} numLiquidationsCompleted running count of liquidated vaults
|
|
93
|
+
* @property {number} numLiquidationsAborted running count of vault liquidations that were reverted.
|
|
105
94
|
*/
|
|
106
95
|
|
|
107
96
|
/**
|
|
108
97
|
* @typedef {{
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
98
|
+
* compoundedInterest: Ratio,
|
|
99
|
+
* interestRate: Ratio,
|
|
100
|
+
* latestInterestUpdate: Timestamp,
|
|
112
101
|
* }} AssetState
|
|
113
102
|
*
|
|
114
103
|
* @typedef {{
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
104
|
+
* getChargingPeriod: () => RelativeTime,
|
|
105
|
+
* getRecordingPeriod: () => RelativeTime,
|
|
106
|
+
* getDebtLimit: () => Amount<'nat'>,
|
|
107
|
+
* getInterestRate: () => Ratio,
|
|
108
|
+
* getLiquidationPadding: () => Ratio,
|
|
109
|
+
* getLiquidationMargin: () => Ratio,
|
|
110
|
+
* getLiquidationPenalty: () => Ratio,
|
|
111
|
+
* getMintFee: () => Ratio,
|
|
112
|
+
* getMinInitialDebt: () => Amount<'nat'>,
|
|
124
113
|
* }} GovernedParamGetters
|
|
125
114
|
*/
|
|
126
115
|
|
|
127
116
|
/**
|
|
128
117
|
* @typedef {Readonly<{
|
|
129
|
-
* debtMint: ZCFMint<'nat'
|
|
130
|
-
* collateralBrand: Brand<'nat'
|
|
131
|
-
* collateralUnit: Amount<'nat'
|
|
132
|
-
* descriptionScope: string
|
|
133
|
-
* startTimeStamp: Timestamp
|
|
134
|
-
* storageNode: StorageNode
|
|
118
|
+
* debtMint: ZCFMint<'nat'>,
|
|
119
|
+
* collateralBrand: Brand<'nat'>,
|
|
120
|
+
* collateralUnit: Amount<'nat'>,
|
|
121
|
+
* descriptionScope: string,
|
|
122
|
+
* startTimeStamp: Timestamp,
|
|
123
|
+
* storageNode: StorageNode,
|
|
135
124
|
* }>} HeldParams
|
|
136
125
|
*/
|
|
137
126
|
|
|
138
127
|
/**
|
|
139
128
|
* @typedef {{
|
|
140
|
-
* assetTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AssetState
|
|
141
|
-
* debtBrand: Brand<'nat'
|
|
142
|
-
* liquidatingVaults: SetStore<Vault
|
|
143
|
-
* metricsTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification
|
|
144
|
-
* poolIncrementSeat: ZCFSeat
|
|
145
|
-
* retainedCollateralSeat: ZCFSeat
|
|
146
|
-
* unsettledVaults: MapStore<string, Vault
|
|
129
|
+
* assetTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AssetState>,
|
|
130
|
+
* debtBrand: Brand<'nat'>,
|
|
131
|
+
* liquidatingVaults: SetStore<Vault>,
|
|
132
|
+
* metricsTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification>,
|
|
133
|
+
* poolIncrementSeat: ZCFSeat,
|
|
134
|
+
* retainedCollateralSeat: ZCFSeat,
|
|
135
|
+
* unsettledVaults: MapStore<string, Vault>,
|
|
147
136
|
* }} ImmutableState
|
|
148
137
|
*/
|
|
149
138
|
|
|
150
139
|
/**
|
|
151
140
|
* @typedef {{
|
|
152
|
-
* compoundedInterest: Ratio
|
|
153
|
-
* latestInterestUpdate: Timestamp
|
|
154
|
-
* numLiquidationsCompleted: number
|
|
155
|
-
* numLiquidationsAborted: number
|
|
156
|
-
* totalCollateral: Amount<'nat'
|
|
157
|
-
* totalCollateralSold: Amount<'nat'
|
|
158
|
-
* totalDebt: Amount<'nat'
|
|
159
|
-
* liquidatingCollateral: Amount<'nat'
|
|
160
|
-
* liquidatingDebt: Amount<'nat'
|
|
161
|
-
* totalOverageReceived: Amount<'nat'
|
|
162
|
-
* totalProceedsReceived: Amount<'nat'
|
|
163
|
-
* totalShortfallReceived: Amount<'nat'
|
|
164
|
-
* vaultCounter: number
|
|
165
|
-
* lockedQuote: PriceQuote | undefined
|
|
141
|
+
* compoundedInterest: Ratio,
|
|
142
|
+
* latestInterestUpdate: Timestamp,
|
|
143
|
+
* numLiquidationsCompleted: number,
|
|
144
|
+
* numLiquidationsAborted: number,
|
|
145
|
+
* totalCollateral: Amount<'nat'>,
|
|
146
|
+
* totalCollateralSold: Amount<'nat'>,
|
|
147
|
+
* totalDebt: Amount<'nat'>,
|
|
148
|
+
* liquidatingCollateral: Amount<'nat'>,
|
|
149
|
+
* liquidatingDebt: Amount<'nat'>,
|
|
150
|
+
* totalOverageReceived: Amount<'nat'>,
|
|
151
|
+
* totalProceedsReceived: Amount<'nat'>,
|
|
152
|
+
* totalShortfallReceived: Amount<'nat'>,
|
|
153
|
+
* vaultCounter: number,
|
|
154
|
+
* lockedQuote: PriceQuote | undefined,
|
|
166
155
|
* }} MutableState
|
|
167
156
|
*/
|
|
168
157
|
|
|
169
158
|
/**
|
|
170
159
|
* @type {(brand: Brand) => {
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
160
|
+
* prioritizedVaults: ReturnType<typeof makePrioritizedVaults>,
|
|
161
|
+
* storedQuotesNotifier: import('@agoric/notifier').StoredNotifier<PriceQuote>,
|
|
162
|
+
* storedCollateralQuote: PriceQuote,
|
|
174
163
|
* }}
|
|
175
164
|
*/
|
|
176
165
|
// any b/c will be filled after start()
|
|
@@ -179,11 +168,11 @@ const collateralEphemera = makeEphemeraProvider(() => /** @type {any} */ ({}));
|
|
|
179
168
|
/**
|
|
180
169
|
* @param {import('@agoric/ertp').Baggage} baggage
|
|
181
170
|
* @param {{
|
|
182
|
-
* zcf: import('./vaultFactory.js').VaultFactoryZCF
|
|
183
|
-
* marshaller: ERef<Marshaller
|
|
184
|
-
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit
|
|
185
|
-
* makeERecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeERecorderKit
|
|
186
|
-
* factoryPowers: import('./vaultDirector.js').FactoryPowersFacet
|
|
171
|
+
* zcf: import('./vaultFactory.js').VaultFactoryZCF,
|
|
172
|
+
* marshaller: ERef<Marshaller>,
|
|
173
|
+
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit,
|
|
174
|
+
* makeERecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeERecorderKit,
|
|
175
|
+
* factoryPowers: import('./vaultDirector.js').FactoryPowersFacet,
|
|
187
176
|
* }} powers
|
|
188
177
|
*/
|
|
189
178
|
export const prepareVaultManagerKit = (
|
|
@@ -214,9 +203,8 @@ export const prepareVaultManagerKit = (
|
|
|
214
203
|
poolIncrementSeat: zcf.makeEmptySeatKit().zcfSeat,
|
|
215
204
|
|
|
216
205
|
/**
|
|
217
|
-
* Vaults that have been sent for liquidation. When we get proceeds (or
|
|
218
|
-
*
|
|
219
|
-
* vaults.
|
|
206
|
+
* Vaults that have been sent for liquidation. When we get proceeds (or lack
|
|
207
|
+
* thereof) back from the liquidator, we will allocate them among the vaults.
|
|
220
208
|
*
|
|
221
209
|
* @type {SetStore<Vault>}
|
|
222
210
|
*/
|
|
@@ -351,7 +339,9 @@ export const prepareVaultManagerKit = (
|
|
|
351
339
|
|
|
352
340
|
// Some of these could go in closures but are kept on a facet anticipating future durability options.
|
|
353
341
|
helper: {
|
|
354
|
-
/**
|
|
342
|
+
/**
|
|
343
|
+
* Start non-durable processes (or restart if needed after vat restart)
|
|
344
|
+
*/
|
|
355
345
|
start() {
|
|
356
346
|
const { state, facets } = this;
|
|
357
347
|
trace(state.collateralBrand, 'helper.start()', state.vaultCounter);
|
|
@@ -410,7 +400,7 @@ export const prepareVaultManagerKit = (
|
|
|
410
400
|
// throw. See https://github.com/Agoric/agoric-sdk/issues/4317
|
|
411
401
|
void observeNotifier(quoteNotifier, {
|
|
412
402
|
updateState(value) {
|
|
413
|
-
trace('
|
|
403
|
+
trace('vaultManager got new collateral quote', value);
|
|
414
404
|
ephemera.storedCollateralQuote = value;
|
|
415
405
|
},
|
|
416
406
|
fail(reason) {
|
|
@@ -419,7 +409,9 @@ export const prepareVaultManagerKit = (
|
|
|
419
409
|
});
|
|
420
410
|
trace('helper.start() done');
|
|
421
411
|
},
|
|
422
|
-
/**
|
|
412
|
+
/**
|
|
413
|
+
* @param {Timestamp} updateTime
|
|
414
|
+
*/
|
|
423
415
|
async chargeAllVaults(updateTime) {
|
|
424
416
|
const { state, facets } = this;
|
|
425
417
|
const { collateralBrand, debtMint, poolIncrementSeat } = state;
|
|
@@ -523,6 +515,7 @@ export const prepareVaultManagerKit = (
|
|
|
523
515
|
state.liquidatingDebt = AmountMath.add(state.liquidatingDebt, debt);
|
|
524
516
|
},
|
|
525
517
|
/**
|
|
518
|
+
*
|
|
526
519
|
* @param {Amount<'nat'>} debt
|
|
527
520
|
* @param {Amount<'nat'>} collateral
|
|
528
521
|
* @param {Amount<'nat'>} overage
|
|
@@ -605,18 +598,14 @@ export const prepareVaultManagerKit = (
|
|
|
605
598
|
},
|
|
606
599
|
|
|
607
600
|
/**
|
|
608
|
-
* This is designed to tolerate an incomplete plan, in case
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* manually in dev and verified this function recovers as expected.
|
|
601
|
+
* This is designed to tolerate an incomplete plan, in case calculateDistributionPlan encounters
|
|
602
|
+
* an error during its calculation. We don't have a way to induce such errors in CI so we've
|
|
603
|
+
* done so manually in dev and verified this function recovers as expected.
|
|
612
604
|
*
|
|
613
605
|
* @param {AmountKeywordRecord} proceeds
|
|
614
606
|
* @param {Amount<'nat'>} totalDebt
|
|
615
607
|
* @param {Pick<PriceQuote, 'quoteAmount'>} oraclePriceAtStart
|
|
616
|
-
* @param {MapStore<
|
|
617
|
-
* Vault,
|
|
618
|
-
* { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
|
|
619
|
-
* >} vaultData
|
|
608
|
+
* @param {MapStore<Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}>} vaultData
|
|
620
609
|
* @param {Amount<'nat'>} totalCollateral
|
|
621
610
|
*/
|
|
622
611
|
planProceedsDistribution(
|
|
@@ -672,14 +661,13 @@ export const prepareVaultManagerKit = (
|
|
|
672
661
|
},
|
|
673
662
|
|
|
674
663
|
/**
|
|
675
|
-
* This is designed to tolerate an incomplete plan, in case
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
* manually in dev and verified this function recovers as expected.
|
|
664
|
+
* This is designed to tolerate an incomplete plan, in case calculateDistributionPlan encounters
|
|
665
|
+
* an error during its calculation. We don't have a way to induce such errors in CI so we've
|
|
666
|
+
* done so manually in dev and verified this function recovers as expected.
|
|
679
667
|
*
|
|
680
668
|
* @param {object} obj
|
|
681
669
|
* @param {import('./proceeds.js').DistributionPlan} obj.plan
|
|
682
|
-
* @param {Vault
|
|
670
|
+
* @param {Array<Vault>} obj.vaultsInPlan
|
|
683
671
|
* @param {ZCFSeat} obj.liqSeat
|
|
684
672
|
* @param {Amount<'nat'>} obj.totalCollateral
|
|
685
673
|
* @param {Amount<'nat'>} obj.totalDebt
|
|
@@ -699,7 +687,7 @@ export const prepareVaultManagerKit = (
|
|
|
699
687
|
if (plan.transfersToVault.length > 0) {
|
|
700
688
|
const transfers = plan.transfersToVault.map(
|
|
701
689
|
([vaultIndex, amounts]) =>
|
|
702
|
-
/** @type {TransferPart} */ ([
|
|
690
|
+
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart} */ ([
|
|
703
691
|
liqSeat,
|
|
704
692
|
vaultsInPlan[vaultIndex].getVaultSeat(),
|
|
705
693
|
amounts,
|
|
@@ -852,7 +840,9 @@ export const prepareVaultManagerKit = (
|
|
|
852
840
|
const { descriptionScope } = this.state;
|
|
853
841
|
return `${descriptionScope}: ${base}`;
|
|
854
842
|
},
|
|
855
|
-
/**
|
|
843
|
+
/**
|
|
844
|
+
* coefficient on existing debt to calculate new debt
|
|
845
|
+
*/
|
|
856
846
|
getCompoundedInterest() {
|
|
857
847
|
return this.state.compoundedInterest;
|
|
858
848
|
},
|
|
@@ -862,8 +852,7 @@ export const prepareVaultManagerKit = (
|
|
|
862
852
|
* @param {NormalizedDebt} oldDebtNormalized
|
|
863
853
|
* @param {Amount<'nat'>} oldCollateral
|
|
864
854
|
* @param {VaultId} vaultId
|
|
865
|
-
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of
|
|
866
|
-
* whatever change updated balances
|
|
855
|
+
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of whatever change updated balances
|
|
867
856
|
* @param {Vault} vault
|
|
868
857
|
* @returns {void}
|
|
869
858
|
*/
|
|
@@ -948,7 +937,9 @@ export const prepareVaultManagerKit = (
|
|
|
948
937
|
return factoryPowers.getGovernedParams(collateralBrand);
|
|
949
938
|
},
|
|
950
939
|
|
|
951
|
-
/**
|
|
940
|
+
/**
|
|
941
|
+
* @param {ZCFSeat} seat
|
|
942
|
+
*/
|
|
952
943
|
async makeVaultKit(seat) {
|
|
953
944
|
const {
|
|
954
945
|
state,
|
|
@@ -972,6 +963,7 @@ export const prepareVaultManagerKit = (
|
|
|
972
963
|
|
|
973
964
|
try {
|
|
974
965
|
// TODO `await` is allowed until the above ordering is fixed
|
|
966
|
+
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
975
967
|
const vaultKit = await vault.initVaultKit(seat, vaultStorageNode);
|
|
976
968
|
// initVaultKit calls back to handleBalanceChange() which will add the
|
|
977
969
|
// vault to prioritizedVaults
|
|
@@ -1045,16 +1037,18 @@ export const prepareVaultManagerKit = (
|
|
|
1045
1037
|
if (!storedCollateralQuote)
|
|
1046
1038
|
throw Fail`lockOraclePrices called before a collateral quote was available`;
|
|
1047
1039
|
trace(
|
|
1048
|
-
`
|
|
1040
|
+
`lockPrice`,
|
|
1049
1041
|
getAmountIn(storedCollateralQuote),
|
|
1050
1042
|
getAmountOut(storedCollateralQuote),
|
|
1051
1043
|
);
|
|
1052
1044
|
|
|
1053
1045
|
state.lockedQuote = storedCollateralQuote;
|
|
1054
|
-
|
|
1046
|
+
facets.helper.writeMetrics();
|
|
1055
1047
|
return storedCollateralQuote;
|
|
1056
1048
|
},
|
|
1057
|
-
/**
|
|
1049
|
+
/**
|
|
1050
|
+
* @param {AuctioneerPublicFacet} auctionPF
|
|
1051
|
+
*/
|
|
1058
1052
|
async liquidateVaults(auctionPF) {
|
|
1059
1053
|
const { state, facets } = this;
|
|
1060
1054
|
const { self, helper } = facets;
|
|
@@ -1067,19 +1061,11 @@ export const prepareVaultManagerKit = (
|
|
|
1067
1061
|
} = state;
|
|
1068
1062
|
trace(collateralBrand, 'considering liquidation');
|
|
1069
1063
|
|
|
1070
|
-
if (!lockedQuote) {
|
|
1071
|
-
// By design, the first cycle of auction may call this before a quote is locked
|
|
1072
|
-
// because the schedule is global at the vaultDirector level, and if a manager
|
|
1073
|
-
// starts after the price lock time there's nothing to be done.
|
|
1074
|
-
// NB: this message should not log repeatedly.
|
|
1075
|
-
console.error(
|
|
1076
|
-
'Skipping liquidation because no quote is locked yet (may happen with new manager)',
|
|
1077
|
-
);
|
|
1078
|
-
return;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
1064
|
const { prioritizedVaults } = collateralEphemera(collateralBrand);
|
|
1082
|
-
|
|
1065
|
+
assert(factoryPowers && prioritizedVaults && zcf);
|
|
1066
|
+
lockedQuote ||
|
|
1067
|
+
Fail`Must have locked a quote before liquidating vaults.`;
|
|
1068
|
+
assert(lockedQuote); // redundant with previous line
|
|
1083
1069
|
|
|
1084
1070
|
const liqMargin = self.getGovernedParams().getLiquidationMargin();
|
|
1085
1071
|
|
|
@@ -1101,7 +1087,6 @@ export const prepareVaultManagerKit = (
|
|
|
1101
1087
|
state.lockedQuote = undefined;
|
|
1102
1088
|
|
|
1103
1089
|
if (vaultData.getSize() === 0) {
|
|
1104
|
-
void helper.writeMetrics();
|
|
1105
1090
|
return;
|
|
1106
1091
|
}
|
|
1107
1092
|
trace(
|
|
@@ -1165,7 +1150,7 @@ export const prepareVaultManagerKit = (
|
|
|
1165
1150
|
liquidatingVaults.delete(vault);
|
|
1166
1151
|
}
|
|
1167
1152
|
|
|
1168
|
-
|
|
1153
|
+
await facets.helper.writeMetrics();
|
|
1169
1154
|
},
|
|
1170
1155
|
},
|
|
1171
1156
|
},
|
|
@@ -1189,12 +1174,7 @@ export const prepareVaultManagerKit = (
|
|
|
1189
1174
|
},
|
|
1190
1175
|
);
|
|
1191
1176
|
|
|
1192
|
-
/**
|
|
1193
|
-
* @param {Omit<
|
|
1194
|
-
* Parameters<typeof makeVaultManagerKitInternal>[0],
|
|
1195
|
-
* 'metricsStorageNode'
|
|
1196
|
-
* >} externalParams
|
|
1197
|
-
*/
|
|
1177
|
+
/** @param {Omit<Parameters<typeof makeVaultManagerKitInternal>[0], 'metricsStorageNode'>} externalParams */
|
|
1198
1178
|
const makeVaultManagerKit = async externalParams => {
|
|
1199
1179
|
const metricsStorageNode = await E(
|
|
1200
1180
|
externalParams.storageNode,
|
|
@@ -1207,13 +1187,15 @@ export const prepareVaultManagerKit = (
|
|
|
1207
1187
|
return makeVaultManagerKit;
|
|
1208
1188
|
};
|
|
1209
1189
|
|
|
1210
|
-
/** @typedef {Awaited<ReturnType<ReturnType<typeof prepareVaultManagerKit>>>} VaultManagerKit */
|
|
1211
1190
|
/**
|
|
1212
|
-
* @typedef {
|
|
1213
|
-
|
|
1191
|
+
* @typedef {Awaited<ReturnType<ReturnType<typeof prepareVaultManagerKit>>>} VaultManagerKit
|
|
1192
|
+
*/
|
|
1193
|
+
/**
|
|
1194
|
+
* @typedef {VaultManagerKit['self']} VaultManager
|
|
1195
|
+
* Each VaultManager manages a single collateral type.
|
|
1214
1196
|
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1197
|
+
* It manages some number of outstanding debt positions, each called a Vault,
|
|
1198
|
+
* for which the collateral is provided in exchange for borrowed Minted.
|
|
1217
1199
|
*/
|
|
1218
1200
|
/** @typedef {VaultManagerKit['collateral']} CollateralManager */
|
|
1219
1201
|
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
export function makeOfferSpecShape(bidBrand: Brand<'nat'>, collateralBrand: Brand<'nat'>): any;
|
|
2
|
-
export function prepareAuctionBook(baggage: Baggage, zcf: ZCF, makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit): (bidBrand: Brand<"nat">, collateralBrand: Brand<"nat">, pAuthority: PriceAuthority, node: StorageNode) => {
|
|
3
|
-
/**
|
|
4
|
-
* @param {Amount<'nat'>} assetAmount
|
|
5
|
-
* @param {ZCFSeat} sourceSeat
|
|
6
|
-
* @param {Amount<'nat'>} [proceedsGoal] an amount that the depositor
|
|
7
|
-
* would like to raise. The auction is requested to not sell more
|
|
8
|
-
* collateral than required to raise that much. The auctioneer might
|
|
9
|
-
* sell more if there is more than one supplier of collateral, and
|
|
10
|
-
* they request inconsistent limits.
|
|
11
|
-
*/
|
|
12
|
-
addAssets(assetAmount: Amount<'nat'>, sourceSeat: ZCFSeat, proceedsGoal?: Amount<"nat"> | undefined): void;
|
|
13
|
-
/** @type {(reduction: Ratio) => void} */
|
|
14
|
-
settleAtNewRate(reduction: Ratio): void;
|
|
15
|
-
getCurrentPrice(): Ratio | null;
|
|
16
|
-
hasOrders(): boolean;
|
|
17
|
-
captureOraclePriceForRound(): void;
|
|
18
|
-
setStartingRate(rate: any): void;
|
|
19
|
-
/**
|
|
20
|
-
* @param {OfferSpec} offerSpec
|
|
21
|
-
* @param {ZCFSeat} seat
|
|
22
|
-
* @param {boolean} trySettle
|
|
23
|
-
*/
|
|
24
|
-
addOffer(offerSpec: OfferSpec, seat: ZCFSeat, trySettle: boolean): void;
|
|
25
|
-
getSeats(): {
|
|
26
|
-
collateralSeat: ZCFSeat;
|
|
27
|
-
bidHoldingSeat: ZCFSeat;
|
|
28
|
-
};
|
|
29
|
-
exitAllSeats(): void;
|
|
30
|
-
endAuction(): void;
|
|
31
|
-
getDataUpdates(): Subscriber<BookDataNotification>;
|
|
32
|
-
getPublicTopics(): {
|
|
33
|
-
bookData: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<BookDataNotification>;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export type OfferSpec = {
|
|
37
|
-
maxBuy: Amount<'nat'>;
|
|
38
|
-
} & {
|
|
39
|
-
exitAfterBuy?: boolean;
|
|
40
|
-
} & ({
|
|
41
|
-
offerPrice: Ratio;
|
|
42
|
-
} | {
|
|
43
|
-
offerBidScaling: Ratio;
|
|
44
|
-
});
|
|
45
|
-
export type Baggage = import('@agoric/vat-data').Baggage;
|
|
46
|
-
export type BookDataNotification = {
|
|
47
|
-
/**
|
|
48
|
-
* identifies the priceAuthority and price
|
|
49
|
-
*/
|
|
50
|
-
startPrice: Ratio | null;
|
|
51
|
-
/**
|
|
52
|
-
* the price at the current auction
|
|
53
|
-
* tier
|
|
54
|
-
*/
|
|
55
|
-
currentPriceLevel: Ratio | null;
|
|
56
|
-
/**
|
|
57
|
-
* The proceeds the sellers
|
|
58
|
-
* were targeting to raise
|
|
59
|
-
*/
|
|
60
|
-
startProceedsGoal: Amount<'nat'> | null;
|
|
61
|
-
/**
|
|
62
|
-
* The remainder of the
|
|
63
|
-
* proceeds the sellers were targeting to raise
|
|
64
|
-
*/
|
|
65
|
-
remainingProceedsGoal: Amount<'nat'> | null;
|
|
66
|
-
/**
|
|
67
|
-
* The proceeds raised so
|
|
68
|
-
* far in the auction
|
|
69
|
-
*/
|
|
70
|
-
proceedsRaised: Amount<'nat'> | undefined;
|
|
71
|
-
/**
|
|
72
|
-
* How much collateral was available
|
|
73
|
-
* for sale at the start. (If more is deposited later, it'll be added in.)
|
|
74
|
-
*/
|
|
75
|
-
startCollateral: Amount<'nat'>;
|
|
76
|
-
/**
|
|
77
|
-
* The amount of collateral
|
|
78
|
-
* remaining
|
|
79
|
-
*/
|
|
80
|
-
collateralAvailable: Amount<'nat'> | null;
|
|
81
|
-
};
|
|
82
|
-
export type AuctionBook = ReturnType<ReturnType<typeof prepareAuctionBook>>;
|
|
83
|
-
//# sourceMappingURL=auctionBook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auctionBook.d.ts","sourceRoot":"","sources":["auctionBook.js"],"names":[],"mappings":"AAyEO,6CAHI,MAAM,KAAK,CAAC,mBACZ,MAAM,KAAK,CAAC,OAiBtB;AA0BM,4CAJI,OAAO,OACP,GAAG,mBACH,OAAO,6CAA6C,EAAE,eAAe;IAwWxE;;;;;;;;OAQG;2BAPQ,OAAO,KAAK,CAAC,cACb,OAAO;IA6ElB,yCAAyC;+BAAlB,KAAK,GAAK,IAAI;;;;;IAsGrC;;;;OAIG;wBAHQ,SAAS,QACT,OAAO,aACP,OAAO;;;;;;;;;;;EAsHzB;wBA9sBY;IACZ,MAAU,EAAE,OAAO,KAAK,CAAC,CAAC;CACvB,GAAG;IACN,YAAgB,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,CACE;IACR,UAAoB,EAAE,KAAK,CAAC;CACnB,GACD;IACR,eAAyB,EAAE,KAAK,CAAC;CACxB,CACJ;sBAuBQ,OAAO,kBAAkB,EAAE,OAAO;;;;;gBAIlC,KAAK,GAAG,IAAI;;;;;uBACZ,KAAK,GAAG,IAAI;;;;;uBAEZ,OAAO,KAAK,CAAC,GAAG,IAAI;;;;;2BAEpB,OAAO,KAAK,CAAC,GAAG,IAAI;;;;;oBAEpB,OAAO,KAAK,CAAC,GAAG,SAAS;;;;;qBAEzB,OAAO,KAAK,CAAC;;;;;yBAEb,OAAO,KAAK,CAAC,GAAG,IAAI;;0BAgqBpB,WAAW,WAAW,yBAAyB,CAAC,CAAC"}
|