@agoric/inter-protocol 0.13.2-dev-606cbd2.0 → 0.13.2-dev-8d17cce.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-auctioneer-js-meta.json +123 -119
- package/bundles/bundle-auctioneer.js +1 -1
- package/bundles/bundle-econCommitteeCharter-js-meta.json +71 -71
- package/bundles/bundle-econCommitteeCharter.js +1 -1
- package/bundles/bundle-feeDistributor-js-meta.json +59 -59
- package/bundles/bundle-feeDistributor.js +1 -1
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +143 -139
- package/bundles/bundle-fluxAggregatorKit.js +1 -1
- package/bundles/bundle-psm-js-meta.json +136 -132
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-js-meta.json +115 -111
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +125 -121
- package/bundles/bundle-scaledPriceAuthority.js +1 -1
- package/bundles/bundle-vaultFactory-js-meta.json +188 -184
- package/bundles/bundle-vaultFactory.js +1 -1
- package/package.json +17 -17
- package/scripts/add-collateral-core.js +2 -0
- package/scripts/init-core.js +1 -0
- package/scripts/invite-committee-core.js +1 -0
- package/scripts/price-feed-core.js +1 -0
- package/src/auction/auctionBook.js +11 -11
- package/src/auction/auctioneer.js +15 -11
- package/src/auction/params.js +4 -4
- package/src/auction/scheduleMath.js +77 -32
- package/src/auction/scheduler.js +191 -79
- package/src/auction/util.js +7 -0
- package/src/clientSupport.js +1 -2
- package/src/price/fluxAggregatorContract.js +29 -6
- package/src/proposals/addAssetToVault.js +6 -34
- package/src/proposals/committee-proposal.js +9 -9
- package/src/proposals/core-proposal.js +58 -1
- package/src/proposals/econ-behaviors.js +56 -45
- package/src/proposals/price-feed-proposal.js +9 -21
- package/src/proposals/startEconCommittee.js +14 -6
- package/src/proposals/startPSM.js +51 -34
- package/src/psm/psm.js +11 -6
- package/src/reserve/assetReserveKit.js +1 -1
- package/src/vaultFactory/liquidation.js +168 -33
- package/src/vaultFactory/vault.js +5 -4
- package/src/vaultFactory/vaultDirector.js +27 -17
- package/src/vaultFactory/vaultFactory.js +26 -11
- package/src/vaultFactory/vaultManager.js +139 -95
|
@@ -31,7 +31,6 @@ import {
|
|
|
31
31
|
M,
|
|
32
32
|
makeScalarBigMapStore,
|
|
33
33
|
makeScalarBigSetStore,
|
|
34
|
-
makeScalarMapStore,
|
|
35
34
|
prepareExoClassKit,
|
|
36
35
|
provide,
|
|
37
36
|
} from '@agoric/vat-data';
|
|
@@ -64,7 +63,7 @@ import { Phase, prepareVault } from './vault.js';
|
|
|
64
63
|
|
|
65
64
|
const { details: X, Fail } = assert;
|
|
66
65
|
|
|
67
|
-
const trace = makeTracer('VM'
|
|
66
|
+
const trace = makeTracer('VM');
|
|
68
67
|
|
|
69
68
|
/** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */
|
|
70
69
|
/** @typedef {import('@agoric/time/src/types').RelativeTime} RelativeTime */
|
|
@@ -275,7 +274,7 @@ export const prepareVaultManagerKit = (
|
|
|
275
274
|
AmountShape,
|
|
276
275
|
M.arrayOf(TransferPartShape),
|
|
277
276
|
).returns(),
|
|
278
|
-
|
|
277
|
+
burn: M.call(AmountShape, SeatShape).returns(),
|
|
279
278
|
getAssetSubscriber: M.call().returns(SubscriberShape),
|
|
280
279
|
getCollateralBrand: M.call().returns(BrandShape),
|
|
281
280
|
getDebtBrand: M.call().returns(BrandShape),
|
|
@@ -355,6 +354,7 @@ export const prepareVaultManagerKit = (
|
|
|
355
354
|
*/
|
|
356
355
|
start() {
|
|
357
356
|
const { state, facets } = this;
|
|
357
|
+
trace(state.collateralBrand, 'helper.start()', state.vaultCounter);
|
|
358
358
|
const {
|
|
359
359
|
collateralBrand,
|
|
360
360
|
collateralUnit,
|
|
@@ -366,6 +366,7 @@ export const prepareVaultManagerKit = (
|
|
|
366
366
|
const ephemera = collateralEphemera(collateralBrand);
|
|
367
367
|
ephemera.prioritizedVaults = makePrioritizedVaults(unsettledVaults);
|
|
368
368
|
|
|
369
|
+
trace('helper.start() making periodNotifier');
|
|
369
370
|
const periodNotifier = E(timerService).makeNotifier(
|
|
370
371
|
0n,
|
|
371
372
|
factoryPowers
|
|
@@ -373,6 +374,7 @@ export const prepareVaultManagerKit = (
|
|
|
373
374
|
.getChargingPeriod(),
|
|
374
375
|
);
|
|
375
376
|
|
|
377
|
+
trace('helper.start() starting observe periodNotifier');
|
|
376
378
|
void observeNotifier(periodNotifier, {
|
|
377
379
|
updateState: updateTime =>
|
|
378
380
|
facets.helper
|
|
@@ -392,6 +394,7 @@ export const prepareVaultManagerKit = (
|
|
|
392
394
|
},
|
|
393
395
|
});
|
|
394
396
|
|
|
397
|
+
trace('helper.start() making quoteNotifier from', priceAuthority);
|
|
395
398
|
const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
|
|
396
399
|
collateralUnit,
|
|
397
400
|
debtBrand,
|
|
@@ -401,14 +404,20 @@ export const prepareVaultManagerKit = (
|
|
|
401
404
|
E(storageNode).makeChildNode('quotes'),
|
|
402
405
|
marshaller,
|
|
403
406
|
);
|
|
407
|
+
trace('helper.start() awaiting observe storedQuotesNotifier');
|
|
408
|
+
// NB: upon restart, there may not be a price for a while. If manager
|
|
409
|
+
// operations are permitted, ones the depend on price information will
|
|
410
|
+
// throw. See https://github.com/Agoric/agoric-sdk/issues/4317
|
|
404
411
|
void observeNotifier(quoteNotifier, {
|
|
405
412
|
updateState(value) {
|
|
413
|
+
trace('vaultManager got new collateral quote', value);
|
|
406
414
|
ephemera.storedCollateralQuote = value;
|
|
407
415
|
},
|
|
408
416
|
fail(reason) {
|
|
409
417
|
console.error('quoteNotifier failed to iterate', reason);
|
|
410
418
|
},
|
|
411
419
|
});
|
|
420
|
+
trace('helper.start() done');
|
|
412
421
|
},
|
|
413
422
|
/**
|
|
414
423
|
* @param {Timestamp} updateTime
|
|
@@ -416,7 +425,7 @@ export const prepareVaultManagerKit = (
|
|
|
416
425
|
async chargeAllVaults(updateTime) {
|
|
417
426
|
const { state, facets } = this;
|
|
418
427
|
const { collateralBrand, debtMint, poolIncrementSeat } = state;
|
|
419
|
-
trace('chargeAllVaults',
|
|
428
|
+
trace(collateralBrand, 'chargeAllVaults', {
|
|
420
429
|
updateTime,
|
|
421
430
|
});
|
|
422
431
|
|
|
@@ -486,28 +495,6 @@ export const prepareVaultManagerKit = (
|
|
|
486
495
|
proceeds,
|
|
487
496
|
);
|
|
488
497
|
},
|
|
489
|
-
|
|
490
|
-
/** @type {(accounting: { overage: Amount<'nat'>, shortfall: Amount<'nat'> }) => void} */
|
|
491
|
-
recordShortfallAndProceeds(accounting) {
|
|
492
|
-
trace('recordShortfallAndProceeds', accounting);
|
|
493
|
-
const { state } = this;
|
|
494
|
-
|
|
495
|
-
const { overage, shortfall } = accounting;
|
|
496
|
-
// cumulative values
|
|
497
|
-
state.totalOverageReceived = AmountMath.add(
|
|
498
|
-
state.totalOverageReceived,
|
|
499
|
-
overage,
|
|
500
|
-
);
|
|
501
|
-
state.totalShortfallReceived = AmountMath.add(
|
|
502
|
-
state.totalShortfallReceived,
|
|
503
|
-
shortfall,
|
|
504
|
-
);
|
|
505
|
-
state.totalDebt = AmountMath.subtract(state.totalDebt, shortfall);
|
|
506
|
-
|
|
507
|
-
void E.when(factoryPowers.getShortfallReporter(), reporter =>
|
|
508
|
-
E(reporter).increaseLiquidationShortfall(shortfall),
|
|
509
|
-
);
|
|
510
|
-
},
|
|
511
498
|
sendToReserve(penalty, seat, seatKeyword = 'Collateral') {
|
|
512
499
|
const invitation =
|
|
513
500
|
E(reservePublicFacet).makeAddCollateralInvitation();
|
|
@@ -545,9 +532,17 @@ export const prepareVaultManagerKit = (
|
|
|
545
532
|
|
|
546
533
|
state.liquidatingDebt = AmountMath.add(state.liquidatingDebt, debt);
|
|
547
534
|
},
|
|
548
|
-
|
|
535
|
+
/**
|
|
536
|
+
*
|
|
537
|
+
* @param {Amount<'nat'>} debt
|
|
538
|
+
* @param {Amount<'nat'>} collateral
|
|
539
|
+
* @param {{ overage: Amount<'nat'>, shortfall: Amount<'nat'> }} accounting
|
|
540
|
+
*/
|
|
541
|
+
markDoneLiquidating(debt, collateral, accounting) {
|
|
549
542
|
const { state } = this;
|
|
550
543
|
|
|
544
|
+
// update liquidation state
|
|
545
|
+
|
|
551
546
|
state.liquidatingCollateral = AmountMath.subtract(
|
|
552
547
|
state.liquidatingCollateral,
|
|
553
548
|
collateral,
|
|
@@ -556,6 +551,32 @@ export const prepareVaultManagerKit = (
|
|
|
556
551
|
state.liquidatingDebt,
|
|
557
552
|
debt,
|
|
558
553
|
);
|
|
554
|
+
|
|
555
|
+
// record shortfall and proceeds
|
|
556
|
+
|
|
557
|
+
const { overage, shortfall } = accounting;
|
|
558
|
+
// cumulative values
|
|
559
|
+
state.totalOverageReceived = AmountMath.add(
|
|
560
|
+
state.totalOverageReceived,
|
|
561
|
+
overage,
|
|
562
|
+
);
|
|
563
|
+
state.totalShortfallReceived = AmountMath.add(
|
|
564
|
+
state.totalShortfallReceived,
|
|
565
|
+
shortfall,
|
|
566
|
+
);
|
|
567
|
+
state.totalDebt = AmountMath.subtract(state.totalDebt, shortfall);
|
|
568
|
+
|
|
569
|
+
E.when(
|
|
570
|
+
factoryPowers.getShortfallReporter(),
|
|
571
|
+
reporter => E(reporter).increaseLiquidationShortfall(shortfall),
|
|
572
|
+
err =>
|
|
573
|
+
console.error(
|
|
574
|
+
'🛠️ getShortfallReporter() failed during liquidation; repair by updating governance',
|
|
575
|
+
err,
|
|
576
|
+
),
|
|
577
|
+
).catch(err => {
|
|
578
|
+
console.error('🚨 failed to report liquidation shortfall', err);
|
|
579
|
+
});
|
|
559
580
|
},
|
|
560
581
|
/**
|
|
561
582
|
* If interest was charged between liquidating and liquidated, erase it.
|
|
@@ -576,7 +597,7 @@ export const prepareVaultManagerKit = (
|
|
|
576
597
|
|
|
577
598
|
state.totalDebt = AmountMath.add(state.totalDebt, debt);
|
|
578
599
|
},
|
|
579
|
-
|
|
600
|
+
writeMetrics() {
|
|
580
601
|
const { state } = this;
|
|
581
602
|
const { collateralBrand, retainedCollateralSeat, metricsTopicKit } =
|
|
582
603
|
state;
|
|
@@ -628,10 +649,13 @@ export const prepareVaultManagerKit = (
|
|
|
628
649
|
const accounting = liquidationResults(totalDebt, mintedProceeds);
|
|
629
650
|
const { Collateral: collateralProceeds } = proceeds;
|
|
630
651
|
|
|
631
|
-
/** @type {
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
652
|
+
/** @type {Array<Vault>} */
|
|
653
|
+
const vaultsToLiquidate = [];
|
|
654
|
+
const liquidateAll = () => {
|
|
655
|
+
for (const vault of vaultsToLiquidate) {
|
|
656
|
+
vault.liquidated();
|
|
657
|
+
liquidatingVaults.delete(vault);
|
|
658
|
+
}
|
|
635
659
|
};
|
|
636
660
|
|
|
637
661
|
const penaltyRate = facets.self
|
|
@@ -689,7 +713,7 @@ export const prepareVaultManagerKit = (
|
|
|
689
713
|
{ Collateral: collat },
|
|
690
714
|
]);
|
|
691
715
|
}
|
|
692
|
-
|
|
716
|
+
vaultsToLiquidate.push(vault);
|
|
693
717
|
}
|
|
694
718
|
if (transfers.length > 0) {
|
|
695
719
|
atomicRearrange(zcf, harden(transfers));
|
|
@@ -705,7 +729,11 @@ export const prepareVaultManagerKit = (
|
|
|
705
729
|
vaultData.getSize(),
|
|
706
730
|
);
|
|
707
731
|
|
|
708
|
-
facets.helper.markDoneLiquidating(
|
|
732
|
+
facets.helper.markDoneLiquidating(
|
|
733
|
+
totalDebt,
|
|
734
|
+
totalCollateral,
|
|
735
|
+
accounting,
|
|
736
|
+
);
|
|
709
737
|
} else if (AmountMath.isEmpty(collateralProceeds)) {
|
|
710
738
|
// Flow #2a
|
|
711
739
|
|
|
@@ -760,7 +788,7 @@ export const prepareVaultManagerKit = (
|
|
|
760
788
|
const seat = vault.getVaultSeat();
|
|
761
789
|
transfers.push([liqSeat, seat, { Minted: mintedToReturn }]);
|
|
762
790
|
}
|
|
763
|
-
|
|
791
|
+
vaultsToLiquidate.push(vault);
|
|
764
792
|
}
|
|
765
793
|
|
|
766
794
|
if (transfers.length > 0) {
|
|
@@ -772,7 +800,11 @@ export const prepareVaultManagerKit = (
|
|
|
772
800
|
vaultData.getSize(),
|
|
773
801
|
);
|
|
774
802
|
|
|
775
|
-
facets.helper.markDoneLiquidating(
|
|
803
|
+
facets.helper.markDoneLiquidating(
|
|
804
|
+
totalDebt,
|
|
805
|
+
totalCollateral,
|
|
806
|
+
accounting,
|
|
807
|
+
);
|
|
776
808
|
} else {
|
|
777
809
|
// Flow #2b: There's unsold collateral; some vaults may be revived.
|
|
778
810
|
|
|
@@ -791,13 +823,22 @@ export const prepareVaultManagerKit = (
|
|
|
791
823
|
: AmountMath.makeEmptyFromAmount(collateralProceeds);
|
|
792
824
|
|
|
793
825
|
let collatRemaining = distributableCollateral;
|
|
794
|
-
let debtRemaining = totalDebt;
|
|
795
826
|
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
|
|
796
827
|
const transfers = [];
|
|
797
828
|
let liquidated = 0;
|
|
798
|
-
/** @type {
|
|
799
|
-
const vaultsToReinstate =
|
|
829
|
+
/** @type {Array<Vault>} */
|
|
830
|
+
const vaultsToReinstate = [];
|
|
831
|
+
const reinstateAll = () => {
|
|
832
|
+
const { prioritizedVaults } = collateralEphemera(collateralBrand);
|
|
833
|
+
for (const vault of vaultsToReinstate) {
|
|
834
|
+
const vaultId = vault.abortLiquidation();
|
|
835
|
+
prioritizedVaults.addVault(vaultId, vault);
|
|
836
|
+
liquidatingVaults.delete(vault);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
|
|
800
840
|
let collateralReduction = AmountMath.makeEmpty(collateralBrand);
|
|
841
|
+
let shortfallToReserve = accounting.shortfall;
|
|
801
842
|
|
|
802
843
|
const reduceCollateral = amount =>
|
|
803
844
|
(collateralReduction = AmountMath.add(
|
|
@@ -815,18 +856,19 @@ export const prepareVaultManagerKit = (
|
|
|
815
856
|
if (
|
|
816
857
|
reconstituteVaults &&
|
|
817
858
|
AmountMath.isGTE(collatRemaining, collatPostDebt) &&
|
|
818
|
-
AmountMath.isGTE(
|
|
859
|
+
AmountMath.isGTE(totalDebt, debtAmount)
|
|
819
860
|
) {
|
|
820
861
|
collatRemaining = AmountMath.subtract(
|
|
821
862
|
collatRemaining,
|
|
822
863
|
collatPostDebt,
|
|
823
864
|
);
|
|
824
|
-
|
|
865
|
+
shortfallToReserve = AmountMath.subtract(
|
|
866
|
+
shortfallToReserve,
|
|
867
|
+
debtAmount,
|
|
868
|
+
);
|
|
825
869
|
const seat = vault.getVaultSeat();
|
|
826
|
-
const vaultId = vault.abortLiquidation();
|
|
827
|
-
liquidatingVaults.delete(vault);
|
|
828
870
|
// must reinstate after atomicRearrange(), so we record them.
|
|
829
|
-
vaultsToReinstate.
|
|
871
|
+
vaultsToReinstate.push(vault);
|
|
830
872
|
reduceCollateral(vaultDebt);
|
|
831
873
|
transfers.push([liqSeat, seat, { Collateral: collatPostDebt }]);
|
|
832
874
|
} else {
|
|
@@ -838,7 +880,7 @@ export const prepareVaultManagerKit = (
|
|
|
838
880
|
);
|
|
839
881
|
|
|
840
882
|
reduceCollateral(vCollat);
|
|
841
|
-
|
|
883
|
+
vaultsToLiquidate.push(vault);
|
|
842
884
|
}
|
|
843
885
|
}
|
|
844
886
|
|
|
@@ -848,10 +890,7 @@ export const prepareVaultManagerKit = (
|
|
|
848
890
|
if (transfers.length > 0) {
|
|
849
891
|
atomicRearrange(zcf, harden(transfers));
|
|
850
892
|
}
|
|
851
|
-
|
|
852
|
-
for (const [vaultId, vault] of vaultsToReinstate.entries()) {
|
|
853
|
-
prioritizedVaults.addVault(vaultId, vault);
|
|
854
|
-
}
|
|
893
|
+
reinstateAll();
|
|
855
894
|
|
|
856
895
|
facets.helper.markCollateralLiquidated(
|
|
857
896
|
collateralReduction,
|
|
@@ -859,14 +898,14 @@ export const prepareVaultManagerKit = (
|
|
|
859
898
|
transfers.length,
|
|
860
899
|
);
|
|
861
900
|
|
|
862
|
-
facets.helper.markRestoreDebt(
|
|
863
|
-
AmountMath.subtract(totalDebt, debtRemaining),
|
|
864
|
-
);
|
|
865
901
|
facets.helper.sendToReserve(collatRemaining, liqSeat);
|
|
866
|
-
facets.helper.markDoneLiquidating(totalDebt, totalCollateral
|
|
902
|
+
facets.helper.markDoneLiquidating(totalDebt, totalCollateral, {
|
|
903
|
+
...accounting,
|
|
904
|
+
shortfall: shortfallToReserve,
|
|
905
|
+
});
|
|
867
906
|
}
|
|
868
|
-
|
|
869
|
-
return facets.helper.
|
|
907
|
+
liquidateAll();
|
|
908
|
+
return facets.helper.writeMetrics();
|
|
870
909
|
},
|
|
871
910
|
},
|
|
872
911
|
|
|
@@ -915,22 +954,20 @@ export const prepareVaultManagerKit = (
|
|
|
915
954
|
toMint,
|
|
916
955
|
);
|
|
917
956
|
factoryPowers.mintAndTransfer(mintReceiver, toMint, fee, transfers);
|
|
918
|
-
state.totalDebt = AmountMath.add(state.totalDebt, toMint);
|
|
919
957
|
},
|
|
920
958
|
/**
|
|
921
959
|
* @param {Amount<'nat'>} toBurn
|
|
922
960
|
* @param {ZCFSeat} seat
|
|
923
961
|
*/
|
|
924
|
-
|
|
962
|
+
burn(toBurn, seat) {
|
|
925
963
|
const { state } = this;
|
|
926
964
|
const { collateralBrand } = this.state;
|
|
927
965
|
|
|
928
|
-
trace('
|
|
966
|
+
trace(collateralBrand, 'burn', {
|
|
929
967
|
toBurn,
|
|
930
968
|
totalDebt: state.totalDebt,
|
|
931
969
|
});
|
|
932
970
|
factoryPowers.burnDebt(toBurn, seat);
|
|
933
|
-
state.totalDebt = AmountMath.subtract(state.totalDebt, toBurn);
|
|
934
971
|
},
|
|
935
972
|
getAssetSubscriber() {
|
|
936
973
|
return this.state.assetTopicKit.subscriber;
|
|
@@ -966,6 +1003,7 @@ export const prepareVaultManagerKit = (
|
|
|
966
1003
|
* @param {VaultId} vaultId
|
|
967
1004
|
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of whatever change updated balances
|
|
968
1005
|
* @param {Vault} vault
|
|
1006
|
+
* @returns {void}
|
|
969
1007
|
*/
|
|
970
1008
|
handleBalanceChange(
|
|
971
1009
|
oldDebtNormalized,
|
|
@@ -1004,41 +1042,42 @@ export const prepareVaultManagerKit = (
|
|
|
1004
1042
|
),
|
|
1005
1043
|
'Settled vaults must not be retained in storage',
|
|
1006
1044
|
);
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
trace({ isNew });
|
|
1010
|
-
if (!isNew) {
|
|
1011
|
-
// its position in the queue is no longer valid
|
|
1012
|
-
|
|
1013
|
-
const vaultInStore = prioritizedVaults.removeVaultByAttributes(
|
|
1014
|
-
oldDebtNormalized,
|
|
1015
|
-
oldCollateral,
|
|
1016
|
-
vaultId,
|
|
1017
|
-
);
|
|
1018
|
-
assert(
|
|
1019
|
-
vault === vaultInStore,
|
|
1020
|
-
'handleBalanceChange for two different vaults',
|
|
1021
|
-
);
|
|
1022
|
-
trace('removed', vault, vaultId);
|
|
1023
|
-
}
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1024
1047
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
}
|
|
1048
|
+
const isNew = AmountMath.isEmpty(oldDebtNormalized);
|
|
1049
|
+
trace(state.collateralBrand, { isNew });
|
|
1050
|
+
if (!isNew) {
|
|
1051
|
+
// its position in the queue is no longer valid
|
|
1030
1052
|
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
AmountMath.add(
|
|
1034
|
-
state.totalCollateral,
|
|
1035
|
-
vault.getCollateralAmount(),
|
|
1036
|
-
),
|
|
1053
|
+
const vaultInStore = prioritizedVaults.removeVaultByAttributes(
|
|
1054
|
+
oldDebtNormalized,
|
|
1037
1055
|
oldCollateral,
|
|
1056
|
+
vaultId,
|
|
1057
|
+
);
|
|
1058
|
+
assert(
|
|
1059
|
+
vault === vaultInStore,
|
|
1060
|
+
'handleBalanceChange for two different vaults',
|
|
1038
1061
|
);
|
|
1039
|
-
|
|
1040
|
-
facets.helper.updateMetrics();
|
|
1062
|
+
trace('removed', vault, vaultId);
|
|
1041
1063
|
}
|
|
1064
|
+
|
|
1065
|
+
// replace in queue, but only if it can accrue interest or be liquidated (i.e. has debt).
|
|
1066
|
+
// getCurrentDebt() would also work (0x = 0) but require more computation.
|
|
1067
|
+
if (!AmountMath.isEmpty(vault.getNormalizedDebt())) {
|
|
1068
|
+
prioritizedVaults.addVault(vaultId, vault);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// total += vault's delta (post — pre)
|
|
1072
|
+
state.totalCollateral = AmountMath.subtract(
|
|
1073
|
+
AmountMath.add(state.totalCollateral, vault.getCollateralAmount()),
|
|
1074
|
+
oldCollateral,
|
|
1075
|
+
);
|
|
1076
|
+
state.totalDebt = AmountMath.subtract(
|
|
1077
|
+
AmountMath.add(state.totalDebt, vault.getCurrentDebt()),
|
|
1078
|
+
oldDebtNormalized,
|
|
1079
|
+
);
|
|
1080
|
+
void facets.helper.writeMetrics();
|
|
1042
1081
|
},
|
|
1043
1082
|
},
|
|
1044
1083
|
self: {
|
|
@@ -1051,11 +1090,11 @@ export const prepareVaultManagerKit = (
|
|
|
1051
1090
|
* @param {ZCFSeat} seat
|
|
1052
1091
|
*/
|
|
1053
1092
|
async makeVaultKit(seat) {
|
|
1054
|
-
trace('makeVaultKit');
|
|
1055
1093
|
const {
|
|
1056
1094
|
state,
|
|
1057
1095
|
facets: { manager },
|
|
1058
1096
|
} = this;
|
|
1097
|
+
trace(state.collateralBrand, 'makeVaultKit');
|
|
1059
1098
|
const { storageNode } = this.state;
|
|
1060
1099
|
assert(marshaller, 'makeVaultKit missing marshaller');
|
|
1061
1100
|
assert(storageNode, 'makeVaultKit missing storageNode');
|
|
@@ -1069,7 +1108,7 @@ export const prepareVaultManagerKit = (
|
|
|
1069
1108
|
).makeChildNode(`vault${vaultId}`);
|
|
1070
1109
|
|
|
1071
1110
|
const { self: vault } = makeVault(manager, vaultId, vaultStorageNode);
|
|
1072
|
-
trace('makeVaultKit made vault', vault);
|
|
1111
|
+
trace(state.collateralBrand, 'makeVaultKit made vault', vault);
|
|
1073
1112
|
|
|
1074
1113
|
try {
|
|
1075
1114
|
// TODO `await` is allowed until the above ordering is fixed
|
|
@@ -1168,7 +1207,7 @@ export const prepareVaultManagerKit = (
|
|
|
1168
1207
|
liquidatingVaults,
|
|
1169
1208
|
lockedQuote,
|
|
1170
1209
|
} = state;
|
|
1171
|
-
trace('considering liquidation');
|
|
1210
|
+
trace(collateralBrand, 'considering liquidation');
|
|
1172
1211
|
|
|
1173
1212
|
const { prioritizedVaults } = collateralEphemera(collateralBrand);
|
|
1174
1213
|
assert(factoryPowers && prioritizedVaults && zcf);
|
|
@@ -1191,6 +1230,9 @@ export const prepareVaultManagerKit = (
|
|
|
1191
1230
|
debtBrand,
|
|
1192
1231
|
collateralBrand,
|
|
1193
1232
|
);
|
|
1233
|
+
// reset lockedQuote after we've used it for the liquidation decision
|
|
1234
|
+
state.lockedQuote = undefined;
|
|
1235
|
+
|
|
1194
1236
|
if (vaultData.getSize() === 0) {
|
|
1195
1237
|
return;
|
|
1196
1238
|
}
|
|
@@ -1201,7 +1243,7 @@ export const prepareVaultManagerKit = (
|
|
|
1201
1243
|
);
|
|
1202
1244
|
|
|
1203
1245
|
helper.markLiquidating(totalDebt, totalCollateral);
|
|
1204
|
-
helper.
|
|
1246
|
+
void helper.writeMetrics();
|
|
1205
1247
|
|
|
1206
1248
|
const { userSeatPromise, deposited } = await E.when(
|
|
1207
1249
|
E(auctionPF).makeDepositInvitation(),
|
|
@@ -1227,7 +1269,7 @@ export const prepareVaultManagerKit = (
|
|
|
1227
1269
|
);
|
|
1228
1270
|
|
|
1229
1271
|
trace(`LiqV after long wait`, proceeds);
|
|
1230
|
-
helper.distributeProceeds(
|
|
1272
|
+
return helper.distributeProceeds(
|
|
1231
1273
|
proceeds,
|
|
1232
1274
|
totalDebt,
|
|
1233
1275
|
storedCollateralQuote,
|
|
@@ -1253,7 +1295,7 @@ export const prepareVaultManagerKit = (
|
|
|
1253
1295
|
);
|
|
1254
1296
|
|
|
1255
1297
|
// push initial state of metrics
|
|
1256
|
-
helper.
|
|
1298
|
+
void helper.writeMetrics();
|
|
1257
1299
|
},
|
|
1258
1300
|
},
|
|
1259
1301
|
);
|
|
@@ -1289,6 +1331,7 @@ export const prepareVaultManagerKit = (
|
|
|
1289
1331
|
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
1290
1332
|
*/
|
|
1291
1333
|
export const provideAndStartVaultManagerKits = baggage => {
|
|
1334
|
+
trace('provideAndStartVaultManagerKits start');
|
|
1292
1335
|
const key = 'vaultManagerKits';
|
|
1293
1336
|
|
|
1294
1337
|
const noKits = /** @type {VaultManagerKit[]} */ (harden([]));
|
|
@@ -1297,6 +1340,7 @@ export const provideAndStartVaultManagerKits = baggage => {
|
|
|
1297
1340
|
kit.helper.start();
|
|
1298
1341
|
}
|
|
1299
1342
|
|
|
1343
|
+
trace('provideAndStartVaultManagerKits returning');
|
|
1300
1344
|
return {
|
|
1301
1345
|
/** @type {(kit: VaultManagerKit) => void} */
|
|
1302
1346
|
add: kit => {
|