@agoric/inter-protocol 0.13.2-dev-70ba9b0.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.
Files changed (70) hide show
  1. package/bundles/bundle-econCommitteeCharter-meta.js +78 -78
  2. package/bundles/bundle-econCommitteeCharter.js +1 -1
  3. package/bundles/bundle-feeDistributor-meta.js +61 -61
  4. package/bundles/bundle-feeDistributor.js +1 -1
  5. package/bundles/bundle-fluxAggregator-meta.js +188 -188
  6. package/bundles/bundle-fluxAggregator.js +1 -1
  7. package/bundles/bundle-psm-meta.js +112 -112
  8. package/bundles/bundle-psm.js +1 -1
  9. package/bundles/bundle-reserve-meta.js +110 -114
  10. package/bundles/bundle-reserve.js +1 -1
  11. package/bundles/bundle-scaledPriceAuthority-meta.js +78 -78
  12. package/bundles/bundle-stakeFactory-meta.js +118 -118
  13. package/bundles/bundle-stakeFactory.js +1 -1
  14. package/bundles/bundle-vaultFactory-meta.js +130 -130
  15. package/bundles/bundle-vaultFactory.js +1 -1
  16. package/exported.js +0 -1
  17. package/package.json +16 -16
  18. package/scripts/deploy-contracts.js +0 -2
  19. package/scripts/init-core.js +0 -16
  20. package/src/feeDistributor.js +1 -1
  21. package/src/proposals/addAssetToVault.js +4 -57
  22. package/src/proposals/committee-proposal.js +3 -6
  23. package/src/proposals/core-proposal.js +1 -73
  24. package/src/proposals/demoIssuers.js +1 -232
  25. package/src/proposals/econ-behaviors.js +10 -193
  26. package/src/proposals/sim-behaviors.js +1 -1
  27. package/src/reserve/assetReserve.js +9 -170
  28. package/src/reserve/params.js +1 -4
  29. package/src/vaultFactory/liquidateIncrementally.js +16 -141
  30. package/src/vaultFactory/liquidateMinimum.js +19 -21
  31. package/src/vaultFactory/params.js +0 -29
  32. package/src/vaultFactory/types.js +0 -6
  33. package/src/vaultFactory/vault.js +1 -3
  34. package/src/vaultFactory/vaultDirector.js +1 -33
  35. package/src/vaultFactory/vaultFactory.js +2 -12
  36. package/src/vaultFactory/vaultManager.js +10 -217
  37. package/bundles/bundle-amm-meta.js +0 -686
  38. package/bundles/bundle-amm.js +0 -1
  39. package/bundles/bundle-interchainPool-meta.js +0 -606
  40. package/bundles/bundle-interchainPool.js +0 -1
  41. package/bundles/bundle-liquidateIncrementally-meta.js +0 -470
  42. package/bundles/bundle-liquidateIncrementally.js +0 -1
  43. package/bundles/bundle-liquidateMinimum-meta.js +0 -470
  44. package/bundles/bundle-liquidateMinimum.js +0 -1
  45. package/scripts/add-initial-liquidity.js +0 -179
  46. package/src/interchainPool.js +0 -134
  47. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  48. package/src/vpool-xyk-amm/addLiquidity.js +0 -221
  49. package/src/vpool-xyk-amm/addPool.js +0 -200
  50. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  51. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  52. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -93
  53. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -83
  54. package/src/vpool-xyk-amm/constantProduct/core.js +0 -145
  55. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -3
  56. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -48
  57. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -114
  58. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -39
  59. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -270
  60. package/src/vpool-xyk-amm/constantProduct/types.js +0 -30
  61. package/src/vpool-xyk-amm/doublePool.js +0 -200
  62. package/src/vpool-xyk-amm/estimate.js +0 -175
  63. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -530
  64. package/src/vpool-xyk-amm/params.js +0 -59
  65. package/src/vpool-xyk-amm/pool.js +0 -398
  66. package/src/vpool-xyk-amm/priceAuthority.js +0 -92
  67. package/src/vpool-xyk-amm/removeLiquidity.js +0 -29
  68. package/src/vpool-xyk-amm/singlePool.js +0 -88
  69. package/src/vpool-xyk-amm/swap.js +0 -68
  70. package/src/vpool-xyk-amm/types.js +0 -152
@@ -39,20 +39,15 @@ import {
39
39
  } from '@agoric/vat-data';
40
40
  import {
41
41
  assertProposalShape,
42
- atomicTransfer,
43
- ceilDivideBy,
44
- getAmountIn,
45
- getAmountOut,
46
42
  makeRatio,
47
- makeRatioFromAmounts,
48
43
  provideEmptySeat,
49
44
  } from '@agoric/zoe/src/contractSupport/index.js';
50
- import { InstallationShape, SeatShape } from '@agoric/zoe/src/typeGuards.js';
45
+ import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
51
46
  import { E } from '@endo/eventual-send';
52
47
  import { TransferPartShape } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
53
48
  import { checkDebtLimit } from '../contractSupport.js';
54
49
  import { chargeInterest } from '../interest.js';
55
- import { liquidate, makeQuote, updateQuote } from './liquidation.js';
50
+ import { updateQuote } from './liquidation.js';
56
51
  import { maxDebtForVault } from './math.js';
57
52
  import { makePrioritizedVaults } from './prioritizedVaults.js';
58
53
  import { Phase, prepareVault } from './vault.js';
@@ -207,6 +202,8 @@ export const prepareVaultManagerKit = (
207
202
  );
208
203
 
209
204
  const poolIncrementSeat = provideEmptySeat(zcf, baggage, 'pool increment');
205
+
206
+ // TODO(#7074) not used while liquidation is disabled. Reinstate with #7074
210
207
  const retainedCollateralSeat = provideEmptySeat(
211
208
  zcf,
212
209
  baggage,
@@ -229,8 +226,11 @@ export const prepareVaultManagerKit = (
229
226
  // ephemeral state
230
227
  /** @type {boolean} */
231
228
  let liquidationQueueing = false;
229
+
230
+ // TODO: (#7047) this variable is vestigial and will go away when we replace
231
+ // liquidation with use of an Auction
232
232
  /** @type {Promise<MutableQuote>?} */
233
- let outstandingQuote = null;
233
+ const outstandingQuote = null;
234
234
 
235
235
  /**
236
236
  * This class is a singleton kind so initState will be called only once per prepare.
@@ -297,11 +297,7 @@ export const prepareVaultManagerKit = (
297
297
  }),
298
298
  self: M.interface('self', {
299
299
  getGovernedParams: M.call().returns(M.remotable()),
300
- liquidateAll: M.call().returns(M.promise()),
301
300
  makeVaultKit: M.call(SeatShape).returns(M.promise()),
302
- setupLiquidator: M.call(InstallationShape, M.record()).returns(
303
- M.promise(),
304
- ),
305
301
  getCollateralQuote: M.call().returns(M.promise()),
306
302
  getPublicFacet: M.call().returns(M.remotable()),
307
303
  }),
@@ -445,7 +441,6 @@ export const prepareVaultManagerKit = (
445
441
  * @returns {Promise<void>}
446
442
  */
447
443
  async reschedulePriceCheck(highestRatio) {
448
- const { facets } = this;
449
444
  trace('reschedulePriceCheck', collateralBrand, {
450
445
  liquidationQueueing,
451
446
  outstandingQuote: !!outstandingQuote,
@@ -454,13 +449,8 @@ export const prepareVaultManagerKit = (
454
449
  // and process liquidations over time.
455
450
  if (!liquidationQueueing) {
456
451
  liquidationQueueing = true;
457
- // eslint-disable-next-line consistent-return
458
- return facets.helper
459
- .processLiquidations()
460
- .catch(e => console.error('Liquidator failed', e))
461
- .finally(() => {
462
- liquidationQueueing = false;
463
- });
452
+ // TODO(7047) replace with new approach to liquidation
453
+ return;
464
454
  }
465
455
 
466
456
  if (!outstandingQuote) {
@@ -485,150 +475,6 @@ export const prepareVaultManagerKit = (
485
475
  updateQuote(outstandingQuote, highestDebtRatio, liquidationMargin);
486
476
  trace('update quote', collateralBrand, highestDebtRatio);
487
477
  },
488
-
489
- async processLiquidations() {
490
- const { facets } = this;
491
- const govParams = factoryPowers.getGovernedParams();
492
-
493
- async function* eventualLiquidations() {
494
- while (true) {
495
- const highestDebtRatio = prioritizedVaults.highestRatio();
496
- if (!highestDebtRatio) {
497
- return;
498
- }
499
- const liquidationMargin = govParams.getLiquidationMargin();
500
-
501
- // ask to be alerted when the price level falls enough that the vault
502
- // with the highest debt to collateral ratio will no longer be valued at the
503
- // liquidationMargin above its debt.
504
- outstandingQuote = makeQuote(
505
- priceAuthority,
506
- highestDebtRatio,
507
- liquidationMargin,
508
- );
509
- trace('posted quote request', collateralBrand, highestDebtRatio);
510
-
511
- // The rest of this method will not happen until after a quote is received.
512
- // This may not happen until much later, when the market changes.
513
- // eslint-disable-next-line no-await-in-loop, @jessie.js/no-nested-await -- loop/nesting to yield each unconditionally
514
- const quote = await E(outstandingQuote).getPromise();
515
- outstandingQuote = null;
516
- // When we receive a quote, we check whether the vault with the highest
517
- // ratio of debt to collateral is below the liquidationMargin, and if so,
518
- // we liquidate it. We use ceilDivide to round up because ratios above
519
- // this will be liquidated.
520
- const quoteRatioPlusMargin = makeRatioFromAmounts(
521
- ceilDivideBy(getAmountOut(quote), liquidationMargin),
522
- getAmountIn(quote),
523
- );
524
- trace('quote', collateralBrand, quote, quoteRatioPlusMargin);
525
-
526
- // Liquidate the head of the queue
527
- const [next] =
528
- prioritizedVaults.entriesPrioritizedGTE(quoteRatioPlusMargin);
529
- if (next) {
530
- yield next;
531
- }
532
- }
533
- }
534
- for await (const next of eventualLiquidations()) {
535
- await facets.helper.liquidateAndRemove(next);
536
- trace('price check liq', collateralBrand, next && next[0]);
537
- }
538
- },
539
-
540
- /**
541
- * @param {[key: string, vaultKit: Vault]} record
542
- */
543
- liquidateAndRemove([key, vault]) {
544
- const { state, facets } = this;
545
- const vaultSeat = vault.getVaultSeat();
546
- trace('liquidating', collateralBrand, vaultSeat.getProposal());
547
-
548
- const collateralPre = vault.getCollateralAmount();
549
-
550
- // Start liquidation (vaultState: LIQUIDATING)
551
- const liquidator = state.liquidator;
552
- assert(liquidator);
553
- liquidatingVaults.add(vault);
554
- prioritizedVaults.removeVault(key);
555
-
556
- return liquidate(
557
- zcf,
558
- vault,
559
- liquidator,
560
- collateralBrand,
561
- factoryPowers.getGovernedParams().getLiquidationPenalty(),
562
- )
563
- .then(accounting => {
564
- facets.manager.burnAndRecord(accounting.toBurn, vaultSeat);
565
-
566
- // current values
567
-
568
- // Sometimes, the AMM will sell less than all the collateral. If there
569
- // was a shortfall, the investor doesn't keep the change, so we get it.
570
- // If there was no shortfall, the collateral is returned.
571
- const collateralPost = vault.getCollateralAmount();
572
- if (
573
- !AmountMath.isEmpty(collateralPost) &&
574
- !AmountMath.isEmpty(accounting.shortfall)
575
- ) {
576
- // The borrower doesn't get the excess collateral remaining when
577
- // liquidation results in a shortfall. We currently do nothing with
578
- // it. We could hold it until it crosses some threshold, then sell it
579
- // to the AMM, or we could transfer it to the reserve. At least it's
580
- // visible in the accounting.
581
- atomicTransfer(zcf, vaultSeat, retainedCollateralSeat, {
582
- Collateral: collateralPost,
583
- });
584
- }
585
-
586
- // Reduce totalCollateral by collateralPre, since all the collateral was
587
- // sold, returned to the vault owner, or held by the VaultManager.
588
- state.totalCollateral = AmountMath.subtract(
589
- state.totalCollateral,
590
- collateralPre,
591
- );
592
- state.totalDebt = AmountMath.subtract(
593
- state.totalDebt,
594
- accounting.shortfall,
595
- );
596
-
597
- // cumulative values
598
- state.totalProceedsReceived = AmountMath.add(
599
- state.totalProceedsReceived,
600
- accounting.proceeds,
601
- );
602
- state.totalOverageReceived = AmountMath.add(
603
- state.totalOverageReceived,
604
- accounting.overage,
605
- );
606
- state.totalShortfallReceived = AmountMath.add(
607
- state.totalShortfallReceived,
608
- accounting.shortfall,
609
- );
610
- liquidatingVaults.delete(vault);
611
- trace('liquidated', collateralBrand);
612
- state.numLiquidationsCompleted += 1;
613
- facets.helper.updateMetrics();
614
-
615
- if (!AmountMath.isEmpty(accounting.shortfall)) {
616
- E(factoryPowers.getShortfallReporter())
617
- .increaseLiquidationShortfall(accounting.shortfall)
618
- .catch(reason =>
619
- console.error(
620
- 'liquidateAndRemove failed to increaseLiquidationShortfall',
621
- reason,
622
- ),
623
- );
624
- }
625
- })
626
- .catch(e => {
627
- // XXX should notify interested parties
628
- console.error('liquidateAndRemove failed with', e);
629
- throw e;
630
- });
631
- },
632
478
  },
633
479
  manager: {
634
480
  getGovernedParams() {
@@ -779,20 +625,6 @@ export const prepareVaultManagerKit = (
779
625
  return factoryPowers.getGovernedParams();
780
626
  },
781
627
 
782
- /**
783
- * In extreme situations, system health may require liquidating all vaults.
784
- * This starts the liquidations all in parallel.
785
- */
786
- async liquidateAll() {
787
- const {
788
- facets: { helper },
789
- } = this;
790
- const toLiquidate = Array.from(prioritizedVaults.entries()).map(
791
- entry => helper.liquidateAndRemove(entry),
792
- );
793
- await Promise.all(toLiquidate);
794
- },
795
-
796
628
  /**
797
629
  * @param {ZCFSeat} seat
798
630
  */
@@ -868,45 +700,6 @@ export const prepareVaultManagerKit = (
868
700
  }
869
701
  },
870
702
 
871
- /**
872
- *
873
- * @param {Installation} liquidationInstall
874
- * @param {object} liquidationTerms
875
- */
876
- async setupLiquidator(liquidationInstall, liquidationTerms) {
877
- const { state, facets } = this;
878
- const { ammPublicFacet, reservePublicFacet } = zcf.getTerms();
879
- const zoe = zcf.getZoeService();
880
- const collateralIssuer = zcf.getIssuerForBrand(collateralBrand);
881
- const debtIssuer = zcf.getIssuerForBrand(debtBrand);
882
- trace('setup liquidator', collateralBrand, {
883
- debtBrand,
884
- debtIssuer,
885
- collateralBrand,
886
- liquidationTerms,
887
- });
888
- const { creatorFacet, instance } = await E(zoe).startInstance(
889
- liquidationInstall,
890
- harden({ Minted: debtIssuer, Collateral: collateralIssuer }),
891
- harden({
892
- ...liquidationTerms,
893
- amm: ammPublicFacet,
894
- debtBrand,
895
- reservePublicFacet,
896
- priceAuthority,
897
- timerService,
898
- }),
899
- );
900
- trace('setup liquidator complete', collateralBrand, {
901
- instance,
902
- old: state.liquidatorInstance,
903
- equal: state.liquidatorInstance === instance,
904
- });
905
- state.liquidatorInstance = instance;
906
- state.liquidator = creatorFacet;
907
- facets.helper.assetNotify();
908
- },
909
-
910
703
  async getCollateralQuote() {
911
704
  // get a quote for one unit of the collateral
912
705
  return E(priceAuthority).quoteGiven(collateralUnit, debtBrand);