@agoric/inter-protocol 0.14.1-dev-acefd94.0 → 0.14.1-dev-d42f8d0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/inter-protocol",
3
- "version": "0.14.1-dev-acefd94.0+acefd94",
3
+ "version": "0.14.1-dev-d42f8d0.0+d42f8d0",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -29,29 +29,29 @@
29
29
  },
30
30
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
31
31
  "dependencies": {
32
- "@agoric/assert": "0.6.1-dev-acefd94.0+acefd94",
33
- "@agoric/ertp": "0.16.1-dev-acefd94.0+acefd94",
34
- "@agoric/governance": "0.10.1-dev-acefd94.0+acefd94",
35
- "@agoric/internal": "0.3.1-dev-acefd94.0+acefd94",
36
- "@agoric/notifier": "0.6.1-dev-acefd94.0+acefd94",
37
- "@agoric/store": "0.9.1-dev-acefd94.0+acefd94",
38
- "@agoric/time": "0.3.1-dev-acefd94.0+acefd94",
39
- "@agoric/vat-data": "0.5.1-dev-acefd94.0+acefd94",
40
- "@agoric/vats": "0.14.1-dev-acefd94.0+acefd94",
41
- "@agoric/zoe": "0.26.1-dev-acefd94.0+acefd94",
32
+ "@agoric/assert": "0.6.1-dev-d42f8d0.0+d42f8d0",
33
+ "@agoric/ertp": "0.16.1-dev-d42f8d0.0+d42f8d0",
34
+ "@agoric/governance": "0.10.1-dev-d42f8d0.0+d42f8d0",
35
+ "@agoric/internal": "0.3.1-dev-d42f8d0.0+d42f8d0",
36
+ "@agoric/notifier": "0.6.1-dev-d42f8d0.0+d42f8d0",
37
+ "@agoric/store": "0.9.1-dev-d42f8d0.0+d42f8d0",
38
+ "@agoric/time": "0.3.1-dev-d42f8d0.0+d42f8d0",
39
+ "@agoric/vat-data": "0.5.1-dev-d42f8d0.0+d42f8d0",
40
+ "@agoric/vats": "0.14.1-dev-d42f8d0.0+d42f8d0",
41
+ "@agoric/zoe": "0.26.1-dev-d42f8d0.0+d42f8d0",
42
42
  "@endo/captp": "^3.1.1",
43
43
  "@endo/eventual-send": "^0.17.2",
44
44
  "@endo/far": "^0.2.18",
45
45
  "@endo/marshal": "^0.8.5",
46
46
  "@endo/nat": "^4.1.27",
47
- "agoric": "0.19.1-dev-acefd94.0+acefd94",
47
+ "agoric": "0.19.1-dev-d42f8d0.0+d42f8d0",
48
48
  "jessie.js": "^0.3.2"
49
49
  },
50
50
  "devDependencies": {
51
- "@agoric/deploy-script-support": "0.10.1-dev-acefd94.0+acefd94",
52
- "@agoric/smart-wallet": "0.5.1-dev-acefd94.0+acefd94",
53
- "@agoric/swingset-liveslots": "0.10.1-dev-acefd94.0+acefd94",
54
- "@agoric/swingset-vat": "0.32.1-dev-acefd94.0+acefd94",
51
+ "@agoric/deploy-script-support": "0.10.1-dev-d42f8d0.0+d42f8d0",
52
+ "@agoric/smart-wallet": "0.5.1-dev-d42f8d0.0+d42f8d0",
53
+ "@agoric/swingset-liveslots": "0.10.1-dev-d42f8d0.0+d42f8d0",
54
+ "@agoric/swingset-vat": "0.32.1-dev-d42f8d0.0+d42f8d0",
55
55
  "@endo/bundle-source": "^2.5.1",
56
56
  "@endo/init": "^0.5.56",
57
57
  "@endo/promise-kit": "^0.2.56",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "acefd94c2191c7fad2ebcb3f31f3d960582fc111"
82
+ "gitHead": "d42f8d099cb6457d27a5d04e3c91797948040502"
83
83
  }
@@ -62,7 +62,7 @@ import { calculateMinimumCollateralization, minimumPrice } from './math.js';
62
62
  import { makePrioritizedVaults } from './prioritizedVaults.js';
63
63
  import { Phase, prepareVault } from './vault.js';
64
64
 
65
- const { details: X, Fail } = assert;
65
+ const { details: X, Fail, quote: q } = assert;
66
66
 
67
67
  const trace = makeTracer('VM');
68
68
 
@@ -499,6 +499,7 @@ export const prepareVaultManagerKit = (
499
499
  sendToReserve(penalty, seat, seatKeyword = 'Collateral') {
500
500
  const invitation =
501
501
  E(reservePublicFacet).makeAddCollateralInvitation();
502
+ trace('Sending to reserve: ', penalty);
502
503
 
503
504
  // don't wait for response
504
505
  void E.when(invitation, invite => {
@@ -675,8 +676,8 @@ export const prepareVaultManagerKit = (
675
676
  quoteAsRatio(oraclePriceAtStart.quoteAmount.value[0]),
676
677
  ),
677
678
  );
679
+ const debtPortion = makeRatioFromAmounts(totalPenalty, totalDebt);
678
680
 
679
- const price = makeRatioFromAmounts(mintedProceeds, collateralSold);
680
681
  // Liquidation.md describes how to process liquidation proceeds
681
682
  const bestToWorst = [...vaultData.entries()].reverse();
682
683
  if (AmountMath.isEmpty(accounting.shortfall)) {
@@ -708,17 +709,27 @@ export const prepareVaultManagerKit = (
708
709
  debtAmount,
709
710
  vault.getCurrentDebt(),
710
711
  );
711
- const debtInCollateral = ceilDivideBy(debtAmount, price);
712
- const collatPostDebt = AmountMath.isGTE(vCollat, debtInCollateral)
713
- ? AmountMath.subtract(vCollat, debtInCollateral)
712
+
713
+ const price = makeRatioFromAmounts(
714
+ mintedProceeds,
715
+ collateralSold,
716
+ );
717
+
718
+ // max return is vault value reduced by debt and penalty value
719
+ const debtCollat = ceilDivideBy(debtAmount, price);
720
+ const penaltyCollat = ceilMultiplyBy(debtAmount, debtPortion);
721
+ const lessCollat = AmountMath.add(debtCollat, penaltyCollat);
722
+
723
+ const maxCollat = AmountMath.isGTE(vCollat, lessCollat)
724
+ ? AmountMath.subtract(vCollat, lessCollat)
714
725
  : AmountMath.makeEmptyFromAmount(vCollat);
715
726
  if (!AmountMath.isEmpty(leftToStage)) {
716
- const collat = AmountMath.min(leftToStage, collatPostDebt);
717
- leftToStage = AmountMath.subtract(leftToStage, collat);
727
+ const collatReturn = AmountMath.min(leftToStage, maxCollat);
728
+ leftToStage = AmountMath.subtract(leftToStage, collatReturn);
718
729
  transfers.push([
719
730
  liqSeat,
720
731
  vault.getVaultSeat(),
721
- { Collateral: collat },
732
+ { Collateral: collatReturn },
722
733
  ]);
723
734
  }
724
735
  vaultsToLiquidate.push(vault);
@@ -847,7 +858,6 @@ export const prepareVaultManagerKit = (
847
858
 
848
859
  let collateralReduction = AmountMath.makeEmpty(collateralBrand);
849
860
  let shortfallToReserve = accounting.shortfall;
850
- const debtPortion = makeRatioFromAmounts(totalPenalty, totalDebt);
851
861
  const reduceCollateral = amount =>
852
862
  (collateralReduction = AmountMath.add(
853
863
  collateralReduction,
@@ -859,10 +869,16 @@ export const prepareVaultManagerKit = (
859
869
  /** @type {Array<[Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}]>} */
860
870
  for (const [vault, balance] of bestToWorst) {
861
871
  const { collateralAmount: vCollat, debtAmount } = balance;
862
- const vaultPenalty = ceilMultiplyBy(debtAmount, penaltyRate);
872
+
873
+ // according to #7123, Collateral for penalty =
874
+ // vault debt / total debt * total liquidation penalty
875
+ const vaultPenalty = ceilMultiplyBy(
876
+ debtAmount,
877
+ makeRatioFromAmounts(totalPenalty, totalDebt),
878
+ );
863
879
  const collatPostPenalty = AmountMath.subtract(
864
880
  vCollat,
865
- ceilMultiplyBy(vaultPenalty, debtPortion),
881
+ vaultPenalty,
866
882
  );
867
883
  const vaultDebt = floorMultiplyBy(debtAmount, debtPortion);
868
884
  if (
@@ -904,7 +920,7 @@ export const prepareVaultManagerKit = (
904
920
  }
905
921
 
906
922
  // Putting all the rearrangements after the loop ensures that errors
907
- // in the calculations don't result in paying pack some vaults and
923
+ // in the calculations don't result in paying back some vaults and
908
924
  // leaving others hanging.
909
925
  if (transfers.length > 0) {
910
926
  atomicRearrange(zcf, harden(transfers));
@@ -917,12 +933,29 @@ export const prepareVaultManagerKit = (
917
933
  transfers.length,
918
934
  );
919
935
 
920
- facets.helper.sendToReserve(collatRemaining, liqSeat);
936
+ const collateralInLiqSeat =
937
+ liqSeat.getCurrentAllocation().Collateral;
938
+ facets.helper.sendToReserve(collateralInLiqSeat, liqSeat);
939
+
940
+ if (
941
+ !AmountMath.isEqual(
942
+ collateralInLiqSeat,
943
+ AmountMath.add(collatRemaining, totalPenalty),
944
+ )
945
+ ) {
946
+ console.error(
947
+ `🚨 Excess collateral remaining sent to reserve. Expected ${q(
948
+ collatRemaining,
949
+ )}, sent ${q(collateralInLiqSeat)}`,
950
+ );
951
+ }
921
952
  facets.helper.markDoneLiquidating(totalDebt, totalCollateral, {
922
953
  ...accounting,
923
954
  shortfall: shortfallToReserve,
924
955
  });
925
956
  }
957
+ // liqSeat should be empty at this point, except that funds are sent
958
+ // asynchronously to the reserve.
926
959
  liquidateAll();
927
960
  return facets.helper.writeMetrics();
928
961
  },