@agoric/inter-protocol 0.16.2-dev-eb7e9eb.0 → 0.16.2-u11.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 (176) hide show
  1. package/CHANGELOG.md +1041 -0
  2. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  3. package/bundles/bundle-auctioneer.js +1 -0
  4. package/bundles/bundle-econCommitteeCharter-js-meta.json +222 -242
  5. package/bundles/bundle-econCommitteeCharter.js +1 -1
  6. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  7. package/bundles/bundle-feeDistributor.js +1 -0
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +327 -343
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -1
  10. package/bundles/bundle-psm-js-meta.json +308 -328
  11. package/bundles/bundle-psm.js +1 -1
  12. package/bundles/bundle-reserve-js-meta.json +662 -0
  13. package/bundles/bundle-reserve.js +1 -0
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -0
  16. package/bundles/bundle-vaultFactory-js-meta.json +790 -0
  17. package/bundles/bundle-vaultFactory.js +1 -0
  18. package/package.json +31 -31
  19. package/scripts/add-collateral-core.js +112 -0
  20. package/scripts/build-bundles.js +21 -5
  21. package/scripts/deploy-contracts.js +100 -0
  22. package/scripts/init-core.js +198 -0
  23. package/scripts/invite-committee-core.js +42 -0
  24. package/scripts/manual-price-feed.js +117 -0
  25. package/scripts/price-feed-core.js +104 -0
  26. package/scripts/start-local-chain.sh +84 -0
  27. package/src/auction/auctionBook.js +56 -68
  28. package/src/auction/auctioneer.js +44 -56
  29. package/src/auction/offerBook.js +11 -12
  30. package/src/auction/params.js +5 -3
  31. package/src/auction/scheduleMath.js +13 -13
  32. package/src/auction/scheduler.js +32 -22
  33. package/src/auction/sortedOffers.js +7 -8
  34. package/src/auction/util.js +4 -4
  35. package/src/clientSupport.js +96 -152
  36. package/src/contractSupport.js +5 -5
  37. package/src/econCommitteeCharter.js +15 -16
  38. package/src/feeDistributor.js +33 -34
  39. package/src/interest.js +14 -20
  40. package/src/price/fluxAggregatorContract.js +45 -51
  41. package/src/price/fluxAggregatorKit.js +32 -47
  42. package/src/price/priceOracleKit.js +13 -11
  43. package/src/price/roundsManager.js +64 -52
  44. package/src/proposals/addAssetToVault.js +3 -15
  45. package/src/proposals/committee-proposal.js +9 -5
  46. package/src/proposals/core-proposal.js +7 -7
  47. package/src/proposals/econ-behaviors.js +32 -57
  48. package/src/proposals/price-feed-proposal.js +26 -59
  49. package/src/proposals/startEconCommittee.js +1 -1
  50. package/src/proposals/startPSM.js +22 -32
  51. package/src/proposals/utils.js +7 -26
  52. package/src/psm/psm.js +63 -69
  53. package/src/reserve/assetReserve.js +18 -27
  54. package/src/reserve/assetReserveKit.js +22 -14
  55. package/src/typeGuards.js +13 -0
  56. package/src/vaultFactory/liquidation.js +17 -30
  57. package/src/vaultFactory/math.js +9 -8
  58. package/src/vaultFactory/orderedVaultStore.js +9 -6
  59. package/src/vaultFactory/params.js +18 -24
  60. package/src/vaultFactory/prioritizedVaults.js +2 -2
  61. package/src/vaultFactory/proceeds.js +18 -24
  62. package/src/vaultFactory/storeUtils.js +12 -8
  63. package/src/vaultFactory/types.js +28 -38
  64. package/src/vaultFactory/vault.js +89 -88
  65. package/src/vaultFactory/vaultDirector.js +41 -33
  66. package/src/vaultFactory/vaultFactory.js +26 -33
  67. package/src/vaultFactory/vaultHolder.js +13 -8
  68. package/src/vaultFactory/vaultKit.js +2 -3
  69. package/src/vaultFactory/vaultManager.js +120 -138
  70. package/src/auction/auctionBook.d.ts +0 -83
  71. package/src/auction/auctionBook.d.ts.map +0 -1
  72. package/src/auction/auctioneer.d.ts +0 -75
  73. package/src/auction/auctioneer.d.ts.map +0 -1
  74. package/src/auction/offerBook.d.ts +0 -72
  75. package/src/auction/offerBook.d.ts.map +0 -1
  76. package/src/auction/params.d.ts +0 -142
  77. package/src/auction/params.d.ts.map +0 -1
  78. package/src/auction/scheduleMath.d.ts +0 -4
  79. package/src/auction/scheduleMath.d.ts.map +0 -1
  80. package/src/auction/scheduler.d.ts +0 -49
  81. package/src/auction/scheduler.d.ts.map +0 -1
  82. package/src/auction/sortedOffers.d.ts +0 -8
  83. package/src/auction/sortedOffers.d.ts.map +0 -1
  84. package/src/auction/util.d.ts +0 -30
  85. package/src/auction/util.d.ts.map +0 -1
  86. package/src/clientSupport.d.ts +0 -167
  87. package/src/clientSupport.d.ts.map +0 -1
  88. package/src/collectFees.d.ts +0 -2
  89. package/src/collectFees.d.ts.map +0 -1
  90. package/src/contractSupport.d.ts +0 -33
  91. package/src/contractSupport.d.ts.map +0 -1
  92. package/src/econCommitteeCharter.d.ts +0 -41
  93. package/src/econCommitteeCharter.d.ts.map +0 -1
  94. package/src/feeDistributor.d.ts +0 -212
  95. package/src/feeDistributor.d.ts.map +0 -1
  96. package/src/index.d.ts +0 -2
  97. package/src/index.d.ts.map +0 -1
  98. package/src/interest-math.d.ts +0 -3
  99. package/src/interest-math.d.ts.map +0 -1
  100. package/src/interest.d.ts +0 -29
  101. package/src/interest.d.ts.map +0 -1
  102. package/src/price/fluxAggregatorContract.d.ts +0 -112
  103. package/src/price/fluxAggregatorContract.d.ts.map +0 -1
  104. package/src/price/fluxAggregatorKit.d.ts +0 -155
  105. package/src/price/fluxAggregatorKit.d.ts.map +0 -1
  106. package/src/price/priceOracleKit.d.ts +0 -52
  107. package/src/price/priceOracleKit.d.ts.map +0 -1
  108. package/src/price/roundsManager.d.ts +0 -330
  109. package/src/price/roundsManager.d.ts.map +0 -1
  110. package/src/proposals/addAssetToVault.d.ts +0 -155
  111. package/src/proposals/addAssetToVault.d.ts.map +0 -1
  112. package/src/proposals/committee-proposal.d.ts +0 -121
  113. package/src/proposals/committee-proposal.d.ts.map +0 -1
  114. package/src/proposals/core-proposal.d.ts +0 -149
  115. package/src/proposals/core-proposal.d.ts.map +0 -1
  116. package/src/proposals/econ-behaviors.d.ts +0 -201
  117. package/src/proposals/econ-behaviors.d.ts.map +0 -1
  118. package/src/proposals/price-feed-proposal.d.ts +0 -83
  119. package/src/proposals/price-feed-proposal.d.ts.map +0 -1
  120. package/src/proposals/startEconCommittee.d.ts +0 -34
  121. package/src/proposals/startEconCommittee.d.ts.map +0 -1
  122. package/src/proposals/startPSM.d.ts +0 -61
  123. package/src/proposals/startPSM.d.ts.map +0 -1
  124. package/src/proposals/utils.d.ts +0 -15
  125. package/src/proposals/utils.d.ts.map +0 -1
  126. package/src/provisionPool.d.ts +0 -165
  127. package/src/provisionPool.d.ts.map +0 -1
  128. package/src/provisionPool.js +0 -119
  129. package/src/provisionPoolKit.d.ts +0 -379
  130. package/src/provisionPoolKit.d.ts.map +0 -1
  131. package/src/provisionPoolKit.js +0 -461
  132. package/src/psm/psm.d.ts +0 -178
  133. package/src/psm/psm.d.ts.map +0 -1
  134. package/src/psm/types.d.ts +0 -2
  135. package/src/psm/types.d.ts.map +0 -1
  136. package/src/reserve/assetReserve.d.ts +0 -44
  137. package/src/reserve/assetReserve.d.ts.map +0 -1
  138. package/src/reserve/assetReserveKit.d.ts +0 -114
  139. package/src/reserve/assetReserveKit.d.ts.map +0 -1
  140. package/src/reserve/params.d.ts +0 -10
  141. package/src/reserve/params.d.ts.map +0 -1
  142. package/src/tokens.d.ts +0 -3
  143. package/src/tokens.d.ts.map +0 -1
  144. package/src/tokens.js +0 -5
  145. package/src/vaultFactory/burn.d.ts +0 -2
  146. package/src/vaultFactory/burn.d.ts.map +0 -1
  147. package/src/vaultFactory/liquidation.d.ts +0 -24
  148. package/src/vaultFactory/liquidation.d.ts.map +0 -1
  149. package/src/vaultFactory/math.d.ts +0 -10
  150. package/src/vaultFactory/math.d.ts.map +0 -1
  151. package/src/vaultFactory/orderedVaultStore.d.ts +0 -94
  152. package/src/vaultFactory/orderedVaultStore.d.ts.map +0 -1
  153. package/src/vaultFactory/params.d.ts +0 -159
  154. package/src/vaultFactory/params.d.ts.map +0 -1
  155. package/src/vaultFactory/prioritizedVaults.d.ts +0 -279
  156. package/src/vaultFactory/prioritizedVaults.d.ts.map +0 -1
  157. package/src/vaultFactory/proceeds.d.ts +0 -34
  158. package/src/vaultFactory/proceeds.d.ts.map +0 -1
  159. package/src/vaultFactory/storeUtils.d.ts +0 -25
  160. package/src/vaultFactory/storeUtils.d.ts.map +0 -1
  161. package/src/vaultFactory/type-imports.d.ts +0 -2
  162. package/src/vaultFactory/type-imports.d.ts.map +0 -1
  163. package/src/vaultFactory/types.d.ts +0 -137
  164. package/src/vaultFactory/types.d.ts.map +0 -1
  165. package/src/vaultFactory/vault.d.ts +0 -529
  166. package/src/vaultFactory/vault.d.ts.map +0 -1
  167. package/src/vaultFactory/vaultDirector.d.ts +0 -560
  168. package/src/vaultFactory/vaultDirector.d.ts.map +0 -1
  169. package/src/vaultFactory/vaultFactory.d.ts +0 -162
  170. package/src/vaultFactory/vaultFactory.d.ts.map +0 -1
  171. package/src/vaultFactory/vaultHolder.d.ts +0 -201
  172. package/src/vaultFactory/vaultHolder.d.ts.map +0 -1
  173. package/src/vaultFactory/vaultKit.d.ts +0 -32
  174. package/src/vaultFactory/vaultKit.d.ts.map +0 -1
  175. package/src/vaultFactory/vaultManager.d.ts +0 -554
  176. package/src/vaultFactory/vaultManager.d.ts.map +0 -1
@@ -1,461 +0,0 @@
1
- // @ts-check
2
- import { AmountMath, BrandShape } from '@agoric/ertp';
3
- import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
4
- import {
5
- observeIteration,
6
- observeNotifier,
7
- subscribeEach,
8
- } from '@agoric/notifier';
9
- import {
10
- M,
11
- makeScalarBigMapStore,
12
- makeScalarBigSetStore,
13
- prepareExoClassKit,
14
- } from '@agoric/vat-data';
15
- import { PowerFlags } from '@agoric/vats/src/walletFlags.js';
16
- import {
17
- PublicTopicShape,
18
- makeRecorderTopic,
19
- } from '@agoric/zoe/src/contractSupport/topics.js';
20
- import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
21
- import { E } from '@endo/far';
22
- import { Far, deeplyFulfilled } from '@endo/marshal';
23
-
24
- const { details: X, quote: q, Fail } = assert;
25
-
26
- /**
27
- * @typedef {import('@agoric/zoe/src/zoeService/utils').Instance<
28
- * import('@agoric/inter-protocol/src/psm/psm.js').start
29
- * >} PsmInstance
30
- */
31
-
32
- /**
33
- * @typedef {object} ProvisionPoolKitReferences
34
- * @property {ERef<BankManager>} bankManager
35
- * @property {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
36
- * @property {ERef<
37
- * import('@agoric/vats/src/core/startWalletFactory').WalletFactoryStartResult['creatorFacet']
38
- * >} walletFactory
39
- */
40
-
41
- /**
42
- * @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
43
- * present values and past-participles are accumulative.
44
- * @property {bigint} walletsProvisioned count of new wallets provisioned
45
- * @property {Amount<'nat'>} totalMintedProvided running sum of Minted provided
46
- * to new wallets
47
- * @property {Amount<'nat'>} totalMintedConverted running sum of Minted ever
48
- * received by the contract from PSM
49
- */
50
-
51
- /**
52
- * Given attenuated access to the funding purse, handle requests to provision
53
- * smart wallets.
54
- *
55
- * @param {(depositBank: ERef<Bank>) => Promise<void>} sendInitialPayment
56
- * @param {() => void} onProvisioned
57
- *
58
- * @typedef {import('@agoric/vats/src/vat-bank.js').Bank} Bank
59
- */
60
- export const makeBridgeProvisionTool = (sendInitialPayment, onProvisioned) => {
61
- /** @param {ProvisionPoolKitReferences} refs */
62
- const makeBridgeHandler = ({
63
- bankManager,
64
- namesByAddressAdmin,
65
- walletFactory,
66
- }) =>
67
- Far('provisioningHandler', {
68
- fromBridge: async obj => {
69
- obj.type === 'PLEASE_PROVISION' ||
70
- Fail`Unrecognized request ${obj.type}`;
71
- console.info('PLEASE_PROVISION', obj);
72
- const { address, powerFlags } = obj;
73
- powerFlags.includes(PowerFlags.SMART_WALLET) ||
74
- Fail`missing SMART_WALLET in powerFlags`;
75
-
76
- const bank = E(bankManager).getBankForAddress(address);
77
- // only proceed if we can provide funds
78
- await sendInitialPayment(bank);
79
-
80
- const [_, created] = await E(walletFactory).provideSmartWallet(
81
- address,
82
- bank,
83
- namesByAddressAdmin,
84
- );
85
- if (created) {
86
- onProvisioned();
87
- }
88
- console.info(created ? 'provisioned' : 're-provisioned', address);
89
- },
90
- });
91
- return makeBridgeHandler;
92
- };
93
-
94
- /**
95
- * @param {import('@agoric/vat-data').Baggage} baggage
96
- * @param {{
97
- * makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit;
98
- * params: any;
99
- * poolBank: import('@endo/far').ERef<Bank>;
100
- * zcf: ZCF;
101
- * }} powers
102
- */
103
- export const prepareProvisionPoolKit = (
104
- baggage,
105
- { makeRecorderKit, params, poolBank, zcf },
106
- ) => {
107
- const zoe = zcf.getZoeService();
108
-
109
- const makeProvisionPoolKitInternal = prepareExoClassKit(
110
- baggage,
111
- 'ProvisionPoolKit',
112
- {
113
- machine: M.interface('ProvisionPoolKit machine', {
114
- addRevivableAddresses: M.call(M.arrayOf(M.string())).returns(),
115
- getWalletReviver: M.call().returns(
116
- M.remotable('ProvisionPoolKit wallet reviver'),
117
- ),
118
- setReferences: M.callWhen({
119
- bankManager: M.eref(M.remotable('bankManager')),
120
- namesByAddressAdmin: M.eref(M.remotable('nameAdmin')),
121
- walletFactory: M.eref(M.remotable('walletFactory')),
122
- }).returns(),
123
- makeHandler: M.call().returns(M.remotable('BridgeHandler')),
124
- initPSM: M.call(BrandShape, InstanceHandleShape).returns(),
125
- }),
126
- walletReviver: M.interface('ProvisionPoolKit wallet reviver', {
127
- reviveWallet: M.callWhen(M.string()).returns(
128
- M.remotable('SmartWallet'),
129
- ),
130
- ackWallet: M.call(M.string()).returns(M.boolean()),
131
- }),
132
- helper: UnguardedHelperI,
133
- public: M.interface('ProvisionPoolKit public', {
134
- getPublicTopics: M.call().returns({ metrics: PublicTopicShape }),
135
- }),
136
- },
137
- /**
138
- * @param {object} opts
139
- * @param {Purse<'nat'>} opts.fundPurse
140
- * @param {Brand} opts.poolBrand
141
- * @param {StorageNode} opts.metricsNode
142
- */
143
- ({ fundPurse, poolBrand, metricsNode }) => {
144
- /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification>} */
145
- const metricsRecorderKit = makeRecorderKit(metricsNode);
146
-
147
- /** @type {MapStore<Brand, PsmInstance>} */
148
- const brandToPSM = makeScalarBigMapStore('brandToPSM', { durable: true });
149
- const revivableAddresses = makeScalarBigSetStore('revivableAddresses', {
150
- durable: true,
151
- keyShape: M.string(),
152
- });
153
-
154
- /**
155
- * to be set by `setReferences`
156
- *
157
- * @type {Partial<ProvisionPoolKitReferences>}
158
- */
159
- const references = {
160
- bankManager: undefined,
161
- namesByAddressAdmin: undefined,
162
- walletFactory: undefined,
163
- };
164
-
165
- return {
166
- brandToPSM,
167
- fundPurse,
168
- metricsRecorderKit,
169
- poolBrand,
170
- walletsProvisioned: 0n,
171
- totalMintedProvided: AmountMath.makeEmpty(poolBrand),
172
- totalMintedConverted: AmountMath.makeEmpty(poolBrand),
173
- revivableAddresses,
174
- ...references,
175
- };
176
- },
177
- {
178
- // aka "limitedCreatorFacet"
179
- machine: {
180
- /** @param {string[]} oldAddresses */
181
- addRevivableAddresses(oldAddresses) {
182
- console.log('revivableAddresses count', oldAddresses.length);
183
- this.state.revivableAddresses.addAll(oldAddresses);
184
- },
185
- getWalletReviver() {
186
- return this.facets.walletReviver;
187
- },
188
- /** @param {ProvisionPoolKitReferences} erefs */
189
- async setReferences(erefs) {
190
- const { bankManager, namesByAddressAdmin, walletFactory } = erefs;
191
- const obj = harden({
192
- bankManager,
193
- namesByAddressAdmin,
194
- walletFactory,
195
- });
196
- const refs = await deeplyFulfilled(obj);
197
- Object.assign(this.state, refs);
198
- },
199
- makeHandler() {
200
- const { bankManager, namesByAddressAdmin, walletFactory } =
201
- this.state;
202
- if (!bankManager || !namesByAddressAdmin || !walletFactory) {
203
- throw Fail`must set references before handling requests`;
204
- }
205
- const { helper } = this.facets;
206
- // a bit obtuse but leave for backwards compatibility with tests
207
- const innerMaker = makeBridgeProvisionTool(
208
- bank => helper.sendInitialPayment(bank),
209
- () => helper.onProvisioned(),
210
- );
211
- return innerMaker({
212
- bankManager,
213
- namesByAddressAdmin,
214
- walletFactory,
215
- });
216
- },
217
- /**
218
- * @param {Brand} brand
219
- * @param {PsmInstance} instance
220
- */
221
- initPSM(brand, instance) {
222
- const { brandToPSM } = this.state;
223
- brandToPSM.init(brand, instance);
224
- },
225
- },
226
- walletReviver: {
227
- /** @param {string} address */
228
- async reviveWallet(address) {
229
- const {
230
- revivableAddresses,
231
- bankManager,
232
- namesByAddressAdmin,
233
- walletFactory,
234
- } = this.state;
235
- if (!bankManager || !namesByAddressAdmin || !walletFactory) {
236
- throw Fail`must set references before handling requests`;
237
- }
238
- revivableAddresses.has(address) ||
239
- Fail`non-revivable address ${address}`;
240
- const bank = E(bankManager).getBankForAddress(address);
241
- const [wallet, _created] = await E(walletFactory).provideSmartWallet(
242
- address,
243
- bank,
244
- namesByAddressAdmin,
245
- );
246
- return wallet;
247
- },
248
- /**
249
- * @param {string} address
250
- * @returns {boolean} isRevive
251
- */
252
- ackWallet(address) {
253
- const { revivableAddresses } = this.state;
254
- if (!revivableAddresses.has(address)) {
255
- return false;
256
- }
257
- revivableAddresses.delete(address);
258
- return true;
259
- },
260
- },
261
- helper: {
262
- publishMetrics() {
263
- const {
264
- metricsRecorderKit,
265
- walletsProvisioned,
266
- totalMintedConverted,
267
- totalMintedProvided,
268
- } = this.state;
269
- void metricsRecorderKit.recorder.write(
270
- harden({
271
- walletsProvisioned,
272
- totalMintedProvided,
273
- totalMintedConverted,
274
- }),
275
- );
276
- },
277
- onTrade(converted) {
278
- const { state, facets } = this;
279
- state.totalMintedConverted = AmountMath.add(
280
- state.totalMintedConverted,
281
- converted,
282
- );
283
- facets.helper.publishMetrics();
284
- },
285
- onSendFunds(provided) {
286
- const { state, facets } = this;
287
- state.totalMintedProvided = AmountMath.add(
288
- state.totalMintedProvided,
289
- provided,
290
- );
291
- facets.helper.publishMetrics();
292
- },
293
- onProvisioned() {
294
- const { state, facets } = this;
295
- state.walletsProvisioned += 1n;
296
- facets.helper.publishMetrics();
297
- },
298
- /** @param {ERef<Bank>} destBank */
299
- async sendInitialPayment(destBank) {
300
- const {
301
- facets: { helper },
302
- state: { fundPurse, poolBrand },
303
- } = this;
304
- const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
305
- params.getPerAccountInitialAmount()
306
- );
307
- const initialPmt = await E(fundPurse).withdraw(
308
- perAccountInitialAmount,
309
- );
310
-
311
- const destPurse = E(destBank).getPurse(poolBrand);
312
- return E(destPurse)
313
- .deposit(initialPmt)
314
- .then(amt => {
315
- helper.onSendFunds(perAccountInitialAmount);
316
- console.log('provisionPool sent', amt);
317
- })
318
- .catch(reason => {
319
- console.error(X`initial deposit failed: ${q(reason)}`);
320
- void E(fundPurse).deposit(initialPmt);
321
- throw reason;
322
- });
323
- },
324
- /**
325
- * @param {object} [options]
326
- * @param {MetricsNotification} [options.metrics]
327
- */
328
- start({ metrics } = {}) {
329
- const {
330
- state: { brandToPSM, poolBrand },
331
- facets: { helper },
332
- } = this;
333
-
334
- // Must match. poolBrand is from durable state and the param is from
335
- // the contract, so it technically can change between incarnations.
336
- // That would be a severe bug.
337
- AmountMath.coerce(poolBrand, params.getPerAccountInitialAmount());
338
-
339
- void observeIteration(
340
- subscribeEach(E(poolBank).getAssetSubscription()),
341
- {
342
- updateState: async desc => {
343
- console.log('provisionPool notified of new asset', desc.brand);
344
- await zcf.saveIssuer(desc.issuer, desc.issuerName);
345
- /** @type {ERef<Purse>} */
346
- // @ts-expect-error vbank purse is close enough for our use.
347
- const exchangePurse = E(poolBank).getPurse(desc.brand);
348
- void observeNotifier(
349
- E(exchangePurse).getCurrentAmountNotifier(),
350
- {
351
- updateState: async amount => {
352
- console.log('provisionPool balance update', amount);
353
- if (
354
- AmountMath.isEmpty(amount) ||
355
- amount.brand === poolBrand
356
- ) {
357
- return;
358
- }
359
- if (!brandToPSM.has(desc.brand)) {
360
- console.error(
361
- 'funds arrived but no PSM instance',
362
- desc.brand,
363
- );
364
- return;
365
- }
366
- const instance = brandToPSM.get(desc.brand);
367
- const payment = E(exchangePurse).withdraw(amount);
368
- await helper
369
- .swap(payment, amount, instance)
370
- .catch(async reason => {
371
- console.error(X`swap failed: ${reason}`);
372
- const resolvedPayment = await payment;
373
- return E(exchangePurse).deposit(resolvedPayment);
374
- });
375
- },
376
- fail: reason => console.error(reason),
377
- },
378
- );
379
- },
380
- },
381
- );
382
-
383
- if (metrics) {
384
- // Restore state.
385
- // we publishMetrics() below
386
- const {
387
- walletsProvisioned,
388
- totalMintedProvided,
389
- totalMintedConverted,
390
- } = metrics;
391
- assert.typeof(walletsProvisioned, 'bigint');
392
- AmountMath.coerce(poolBrand, totalMintedProvided);
393
- AmountMath.coerce(poolBrand, totalMintedConverted);
394
- Object.assign(this.state, {
395
- walletsProvisioned,
396
- totalMintedProvided,
397
- totalMintedConverted,
398
- });
399
- helper.publishMetrics();
400
- }
401
- },
402
- /**
403
- * @param {ERef<Payment>} payIn
404
- * @param {Amount} amount
405
- * @param {PsmInstance} instance
406
- */
407
- async swap(payIn, amount, instance) {
408
- const {
409
- facets: { helper },
410
- state: { fundPurse },
411
- } = this;
412
- const psmPub = E(zoe).getPublicFacet(instance);
413
- const proposal = harden({ give: { In: amount } });
414
- const invitation = E(psmPub).makeWantMintedInvitation();
415
- const seat = E(zoe).offer(invitation, proposal, { In: payIn });
416
- const payout = await E(seat).getPayout('Out');
417
- const rxd = await E(fundPurse).deposit(payout);
418
- helper.onTrade(rxd);
419
- return rxd;
420
- },
421
- },
422
- public: {
423
- getPublicTopics() {
424
- return {
425
- metrics: makeRecorderTopic(
426
- 'Provision Pool metrics',
427
- this.state.metricsRecorderKit,
428
- ),
429
- };
430
- },
431
- },
432
- },
433
- {
434
- finish: ({ facets }) => {
435
- facets.helper.publishMetrics();
436
- },
437
- },
438
- );
439
-
440
- /**
441
- * Prepare synchronous values before passing to real Exo maker
442
- *
443
- * @param {object} opts
444
- * @param {Brand} opts.poolBrand
445
- * @param {ERef<StorageNode>} opts.storageNode
446
- */
447
- const makeProvisionPoolKit = async ({ poolBrand, storageNode }) => {
448
- /** @type {Purse<'nat'>} */
449
- // @ts-expect-error vbank purse is close enough for our use.
450
- const fundPurse = await E(poolBank).getPurse(poolBrand);
451
- const metricsNode = await E(storageNode).makeChildNode('metrics');
452
-
453
- return makeProvisionPoolKitInternal({
454
- fundPurse,
455
- poolBrand,
456
- metricsNode,
457
- });
458
- };
459
-
460
- return makeProvisionPoolKit;
461
- };
package/src/psm/psm.d.ts DELETED
@@ -1,178 +0,0 @@
1
- /**
2
- * @file The Parity Stability Module supports efficiently minting/burning a
3
- * stable token at a specified fixed ratio to a reference stable token, which
4
- * thereby acts as an anchor to provide additional stability. For flexible
5
- * economic policies, the fee percentage for trading into and out of the
6
- * stable token are specified separately.
7
- */
8
- /**
9
- * @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
10
- * present values and past-participles are accumulative.
11
- * @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token available
12
- * to be swapped
13
- * @property {Amount<'nat'>} mintedPoolBalance amount of Minted token
14
- * outstanding (the amount minted minus the amount burned).
15
- * @property {Amount<'nat'>} feePoolBalance amount of Minted token fees
16
- * available to be collected
17
- * @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor ever
18
- * given by this contract
19
- * @property {Amount<'nat'>} totalMintedProvided running sum of Minted ever
20
- * given by this contract
21
- */
22
- /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
23
- /** @type {ContractMeta} */
24
- export const meta: ContractMeta;
25
- export function start(zcf: ZCF<GovernanceTerms<{
26
- GiveMintedFee: 'ratio';
27
- WantMintedFee: 'ratio';
28
- MintLimit: 'amount';
29
- }> & {
30
- anchorBrand: Brand<'nat'>;
31
- anchorPerMinted: Ratio;
32
- }>, privateArgs: {
33
- feeMintAccess: FeeMintAccess;
34
- initialPoserInvitation: Invitation;
35
- storageNode: StorageNode;
36
- marshaller: Marshaller;
37
- }, baggage: Baggage): Promise<{
38
- creatorFacet: {
39
- getParamMgrRetriever: () => {
40
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
41
- GiveMintedFee: "ratio";
42
- MintLimit: "amount";
43
- WantMintedFee: "ratio";
44
- } & {
45
- Electorate: "invitation";
46
- }>;
47
- } & import("@endo/eventual-send").RemotableBrand<{}, {
48
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
49
- GiveMintedFee: "ratio";
50
- MintLimit: "amount";
51
- WantMintedFee: "ratio";
52
- } & {
53
- Electorate: "invitation";
54
- }>;
55
- }>;
56
- getInvitation: (name: any) => Promise<Invitation<R, A>>;
57
- getLimitedCreatorFacet: () => {
58
- getRewardAllocation(): AmountKeywordRecord;
59
- makeCollectFeesInvitation(): Promise<Invitation<R, A>>;
60
- makeRestoreMetricsInvitation(): Promise<Invitation<R, A>>;
61
- } & import("@endo/eventual-send").RemotableBrand<{}, {
62
- getRewardAllocation(): AmountKeywordRecord;
63
- makeCollectFeesInvitation(): Promise<Invitation<R, A>>;
64
- makeRestoreMetricsInvitation(): Promise<Invitation<R, A>>;
65
- }>;
66
- getGovernedApis: () => GovernedApis;
67
- getGovernedApiNames: () => string[];
68
- setOfferFilter: (strings: any) => Promise<void>;
69
- } & import("@endo/eventual-send").RemotableBrand<{}, {
70
- getParamMgrRetriever: () => {
71
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
72
- GiveMintedFee: "ratio";
73
- MintLimit: "amount";
74
- WantMintedFee: "ratio";
75
- } & {
76
- Electorate: "invitation";
77
- }>;
78
- } & import("@endo/eventual-send").RemotableBrand<{}, {
79
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
80
- GiveMintedFee: "ratio";
81
- MintLimit: "amount";
82
- WantMintedFee: "ratio";
83
- } & {
84
- Electorate: "invitation";
85
- }>;
86
- }>;
87
- getInvitation: (name: any) => Promise<Invitation<R, A>>;
88
- getLimitedCreatorFacet: () => {
89
- getRewardAllocation(): AmountKeywordRecord;
90
- makeCollectFeesInvitation(): Promise<Invitation<R, A>>;
91
- makeRestoreMetricsInvitation(): Promise<Invitation<R, A>>;
92
- } & import("@endo/eventual-send").RemotableBrand<{}, {
93
- getRewardAllocation(): AmountKeywordRecord;
94
- makeCollectFeesInvitation(): Promise<Invitation<R, A>>;
95
- makeRestoreMetricsInvitation(): Promise<Invitation<R, A>>;
96
- }>;
97
- getGovernedApis: () => GovernedApis;
98
- getGovernedApiNames: () => string[];
99
- setOfferFilter: (strings: any) => Promise<void>;
100
- }>;
101
- publicFacet: {
102
- getAmount: (name: string) => Amount<AssetKind>;
103
- getBrand: (name: string) => Brand<AssetKind>;
104
- getInstance: (name: string) => Instance;
105
- getInstallation: (name: string) => Installation<any>;
106
- getInvitationAmount: (name: string) => Amount<"set">;
107
- getNat: (name: string) => bigint;
108
- getRatio: (name: string) => Ratio;
109
- getString: (name: string) => string;
110
- getTimestamp: (name: string) => import("@agoric/time/src/types.js").TimestampRecord;
111
- getRelativeTime: (name: string) => import("@agoric/time/src/types.js").RelativeTimeRecord;
112
- getUnknown: (name: string) => any;
113
- getSubscription: () => StoredSubscription<GovernanceSubscriptionState>;
114
- getGovernedParams: () => ERef<ParamStateRecord>;
115
- getMetrics(): Subscriber<MetricsNotification>;
116
- getPoolBalance(): Amount<any>;
117
- getPublicTopics(): {
118
- metrics: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<MetricsNotification>;
119
- };
120
- makeWantMintedInvitation(): Promise<Invitation<R, A>>;
121
- makeGiveMintedInvitation(): Promise<Invitation<R, A>>;
122
- } & import("@endo/eventual-send").RemotableBrand<{}, {
123
- getAmount: (name: string) => Amount<AssetKind>;
124
- getBrand: (name: string) => Brand<AssetKind>;
125
- getInstance: (name: string) => Instance;
126
- getInstallation: (name: string) => Installation<any>;
127
- getInvitationAmount: (name: string) => Amount<"set">;
128
- getNat: (name: string) => bigint;
129
- getRatio: (name: string) => Ratio;
130
- getString: (name: string) => string;
131
- getTimestamp: (name: string) => import("@agoric/time/src/types.js").TimestampRecord;
132
- getRelativeTime: (name: string) => import("@agoric/time/src/types.js").RelativeTimeRecord;
133
- getUnknown: (name: string) => any;
134
- getSubscription: () => StoredSubscription<GovernanceSubscriptionState>;
135
- getGovernedParams: () => ERef<ParamStateRecord>;
136
- getMetrics(): Subscriber<MetricsNotification>;
137
- getPoolBalance(): Amount<any>;
138
- getPublicTopics(): {
139
- metrics: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<MetricsNotification>;
140
- };
141
- makeWantMintedInvitation(): Promise<Invitation<R, A>>;
142
- makeGiveMintedInvitation(): Promise<Invitation<R, A>>;
143
- }>;
144
- }>;
145
- /**
146
- * Metrics naming scheme is that nouns are
147
- * present values and past-participles are accumulative.
148
- */
149
- export type MetricsNotification = {
150
- /**
151
- * amount of Anchor token available
152
- * to be swapped
153
- */
154
- anchorPoolBalance: Amount<'nat'>;
155
- /**
156
- * amount of Minted token
157
- * outstanding (the amount minted minus the amount burned).
158
- */
159
- mintedPoolBalance: Amount<'nat'>;
160
- /**
161
- * amount of Minted token fees
162
- * available to be collected
163
- */
164
- feePoolBalance: Amount<'nat'>;
165
- /**
166
- * running sum of Anchor ever
167
- * given by this contract
168
- */
169
- totalAnchorProvided: Amount<'nat'>;
170
- /**
171
- * running sum of Minted ever
172
- * given by this contract
173
- */
174
- totalMintedProvided: Amount<'nat'>;
175
- };
176
- export type Baggage = import('@agoric/vat-data').Baggage;
177
- export type PsmPublicFacet = Awaited<ReturnType<typeof start>>['publicFacet'];
178
- //# sourceMappingURL=psm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"psm.d.ts","sourceRoot":"","sources":["psm.js"],"names":[],"mappings":"AAyCA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AAEH,4DAA4D;AAE5D,2BAA2B;AAC3B,mBADW,YAAY,CAkCrB;AAsBK;mBAhBe,OAAO;mBACP,OAAO;eACX,QAAQ;;iBAEN,MAAM,KAAK,CAAC;qBACR,KAAK;iBAGlB;IACV,aAAiB,EAAE,aAAa,CAAC;IACjC,sBAA0B,EAAE,UAAU,CAAC;IACvC,WAAe,EAAE,WAAW,CAAC;IAC7B,UAAc,EAAE,UAAU,CAAC;CACxB,WACO,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsUjB;;;;;;;;;;uBA1Ya,OAAO,KAAK,CAAC;;;;;uBAEb,OAAO,KAAK,CAAC;;;;;oBAEb,OAAO,KAAK,CAAC;;;;;yBAEb,OAAO,KAAK,CAAC;;;;;yBAEb,OAAO,KAAK,CAAC;;sBAIb,OAAO,kBAAkB,EAAE,OAAO;6BAiYlC,QAAQ,WAAW,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC"}
@@ -1,2 +0,0 @@
1
- type PsmPublicFacet = import('./psm').PsmPublicFacet;
2
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"sBAEc,OAAO,OAAO,EAAE,cAAc"}
@@ -1,44 +0,0 @@
1
- /** @type {ContractMeta} */
2
- export const meta: ContractMeta;
3
- export function start(zcf: ZCF<GovernanceTerms<{}> & {
4
- governedApis: ['burnFeesToReduceShortfall'];
5
- }>, privateArgs: {
6
- feeMintAccess: FeeMintAccess;
7
- initialPoserInvitation: Invitation;
8
- marshaller: ERef<Marshaller>;
9
- storageNode: ERef<StorageNode>;
10
- }, baggage: Baggage): Promise<{
11
- /** @type {GovernedCreatorFacet<typeof assetReserveKit.machine>} */
12
- creatorFacet: GovernedCreatorFacet<{
13
- addIssuer(issuer: Issuer<AssetKind>, keyword: string): Promise<void>;
14
- getAllocations(): AmountKeywordRecord;
15
- makeShortfallReportingInvitation(): Promise<Invitation<R, A>>;
16
- }>;
17
- /** @type {GovernedPublicFacet<typeof assetReserveKit.public>} */
18
- publicFacet: GovernedPublicFacet<{
19
- makeAddCollateralInvitation(): Promise<Invitation<R, A>>;
20
- getPublicTopics(): {
21
- metrics: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<import("./assetReserveKit.js").MetricsNotification>;
22
- };
23
- }>;
24
- }>;
25
- export type ShortfallReportingFacet = {
26
- increaseLiquidationShortfall: (increase: Amount) => void;
27
- reduceLiquidationShortfall: (reduction: Amount) => void;
28
- };
29
- export type Baggage = import('@agoric/vat-data').Baggage;
30
- export type ShortfallReporter = {
31
- increaseLiquidationShortfall: (shortfall: Amount) => void;
32
- reduceLiquidationShortfall: (shortfall: Amount) => void;
33
- };
34
- export type AssetReserveLimitedCreatorFacet = {
35
- addIssuer: (issuer: Issuer, kwd: string) => void;
36
- getAllocations: () => Allocation;
37
- makeShortfallReportingInvitation: () => Promise<Invitation<ShortfallReporter>>;
38
- };
39
- export type AssetReservePublicFacet = Awaited<ReturnType<typeof start>>['publicFacet'];
40
- /**
41
- * the creator facet for the governor
42
- */
43
- export type AssetReserveCreatorFacet = Awaited<ReturnType<typeof start>>['creatorFacet'];
44
- //# sourceMappingURL=assetReserve.d.ts.map