@agoric/zoe 0.26.2 → 0.26.3-calypso-dev-84eb287.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 (274) hide show
  1. package/README.md +7 -7
  2. package/bundles/bundle-contractFacet-js-meta.json +628 -314
  3. package/bundles/bundle-contractFacet.d.ts +3 -3
  4. package/bundles/bundle-contractFacet.js +1 -1
  5. package/exported.js +1 -12
  6. package/package.json +75 -59
  7. package/src/cleanProposal.d.ts +2 -2
  8. package/src/cleanProposal.d.ts.map +1 -1
  9. package/src/cleanProposal.js +15 -12
  10. package/src/contractFacet/evalContractCode.d.ts.map +1 -1
  11. package/src/contractFacet/evalContractCode.js +2 -2
  12. package/src/contractFacet/exit.d.ts.map +1 -1
  13. package/src/contractFacet/exit.js +1 -0
  14. package/src/contractFacet/internal-types.d.ts +2 -2
  15. package/src/contractFacet/internal-types.d.ts.map +1 -1
  16. package/src/contractFacet/internal-types.js +1 -1
  17. package/src/contractFacet/offerHandlerStorage.d.ts +4 -1
  18. package/src/contractFacet/offerHandlerStorage.d.ts.map +1 -1
  19. package/src/contractFacet/offerHandlerStorage.js +11 -3
  20. package/src/contractFacet/reallocate.d.ts +3 -0
  21. package/src/contractFacet/reallocate.d.ts.map +1 -0
  22. package/src/contractFacet/reallocate.js +94 -0
  23. package/src/contractFacet/rightsConservation.d.ts.map +1 -1
  24. package/src/contractFacet/rightsConservation.js +3 -0
  25. package/src/contractFacet/typeGuards.d.ts +8 -0
  26. package/src/contractFacet/typeGuards.d.ts.map +1 -0
  27. package/src/contractFacet/typeGuards.js +25 -0
  28. package/src/contractFacet/types-ambient.d.ts +271 -0
  29. package/src/contractFacet/types-ambient.js +1 -0
  30. package/src/contractFacet/vatRoot.d.ts +3 -3
  31. package/src/contractFacet/vatRoot.d.ts.map +1 -1
  32. package/src/contractFacet/zcfMint.d.ts +4 -2
  33. package/src/contractFacet/zcfMint.d.ts.map +1 -1
  34. package/src/contractFacet/zcfMint.js +7 -7
  35. package/src/contractFacet/zcfSeat.d.ts +4 -2
  36. package/src/contractFacet/zcfSeat.d.ts.map +1 -1
  37. package/src/contractFacet/zcfSeat.js +130 -7
  38. package/src/contractFacet/zcfZygote.d.ts +1 -2
  39. package/src/contractFacet/zcfZygote.d.ts.map +1 -1
  40. package/src/contractFacet/zcfZygote.js +102 -48
  41. package/src/contractSupport/atomicTransfer.d.ts +0 -6
  42. package/src/contractSupport/atomicTransfer.d.ts.map +1 -1
  43. package/src/contractSupport/atomicTransfer.js +5 -90
  44. package/src/contractSupport/bondingCurves.js +2 -2
  45. package/src/contractSupport/durability.d.ts +3 -3
  46. package/src/contractSupport/durability.d.ts.map +1 -1
  47. package/src/contractSupport/durability.js +5 -5
  48. package/src/contractSupport/index.d.ts +1 -0
  49. package/src/contractSupport/index.js +1 -0
  50. package/src/contractSupport/prepare-ownable.d.ts +11 -0
  51. package/src/contractSupport/prepare-ownable.d.ts.map +1 -0
  52. package/src/contractSupport/prepare-ownable.js +100 -0
  53. package/src/contractSupport/priceAuthority.d.ts +23 -15
  54. package/src/contractSupport/priceAuthority.d.ts.map +1 -1
  55. package/src/contractSupport/priceAuthority.js +33 -18
  56. package/src/contractSupport/priceAuthorityInitial.d.ts +3 -2
  57. package/src/contractSupport/priceAuthorityInitial.d.ts.map +1 -1
  58. package/src/contractSupport/priceAuthorityInitial.js +6 -3
  59. package/src/contractSupport/priceAuthorityQuoteMint.d.ts +2 -1
  60. package/src/contractSupport/priceAuthorityQuoteMint.d.ts.map +1 -1
  61. package/src/contractSupport/priceAuthorityQuoteMint.js +23 -27
  62. package/src/contractSupport/priceAuthorityTransform.d.ts +13 -11
  63. package/src/contractSupport/priceAuthorityTransform.d.ts.map +1 -1
  64. package/src/contractSupport/priceAuthorityTransform.js +10 -8
  65. package/src/contractSupport/priceQuote.d.ts +7 -5
  66. package/src/contractSupport/priceQuote.d.ts.map +1 -1
  67. package/src/contractSupport/priceQuote.js +5 -1
  68. package/src/contractSupport/ratio.d.ts +2 -2
  69. package/src/contractSupport/ratio.d.ts.map +1 -1
  70. package/src/contractSupport/ratio.js +19 -15
  71. package/src/contractSupport/recorder.d.ts +33 -119
  72. package/src/contractSupport/recorder.d.ts.map +1 -1
  73. package/src/contractSupport/recorder.js +21 -10
  74. package/src/contractSupport/safeMath.d.ts +7 -7
  75. package/src/contractSupport/safeMath.d.ts.map +1 -1
  76. package/src/contractSupport/statistics.d.ts +1 -1
  77. package/src/contractSupport/statistics.d.ts.map +1 -1
  78. package/src/contractSupport/topics.d.ts +1 -1
  79. package/src/contractSupport/topics.d.ts.map +1 -1
  80. package/src/contractSupport/{types.d.ts → types-ambient.d.ts} +4 -4
  81. package/src/contractSupport/types-ambient.d.ts.map +1 -0
  82. package/src/contractSupport/{types.js → types-ambient.js} +1 -1
  83. package/src/contractSupport/zoeHelpers.d.ts +1 -1
  84. package/src/contractSupport/zoeHelpers.d.ts.map +1 -1
  85. package/src/contractSupport/zoeHelpers.js +6 -12
  86. package/src/contracts/auction/firstPriceLogic.d.ts.map +1 -1
  87. package/src/contracts/auction/firstPriceLogic.js +5 -8
  88. package/src/contracts/auction/index.d.ts +10 -10
  89. package/src/contracts/auction/index.d.ts.map +1 -1
  90. package/src/contracts/auction/index.js +3 -3
  91. package/src/contracts/auction/secondPriceLogic.d.ts.map +1 -1
  92. package/src/contracts/auction/secondPriceLogic.js +1 -4
  93. package/src/contracts/automaticRefund.d.ts +1 -1
  94. package/src/contracts/automaticRefund.d.ts.map +1 -1
  95. package/src/contracts/autoswap.d.ts.map +1 -1
  96. package/src/contracts/autoswap.js +8 -9
  97. package/src/contracts/barterExchange.d.ts +1 -1
  98. package/src/contracts/barterExchange.d.ts.map +1 -1
  99. package/src/contracts/barterExchange.js +2 -3
  100. package/src/contracts/callSpread/calculateShares.d.ts +1 -8
  101. package/src/contracts/callSpread/calculateShares.d.ts.map +1 -1
  102. package/src/contracts/callSpread/calculateShares.js +1 -1
  103. package/src/contracts/callSpread/fundedCallSpread.d.ts +4 -0
  104. package/src/contracts/callSpread/fundedCallSpread.d.ts.map +1 -1
  105. package/src/contracts/callSpread/fundedCallSpread.js +6 -4
  106. package/src/contracts/callSpread/payoffHandler.d.ts.map +1 -1
  107. package/src/contracts/callSpread/payoffHandler.js +3 -2
  108. package/src/contracts/callSpread/percent.d.ts +2 -4
  109. package/src/contracts/callSpread/percent.d.ts.map +1 -1
  110. package/src/contracts/callSpread/position.d.ts +2 -2
  111. package/src/contracts/callSpread/pricedCallSpread.d.ts +6 -5
  112. package/src/contracts/callSpread/pricedCallSpread.d.ts.map +1 -1
  113. package/src/contracts/callSpread/pricedCallSpread.js +9 -5
  114. package/src/contracts/callSpread/{types.d.ts → types-ambient.d.ts} +3 -3
  115. package/src/contracts/callSpread/types-ambient.d.ts.map +1 -0
  116. package/src/contracts/coveredCall-durable.d.ts +2 -4
  117. package/src/contracts/coveredCall-durable.d.ts.map +1 -1
  118. package/src/contracts/exported.js +3 -3
  119. package/src/contracts/loan/borrow.d.ts.map +1 -1
  120. package/src/contracts/loan/borrow.js +7 -4
  121. package/src/contracts/loan/close.d.ts.map +1 -1
  122. package/src/contracts/loan/close.js +3 -7
  123. package/src/contracts/loan/index.d.ts +5 -1
  124. package/src/contracts/loan/index.d.ts.map +1 -1
  125. package/src/contracts/loan/index.js +4 -0
  126. package/src/contracts/loan/liquidate.d.ts +1 -12
  127. package/src/contracts/loan/liquidate.d.ts.map +1 -1
  128. package/src/contracts/loan/liquidate.js +4 -2
  129. package/src/contracts/loan/scheduleLiquidation.d.ts.map +1 -1
  130. package/src/contracts/loan/scheduleLiquidation.js +2 -1
  131. package/src/contracts/loan/{types.d.ts → types-ambient.d.ts} +16 -17
  132. package/src/contracts/loan/types-ambient.d.ts.map +1 -0
  133. package/src/contracts/loan/{types.js → types-ambient.js} +11 -18
  134. package/src/contracts/loan/updateDebt.js +1 -1
  135. package/src/contracts/mintAndSellNFT.d.ts.map +1 -1
  136. package/src/contracts/mintPayments.d.ts +14 -6
  137. package/src/contracts/mintPayments.d.ts.map +1 -1
  138. package/src/contracts/mintPayments.js +1 -1
  139. package/src/contracts/oracle.d.ts +6 -2
  140. package/src/contracts/oracle.d.ts.map +1 -1
  141. package/src/contracts/oracle.js +10 -3
  142. package/src/contracts/otcDesk.d.ts +3 -3
  143. package/src/contracts/otcDesk.d.ts.map +1 -1
  144. package/src/contracts/otcDesk.js +1 -1
  145. package/src/contracts/priceAggregator.d.ts +25 -17
  146. package/src/contracts/priceAggregator.d.ts.map +1 -1
  147. package/src/contracts/priceAggregator.js +33 -32
  148. package/src/contracts/priceAggregatorTypes.d.ts +2 -2
  149. package/src/contracts/priceAggregatorTypes.d.ts.map +1 -1
  150. package/src/contracts/scaledPriceAuthority.d.ts +3 -4
  151. package/src/contracts/scaledPriceAuthority.d.ts.map +1 -1
  152. package/src/contracts/scaledPriceAuthority.js +6 -0
  153. package/src/contracts/sellItems.d.ts +2 -2
  154. package/src/contracts/sellItems.d.ts.map +1 -1
  155. package/src/contracts/sellItems.js +3 -4
  156. package/src/contracts/simpleExchange.d.ts +3 -3
  157. package/src/contracts/{types.d.ts → types-ambient.d.ts} +1 -1
  158. package/src/contracts/types-ambient.d.ts.map +1 -0
  159. package/src/handleWarning.d.ts.map +1 -1
  160. package/src/instanceRecordStorage.d.ts +1 -1
  161. package/src/instanceRecordStorage.d.ts.map +1 -1
  162. package/src/internal-types.d.ts +21 -32
  163. package/src/internal-types.d.ts.map +1 -1
  164. package/src/internal-types.js +19 -58
  165. package/src/issuerRecord.d.ts +1 -1
  166. package/src/issuerRecord.d.ts.map +1 -1
  167. package/src/issuerStorage.d.ts +3 -3
  168. package/src/issuerStorage.d.ts.map +1 -1
  169. package/src/issuerStorage.js +12 -28
  170. package/src/makeHandle.d.ts +2 -2
  171. package/src/makeHandle.d.ts.map +1 -1
  172. package/src/makeHandle.js +1 -1
  173. package/src/typeGuards.d.ts +114 -20
  174. package/src/typeGuards.d.ts.map +1 -1
  175. package/src/typeGuards.js +19 -20
  176. package/src/types-ambient.d.ts +41 -0
  177. package/src/types-ambient.d.ts.map +1 -0
  178. package/src/{types.js → types-ambient.js} +7 -15
  179. package/src/zoeService/escrowStorage.d.ts +1 -1
  180. package/src/zoeService/escrowStorage.d.ts.map +1 -1
  181. package/src/zoeService/escrowStorage.js +20 -27
  182. package/src/zoeService/feeMint.d.ts +9 -16
  183. package/src/zoeService/feeMint.d.ts.map +1 -1
  184. package/src/zoeService/feeMint.js +21 -15
  185. package/src/zoeService/installationStorage.d.ts +5 -20
  186. package/src/zoeService/installationStorage.d.ts.map +1 -1
  187. package/src/zoeService/installationStorage.js +11 -7
  188. package/src/zoeService/instanceAdminStorage.d.ts +22 -42
  189. package/src/zoeService/instanceAdminStorage.d.ts.map +1 -1
  190. package/src/zoeService/instanceAdminStorage.js +2 -1
  191. package/src/zoeService/internal-types.d.ts +12 -12
  192. package/src/zoeService/internal-types.d.ts.map +1 -1
  193. package/src/zoeService/internal-types.js +6 -6
  194. package/src/zoeService/invitationQueries.d.ts.map +1 -1
  195. package/src/zoeService/invitationQueries.js +7 -5
  196. package/src/zoeService/makeInvitation.d.ts +3 -3
  197. package/src/zoeService/makeInvitation.d.ts.map +1 -1
  198. package/src/zoeService/makeInvitation.js +25 -21
  199. package/src/zoeService/offer/burnInvitation.d.ts.map +1 -1
  200. package/src/zoeService/offer/offer.d.ts.map +1 -1
  201. package/src/zoeService/offer/offer.js +2 -5
  202. package/src/zoeService/originalZoeSeat.d.ts +34 -0
  203. package/src/zoeService/originalZoeSeat.d.ts.map +1 -0
  204. package/src/zoeService/originalZoeSeat.js +353 -0
  205. package/src/zoeService/startInstance.d.ts +3 -3
  206. package/src/zoeService/startInstance.d.ts.map +1 -1
  207. package/src/zoeService/startInstance.js +82 -37
  208. package/src/zoeService/{types.d.ts → types-ambient.d.ts} +23 -28
  209. package/src/zoeService/types-ambient.d.ts.map +1 -0
  210. package/src/zoeService/{types.js → types-ambient.js} +19 -32
  211. package/src/zoeService/utils.d.ts +57 -58
  212. package/src/zoeService/utils.test-d.d.ts +2 -0
  213. package/src/zoeService/utils.test-d.d.ts.map +1 -0
  214. package/src/zoeService/utils.test-d.ts +33 -0
  215. package/src/zoeService/zoe.d.ts +14 -8
  216. package/src/zoeService/zoe.d.ts.map +1 -1
  217. package/src/zoeService/zoe.js +39 -11
  218. package/src/zoeService/zoeSeat.d.ts +15 -45
  219. package/src/zoeService/zoeSeat.d.ts.map +1 -1
  220. package/src/zoeService/zoeSeat.js +215 -115
  221. package/src/zoeService/zoeStorageManager.d.ts +13 -47
  222. package/src/zoeService/zoeStorageManager.d.ts.map +1 -1
  223. package/src/zoeService/zoeStorageManager.js +13 -6
  224. package/tools/fakePriceAuthority.d.ts +9 -8
  225. package/tools/fakePriceAuthority.d.ts.map +1 -1
  226. package/tools/fakePriceAuthority.js +21 -17
  227. package/tools/fakeVatAdmin.d.ts +10 -10
  228. package/tools/manualPriceAuthority.d.ts +11 -6
  229. package/tools/manualPriceAuthority.d.ts.map +1 -1
  230. package/tools/manualPriceAuthority.js +16 -3
  231. package/tools/manualTimer.d.ts +17 -40
  232. package/tools/manualTimer.d.ts.map +1 -1
  233. package/tools/manualTimer.js +30 -16
  234. package/tools/prepare-test-env.js +1 -1
  235. package/tools/scriptedOracle.d.ts +3 -3
  236. package/tools/scriptedOracle.d.ts.map +1 -1
  237. package/tools/scriptedOracle.js +1 -1
  238. package/tools/scriptedPriceAuthority.d.ts +4 -0
  239. package/tools/scriptedPriceAuthority.d.ts.map +1 -1
  240. package/tools/scriptedPriceAuthority.js +8 -3
  241. package/tools/setup-zoe.d.ts +10 -6
  242. package/tools/setup-zoe.d.ts.map +1 -1
  243. package/tools/setup-zoe.js +16 -1
  244. package/tools/test-utils.d.ts +20 -0
  245. package/tools/test-utils.d.ts.map +1 -0
  246. package/tools/test-utils.js +26 -0
  247. package/tools/types.d.ts +21 -21
  248. package/tools/types.d.ts.map +1 -1
  249. package/tools/types.js +10 -10
  250. package/CHANGELOG.md +0 -1171
  251. package/src/contractFacet/types.d.ts +0 -191
  252. package/src/contractFacet/types.d.ts.map +0 -1
  253. package/src/contractFacet/types.js +0 -256
  254. package/src/contractSupport/types.d.ts.map +0 -1
  255. package/src/contracts/callSpread/types.d.ts.map +0 -1
  256. package/src/contracts/loan/types.d.ts.map +0 -1
  257. package/src/contracts/types.d.ts.map +0 -1
  258. package/src/objArrayConversion.d.ts +0 -5
  259. package/src/objArrayConversion.d.ts.map +0 -1
  260. package/src/objArrayConversion.js +0 -35
  261. package/src/types.d.ts +0 -45
  262. package/src/types.d.ts.map +0 -1
  263. package/src/zoeService/types.d.ts.map +0 -1
  264. package/tools/internal-types.d.ts +0 -12
  265. package/tools/internal-types.d.ts.map +0 -1
  266. package/tools/internal-types.js +0 -14
  267. package/tools/priceAuthorityRegistry.d.ts +0 -20
  268. package/tools/priceAuthorityRegistry.d.ts.map +0 -1
  269. package/tools/priceAuthorityRegistry.js +0 -209
  270. package/tools/types-ambient.d.ts +0 -142
  271. package/tools/types-ambient.d.ts.map +0 -1
  272. package/tools/types-ambient.js +0 -160
  273. /package/src/contracts/callSpread/{types.js → types-ambient.js} +0 -0
  274. /package/src/contracts/{types.js → types-ambient.js} +0 -0
@@ -1,41 +1,45 @@
1
1
  // @jessie-check
2
2
 
3
+ import { Fail, q } from '@agoric/assert';
3
4
  import { provideDurableMapStore } from '@agoric/vat-data';
4
- import {
5
- AssetKind,
6
- makeDurableIssuerKit,
7
- prepareIssuerKit,
8
- } from '@agoric/ertp';
5
+ import { AssetKind, hasIssuer, prepareIssuerKit } from '@agoric/ertp';
9
6
  import { InvitationElementShape } from '../typeGuards.js';
10
7
 
8
+ /**
9
+ * Not deprecated because the first use below is still correct.
10
+ */
11
11
  const ZOE_INVITATION_KIT = 'ZoeInvitationKit';
12
12
 
13
13
  /**
14
14
  * @param {import('@agoric/vat-data').Baggage} baggage
15
- * @param {ShutdownWithFailure | undefined} shutdownZoeVat
15
+ * @param {import('@agoric/swingset-vat').ShutdownWithFailure | undefined} shutdownZoeVat
16
16
  */
17
17
  export const prepareInvitationKit = (baggage, shutdownZoeVat = undefined) => {
18
- /** @type {IssuerKit<'set'> | undefined} */
19
- let invitationKit;
20
-
21
18
  const invitationKitBaggage = provideDurableMapStore(
22
19
  baggage,
23
20
  ZOE_INVITATION_KIT,
24
21
  );
25
- if (!invitationKitBaggage.has(ZOE_INVITATION_KIT)) {
26
- invitationKit = makeDurableIssuerKit(
27
- invitationKitBaggage,
28
- 'Zoe Invitation',
29
- AssetKind.SET,
30
- undefined,
31
- shutdownZoeVat,
32
- { elementShape: InvitationElementShape },
33
- );
34
- invitationKitBaggage.init(ZOE_INVITATION_KIT, invitationKit);
35
- } else {
36
- invitationKit = prepareIssuerKit(invitationKitBaggage);
22
+ if (invitationKitBaggage.has(ZOE_INVITATION_KIT)) {
23
+ // This legacy second use of ZOE_INVITATION_KIT is unneeded.
24
+ hasIssuer(invitationKitBaggage) ||
25
+ Fail`Legacy use of ${q(
26
+ ZOE_INVITATION_KIT,
27
+ )} must be redundant with normal storing of issuerKit in issuerBaggage`;
28
+ // Upgrade this legacy state by simply deleting it.
29
+ invitationKitBaggage.delete(ZOE_INVITATION_KIT);
37
30
  }
38
31
 
32
+ /** @type {IssuerKit<'set', InvitationDetails>} */
33
+ // @ts-expect-error cast
34
+ const invitationKit = prepareIssuerKit(
35
+ invitationKitBaggage,
36
+ 'Zoe Invitation',
37
+ AssetKind.SET,
38
+ undefined,
39
+ shutdownZoeVat,
40
+ { elementShape: InvitationElementShape },
41
+ );
42
+
39
43
  return harden({
40
44
  invitationIssuer: invitationKit.issuer,
41
45
  invitationKit,
@@ -1 +1 @@
1
- {"version":3,"file":"burnInvitation.d.ts","sourceRoot":"","sources":["burnInvitation.js"],"names":[],"mappings":"AAgBO,iDAPI,MAAM,cACN,KAAK,OAAO,CAAC,GACX,QAAQ;IACpB,cAAkB,EAAE,QAAQ,CAAC;IAC7B,gBAAoB,EAAE,gBAAgB,CAAC;CACpC,CAAC,CA4BJ"}
1
+ {"version":3,"file":"burnInvitation.d.ts","sourceRoot":"","sources":["burnInvitation.js"],"names":[],"mappings":"AAgBO,iDAPI,MAAM,cACN,IAAI,CAAC,OAAO,CAAC,GACX,OAAO,CAAC;IACpB,cAAkB,EAAE,QAAQ,CAAC;IAC7B,gBAAoB,EAAE,gBAAgB,CAAC;CACpC,CAAC,CA4BJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"offer.d.ts","sourceRoot":"","sources":["offer.js"],"names":[],"mappings":"AAgBO,6DA2DN"}
1
+ {"version":3,"file":"offer.d.ts","sourceRoot":"","sources":["offer.js"],"names":[],"mappings":"AAcO,6DA0DN"}
@@ -8,8 +8,6 @@ import { cleanProposal } from '../../cleanProposal.js';
8
8
  import { burnInvitation } from './burnInvitation.js';
9
9
  import { makeInvitationQueryFns } from '../invitationQueries.js';
10
10
 
11
- import '@agoric/ertp/exported.js';
12
- import '@agoric/store/exported.js';
13
11
  import '../internal-types.js';
14
12
 
15
13
  const { quote: q, Fail } = assert;
@@ -24,9 +22,8 @@ export const makeOfferMethod = offerDataAccess => {
24
22
  ) => {
25
23
  const invitationIssuer = offerDataAccess.getInvitationIssuer();
26
24
  const query = makeInvitationQueryFns(invitationIssuer);
27
- const { instance, description } = await query.getInvitationDetails(
28
- invitation,
29
- );
25
+ const { instance, description } =
26
+ await query.getInvitationDetails(invitation);
30
27
  // AWAIT ///
31
28
 
32
29
  const instanceAdmin = await offerDataAccess.getInstanceAdmin(instance);
@@ -0,0 +1,34 @@
1
+ export namespace coreUserSeatMethods {
2
+ let getProposal: import("@endo/patterns").MethodGuard;
3
+ let getPayouts: import("@endo/patterns").MethodGuard;
4
+ let getPayout: import("@endo/patterns").MethodGuard;
5
+ let getOfferResult: import("@endo/patterns").MethodGuard;
6
+ let hasExited: import("@endo/patterns").MethodGuard;
7
+ let numWantsSatisfied: import("@endo/patterns").MethodGuard;
8
+ let getFinalAllocation: import("@endo/patterns").MethodGuard;
9
+ let getExitSubscriber: import("@endo/patterns").MethodGuard;
10
+ }
11
+ export const ZoeUserSeatShape: import("@endo/patterns").InterfaceGuard<{
12
+ tryExit: import("@endo/patterns").MethodGuard;
13
+ getProposal: import("@endo/patterns").MethodGuard;
14
+ getPayouts: import("@endo/patterns").MethodGuard;
15
+ getPayout: import("@endo/patterns").MethodGuard;
16
+ getOfferResult: import("@endo/patterns").MethodGuard;
17
+ hasExited: import("@endo/patterns").MethodGuard;
18
+ numWantsSatisfied: import("@endo/patterns").MethodGuard;
19
+ getFinalAllocation: import("@endo/patterns").MethodGuard;
20
+ getExitSubscriber: import("@endo/patterns").MethodGuard;
21
+ }>;
22
+ export namespace OriginalZoeSeatIKit {
23
+ export let zoeSeatAdmin: import("@endo/patterns").InterfaceGuard<{
24
+ replaceAllocation: import("@endo/patterns").MethodGuard;
25
+ exit: import("@endo/patterns").MethodGuard;
26
+ fail: import("@endo/patterns").MethodGuard;
27
+ resolveExitAndResult: import("@endo/patterns").MethodGuard;
28
+ getExitSubscriber: import("@endo/patterns").MethodGuard;
29
+ finalPayouts: import("@endo/patterns").MethodGuard;
30
+ }>;
31
+ export { ZoeUserSeatShape as userSeat };
32
+ }
33
+ export function declareOldZoeSeatAdminKind(baggage: import("@agoric/vat-data").Baggage, makeDurablePublishKit: () => PublishKit<any>): void;
34
+ //# sourceMappingURL=originalZoeSeat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"originalZoeSeat.d.ts","sourceRoot":"","sources":["originalZoeSeat.js"],"names":[],"mappings":";;;;;;;;;;AA8BA;;;;;;;;;;GAGG;;;;;;;;;;;;AA+CI,oDAHI,OAAO,kBAAkB,EAAE,OAAO,yBAClC,MAAM,UAAU,CAAC,GAAG,CAAC,QAkR/B"}
@@ -0,0 +1,353 @@
1
+ /* eslint @typescript-eslint/no-floating-promises: "warn" */
2
+ import { SubscriberShape } from '@agoric/notifier';
3
+ import { E } from '@endo/eventual-send';
4
+ import { M, prepareExoClassKit } from '@agoric/vat-data';
5
+ import { deeplyFulfilled } from '@endo/marshal';
6
+ import { makePromiseKit } from '@endo/promise-kit';
7
+
8
+ import { satisfiesWant } from '../contractFacet/offerSafety.js';
9
+ import '../types-ambient.js';
10
+ import '../internal-types.js';
11
+ import {
12
+ AmountKeywordRecordShape,
13
+ KeywordShape,
14
+ ExitObjectShape,
15
+ PaymentPKeywordRecordShape,
16
+ } from '../typeGuards.js';
17
+
18
+ const { Fail } = assert;
19
+
20
+ export const coreUserSeatMethods = harden({
21
+ getProposal: M.call().returns(M.promise()),
22
+ getPayouts: M.call().returns(M.promise()),
23
+ getPayout: M.call(KeywordShape).returns(M.promise()),
24
+ getOfferResult: M.call().returns(M.promise()),
25
+ hasExited: M.call().returns(M.promise()),
26
+ numWantsSatisfied: M.call().returns(M.promise()),
27
+ getFinalAllocation: M.call().returns(M.promise()),
28
+ getExitSubscriber: M.call().returns(M.any()),
29
+ });
30
+
31
+ export const ZoeUserSeatShape = M.interface('UserSeat', {
32
+ ...coreUserSeatMethods,
33
+ tryExit: M.call().returns(M.promise()),
34
+ });
35
+
36
+ export const OriginalZoeSeatIKit = harden({
37
+ zoeSeatAdmin: M.interface('ZoeSeatAdmin', {
38
+ replaceAllocation: M.call(AmountKeywordRecordShape).returns(),
39
+ exit: M.call(M.any()).returns(),
40
+ fail: M.call(M.any()).returns(),
41
+ resolveExitAndResult: M.call({
42
+ offerResultPromise: M.promise(),
43
+ exitObj: ExitObjectShape,
44
+ }).returns(),
45
+ getExitSubscriber: M.call().returns(SubscriberShape),
46
+ // The return promise is empty, but doExit relies on settlement as a signal
47
+ // that the payouts have settled. The exit publisher is notified after that.
48
+ finalPayouts: M.call(M.eref(PaymentPKeywordRecordShape)).returns(
49
+ M.promise(),
50
+ ),
51
+ }),
52
+ userSeat: ZoeUserSeatShape,
53
+ });
54
+
55
+ const assertHasNotExited = (c, msg) => {
56
+ !c.state.instanceAdminHelper.hasExited(c.facets.zoeSeatAdmin) ||
57
+ assert(!c.state.instanceAdminHelper.hasExited(c.facets.zoeSeatAdmin), msg);
58
+ };
59
+
60
+ /**
61
+ * declareOldZoeSeatAdminKind declares an exo for the original kind of ZoeSeatKit.
62
+ * This version creates a reference cycle that garbage collection can't remove
63
+ * because it goes through weakMaps in two different Vats. We've defined a new
64
+ * Kind that doesn't have this problem, but we won't upgrade the existing
65
+ * objects, so the Kind must continue to be defined, but we don't return the
66
+ * maker function.
67
+ *
68
+ * The original ZoeSeatKit is an object that manages the state
69
+ * of a seat participating in a Zoe contract and return its two facets.
70
+ *
71
+ * The UserSeat is suitable to be handed to an agent outside zoe and the
72
+ * contract and allows them to query or monitor the current state, access the
73
+ * payouts and result, and call exit() if that's allowed for this seat.
74
+ *
75
+ * The zoeSeatAdmin is passed by Zoe to the ContractFacet (zcf), to allow zcf to
76
+ * query or update the allocation or exit the seat cleanly.
77
+ *
78
+ * @param {import('@agoric/vat-data').Baggage} baggage
79
+ * @param {() => PublishKit<any>} makeDurablePublishKit
80
+ */
81
+ export const declareOldZoeSeatAdminKind = (baggage, makeDurablePublishKit) => {
82
+ const doExit = (
83
+ zoeSeatAdmin,
84
+ currentAllocation,
85
+ withdrawFacet,
86
+ instanceAdminHelper,
87
+ ) => {
88
+ /** @type {PaymentPKeywordRecord} */
89
+ const payouts = withdrawFacet.withdrawPayments(currentAllocation);
90
+ return E.when(
91
+ zoeSeatAdmin.finalPayouts(payouts),
92
+ () => instanceAdminHelper.exitZoeSeatAdmin(zoeSeatAdmin),
93
+ () => instanceAdminHelper.exitZoeSeatAdmin(zoeSeatAdmin),
94
+ );
95
+ };
96
+
97
+ // There is a race between resolveExitAndResult() and getOfferResult() that
98
+ // can be limited to when the adminFactory is paged in. If state.offerResult
99
+ // is defined, getOfferResult will return it. If it's not defined when
100
+ // getOfferResult is called, create a promiseKit, return the promise and store
101
+ // the kit here. When resolveExitAndResult() is called, it saves
102
+ // state.offerResult and resolves the promise if it exists, then removes the
103
+ // table entry.
104
+ /**
105
+ * @typedef {WeakMap<ZCFSeat, unknown>}
106
+ */
107
+ const ephemeralOfferResultStore = new WeakMap();
108
+
109
+ // notice that this returns a maker function which we drop on the floor.
110
+ prepareExoClassKit(
111
+ baggage,
112
+ 'ZoeSeatKit',
113
+ OriginalZoeSeatIKit,
114
+ /**
115
+ *
116
+ * @param {Allocation} initialAllocation
117
+ * @param {ProposalRecord} proposal
118
+ * @param {InstanceAdminHelper} instanceAdminHelper
119
+ * @param {WithdrawFacet} withdrawFacet
120
+ * @param {ERef<ExitObj>} [exitObj]
121
+ * @param {boolean} [offerResultIsUndefined]
122
+ */
123
+ (
124
+ initialAllocation,
125
+ proposal,
126
+ instanceAdminHelper,
127
+ withdrawFacet,
128
+ exitObj = undefined,
129
+ // emptySeatKits start with offerResult validly undefined; others can set
130
+ // it to anything (including undefined) in resolveExitAndResult()
131
+ offerResultIsUndefined = false,
132
+ ) => {
133
+ const { publisher, subscriber } = makeDurablePublishKit();
134
+ return {
135
+ currentAllocation: initialAllocation,
136
+ proposal,
137
+ exitObj,
138
+ offerResult: /** @type {any} */ (undefined),
139
+ offerResultStored: offerResultIsUndefined,
140
+ instanceAdminHelper,
141
+ withdrawFacet,
142
+ publisher,
143
+ subscriber,
144
+ payouts: harden({}),
145
+ exiting: false,
146
+ };
147
+ },
148
+ {
149
+ zoeSeatAdmin: {
150
+ replaceAllocation(replacementAllocation) {
151
+ const { state } = this;
152
+ assertHasNotExited(
153
+ this,
154
+ 'Cannot replace allocation. Seat has already exited',
155
+ );
156
+ harden(replacementAllocation);
157
+ // Merging happens in ZCF, so replacementAllocation can
158
+ // replace the old allocation entirely.
159
+
160
+ state.currentAllocation = replacementAllocation;
161
+ },
162
+ exit(completion) {
163
+ const { state, facets } = this;
164
+ // Since this method doesn't wait, we could re-enter via exitAllSeats.
165
+ // If that happens, we shouldn't re-do any of the work.
166
+ if (state.exiting) {
167
+ return;
168
+ }
169
+ assertHasNotExited(this, 'Cannot exit seat. Seat has already exited');
170
+
171
+ state.exiting = true;
172
+ void E.when(
173
+ doExit(
174
+ facets.zoeSeatAdmin,
175
+ state.currentAllocation,
176
+ state.withdrawFacet,
177
+ state.instanceAdminHelper,
178
+ ),
179
+ () => state.publisher.finish(completion),
180
+ );
181
+ },
182
+ fail(reason) {
183
+ const { state, facets } = this;
184
+ // Since this method doesn't wait, we could re-enter via failAllSeats.
185
+ // If that happens, we shouldn't re-do any of the work.
186
+ if (state.exiting) {
187
+ return;
188
+ }
189
+
190
+ assertHasNotExited(this, 'Cannot fail seat. Seat has already exited');
191
+
192
+ state.exiting = true;
193
+ void E.when(
194
+ doExit(
195
+ facets.zoeSeatAdmin,
196
+ state.currentAllocation,
197
+ state.withdrawFacet,
198
+ state.instanceAdminHelper,
199
+ ),
200
+ () => state.publisher.fail(reason),
201
+ () => state.publisher.fail(reason),
202
+ );
203
+ },
204
+ // called only for seats resulting from offers.
205
+ /** @param {HandleOfferResult} result */
206
+ resolveExitAndResult({ offerResultPromise, exitObj }) {
207
+ const { state, facets } = this;
208
+
209
+ !state.offerResultStored ||
210
+ Fail`offerResultStored before offerResultPromise`;
211
+
212
+ if (!ephemeralOfferResultStore.has(facets.userSeat)) {
213
+ // this was called before getOfferResult
214
+ const kit = makePromiseKit();
215
+ kit.resolve(offerResultPromise);
216
+ ephemeralOfferResultStore.set(facets.userSeat, kit);
217
+ }
218
+
219
+ const pKit = ephemeralOfferResultStore.get(facets.userSeat);
220
+ void E.when(
221
+ offerResultPromise,
222
+ offerResult => {
223
+ // Resolve the ephemeral promise for offerResult
224
+ pKit.resolve(offerResult);
225
+ // Now we want to store the offerResult in `state` to get it off the heap,
226
+ // but we need to handle three cases:
227
+ // 1. already durable. (This includes being a remote presence.)
228
+ // 2. has promises for durable objects.
229
+ // 3. not durable even after resolving promises.
230
+ // For #1 we can assign directly, but we deeply await to also handle #2.
231
+ void E.when(
232
+ deeplyFulfilled(offerResult),
233
+ fulfilledOfferResult => {
234
+ try {
235
+ // In cases 1-2 this assignment will succeed.
236
+ state.offerResult = fulfilledOfferResult;
237
+ // If it doesn't, then these lines won't be reached so the
238
+ // flag will stay false and the promise will stay in the heap
239
+ state.offerResultStored = true;
240
+ ephemeralOfferResultStore.delete(facets.userSeat);
241
+ } catch (err) {
242
+ console.warn(
243
+ 'non-durable offer result will be lost upon zoe vat termination:',
244
+ offerResult,
245
+ );
246
+ }
247
+ },
248
+ // no rejection handler because an offer result containing promises that reject
249
+ // is within spec
250
+ );
251
+ },
252
+ e => {
253
+ pKit.reject(e);
254
+ // NB: leave the rejected promise in the ephemeralOfferResultStore
255
+ // because it can't go in durable state
256
+ },
257
+ );
258
+
259
+ state.exitObj = exitObj;
260
+ },
261
+ getExitSubscriber() {
262
+ const { state } = this;
263
+ return state.subscriber;
264
+ },
265
+ async finalPayouts(payments) {
266
+ const { state } = this;
267
+
268
+ const settledPayouts = await deeplyFulfilled(payments);
269
+ state.payouts = settledPayouts;
270
+ },
271
+ },
272
+ userSeat: {
273
+ async getProposal() {
274
+ const { state } = this;
275
+ return state.proposal;
276
+ },
277
+ async getPayouts() {
278
+ const { state } = this;
279
+
280
+ return E.when(
281
+ state.subscriber.subscribeAfter(),
282
+ () => state.payouts,
283
+ () => state.payouts,
284
+ );
285
+ },
286
+ async getPayout(keyword) {
287
+ const { state } = this;
288
+
289
+ // subscriber.subscribeAfter() only triggers after publisher.finish()
290
+ // in exit() or publisher.fail() in fail(). Both of those wait for
291
+ // doExit(), which ensures that finalPayouts() has set state.payouts.
292
+ return E.when(
293
+ state.subscriber.subscribeAfter(),
294
+ () => state.payouts[keyword],
295
+ () => state.payouts[keyword],
296
+ );
297
+ },
298
+
299
+ async getOfferResult() {
300
+ const { state, facets } = this;
301
+
302
+ if (state.offerResultStored) {
303
+ return state.offerResult;
304
+ }
305
+
306
+ if (ephemeralOfferResultStore.has(facets.userSeat)) {
307
+ return ephemeralOfferResultStore.get(facets.userSeat).promise;
308
+ }
309
+
310
+ const kit = makePromiseKit();
311
+ ephemeralOfferResultStore.set(facets.userSeat, kit);
312
+ return kit.promise;
313
+ },
314
+ async hasExited() {
315
+ const { state, facets } = this;
316
+
317
+ return (
318
+ state.exiting ||
319
+ state.instanceAdminHelper.hasExited(facets.zoeSeatAdmin)
320
+ );
321
+ },
322
+ async tryExit() {
323
+ const { state } = this;
324
+ if (!state.exitObj)
325
+ throw Fail`exitObj must be initialized before use`;
326
+ assertHasNotExited(this, 'Cannot exit; seat has already exited');
327
+
328
+ return E(state.exitObj).exit();
329
+ },
330
+ async numWantsSatisfied() {
331
+ const { state } = this;
332
+ return E.when(
333
+ state.subscriber.subscribeAfter(),
334
+ () => satisfiesWant(state.proposal, state.currentAllocation),
335
+ () => satisfiesWant(state.proposal, state.currentAllocation),
336
+ );
337
+ },
338
+ getExitSubscriber() {
339
+ const { state } = this;
340
+ return state.subscriber;
341
+ },
342
+ getFinalAllocation() {
343
+ const { state } = this;
344
+ return E.when(
345
+ state.subscriber.subscribeAfter(),
346
+ () => state.currentAllocation,
347
+ () => state.currentAllocation,
348
+ );
349
+ },
350
+ },
351
+ },
352
+ );
353
+ };
@@ -1,4 +1,4 @@
1
- export function makeStartInstance(startInstanceAccess: Pick<ZoeStorageManager, 'makeZoeInstanceStorageManager' | 'unwrapInstallation'>, getZcfBundleCapP: () => ERef<BundleCap>, getBundleCapByIdNow: (id: string) => BundleCap, zoeBaggage: MapStore<string, unknown>): import('./utils').StartInstance;
2
- export type Baggage = import('@agoric/vat-data').Baggage;
3
- export type BundleCap = import('@agoric/swingset-vat').BundleCap;
1
+ export function makeStartInstance(startInstanceAccess: Pick<ZoeStorageManager, "makeZoeInstanceStorageManager" | "unwrapInstallation">, getZcfBundleCapP: () => ERef<BundleCap>, getBundleCapByIdNow: (id: string) => BundleCap, zoeBaggage: Baggage): import("./utils.js").StartInstance;
2
+ export type BundleCap = import("@agoric/swingset-vat").BundleCap;
3
+ import type { Baggage } from '@agoric/vat-data';
4
4
  //# sourceMappingURL=startInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"startInstance.d.ts","sourceRoot":"","sources":["startInstance.js"],"names":[],"mappings":"AA0BO,uDANI,KAAK,iBAAiB,EAAE,+BAA+B,GAAG,oBAAoB,CAAC,oBAC/E,MAAM,KAAK,SAAS,CAAC,4BAChB,MAAM,KAAK,SAAS,0CAEvB,OAAO,SAAS,EAAE,aAAa,CAmU3C;sBA7Ua,OAAO,kBAAkB,EAAE,OAAO;wBACjC,OAAO,sBAAsB,EAAE,SAAS"}
1
+ {"version":3,"file":"startInstance.d.ts","sourceRoot":"","sources":["startInstance.js"],"names":[],"mappings":"AAoCO,uDANI,IAAI,CAAC,iBAAiB,EAAE,+BAA+B,GAAG,oBAAoB,CAAC,oBAC/E,MAAM,IAAI,CAAC,SAAS,CAAC,uBACrB,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,cACzB,OAAO,GACL,OAAO,YAAY,EAAE,aAAa,CAsW9C;wBA/Wc,OAAO,sBAAsB,EAAE,SAAS;6BAD5B,kBAAkB"}