@agoric/inter-protocol 0.16.2-dev-7cc5def.0 → 0.16.2-u11.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/bundles/bundle-auctioneer-js-meta.json +722 -0
- package/bundles/bundle-auctioneer.js +1 -0
- package/bundles/bundle-econCommitteeCharter-js-meta.json +222 -242
- package/bundles/bundle-econCommitteeCharter.js +1 -1
- package/bundles/bundle-feeDistributor-js-meta.json +458 -0
- package/bundles/bundle-feeDistributor.js +1 -0
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +327 -343
- package/bundles/bundle-fluxAggregatorKit.js +1 -1
- package/bundles/bundle-psm-js-meta.json +308 -328
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-js-meta.json +662 -0
- package/bundles/bundle-reserve.js +1 -0
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
- package/bundles/bundle-scaledPriceAuthority.js +1 -0
- package/bundles/bundle-vaultFactory-js-meta.json +790 -0
- package/bundles/bundle-vaultFactory.js +1 -0
- package/package.json +31 -31
- 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 +56 -68
- 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 -22
- 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 +15 -16
- package/src/feeDistributor.js +33 -34
- package/src/interest.js +14 -20
- package/src/price/fluxAggregatorContract.js +45 -51
- package/src/price/fluxAggregatorKit.js +32 -47
- package/src/price/priceOracleKit.js +13 -11
- package/src/price/roundsManager.js +64 -52
- package/src/proposals/addAssetToVault.js +3 -15
- package/src/proposals/committee-proposal.js +9 -5
- package/src/proposals/core-proposal.js +7 -7
- package/src/proposals/econ-behaviors.js +32 -57
- package/src/proposals/price-feed-proposal.js +26 -59
- 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 +41 -33
- 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 -155
- package/src/proposals/addAssetToVault.d.ts.map +0 -1
- package/src/proposals/committee-proposal.d.ts +0 -121
- 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 -83
- 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
package/src/psm/psm.js
CHANGED
|
@@ -41,86 +41,80 @@ const { Fail } = assert;
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @file The Parity Stability Module supports efficiently minting/burning a
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* stable token at a specified fixed ratio to a reference stable token, which
|
|
45
|
+
* thereby acts as an anchor to provide additional stability. For flexible
|
|
46
|
+
* economic policies, the fee percentage for trading into and out of the stable
|
|
47
|
+
* token are specified separately.
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* @typedef {object} MetricsNotification
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @property {Amount<'nat'>}
|
|
56
|
-
*
|
|
57
|
-
* @property {Amount<'nat'>}
|
|
58
|
-
*
|
|
59
|
-
* @property {Amount<'nat'>}
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
51
|
+
* @typedef {object} MetricsNotification
|
|
52
|
+
* Metrics naming scheme is that nouns are present values and past-participles
|
|
53
|
+
* are accumulative.
|
|
54
|
+
*
|
|
55
|
+
* @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token
|
|
56
|
+
* available to be swapped
|
|
57
|
+
* @property {Amount<'nat'>} mintedPoolBalance amount of Minted token
|
|
58
|
+
* outstanding (the amount minted minus the amount burned).
|
|
59
|
+
* @property {Amount<'nat'>} feePoolBalance amount of Minted token
|
|
60
|
+
* fees available to be collected
|
|
61
|
+
*
|
|
62
|
+
* @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor
|
|
63
|
+
* ever given by this contract
|
|
64
|
+
* @property {Amount<'nat'>} totalMintedProvided running sum of Minted
|
|
65
|
+
* ever given by this contract
|
|
63
66
|
*/
|
|
64
67
|
|
|
65
68
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
[CONTRACT_ELECTORATE]: {
|
|
76
|
-
type: ParamTypes.INVITATION,
|
|
77
|
-
value: AmountShape,
|
|
78
|
-
},
|
|
79
|
-
WantMintedFee: {
|
|
80
|
-
type: ParamTypes.RATIO,
|
|
81
|
-
value: RatioShape,
|
|
82
|
-
},
|
|
83
|
-
GiveMintedFee: {
|
|
84
|
-
type: ParamTypes.RATIO,
|
|
85
|
-
value: RatioShape,
|
|
86
|
-
},
|
|
87
|
-
MintLimit: { type: ParamTypes.AMOUNT, value: AmountShape },
|
|
70
|
+
export const customTermsShape = {
|
|
71
|
+
anchorBrand: BrandShape,
|
|
72
|
+
anchorPerMinted: RatioShape,
|
|
73
|
+
electionManager: InstanceHandleShape,
|
|
74
|
+
governedParams: {
|
|
75
|
+
[CONTRACT_ELECTORATE]: {
|
|
76
|
+
type: ParamTypes.INVITATION,
|
|
77
|
+
value: AmountShape,
|
|
88
78
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
marshaller: M.remotable('Marshaller'),
|
|
93
|
-
storageNode: StorageNodeShape,
|
|
79
|
+
WantMintedFee: {
|
|
80
|
+
type: ParamTypes.RATIO,
|
|
81
|
+
value: RatioShape,
|
|
94
82
|
},
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
initialPoserInvitation: InvitationShape,
|
|
83
|
+
GiveMintedFee: {
|
|
84
|
+
type: ParamTypes.RATIO,
|
|
85
|
+
value: RatioShape,
|
|
99
86
|
},
|
|
100
|
-
|
|
87
|
+
MintLimit: { type: ParamTypes.AMOUNT, value: AmountShape },
|
|
88
|
+
},
|
|
101
89
|
};
|
|
102
|
-
harden(
|
|
90
|
+
harden(customTermsShape);
|
|
91
|
+
|
|
92
|
+
export const privateArgsShape = M.splitRecord(
|
|
93
|
+
harden({
|
|
94
|
+
marshaller: M.remotable('Marshaller'),
|
|
95
|
+
storageNode: StorageNodeShape,
|
|
96
|
+
}),
|
|
97
|
+
harden({
|
|
98
|
+
// only necessary on first invocation, not subsequent
|
|
99
|
+
feeMintAccess: FeeMintAccessShape,
|
|
100
|
+
initialPoserInvitation: InvitationShape,
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
harden(privateArgsShape);
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
|
-
* @param {ZCF<
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* MintLimit: 'amount';
|
|
106
|
+
* @param {ZCF<GovernanceTerms<{
|
|
107
|
+
* GiveMintedFee: 'ratio',
|
|
108
|
+
* WantMintedFee: 'ratio',
|
|
109
|
+
* MintLimit: 'amount',
|
|
110
110
|
* }> & {
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @param {{
|
|
116
|
-
* feeMintAccess: FeeMintAccess;
|
|
117
|
-
* initialPoserInvitation: Invitation;
|
|
118
|
-
* storageNode: StorageNode;
|
|
119
|
-
* marshaller: Marshaller;
|
|
120
|
-
* }} privateArgs
|
|
111
|
+
* anchorBrand: Brand<'nat'>,
|
|
112
|
+
* anchorPerMinted: Ratio,
|
|
113
|
+
* }>} zcf
|
|
114
|
+
* @param {{feeMintAccess: FeeMintAccess, initialPoserInvitation: Invitation, storageNode: StorageNode, marshaller: Marshaller}} privateArgs
|
|
121
115
|
* @param {Baggage} baggage
|
|
122
116
|
*/
|
|
123
|
-
export const
|
|
117
|
+
export const prepare = async (zcf, privateArgs, baggage) => {
|
|
124
118
|
const { anchorBrand, anchorPerMinted } = zcf.getTerms();
|
|
125
119
|
console.log('PSM Starting', anchorBrand, anchorPerMinted);
|
|
126
120
|
|
|
@@ -237,7 +231,9 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
237
231
|
updateMetrics();
|
|
238
232
|
};
|
|
239
233
|
|
|
240
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* @param {Amount<'nat'>} toMint
|
|
236
|
+
*/
|
|
241
237
|
const assertUnderLimit = toMint => {
|
|
242
238
|
const mintedAfter = AmountMath.add(
|
|
243
239
|
baggage.get('mintedPoolBalance'),
|
|
@@ -266,8 +262,7 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
266
262
|
/**
|
|
267
263
|
* @param {ZCFSeat} seat
|
|
268
264
|
* @param {Amount<'nat'>} given
|
|
269
|
-
* @param {Amount<'nat'>} [wanted] defaults to maximum anchor (given exchange
|
|
270
|
-
* rate minus fees)
|
|
265
|
+
* @param {Amount<'nat'>} [wanted] defaults to maximum anchor (given exchange rate minus fees)
|
|
271
266
|
*/
|
|
272
267
|
const giveMinted = (seat, given, wanted = emptyAnchor) => {
|
|
273
268
|
const fee = ceilMultiplyBy(given, params.getGiveMintedFee());
|
|
@@ -445,6 +440,5 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
445
440
|
publicFacet,
|
|
446
441
|
});
|
|
447
442
|
};
|
|
448
|
-
harden(start);
|
|
449
443
|
|
|
450
|
-
/** @typedef {Awaited<ReturnType<typeof
|
|
444
|
+
/** @typedef {Awaited<ReturnType<typeof prepare>>['publicFacet']} PsmPublicFacet */
|
|
@@ -10,42 +10,36 @@ import { prepareAssetReserveKit } from './assetReserveKit.js';
|
|
|
10
10
|
|
|
11
11
|
const trace = makeTracer('AR', true);
|
|
12
12
|
|
|
13
|
-
/** @type {ContractMeta} */
|
|
14
|
-
export const meta = {
|
|
15
|
-
upgradability: 'canUpgrade',
|
|
16
|
-
};
|
|
17
|
-
harden(meta);
|
|
18
|
-
|
|
19
13
|
/**
|
|
20
14
|
* @typedef {{
|
|
21
|
-
* increaseLiquidationShortfall: (increase: Amount) => void
|
|
22
|
-
* reduceLiquidationShortfall: (reduction: Amount) => void
|
|
15
|
+
* increaseLiquidationShortfall: (increase: Amount) => void
|
|
16
|
+
* reduceLiquidationShortfall: (reduction: Amount) => void
|
|
23
17
|
* }} ShortfallReportingFacet
|
|
24
18
|
*/
|
|
25
19
|
|
|
26
20
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
27
21
|
|
|
28
22
|
/**
|
|
29
|
-
* Asset Reserve holds onto assets for the Inter Protocol, and can
|
|
30
|
-
* for various purposes under governance control.
|
|
23
|
+
* Asset Reserve holds onto assets for the Inter Protocol, and can
|
|
24
|
+
* dispense it for various purposes under governance control.
|
|
31
25
|
*
|
|
32
26
|
* This contract has the ability to mint Fee tokens, granted through its private
|
|
33
27
|
* arguments.
|
|
34
28
|
*
|
|
35
|
-
* @param {ZCF<
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
29
|
+
* @param {ZCF<GovernanceTerms<{}> &
|
|
30
|
+
* {
|
|
31
|
+
* governedApis: ['burnFeesToReduceShortfall'],
|
|
32
|
+
* }
|
|
39
33
|
* >} zcf
|
|
40
34
|
* @param {{
|
|
41
|
-
* feeMintAccess: FeeMintAccess
|
|
42
|
-
* initialPoserInvitation: Invitation
|
|
43
|
-
* marshaller: ERef<Marshaller
|
|
44
|
-
* storageNode: ERef<StorageNode
|
|
35
|
+
* feeMintAccess: FeeMintAccess,
|
|
36
|
+
* initialPoserInvitation: Invitation,
|
|
37
|
+
* marshaller: ERef<Marshaller>,
|
|
38
|
+
* storageNode: ERef<StorageNode>,
|
|
45
39
|
* }} privateArgs
|
|
46
40
|
* @param {Baggage} baggage
|
|
47
41
|
*/
|
|
48
|
-
export const
|
|
42
|
+
export const prepare = async (zcf, privateArgs, baggage) => {
|
|
49
43
|
trace('prepare', Object.keys(privateArgs), [...baggage.keys()]);
|
|
50
44
|
// This contract mixes two styles of access to durable state. durableStores
|
|
51
45
|
// are declared at the top level and referenced lexically. local state is
|
|
@@ -72,11 +66,11 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
72
66
|
};
|
|
73
67
|
trace('awaiting takeFeeMint');
|
|
74
68
|
const feeMint = await takeFeeMint();
|
|
75
|
-
const storageNode = await privateArgs.storageNode;
|
|
76
69
|
const makeAssetReserveKit = await prepareAssetReserveKit(baggage, {
|
|
77
70
|
feeMint,
|
|
78
71
|
makeRecorderKit,
|
|
79
|
-
|
|
72
|
+
// eslint-disable-next-line @jessie.js/no-nested-await -- spurious
|
|
73
|
+
storageNode: await privateArgs.storageNode,
|
|
80
74
|
zcf,
|
|
81
75
|
});
|
|
82
76
|
|
|
@@ -112,7 +106,7 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
112
106
|
publicFacet: /** @type {any} */ (assetReserveKit.public),
|
|
113
107
|
};
|
|
114
108
|
};
|
|
115
|
-
harden(
|
|
109
|
+
harden(prepare);
|
|
116
110
|
|
|
117
111
|
/**
|
|
118
112
|
* @typedef {object} ShortfallReporter
|
|
@@ -127,8 +121,5 @@ harden(start);
|
|
|
127
121
|
* @property {() => Promise<Invitation<ShortfallReporter>>} makeShortfallReportingInvitation
|
|
128
122
|
*/
|
|
129
123
|
|
|
130
|
-
/** @typedef {Awaited<ReturnType<typeof
|
|
131
|
-
/**
|
|
132
|
-
* @typedef {Awaited<ReturnType<typeof start>>['creatorFacet']} AssetReserveCreatorFacet
|
|
133
|
-
* the creator facet for the governor
|
|
134
|
-
*/
|
|
124
|
+
/** @typedef {Awaited<ReturnType<typeof prepare>>['publicFacet']} AssetReservePublicFacet */
|
|
125
|
+
/** @typedef {Awaited<ReturnType<typeof prepare>>['creatorFacet']} AssetReserveCreatorFacet the creator facet for the governor */
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@agoric/zoe/src/contractSupport/topics.js';
|
|
10
10
|
import { AmountKeywordRecordShape } from '@agoric/zoe/src/typeGuards.js';
|
|
11
11
|
import { E } from '@endo/eventual-send';
|
|
12
|
-
import { UnguardedHelperI } from '
|
|
12
|
+
import { UnguardedHelperI } from '../typeGuards.js';
|
|
13
13
|
|
|
14
14
|
const { quote: q } = assert;
|
|
15
15
|
|
|
@@ -17,6 +17,7 @@ const trace = makeTracer('ReserveKit', true);
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @typedef {object} MetricsNotification
|
|
20
|
+
*
|
|
20
21
|
* @property {AmountKeywordRecord} allocations
|
|
21
22
|
* @property {Amount<'nat'>} shortfallBalance shortfall from liquidation that
|
|
22
23
|
* has not yet been compensated.
|
|
@@ -27,11 +28,10 @@ const trace = makeTracer('ReserveKit', true);
|
|
|
27
28
|
/**
|
|
28
29
|
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
29
30
|
* @param {{
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* }} powers
|
|
31
|
+
* feeMint: ZCFMint<'nat'>,
|
|
32
|
+
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit,
|
|
33
|
+
* storageNode: StorageNode,
|
|
34
|
+
* zcf: ZCF}} powers
|
|
35
35
|
*/
|
|
36
36
|
export const prepareAssetReserveKit = async (
|
|
37
37
|
baggage,
|
|
@@ -63,7 +63,10 @@ export const prepareAssetReserveKit = async (
|
|
|
63
63
|
reduceLiquidationShortfall: M.call(AmountShape).returns(),
|
|
64
64
|
}),
|
|
65
65
|
},
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param {StorageNode} metricsNode
|
|
69
|
+
*/
|
|
67
70
|
metricsNode => {
|
|
68
71
|
/**
|
|
69
72
|
* Used to look up the unique keyword for each brand, including Fee brand.
|
|
@@ -74,8 +77,7 @@ export const prepareAssetReserveKit = async (
|
|
|
74
77
|
durable: true,
|
|
75
78
|
});
|
|
76
79
|
/**
|
|
77
|
-
* Used to look up the brands for keywords, excluding Fee because it's a
|
|
78
|
-
* special case.
|
|
80
|
+
* Used to look up the brands for keywords, excluding Fee because it's a special case.
|
|
79
81
|
*
|
|
80
82
|
* @type {MapStore<Keyword, Brand>}
|
|
81
83
|
*/
|
|
@@ -135,6 +137,7 @@ export const prepareAssetReserveKit = async (
|
|
|
135
137
|
},
|
|
136
138
|
governedApis: {
|
|
137
139
|
/**
|
|
140
|
+
*
|
|
138
141
|
* @param {Amount<'nat'>} reduction
|
|
139
142
|
* @returns {void}
|
|
140
143
|
*/
|
|
@@ -202,11 +205,12 @@ export const prepareAssetReserveKit = async (
|
|
|
202
205
|
},
|
|
203
206
|
},
|
|
204
207
|
/**
|
|
205
|
-
* XXX missing governance public methods
|
|
206
|
-
* https://github.com/Agoric/agoric-sdk/issues/5200
|
|
208
|
+
* XXX missing governance public methods https://github.com/Agoric/agoric-sdk/issues/5200
|
|
207
209
|
*/
|
|
208
210
|
public: {
|
|
209
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Anyone can deposit any assets to the reserve
|
|
213
|
+
*/
|
|
210
214
|
makeAddCollateralInvitation() {
|
|
211
215
|
/** @type {OfferHandler<Promise<string>>} */
|
|
212
216
|
const handler = async seat => {
|
|
@@ -243,7 +247,9 @@ export const prepareAssetReserveKit = async (
|
|
|
243
247
|
},
|
|
244
248
|
},
|
|
245
249
|
shortfallReportingFacet: {
|
|
246
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* @param {Amount<"nat">} shortfall
|
|
252
|
+
*/
|
|
247
253
|
increaseLiquidationShortfall(shortfall) {
|
|
248
254
|
const { facets, state } = this;
|
|
249
255
|
state.shortfallBalance = AmountMath.add(
|
|
@@ -254,7 +260,9 @@ export const prepareAssetReserveKit = async (
|
|
|
254
260
|
},
|
|
255
261
|
|
|
256
262
|
// currently exposed for testing. Maybe it only gets called internally?
|
|
257
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* @param {Amount<"nat">} reduction
|
|
265
|
+
*/
|
|
258
266
|
reduceLiquidationShortfall(reduction) {
|
|
259
267
|
const { state } = this;
|
|
260
268
|
if (AmountMath.isGTE(reduction, state.shortfallBalance)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @jessie-check
|
|
2
|
+
|
|
3
|
+
import { M } from '@agoric/store';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* To be used only for 'helper' facets where the calls are from trusted code.
|
|
7
|
+
*/
|
|
8
|
+
export const UnguardedHelperI = M.interface(
|
|
9
|
+
'helper',
|
|
10
|
+
{},
|
|
11
|
+
// not exposed so sloppy okay
|
|
12
|
+
{ sloppy: true },
|
|
13
|
+
);
|
|
@@ -22,8 +22,7 @@ const makeCancelToken = makeCancelTokenMaker('liq');
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* This will normally be set. If the schedule goes sideways, we'll unschedule
|
|
25
|
-
* all events and unset it. When auction params are changed, we'll restart the
|
|
26
|
-
* schedule
|
|
25
|
+
* all events and unset it. When auction params are changed, we'll restart the schedule
|
|
27
26
|
*
|
|
28
27
|
* @type {object | undefined}
|
|
29
28
|
*/
|
|
@@ -48,16 +47,15 @@ const cancelWakeups = timer => {
|
|
|
48
47
|
};
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
|
-
* Schedule wakeups for the
|
|
50
|
+
* Schedule wakeups for the *next* auction round.
|
|
52
51
|
*
|
|
53
|
-
* In practice, there are these cases to handle (with N as "live" and N+1 is
|
|
54
|
-
* "next"):
|
|
52
|
+
* In practice, there are these cases to handle (with N as "live" and N+1 is "next"):
|
|
55
53
|
*
|
|
56
|
-
* | when (now within the range)
|
|
57
|
-
* |
|
|
58
|
-
* | [start N, nominalStart N+1]
|
|
59
|
-
* | (nominalStart N+1, endTime N+1]
|
|
60
|
-
* | (endTime N+1, ∞)
|
|
54
|
+
* | when (now within the range) | what |
|
|
55
|
+
* | -------------------------------- | --------------------------------------- |
|
|
56
|
+
* | [start N, nominalStart N+1] | good: schedule normally the three wakers|
|
|
57
|
+
* | (nominalStart N+1, endTime N+1] | recover: skip round N+1 and schedule N+2|
|
|
58
|
+
* | (endTime N+1, ∞) | give up: wait for repair by governance |
|
|
61
59
|
*
|
|
62
60
|
* @param {object} opts
|
|
63
61
|
* @param {ERef<TimerService>} opts.timer
|
|
@@ -134,7 +132,7 @@ const setWakeups = ({
|
|
|
134
132
|
};
|
|
135
133
|
|
|
136
134
|
/**
|
|
137
|
-
* Schedule wakeups for the
|
|
135
|
+
* Schedule wakeups for the *next* auction round.
|
|
138
136
|
*
|
|
139
137
|
* Called by vaultDirector's resetWakeupsForNextAuction at start() and every
|
|
140
138
|
* time there's a "reschedule" wakeup.
|
|
@@ -187,7 +185,7 @@ harden(setWakeupsForNextAuction);
|
|
|
187
185
|
/**
|
|
188
186
|
* @param {Amount<'nat'>} debt
|
|
189
187
|
* @param {Amount<'nat'>} minted
|
|
190
|
-
* @returns {{ overage: Amount<'nat'
|
|
188
|
+
* @returns {{ overage: Amount<'nat'>, shortfall: Amount<'nat'>}}
|
|
191
189
|
*/
|
|
192
190
|
export const liquidationResults = (debt, minted) => {
|
|
193
191
|
if (AmountMath.isEmpty(minted)) {
|
|
@@ -242,21 +240,15 @@ export const watchForGovernanceChange = (
|
|
|
242
240
|
* @param {PriceQuote} collateralizationDetails.quote
|
|
243
241
|
* @param {Ratio} collateralizationDetails.interest
|
|
244
242
|
* @param {Ratio} collateralizationDetails.margin
|
|
245
|
-
* @param {ReturnType<
|
|
246
|
-
* typeof import('./prioritizedVaults.js').makePrioritizedVaults
|
|
247
|
-
* >} prioritizedVaults
|
|
243
|
+
* @param {ReturnType<typeof import('./prioritizedVaults.js').makePrioritizedVaults>} prioritizedVaults
|
|
248
244
|
* @param {SetStore<Vault>} liquidatingVaults
|
|
249
245
|
* @param {Brand<'nat'>} debtBrand
|
|
250
246
|
* @param {Brand<'nat'>} collateralBrand
|
|
251
247
|
* @returns {{
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* totalDebt: Amount<'nat'>;
|
|
257
|
-
* totalCollateral: Amount<'nat'>;
|
|
258
|
-
* liqSeat: ZCFSeat;
|
|
259
|
-
* }}
|
|
248
|
+
* vaultData: MapStore<Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}>,
|
|
249
|
+
* totalDebt: Amount<'nat'>,
|
|
250
|
+
* totalCollateral: Amount<'nat'>,
|
|
251
|
+
* liqSeat: ZCFSeat}}
|
|
260
252
|
*/
|
|
261
253
|
export const getLiquidatableVaults = (
|
|
262
254
|
zcf,
|
|
@@ -269,18 +261,13 @@ export const getLiquidatableVaults = (
|
|
|
269
261
|
const vaultsToLiquidate = prioritizedVaults.removeVaultsBelow(
|
|
270
262
|
collateralizationDetails,
|
|
271
263
|
);
|
|
272
|
-
/**
|
|
273
|
-
* @type {MapStore<
|
|
274
|
-
* Vault,
|
|
275
|
-
* { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
|
|
276
|
-
* >}
|
|
277
|
-
*/
|
|
264
|
+
/** @type {MapStore<Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}>} */
|
|
278
265
|
const vaultData = makeScalarMapStore();
|
|
279
266
|
|
|
280
267
|
const { zcfSeat: liqSeat } = zcf.makeEmptySeatKit();
|
|
281
268
|
let totalDebt = AmountMath.makeEmpty(debtBrand);
|
|
282
269
|
let totalCollateral = AmountMath.makeEmpty(collateralBrand);
|
|
283
|
-
/** @type {TransferPart[]} */
|
|
270
|
+
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
|
|
284
271
|
const transfers = [];
|
|
285
272
|
|
|
286
273
|
for (const vault of vaultsToLiquidate.values()) {
|
package/src/vaultFactory/math.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file calculations specific to the Vault Factory contract
|
|
5
|
-
*
|
|
4
|
+
* @file calculations specific to the Vault Factory contract
|
|
5
|
+
* See also ../interest-math.js
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { AmountMath } from '@agoric/ertp';
|
|
@@ -17,8 +17,8 @@ import { priceFrom } from '../auction/util.js';
|
|
|
17
17
|
import { addSubtract } from '../contractSupport.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Calculate the minimum collateralization given the liquidation margin and the
|
|
21
|
-
*
|
|
20
|
+
* Calculate the minimum collateralization given the liquidation margin and the "padding"
|
|
21
|
+
* from that liquidation threshold.
|
|
22
22
|
*
|
|
23
23
|
* @param {Ratio} liquidationMargin
|
|
24
24
|
* @param {Ratio} liquidationPadding
|
|
@@ -74,10 +74,11 @@ export const maxDebtForVault = (
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* Calculate the fee, the amount to mint and the resulting debt.
|
|
78
|
-
* the want together reflect a delta, where typically
|
|
79
|
-
* come from the gave/want of an offer
|
|
80
|
-
* `fee` will also be zero,
|
|
77
|
+
* Calculate the fee, the amount to mint and the resulting debt.
|
|
78
|
+
* The give and the want together reflect a delta, where typically
|
|
79
|
+
* one is zero because they come from the gave/want of an offer
|
|
80
|
+
* proposal. If the `want` is zero, the `fee` will also be zero,
|
|
81
|
+
* so the simple math works.
|
|
81
82
|
*
|
|
82
83
|
* @param {Amount<'nat'>} currentDebt
|
|
83
84
|
* @param {Amount<'nat'>} give excess of currentDebt is returned in 'surplus'
|
|
@@ -3,20 +3,22 @@ import { fromVaultKey, toVaultKey } from './storeUtils.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Used by prioritizedVaults to wrap the Collections API for this use case.
|
|
5
5
|
*
|
|
6
|
-
* Designed to be replaceable by naked Collections API when composite keys are
|
|
7
|
-
* available.
|
|
6
|
+
* Designed to be replaceable by naked Collections API when composite keys are available.
|
|
8
7
|
*
|
|
9
|
-
* In this module debts are encoded as the inverse quotient (collateral over
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* In this module debts are encoded as the inverse quotient (collateral over debt) so that
|
|
9
|
+
* greater collateralization sorts after lower. (Higher debt-to-collateral come
|
|
10
|
+
* first.)
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
/** @typedef {import('./vault').Vault} Vault */
|
|
15
14
|
/** @typedef {import('./storeUtils').CompositeKey} CompositeKey */
|
|
16
15
|
|
|
17
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* @param {MapStore<string, Vault>} store
|
|
18
|
+
*/
|
|
18
19
|
export const makeOrderedVaultStore = store => {
|
|
19
20
|
/**
|
|
21
|
+
*
|
|
20
22
|
* @param {string} vaultId
|
|
21
23
|
* @param {Vault} vault
|
|
22
24
|
*/
|
|
@@ -29,6 +31,7 @@ export const makeOrderedVaultStore = store => {
|
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
/**
|
|
34
|
+
*
|
|
32
35
|
* @param {string} key
|
|
33
36
|
* @returns {Vault}
|
|
34
37
|
*/
|
|
@@ -75,11 +75,7 @@ const makeVaultDirectorParams = (
|
|
|
75
75
|
};
|
|
76
76
|
harden(makeVaultDirectorParams);
|
|
77
77
|
|
|
78
|
-
/**
|
|
79
|
-
* @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').ParamTypesMapFromRecord<
|
|
80
|
-
* ReturnType<typeof makeVaultDirectorParams>
|
|
81
|
-
* >} VaultDirectorParams
|
|
82
|
-
*/
|
|
78
|
+
/** @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').ParamTypesMapFromRecord<ReturnType<typeof makeVaultDirectorParams>>} VaultDirectorParams */
|
|
83
79
|
|
|
84
80
|
/** @type {(liquidationMargin: Ratio) => Ratio} */
|
|
85
81
|
const zeroRatio = liquidationMargin =>
|
|
@@ -126,16 +122,16 @@ export const vaultParamPattern = M.splitRecord(
|
|
|
126
122
|
|
|
127
123
|
/**
|
|
128
124
|
* @param {{
|
|
129
|
-
* auctioneerPublicFacet: ERef<AuctioneerPublicFacet
|
|
130
|
-
* electorateInvitationAmount: Amount<'set'
|
|
131
|
-
* minInitialDebt: Amount<'nat'
|
|
132
|
-
* bootstrapPaymentValue: bigint
|
|
133
|
-
* priceAuthority: ERef<PriceAuthority
|
|
134
|
-
* timer: ERef<import('@agoric/time/src/types').TimerService
|
|
135
|
-
* reservePublicFacet: AssetReservePublicFacet
|
|
136
|
-
* interestTiming: InterestTiming
|
|
137
|
-
* shortfallInvitationAmount: Amount<'set'
|
|
138
|
-
* referencedUi?: string
|
|
125
|
+
* auctioneerPublicFacet: ERef<AuctioneerPublicFacet>,
|
|
126
|
+
* electorateInvitationAmount: Amount<'set'>,
|
|
127
|
+
* minInitialDebt: Amount<'nat'>,
|
|
128
|
+
* bootstrapPaymentValue: bigint,
|
|
129
|
+
* priceAuthority: ERef<PriceAuthority>,
|
|
130
|
+
* timer: ERef<import('@agoric/time/src/types').TimerService>,
|
|
131
|
+
* reservePublicFacet: AssetReservePublicFacet,
|
|
132
|
+
* interestTiming: InterestTiming,
|
|
133
|
+
* shortfallInvitationAmount: Amount<'set'>,
|
|
134
|
+
* referencedUi?: string,
|
|
139
135
|
* }} opts
|
|
140
136
|
*/
|
|
141
137
|
export const makeGovernedTerms = ({
|
|
@@ -167,8 +163,8 @@ export const makeGovernedTerms = ({
|
|
|
167
163
|
};
|
|
168
164
|
harden(makeGovernedTerms);
|
|
169
165
|
/**
|
|
170
|
-
* Stop-gap which restores initial param values
|
|
171
|
-
* https://github.com/Agoric/agoric-sdk/issues/5200
|
|
166
|
+
* Stop-gap which restores initial param values
|
|
167
|
+
* UNTIL https://github.com/Agoric/agoric-sdk/issues/5200
|
|
172
168
|
*
|
|
173
169
|
* NB: changes from initial values will be lost upon restart
|
|
174
170
|
*
|
|
@@ -180,12 +176,7 @@ export const provideVaultParamManagers = (baggage, marshaller) => {
|
|
|
180
176
|
const managers = makeScalarMapStore();
|
|
181
177
|
|
|
182
178
|
// the managers aren't durable but their arguments are
|
|
183
|
-
/**
|
|
184
|
-
* @type {MapStore<
|
|
185
|
-
* Brand,
|
|
186
|
-
* { storageNode: StorageNode; initialParamValues: VaultManagerParamValues }
|
|
187
|
-
* >}
|
|
188
|
-
*/
|
|
179
|
+
/** @type {MapStore<Brand, {storageNode: StorageNode, initialParamValues: VaultManagerParamValues}>} */
|
|
189
180
|
const managerArgs = provideDurableMapStore(
|
|
190
181
|
baggage,
|
|
191
182
|
'vault param manager parts',
|
|
@@ -205,6 +196,7 @@ export const provideVaultParamManagers = (baggage, marshaller) => {
|
|
|
205
196
|
|
|
206
197
|
return {
|
|
207
198
|
/**
|
|
199
|
+
*
|
|
208
200
|
* @param {Brand} brand
|
|
209
201
|
* @param {StorageNode} storageNode
|
|
210
202
|
* @param {VaultManagerParamValues} initialParamValues
|
|
@@ -214,7 +206,9 @@ export const provideVaultParamManagers = (baggage, marshaller) => {
|
|
|
214
206
|
managerArgs.init(brand, args);
|
|
215
207
|
return makeManager(brand, args);
|
|
216
208
|
},
|
|
217
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* @param {Brand} brand
|
|
211
|
+
*/
|
|
218
212
|
get(brand) {
|
|
219
213
|
return managers.get(brand);
|
|
220
214
|
},
|
|
@@ -47,8 +47,8 @@ export const currentDebtToCollateral = vault =>
|
|
|
47
47
|
* Vaults, ordered by their debt ratio so that all the vaults below a threshold
|
|
48
48
|
* can be quickly found and liquidated.
|
|
49
49
|
*
|
|
50
|
-
* @param {MapStore<string, Vault>} store
|
|
51
|
-
*
|
|
50
|
+
* @param {MapStore<string, Vault>} store
|
|
51
|
+
* vault has a higher debt ratio than the previous highest
|
|
52
52
|
*/
|
|
53
53
|
export const makePrioritizedVaults = store => {
|
|
54
54
|
const vaults = makeOrderedVaultStore(store);
|