@agoric/vats 0.15.2-dev-ecf2d8e.0 → 0.15.2-other-dev-70beeb7.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.
- package/CHANGELOG.md +9 -0
- package/decentral-core-config.json +66 -0
- package/decentral-demo-config.json +155 -0
- package/decentral-devnet-config.json +216 -0
- package/decentral-itest-vaults-config.json +210 -0
- package/decentral-main-vaults-config.json +229 -0
- package/decentral-test-vaults-config.json +195 -0
- package/demo-proposals.json +5 -0
- package/exported.js +1 -1
- package/jsconfig.build.json +12 -0
- package/{tsconfig.json → jsconfig.json} +0 -3
- package/package.json +42 -32
- package/scripts/build-bundles.d.ts +3 -0
- package/scripts/build-bundles.d.ts.map +1 -0
- package/scripts/build-bundles.js +3 -8
- package/scripts/build-game1-start.d.ts +5 -0
- package/scripts/build-game1-start.d.ts.map +1 -0
- package/scripts/build-game1-start.js +34 -0
- package/scripts/build-walletFactory-upgrade.d.ts +5 -0
- package/scripts/build-walletFactory-upgrade.d.ts.map +1 -0
- package/scripts/build-walletFactory-upgrade.js +35 -0
- package/scripts/init-core.d.ts +5 -0
- package/scripts/init-core.d.ts.map +1 -0
- package/scripts/init-core.js +31 -0
- package/scripts/init-network.d.ts +5 -0
- package/scripts/init-network.d.ts.map +1 -0
- package/scripts/init-network.js +19 -0
- package/scripts/restart-vats.d.ts +5 -0
- package/scripts/restart-vats.d.ts.map +1 -0
- package/scripts/restart-vats.js +23 -0
- package/scripts/set-core-proposal-env.d.ts +3 -0
- package/scripts/set-core-proposal-env.d.ts.map +1 -0
- package/scripts/set-core-proposal-env.js +37 -0
- package/src/bridge.d.ts +3 -12
- package/src/bridge.d.ts.map +1 -1
- package/src/bridge.js +12 -24
- package/src/centralSupply.d.ts.map +1 -1
- package/src/centralSupply.js +3 -3
- package/src/core/basic-behaviors.d.ts +7 -7
- package/src/core/basic-behaviors.d.ts.map +1 -1
- package/src/core/basic-behaviors.js +50 -56
- package/src/core/boot-chain.d.ts +1 -1
- package/src/core/boot-chain.js +3 -3
- package/src/core/boot-sim.js +3 -3
- package/src/core/boot-solo.js +4 -4
- package/src/core/chain-behaviors.d.ts.map +1 -1
- package/src/core/chain-behaviors.js +23 -29
- package/src/core/client-behaviors.d.ts.map +1 -1
- package/src/core/client-behaviors.js +4 -5
- package/src/core/demoIssuers.d.ts +15 -17
- package/src/core/demoIssuers.d.ts.map +1 -1
- package/src/core/demoIssuers.js +36 -36
- package/src/core/lib-boot.d.ts +9 -11
- package/src/core/lib-boot.d.ts.map +1 -1
- package/src/core/lib-boot.js +22 -32
- package/src/core/promise-space.d.ts.map +1 -1
- package/src/core/promise-space.js +14 -14
- package/src/core/sim-behaviors.d.ts +1 -1
- package/src/core/sim-behaviors.d.ts.map +1 -1
- package/src/core/startWalletFactory.d.ts +62 -9
- package/src/core/startWalletFactory.d.ts.map +1 -1
- package/src/core/startWalletFactory.js +17 -26
- package/src/core/types.d.ts +820 -0
- package/src/core/types.d.ts.map +1 -0
- package/src/core/types.js +347 -0
- package/src/core/utils.d.ts +16 -18
- package/src/core/utils.d.ts.map +1 -1
- package/src/core/utils.js +30 -32
- package/src/crc.d.ts +6 -2
- package/src/crc.d.ts.map +1 -1
- package/src/crc.js +15 -5
- package/src/ibc.d.ts +5 -5
- package/src/ibc.d.ts.map +1 -1
- package/src/ibc.js +47 -27
- package/src/lib-board.d.ts +50 -49
- package/src/lib-board.d.ts.map +1 -1
- package/src/lib-board.js +39 -32
- package/src/mintHolder.d.ts +1 -3
- package/src/mintHolder.d.ts.map +1 -1
- package/src/mintHolder.js +8 -13
- package/src/nameHub.d.ts +2 -18
- package/src/nameHub.d.ts.map +1 -1
- package/src/nameHub.js +17 -26
- package/src/proposals/network-proposal.d.ts.map +1 -1
- package/src/proposals/network-proposal.js +12 -15
- package/src/proposals/restart-vats-proposal.d.ts +1 -1
- package/src/proposals/restart-vats-proposal.d.ts.map +1 -1
- package/src/proposals/restart-vats-proposal.js +5 -3
- package/src/provisionPool.d.ts +164 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +113 -0
- package/src/provisionPoolKit.d.ts +408 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +464 -0
- package/src/repl.js +1 -1
- package/src/tokens.d.ts +36 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +37 -0
- package/src/types.d.ts +103 -84
- package/src/types.d.ts.map +1 -0
- package/src/types.js +97 -1
- package/src/vat-agoricNames.d.ts +1 -1
- package/src/vat-agoricNames.d.ts.map +1 -1
- package/src/vat-agoricNames.js +3 -2
- package/src/vat-bank.d.ts +58 -62
- package/src/vat-bank.d.ts.map +1 -1
- package/src/vat-bank.js +54 -62
- package/src/vat-board.d.ts +1 -1
- package/src/vat-bridge.d.ts +30 -2
- package/src/vat-bridge.d.ts.map +1 -1
- package/src/vat-mints.d.ts +12 -12
- package/src/vat-mints.d.ts.map +1 -1
- package/src/vat-mints.js +6 -6
- package/src/vat-network.d.ts +1 -1
- package/src/vat-network.d.ts.map +1 -1
- package/src/vat-network.js +1 -1
- package/src/vat-priceAuthority.d.ts +1 -1
- package/src/vat-provisioning.d.ts +1 -1
- package/src/vat-provisioning.d.ts.map +1 -1
- package/src/vat-provisioning.js +7 -11
- package/src/vat-sharing.d.ts +54 -0
- package/src/vat-sharing.d.ts.map +1 -0
- package/src/vat-sharing.js +14 -0
- package/src/vat-zoe.d.ts +0 -2
- package/src/vat-zoe.d.ts.map +1 -1
- package/src/vat-zoe.js +2 -8
- package/src/virtual-purse.d.ts +12 -37
- package/src/virtual-purse.d.ts.map +1 -1
- package/src/virtual-purse.js +36 -38
- package/src/walletFlags.d.ts +2 -2
- package/src/walletFlags.js +2 -1
- package/tools/authorityViz.d.ts +27 -0
- package/tools/authorityViz.d.ts.map +1 -0
- package/tools/authorityViz.js +272 -0
- package/tools/bank-utils.d.ts +1 -1
- package/tools/bank-utils.d.ts.map +1 -1
- package/tools/bank-utils.js +5 -12
- package/tools/board-utils.d.ts +19 -5
- package/tools/board-utils.d.ts.map +1 -1
- package/tools/board-utils.js +81 -29
- package/tools/boot-test-utils.d.ts +10 -9
- package/tools/boot-test-utils.d.ts.map +1 -1
- package/tools/boot-test-utils.js +16 -6
- package/tools/viz.mk +17 -0
- package/index.js +0 -11
- package/src/core/types-ambient.d.ts +0 -475
- package/src/core/types-ambient.js +0 -1
- package/src/proposals/zcf-proposal.d.ts +0 -30
- package/src/proposals/zcf-proposal.d.ts.map +0 -1
- package/src/proposals/zcf-proposal.js +0 -45
- package/tsconfig.build.json +0 -6
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { AmountMath, BrandShape } from '@agoric/ertp';
|
|
3
|
+
import { UnguardedHelperI } from '@agoric/inter-protocol/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 {
|
|
16
|
+
makeRecorderTopic,
|
|
17
|
+
PublicTopicShape,
|
|
18
|
+
} from '@agoric/zoe/src/contractSupport/topics.js';
|
|
19
|
+
import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
|
|
20
|
+
import { E } from '@endo/far';
|
|
21
|
+
import { deeplyFulfilled, Far } from '@endo/marshal';
|
|
22
|
+
import { PowerFlags } from './walletFlags.js';
|
|
23
|
+
|
|
24
|
+
const { details: X, quote: q, Fail } = assert;
|
|
25
|
+
|
|
26
|
+
/** @typedef {import('@agoric/zoe/src/zoeService/utils').Instance<import('@agoric/inter-protocol/src/psm/psm.js').prepare>} PsmInstance */
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} ProvisionPoolKitReferences
|
|
30
|
+
* @property {ERef<BankManager>} bankManager
|
|
31
|
+
* @property {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
|
|
32
|
+
* @property {ERef<import('@agoric/vats/src/core/startWalletFactory').WalletFactoryStartResult['creatorFacet']>} walletFactory
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {object} MetricsNotification
|
|
37
|
+
* Metrics naming scheme is that nouns are present values and past-participles
|
|
38
|
+
* are accumulative.
|
|
39
|
+
*
|
|
40
|
+
* @property {bigint} walletsProvisioned count of new wallets provisioned
|
|
41
|
+
* @property {Amount<'nat'>} totalMintedProvided running sum of Minted provided to new wallets
|
|
42
|
+
* @property {Amount<'nat'>} totalMintedConverted running sum of Minted
|
|
43
|
+
* ever received by the contract from PSM
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Given attenuated access to the funding purse,
|
|
48
|
+
* handle requests to provision smart wallets.
|
|
49
|
+
*
|
|
50
|
+
* @param {(depositBank: ERef<Bank>) => Promise<void>} sendInitialPayment
|
|
51
|
+
* @param {() => void} onProvisioned
|
|
52
|
+
* @typedef {import('./vat-bank.js').Bank} Bank
|
|
53
|
+
*/
|
|
54
|
+
export const makeBridgeProvisionTool = (sendInitialPayment, onProvisioned) => {
|
|
55
|
+
/**
|
|
56
|
+
* @param {ProvisionPoolKitReferences} refs
|
|
57
|
+
*/
|
|
58
|
+
const makeBridgeHandler = ({
|
|
59
|
+
bankManager,
|
|
60
|
+
namesByAddressAdmin,
|
|
61
|
+
walletFactory,
|
|
62
|
+
}) =>
|
|
63
|
+
Far('provisioningHandler', {
|
|
64
|
+
fromBridge: async obj => {
|
|
65
|
+
obj.type === 'PLEASE_PROVISION' ||
|
|
66
|
+
Fail`Unrecognized request ${obj.type}`;
|
|
67
|
+
console.info('PLEASE_PROVISION', obj);
|
|
68
|
+
const { address, powerFlags } = obj;
|
|
69
|
+
powerFlags.includes(PowerFlags.SMART_WALLET) ||
|
|
70
|
+
Fail`missing SMART_WALLET in powerFlags`;
|
|
71
|
+
|
|
72
|
+
const bank = E(bankManager).getBankForAddress(address);
|
|
73
|
+
// only proceed if we can provide funds
|
|
74
|
+
await sendInitialPayment(bank);
|
|
75
|
+
|
|
76
|
+
const [_, created] = await E(walletFactory).provideSmartWallet(
|
|
77
|
+
address,
|
|
78
|
+
bank,
|
|
79
|
+
namesByAddressAdmin,
|
|
80
|
+
);
|
|
81
|
+
if (created) {
|
|
82
|
+
onProvisioned();
|
|
83
|
+
}
|
|
84
|
+
console.info(created ? 'provisioned' : 're-provisioned', address);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return makeBridgeHandler;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
92
|
+
* @param {{
|
|
93
|
+
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit,
|
|
94
|
+
* params: *,
|
|
95
|
+
* poolBank: import('@endo/far').ERef<Bank>,
|
|
96
|
+
* zcf: ZCF,
|
|
97
|
+
* }} powers
|
|
98
|
+
*/
|
|
99
|
+
export const prepareProvisionPoolKit = (
|
|
100
|
+
baggage,
|
|
101
|
+
{ makeRecorderKit, params, poolBank, zcf },
|
|
102
|
+
) => {
|
|
103
|
+
const zoe = zcf.getZoeService();
|
|
104
|
+
|
|
105
|
+
const makeProvisionPoolKitInternal = prepareExoClassKit(
|
|
106
|
+
baggage,
|
|
107
|
+
'ProvisionPoolKit',
|
|
108
|
+
{
|
|
109
|
+
machine: M.interface('ProvisionPoolKit machine', {
|
|
110
|
+
addRevivableAddresses: M.call(M.arrayOf(M.string())).returns(),
|
|
111
|
+
getWalletReviver: M.call().returns(
|
|
112
|
+
M.remotable('ProvisionPoolKit wallet reviver'),
|
|
113
|
+
),
|
|
114
|
+
setReferences: M.callWhen({
|
|
115
|
+
bankManager: M.eref(M.remotable('bankManager')),
|
|
116
|
+
namesByAddressAdmin: M.eref(M.remotable('nameAdmin')),
|
|
117
|
+
walletFactory: M.eref(M.remotable('walletFactory')),
|
|
118
|
+
}).returns(),
|
|
119
|
+
makeHandler: M.call().returns(M.remotable('BridgeHandler')),
|
|
120
|
+
initPSM: M.call(BrandShape, InstanceHandleShape).returns(),
|
|
121
|
+
}),
|
|
122
|
+
walletReviver: M.interface('ProvisionPoolKit wallet reviver', {
|
|
123
|
+
reviveWallet: M.callWhen(M.string()).returns(
|
|
124
|
+
M.remotable('SmartWallet'),
|
|
125
|
+
),
|
|
126
|
+
ackWallet: M.call(M.string()).returns(M.boolean()),
|
|
127
|
+
}),
|
|
128
|
+
helper: UnguardedHelperI,
|
|
129
|
+
public: M.interface('ProvisionPoolKit public', {
|
|
130
|
+
getPublicTopics: M.call().returns({ metrics: PublicTopicShape }),
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* @param {object} opts
|
|
135
|
+
* @param {Purse<'nat'>} opts.fundPurse
|
|
136
|
+
* @param {Brand} opts.poolBrand
|
|
137
|
+
* @param {StorageNode} opts.metricsNode
|
|
138
|
+
*/
|
|
139
|
+
({ fundPurse, poolBrand, metricsNode }) => {
|
|
140
|
+
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification>} */
|
|
141
|
+
const metricsRecorderKit = makeRecorderKit(metricsNode);
|
|
142
|
+
|
|
143
|
+
/** @type {MapStore<Brand, PsmInstance>} */
|
|
144
|
+
const brandToPSM = makeScalarBigMapStore('brandToPSM', { durable: true });
|
|
145
|
+
const revivableAddresses = makeScalarBigSetStore('revivableAddresses', {
|
|
146
|
+
durable: true,
|
|
147
|
+
keyShape: M.string(),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* to be set by `setReferences`
|
|
152
|
+
*
|
|
153
|
+
* @type {Partial<ProvisionPoolKitReferences>}
|
|
154
|
+
*/
|
|
155
|
+
const references = {
|
|
156
|
+
bankManager: undefined,
|
|
157
|
+
namesByAddressAdmin: undefined,
|
|
158
|
+
walletFactory: undefined,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
brandToPSM,
|
|
163
|
+
fundPurse,
|
|
164
|
+
metricsRecorderKit,
|
|
165
|
+
poolBrand,
|
|
166
|
+
walletsProvisioned: 0n,
|
|
167
|
+
totalMintedProvided: AmountMath.makeEmpty(poolBrand),
|
|
168
|
+
totalMintedConverted: AmountMath.makeEmpty(poolBrand),
|
|
169
|
+
revivableAddresses,
|
|
170
|
+
...references,
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
// aka "limitedCreatorFacet"
|
|
175
|
+
machine: {
|
|
176
|
+
/**
|
|
177
|
+
* @param {string[]} oldAddresses
|
|
178
|
+
*/
|
|
179
|
+
addRevivableAddresses(oldAddresses) {
|
|
180
|
+
console.log('revivableAddresses count', oldAddresses.length);
|
|
181
|
+
this.state.revivableAddresses.addAll(oldAddresses);
|
|
182
|
+
},
|
|
183
|
+
getWalletReviver() {
|
|
184
|
+
return this.facets.walletReviver;
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* @param {ProvisionPoolKitReferences} erefs
|
|
188
|
+
*/
|
|
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
|
+
/**
|
|
299
|
+
*
|
|
300
|
+
* @param {ERef<Bank>} destBank
|
|
301
|
+
*/
|
|
302
|
+
async sendInitialPayment(destBank) {
|
|
303
|
+
const {
|
|
304
|
+
facets: { helper },
|
|
305
|
+
state: { fundPurse, poolBrand },
|
|
306
|
+
} = this;
|
|
307
|
+
const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
|
|
308
|
+
params.getPerAccountInitialAmount()
|
|
309
|
+
);
|
|
310
|
+
const initialPmt = await E(fundPurse).withdraw(
|
|
311
|
+
perAccountInitialAmount,
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
const destPurse = E(destBank).getPurse(poolBrand);
|
|
315
|
+
return E(destPurse)
|
|
316
|
+
.deposit(initialPmt)
|
|
317
|
+
.then(amt => {
|
|
318
|
+
helper.onSendFunds(perAccountInitialAmount);
|
|
319
|
+
console.log('provisionPool sent', amt);
|
|
320
|
+
})
|
|
321
|
+
.catch(reason => {
|
|
322
|
+
console.error(X`initial deposit failed: ${q(reason)}`);
|
|
323
|
+
void E(fundPurse).deposit(initialPmt);
|
|
324
|
+
throw reason;
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* @param {object} [options]
|
|
329
|
+
* @param {MetricsNotification} [options.metrics]
|
|
330
|
+
*/
|
|
331
|
+
start({ metrics } = {}) {
|
|
332
|
+
const {
|
|
333
|
+
state: { brandToPSM, poolBrand },
|
|
334
|
+
facets: { helper },
|
|
335
|
+
} = this;
|
|
336
|
+
|
|
337
|
+
// Must match. poolBrand is from durable state and the param is from
|
|
338
|
+
// the contract, so it technically can change between incarnations.
|
|
339
|
+
// That would be a severe bug.
|
|
340
|
+
AmountMath.coerce(poolBrand, params.getPerAccountInitialAmount());
|
|
341
|
+
|
|
342
|
+
void observeIteration(
|
|
343
|
+
subscribeEach(E(poolBank).getAssetSubscription()),
|
|
344
|
+
{
|
|
345
|
+
updateState: async desc => {
|
|
346
|
+
console.log('provisionPool notified of new asset', desc.brand);
|
|
347
|
+
await zcf.saveIssuer(desc.issuer, desc.issuerName);
|
|
348
|
+
/** @type {ERef<Purse>} */
|
|
349
|
+
// @ts-expect-error vbank purse is close enough for our use.
|
|
350
|
+
const exchangePurse = E(poolBank).getPurse(desc.brand);
|
|
351
|
+
void observeNotifier(
|
|
352
|
+
E(exchangePurse).getCurrentAmountNotifier(),
|
|
353
|
+
{
|
|
354
|
+
updateState: async amount => {
|
|
355
|
+
console.log('provisionPool balance update', amount);
|
|
356
|
+
if (
|
|
357
|
+
AmountMath.isEmpty(amount) ||
|
|
358
|
+
amount.brand === poolBrand
|
|
359
|
+
) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (!brandToPSM.has(desc.brand)) {
|
|
363
|
+
console.error(
|
|
364
|
+
'funds arrived but no PSM instance',
|
|
365
|
+
desc.brand,
|
|
366
|
+
);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const instance = brandToPSM.get(desc.brand);
|
|
370
|
+
const payment = E(exchangePurse).withdraw(amount);
|
|
371
|
+
await helper
|
|
372
|
+
.swap(payment, amount, instance)
|
|
373
|
+
.catch(async reason => {
|
|
374
|
+
console.error(X`swap failed: ${reason}`);
|
|
375
|
+
const resolvedPayment = await payment;
|
|
376
|
+
return E(exchangePurse).deposit(resolvedPayment);
|
|
377
|
+
});
|
|
378
|
+
},
|
|
379
|
+
fail: reason => console.error(reason),
|
|
380
|
+
},
|
|
381
|
+
);
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
if (metrics) {
|
|
387
|
+
// Restore state.
|
|
388
|
+
// we publishMetrics() below
|
|
389
|
+
const {
|
|
390
|
+
walletsProvisioned,
|
|
391
|
+
totalMintedProvided,
|
|
392
|
+
totalMintedConverted,
|
|
393
|
+
} = metrics;
|
|
394
|
+
assert.typeof(walletsProvisioned, 'bigint');
|
|
395
|
+
AmountMath.coerce(poolBrand, totalMintedProvided);
|
|
396
|
+
AmountMath.coerce(poolBrand, totalMintedConverted);
|
|
397
|
+
Object.assign(this.state, {
|
|
398
|
+
walletsProvisioned,
|
|
399
|
+
totalMintedProvided,
|
|
400
|
+
totalMintedConverted,
|
|
401
|
+
});
|
|
402
|
+
helper.publishMetrics();
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
/**
|
|
406
|
+
* @param {ERef<Payment>} payIn
|
|
407
|
+
* @param {Amount} amount
|
|
408
|
+
* @param {PsmInstance} instance
|
|
409
|
+
*/
|
|
410
|
+
async swap(payIn, amount, instance) {
|
|
411
|
+
const {
|
|
412
|
+
facets: { helper },
|
|
413
|
+
state: { fundPurse },
|
|
414
|
+
} = this;
|
|
415
|
+
const psmPub = E(zoe).getPublicFacet(instance);
|
|
416
|
+
const proposal = harden({ give: { In: amount } });
|
|
417
|
+
const invitation = E(psmPub).makeWantMintedInvitation();
|
|
418
|
+
const seat = E(zoe).offer(invitation, proposal, { In: payIn });
|
|
419
|
+
const payout = await E(seat).getPayout('Out');
|
|
420
|
+
const rxd = await E(fundPurse).deposit(payout);
|
|
421
|
+
helper.onTrade(rxd);
|
|
422
|
+
return rxd;
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
public: {
|
|
426
|
+
getPublicTopics() {
|
|
427
|
+
return {
|
|
428
|
+
metrics: makeRecorderTopic(
|
|
429
|
+
'Provision Pool metrics',
|
|
430
|
+
this.state.metricsRecorderKit,
|
|
431
|
+
),
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
finish: ({ facets }) => {
|
|
438
|
+
facets.helper.publishMetrics();
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Prepare synchronous values before passing to real Exo maker
|
|
445
|
+
*
|
|
446
|
+
* @param {object} opts
|
|
447
|
+
* @param {Brand} opts.poolBrand
|
|
448
|
+
* @param {ERef<StorageNode>} opts.storageNode
|
|
449
|
+
*/
|
|
450
|
+
const makeProvisionPoolKit = async ({ poolBrand, storageNode }) => {
|
|
451
|
+
/** @type {Purse<'nat'>} */
|
|
452
|
+
// @ts-expect-error vbank purse is close enough for our use.
|
|
453
|
+
const fundPurse = await E(poolBank).getPurse(poolBrand);
|
|
454
|
+
const metricsNode = await E(storageNode).makeChildNode('metrics');
|
|
455
|
+
|
|
456
|
+
return makeProvisionPoolKitInternal({
|
|
457
|
+
fundPurse,
|
|
458
|
+
poolBrand,
|
|
459
|
+
metricsNode,
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
return makeProvisionPoolKit;
|
|
464
|
+
};
|
package/src/repl.js
CHANGED
|
@@ -74,7 +74,7 @@ function dump0(value, spaces, inProgress, depth) {
|
|
|
74
74
|
|
|
75
75
|
let sep = '';
|
|
76
76
|
let closer;
|
|
77
|
-
/** @type {
|
|
77
|
+
/** @type {Array<string | symbol>} */
|
|
78
78
|
const names = Object.getOwnPropertyNames(value);
|
|
79
79
|
const nonNumber = new Set(names);
|
|
80
80
|
if (Array.isArray(value)) {
|
package/src/tokens.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export namespace Stable {
|
|
2
|
+
export const symbol: "IST";
|
|
3
|
+
export const denom: "uist";
|
|
4
|
+
export const proposedName: "Agoric stable token";
|
|
5
|
+
export { NAT as assetKind };
|
|
6
|
+
export namespace displayInfo {
|
|
7
|
+
export const decimalPlaces: 6;
|
|
8
|
+
export { NAT as assetKind };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export namespace Stake {
|
|
12
|
+
const symbol_1: "BLD";
|
|
13
|
+
export { symbol_1 as symbol };
|
|
14
|
+
const denom_1: "ubld";
|
|
15
|
+
export { denom_1 as denom };
|
|
16
|
+
const proposedName_1: "Agoric staking token";
|
|
17
|
+
export { proposedName_1 as proposedName };
|
|
18
|
+
export { NAT as assetKind };
|
|
19
|
+
export namespace displayInfo_1 {
|
|
20
|
+
const decimalPlaces_1: 6;
|
|
21
|
+
export { decimalPlaces_1 as decimalPlaces };
|
|
22
|
+
export { NAT as assetKind };
|
|
23
|
+
}
|
|
24
|
+
export { displayInfo_1 as displayInfo };
|
|
25
|
+
}
|
|
26
|
+
export type TokenKeyword = 'IST' | 'BLD';
|
|
27
|
+
/** @typedef { 'IST' | 'BLD' } TokenKeyword */
|
|
28
|
+
/**
|
|
29
|
+
* Use static type check and unit tests rather than runtime import
|
|
30
|
+
* to avoid bundling all of ERTP just to get Stable.symbol.
|
|
31
|
+
*
|
|
32
|
+
* @type {typeof import('@agoric/ertp').AssetKind.NAT}
|
|
33
|
+
*/
|
|
34
|
+
declare const NAT: typeof import('@agoric/ertp').AssetKind.NAT;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;2BAEe,KAAK,GAAG,KAAK;AAA5B,8CAA8C;AAE9C;;;;;GAKG;AACH,mBAFU,cAAc,cAAc,EAAE,SAAS,CAAC,GAAG,CAEnC"}
|
package/src/tokens.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** @typedef { 'IST' | 'BLD' } TokenKeyword */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use static type check and unit tests rather than runtime import
|
|
7
|
+
* to avoid bundling all of ERTP just to get Stable.symbol.
|
|
8
|
+
*
|
|
9
|
+
* @type {typeof import('@agoric/ertp').AssetKind.NAT}
|
|
10
|
+
*/
|
|
11
|
+
const NAT = 'nat';
|
|
12
|
+
|
|
13
|
+
export const Stable = harden(
|
|
14
|
+
/** @type {const } */ ({
|
|
15
|
+
symbol: 'IST',
|
|
16
|
+
denom: 'uist',
|
|
17
|
+
proposedName: 'Agoric stable token',
|
|
18
|
+
assetKind: NAT,
|
|
19
|
+
displayInfo: {
|
|
20
|
+
decimalPlaces: 6,
|
|
21
|
+
assetKind: NAT,
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const Stake = harden(
|
|
27
|
+
/** @type {const } */ ({
|
|
28
|
+
symbol: 'BLD',
|
|
29
|
+
denom: 'ubld',
|
|
30
|
+
proposedName: 'Agoric staking token',
|
|
31
|
+
assetKind: NAT,
|
|
32
|
+
displayInfo: {
|
|
33
|
+
decimalPlaces: 6,
|
|
34
|
+
assetKind: NAT,
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
);
|