@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
|
@@ -11,32 +11,27 @@ import { liquidationResults } from './liquidation.js';
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @typedef {{
|
|
14
|
-
* overage: Amount<'nat'
|
|
15
|
-
* shortfallToReserve: Amount<'nat'
|
|
16
|
-
* collateralForReserve: Amount<'nat'
|
|
17
|
-
* actualCollateralSold: Amount<'nat'
|
|
18
|
-
* collateralSold: Amount<'nat'
|
|
19
|
-
* collatRemaining: Amount<'nat'
|
|
20
|
-
* debtToBurn: Amount<'nat'
|
|
21
|
-
* mintedForReserve: Amount<'nat'
|
|
22
|
-
* mintedProceeds: Amount<'nat'
|
|
23
|
-
* phantomDebt: Amount<'nat'
|
|
24
|
-
* totalPenalty: Amount<'nat'
|
|
25
|
-
* transfersToVault: [number, AmountKeywordRecord]
|
|
26
|
-
* vaultsToReinstate: number
|
|
14
|
+
* overage: Amount<'nat'>,
|
|
15
|
+
* shortfallToReserve: Amount<'nat'>,
|
|
16
|
+
* collateralForReserve: Amount<'nat'>,
|
|
17
|
+
* actualCollateralSold: Amount<'nat'>,
|
|
18
|
+
* collateralSold: Amount<'nat'>,
|
|
19
|
+
* collatRemaining: Amount<'nat'>,
|
|
20
|
+
* debtToBurn: Amount<'nat'>,
|
|
21
|
+
* mintedForReserve: Amount<'nat'>,
|
|
22
|
+
* mintedProceeds: Amount<'nat'>,
|
|
23
|
+
* phantomDebt: Amount<'nat'>,
|
|
24
|
+
* totalPenalty: Amount<'nat'>,
|
|
25
|
+
* transfersToVault: Array<[number, AmountKeywordRecord]>,
|
|
26
|
+
* vaultsToReinstate: Array<number>
|
|
27
27
|
* }} DistributionPlan
|
|
28
|
-
* The plan to execute for distributing proceeds of a liquidation.
|
|
29
28
|
*
|
|
30
|
-
*
|
|
29
|
+
* The plan to execute for distributing proceeds of a liquidation.
|
|
30
|
+
*
|
|
31
|
+
* Vaults are referenced by index in the list sent to the calculator.
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {{
|
|
35
|
-
* collateral: Amount<'nat'>;
|
|
36
|
-
* presaleDebt: Amount<'nat'>;
|
|
37
|
-
* currentDebt: Amount<'nat'>;
|
|
38
|
-
* }} VaultBalances
|
|
39
|
-
*/
|
|
34
|
+
/** @typedef {{ collateral: Amount<'nat'>, presaleDebt: Amount<'nat'>, currentDebt: Amount<'nat'> }} VaultBalances */
|
|
40
35
|
|
|
41
36
|
/**
|
|
42
37
|
* Liquidation.md describes how to process liquidation proceeds.
|
|
@@ -51,8 +46,7 @@ import { liquidationResults } from './liquidation.js';
|
|
|
51
46
|
* @param {Amount<'nat'>} inputs.totalDebt
|
|
52
47
|
* @param {Amount<'nat'>} inputs.totalCollateral
|
|
53
48
|
* @param {PriceDescription} inputs.oraclePriceAtStart
|
|
54
|
-
* @param {VaultBalances
|
|
55
|
-
* collateralized
|
|
49
|
+
* @param {Array<VaultBalances>} inputs.vaultsBalances ordered best to worst collateralized
|
|
56
50
|
* @param {Ratio} inputs.penaltyRate
|
|
57
51
|
* @returns {DistributionPlan}
|
|
58
52
|
*/
|
|
@@ -19,9 +19,13 @@ const { multiply } = natSafeMath;
|
|
|
19
19
|
|
|
20
20
|
const trace = makeTracer('Store', true);
|
|
21
21
|
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {import('@endo/marshal').PureData} PureData
|
|
24
|
+
*/
|
|
23
25
|
|
|
24
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {[normalizedCollateralization: number, vaultId: VaultId]} CompositeKey
|
|
28
|
+
*/
|
|
25
29
|
|
|
26
30
|
// `makeEncodePassable` has three named options:
|
|
27
31
|
// `encodeRemotable`, `encodeError`, and `encodePromise`.
|
|
@@ -65,12 +69,12 @@ const decodeNumber = encoded => {
|
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
// Type annotations to support static testing of amount values
|
|
68
|
-
/** @typedef {Amount<'nat'> & {
|
|
69
|
-
/** @typedef {Amount<'nat'> & {
|
|
72
|
+
/** @typedef {Amount<'nat'> & {normalized: true}} NormalizedDebt */
|
|
73
|
+
/** @typedef {Amount<'nat'> & {normalized: false}} ActualDebt */
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
|
-
* Overcollateralized are greater than one.
|
|
73
|
-
* smaller in [0-1].
|
|
76
|
+
* Overcollateralized are greater than one.
|
|
77
|
+
* The more undercollaterized the smaller in [0-1].
|
|
74
78
|
*
|
|
75
79
|
* @param {NormalizedDebt} normalizedDebt normalized (not actual) total debt
|
|
76
80
|
* @param {Amount<'nat'>} collateral
|
|
@@ -91,7 +95,7 @@ const collateralizationRatio = (normalizedDebt, collateral) => {
|
|
|
91
95
|
* @param {Amount<'nat'>} collateral
|
|
92
96
|
* @param {VaultId} vaultId
|
|
93
97
|
* @returns {string} lexically sortable string in which highest
|
|
94
|
-
*
|
|
98
|
+
* debt-to-collateral is earliest
|
|
95
99
|
*/
|
|
96
100
|
export const toVaultKey = (normalizedDebt, collateral, vaultId) => {
|
|
97
101
|
assert(normalizedDebt);
|
|
@@ -158,7 +162,7 @@ harden(normalizedCollRatio);
|
|
|
158
162
|
* @param {Ratio} compoundedInterest
|
|
159
163
|
* @param {Ratio} margin
|
|
160
164
|
* @returns {string} lexically sortable string in which highest
|
|
161
|
-
*
|
|
165
|
+
* debt-to-collateral is earliest
|
|
162
166
|
*/
|
|
163
167
|
export const normalizedCollRatioKey = (quote, compoundedInterest, margin) => {
|
|
164
168
|
const collRatio = normalizedCollRatio(quote, compoundedInterest, margin);
|
|
@@ -2,30 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('./vault').VaultNotification} VaultNotification
|
|
5
|
-
*
|
|
6
5
|
* @typedef {import('./vault').Vault} Vault
|
|
7
|
-
*
|
|
8
6
|
* @typedef {import('./vaultKit').VaultKit} VaultKit
|
|
9
|
-
*
|
|
10
7
|
* @typedef {import('./vaultManager').VaultManager} VaultManager
|
|
11
|
-
*
|
|
12
8
|
* @typedef {import('./vaultManager').CollateralManager} CollateralManager
|
|
13
|
-
*
|
|
14
9
|
* @typedef {import('../reserve/assetReserve.js').AssetReserveLimitedCreatorFacet} AssetReserveCreatorFacet
|
|
15
|
-
*
|
|
16
10
|
* @typedef {import('../reserve/assetReserve.js').AssetReservePublicFacet} AssetReservePublicFacet
|
|
17
|
-
*
|
|
18
11
|
* @typedef {import('../auction/auctioneer.js').AuctioneerPublicFacet} AuctioneerPublicFacet
|
|
19
|
-
*
|
|
20
12
|
* @typedef {import('./vaultFactory.js').VaultFactoryContract['publicFacet']} VaultFactoryPublicFacet
|
|
21
13
|
*
|
|
22
14
|
* @typedef {import('@agoric/time/src/types').Timestamp} Timestamp
|
|
23
|
-
*
|
|
24
15
|
* @typedef {import('@agoric/time/src/types').RelativeTime} RelativeTime
|
|
25
16
|
*/
|
|
26
17
|
|
|
27
18
|
/**
|
|
28
|
-
* @typedef
|
|
19
|
+
* @typedef {object} AutoswapLocal
|
|
29
20
|
* @property {(amount: Amount, brand: Brand) => Amount} getInputPrice
|
|
30
21
|
* @property {() => Invitation} makeSwapInvitation
|
|
31
22
|
*/
|
|
@@ -33,16 +24,13 @@
|
|
|
33
24
|
/**
|
|
34
25
|
* @typedef {object} VaultManagerParamValues
|
|
35
26
|
* @property {Ratio} liquidationMargin - margin below which collateral will be
|
|
36
|
-
*
|
|
37
|
-
* @property {Ratio} liquidationPenalty - penalty charged upon liquidation as
|
|
38
|
-
*
|
|
39
|
-
* @property {Ratio}
|
|
40
|
-
*
|
|
41
|
-
* @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating or
|
|
42
|
-
* increasing a debt position.
|
|
27
|
+
* liquidated to satisfy the debt.
|
|
28
|
+
* @property {Ratio} liquidationPenalty - penalty charged upon liquidation as proportion of debt
|
|
29
|
+
* @property {Ratio} interestRate - annual interest rate charged on debt positions
|
|
30
|
+
* @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating
|
|
31
|
+
* or increasing a debt position.
|
|
43
32
|
* @property {Amount<'nat'>} debtLimit
|
|
44
|
-
* @property {Ratio} [liquidationPadding] - vault must maintain this in order to
|
|
45
|
-
* remove collateral or add debt
|
|
33
|
+
* @property {Ratio} [liquidationPadding] - vault must maintain this in order to remove collateral or add debt
|
|
46
34
|
*/
|
|
47
35
|
|
|
48
36
|
/**
|
|
@@ -54,7 +42,7 @@
|
|
|
54
42
|
*/
|
|
55
43
|
|
|
56
44
|
/**
|
|
57
|
-
* @typedef
|
|
45
|
+
* @typedef {object} VaultFactoryCreatorFacet
|
|
58
46
|
* @property {AddVaultType} addVaultType
|
|
59
47
|
* @property {() => Allocation} getRewardAllocation
|
|
60
48
|
* @property {() => Promise<Invitation<string, never>>} makeCollectFeesInvitation
|
|
@@ -63,20 +51,23 @@
|
|
|
63
51
|
*/
|
|
64
52
|
|
|
65
53
|
/**
|
|
66
|
-
* @callback MintAndTransfer
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
54
|
+
* @callback MintAndTransfer
|
|
55
|
+
* Mint new debt `toMint` and transfer the `fee` portion to the vaultFactory's reward
|
|
56
|
+
* pool. Then reallocate over all the seat arguments and the rewardPoolSeat. Update
|
|
57
|
+
* the `totalDebt` if the reallocate succeeds.
|
|
70
58
|
* @param {ZCFSeat} mintReceiver
|
|
71
59
|
* @param {Amount<'nat'>} toMint
|
|
72
60
|
* @param {Amount<'nat'>} fee
|
|
73
|
-
* @param {TransferPart[]} transfers
|
|
61
|
+
* @param {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} transfers
|
|
74
62
|
* @returns {void}
|
|
75
63
|
*/
|
|
76
64
|
|
|
77
65
|
/**
|
|
78
|
-
* @callback BurnDebt
|
|
79
|
-
*
|
|
66
|
+
* @callback BurnDebt
|
|
67
|
+
*
|
|
68
|
+
* Burn debt tokens off a seat and update
|
|
69
|
+
* the `totalDebt` if the reallocate succeeds.
|
|
70
|
+
*
|
|
80
71
|
* @param {Amount} toBurn
|
|
81
72
|
* @param {ZCFSeat} fromSeat
|
|
82
73
|
* @returns {void}
|
|
@@ -87,15 +78,16 @@
|
|
|
87
78
|
* @property {() => Ratio} getLiquidationMargin
|
|
88
79
|
* @property {() => Ratio} getMintFee
|
|
89
80
|
* @property {() => Promise<PriceQuote>} getCollateralQuote
|
|
90
|
-
* @property {() => Ratio} getInterestRate - The annual interest rate on a debt
|
|
91
|
-
* position
|
|
81
|
+
* @property {() => Ratio} getInterestRate - The annual interest rate on a debt position
|
|
92
82
|
* @property {() => RelativeTime} getChargingPeriod - The period (in seconds) at
|
|
93
83
|
* which interest is charged to the debt position.
|
|
94
84
|
* @property {() => RelativeTime} getRecordingPeriod - The period (in seconds)
|
|
95
85
|
* at which interest is recorded to the debt position.
|
|
96
86
|
*/
|
|
97
87
|
|
|
98
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* @typedef {string} VaultId
|
|
90
|
+
*/
|
|
99
91
|
|
|
100
92
|
/**
|
|
101
93
|
* @typedef {object} InterestTiming
|
|
@@ -112,9 +104,7 @@
|
|
|
112
104
|
|
|
113
105
|
/**
|
|
114
106
|
* @typedef {object} Liquidator
|
|
115
|
-
* @property {() => Promise<
|
|
116
|
-
* Invitation<void, { debt: Amount<'nat'>; penaltyRate: Ratio }>
|
|
117
|
-
* >} makeLiquidateInvitation
|
|
107
|
+
* @property {() => Promise<Invitation<void, { debt: Amount<'nat'>; penaltyRate: Ratio; }>>} makeLiquidateInvitation
|
|
118
108
|
*/
|
|
119
109
|
|
|
120
110
|
/**
|
|
@@ -134,11 +124,11 @@
|
|
|
134
124
|
/**
|
|
135
125
|
* @typedef {object} CalculatorKit
|
|
136
126
|
* @property {Calculate} calculate calculate new debt for charging periods up to
|
|
137
|
-
*
|
|
127
|
+
* the present.
|
|
138
128
|
* @property {Calculate} calculateReportingPeriod calculate new debt for
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
129
|
+
* reporting periods up to the present. If some charging periods have elapsed
|
|
130
|
+
* that don't constitute whole reporting periods, the time is not updated past
|
|
131
|
+
* them and interest is not accumulated for them.
|
|
142
132
|
*/
|
|
143
133
|
|
|
144
|
-
/** @typedef {{
|
|
134
|
+
/** @typedef {{key: 'governedParams' | {collateralBrand: Brand}}} VaultFactoryParamPath */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AmountMath, AmountShape } from '@agoric/ertp';
|
|
2
|
-
import {
|
|
3
|
-
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
2
|
+
import { makeTracer, StorageNodeShape } from '@agoric/internal';
|
|
4
3
|
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
5
4
|
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
|
|
6
5
|
import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
|
|
@@ -10,10 +9,11 @@ import {
|
|
|
10
9
|
makeNatAmountShape,
|
|
11
10
|
} from '../contractSupport.js';
|
|
12
11
|
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
|
|
13
|
-
import {
|
|
12
|
+
import { UnguardedHelperI } from '../typeGuards.js';
|
|
14
13
|
import { prepareVaultKit } from './vaultKit.js';
|
|
15
14
|
|
|
16
15
|
import '@agoric/zoe/exported.js';
|
|
16
|
+
import { calculateDebtCosts } from './math.js';
|
|
17
17
|
|
|
18
18
|
const { quote: q, Fail } = assert;
|
|
19
19
|
|
|
@@ -22,36 +22,31 @@ const trace = makeTracer('Vault', true);
|
|
|
22
22
|
/** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @file This has most of the logic for a Vault, to borrow Minted against
|
|
26
|
-
* collateral.
|
|
25
|
+
* @file This has most of the logic for a Vault, to borrow Minted against collateral.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The logic here is for Vault which is the majority of logic of vaults but
|
|
28
|
+
* the user view is the `vault` value contained in VaultKit.
|
|
30
29
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* - the absence of one of these implies the opposite, so `newDebt` is the future
|
|
40
|
-
* value fo `debt`, as computed based on values after any `await`
|
|
30
|
+
* A note on naming convention:
|
|
31
|
+
* - `Pre` is used as a postfix for any mutable value retrieved *before* an
|
|
32
|
+
* `await`, to flag values that must used very carefully after the `await`
|
|
33
|
+
* - `new` is a prefix for values that describe the result of executing a
|
|
34
|
+
* transaction; e.g., `debt` is the value before the txn, and `newDebt`
|
|
35
|
+
* will be value if the txn completes.
|
|
36
|
+
* - the absence of one of these implies the opposite, so `newDebt` is the
|
|
37
|
+
* future value fo `debt`, as computed based on values after any `await`
|
|
41
38
|
*/
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* Constants for vault phase.
|
|
45
42
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* -
|
|
53
|
-
* - LIQUIDATED - vault was closed by the manager, with remaining assets paid to
|
|
54
|
-
* owner
|
|
43
|
+
* ACTIVE - vault is in use and can be changed
|
|
44
|
+
* LIQUIDATING - vault is being liquidated by the vault manager, and cannot be changed by the user.
|
|
45
|
+
* If liquidation fails, vaults may remain in this state. An upgrade to the contract
|
|
46
|
+
* might be able to recover them.
|
|
47
|
+
* TRANSFER - vault is able to be transferred (payments and debits frozen until it has a new owner)
|
|
48
|
+
* CLOSED - vault was closed by the user and all assets have been paid out
|
|
49
|
+
* LIQUIDATED - vault was closed by the manager, with remaining assets paid to owner
|
|
55
50
|
*/
|
|
56
51
|
export const Phase = /** @type {const} */ ({
|
|
57
52
|
ACTIVE: 'active',
|
|
@@ -63,7 +58,7 @@ export const Phase = /** @type {const} */ ({
|
|
|
63
58
|
|
|
64
59
|
/**
|
|
65
60
|
* @typedef {Phase[keyof Omit<typeof Phase, 'TRANSFER'>]} VaultPhase
|
|
66
|
-
* @type {{
|
|
61
|
+
* @type {{[K in VaultPhase]: Array<VaultPhase>}}
|
|
67
62
|
*/
|
|
68
63
|
const validTransitions = {
|
|
69
64
|
[Phase.ACTIVE]: [Phase.LIQUIDATING, Phase.CLOSED],
|
|
@@ -77,8 +72,7 @@ const validTransitions = {
|
|
|
77
72
|
*
|
|
78
73
|
* @typedef {object} VaultNotification
|
|
79
74
|
* @property {Amount<'nat'>} locked Amount of Collateral locked
|
|
80
|
-
* @property {{
|
|
81
|
-
* the point the compounded interest was 'interest'
|
|
75
|
+
* @property {{debt: Amount<'nat'>, interest: Ratio}} debtSnapshot 'debt' at the point the compounded interest was 'interest'
|
|
82
76
|
* @property {HolderPhase} vaultState
|
|
83
77
|
*/
|
|
84
78
|
|
|
@@ -93,36 +87,27 @@ const validTransitions = {
|
|
|
93
87
|
* @property {MintAndTransfer} mintAndTransfer
|
|
94
88
|
* @property {(amount: Amount, seat: ZCFSeat) => void} burn
|
|
95
89
|
* @property {() => Ratio} getCompoundedInterest
|
|
96
|
-
* @property {(
|
|
97
|
-
* oldDebt: import('./storeUtils.js').NormalizedDebt,
|
|
98
|
-
* oldCollateral: Amount<'nat'>,
|
|
99
|
-
* vaultId: VaultId,
|
|
100
|
-
* vaultPhase: VaultPhase,
|
|
101
|
-
* vault: Vault,
|
|
102
|
-
* ) => void} handleBalanceChange
|
|
90
|
+
* @property {(oldDebt: import('./storeUtils.js').NormalizedDebt, oldCollateral: Amount<'nat'>, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void} handleBalanceChange
|
|
103
91
|
* @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
|
|
104
92
|
*/
|
|
105
93
|
|
|
106
94
|
/**
|
|
107
95
|
* @typedef {Readonly<{
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
96
|
+
* idInManager: VaultId,
|
|
97
|
+
* manager: VaultManager,
|
|
98
|
+
* storageNode: StorageNode,
|
|
99
|
+
* vaultSeat: ZCFSeat,
|
|
112
100
|
* }>} ImmutableState
|
|
113
101
|
*/
|
|
114
102
|
|
|
115
103
|
/**
|
|
116
|
-
* Snapshot is of the debt and compounded interest when the principal was last
|
|
117
|
-
* changed.
|
|
104
|
+
* Snapshot is of the debt and compounded interest when the principal was last changed.
|
|
118
105
|
*
|
|
119
106
|
* @typedef {{
|
|
120
|
-
* interestSnapshot: Ratio
|
|
121
|
-
* phase: VaultPhase
|
|
122
|
-
* debtSnapshot: Amount<'nat'
|
|
123
|
-
* outerUpdater:
|
|
124
|
-
* | import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification>
|
|
125
|
-
* | null;
|
|
107
|
+
* interestSnapshot: Ratio,
|
|
108
|
+
* phase: VaultPhase,
|
|
109
|
+
* debtSnapshot: Amount<'nat'>,
|
|
110
|
+
* outerUpdater: import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification> | null,
|
|
126
111
|
* }} MutableState
|
|
127
112
|
*/
|
|
128
113
|
|
|
@@ -210,10 +195,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
210
195
|
return AmountMath.makeEmpty(this.facets.helper.debtBrand());
|
|
211
196
|
},
|
|
212
197
|
/**
|
|
213
|
-
* @typedef {{
|
|
214
|
-
* give: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
215
|
-
* want: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
216
|
-
* }} FullProposal
|
|
198
|
+
* @typedef {{ give: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> }, want: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> } }} FullProposal
|
|
217
199
|
*/
|
|
218
200
|
/**
|
|
219
201
|
* @param {ProposalRecord} partial
|
|
@@ -238,7 +220,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
238
220
|
//#endregion
|
|
239
221
|
|
|
240
222
|
//#region Phase logic
|
|
241
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* @param {VaultPhase} newPhase
|
|
225
|
+
*/
|
|
242
226
|
assignPhase(newPhase) {
|
|
243
227
|
const { state } = this;
|
|
244
228
|
|
|
@@ -277,14 +261,12 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
277
261
|
},
|
|
278
262
|
|
|
279
263
|
/**
|
|
280
|
-
* Update the debt balance and propagate upwards to
|
|
281
|
-
* debt and liquidation order.
|
|
264
|
+
* Update the debt balance and propagate upwards to
|
|
265
|
+
* maintain aggregate debt and liquidation order.
|
|
282
266
|
*
|
|
283
|
-
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all
|
|
284
|
-
* accrued interest, normalized to the launch of the vaultManager
|
|
267
|
+
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all accrued interest, normalized to the launch of the vaultManager
|
|
285
268
|
* @param {Amount<'nat'>} oldCollateral - actual collateral
|
|
286
|
-
* @param {Amount<'nat'>} newDebtActual - actual principal and all
|
|
287
|
-
* accrued interest
|
|
269
|
+
* @param {Amount<'nat'>} newDebtActual - actual principal and all accrued interest
|
|
288
270
|
*/
|
|
289
271
|
updateDebtAccounting(oldDebtNormalized, oldCollateral, newDebtActual) {
|
|
290
272
|
const { state, facets } = this;
|
|
@@ -300,7 +282,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
300
282
|
);
|
|
301
283
|
},
|
|
302
284
|
|
|
303
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
*
|
|
287
|
+
* @param {ZCFSeat} seat
|
|
288
|
+
*/
|
|
304
289
|
getCollateralAllocated(seat) {
|
|
305
290
|
return seat.getAmountAllocated(
|
|
306
291
|
'Collateral',
|
|
@@ -322,6 +307,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
322
307
|
},
|
|
323
308
|
|
|
324
309
|
/**
|
|
310
|
+
*
|
|
325
311
|
* @param {Amount<'nat'>} collateralAmount
|
|
326
312
|
* @param {Amount<'nat'>} proposedDebt
|
|
327
313
|
*/
|
|
@@ -334,7 +320,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
334
320
|
)} for ${q(collateralAmount)} collateral`;
|
|
335
321
|
},
|
|
336
322
|
|
|
337
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
*
|
|
325
|
+
* @param {HolderPhase} newPhase
|
|
326
|
+
*/
|
|
338
327
|
getStateSnapshot(newPhase) {
|
|
339
328
|
const { state, facets } = this;
|
|
340
329
|
|
|
@@ -349,7 +338,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
349
338
|
});
|
|
350
339
|
},
|
|
351
340
|
|
|
352
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* call this whenever anything changes!
|
|
343
|
+
*/
|
|
353
344
|
updateUiState() {
|
|
354
345
|
const { state, facets } = this;
|
|
355
346
|
const { outerUpdater } = state;
|
|
@@ -377,7 +368,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
377
368
|
}
|
|
378
369
|
},
|
|
379
370
|
|
|
380
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* @param {ZCFSeat} seat
|
|
373
|
+
*/
|
|
381
374
|
async closeHook(seat) {
|
|
382
375
|
const { state, facets } = this;
|
|
383
376
|
|
|
@@ -447,11 +440,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
447
440
|
},
|
|
448
441
|
|
|
449
442
|
/**
|
|
450
|
-
* Calculate the fee, the amount to mint and the resulting debt.
|
|
451
|
-
* give and the want together reflect a delta, where typically
|
|
452
|
-
* zero because they come from the gave/want of an offer
|
|
453
|
-
* the `want` is zero, the `fee` will also be zero,
|
|
454
|
-
* works.
|
|
443
|
+
* Calculate the fee, the amount to mint and the resulting debt.
|
|
444
|
+
* The give and the want together reflect a delta, where typically
|
|
445
|
+
* one is zero because they come from the gave/want of an offer
|
|
446
|
+
* proposal. If the `want` is zero, the `fee` will also be zero,
|
|
447
|
+
* so the simple math works.
|
|
455
448
|
*
|
|
456
449
|
* @param {Amount<'nat'>} currentDebt
|
|
457
450
|
* @param {Amount<'nat'>} giveAmount
|
|
@@ -529,6 +522,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
529
522
|
},
|
|
530
523
|
|
|
531
524
|
/**
|
|
525
|
+
*
|
|
532
526
|
* @param {ZCFSeat} clientSeat
|
|
533
527
|
* @param {FullProposal} fp
|
|
534
528
|
* @param {ReturnType<typeof calculateDebtCosts>} costs
|
|
@@ -549,7 +543,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
549
543
|
|
|
550
544
|
const giveMintedTaken = AmountMath.subtract(fp.give.Minted, surplus);
|
|
551
545
|
|
|
552
|
-
/** @type {TransferPart[]} */
|
|
546
|
+
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
|
|
553
547
|
const transfers = harden([
|
|
554
548
|
[clientSeat, vaultSeat, { Collateral: fp.give.Collateral }],
|
|
555
549
|
[vaultSeat, clientSeat, { Collateral: fp.want.Collateral }],
|
|
@@ -574,6 +568,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
574
568
|
},
|
|
575
569
|
|
|
576
570
|
/**
|
|
571
|
+
*
|
|
577
572
|
* @param {ZCFSeat} seat
|
|
578
573
|
* @returns {VaultKit}
|
|
579
574
|
*/
|
|
@@ -674,7 +669,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
674
669
|
return vaultKit;
|
|
675
670
|
},
|
|
676
671
|
|
|
677
|
-
/**
|
|
672
|
+
/**
|
|
673
|
+
* Called by manager at start of liquidation.
|
|
674
|
+
*/
|
|
678
675
|
liquidating() {
|
|
679
676
|
const { facets } = this;
|
|
680
677
|
|
|
@@ -684,8 +681,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
684
681
|
},
|
|
685
682
|
|
|
686
683
|
/**
|
|
687
|
-
* Called by manager at end of liquidation, at which point all debts
|
|
688
|
-
*
|
|
684
|
+
* Called by manager at end of liquidation, at which point all debts have been
|
|
685
|
+
* covered.
|
|
689
686
|
*/
|
|
690
687
|
liquidated() {
|
|
691
688
|
const { facets } = this;
|
|
@@ -777,7 +774,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
777
774
|
);
|
|
778
775
|
},
|
|
779
776
|
|
|
780
|
-
/**
|
|
777
|
+
/**
|
|
778
|
+
* @returns {Promise<Invitation>}
|
|
779
|
+
*/
|
|
781
780
|
makeTransferInvitation() {
|
|
782
781
|
const { state, facets } = this;
|
|
783
782
|
const { outerUpdater } = state;
|
|
@@ -809,7 +808,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
809
808
|
|
|
810
809
|
// for status/debugging
|
|
811
810
|
|
|
812
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
*
|
|
813
|
+
* @returns {Amount<'nat'>}
|
|
814
|
+
*/
|
|
813
815
|
getCollateralAmount() {
|
|
814
816
|
const { state, facets } = this;
|
|
815
817
|
const { vaultSeat } = state;
|
|
@@ -823,15 +825,15 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
823
825
|
/**
|
|
824
826
|
* The actual current debt, including accrued interest.
|
|
825
827
|
*
|
|
826
|
-
* This looks like a simple getter but it does a lot of the heavy
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
* what
|
|
831
|
-
* this vault record was written.
|
|
828
|
+
* This looks like a simple getter but it does a lot of the heavy lifting for
|
|
829
|
+
* interest accrual. Rather than updating all records when interest accrues,
|
|
830
|
+
* the vault manager updates just its rolling compounded interest. Here we
|
|
831
|
+
* calculate what the current debt is given what's recorded in this vault and
|
|
832
|
+
* what interest has compounded since this vault record was written.
|
|
832
833
|
*
|
|
833
|
-
* @returns {Amount<'nat'>}
|
|
834
834
|
* @see getNormalizedDebt
|
|
835
|
+
*
|
|
836
|
+
* @returns {Amount<'nat'>}
|
|
835
837
|
*/
|
|
836
838
|
getCurrentDebt() {
|
|
837
839
|
const { state } = this;
|
|
@@ -843,15 +845,14 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
843
845
|
},
|
|
844
846
|
|
|
845
847
|
/**
|
|
846
|
-
* The normalization puts all debts on a common time-independent scale
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
848
|
+
* The normalization puts all debts on a common time-independent scale since
|
|
849
|
+
* the launch of this vault manager. This allows the manager to order vaults
|
|
850
|
+
* by their debt-to-collateral ratios without having to mutate the debts as
|
|
851
|
+
* the interest accrues.
|
|
850
852
|
*
|
|
851
|
-
* @returns {import('./storeUtils.js').NormalizedDebt} as if the vault
|
|
852
|
-
* was open at the launch of this manager, before any interest
|
|
853
|
-
* accrued
|
|
854
853
|
* @see getActualDebAmount
|
|
854
|
+
*
|
|
855
|
+
* @returns {import('./storeUtils.js').NormalizedDebt} as if the vault was open at the launch of this manager, before any interest accrued
|
|
855
856
|
*/
|
|
856
857
|
getNormalizedDebt() {
|
|
857
858
|
const { state } = this;
|