@agoric/inter-protocol 0.13.2-dev-0e039d9.0 → 0.13.2-dev-ed5ee58.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/bundles/bundle-econCommitteeCharter-meta.js +78 -78
- package/bundles/bundle-econCommitteeCharter.js +1 -1
- package/bundles/bundle-feeDistributor-meta.js +61 -61
- package/bundles/bundle-feeDistributor.js +1 -1
- package/bundles/bundle-fluxAggregator-meta.js +114 -114
- package/bundles/bundle-fluxAggregator.js +1 -1
- package/bundles/bundle-psm-meta.js +112 -112
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-meta.js +110 -114
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-meta.js +78 -78
- package/bundles/bundle-scaledPriceAuthority.js +1 -1
- package/bundles/bundle-stakeFactory-meta.js +118 -118
- package/bundles/bundle-stakeFactory.js +1 -1
- package/bundles/bundle-vaultFactory-meta.js +128 -128
- package/bundles/bundle-vaultFactory.js +1 -1
- package/exported.js +0 -1
- package/package.json +16 -16
- package/scripts/deploy-contracts.js +0 -2
- package/scripts/init-core.js +0 -16
- package/src/feeDistributor.js +1 -1
- package/src/proposals/addAssetToVault.js +4 -57
- package/src/proposals/committee-proposal.js +3 -6
- package/src/proposals/core-proposal.js +1 -73
- package/src/proposals/demoIssuers.js +1 -232
- package/src/proposals/econ-behaviors.js +10 -193
- package/src/proposals/sim-behaviors.js +1 -1
- package/src/reserve/assetReserve.js +9 -170
- package/src/reserve/params.js +1 -4
- package/src/vaultFactory/liquidateIncrementally.js +16 -141
- package/src/vaultFactory/liquidateMinimum.js +19 -21
- package/src/vaultFactory/params.js +0 -29
- package/src/vaultFactory/types.js +0 -6
- package/src/vaultFactory/vault.js +1 -3
- package/src/vaultFactory/vaultDirector.js +1 -33
- package/src/vaultFactory/vaultFactory.js +2 -12
- package/src/vaultFactory/vaultManager.js +10 -217
- package/bundles/bundle-amm-meta.js +0 -686
- package/bundles/bundle-amm.js +0 -1
- package/bundles/bundle-interchainPool-meta.js +0 -606
- package/bundles/bundle-interchainPool.js +0 -1
- package/bundles/bundle-liquidateIncrementally-meta.js +0 -470
- package/bundles/bundle-liquidateIncrementally.js +0 -1
- package/bundles/bundle-liquidateMinimum-meta.js +0 -470
- package/bundles/bundle-liquidateMinimum.js +0 -1
- package/scripts/add-initial-liquidity.js +0 -179
- package/src/interchainPool.js +0 -134
- package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
- package/src/vpool-xyk-amm/addLiquidity.js +0 -221
- package/src/vpool-xyk-amm/addPool.js +0 -200
- package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
- package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
- package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -93
- package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -83
- package/src/vpool-xyk-amm/constantProduct/core.js +0 -145
- package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -3
- package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -48
- package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -114
- package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -39
- package/src/vpool-xyk-amm/constantProduct/swap.js +0 -270
- package/src/vpool-xyk-amm/constantProduct/types.js +0 -30
- package/src/vpool-xyk-amm/doublePool.js +0 -200
- package/src/vpool-xyk-amm/estimate.js +0 -175
- package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -530
- package/src/vpool-xyk-amm/params.js +0 -59
- package/src/vpool-xyk-amm/pool.js +0 -398
- package/src/vpool-xyk-amm/priceAuthority.js +0 -92
- package/src/vpool-xyk-amm/removeLiquidity.js +0 -29
- package/src/vpool-xyk-amm/singlePool.js +0 -88
- package/src/vpool-xyk-amm/swap.js +0 -68
- package/src/vpool-xyk-amm/types.js +0 -152
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
import { E } from '@endo/eventual-send';
|
|
3
3
|
import {
|
|
4
|
-
getAmountOut,
|
|
5
4
|
assertProposalShape,
|
|
6
|
-
|
|
7
|
-
natSafeMath as NatMath,
|
|
5
|
+
atomicTransfer,
|
|
8
6
|
ceilMultiplyBy,
|
|
7
|
+
getAmountOut,
|
|
8
|
+
offerTo,
|
|
9
9
|
oneMinus,
|
|
10
|
-
atomicTransfer,
|
|
11
10
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
12
11
|
import { AmountMath } from '@agoric/ertp';
|
|
13
12
|
import { Far } from '@endo/marshal';
|
|
@@ -46,9 +45,11 @@ const trace = makeTracer('LiqI', false);
|
|
|
46
45
|
* TODO integrate the reserve, including the above Reserve strategies.
|
|
47
46
|
*/
|
|
48
47
|
|
|
48
|
+
// TODO: (#7047) this file goes away shortly, and is here to keep vaults happy
|
|
49
|
+
// until we have a replacement
|
|
49
50
|
/**
|
|
50
51
|
* @typedef {{
|
|
51
|
-
* amm:
|
|
52
|
+
* amm: unknown,
|
|
52
53
|
* priceAuthority: PriceAuthority,
|
|
53
54
|
* reservePublicFacet: AssetReservePublicFacet,
|
|
54
55
|
* timerService: import('@agoric/time/src/types').TimerService,
|
|
@@ -61,24 +62,13 @@ const trace = makeTracer('LiqI', false);
|
|
|
61
62
|
*/
|
|
62
63
|
const start = async zcf => {
|
|
63
64
|
const {
|
|
64
|
-
amm,
|
|
65
65
|
priceAuthority,
|
|
66
66
|
reservePublicFacet,
|
|
67
67
|
timerService,
|
|
68
68
|
debtBrand,
|
|
69
|
-
MaxImpactBP,
|
|
70
69
|
OracleTolerance,
|
|
71
|
-
AMMMaxSlippage,
|
|
72
70
|
} = zcf.getTerms();
|
|
73
71
|
|
|
74
|
-
const SCALE = 1_000_000n;
|
|
75
|
-
const BASIS_POINTS = 10_000n * SCALE;
|
|
76
|
-
const BP2 = BASIS_POINTS * BASIS_POINTS;
|
|
77
|
-
const ONE = BASIS_POINTS;
|
|
78
|
-
|
|
79
|
-
const asFloat = (numerator, denominator) =>
|
|
80
|
-
Number(numerator) / Number(denominator);
|
|
81
|
-
|
|
82
72
|
// #region penalty distribution
|
|
83
73
|
const { zcfSeat: penaltyPoolSeat } = zcf.makeEmptySeatKit();
|
|
84
74
|
const drainPenaltyPool = async () => {
|
|
@@ -100,81 +90,10 @@ const start = async zcf => {
|
|
|
100
90
|
};
|
|
101
91
|
// #endregion
|
|
102
92
|
|
|
103
|
-
/**
|
|
104
|
-
* Compute the tranche size whose sale on the AMM would have
|
|
105
|
-
* a price impact of MAX_IMPACT_BP.
|
|
106
|
-
* This doesn't use ratios so that it is usable for any brand
|
|
107
|
-
*
|
|
108
|
-
* @param {Amount<'nat'>} poolSize
|
|
109
|
-
* @param {bigint} maxImpactBP
|
|
110
|
-
* @param {bigint} feeBP
|
|
111
|
-
* @returns {Amount<'nat'>}
|
|
112
|
-
*/
|
|
113
|
-
const maxTrancheWithFees = (poolSize, maxImpactBP, feeBP) => {
|
|
114
|
-
trace('maxTrancheWithFees', poolSize, maxImpactBP, feeBP);
|
|
115
|
-
const maxImpactScaled = maxImpactBP * SCALE;
|
|
116
|
-
const ammFeeScaled = feeBP * SCALE;
|
|
117
|
-
// sqrt(impact + 1) - 1
|
|
118
|
-
// Since we take SQRT but want to be BP, multiply in BP
|
|
119
|
-
const impactFactor =
|
|
120
|
-
BigInt(
|
|
121
|
-
Math.ceil(Math.sqrt(Number((maxImpactScaled + ONE) * BASIS_POINTS))),
|
|
122
|
-
) - ONE;
|
|
123
|
-
const impactWithFee = impactFactor * (ONE - ammFeeScaled);
|
|
124
|
-
return AmountMath.make(
|
|
125
|
-
poolSize.brand,
|
|
126
|
-
NatMath.ceilDivide(NatMath.multiply(poolSize.value, impactWithFee), BP2),
|
|
127
|
-
);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
93
|
const computeOracleLimit = (oracleQuote, oracleTolerance) => {
|
|
131
94
|
return ceilMultiplyBy(getAmountOut(oracleQuote), oneMinus(oracleTolerance));
|
|
132
95
|
};
|
|
133
96
|
|
|
134
|
-
const getAMMFeeBP = async () => {
|
|
135
|
-
const zoe = zcf.getZoeService();
|
|
136
|
-
const instance = await E(zoe).getInstance(E(amm).makeSwapInvitation());
|
|
137
|
-
const terms = await E(zoe).getTerms(instance);
|
|
138
|
-
// trace('amm terms', terms);
|
|
139
|
-
const { poolFeeBP, protocolFeeBP } = terms;
|
|
140
|
-
return poolFeeBP + protocolFeeBP;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const AMMFeeBP = await getAMMFeeBP();
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* @param {Amount<'nat'>} poolCentral
|
|
148
|
-
* @param {Amount<'nat'>} poolCollateral
|
|
149
|
-
* @param {Amount<'nat'>} tranche
|
|
150
|
-
* @param {Amount<'nat'>} debt
|
|
151
|
-
* @param {Ratio} maxSlip
|
|
152
|
-
*/
|
|
153
|
-
const estimateAMMProceeds = (
|
|
154
|
-
poolCentral,
|
|
155
|
-
poolCollateral,
|
|
156
|
-
tranche,
|
|
157
|
-
debt,
|
|
158
|
-
maxSlip,
|
|
159
|
-
) => {
|
|
160
|
-
const k = NatMath.multiply(poolCentral.value, poolCollateral.value);
|
|
161
|
-
const postSaleCollateral = AmountMath.add(tranche, poolCollateral);
|
|
162
|
-
const estimateCentral = NatMath.subtract(
|
|
163
|
-
poolCentral.value,
|
|
164
|
-
NatMath.floorDivide(k, postSaleCollateral.value),
|
|
165
|
-
);
|
|
166
|
-
/** @type {Amount<'nat'>} */
|
|
167
|
-
const estimateAmount = AmountMath.make(debt.brand, estimateCentral);
|
|
168
|
-
const minAmmProceeds = ceilMultiplyBy(estimateAmount, oneMinus(maxSlip));
|
|
169
|
-
trace('AMM estimate', {
|
|
170
|
-
tranche,
|
|
171
|
-
minAmmProceeds,
|
|
172
|
-
poolCentral,
|
|
173
|
-
poolCollateral,
|
|
174
|
-
});
|
|
175
|
-
return minAmmProceeds;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
97
|
/**
|
|
179
98
|
* A generator that yields once per block, starting in the current block.
|
|
180
99
|
*
|
|
@@ -207,28 +126,10 @@ const start = async zcf => {
|
|
|
207
126
|
}
|
|
208
127
|
await oncePerBlock();
|
|
209
128
|
|
|
210
|
-
|
|
211
|
-
const { Secondary: poolCollateral, Central: poolCentral } = await E(
|
|
212
|
-
amm,
|
|
213
|
-
).getPoolAllocation(toSell.brand);
|
|
214
|
-
const maxAllowedTranche = maxTrancheWithFees(
|
|
215
|
-
poolCollateral,
|
|
216
|
-
MaxImpactBP,
|
|
217
|
-
AMMFeeBP,
|
|
218
|
-
);
|
|
219
|
-
trace('Pool', { poolCentral, poolCollateral });
|
|
220
|
-
trace('Max tranche', asFloat(maxAllowedTranche.value, 100000n));
|
|
221
|
-
const tranche = AmountMath.min(maxAllowedTranche, toSell);
|
|
129
|
+
const tranche = toSell;
|
|
222
130
|
|
|
223
131
|
// compute the expected proceeds from the AMM for tranche
|
|
224
132
|
const debt = AmountMath.subtract(originalDebt, proceedsSoFar);
|
|
225
|
-
const minAmmProceeds = estimateAMMProceeds(
|
|
226
|
-
poolCentral,
|
|
227
|
-
poolCollateral,
|
|
228
|
-
tranche,
|
|
229
|
-
debt,
|
|
230
|
-
AMMMaxSlippage,
|
|
231
|
-
);
|
|
232
133
|
|
|
233
134
|
// this could use a unit rather than the tranche size to run concurrently
|
|
234
135
|
/** @type PriceQuote */
|
|
@@ -238,43 +139,15 @@ const start = async zcf => {
|
|
|
238
139
|
);
|
|
239
140
|
const oracleLimit = computeOracleLimit(oracleQuote, OracleTolerance);
|
|
240
141
|
|
|
241
|
-
trace('Tranche', { debt, tranche,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
debt,
|
|
248
|
-
oracleLimit,
|
|
249
|
-
};
|
|
250
|
-
} else {
|
|
251
|
-
// prices are too far apart; don't sell this block
|
|
252
|
-
trace('SKIP');
|
|
253
|
-
}
|
|
142
|
+
trace('Tranche', { debt, tranche, oracleLimit });
|
|
143
|
+
yield {
|
|
144
|
+
collateral: tranche,
|
|
145
|
+
debt,
|
|
146
|
+
oracleLimit,
|
|
147
|
+
};
|
|
254
148
|
}
|
|
255
149
|
}
|
|
256
150
|
|
|
257
|
-
async function sellTranche(debtorSeat, collateral, debt, oracleLimit) {
|
|
258
|
-
const swapInvitation = E(amm).makeSwapInvitation();
|
|
259
|
-
const want = AmountMath.min(debt, oracleLimit);
|
|
260
|
-
// TODO if the debt shouldn't require all the collatearal to cover it,
|
|
261
|
-
// this may not provide relevant offer safety
|
|
262
|
-
const proposal = {
|
|
263
|
-
give: { In: collateral },
|
|
264
|
-
want: { Out: want },
|
|
265
|
-
};
|
|
266
|
-
const { deposited, userSeatPromise: liqSeat } = await offerTo(
|
|
267
|
-
zcf,
|
|
268
|
-
swapInvitation,
|
|
269
|
-
undefined, // The keywords were mapped already
|
|
270
|
-
proposal,
|
|
271
|
-
debtorSeat,
|
|
272
|
-
debtorSeat,
|
|
273
|
-
{ stopAfter: debt },
|
|
274
|
-
);
|
|
275
|
-
await Promise.all([E(liqSeat).getOfferResult(), deposited]);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
151
|
/**
|
|
279
152
|
* @param {ZCFSeat} debtorSeat
|
|
280
153
|
* @param {object} options
|
|
@@ -305,7 +178,9 @@ const start = async zcf => {
|
|
|
305
178
|
const collateralBefore = debtorSeat.getAmountAllocated('In');
|
|
306
179
|
const proceedsBefore = debtorSeat.getAmountAllocated('Out');
|
|
307
180
|
|
|
308
|
-
|
|
181
|
+
// AMM is gone. This liquidation contract will depart with #7047
|
|
182
|
+
|
|
183
|
+
// await sellTranche(debtorSeat, collateral, debt, oracleLimit);
|
|
309
184
|
|
|
310
185
|
const proceedsAfter = debtorSeat.getAmountAllocated('Out');
|
|
311
186
|
if (AmountMath.isEqual(proceedsBefore, proceedsAfter)) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { E } from '@endo/eventual-send';
|
|
2
1
|
import {
|
|
3
2
|
ceilMultiplyBy,
|
|
4
|
-
offerTo,
|
|
5
3
|
atomicTransfer,
|
|
6
4
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
7
5
|
import { AmountMath } from '@agoric/ertp';
|
|
@@ -11,6 +9,9 @@ import { makeTracer } from '@agoric/internal';
|
|
|
11
9
|
|
|
12
10
|
const trace = makeTracer('LiqMin', false);
|
|
13
11
|
|
|
12
|
+
// TODO: (#7047) this file goes away shortly, and is here to keep vaults happy
|
|
13
|
+
// until we have a replacement. The reference to AMM is to ease the transition.
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* This contract liquidates the minimum amount of vault's collateral necessary
|
|
16
17
|
* to satisfy the debt. It uses the AMM's swapOut, which sells no more than
|
|
@@ -19,11 +20,10 @@ const trace = makeTracer('LiqMin', false);
|
|
|
19
20
|
* uses the AMM's swapIn instead.
|
|
20
21
|
*
|
|
21
22
|
* @param {ZCF<{
|
|
22
|
-
* amm:
|
|
23
|
+
* amm: unknown,
|
|
23
24
|
* }>} zcf
|
|
24
25
|
*/
|
|
25
26
|
const start = async zcf => {
|
|
26
|
-
const { amm } = zcf.getTerms();
|
|
27
27
|
trace('start', zcf.getTerms());
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -45,27 +45,25 @@ const start = async zcf => {
|
|
|
45
45
|
give: { In: amountIn },
|
|
46
46
|
} = debtorSeat.getProposal();
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { deposited } = await offerTo(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
const amounts = await deposited;
|
|
48
|
+
// AMM is gone, and liquidateMinimum will follow shortly in #7074
|
|
49
|
+
|
|
50
|
+
// const liqProposal = harden({
|
|
51
|
+
// give: { In: amountIn },
|
|
52
|
+
// want: { Out: AmountMath.makeEmpty(debtBrand) },
|
|
53
|
+
// });
|
|
54
|
+
// const { deposited } = await offerTo(
|
|
55
|
+
// zcf,
|
|
56
|
+
// swapInvitation,
|
|
57
|
+
// undefined, // The keywords were mapped already
|
|
58
|
+
// liqProposal,
|
|
59
|
+
// debtorSeat,
|
|
60
|
+
// debtorSeat,
|
|
61
|
+
// { stopAfter: debtWithPenalty },
|
|
62
|
+
// );
|
|
64
63
|
trace(`Liq results`, {
|
|
65
64
|
debtWithPenalty,
|
|
66
65
|
amountIn,
|
|
67
66
|
paid: debtorSeat.getCurrentAllocation(),
|
|
68
|
-
amounts,
|
|
69
67
|
});
|
|
70
68
|
|
|
71
69
|
// Now we need to know how much was sold so we can pay off the debt.
|
|
@@ -21,24 +21,18 @@ export const LIQUIDATION_PADDING_KEY = 'LiquidationPadding';
|
|
|
21
21
|
export const LIQUIDATION_PENALTY_KEY = 'LiquidationPenalty';
|
|
22
22
|
export const INTEREST_RATE_KEY = 'InterestRate';
|
|
23
23
|
export const LOAN_FEE_KEY = 'LoanFee';
|
|
24
|
-
export const LIQUIDATION_INSTALL_KEY = 'LiquidationInstall';
|
|
25
|
-
export const LIQUIDATION_TERMS_KEY = 'LiquidationTerms';
|
|
26
24
|
export const MIN_INITIAL_DEBT_KEY = 'MinInitialDebt';
|
|
27
25
|
export const SHORTFALL_INVITATION_KEY = 'ShortfallInvitation';
|
|
28
26
|
export const ENDORSED_UI_KEY = 'EndorsedUI';
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
29
|
* @param {Amount} electorateInvitationAmount
|
|
32
|
-
* @param {Installation} liquidationInstall
|
|
33
|
-
* @param {import('./liquidation.js').LiquidationTerms} liquidationTerms
|
|
34
30
|
* @param {Amount} minInitialDebt
|
|
35
31
|
* @param {Amount} shortfallInvitationAmount
|
|
36
32
|
* @param {string} endorsedUi
|
|
37
33
|
*/
|
|
38
34
|
const makeVaultDirectorParams = (
|
|
39
35
|
electorateInvitationAmount,
|
|
40
|
-
liquidationInstall,
|
|
41
|
-
liquidationTerms,
|
|
42
36
|
minInitialDebt,
|
|
43
37
|
shortfallInvitationAmount,
|
|
44
38
|
endorsedUi,
|
|
@@ -48,14 +42,6 @@ const makeVaultDirectorParams = (
|
|
|
48
42
|
type: ParamTypes.INVITATION,
|
|
49
43
|
value: electorateInvitationAmount,
|
|
50
44
|
},
|
|
51
|
-
[LIQUIDATION_INSTALL_KEY]: {
|
|
52
|
-
type: ParamTypes.INSTALLATION,
|
|
53
|
-
value: liquidationInstall,
|
|
54
|
-
},
|
|
55
|
-
[LIQUIDATION_TERMS_KEY]: {
|
|
56
|
-
type: ParamTypes.UNKNOWN,
|
|
57
|
-
value: liquidationTerms,
|
|
58
|
-
},
|
|
59
45
|
[MIN_INITIAL_DEBT_KEY]: {
|
|
60
46
|
type: ParamTypes.AMOUNT,
|
|
61
47
|
value: minInitialDebt,
|
|
@@ -118,8 +104,6 @@ export const vaultParamPattern = M.splitRecord(
|
|
|
118
104
|
* @param {import('@agoric/notifier').StoredPublisherKit<GovernanceSubscriptionState>} publisherKit
|
|
119
105
|
* @param {ERef<ZoeService>} zoe
|
|
120
106
|
* @param {Invitation} electorateInvitation
|
|
121
|
-
* @param {Installation} liquidationInstall
|
|
122
|
-
* @param {object} liquidationTerms
|
|
123
107
|
* @param {Amount} minInitialDebt
|
|
124
108
|
* @param {Invitation} shortfallInvitation
|
|
125
109
|
* @param {string} [endorsedUi]
|
|
@@ -128,8 +112,6 @@ export const makeVaultDirectorParamManager = async (
|
|
|
128
112
|
publisherKit,
|
|
129
113
|
zoe,
|
|
130
114
|
electorateInvitation,
|
|
131
|
-
liquidationInstall,
|
|
132
|
-
liquidationTerms,
|
|
133
115
|
minInitialDebt,
|
|
134
116
|
shortfallInvitation,
|
|
135
117
|
endorsedUi = 'NO ENDORSEMENT',
|
|
@@ -138,8 +120,6 @@ export const makeVaultDirectorParamManager = async (
|
|
|
138
120
|
publisherKit,
|
|
139
121
|
{
|
|
140
122
|
[CONTRACT_ELECTORATE]: [ParamTypes.INVITATION, electorateInvitation],
|
|
141
|
-
[LIQUIDATION_INSTALL_KEY]: [ParamTypes.INSTALLATION, liquidationInstall],
|
|
142
|
-
[LIQUIDATION_TERMS_KEY]: [ParamTypes.UNKNOWN, liquidationTerms],
|
|
143
123
|
[MIN_INITIAL_DEBT_KEY]: [ParamTypes.AMOUNT, minInitialDebt],
|
|
144
124
|
[SHORTFALL_INVITATION_KEY]: [ParamTypes.INVITATION, shortfallInvitation],
|
|
145
125
|
[ENDORSED_UI_KEY]: [ParamTypes.STRING, endorsedUi],
|
|
@@ -158,10 +138,7 @@ harden(makeVaultDirectorParamManager);
|
|
|
158
138
|
* priceAuthority: ERef<PriceAuthority>,
|
|
159
139
|
* timer: ERef<import('@agoric/time/src/types').TimerService>,
|
|
160
140
|
* reservePublicFacet: AssetReservePublicFacet,
|
|
161
|
-
* liquidationInstall: Installation,
|
|
162
141
|
* loanTiming: LoanTiming,
|
|
163
|
-
* liquidationTerms: import('./liquidation.js').LiquidationTerms,
|
|
164
|
-
* ammPublicFacet: XYKAMMPublicFacet,
|
|
165
142
|
* shortfallInvitationAmount: Amount,
|
|
166
143
|
* endorsedUi?: string,
|
|
167
144
|
* }} opts
|
|
@@ -169,11 +146,8 @@ harden(makeVaultDirectorParamManager);
|
|
|
169
146
|
export const makeGovernedTerms = (
|
|
170
147
|
{ storageNode, marshaller },
|
|
171
148
|
{
|
|
172
|
-
ammPublicFacet,
|
|
173
149
|
bootstrapPaymentValue,
|
|
174
150
|
electorateInvitationAmount,
|
|
175
|
-
liquidationInstall,
|
|
176
|
-
liquidationTerms,
|
|
177
151
|
loanTiming,
|
|
178
152
|
minInitialDebt,
|
|
179
153
|
priceAuthority,
|
|
@@ -198,15 +172,12 @@ export const makeGovernedTerms = (
|
|
|
198
172
|
).getParams();
|
|
199
173
|
|
|
200
174
|
return harden({
|
|
201
|
-
ammPublicFacet,
|
|
202
175
|
priceAuthority,
|
|
203
176
|
loanTimingParams,
|
|
204
177
|
reservePublicFacet,
|
|
205
178
|
timerService: timer,
|
|
206
179
|
governedParams: makeVaultDirectorParams(
|
|
207
180
|
electorateInvitationAmount,
|
|
208
|
-
liquidationInstall,
|
|
209
|
-
liquidationTerms,
|
|
210
181
|
minInitialDebt,
|
|
211
182
|
shortfallInvitationAmount,
|
|
212
183
|
endorsedUi,
|
|
@@ -100,12 +100,6 @@
|
|
|
100
100
|
* @property {RelativeTime} recordingPeriod in seconds
|
|
101
101
|
*/
|
|
102
102
|
|
|
103
|
-
/**
|
|
104
|
-
* @typedef {object} AMMFees
|
|
105
|
-
* @property {bigint} poolFee
|
|
106
|
-
* @property {bigint} protocolFee
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
103
|
/**
|
|
110
104
|
* @typedef {object} LiquidationStrategy
|
|
111
105
|
* @property {() => KeywordKeywordRecord} keywordMapping
|
|
@@ -137,9 +137,7 @@ const allocationsChangedSinceQuote = (
|
|
|
137
137
|
if (AmountMath.isGTE(newCollateralPre, newCollateral)) {
|
|
138
138
|
// The collateral did not go up. If the collateral decreased, we pro-rate maxDebt.
|
|
139
139
|
// We can pro-rate maxDebt because the quote is either linear (price is
|
|
140
|
-
// unchanging) or super-linear (also called "convex").
|
|
141
|
-
// AMMs: selling less collateral would mean an even smaller price impact, so
|
|
142
|
-
// this is a conservative choice.
|
|
140
|
+
// unchanging) or super-linear (also called "convex").
|
|
143
141
|
const debtPerCollateral = makeRatioFromAmounts(
|
|
144
142
|
maxDebtPre,
|
|
145
143
|
newCollateralPre,
|
|
@@ -3,13 +3,12 @@ import { AmountMath, AmountShape, BrandShape, IssuerShape } from '@agoric/ertp';
|
|
|
3
3
|
import {
|
|
4
4
|
makePublicTopic,
|
|
5
5
|
makeStoredPublisherKit,
|
|
6
|
-
observeIteration,
|
|
7
6
|
pipeTopicToStorage,
|
|
8
7
|
prepareDurablePublishKit,
|
|
9
8
|
SubscriberShape,
|
|
10
9
|
TopicsRecordShape,
|
|
11
10
|
} from '@agoric/notifier';
|
|
12
|
-
import {
|
|
11
|
+
import { M, makeScalarMapStore, mustMatch } from '@agoric/store';
|
|
13
12
|
import {
|
|
14
13
|
defineDurableExoClassKit,
|
|
15
14
|
makeKindHandle,
|
|
@@ -134,11 +133,6 @@ export const prepareVaultDirector = (
|
|
|
134
133
|
};
|
|
135
134
|
};
|
|
136
135
|
|
|
137
|
-
const getLiquidationConfig = () => ({
|
|
138
|
-
install: directorParamManager.getLiquidationInstall(),
|
|
139
|
-
terms: directorParamManager.getLiquidationTerms(),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
136
|
/**
|
|
143
137
|
* @returns {MetricsNotification}
|
|
144
138
|
*/
|
|
@@ -149,29 +143,6 @@ export const prepareVaultDirector = (
|
|
|
149
143
|
});
|
|
150
144
|
};
|
|
151
145
|
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
* @param {VaultManager} vaultManager
|
|
155
|
-
* @param {Installation<unknown>} oldInstall
|
|
156
|
-
* @param {unknown} oldTerms
|
|
157
|
-
*/
|
|
158
|
-
const watchGovernance = (vaultManager, oldInstall, oldTerms) => {
|
|
159
|
-
const subscription = directorParamManager.getSubscription();
|
|
160
|
-
void observeIteration(subscription, {
|
|
161
|
-
updateState(_paramUpdate) {
|
|
162
|
-
const { install, terms } = getLiquidationConfig();
|
|
163
|
-
if (install === oldInstall && keyEQ(terms, oldTerms)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
oldInstall = install;
|
|
167
|
-
oldTerms = terms;
|
|
168
|
-
vaultManager
|
|
169
|
-
.setupLiquidator(install, terms)
|
|
170
|
-
.catch(e => console.error('Failed to setup liquidator', e));
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
|
|
175
146
|
const updateShortfallReporter = async () => {
|
|
176
147
|
const oldInvitation = baggage.has(shortfallInvitationKey)
|
|
177
148
|
? baggage.get(shortfallInvitationKey)
|
|
@@ -409,9 +380,6 @@ export const prepareVaultDirector = (
|
|
|
409
380
|
|
|
410
381
|
const { self: vm } = makeVaultManager();
|
|
411
382
|
collateralTypes.init(collateralBrand, vm);
|
|
412
|
-
const { install, terms } = getLiquidationConfig();
|
|
413
|
-
await vm.setupLiquidator(install, terms);
|
|
414
|
-
watchGovernance(vm, install, terms);
|
|
415
383
|
facets.machine.updateMetrics();
|
|
416
384
|
state.managerCounter += 1;
|
|
417
385
|
return vm;
|
|
@@ -6,10 +6,8 @@ import '@agoric/zoe/src/contracts/exported.js';
|
|
|
6
6
|
//
|
|
7
7
|
// addVaultType is a closely held method that adds a brand new collateral type.
|
|
8
8
|
// It specifies the initial exchange rate for that type. It depends on a
|
|
9
|
-
// separately specified
|
|
10
|
-
// in arrears.
|
|
11
|
-
// moment leave that to those participating in the governance process for adding
|
|
12
|
-
// new collateral type to ascertain.
|
|
9
|
+
// separately specified mechanism to liquidate loans that are
|
|
10
|
+
// in arrears.
|
|
13
11
|
|
|
14
12
|
// This contract wants to be managed by a contractGovernor, but it isn't
|
|
15
13
|
// compatible with contractGovernor, since it has a separate paramManager for
|
|
@@ -22,8 +20,6 @@ import { makeStoredPublisherKit } from '@agoric/notifier';
|
|
|
22
20
|
import { assertAllDefined } from '@agoric/internal';
|
|
23
21
|
import {
|
|
24
22
|
makeVaultDirectorParamManager,
|
|
25
|
-
LIQUIDATION_INSTALL_KEY,
|
|
26
|
-
LIQUIDATION_TERMS_KEY,
|
|
27
23
|
MIN_INITIAL_DEBT_KEY,
|
|
28
24
|
ENDORSED_UI_KEY,
|
|
29
25
|
} from './params.js';
|
|
@@ -31,8 +27,6 @@ import { prepareVaultDirector } from './vaultDirector.js';
|
|
|
31
27
|
|
|
32
28
|
/**
|
|
33
29
|
* @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
|
|
34
|
-
* ammPublicFacet: AutoswapPublicFacet,
|
|
35
|
-
* liquidationInstall: Installation<import('./liquidateMinimum.js').start>,
|
|
36
30
|
* loanTimingParams: {ChargingPeriod: ParamValueTyped<'nat'>, RecordingPeriod: ParamValueTyped<'nat'>},
|
|
37
31
|
* minInitialDebt: Amount,
|
|
38
32
|
* priceAuthority: ERef<PriceAuthority>,
|
|
@@ -74,8 +68,6 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
74
68
|
}));
|
|
75
69
|
|
|
76
70
|
const {
|
|
77
|
-
[LIQUIDATION_INSTALL_KEY]: { value: liqInstall },
|
|
78
|
-
[LIQUIDATION_TERMS_KEY]: { value: liqTerms },
|
|
79
71
|
[MIN_INITIAL_DEBT_KEY]: { value: minInitialDebt },
|
|
80
72
|
[ENDORSED_UI_KEY]: { value: endorsedUi },
|
|
81
73
|
} = zcf.getTerms().governedParams;
|
|
@@ -84,8 +76,6 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
84
76
|
makeStoredPublisherKit(storageNode, marshaller, 'governance'),
|
|
85
77
|
zcf.getZoeService(),
|
|
86
78
|
initialPoserInvitation,
|
|
87
|
-
liqInstall,
|
|
88
|
-
liqTerms,
|
|
89
79
|
minInitialDebt,
|
|
90
80
|
initialShortfallInvitation,
|
|
91
81
|
endorsedUi,
|