@agoric/inter-protocol 0.13.3-pismo-dev-50dc068.0 → 0.13.4-dev-800c2bb.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 (141) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +26 -20
  3. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  4. package/bundles/bundle-auctioneer.js +1 -0
  5. package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
  6. package/bundles/bundle-econCommitteeCharter.js +1 -0
  7. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  8. package/bundles/bundle-feeDistributor.js +1 -1
  9. package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
  10. package/bundles/bundle-fluxAggregatorKit.js +1 -0
  11. package/bundles/bundle-psm-js-meta.json +666 -0
  12. package/bundles/bundle-psm.js +1 -1
  13. package/bundles/bundle-reserve-js-meta.json +662 -0
  14. package/bundles/bundle-reserve.js +1 -1
  15. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  16. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  17. package/bundles/bundle-vaultFactory-js-meta.json +786 -0
  18. package/bundles/bundle-vaultFactory.js +1 -1
  19. package/exported.js +0 -2
  20. package/package.json +34 -31
  21. package/scripts/add-collateral-core.js +14 -4
  22. package/scripts/build-bundles.js +9 -2
  23. package/scripts/deploy-contracts.js +1 -4
  24. package/scripts/init-core.js +20 -38
  25. package/scripts/invite-committee-core.js +1 -1
  26. package/scripts/manual-price-feed.js +2 -2
  27. package/scripts/price-feed-core.js +7 -6
  28. package/scripts/start-local-chain.sh +84 -0
  29. package/src/auction/auctionBook.js +755 -0
  30. package/src/auction/auctioneer.js +720 -0
  31. package/src/auction/offerBook.js +221 -0
  32. package/src/auction/params.js +174 -0
  33. package/src/auction/scheduleMath.js +167 -0
  34. package/src/auction/scheduler.js +370 -0
  35. package/src/auction/sortedOffers.js +136 -0
  36. package/src/auction/util.js +55 -0
  37. package/src/clientSupport.js +324 -0
  38. package/src/collectFees.js +8 -14
  39. package/src/contractSupport.js +24 -68
  40. package/src/econCommitteeCharter.js +161 -77
  41. package/src/feeDistributor.js +60 -20
  42. package/src/index.js +2 -0
  43. package/src/interest-math.js +1 -4
  44. package/src/interest.js +20 -13
  45. package/src/price/README.md +57 -0
  46. package/src/price/fluxAggregatorContract.js +190 -0
  47. package/src/price/fluxAggregatorKit.js +375 -0
  48. package/src/price/priceOracleKit.js +127 -0
  49. package/src/price/roundsManager.js +726 -0
  50. package/src/proposals/addAssetToVault.js +89 -94
  51. package/src/proposals/committee-proposal.js +141 -40
  52. package/src/proposals/core-proposal.js +100 -167
  53. package/src/proposals/econ-behaviors.js +320 -564
  54. package/src/proposals/price-feed-proposal.js +175 -78
  55. package/src/proposals/startEconCommittee.js +25 -12
  56. package/src/proposals/startPSM.js +231 -211
  57. package/src/proposals/utils.js +31 -17
  58. package/src/psm/README.md +71 -0
  59. package/src/psm/psm.js +272 -160
  60. package/src/psm/types.js +2 -0
  61. package/src/reserve/assetReserve.js +56 -413
  62. package/src/reserve/assetReserveKit.js +303 -0
  63. package/src/reserve/doc.md +1 -3
  64. package/src/reserve/params.js +2 -5
  65. package/src/typeGuards.js +13 -0
  66. package/src/vaultFactory/Liquidation.md +100 -0
  67. package/src/vaultFactory/burn.js +2 -1
  68. package/src/vaultFactory/liquidation.js +270 -108
  69. package/src/vaultFactory/math.js +95 -0
  70. package/src/vaultFactory/orderedVaultStore.js +0 -1
  71. package/src/vaultFactory/params.js +133 -112
  72. package/src/vaultFactory/prioritizedVaults.js +36 -79
  73. package/src/vaultFactory/storeUtils.js +67 -9
  74. package/src/vaultFactory/type-imports.js +2 -0
  75. package/src/vaultFactory/types.js +22 -26
  76. package/src/vaultFactory/vault.js +772 -709
  77. package/src/vaultFactory/vaultDirector.js +480 -483
  78. package/src/vaultFactory/vaultFactory.js +99 -60
  79. package/src/vaultFactory/vaultHolder.js +121 -95
  80. package/src/vaultFactory/vaultKit.js +39 -31
  81. package/src/vaultFactory/vaultManager.js +1249 -868
  82. package/bundles/bundle-amm-meta.js +0 -618
  83. package/bundles/bundle-amm.js +0 -1
  84. package/bundles/bundle-feeDistributor-meta.js +0 -346
  85. package/bundles/bundle-interchainPool-meta.js +0 -534
  86. package/bundles/bundle-interchainPool.js +0 -1
  87. package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
  88. package/bundles/bundle-liquidateIncrementally.js +0 -1
  89. package/bundles/bundle-liquidateMinimum-meta.js +0 -442
  90. package/bundles/bundle-liquidateMinimum.js +0 -1
  91. package/bundles/bundle-psm-meta.js +0 -538
  92. package/bundles/bundle-psmCharter-meta.js +0 -418
  93. package/bundles/bundle-psmCharter.js +0 -1
  94. package/bundles/bundle-reserve-meta.js +0 -542
  95. package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
  96. package/bundles/bundle-stakeFactory-meta.js +0 -574
  97. package/bundles/bundle-stakeFactory.js +0 -1
  98. package/bundles/bundle-vaultFactory-meta.js +0 -598
  99. package/scripts/add-initial-liquidity.js +0 -180
  100. package/src/collect.js +0 -13
  101. package/src/interchainPool.js +0 -135
  102. package/src/makeTracer.js +0 -36
  103. package/src/my-lien.js +0 -85
  104. package/src/proposals/demoIssuers.js +0 -685
  105. package/src/proposals/sim-behaviors.js +0 -40
  106. package/src/psm/psmCharter.js +0 -139
  107. package/src/stakeFactory/README.md +0 -62
  108. package/src/stakeFactory/attestation.js +0 -267
  109. package/src/stakeFactory/attestationTool.js +0 -66
  110. package/src/stakeFactory/constants.js +0 -16
  111. package/src/stakeFactory/params.js +0 -31
  112. package/src/stakeFactory/stakeFactory.js +0 -236
  113. package/src/stakeFactory/stakeFactoryKit.js +0 -455
  114. package/src/stakeFactory/stakeFactoryManager.js +0 -296
  115. package/src/stakeFactory/types.js +0 -42
  116. package/src/vaultFactory/liquidateIncrementally.js +0 -350
  117. package/src/vaultFactory/liquidateMinimum.js +0 -100
  118. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  119. package/src/vpool-xyk-amm/addLiquidity.js +0 -222
  120. package/src/vpool-xyk-amm/addPool.js +0 -197
  121. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  122. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  123. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
  124. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
  125. package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
  126. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
  127. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
  128. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
  129. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
  130. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
  131. package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
  132. package/src/vpool-xyk-amm/doublePool.js +0 -194
  133. package/src/vpool-xyk-amm/estimate.js +0 -155
  134. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
  135. package/src/vpool-xyk-amm/params.js +0 -61
  136. package/src/vpool-xyk-amm/pool.js +0 -396
  137. package/src/vpool-xyk-amm/priceAuthority.js +0 -94
  138. package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
  139. package/src/vpool-xyk-amm/singlePool.js +0 -73
  140. package/src/vpool-xyk-amm/swap.js +0 -69
  141. package/src/vpool-xyk-amm/types.js +0 -154
@@ -1,6 +1,6 @@
1
- // @ts-check
1
+ // @jessie-check
2
2
 
3
- import '@agoric/governance/src/exported.js';
3
+ import '@agoric/governance/exported.js';
4
4
  import '@agoric/zoe/exported.js';
5
5
  import '@agoric/zoe/src/contracts/exported.js';
6
6
 
@@ -8,10 +8,8 @@ import '@agoric/zoe/src/contracts/exported.js';
8
8
  //
9
9
  // addVaultType is a closely held method that adds a brand new collateral type.
10
10
  // It specifies the initial exchange rate for that type. It depends on a
11
- // separately specified AMM to provide the ability to liquidate loans that are
12
- // in arrears. We could check that the AMM has sufficient liquidity, but for the
13
- // moment leave that to those participating in the governance process for adding
14
- // new collateral type to ascertain.
11
+ // separately specified mechanism to liquidate vaults that are
12
+ // in arrears.
15
13
 
16
14
  // This contract wants to be managed by a contractGovernor, but it isn't
17
15
  // compatible with contractGovernor, since it has a separate paramManager for
@@ -19,30 +17,45 @@ import '@agoric/zoe/src/contracts/exported.js';
19
17
  // to satisfy contractGovernor. It needs to return a creatorFacet with
20
18
  // { getParamMgrRetriever, getInvitation, getLimitedCreatorFacet }.
21
19
 
22
- import { assertElectorateMatches } from '@agoric/governance';
23
- import { makeStoredPublisherKit } from '@agoric/notifier';
24
- import {
25
- makeVaultDirectorParamManager,
26
- LIQUIDATION_INSTALL_KEY,
27
- LIQUIDATION_TERMS_KEY,
28
- MIN_INITIAL_DEBT_KEY,
29
- } from './params.js';
30
- import { makeVaultDirector } from './vaultDirector.js';
31
- import { assertKeysDefined } from '../contractSupport.js';
20
+ import { CONTRACT_ELECTORATE } from '@agoric/governance';
21
+ import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js';
22
+ import { validateElectorate } from '@agoric/governance/src/contractHelper.js';
23
+ import { makeTracer, StorageNodeShape } from '@agoric/internal';
24
+ import { makeStoredSubscription, makeSubscriptionKit } from '@agoric/notifier';
25
+ import { M } from '@agoric/store';
26
+ import { provideAll } from '@agoric/zoe/src/contractSupport/durability.js';
27
+ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
28
+ import { E } from '@endo/eventual-send';
29
+ import { FeeMintAccessShape } from '@agoric/zoe/src/typeGuards.js';
30
+ import { InvitationShape } from '../auction/params.js';
31
+ import { SHORTFALL_INVITATION_KEY, vaultDirectorParamTypes } from './params.js';
32
+ import { provideDirector } from './vaultDirector.js';
33
+
34
+ const trace = makeTracer('VF', true);
32
35
 
33
36
  /**
34
37
  * @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
35
- * ammPublicFacet: AutoswapPublicFacet,
36
- * liquidationInstall: Installation<import('./liquidateMinimum.js').start>,
37
- * loanTimingParams: {ChargingPeriod: ParamValueTyped<'nat'>, RecordingPeriod: ParamValueTyped<'nat'>},
38
- * minInitialDebt: Amount,
38
+ * auctioneerPublicFacet: import('../auction/auctioneer.js').AuctioneerPublicFacet,
39
39
  * priceAuthority: ERef<PriceAuthority>,
40
40
  * reservePublicFacet: AssetReservePublicFacet,
41
- * timerService: TimerService,
42
- * shortfallInvitation: 'invitation',
41
+ * timerService: import('@agoric/time/src/types').TimerService,
43
42
  * }>} VaultFactoryZCF
44
43
  */
45
44
 
45
+ export const privateArgsShape = M.splitRecord(
46
+ harden({
47
+ marshaller: M.remotable('Marshaller'),
48
+ storageNode: StorageNodeShape,
49
+ }),
50
+ harden({
51
+ // only necessary on first invocation, not subsequent
52
+ feeMintAccess: FeeMintAccessShape,
53
+ initialPoserInvitation: InvitationShape,
54
+ initialShortfallInvitation: InvitationShape,
55
+ }),
56
+ );
57
+ harden(privateArgsShape);
58
+
46
59
  /**
47
60
  * @param {VaultFactoryZCF} zcf
48
61
  * @param {{
@@ -52,59 +65,85 @@ import { assertKeysDefined } from '../contractSupport.js';
52
65
  * storageNode: ERef<StorageNode>,
53
66
  * marshaller: ERef<Marshaller>,
54
67
  * }} privateArgs
68
+ * @param {import('@agoric/ertp').Baggage} baggage
55
69
  */
56
- export const start = async (zcf, privateArgs) => {
57
- assertKeysDefined(privateArgs, [
58
- 'feeMintAccess',
59
- 'initialPoserInvitation',
60
- 'initialShortfallInvitation',
61
- 'storageNode',
62
- 'marshaller',
63
- ]);
64
- const { feeMintAccess, initialPoserInvitation, initialShortfallInvitation } =
65
- privateArgs;
66
- const debtMint = await zcf.registerFeeMint('Minted', feeMintAccess);
70
+ export const prepare = async (zcf, privateArgs, baggage) => {
71
+ trace('prepare start', privateArgs, [...baggage.keys()]);
72
+ const {
73
+ initialPoserInvitation,
74
+ initialShortfallInvitation,
75
+ marshaller,
76
+ storageNode,
77
+ } = privateArgs;
78
+
79
+ trace('awaiting debtMint');
80
+ const { debtMint } = await provideAll(baggage, {
81
+ debtMint: () => zcf.registerFeeMint('Minted', privateArgs.feeMintAccess),
82
+ });
83
+
67
84
  zcf.setTestJig(() => ({
68
85
  mintedIssuerRecord: debtMint.getIssuerRecord(),
69
86
  }));
70
87
 
71
- const {
72
- [LIQUIDATION_INSTALL_KEY]: { value: liqInstall },
73
- [LIQUIDATION_TERMS_KEY]: { value: liqTerms },
74
- [MIN_INITIAL_DEBT_KEY]: { value: minInitialDebt },
75
- } = zcf.getTerms().governedParams;
76
- /** a powerful object; can modify the invitation */
77
- const vaultDirectorParamManager = await makeVaultDirectorParamManager(
78
- makeStoredPublisherKit(
79
- privateArgs.storageNode,
80
- privateArgs.marshaller,
81
- 'governance',
82
- ),
83
- zcf.getZoeService(),
84
- initialPoserInvitation,
85
- liqInstall,
86
- liqTerms,
87
- minInitialDebt,
88
- initialShortfallInvitation,
88
+ const { timerService, auctioneerPublicFacet } = zcf.getTerms();
89
+
90
+ const { makeRecorderKit, makeERecorderKit } = prepareRecorderKitMakers(
91
+ baggage,
92
+ marshaller,
89
93
  );
90
94
 
91
- assertElectorateMatches(
92
- vaultDirectorParamManager,
93
- zcf.getTerms().governedParams,
95
+ trace('making non-durable publishers');
96
+ // XXX non-durable, will sever upon vat restart
97
+ const governanceSubscriptionKit = makeSubscriptionKit();
98
+ const governanceNode = E(storageNode).makeChildNode('governance');
99
+ const governanceSubscriber = makeStoredSubscription(
100
+ governanceSubscriptionKit.subscription,
101
+ governanceNode,
102
+ marshaller,
103
+ );
104
+ /** a powerful object; can modify the invitation */
105
+ trace('awaiting makeParamManagerFromTerms');
106
+ const vaultDirectorParamManager = await makeParamManagerFromTerms(
107
+ {
108
+ publisher: governanceSubscriptionKit.publication,
109
+ subscriber: governanceSubscriber,
110
+ },
111
+ zcf,
112
+ {
113
+ [CONTRACT_ELECTORATE]: initialPoserInvitation,
114
+ [SHORTFALL_INVITATION_KEY]: initialShortfallInvitation,
115
+ },
116
+ vaultDirectorParamTypes,
94
117
  );
95
118
 
96
- const factory = makeVaultDirector(
119
+ const director = provideDirector(
120
+ baggage,
97
121
  zcf,
98
122
  vaultDirectorParamManager,
99
123
  debtMint,
100
- privateArgs.storageNode,
101
- privateArgs.marshaller,
124
+ timerService,
125
+ auctioneerPublicFacet,
126
+ storageNode,
127
+ // XXX remove Recorder makers; remove once we excise deprecated kits for governance
128
+ marshaller,
129
+ makeRecorderKit,
130
+ makeERecorderKit,
102
131
  );
103
132
 
133
+ // cannot await because it would make remote calls during vat restart
134
+ director.helper.start().catch(err => {
135
+ console.error('💀 vaultDirector failed to start:', err);
136
+ zcf.shutdownWithFailure(err);
137
+ });
138
+
139
+ // validate async to wait for params to be finished
140
+ // UNTIL https://github.com/Agoric/agoric-sdk/issues/4343
141
+ void validateElectorate(zcf, vaultDirectorParamManager);
142
+
104
143
  return harden({
105
- creatorFacet: factory.creator,
106
- publicFacet: factory.public,
144
+ creatorFacet: director.creator,
145
+ publicFacet: director.public,
107
146
  });
108
147
  };
109
148
 
110
- /** @typedef {ContractOf<typeof start>} VaultFactoryContract */
149
+ /** @typedef {ContractOf<typeof prepare>} VaultFactoryContract */
@@ -1,111 +1,137 @@
1
1
  /**
2
2
  * @file Use-object for the owner of a vault
3
3
  */
4
- // @ts-check
5
- import '@agoric/zoe/exported.js';
4
+ import { AmountShape } from '@agoric/ertp';
5
+ import { M, prepareExoClassKit } from '@agoric/vat-data';
6
+ import {
7
+ SubscriberShape,
8
+ TopicsRecordShape,
9
+ } from '@agoric/zoe/src/contractSupport/index.js';
10
+ import { UnguardedHelperI } from '../typeGuards.js';
6
11
 
7
- import { makeStoredPublishKit } from '@agoric/notifier';
8
- import { defineDurableKindMulti, makeKindHandle } from '@agoric/vat-data';
9
- import { makeEphemeraProvider } from '../contractSupport.js';
10
-
11
- const { details: X } = assert;
12
-
13
- // XXX durable key to an ephemeral object
14
- // UNTIL https://github.com/Agoric/agoric-sdk/issues/4567
15
- let holderId = 0n;
16
-
17
- /**
18
- * @type {(key: bigint) => {
19
- * publisher: StoredPublishKit<VaultNotification>['publisher'],
20
- * subscriber: StoredPublishKit<VaultNotification>['subscriber'],
21
- * }} */
22
- // @ts-expect-error not yet defined
23
- const provideEphemera = makeEphemeraProvider(() => ({}));
12
+ const { Fail } = assert;
24
13
 
25
14
  /**
26
15
  * @typedef {{
27
- * holderId: bigint,
16
+ * topicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<VaultNotification>,
28
17
  * vault: Vault | null,
29
18
  * }} State
30
- * @typedef {Readonly<{
31
- * state: State,
32
- * facets: {
33
- * helper: import('@agoric/vat-data/src/types').KindFacet<typeof helper>,
34
- * self: import('@agoric/vat-data/src/types').KindFacet<typeof holder>,
35
- * },
36
- * }>} MethodContext
37
- */
38
-
39
- /**
40
- *
41
- * @param {Vault} vault
42
- * @param {ERef<StorageNode>} storageNode
43
- * @param {ERef<Marshaller>} marshaller
44
- * @returns {State}
45
19
  */
46
- const initState = (vault, storageNode, marshaller) => {
47
- /** @type {StoredPublishKit<VaultNotification>} */
48
- const { subscriber, publisher } = makeStoredPublishKit(
49
- storageNode,
50
- marshaller,
51
- );
52
20
 
53
- holderId += 1n;
54
- const ephemera = provideEphemera(holderId);
55
- // UNTIL https://github.com/Agoric/agoric-sdk/issues/4567
56
- Object.assign(ephemera, { subscriber, publisher });
21
+ const HolderI = M.interface('holder', {
22
+ getCollateralAmount: M.call().returns(AmountShape),
23
+ getCurrentDebt: M.call().returns(AmountShape),
24
+ getNormalizedDebt: M.call().returns(AmountShape),
25
+ getSubscriber: M.call().returns(SubscriberShape),
26
+ getPublicTopics: M.call().returns(TopicsRecordShape),
27
+ makeAdjustBalancesInvitation: M.call().returns(M.promise()),
28
+ makeCloseInvitation: M.call().returns(M.promise()),
29
+ makeTransferInvitation: M.call().returns(M.promise()),
30
+ });
57
31
 
58
- return { holderId, vault };
32
+ /** @type {{ [name: string]: [ description: string, valueShape: Pattern ] }} */
33
+ const PUBLIC_TOPICS = {
34
+ vault: ['Vault holder status', M.any()],
59
35
  };
60
36
 
61
- const helper = {
62
- /**
63
- * @param {MethodContext} context
64
- * @throws if this holder no longer owns the vault
65
- */
66
- owned: ({ state }) => {
67
- const { vault } = state;
68
- assert(vault, X`Using vault holder after transfer`);
69
- return vault;
70
- },
71
- /** @param {MethodContext} context */
72
- getUpdater: ({ state }) => provideEphemera(state.holderId).publisher,
73
- };
37
+ /**
38
+ * @param {import('@agoric/ertp').Baggage} baggage
39
+ * @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
40
+ */
41
+ export const prepareVaultHolder = (baggage, makeRecorderKit) => {
42
+ const makeVaultHolderKit = prepareExoClassKit(
43
+ baggage,
44
+ 'Vault Holder',
45
+ {
46
+ helper: UnguardedHelperI,
47
+ holder: HolderI,
48
+ invitationMakers: M.interface('invitationMakers', {
49
+ AdjustBalances: M.call().returns(M.promise()),
50
+ CloseVault: M.call().returns(M.promise()),
51
+ TransferVault: M.call().returns(M.promise()),
52
+ }),
53
+ },
54
+ /**
55
+ *
56
+ * @param {Vault} vault
57
+ * @param {StorageNode} storageNode
58
+ * @returns {State}
59
+ */
60
+ (vault, storageNode) => {
61
+ // must be the fully synchronous maker because the kit is held in durable state
62
+ const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.vault[1]);
74
63
 
75
- const holder = {
76
- /** @param {MethodContext} context */
77
- getSubscriber: ({ state }) => provideEphemera(state.holderId).subscriber,
78
- /** @param {MethodContext} context */
79
- makeAdjustBalancesInvitation: ({ facets }) =>
80
- facets.helper.owned().makeAdjustBalancesInvitation(),
81
- /** @param {MethodContext} context */
82
- makeCloseInvitation: ({ facets }) =>
83
- facets.helper.owned().makeCloseInvitation(),
84
- /**
85
- * Starting a transfer revokes the vault holder. The associated updater will
86
- * get a special notification that the vault is being transferred.
87
- *
88
- * @param {MethodContext} context
89
- */
90
- makeTransferInvitation: ({ state, facets }) => {
91
- const vault = facets.helper.owned();
92
- state.vault = null;
93
- return vault.makeTransferInvitation();
94
- },
95
- // for status/debugging
96
- /** @param {MethodContext} context */
97
- getCollateralAmount: ({ facets }) =>
98
- facets.helper.owned().getCollateralAmount(),
99
- /** @param {MethodContext} context */
100
- getCurrentDebt: ({ facets }) => facets.helper.owned().getCurrentDebt(),
101
- /** @param {MethodContext} context */
102
- getNormalizedDebt: ({ facets }) => facets.helper.owned().getNormalizedDebt(),
64
+ return { topicKit, vault };
65
+ },
66
+ {
67
+ helper: {
68
+ /**
69
+ * @throws if this holder no longer owns the vault
70
+ */
71
+ owned() {
72
+ const { vault } = this.state;
73
+ if (!vault) {
74
+ throw Fail`Using vault holder after transfer`;
75
+ }
76
+ return vault;
77
+ },
78
+ getUpdater() {
79
+ return this.state.topicKit.recorder;
80
+ },
81
+ },
82
+ invitationMakers: {
83
+ AdjustBalances() {
84
+ return this.facets.holder.makeAdjustBalancesInvitation();
85
+ },
86
+ CloseVault() {
87
+ return this.facets.holder.makeCloseInvitation();
88
+ },
89
+ TransferVault() {
90
+ return this.facets.holder.makeTransferInvitation();
91
+ },
92
+ },
93
+ holder: {
94
+ /** @deprecated use getPublicTopics */
95
+ getSubscriber() {
96
+ return this.state.topicKit.subscriber;
97
+ },
98
+ getPublicTopics() {
99
+ const { topicKit } = this.state;
100
+ return harden({
101
+ vault: {
102
+ description: PUBLIC_TOPICS.vault[0],
103
+ subscriber: topicKit.subscriber,
104
+ storagePath: topicKit.recorder.getStoragePath(),
105
+ },
106
+ });
107
+ },
108
+ makeAdjustBalancesInvitation() {
109
+ return this.facets.helper.owned().makeAdjustBalancesInvitation();
110
+ },
111
+ makeCloseInvitation() {
112
+ return this.facets.helper.owned().makeCloseInvitation();
113
+ },
114
+ /**
115
+ * Starting a transfer revokes the vault holder. The associated updater will
116
+ * get a special notification that the vault is being transferred.
117
+ */
118
+ makeTransferInvitation() {
119
+ const vault = this.facets.helper.owned();
120
+ this.state.vault = null;
121
+ return vault.makeTransferInvitation();
122
+ },
123
+ // for status/debugging
124
+ getCollateralAmount() {
125
+ return this.facets.helper.owned().getCollateralAmount();
126
+ },
127
+ getCurrentDebt() {
128
+ return this.facets.helper.owned().getCurrentDebt();
129
+ },
130
+ getNormalizedDebt() {
131
+ return this.facets.helper.owned().getNormalizedDebt();
132
+ },
133
+ },
134
+ },
135
+ );
136
+ return makeVaultHolderKit;
103
137
  };
104
-
105
- const behavior = { helper, holder };
106
-
107
- export const makeVaultHolder = defineDurableKindMulti(
108
- makeKindHandle('VaultHolder'),
109
- initState,
110
- behavior,
111
- );
@@ -1,38 +1,46 @@
1
- // @ts-check
1
+ // @jessie-check
2
+
2
3
  import '@agoric/zoe/exported.js';
3
- import { Far } from '@endo/marshal';
4
- import { makeVaultHolder } from './vaultHolder.js';
4
+
5
+ import { makeTracer } from '@agoric/internal';
6
+ import { prepareVaultHolder } from './vaultHolder.js';
7
+
8
+ const trace = makeTracer('VK', true);
5
9
 
6
10
  /**
7
- * Create a kit of utilities for use of the vault.
11
+ * Wrap the VaultHolder duration object in a record suitable for the result of an invitation.
8
12
  *
9
- * @param {Vault} vault
10
- * @param {ERef<StorageNode>} storageNode
11
- * @param {ERef<Marshaller>} marshaller
12
- * @param {Subscriber<import('./vaultManager').AssetState>} assetSubscriber
13
+ * @param {import('@agoric/ertp').Baggage} baggage
14
+ * @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
13
15
  */
14
- export const makeVaultKit = (
15
- vault,
16
- storageNode,
17
- marshaller,
18
- assetSubscriber,
19
- ) => {
20
- const { holder, helper } = makeVaultHolder(vault, storageNode, marshaller);
21
- const vaultKit = harden({
22
- publicSubscribers: {
23
- // XXX should come from manager directly https://github.com/Agoric/agoric-sdk/issues/5814
24
- asset: assetSubscriber,
25
- vault: holder.getSubscriber(),
26
- },
27
- invitationMakers: Far('invitation makers', {
28
- AdjustBalances: holder.makeAdjustBalancesInvitation,
29
- CloseVault: holder.makeCloseInvitation,
30
- TransferVault: holder.makeTransferInvitation,
31
- }),
32
- vault: holder,
33
- vaultUpdater: helper.getUpdater(),
34
- });
35
- return vaultKit;
16
+ export const prepareVaultKit = (baggage, makeRecorderKit) => {
17
+ trace('prepareVaultKit', [...baggage.keys()]);
18
+
19
+ const makeVaultHolder = prepareVaultHolder(baggage, makeRecorderKit);
20
+ /**
21
+ * Create a kit of utilities for use of the vault.
22
+ *
23
+ * @param {Vault} vault
24
+ * @param {StorageNode} storageNode
25
+ */
26
+ const makeVaultKit = (vault, storageNode) => {
27
+ trace('prepareVaultKit makeVaultKit');
28
+ const { holder, helper, invitationMakers } = makeVaultHolder(
29
+ vault,
30
+ storageNode,
31
+ );
32
+ const holderTopics = holder.getPublicTopics();
33
+ const vaultKit = harden({
34
+ publicSubscribers: {
35
+ vault: holderTopics.vault,
36
+ },
37
+ invitationMakers,
38
+ vault: holder,
39
+ vaultUpdater: helper.getUpdater(),
40
+ });
41
+ return vaultKit;
42
+ };
43
+ return makeVaultKit;
36
44
  };
37
45
 
38
- /** @typedef {(ReturnType<typeof makeVaultKit>)} VaultKit */
46
+ /** @typedef {(ReturnType<ReturnType<typeof prepareVaultKit>>)} VaultKit */