@agoric/inter-protocol 0.13.2-dev-65d3f14.0 → 0.13.2-pismo-dev-12e97f1.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 (103) hide show
  1. package/bundles/bundle-amm-meta.js +168 -188
  2. package/bundles/bundle-amm.js +1 -1
  3. package/bundles/bundle-feeDistributor-meta.js +92 -92
  4. package/bundles/bundle-feeDistributor.js +1 -1
  5. package/bundles/bundle-interchainPool-meta.js +174 -190
  6. package/bundles/bundle-interchainPool.js +1 -1
  7. package/bundles/bundle-liquidateIncrementally-meta.js +149 -109
  8. package/bundles/bundle-liquidateIncrementally.js +1 -1
  9. package/bundles/bundle-liquidateMinimum-meta.js +149 -109
  10. package/bundles/bundle-liquidateMinimum.js +1 -1
  11. package/bundles/bundle-psm-meta.js +148 -168
  12. package/bundles/bundle-psm.js +1 -1
  13. package/bundles/bundle-psmCharter-meta.js +418 -0
  14. package/bundles/bundle-psmCharter.js +1 -0
  15. package/bundles/bundle-reserve-meta.js +176 -192
  16. package/bundles/bundle-reserve.js +1 -1
  17. package/bundles/bundle-scaledPriceAuthority-meta.js +173 -133
  18. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  19. package/bundles/bundle-stakeFactory-meta.js +186 -206
  20. package/bundles/bundle-stakeFactory.js +1 -1
  21. package/bundles/bundle-vaultFactory-meta.js +197 -217
  22. package/bundles/bundle-vaultFactory.js +1 -1
  23. package/package.json +23 -25
  24. package/scripts/add-collateral-core.js +3 -52
  25. package/scripts/add-initial-liquidity.js +1 -0
  26. package/scripts/build-bundles.js +1 -4
  27. package/scripts/deploy-contracts.js +1 -0
  28. package/scripts/init-core.js +9 -11
  29. package/scripts/invite-committee-core.js +1 -0
  30. package/scripts/manual-price-feed.js +1 -1
  31. package/scripts/price-feed-core.js +2 -2
  32. package/src/collect.js +2 -0
  33. package/src/collectFees.js +4 -3
  34. package/src/contractSupport.js +27 -13
  35. package/src/econCommitteeCharter.js +80 -110
  36. package/src/feeDistributor.js +8 -6
  37. package/src/interchainPool.js +8 -7
  38. package/src/interest-math.js +2 -0
  39. package/src/interest.js +10 -6
  40. package/src/makeTracer.js +0 -5
  41. package/src/my-lien.js +7 -3
  42. package/src/proposals/addAssetToVault.js +5 -3
  43. package/src/proposals/committee-proposal.js +42 -112
  44. package/src/proposals/core-proposal.js +30 -17
  45. package/src/proposals/demoIssuers.js +16 -17
  46. package/src/proposals/econ-behaviors.js +115 -156
  47. package/src/proposals/price-feed-proposal.js +6 -118
  48. package/src/proposals/sim-behaviors.js +1 -0
  49. package/src/proposals/startEconCommittee.js +2 -1
  50. package/src/proposals/startPSM.js +117 -77
  51. package/src/proposals/utils.js +12 -23
  52. package/src/psm/psm.js +55 -37
  53. package/src/psm/psmCharter.js +139 -0
  54. package/src/reserve/assetReserve.js +35 -28
  55. package/src/reserve/params.js +2 -0
  56. package/src/stakeFactory/attestation.js +9 -4
  57. package/src/stakeFactory/attestationTool.js +1 -0
  58. package/src/stakeFactory/params.js +1 -0
  59. package/src/stakeFactory/stakeFactory.js +1 -1
  60. package/src/stakeFactory/stakeFactoryKit.js +20 -13
  61. package/src/stakeFactory/stakeFactoryManager.js +3 -2
  62. package/src/vaultFactory/burn.js +1 -0
  63. package/src/vaultFactory/liquidateIncrementally.js +8 -5
  64. package/src/vaultFactory/liquidateMinimum.js +6 -2
  65. package/src/vaultFactory/liquidation.js +2 -2
  66. package/src/vaultFactory/orderedVaultStore.js +1 -0
  67. package/src/vaultFactory/params.js +12 -7
  68. package/src/vaultFactory/prioritizedVaults.js +1 -0
  69. package/src/vaultFactory/storeUtils.js +1 -0
  70. package/src/vaultFactory/types.js +2 -0
  71. package/src/vaultFactory/vault.js +40 -26
  72. package/src/vaultFactory/vaultDirector.js +18 -15
  73. package/src/vaultFactory/vaultFactory.js +20 -19
  74. package/src/vaultFactory/vaultHolder.js +3 -4
  75. package/src/vaultFactory/vaultKit.js +1 -0
  76. package/src/vaultFactory/vaultManager.js +10 -7
  77. package/src/vpool-xyk-amm/addLiquidity.js +4 -3
  78. package/src/vpool-xyk-amm/addPool.js +20 -23
  79. package/src/vpool-xyk-amm/constantProduct/calcFees.js +12 -6
  80. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +2 -0
  81. package/src/vpool-xyk-amm/constantProduct/core.js +24 -16
  82. package/src/vpool-xyk-amm/constantProduct/defaults.js +2 -0
  83. package/src/vpool-xyk-amm/constantProduct/getXY.js +6 -2
  84. package/src/vpool-xyk-amm/constantProduct/internal-types.js +14 -12
  85. package/src/vpool-xyk-amm/constantProduct/invariants.js +8 -4
  86. package/src/vpool-xyk-amm/constantProduct/swap.js +19 -17
  87. package/src/vpool-xyk-amm/constantProduct/types.js +2 -0
  88. package/src/vpool-xyk-amm/doublePool.js +14 -20
  89. package/src/vpool-xyk-amm/estimate.js +2 -0
  90. package/src/vpool-xyk-amm/multipoolMarketMaker.js +5 -3
  91. package/src/vpool-xyk-amm/params.js +2 -0
  92. package/src/vpool-xyk-amm/pool.js +14 -16
  93. package/src/vpool-xyk-amm/priceAuthority.js +3 -1
  94. package/src/vpool-xyk-amm/removeLiquidity.js +2 -0
  95. package/src/vpool-xyk-amm/singlePool.js +14 -29
  96. package/src/vpool-xyk-amm/swap.js +1 -0
  97. package/src/vpool-xyk-amm/types.js +12 -10
  98. package/bundles/bundle-econCommitteeCharter-meta.js +0 -418
  99. package/bundles/bundle-econCommitteeCharter.js +0 -1
  100. package/scripts/start-local-chain-boot.js +0 -96
  101. package/scripts/start-local-chain-config.json +0 -83
  102. package/scripts/start-local-chain.sh +0 -69
  103. package/src/psm/README.md +0 -71
@@ -0,0 +1,139 @@
1
+ // @ts-check
2
+
3
+ import '@agoric/governance/src/exported.js';
4
+ import { makeScalarMapStore, M, makeHeapFarInstance, fit } from '@agoric/store';
5
+ import '@agoric/zoe/exported.js';
6
+ import '@agoric/zoe/src/contracts/exported.js';
7
+ import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
8
+ import { BrandShape } from '@agoric/ertp';
9
+ import { TimestampShape } from '@agoric/swingset-vat/src/vats/timer/typeGuards.js';
10
+ import { E } from '@endo/far';
11
+
12
+ /**
13
+ * @file
14
+ *
15
+ * This contract makes it possible for those who govern the PSM to call for
16
+ * votes on changes. A more complete implementation would validate parameters,
17
+ * constrain deadlines and possibly split the ability to call for votes into
18
+ * separate capabilities for finer grain encapsulation.
19
+ */
20
+
21
+ /**
22
+ * @typedef {object} ParamChangesOfferArgs
23
+ * @property {bigint} deadline
24
+ * @property {Instance} instance
25
+ * @property {Record<string, unknown>} params
26
+ * @property {{paramPath: { key: string }}} [path]
27
+ */
28
+ const ParamChangesOfferArgsShape = harden(
29
+ M.split(
30
+ {
31
+ deadline: TimestampShape,
32
+ instance: InstanceHandleShape,
33
+ params: M.recordOf(M.string(), M.any()),
34
+ },
35
+ M.partial({
36
+ path: { paramPath: { key: M.string() } },
37
+ }),
38
+ ),
39
+ );
40
+
41
+ /**
42
+ * @param {ZCF<{binaryVoteCounterInstallation:Installation}>} zcf
43
+ */
44
+ export const start = async zcf => {
45
+ const { binaryVoteCounterInstallation: counter } = zcf.getTerms();
46
+ /** @type {MapStore<Instance,GovernedContractFacetAccess<{},{}>>} */
47
+ const instanceToGovernor = makeScalarMapStore();
48
+
49
+ const makeParamInvitation = () => {
50
+ /**
51
+ * @param {ZCFSeat} seat
52
+ * @param {ParamChangesOfferArgs} args
53
+ */
54
+ const voteOnParamChanges = (seat, args) => {
55
+ fit(args, ParamChangesOfferArgsShape);
56
+ seat.exit();
57
+
58
+ const {
59
+ params,
60
+ instance,
61
+ deadline,
62
+ path = { paramPath: { key: 'governedApi' } },
63
+ } = args;
64
+ const psmGovernor = instanceToGovernor.get(instance);
65
+ return E(psmGovernor).voteOnParamChanges(counter, deadline, {
66
+ ...path,
67
+ changes: params,
68
+ });
69
+ };
70
+
71
+ return zcf.makeInvitation(voteOnParamChanges, 'vote on param changes');
72
+ };
73
+
74
+ const makeOfferFilterInvitation = (instance, strings, deadline) => {
75
+ const voteOnOfferFilterHandler = seat => {
76
+ seat.exit();
77
+
78
+ const psmGovernor = instanceToGovernor.get(instance);
79
+ return E(psmGovernor).voteOnOfferFilter(counter, deadline, strings);
80
+ };
81
+
82
+ return zcf.makeInvitation(voteOnOfferFilterHandler, 'vote on offer filter');
83
+ };
84
+
85
+ const MakerShape = M.interface('PSM Charter InvitationMakers', {
86
+ VoteOnParamChange: M.call().returns(M.promise()),
87
+ VoteOnPauseOffers: M.call(
88
+ InstanceHandleShape,
89
+ M.arrayOf(M.string()),
90
+ TimestampShape,
91
+ ).returns(M.promise()),
92
+ });
93
+ const invitationMakers = makeHeapFarInstance(
94
+ 'PSM Invitation Makers',
95
+ MakerShape,
96
+ {
97
+ VoteOnParamChange: makeParamInvitation,
98
+ VoteOnPauseOffers: makeOfferFilterInvitation,
99
+ },
100
+ );
101
+
102
+ const charterMemberHandler = seat => {
103
+ seat.exit();
104
+ return harden({ invitationMakers });
105
+ };
106
+
107
+ const psmCharterCreatorI = M.interface('PSM Charter creatorFacet', {
108
+ addInstance: M.call(InstanceHandleShape, M.any())
109
+ .optional(BrandShape, BrandShape)
110
+ .returns(),
111
+ makeCharterMemberInvitation: M.call().returns(M.promise()),
112
+ });
113
+
114
+ const creatorFacet = makeHeapFarInstance(
115
+ 'PSM Charter creatorFacet',
116
+ psmCharterCreatorI,
117
+ {
118
+ /**
119
+ * @param {Instance} psmInstance
120
+ * @param {GovernedContractFacetAccess<{},{}>} psmGovernorFacet
121
+ * @param {Brand} [anchor] for diagnostic use only
122
+ * @param {Brand} [minted] for diagnostic use only
123
+ */
124
+ addInstance: (psmInstance, psmGovernorFacet, anchor, minted) => {
125
+ console.log('psmCharter: adding instance', { minted, anchor });
126
+ instanceToGovernor.init(psmInstance, psmGovernorFacet);
127
+ },
128
+ makeCharterMemberInvitation: () =>
129
+ zcf.makeInvitation(
130
+ charterMemberHandler,
131
+ 'PSM charter member invitation',
132
+ ),
133
+ },
134
+ );
135
+
136
+ return harden({ creatorFacet });
137
+ };
138
+
139
+ export const INVITATION_MAKERS_DESC = 'PSM charter member invitation';
@@ -1,17 +1,16 @@
1
+ // @ts-check
2
+
1
3
  import { E, Far } from '@endo/far';
2
4
  import { AmountMath } from '@agoric/ertp';
3
5
  import { handleParamGovernance, ParamTypes } from '@agoric/governance';
4
- import {
5
- offerTo,
6
- atomicTransfer,
7
- } from '@agoric/zoe/src/contractSupport/index.js';
6
+ import { offerTo } from '@agoric/zoe/src/contractSupport/index.js';
8
7
  import { provideDurableMapStore, vivifyKindMulti } from '@agoric/vat-data';
9
8
 
10
9
  import { AMM_INSTANCE } from './params.js';
11
10
  import { makeTracer } from '../makeTracer.js';
12
11
  import { makeMetricsPublisherKit } from '../contractSupport.js';
13
12
 
14
- const { Fail, quote: q } = assert;
13
+ const { details: X, quote: q } = assert;
15
14
 
16
15
  const trace = makeTracer('Reserve', false);
17
16
 
@@ -71,7 +70,7 @@ const nonalphanumeric = /[^A-Za-z0-9]/g;
71
70
  * >} zcf
72
71
  * @param {{
73
72
  * feeMintAccess: FeeMintAccess,
74
- * initialPoserInvitation: Invitation,
73
+ * initialPoserInvitation: Payment,
75
74
  * marshaller: ERef<Marshaller>,
76
75
  * storageNode: ERef<StorageNode>,
77
76
  * }} privateArgs
@@ -96,7 +95,7 @@ const start = async (zcf, privateArgs, baggage) => {
96
95
  */
97
96
  const brandForKeyword = provideDurableMapStore(baggage, 'brandForKeyword');
98
97
  /**
99
- * @type {MapStore<Brand<'nat'>, Brand<'nat'>>}
98
+ * @type {MapStore<Brand, Brand>}
100
99
  */
101
100
  const liquidityBrandForBrand = provideDurableMapStore(
102
101
  baggage,
@@ -115,6 +114,7 @@ const start = async (zcf, privateArgs, baggage) => {
115
114
  baggage.init('feeMint', feeMintTemp);
116
115
  return feeMintTemp;
117
116
  };
117
+ /** @type {ZCFMint} */
118
118
  const feeMint = await takeFeeMint();
119
119
  const feeKit = feeMint.getIssuerRecord();
120
120
  const emptyAmount = AmountMath.makeEmpty(feeKit.brand);
@@ -171,7 +171,7 @@ const start = async (zcf, privateArgs, baggage) => {
171
171
 
172
172
  /**
173
173
  * @param {MethodContext} _context
174
- * @param {Issuer<'nat'>} baseIssuer on which the liquidity issuer is based
174
+ * @param {Issuer} baseIssuer on which the liquidity issuer is based
175
175
  */
176
176
  const addLiquidityIssuer = async (_context, baseIssuer) => {
177
177
  const getBrand = () => {
@@ -216,7 +216,7 @@ const start = async (zcf, privateArgs, baggage) => {
216
216
 
217
217
  /**
218
218
  * @param {MethodContext} context
219
- * @param {Brand<'nat'>} ammSecondaryBrand
219
+ * @param {Brand} ammSecondaryBrand
220
220
  */
221
221
  const addIssuerFromAmm = async (context, ammSecondaryBrand) => {
222
222
  assert(
@@ -235,7 +235,9 @@ const start = async (zcf, privateArgs, baggage) => {
235
235
 
236
236
  const getKeywordForBrand = brand => {
237
237
  keywordForBrand.has(brand) ||
238
- Fail`Issuer not defined for brand ${q(brand)}; first call addIssuer()`;
238
+ assert.fail(
239
+ X`Issuer not defined for brand ${q(brand)}; first call addIssuer()`,
240
+ );
239
241
  return keywordForBrand.get(brand);
240
242
  };
241
243
 
@@ -256,14 +258,10 @@ const start = async (zcf, privateArgs, baggage) => {
256
258
  } = seat.getProposal();
257
259
 
258
260
  const collateralKeyword = getKeywordForBrand(amountIn.brand);
261
+ seat.decrementBy(harden({ Collateral: amountIn }));
262
+ collateralSeat.incrementBy(harden({ [collateralKeyword]: amountIn }));
259
263
 
260
- atomicTransfer(
261
- zcf,
262
- seat,
263
- collateralSeat,
264
- { Collateral: amountIn },
265
- { [collateralKeyword]: amountIn },
266
- );
264
+ zcf.reallocate(collateralSeat, seat);
267
265
  seat.exit();
268
266
 
269
267
  trace('received collateral', amountIn);
@@ -321,8 +319,8 @@ const start = async (zcf, privateArgs, baggage) => {
321
319
  * to add Liquidity to a pool in the AMM.
322
320
  *
323
321
  * @param {MethodContext} context
324
- * @param {Amount<'nat'>} collateral
325
- * @param {Amount<'nat'>} fee
322
+ * @param {Amount} collateral
323
+ * @param {Amount} fee
326
324
  */
327
325
  const addLiquidityToAmmPool = async ({ state }, collateral, fee) => {
328
326
  // verify we have the funds
@@ -340,9 +338,14 @@ const start = async (zcf, privateArgs, baggage) => {
340
338
  const offerToSeat = feeMint.mintGains(harden({ Fee: fee }));
341
339
  state.totalFeeMinted = AmountMath.add(state.totalFeeMinted, fee);
342
340
 
343
- atomicTransfer(zcf, collateralSeat, offerToSeat, {
344
- [collateralKeyword]: collateral,
345
- });
341
+ offerToSeat.incrementBy(
342
+ collateralSeat.decrementBy(
343
+ harden({
344
+ [collateralKeyword]: collateral,
345
+ }),
346
+ ),
347
+ );
348
+ zcf.reallocate(collateralSeat, offerToSeat);
346
349
 
347
350
  // Add Fee tokens and collateral to the AMM
348
351
  const invitation = await E(
@@ -370,13 +373,17 @@ const start = async (zcf, privateArgs, baggage) => {
370
373
  const liquidityAmount = offerToSeat.getCurrentAllocation();
371
374
  const liquidityKeyword = makeLiquidityKeyword(collateralKeyword);
372
375
 
373
- atomicTransfer(
374
- zcf,
375
- offerToSeat,
376
- collateralSeat,
377
- { Liquidity: liquidityAmount.Liquidity },
378
- { [liquidityKeyword]: liquidityAmount.Liquidity },
376
+ offerToSeat.decrementBy(
377
+ harden({
378
+ Liquidity: liquidityAmount.Liquidity,
379
+ }),
380
+ );
381
+ collateralSeat.incrementBy(
382
+ harden({
383
+ [liquidityKeyword]: liquidityAmount.Liquidity,
384
+ }),
379
385
  );
386
+ zcf.reallocate(offerToSeat, collateralSeat);
380
387
  updateMetrics({ state });
381
388
  };
382
389
 
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
2
4
 
3
5
  export const AMM_INSTANCE = 'AmmInstance';
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
 
3
4
  import { AmountMath, AssetKind } from '@agoric/ertp';
@@ -7,7 +8,7 @@ import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
7
8
  import { AttKW as KW } from './constants.js';
8
9
  import { makeAttestationTool } from './attestationTool.js';
9
10
 
10
- const { Fail } = assert;
11
+ const { details: X } = assert;
11
12
 
12
13
  /**
13
14
  * @typedef {{
@@ -70,7 +71,9 @@ const makeAttestationIssuerKit = async (zcf, stakeBrand, lienBridge) => {
70
71
  /** @param {Amount<'copyBag'>} attestationAmount */
71
72
  const unwrapLienedAmount = attestationAmount => {
72
73
  attestationAmount.brand === attBrand ||
73
- Fail`The escrowed attestation ${attestationAmount} was not of the attestation brand ${attBrand}`;
74
+ assert.fail(
75
+ X`The escrowed attestation ${attestationAmount} was not of the attestation brand ${attBrand}`,
76
+ );
74
77
  fit(
75
78
  attestationAmount.value.payload,
76
79
  harden([[M.string(), M.bigint()]]),
@@ -117,9 +120,11 @@ const makeAttestationIssuerKit = async (zcf, stakeBrand, lienBridge) => {
117
120
  // check that x <= hi - lo
118
121
  const checkDelta = (x, label, hi, lo) => {
119
122
  const bound = subtractOrZero(hi, lo);
120
- isGTE(bound, coerce(stakeBrand, x)) ||
123
+ assert(
124
+ isGTE(bound, coerce(stakeBrand, x)),
121
125
  // TODO: X`...${raw(label)}...`
122
- Fail`Only ${bound} was ${label}, but an attestation was attempted for ${x}`;
126
+ X`Only ${bound} was ${label}, but an attestation was attempted for ${x}`,
127
+ );
123
128
  };
124
129
  const assertAccountStateOK = async (address, toLien) => {
125
130
  const s = await getAccountState(address, stakeBrand);
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  /**
2
3
  * @typedef {Readonly<{
3
4
  * address: Address,
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
 
3
4
  import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
  import { AmountMath } from '@agoric/ertp';
3
4
  import { handleParamGovernance, ParamTypes } from '@agoric/governance';
@@ -180,7 +181,6 @@ export const start = async (
180
181
  zcf,
181
182
  debtMint,
182
183
  harden({ Attestation: attestBrand, debt: debtBrand, Stake: stakeBrand }),
183
- // @ts-expect-error xxx governance types
184
184
  mintPowers,
185
185
  { timerService, chargingPeriod, recordingPeriod, startTimeStamp },
186
186
  );
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
  import { AmountMath, AssetKind } from '@agoric/ertp';
3
4
  import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
@@ -11,7 +12,7 @@ import { addSubtract, assertOnlyKeys, stageDelta } from '../contractSupport.js';
11
12
  import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
12
13
  import { ManagerKW as KW } from './constants.js';
13
14
 
14
- const { Fail, quote: q } = assert;
15
+ const { details: X, quote: q } = assert;
15
16
 
16
17
  const trace = makeTracer('R1');
17
18
 
@@ -19,9 +20,9 @@ const trace = makeTracer('R1');
19
20
  * Calculate the fee, the amount to mint and the resulting debt.
20
21
  *
21
22
  * @param {Ratio} feeCoeff fee coefficient
22
- * @param {Amount<'nat'>} currentDebt
23
- * @param {Amount<'nat'>} giveAmount
24
- * @param {Amount<'nat'>} wantAmount
23
+ * @param {Amount} currentDebt
24
+ * @param {Amount} giveAmount
25
+ * @param {Amount} wantAmount
25
26
  */
26
27
  const calculateFee = (feeCoeff, currentDebt, giveAmount, wantAmount) => {
27
28
  const fee = ceilMultiplyBy(wantAmount, feeCoeff);
@@ -33,7 +34,7 @@ const calculateFee = (feeCoeff, currentDebt, giveAmount, wantAmount) => {
33
34
  /**
34
35
  * @typedef {Readonly<{
35
36
  * collateralBrand: Brand,
36
- * debtBrand: Brand<'nat'>,
37
+ * debtBrand: Brand,
37
38
  * manager: import('./stakeFactoryManager.js').StakeFactoryManager,
38
39
  * subscriber: Subscriber<unknown>
39
40
  * vaultSeat: ZCFSeat,
@@ -83,7 +84,9 @@ const initState = (zcf, startSeat, manager) => {
83
84
 
84
85
  const { maxDebt } = manager.maxDebtForLien(attestationGiven);
85
86
  AmountMath.isGTE(maxDebt, runWanted) ||
86
- Fail`wanted ${runWanted}, more than max debt (${maxDebt}) for ${attestationGiven}`;
87
+ assert.fail(
88
+ X`wanted ${runWanted}, more than max debt (${maxDebt}) for ${attestationGiven}`,
89
+ );
87
90
 
88
91
  const { newDebt, fee, toMint } = calculateFee(
89
92
  manager.getLoanFee(),
@@ -92,8 +95,10 @@ const initState = (zcf, startSeat, manager) => {
92
95
  runWanted,
93
96
  );
94
97
  !AmountMath.isEmpty(fee) ||
95
- Fail`loan requested (${runWanted}) is too small; cannot accrue interest`;
96
- AmountMath.isEqual(newDebt, toMint) || Fail`loan fee mismatch`;
98
+ assert.fail(
99
+ X`loan requested (${runWanted}) is too small; cannot accrue interest`,
100
+ );
101
+ assert(AmountMath.isEqual(newDebt, toMint), X`loan fee mismatch`);
97
102
  trace('init', { runWanted, fee, attestationGiven });
98
103
 
99
104
  vaultSeat.incrementBy(
@@ -200,7 +205,7 @@ const helperBehavior = {
200
205
  * but not for interest accrual.
201
206
  *
202
207
  * @param {MethodContext} context
203
- * @param {Amount<'nat'>} newDebt - principal and all accrued interest
208
+ * @param {Amount} newDebt - principal and all accrued interest
204
209
  */
205
210
  updateDebtSnapshot: ({ state }, newDebt) => {
206
211
  const { manager } = state;
@@ -214,8 +219,8 @@ const helperBehavior = {
214
219
  * maintain aggregate debt and liquidation order.
215
220
  *
216
221
  * @param {MethodContext} context
217
- * @param {Amount<'nat'>} oldDebt - prior principal and all accrued interest
218
- * @param {Amount<'nat'>} newDebt - actual principal and all accrued interest
222
+ * @param {Amount} oldDebt - prior principal and all accrued interest
223
+ * @param {Amount} newDebt - actual principal and all accrued interest
219
224
  */
220
225
  updateDebtAccounting: ({ state, facets }, oldDebt, newDebt) => {
221
226
  const { manager } = state;
@@ -232,7 +237,7 @@ const helperBehavior = {
232
237
  const { vaultSeat } = state;
233
238
  const { helper } = facets;
234
239
  AmountMath.isEmpty(helper.getMintedAllocated(vaultSeat)) ||
235
- Fail`Vault should be empty of debt`;
240
+ assert.fail(X`Vault should be empty of debt`);
236
241
  },
237
242
 
238
243
  /**
@@ -333,7 +338,9 @@ const helperBehavior = {
333
338
  give: { [KW.Debt]: runOffered },
334
339
  } = seat.getProposal();
335
340
  AmountMath.isGTE(runOffered, currentDebt) ||
336
- Fail`Offer ${runOffered} is not sufficient to pay off debt ${currentDebt}`;
341
+ assert.fail(
342
+ X`Offer ${runOffered} is not sufficient to pay off debt ${currentDebt}`,
343
+ );
337
344
  vaultSeat.incrementBy(seat.decrementBy(harden({ [KW.Debt]: currentDebt })));
338
345
  seat.incrementBy(
339
346
  vaultSeat.decrementBy(
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
  import { AmountMath } from '@agoric/ertp';
3
4
  import { makePublishKit, observeNotifier } from '@agoric/notifier';
@@ -238,8 +239,8 @@ const manager = {
238
239
 
239
240
  /**
240
241
  * @param {MethodContext} context
241
- * @param {Amount<'nat'>} toMint
242
- * @param {Amount<'nat'>} fee
242
+ * @param {Amount} toMint
243
+ * @param {Amount} fee
243
244
  * @param {ZCFSeat} seat
244
245
  * @param {...ZCFSeat} otherSeats
245
246
  * @returns {void}
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  import '@agoric/zoe/exported.js';
2
3
 
3
4
  import { E } from '@endo/eventual-send';
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable no-await-in-loop */
2
+ // @ts-check
3
+
2
4
  import { E } from '@endo/eventual-send';
3
5
  import {
4
6
  getAmountOut,
@@ -7,13 +9,12 @@ import {
7
9
  natSafeMath as NatMath,
8
10
  ceilMultiplyBy,
9
11
  oneMinus,
10
- atomicTransfer,
11
12
  } from '@agoric/zoe/src/contractSupport/index.js';
12
13
  import { AmountMath } from '@agoric/ertp';
13
14
  import { Far } from '@endo/marshal';
14
15
  import { makeTracer } from '../makeTracer.js';
15
16
 
16
- const { Fail } = assert;
17
+ const { details: X } = assert;
17
18
  const trace = makeTracer('LiqI', false);
18
19
 
19
20
  /**
@@ -155,7 +156,6 @@ const start = async zcf => {
155
156
  poolCentral.value,
156
157
  NatMath.floorDivide(k, postSaleCollateral.value),
157
158
  );
158
- /** @type {Amount<'nat'>} */
159
159
  const estimateAmount = AmountMath.make(debt.brand, estimateCentral);
160
160
  const minAmmProceeds = ceilMultiplyBy(estimateAmount, oneMinus(maxSlip));
161
161
  trace('AMM estimate', {
@@ -285,7 +285,7 @@ const start = async zcf => {
285
285
  give: { In: null },
286
286
  });
287
287
  originalDebt.brand === debtBrand ||
288
- Fail`Cannot liquidate to ${originalDebt.brand}`;
288
+ assert.fail(X`Cannot liquidate to ${originalDebt.brand}`);
289
289
  const penalty = ceilMultiplyBy(originalDebt, penaltyRate);
290
290
  const debtWithPenalty = AmountMath.add(originalDebt, penalty);
291
291
  trace('LIQ', { originalDebt, debtWithPenalty });
@@ -322,7 +322,10 @@ const start = async zcf => {
322
322
  const penaltyPaid = AmountMath.min(penalty, debtPaid);
323
323
 
324
324
  // Allocate penalty portion of proceeds to a seat that will hold it for transfer to reserve
325
- atomicTransfer(zcf, debtorSeat, penaltyPoolSeat, { Out: penaltyPaid });
325
+ penaltyPoolSeat.incrementBy(
326
+ debtorSeat.decrementBy(harden({ Out: penaltyPaid })),
327
+ );
328
+ zcf.reallocate(penaltyPoolSeat, debtorSeat);
326
329
 
327
330
  debtorSeat.exit();
328
331
  trace('exit seat');
@@ -1,8 +1,9 @@
1
+ // @ts-check
2
+
1
3
  import { E } from '@endo/eventual-send';
2
4
  import {
3
5
  ceilMultiplyBy,
4
6
  offerTo,
5
- atomicTransfer,
6
7
  } from '@agoric/zoe/src/contractSupport/index.js';
7
8
  import { AmountMath } from '@agoric/ertp';
8
9
  import { Far } from '@endo/marshal';
@@ -74,7 +75,10 @@ const start = async zcf => {
74
75
  const penaltyPaid = AmountMath.min(penalty, debtPaid);
75
76
 
76
77
  // Allocate penalty portion of proceeds to a seat that will hold it for transfer to reserve
77
- atomicTransfer(zcf, debtorSeat, penaltyPoolSeat, { Out: penaltyPaid });
78
+ penaltyPoolSeat.incrementBy(
79
+ debtorSeat.decrementBy(harden({ Out: penaltyPaid })),
80
+ );
81
+ zcf.reallocate(penaltyPoolSeat, debtorSeat);
78
82
 
79
83
  debtorSeat.exit();
80
84
  };
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
 
3
4
  import { E } from '@endo/eventual-send';
@@ -61,7 +62,7 @@ const updateQuote = (quote, highestDebtRatio, liquidationMargin) => {
61
62
  * @param {ZCF} zcf
62
63
  * @param {Vault} vault
63
64
  * @param {Liquidator} liquidator
64
- * @param {Brand<'nat'>} collateralBrand
65
+ * @param {Brand} collateralBrand
65
66
  * @param {Ratio} penaltyRate
66
67
  */
67
68
  const liquidate = async (
@@ -105,7 +106,6 @@ const liquidate = async (
105
106
  ]);
106
107
  // NB: all the proceeds from AMM sale are on the vault seat instead of a staging seat
107
108
 
108
- /** @type { [Amount<'nat'>, Amount<'nat'>] } */
109
109
  const [overage, shortfall] = AmountMath.isGTE(debt, proceeds.Minted)
110
110
  ? [
111
111
  AmountMath.makeEmptyFromAmount(debt),
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  import { fromVaultKey, toVaultKey } from './storeUtils.js';
2
3
 
3
4
  /**
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import './types.js';
2
4
 
3
5
  import {
@@ -78,13 +80,16 @@ const makeVaultParamManager = (publisherKit, initial) =>
78
80
  });
79
81
  /** @typedef {ReturnType<typeof makeVaultParamManager>} VaultParamManager */
80
82
 
81
- export const vaultParamPattern = M.splitRecord({
82
- liquidationMargin: ratioPattern,
83
- liquidationPenalty: ratioPattern,
84
- interestRate: ratioPattern,
85
- loanFee: ratioPattern,
86
- debtLimit: amountPattern,
87
- });
83
+ export const vaultParamPattern = M.split(
84
+ {
85
+ liquidationMargin: ratioPattern,
86
+ liquidationPenalty: ratioPattern,
87
+ interestRate: ratioPattern,
88
+ loanFee: ratioPattern,
89
+ debtLimit: amountPattern,
90
+ },
91
+ M.any(),
92
+ );
88
93
 
89
94
  /**
90
95
  * @param {import('@agoric/notifier').StoredPublisherKit<GovernanceSubscriptionState>} publisherKit
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // @jessie-check
2
3
 
3
4
  import { makeRatioFromAmounts } from '@agoric/zoe/src/contractSupport/index.js';
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  /**
2
3
  * Module to improvise composite keys for orderedVaultStore until Collections
3
4
  * API supports them.
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  /**
2
4
  * @typedef {import('./vault').VaultNotification} VaultNotification
3
5
  * @typedef {import('./vault').Vault} Vault