@agoric/inter-protocol 0.16.2-other-dev-1f26562.0 → 0.16.2-other-dev-3eb1a1d.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 (191) hide show
  1. package/README.md +6 -6
  2. package/package.json +42 -36
  3. package/scripts/build-bundles.js +5 -21
  4. package/src/auction/auctionBook.d.ts +147 -0
  5. package/src/auction/auctionBook.d.ts.map +1 -0
  6. package/src/auction/auctionBook.js +156 -150
  7. package/src/auction/auctionMath.d.ts +17 -0
  8. package/src/auction/auctionMath.d.ts.map +1 -0
  9. package/src/auction/auctionMath.js +81 -0
  10. package/src/auction/auctioneer.d.ts +69 -0
  11. package/src/auction/auctioneer.d.ts.map +1 -0
  12. package/src/auction/auctioneer.js +70 -59
  13. package/src/auction/offerBook.d.ts +45 -0
  14. package/src/auction/offerBook.d.ts.map +1 -0
  15. package/src/auction/offerBook.js +13 -12
  16. package/src/auction/params.d.ts +144 -0
  17. package/src/auction/params.d.ts.map +1 -0
  18. package/src/auction/params.js +10 -9
  19. package/src/auction/scheduleMath.d.ts +5 -0
  20. package/src/auction/scheduleMath.d.ts.map +1 -0
  21. package/src/auction/scheduleMath.js +18 -16
  22. package/src/auction/scheduler.d.ts +50 -0
  23. package/src/auction/scheduler.d.ts.map +1 -0
  24. package/src/auction/scheduler.js +53 -47
  25. package/src/auction/sortedOffers.d.ts +8 -0
  26. package/src/auction/sortedOffers.d.ts.map +1 -0
  27. package/src/auction/sortedOffers.js +10 -9
  28. package/src/auction/util.d.ts +30 -0
  29. package/src/auction/util.d.ts.map +1 -0
  30. package/src/auction/util.js +9 -6
  31. package/src/clientSupport.d.ts +167 -0
  32. package/src/clientSupport.d.ts.map +1 -0
  33. package/src/clientSupport.js +155 -97
  34. package/src/collectFees.d.ts +2 -0
  35. package/src/collectFees.d.ts.map +1 -0
  36. package/src/contractSupport.d.ts +28 -0
  37. package/src/contractSupport.d.ts.map +1 -0
  38. package/src/contractSupport.js +19 -13
  39. package/src/econCommitteeCharter.d.ts +40 -0
  40. package/src/econCommitteeCharter.d.ts.map +1 -0
  41. package/src/econCommitteeCharter.js +21 -20
  42. package/src/feeDistributor.d.ts +224 -0
  43. package/src/feeDistributor.d.ts.map +1 -0
  44. package/src/feeDistributor.js +37 -33
  45. package/src/index.d.ts +2 -0
  46. package/src/index.d.ts.map +1 -0
  47. package/src/index.js +1 -0
  48. package/src/interest-math.d.ts +3 -0
  49. package/src/interest-math.d.ts.map +1 -0
  50. package/src/interest.d.ts +28 -0
  51. package/src/interest.d.ts.map +1 -0
  52. package/src/interest.js +23 -18
  53. package/src/price/README.md +13 -0
  54. package/src/price/fluxAggregatorContract.d.ts +71 -0
  55. package/src/price/fluxAggregatorContract.d.ts.map +1 -0
  56. package/src/price/fluxAggregatorContract.js +64 -55
  57. package/src/price/fluxAggregatorKit.d.ts +103 -0
  58. package/src/price/fluxAggregatorKit.d.ts.map +1 -0
  59. package/src/price/fluxAggregatorKit.js +52 -40
  60. package/src/price/priceOracleKit.d.ts +38 -0
  61. package/src/price/priceOracleKit.d.ts.map +1 -0
  62. package/src/price/priceOracleKit.js +12 -14
  63. package/src/price/roundsManager.d.ts +204 -0
  64. package/src/price/roundsManager.d.ts.map +1 -0
  65. package/src/price/roundsManager.js +131 -85
  66. package/src/proposals/README.md +2 -3
  67. package/src/proposals/add-auction.d.ts +109 -0
  68. package/src/proposals/add-auction.d.ts.map +1 -0
  69. package/src/proposals/add-auction.js +256 -0
  70. package/src/proposals/addAssetToVault.d.ts +173 -0
  71. package/src/proposals/addAssetToVault.d.ts.map +1 -0
  72. package/src/proposals/addAssetToVault.js +192 -40
  73. package/src/proposals/committee-proposal.d.ts +113 -0
  74. package/src/proposals/committee-proposal.d.ts.map +1 -0
  75. package/src/proposals/committee-proposal.js +25 -31
  76. package/src/proposals/core-proposal.d.ts +149 -0
  77. package/src/proposals/core-proposal.d.ts.map +1 -0
  78. package/src/proposals/core-proposal.js +9 -11
  79. package/src/proposals/deploy-price-feeds.d.ts +76 -0
  80. package/src/proposals/deploy-price-feeds.d.ts.map +1 -0
  81. package/src/proposals/deploy-price-feeds.js +316 -0
  82. package/src/proposals/econ-behaviors.d.ts +541 -0
  83. package/src/proposals/econ-behaviors.d.ts.map +1 -0
  84. package/src/proposals/econ-behaviors.js +64 -45
  85. package/src/proposals/price-feed-proposal.d.ts +84 -0
  86. package/src/proposals/price-feed-proposal.d.ts.map +1 -0
  87. package/src/proposals/price-feed-proposal.js +109 -51
  88. package/src/proposals/replace-fee-distributor.d.ts +48 -0
  89. package/src/proposals/replace-fee-distributor.d.ts.map +1 -0
  90. package/src/proposals/replace-fee-distributor.js +195 -0
  91. package/src/proposals/replace-scaledPriceAuthorities.d.ts +30 -0
  92. package/src/proposals/replace-scaledPriceAuthorities.d.ts.map +1 -0
  93. package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
  94. package/src/proposals/replaceElectorate.d.ts +55 -0
  95. package/src/proposals/replaceElectorate.d.ts.map +1 -0
  96. package/src/proposals/replaceElectorate.js +521 -0
  97. package/src/proposals/startEconCommittee.d.ts +34 -0
  98. package/src/proposals/startEconCommittee.d.ts.map +1 -0
  99. package/src/proposals/startEconCommittee.js +2 -2
  100. package/src/proposals/startPSM.d.ts +59 -0
  101. package/src/proposals/startPSM.d.ts.map +1 -0
  102. package/src/proposals/startPSM.js +44 -29
  103. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts +24 -0
  104. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts.map +1 -0
  105. package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
  106. package/src/proposals/upgrade-vaults.d.ts +41 -0
  107. package/src/proposals/upgrade-vaults.d.ts.map +1 -0
  108. package/src/proposals/upgrade-vaults.js +202 -0
  109. package/src/proposals/utils.d.ts +19 -0
  110. package/src/proposals/utils.d.ts.map +1 -0
  111. package/src/proposals/utils.js +43 -9
  112. package/src/provisionPool.d.ts +163 -0
  113. package/src/provisionPool.d.ts.map +1 -0
  114. package/src/provisionPool.js +122 -0
  115. package/src/provisionPoolKit.d.ts +359 -0
  116. package/src/provisionPoolKit.d.ts.map +1 -0
  117. package/src/provisionPoolKit.js +522 -0
  118. package/src/psm/psm.d.ts +125 -0
  119. package/src/psm/psm.d.ts.map +1 -0
  120. package/src/psm/psm.js +80 -79
  121. package/src/psm/types-ambient.d.ts +2 -0
  122. package/src/psm/types-ambient.d.ts.map +1 -0
  123. package/src/psm/types-ambient.js +3 -0
  124. package/src/reserve/assetReserve.d.ts +47 -0
  125. package/src/reserve/assetReserve.d.ts.map +1 -0
  126. package/src/reserve/assetReserve.js +28 -19
  127. package/src/reserve/assetReserveKit.d.ts +74 -0
  128. package/src/reserve/assetReserveKit.d.ts.map +1 -0
  129. package/src/reserve/assetReserveKit.js +24 -30
  130. package/src/reserve/params.d.ts +10 -0
  131. package/src/reserve/params.d.ts.map +1 -0
  132. package/src/tokens.d.ts +3 -0
  133. package/src/tokens.d.ts.map +1 -0
  134. package/src/tokens.js +5 -0
  135. package/src/vaultFactory/burn.d.ts +2 -0
  136. package/src/vaultFactory/burn.d.ts.map +1 -0
  137. package/src/vaultFactory/burn.js +1 -1
  138. package/src/vaultFactory/liquidation.d.ts +23 -0
  139. package/src/vaultFactory/liquidation.d.ts.map +1 -0
  140. package/src/vaultFactory/liquidation.js +37 -24
  141. package/src/vaultFactory/math.d.ts +11 -0
  142. package/src/vaultFactory/math.d.ts.map +1 -0
  143. package/src/vaultFactory/math.js +10 -9
  144. package/src/vaultFactory/orderedVaultStore.d.ts +93 -0
  145. package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
  146. package/src/vaultFactory/orderedVaultStore.js +8 -11
  147. package/src/vaultFactory/params.d.ts +140 -0
  148. package/src/vaultFactory/params.d.ts.map +1 -0
  149. package/src/vaultFactory/params.js +52 -24
  150. package/src/vaultFactory/prioritizedVaults.d.ts +279 -0
  151. package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
  152. package/src/vaultFactory/prioritizedVaults.js +4 -4
  153. package/src/vaultFactory/proceeds.d.ts +35 -0
  154. package/src/vaultFactory/proceeds.d.ts.map +1 -0
  155. package/src/vaultFactory/proceeds.js +26 -18
  156. package/src/vaultFactory/storeUtils.d.ts +25 -0
  157. package/src/vaultFactory/storeUtils.d.ts.map +1 -0
  158. package/src/vaultFactory/storeUtils.js +10 -12
  159. package/src/vaultFactory/types-ambient.d.ts +137 -0
  160. package/src/vaultFactory/types-ambient.d.ts.map +1 -0
  161. package/src/vaultFactory/{types.js → types-ambient.js} +42 -42
  162. package/src/vaultFactory/vault.d.ts +343 -0
  163. package/src/vaultFactory/vault.d.ts.map +1 -0
  164. package/src/vaultFactory/vault.js +105 -99
  165. package/src/vaultFactory/vaultDirector.d.ts +341 -0
  166. package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
  167. package/src/vaultFactory/vaultDirector.js +86 -64
  168. package/src/vaultFactory/vaultFactory.d.ts +202 -0
  169. package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
  170. package/src/vaultFactory/vaultFactory.js +52 -33
  171. package/src/vaultFactory/vaultHolder.d.ts +126 -0
  172. package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
  173. package/src/vaultFactory/vaultHolder.js +11 -16
  174. package/src/vaultFactory/vaultKit.d.ts +32 -0
  175. package/src/vaultFactory/vaultKit.d.ts.map +1 -0
  176. package/src/vaultFactory/vaultKit.js +5 -4
  177. package/src/vaultFactory/vaultManager.d.ts +674 -0
  178. package/src/vaultFactory/vaultManager.d.ts.map +1 -0
  179. package/src/vaultFactory/vaultManager.js +257 -158
  180. package/CHANGELOG.md +0 -1041
  181. package/exported.js +0 -2
  182. package/scripts/add-collateral-core.js +0 -112
  183. package/scripts/deploy-contracts.js +0 -100
  184. package/scripts/init-core.js +0 -198
  185. package/scripts/invite-committee-core.js +0 -42
  186. package/scripts/manual-price-feed.js +0 -117
  187. package/scripts/price-feed-core.js +0 -104
  188. package/scripts/start-local-chain.sh +0 -84
  189. package/src/psm/types.js +0 -3
  190. package/src/typeGuards.js +0 -13
  191. package/src/vaultFactory/type-imports.js +0 -4
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- import { Fail } from '@agoric/assert';
3
+ import { Fail } from '@endo/errors';
4
4
  import { AmountMath } from '@agoric/ertp';
5
5
  import { assertAllDefined } from '@agoric/internal';
6
6
  import { parseRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
@@ -15,23 +15,31 @@ const scaleDecimals = num => BigInt(num * Number(COSMOS_UNIT));
15
15
  /**
16
16
  * Give/want
17
17
  *
18
- * @param {Record<string, Brand>} brands
19
- * @param {{ giveMinted?: number, wantMinted?: number } | { collateralBrandKey: string, giveCollateral?: number, wantCollateral?: number }} opts
18
+ * @param {Pick<
19
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
20
+ * 'brand'
21
+ * >} agoricNames
22
+ * @param {{ giveMinted?: number; wantMinted?: number }
23
+ * | {
24
+ * collateralBrandKey: string;
25
+ * giveCollateral?: number;
26
+ * wantCollateral?: number;
27
+ * }} opts
20
28
  * @returns {Proposal}
21
29
  */
22
- const makeVaultProposal = (brands, opts) => {
30
+ const makeVaultProposal = ({ brand }, opts) => {
23
31
  const proposal = { give: {}, want: {} };
24
32
 
25
33
  if ('giveCollateral' in opts && opts.giveCollateral) {
26
34
  const { collateralBrandKey } = opts;
27
35
  proposal.give.Collateral = {
28
- brand: brands[collateralBrandKey],
36
+ brand: brand[collateralBrandKey],
29
37
  value: scaleDecimals(opts.giveCollateral),
30
38
  };
31
39
  }
32
40
  if ('giveMinted' in opts && opts.giveMinted) {
33
41
  proposal.give.Minted = {
34
- brand: brands.IST,
42
+ brand: brand.IST,
35
43
  value: scaleDecimals(opts.giveMinted),
36
44
  };
37
45
  }
@@ -39,13 +47,13 @@ const makeVaultProposal = (brands, opts) => {
39
47
  if ('wantCollateral' in opts && opts.wantCollateral) {
40
48
  const { collateralBrandKey } = opts;
41
49
  proposal.want.Collateral = {
42
- brand: brands[collateralBrandKey],
50
+ brand: brand[collateralBrandKey],
43
51
  value: scaleDecimals(opts.wantCollateral),
44
52
  };
45
53
  }
46
54
  if ('wantMinted' in opts && opts.wantMinted) {
47
55
  proposal.want.Minted = {
48
- brand: brands.IST,
56
+ brand: brand.IST,
49
57
  value: scaleDecimals(opts.wantMinted),
50
58
  };
51
59
  }
@@ -54,18 +62,26 @@ const makeVaultProposal = (brands, opts) => {
54
62
  };
55
63
 
56
64
  /**
57
- * @param {Record<string, Brand>} brands
58
- * @param {{ offerId: string, wantMinted: number, giveCollateral: number, collateralBrandKey: string }} opts
65
+ * @param {Pick<
66
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
67
+ * 'brand'
68
+ * >} agoricNames
69
+ * @param {{
70
+ * offerId: string;
71
+ * wantMinted: number;
72
+ * giveCollateral: number;
73
+ * collateralBrandKey: string;
74
+ * }} opts
59
75
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
60
76
  */
61
- const makeOpenOffer = (brands, opts) => {
62
- const proposal = makeVaultProposal(brands, opts);
77
+ const makeOpenOffer = ({ brand }, opts) => {
78
+ const proposal = makeVaultProposal({ brand }, opts);
63
79
 
64
80
  // NB: not really a Proposal because the brands are not remotes
65
81
  // Instead they're copyRecord like "{"boardId":"board0257","iface":"Alleged: IST brand"}" to pass through the boardId
66
82
  // mustMatch(harden(proposal), ProposalShape);
67
83
 
68
- const collateralBrand = brands[opts.collateralBrandKey];
84
+ const collateralBrand = brand[opts.collateralBrandKey];
69
85
 
70
86
  return {
71
87
  id: opts.offerId,
@@ -82,16 +98,26 @@ const makeOpenOffer = (brands, opts) => {
82
98
  };
83
99
 
84
100
  /**
85
- * @param {Record<string, Brand>} brands
86
- * @param {{ offerId: string, collateralBrandKey?: string, giveCollateral?: number, wantCollateral?: number, giveMinted?: number, wantMinted?: number }} opts
101
+ * @param {Pick<
102
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
103
+ * 'brand'
104
+ * >} agoricNames
105
+ * @param {{
106
+ * offerId: string;
107
+ * collateralBrandKey?: string;
108
+ * giveCollateral?: number;
109
+ * wantCollateral?: number;
110
+ * giveMinted?: number;
111
+ * wantMinted?: number;
112
+ * }} opts
87
113
  * @param {string} previousOffer
88
114
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
89
115
  */
90
- const makeAdjustOffer = (brands, opts, previousOffer) => {
116
+ const makeAdjustOffer = ({ brand }, opts, previousOffer) => {
91
117
  // NB: not really a Proposal because the brands are not remotes
92
118
  // Instead they're copyRecord like "{"boardId":"board0257","iface":"Alleged: IST brand"}" to pass through the boardId
93
119
  // mustMatch(harden(proposal), ProposalShape);
94
- const proposal = makeVaultProposal(brands, opts);
120
+ const proposal = makeVaultProposal({ brand }, opts);
95
121
 
96
122
  return {
97
123
  id: opts.offerId,
@@ -105,13 +131,20 @@ const makeAdjustOffer = (brands, opts, previousOffer) => {
105
131
  };
106
132
 
107
133
  /**
108
- * @param {Record<string, Brand>} brands
109
- * @param {{ offerId: string, collateralBrandKey?: string, giveMinted: number }} opts
134
+ * @param {Pick<
135
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
136
+ * 'brand'
137
+ * >} agoricNames
138
+ * @param {{
139
+ * offerId: string;
140
+ * collateralBrandKey?: string;
141
+ * giveMinted: number;
142
+ * }} opts
110
143
  * @param {string} previousOffer
111
144
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
112
145
  */
113
- const makeCloseOffer = (brands, opts, previousOffer) => {
114
- const proposal = makeVaultProposal(brands, opts);
146
+ const makeCloseOffer = ({ brand }, opts, previousOffer) => {
147
+ const proposal = makeVaultProposal({ brand }, opts);
115
148
 
116
149
  return {
117
150
  id: opts.offerId,
@@ -126,7 +159,9 @@ const makeCloseOffer = (brands, opts, previousOffer) => {
126
159
 
127
160
  /**
128
161
  * @param {string} vaultId
129
- * @param {Promise<import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord>} currentP
162
+ * @param {Promise<
163
+ * import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord
164
+ * >} currentP
130
165
  * @returns {Promise<string>} offer id in which the vault was made
131
166
  */
132
167
  export const lookupOfferIdForVault = async (vaultId, currentP) => {
@@ -141,11 +176,14 @@ export const lookupOfferIdForVault = async (vaultId, currentP) => {
141
176
  };
142
177
 
143
178
  /**
144
- * @param {Record<string, Brand>} brands
145
- * @param {({ wantMinted: number, giveMinted?: undefined } | { giveMinted: number, wantMinted?: undefined })} opts
146
- * @param {number} [fee=0]
179
+ * @param {Record<
180
+ * string,
181
+ * import('@agoric/internal/src/marshal.js').BoardRemote
182
+ * >} brands
183
+ * @param {{ wantMinted: number; giveMinted?: undefined }
184
+ * | { giveMinted: number; wantMinted?: undefined }} opts
185
+ * @param {number} [fee]
147
186
  * @param {string} [anchor]
148
- * @returns {Proposal} XXX not a real proposal, uses BoardRemote
149
187
  */
150
188
  const makePsmProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
151
189
  const giving = 'giveMinted' in opts ? 'minted' : 'anchor';
@@ -171,19 +209,24 @@ const makePsmProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
171
209
  };
172
210
 
173
211
  /**
212
+ * @param {Pick<
213
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
214
+ * 'brand'
215
+ * >} agoricNames
174
216
  * @param {Instance} instance
175
- * @param {Record<string, Brand>} brands
176
- * @param {{ offerId: string, feePct?: number, pair: [string, string] } &
177
- * ({ wantMinted: number } | { giveMinted: number })} opts
217
+ * @param {{ offerId: string; feePct?: number; pair: [string, string] } & (
218
+ * | { wantMinted: number }
219
+ * | { giveMinted: number }
220
+ * )} opts
178
221
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
179
222
  */
180
- const makePsmSwapOffer = (instance, brands, opts) => {
223
+ const makePsmSwapOffer = ({ brand }, instance, opts) => {
181
224
  const method =
182
225
  'wantMinted' in opts
183
226
  ? 'makeWantMintedInvitation'
184
227
  : 'makeGiveMintedInvitation'; // ref psm.js
185
228
  const proposal = makePsmProposal(
186
- brands,
229
+ brand,
187
230
  opts,
188
231
  opts.feePct ? opts.feePct / 100 : undefined,
189
232
  opts.pair[1],
@@ -200,33 +243,81 @@ const makePsmSwapOffer = (instance, brands, opts) => {
200
243
  instance,
201
244
  publicInvitationMaker: method,
202
245
  },
246
+ // @ts-expect-error BoardRemote not a Brand object
203
247
  proposal,
204
248
  };
205
249
  };
206
250
 
207
251
  /**
208
- * @param {Record<string, Brand>} _brands
252
+ * @param {Pick<
253
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
254
+ * 'brand' | 'vbankAsset'
255
+ * >} agoricNames
256
+ * @param {(msg: string) => Error} makeError error constructor
257
+ * @returns {(a: string) => Amount<'nat'>}
258
+ */
259
+ export const makeParseAmount =
260
+ (agoricNames, makeError = msg => RangeError(msg)) =>
261
+ opt => {
262
+ assert.typeof(opt, 'string', 'parseAmount expected string');
263
+ const m = opt.match(
264
+ /^(?<value>[\d_]+(?:\.[\d_]+)?)\s*(?<brand>[A-Za-z]\w*)$/,
265
+ );
266
+ if (!m || !m.groups) {
267
+ throw makeError(`invalid amount: ${opt}`);
268
+ }
269
+ const anyBrand = agoricNames.brand[m.groups.brand];
270
+ if (!anyBrand) {
271
+ throw makeError(`unknown brand: ${m.groups.brand}`);
272
+ }
273
+ const assetDesc = Object.values(agoricNames.vbankAsset).find(
274
+ d => d.brand === anyBrand,
275
+ );
276
+ if (!assetDesc) {
277
+ throw makeError(`unknown brand: ${m.groups.brand}`);
278
+ }
279
+ const { displayInfo } = assetDesc;
280
+ if (!displayInfo.decimalPlaces || displayInfo.assetKind !== 'nat') {
281
+ throw makeError(`bad brand: ${displayInfo}`);
282
+ }
283
+ const value = BigInt(
284
+ Number(m.groups.value.replace(/_/g, '')) *
285
+ 10 ** displayInfo.decimalPlaces,
286
+ );
287
+ /** @type {Brand<'nat'>} */
288
+ // @ts-expect-error dynamic cast
289
+ const natBrand = anyBrand;
290
+ const amt = { value, brand: natBrand };
291
+ return amt;
292
+ };
293
+
294
+ /**
295
+ * @param {Pick<
296
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
297
+ * 'brand' | 'vbankAsset'
298
+ * >} agoricNames
209
299
  * @param {{
210
- * offerId: string,
211
- * give: string,
212
- * maxBuy: string,
213
- * wantMinimum?: string,
214
- * parseAmount: (x: string) => Amount<'nat'>,
215
- * } & ({
216
- * price: number,
217
- * } | {
218
- * discount: number, // -1 to 1. e.g. 0.10 for 10% discount, -0.05 for 5% markup
219
- * })} opts
300
+ * offerId: string;
301
+ * give: string;
302
+ * maxBuy: string;
303
+ * wantMinimum?: string;
304
+ * } & (
305
+ * | {
306
+ * price: number;
307
+ * }
308
+ * | {
309
+ * discount: number; // -1 to 1. e.g. 0.10 for 10% discount, -0.05 for 5% markup
310
+ * }
311
+ * )} opts
220
312
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
221
313
  */
222
- const makeBidOffer = (_brands, opts) => {
223
- assert.typeof(opts.parseAmount, 'function');
314
+ const makeBidOffer = (agoricNames, opts) => {
224
315
  assertAllDefined({
225
316
  offerId: opts.offerId,
226
317
  give: opts.give,
227
318
  maxBuy: opts.maxBuy,
228
319
  });
229
- const { parseAmount } = opts;
320
+ const parseAmount = makeParseAmount(agoricNames);
230
321
  const proposal = {
231
322
  give: { Bid: parseAmount(opts.give) },
232
323
  ...(opts.wantMinimum
@@ -276,19 +367,23 @@ const makeBidOffer = (_brands, opts) => {
276
367
  };
277
368
 
278
369
  /**
279
- * @param {Record<string, Brand>} brands
370
+ * @param {Pick<
371
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
372
+ * 'brand'
373
+ * >} agoricNames
280
374
  * @param {{
281
- * offerId: string,
282
- * give: number,
283
- * collateralBrandKey: string,
375
+ * offerId: string;
376
+ * give: number;
377
+ * collateralBrandKey: string;
284
378
  * }} opts
285
379
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
286
380
  */
287
- const makeAddCollateralOffer = (brands, opts) => {
381
+ const makeAddCollateralOffer = ({ brand }, opts) => {
288
382
  /** @type {AmountKeywordRecord} */
289
383
  const give = {
290
384
  Collateral: AmountMath.make(
291
- brands[opts.collateralBrandKey],
385
+ // @ts-expect-error BoardRemote not a Brand object
386
+ brand[opts.collateralBrandKey],
292
387
  scaleDecimals(opts.give),
293
388
  ),
294
389
  };
@@ -307,17 +402,16 @@ const makeAddCollateralOffer = (brands, opts) => {
307
402
  };
308
403
 
309
404
  /**
310
- *
311
- * @param {Record<string, Brand>} _brands
405
+ * @param {unknown} _agoricNames
312
406
  * @param {{
313
- * offerId: string,
314
- * roundId?: bigint,
315
- * unitPrice: bigint,
407
+ * offerId: string;
408
+ * roundId?: bigint;
409
+ * unitPrice: bigint;
316
410
  * }} opts
317
411
  * @param {string} previousOffer
318
412
  * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
319
413
  */
320
- const makePushPriceOffer = (_brands, opts, previousOffer) => {
414
+ const makePushPriceOffer = (_agoricNames, opts, previousOffer) => {
321
415
  return {
322
416
  id: opts.offerId,
323
417
  invitationSpec: {
@@ -332,48 +426,12 @@ const makePushPriceOffer = (_brands, opts, previousOffer) => {
332
426
  };
333
427
  };
334
428
 
335
- // TODO DRY with CLI wallet.js
336
429
  /**
337
- * @param {{
338
- * brand: Record<string, Brand>,
339
- * vbankAsset: Record<string, { brand: Brand, displayInfo: DisplayInfo }>,
340
- * }} agoricNames
341
- * @param {(msg: string) => Error} makeError error constructor
342
- * @returns {(a: string) => Amount<'nat'>}
430
+ * @satisfies {Record<
431
+ * string,
432
+ * Record<string, import('@agoric/smart-wallet/src/types.js').OfferMaker>
433
+ * >}
343
434
  */
344
- export const makeParseAmount =
345
- (agoricNames, makeError = msg => RangeError(msg)) =>
346
- opt => {
347
- assert.typeof(opt, 'string', 'parseAmount expected string');
348
- const m = opt.match(/^(?<value>[\d_]+(\.[\d_]+)?)(?<brand>[A-Z]\w*?)$/);
349
- if (!m || !m.groups) {
350
- throw makeError(`invalid amount: ${opt}`);
351
- }
352
- const anyBrand = agoricNames.brand[m.groups.brand];
353
- if (!anyBrand) {
354
- throw makeError(`unknown brand: ${m.groups.brand}`);
355
- }
356
- const assetDesc = Object.values(agoricNames.vbankAsset).find(
357
- d => d.brand === anyBrand,
358
- );
359
- if (!assetDesc) {
360
- throw makeError(`unknown brand: ${m.groups.brand}`);
361
- }
362
- const { displayInfo } = assetDesc;
363
- if (!displayInfo.decimalPlaces || displayInfo.assetKind !== 'nat') {
364
- throw makeError(`bad brand: ${displayInfo}`);
365
- }
366
- const value = BigInt(
367
- Number(m.groups.value.replace(/_/g, '')) *
368
- 10 ** displayInfo.decimalPlaces,
369
- );
370
- /** @type {Brand<'nat'>} */
371
- // @ts-expect-error dynamic cast
372
- const natBrand = anyBrand;
373
- const amt = { value, brand: natBrand };
374
- return amt;
375
- };
376
-
377
435
  export const Offers = {
378
436
  auction: {
379
437
  Bid: makeBidOffer,
@@ -0,0 +1,2 @@
1
+ export function makeCollectFeesInvitation(zcf: ZCF, feeSeat: ZCFSeat, feeBrand: Brand, keyword: string): Promise<Invitation<string>>;
2
+ //# sourceMappingURL=collectFees.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectFees.d.ts","sourceRoot":"","sources":["collectFees.js"],"names":[],"mappings":"AAaO,+CANI,GAAG,WACH,OAAO,YACP,KAAK,WACL,MAAM,GACJ,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAYvC"}
@@ -0,0 +1,28 @@
1
+ export namespace amountPattern {
2
+ let brand: import("@endo/patterns").Matcher;
3
+ let value: import("@endo/patterns").Matcher;
4
+ }
5
+ export namespace ratioPattern {
6
+ export { amountPattern as numerator };
7
+ export { amountPattern as denominator };
8
+ }
9
+ export function addSubtract<A extends Amount>(base: A, gain: A, loss: A): A;
10
+ export function subtractToEmpty<T extends Amount>(left: T, right: T): T;
11
+ export function assertOnlyKeys(proposal: ProposalRecord, keys: string[]): void;
12
+ export function allEmpty(amounts: Amount[]): boolean;
13
+ export function checkDebtLimit(debtLimit: Amount<"nat">, totalDebt: Amount<"nat">, toMint: Amount<"nat">): void;
14
+ export function makeNatAmountShape(brand: Brand, min?: bigint | undefined): {
15
+ brand: globalThis.Brand;
16
+ value: import("@endo/patterns").Matcher;
17
+ };
18
+ export function quoteAsRatio(quoteAmount: Pick<PriceDescription, "amountIn" | "amountOut">): Ratio;
19
+ export type MetricsPublisherKit<T> = {
20
+ metricsPublication: IterationObserver<T>;
21
+ metricsSubscription: StoredSubscription<T>;
22
+ };
23
+ export type MetricsPublishKit<T> = {
24
+ metricsPublisher: Publisher<T>;
25
+ metricsSubscriber: StoredSubscriber<T>;
26
+ };
27
+ import type { PriceDescription } from '@agoric/zoe/tools/types.js';
28
+ //# sourceMappingURL=contractSupport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contractSupport.d.ts","sourceRoot":"","sources":["contractSupport.js"],"names":[],"mappings":";;;;;;;;AA4BO,4BANe,CAAC,SAAT,MAAO,QACV,CAAC,QACD,CAAC,QACD,CAAC,GACC,CAAC,CAGyC;AAQhD,gCALe,CAAC,SAAT,MAAO,QACV,CAAC,SACD,CAAC,GACC,CAAC,CAK2C;AAQlD,yCAHI,cAAc,QACd,MAAM,EAAE,QAQlB;AAMM,kCAHI,MAAM,EAAE,GACN,OAAO,CAInB;AAUM,0CAPI,MAAM,CAAC,KAAK,CAAC,aACb,MAAM,CAAC,KAAK,CAAC,UACb,MAAM,CAAC,KAAK,CAAC,QAcvB;AAoBM,0CAHI,KAAK;;;EAIsC;AAG/C,0CADK,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,WAAW,CAAC,SAEO;gCAtBtD,CAAC;wBAEA,iBAAiB,CAAC,CAAC,CAAC;yBACpB,kBAAkB,CAAC,CAAC,CAAC;;8BAItB,CAAC;sBAEA,SAAS,CAAC,CAAC,CAAC;uBACZ,gBAAgB,CAAC,CAAC,CAAC;;sCAvF6D,4BAA4B"}
@@ -1,10 +1,11 @@
1
1
  // @jessie-check
2
2
 
3
+ import { Fail, q } from '@endo/errors';
3
4
  import { AmountMath } from '@agoric/ertp';
4
5
  import { M } from '@agoric/store';
5
6
  import { makeRatioFromAmounts } from '@agoric/zoe/src/contractSupport/index.js';
6
7
 
7
- const { Fail, quote: q } = assert;
8
+ /** @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */
8
9
 
9
10
  export const amountPattern = harden({ brand: M.remotable(), value: M.any() });
10
11
  export const ratioPattern = harden({
@@ -13,17 +14,17 @@ export const ratioPattern = harden({
13
14
  });
14
15
 
15
16
  /**
16
- * Apply a delta to the `base` Amount, where the delta is represented as
17
- * an amount to gain and an amount to lose. Typically one of those will
18
- * be empty because gain/loss comes from the give/want for a specific asset
19
- * on a proposal. We use two Amounts because an Amount cannot represent
20
- * a negative number (so we use a "loss" that will be subtracted).
17
+ * Apply a delta to the `base` Amount, where the delta is represented as an
18
+ * amount to gain and an amount to lose. Typically one of those will be empty
19
+ * because gain/loss comes from the give/want for a specific asset on a
20
+ * proposal. We use two Amounts because an Amount cannot represent a negative
21
+ * number (so we use a "loss" that will be subtracted).
21
22
  *
22
- * @template {AssetKind} K
23
- * @param {Amount<K>} base
24
- * @param {Amount<K>} gain
25
- * @param {Amount<K>} loss
26
- * @returns {Amount<K>}
23
+ * @template {Amount} A
24
+ * @param {A} base
25
+ * @param {A} gain
26
+ * @param {A} loss
27
+ * @returns {A}
27
28
  */
28
29
  export const addSubtract = (base, gain, loss) =>
29
30
  AmountMath.subtract(AmountMath.add(base, gain), loss);
@@ -66,8 +67,13 @@ export const allEmpty = amounts => {
66
67
  * @param {Amount<'nat'>} totalDebt
67
68
  * @param {Amount<'nat'>} toMint
68
69
  * @throws if minting would exceed total debt
70
+ *
71
+ * Note: Succeeds regardless of debtLimit if toMint is empty.
69
72
  */
70
73
  export const checkDebtLimit = (debtLimit, totalDebt, toMint) => {
74
+ if (AmountMath.isEmpty(toMint)) {
75
+ return;
76
+ }
71
77
  const debtPost = AmountMath.add(totalDebt, toMint);
72
78
  AmountMath.isGTE(debtLimit, debtPost) ||
73
79
  Fail`Minting ${q(toMint)} past ${q(
@@ -77,14 +83,14 @@ export const checkDebtLimit = (debtLimit, totalDebt, toMint) => {
77
83
 
78
84
  /**
79
85
  * @template T
80
- * @typedef {object} MetricsPublisherKit<T>
86
+ * @typedef {object} MetricsPublisherKit
81
87
  * @property {IterationObserver<T>} metricsPublication
82
88
  * @property {StoredSubscription<T>} metricsSubscription
83
89
  */
84
90
 
85
91
  /**
86
92
  * @template T
87
- * @typedef {object} MetricsPublishKit<T>
93
+ * @typedef {object} MetricsPublishKit
88
94
  * @property {Publisher<T>} metricsPublisher
89
95
  * @property {StoredSubscriber<T>} metricsSubscriber
90
96
  */
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file This contract makes it possible for those who govern contracts to call
3
+ * for votes on changes. A more complete implementation would validate
4
+ * parameters, constrain deadlines and possibly split the ability to call for
5
+ * votes into separate capabilities for finer grain encapsulation.
6
+ */
7
+ export const INVITATION_MAKERS_DESC: "charter member invitation";
8
+ /** @type {ContractMeta<typeof start>} */
9
+ export const meta: ContractMeta<typeof start>;
10
+ export function start(zcf: ZCF<{
11
+ binaryVoteCounterInstallation: Installation;
12
+ }>, privateArgs: undefined, baggage: import("@agoric/vat-data").Baggage): Promise<{
13
+ creatorFacet: import("@endo/exo").Guarded<{
14
+ /**
15
+ * @param {Instance} governedInstance
16
+ * @param {GovernorCreatorFacet<any>} governorFacet
17
+ * @param {string} [label] for diagnostic use only
18
+ */
19
+ addInstance: (governedInstance: Instance, governorFacet: GovernorCreatorFacet<any>, label?: string | undefined) => void;
20
+ makeCharterMemberInvitation: () => Promise<Invitation<{
21
+ invitationMakers: import("@endo/exo").Guarded<{
22
+ VoteOnParamChange: () => Promise<Invitation<import("@agoric/governance/src/types").ContractGovernanceVoteResult, ParamChangesOfferArgs>>;
23
+ VoteOnPauseOffers: (instance: any, strings: any, deadline: any) => Promise<Invitation<import("@agoric/governance/src/types").ContractGovernanceVoteResult, undefined>>;
24
+ VoteOnApiCall: (instance: Instance, methodName: string, methodArgs: string[], deadline: import("@agoric/time").TimestampValue) => Promise<Invitation<import("@agoric/governance/src/types").ContractGovernanceVoteResult, undefined>>;
25
+ }>;
26
+ }, undefined>>;
27
+ }>;
28
+ }>;
29
+ export type ParamChangesOfferArgs = {
30
+ deadline: bigint;
31
+ instance: Instance;
32
+ params: Record<string, unknown>;
33
+ /**
34
+ * paramPath is determined by contract
35
+ */
36
+ path?: {
37
+ paramPath: unknown;
38
+ } | undefined;
39
+ };
40
+ //# sourceMappingURL=econCommitteeCharter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"econCommitteeCharter.d.ts","sourceRoot":"","sources":["econCommitteeCharter.js"],"names":[],"mappings":"AAaA;;;;;GAKG;AAEH,iEAAkE;AAoBlE,yCAAyC;AACzC,mBADW,YAAY,CAAC,OAAO,KAAK,CAAC,CAMnC;AAQK,2BAJI,GAAG,CAAC;IAAE,6BAA6B,EAAE,YAAY,CAAA;CAAE,CAAC,eACpD,SAAS,WACT,OAAO,kBAAkB,EAAE,OAAO;;QAsHvC;;;;WAIG;wCAHQ,QAAQ,iBACR,oBAAoB,CAAC,GAAG,CAAC;;;;;0CAxE7B,QAAQ,cACR,MAAM,cACN,MAAM,EAAE,YACR,OAAO,cAAc,EAAE,cAAc;;;;GAkFjD;;cAjKa,MAAM;cACN,QAAQ;YACR,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;mBACV,OAAO"}
@@ -1,11 +1,10 @@
1
1
  // @jessie-check
2
+ /// <reference types="@agoric/governance/exported" />
3
+ /// <reference types="@agoric/zoe/exported" />
2
4
 
3
- import '@agoric/governance/exported.js';
4
5
  import { M, mustMatch } from '@agoric/store';
5
6
  import { TimestampShape } from '@agoric/time';
6
7
  import { prepareExo, provideDurableMapStore } from '@agoric/vat-data';
7
- import '@agoric/zoe/exported.js';
8
- import '@agoric/zoe/src/contracts/exported.js';
9
8
  import {
10
9
  InstallationShape,
11
10
  InstanceHandleShape,
@@ -13,12 +12,10 @@ import {
13
12
  import { E } from '@endo/far';
14
13
 
15
14
  /**
16
- * @file
17
- *
18
- * This contract makes it possible for those who govern contracts to call for
19
- * votes on changes. A more complete implementation would validate parameters,
20
- * constrain deadlines and possibly split the ability to call for votes into
21
- * separate capabilities for finer grain encapsulation.
15
+ * @file This contract makes it possible for those who govern contracts to call
16
+ * for votes on changes. A more complete implementation would validate
17
+ * parameters, constrain deadlines and possibly split the ability to call for
18
+ * votes into separate capabilities for finer grain encapsulation.
22
19
  */
23
20
 
24
21
  export const INVITATION_MAKERS_DESC = 'charter member invitation';
@@ -28,7 +25,7 @@ export const INVITATION_MAKERS_DESC = 'charter member invitation';
28
25
  * @property {bigint} deadline
29
26
  * @property {Instance} instance
30
27
  * @property {Record<string, unknown>} params
31
- * @property {{paramPath: { key: string }}} [path]
28
+ * @property {{ paramPath: unknown }} [path] paramPath is determined by contract
32
29
  */
33
30
  const ParamChangesOfferArgsShape = M.splitRecord(
34
31
  {
@@ -41,19 +38,21 @@ const ParamChangesOfferArgsShape = M.splitRecord(
41
38
  },
42
39
  );
43
40
 
44
- /**
45
- * A pattern for Zoe to check custom terms before `start()`ing the contract.
46
- */
47
- export const customTermsShape = harden({
48
- binaryVoteCounterInstallation: InstallationShape,
49
- });
41
+ /** @type {ContractMeta<typeof start>} */
42
+ export const meta = {
43
+ customTermsShape: {
44
+ binaryVoteCounterInstallation: InstallationShape,
45
+ },
46
+ upgradability: 'canUpgrade',
47
+ };
48
+ harden(meta);
50
49
 
51
50
  /**
52
- * @param {ZCF<{binaryVoteCounterInstallation: Installation}>} zcf
51
+ * @param {ZCF<{ binaryVoteCounterInstallation: Installation }>} zcf
53
52
  * @param {undefined} privateArgs
54
53
  * @param {import('@agoric/vat-data').Baggage} baggage
55
54
  */
56
- export const prepare = async (zcf, privateArgs, baggage) => {
55
+ export const start = async (zcf, privateArgs, baggage) => {
57
56
  const { binaryVoteCounterInstallation: counter } = zcf.getTerms();
58
57
  /** @type {MapStore<Instance, GovernorCreatorFacet<any>>} */
59
58
  const instanceToGovernor = provideDurableMapStore(
@@ -79,6 +78,7 @@ export const prepare = async (zcf, privateArgs, baggage) => {
79
78
  const governor = instanceToGovernor.get(instance);
80
79
  return E(governor).voteOnParamChanges(counter, deadline, {
81
80
  ...path,
81
+ // @ts-expect-error XXX
82
82
  changes: params,
83
83
  });
84
84
  };
@@ -156,7 +156,7 @@ export const prepare = async (zcf, privateArgs, baggage) => {
156
156
  return harden({ invitationMakers });
157
157
  };
158
158
 
159
- const charterCreatorI = M.interface('Charter creatorFacet', {
159
+ const CharterCreatorI = M.interface('Charter creatorFacet', {
160
160
  addInstance: M.call(InstanceHandleShape, M.any())
161
161
  .optional(M.string())
162
162
  .returns(),
@@ -166,7 +166,7 @@ export const prepare = async (zcf, privateArgs, baggage) => {
166
166
  const creatorFacet = prepareExo(
167
167
  baggage,
168
168
  'Charter creatorFacet',
169
- charterCreatorI,
169
+ CharterCreatorI,
170
170
  {
171
171
  /**
172
172
  * @param {Instance} governedInstance
@@ -184,3 +184,4 @@ export const prepare = async (zcf, privateArgs, baggage) => {
184
184
 
185
185
  return harden({ creatorFacet });
186
186
  };
187
+ harden(start);