@agoric/inter-protocol 0.16.2-dev-3294e0c.0.3294e0c → 0.16.2-dev-488dec7.0.488dec7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/inter-protocol",
3
- "version": "0.16.2-dev-3294e0c.0.3294e0c",
3
+ "version": "0.16.2-dev-488dec7.0.488dec7",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -16,7 +16,7 @@
16
16
  "lint-fix": "yarn lint:eslint --fix",
17
17
  "lint": "yarn run -T run-s --continue-on-error 'lint:*'",
18
18
  "lint:eslint": "node ../../scripts/eslint-repo.mjs .",
19
- "lint:types": "yarn run -T tsc"
19
+ "lint:types": "yarn run -T tsgo --tsBuildInfoFile tsconfig.tsgo.tsbuildinfo"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -29,17 +29,17 @@
29
29
  },
30
30
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
31
31
  "dependencies": {
32
- "@agoric/base-zone": "0.1.1-dev-3294e0c.0.3294e0c",
33
- "@agoric/ertp": "0.16.3-dev-3294e0c.0.3294e0c",
34
- "@agoric/governance": "0.10.4-dev-3294e0c.0.3294e0c",
35
- "@agoric/internal": "0.3.3-dev-3294e0c.0.3294e0c",
36
- "@agoric/notifier": "0.6.3-dev-3294e0c.0.3294e0c",
37
- "@agoric/store": "0.9.3-dev-3294e0c.0.3294e0c",
38
- "@agoric/time": "0.3.3-dev-3294e0c.0.3294e0c",
39
- "@agoric/vat-data": "0.5.3-dev-3294e0c.0.3294e0c",
40
- "@agoric/vats": "0.15.2-dev-3294e0c.0.3294e0c",
41
- "@agoric/zoe": "0.26.3-dev-3294e0c.0.3294e0c",
42
- "@agoric/zone": "0.2.3-dev-3294e0c.0.3294e0c",
32
+ "@agoric/base-zone": "0.1.1-dev-488dec7.0.488dec7",
33
+ "@agoric/ertp": "0.16.3-dev-488dec7.0.488dec7",
34
+ "@agoric/governance": "0.10.4-dev-488dec7.0.488dec7",
35
+ "@agoric/internal": "0.3.3-dev-488dec7.0.488dec7",
36
+ "@agoric/notifier": "0.6.3-dev-488dec7.0.488dec7",
37
+ "@agoric/store": "0.9.3-dev-488dec7.0.488dec7",
38
+ "@agoric/time": "0.3.3-dev-488dec7.0.488dec7",
39
+ "@agoric/vat-data": "0.5.3-dev-488dec7.0.488dec7",
40
+ "@agoric/vats": "0.15.2-dev-488dec7.0.488dec7",
41
+ "@agoric/zoe": "0.26.3-dev-488dec7.0.488dec7",
42
+ "@agoric/zone": "0.2.3-dev-488dec7.0.488dec7",
43
43
  "@endo/captp": "^4.4.8",
44
44
  "@endo/errors": "^1.2.13",
45
45
  "@endo/eventual-send": "^1.3.4",
@@ -50,9 +50,9 @@
50
50
  "jessie.js": "^0.3.4"
51
51
  },
52
52
  "devDependencies": {
53
- "@agoric/smart-wallet": "0.5.4-dev-3294e0c.0.3294e0c",
54
- "@agoric/swingset-liveslots": "0.10.3-dev-3294e0c.0.3294e0c",
55
- "@agoric/swingset-vat": "0.32.3-dev-3294e0c.0.3294e0c",
53
+ "@agoric/smart-wallet": "0.5.4-dev-488dec7.0.488dec7",
54
+ "@agoric/swingset-liveslots": "0.10.3-dev-488dec7.0.488dec7",
55
+ "@agoric/swingset-vat": "0.32.3-dev-488dec7.0.488dec7",
56
56
  "@endo/bundle-source": "^4.1.2",
57
57
  "@endo/init": "^1.1.12",
58
58
  "@endo/promise-kit": "^1.1.13",
@@ -81,5 +81,5 @@
81
81
  "typeCoverage": {
82
82
  "atLeast": 95.3
83
83
  },
84
- "gitHead": "3294e0c1e81f8d145c6b57624d080908b935f524"
84
+ "gitHead": "488dec73a49f5a4fd66eea6521638ce5ba11dd2f"
85
85
  }
@@ -25,10 +25,8 @@ export const interProtocolBundleSpecs = {
25
25
  },
26
26
  provisionPool: {
27
27
  bundleName: 'provisionPool',
28
- packagePath: '@agoric/inter-protocol/src/provisionPool.js',
29
- sourceSpec: resolveSourceSpec(
30
- '@agoric/inter-protocol/src/provisionPool.js',
31
- ),
28
+ packagePath: '@agoric/vats/src/provisionPool.js',
29
+ sourceSpec: resolveSourceSpec('@agoric/vats/src/provisionPool.js'),
32
30
  },
33
31
  priceAggregator: {
34
32
  bundleName: 'priceAggregator',
@@ -16,7 +16,7 @@ import { makeGovernedTerms as makeGovernedVFTerms } from '../vaultFactory/params
16
16
  * @import {AdminFacet, Instance} from '@agoric/zoe';
17
17
  * @import {MapStore, SetStore} from '@agoric/store';
18
18
  * @import {RelativeTime} from '@agoric/time';
19
- * @import {WellKnownSpaces} from '@agoric/vats/src/core/types.js';
19
+ * @import {WellKnownSpaces, ContractInstallationPromises, ContractInstancePromises} from '@agoric/vats/src/core/types.js';
20
20
  * @import {ChainBootstrapSpace} from '@agoric/vats/src/core/types.js';
21
21
  * @import {PromiseSpaceOf} from '@agoric/vats/src/core/types.js';
22
22
  * @import {CommitteeElectorateCreatorFacet} from '@agoric/governance/src/committee.js';
@@ -62,7 +62,32 @@ export const SECONDS_PER_WEEK = 7n * SECONDS_PER_DAY;
62
62
  */
63
63
 
64
64
  /**
65
- * @typedef {WellKnownSpaces & ChainBootstrapSpace & EconomyBootstrapSpace} EconomyBootstrapPowers
65
+ * Contracts that Inter Protocol adds to the well-known spaces. Defined here
66
+ * rather than in @agoric/vats so that the base layer doesn't depend on this
67
+ * package.
68
+ *
69
+ * @typedef {{
70
+ * econCommitteeCharter: typeof import('../econCommitteeCharter.js').start;
71
+ * feeDistributor: typeof import('../feeDistributor.js').start;
72
+ * psm: typeof import('../psm/psm.js').start;
73
+ * priceAggregator: typeof import('../price/fluxAggregatorContract.js').start;
74
+ * reserve: typeof import('../reserve/assetReserve.js').start;
75
+ * VaultFactory: VFStart;
76
+ * }} EconContractStarts
77
+ *
78
+ * @typedef {{
79
+ * installation: {
80
+ * consume: ContractInstallationPromises<EconContractStarts>;
81
+ * };
82
+ * instance: {
83
+ * consume: ContractInstancePromises<EconContractStarts>;
84
+ * };
85
+ * }} EconContractSpaces
86
+ *
87
+ * @typedef {WellKnownSpaces &
88
+ * EconContractSpaces &
89
+ * ChainBootstrapSpace &
90
+ * EconomyBootstrapSpace} EconomyBootstrapPowers
66
91
  *
67
92
  *
68
93
  * @typedef {PromiseSpaceOf<{
@@ -105,7 +105,6 @@ export const startPSM = async (
105
105
  feeMintAccess: feeMintAccessP,
106
106
  economicCommitteeCreatorFacet,
107
107
  econCharterKit,
108
- provisionPoolStartResult,
109
108
  chainStorage,
110
109
  chainTimerService,
111
110
  psmKit,
@@ -285,10 +284,6 @@ export const startPSM = async (
285
284
  governorFacets.creatorFacet,
286
285
  instanceKey,
287
286
  ),
288
- E(E.get(provisionPoolStartResult).creatorFacet).initPSM(
289
- anchorBrand,
290
- newpsmKit.psm,
291
- ),
292
287
  ]);
293
288
  };
294
289
  harden(startPSM);
@@ -43,24 +43,24 @@ declare function prepareVaultDirector(baggage: Baggage, zcf: VaultFactoryZCF, di
43
43
  creator: {
44
44
  getParamMgrRetriever: () => {
45
45
  /** @param {VaultFactoryParamPath} paramPath */
46
- get: (paramPath?: VaultFactoryParamPath) => VaultDirectorParamManager | TypedParamManager<{
46
+ get: (paramPath?: VaultFactoryParamPath) => TypedParamManager<{
47
47
  DebtLimit: "amount";
48
48
  InterestRate: "ratio";
49
49
  LiquidationPadding: "ratio";
50
50
  LiquidationMargin: "ratio";
51
51
  LiquidationPenalty: "ratio";
52
52
  MintFee: "ratio";
53
- }>;
53
+ }> | VaultDirectorParamManager;
54
54
  } & import("@endo/marshal").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
55
55
  /** @param {VaultFactoryParamPath} paramPath */
56
- get: (paramPath?: VaultFactoryParamPath) => VaultDirectorParamManager | TypedParamManager<{
56
+ get: (paramPath?: VaultFactoryParamPath) => TypedParamManager<{
57
57
  DebtLimit: "amount";
58
58
  InterestRate: "ratio";
59
59
  LiquidationPadding: "ratio";
60
60
  LiquidationMargin: "ratio";
61
61
  LiquidationPenalty: "ratio";
62
62
  MintFee: "ratio";
63
- }>;
63
+ }> | VaultDirectorParamManager;
64
64
  }>;
65
65
  /** @param {string} name */
66
66
  getInvitation(name: string): Promise<import("@agoric/zoe").Invitation>;
@@ -20,23 +20,23 @@ export function start(zcf: VaultFactoryZCF, privateArgs: {
20
20
  }, baggage: Baggage): Promise<{
21
21
  creatorFacet: import("@endo/exo").Guarded<{
22
22
  getParamMgrRetriever: () => {
23
- get: (paramPath?: import("./types.js").VaultFactoryParamPath) => import("./vaultDirector.js").VaultDirectorParamManager | import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
23
+ get: (paramPath?: import("./types.js").VaultFactoryParamPath) => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
24
24
  DebtLimit: "amount";
25
25
  InterestRate: "ratio";
26
26
  LiquidationPadding: "ratio";
27
27
  LiquidationMargin: "ratio";
28
28
  LiquidationPenalty: "ratio";
29
29
  MintFee: "ratio";
30
- }>;
30
+ }> | import("./vaultDirector.js").VaultDirectorParamManager;
31
31
  } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
32
- get: (paramPath?: import("./types.js").VaultFactoryParamPath) => import("./vaultDirector.js").VaultDirectorParamManager | import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
32
+ get: (paramPath?: import("./types.js").VaultFactoryParamPath) => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
33
33
  DebtLimit: "amount";
34
34
  InterestRate: "ratio";
35
35
  LiquidationPadding: "ratio";
36
36
  LiquidationMargin: "ratio";
37
37
  LiquidationPenalty: "ratio";
38
38
  MintFee: "ratio";
39
- }>;
39
+ }> | import("./vaultDirector.js").VaultDirectorParamManager;
40
40
  }>;
41
41
  getInvitation(name: string): Promise<Invitation>;
42
42
  getLimitedCreatorFacet(): import("@endo/exo").Guarded<{
@@ -1,87 +0,0 @@
1
- /**
2
- * @import {Remote} from '@agoric/internal';
3
- * @import {Amount, Brand, Payment, Purse} from '@agoric/ertp';
4
- * @import {ContractMeta, Invitation, StandardTerms, ZCF} from '@agoric/zoe';
5
- * @import {GovernanceTerms} from '@agoric/governance/src/types.js';
6
- * @import {ERef} from '@endo/far';
7
- * @import {Bank} from '@agoric/vats/src/vat-bank.js';
8
- * @import {MetricsNotification} from './provisionPoolKit.js';
9
- * @import {Baggage} from '@agoric/vat-data';
10
- * @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
11
- * @import {Marshaller} from '@agoric/internal/src/lib-chainStorage.js';
12
- */
13
- /** @type {ContractMeta<typeof start>} */
14
- export const meta: ContractMeta<typeof start>;
15
- export function start(zcf: ZCF<ProvisionTerms>, privateArgs: {
16
- poolBank: ERef<Bank>;
17
- initialPoserInvitation: Invitation;
18
- storageNode: Remote<StorageNode>;
19
- marshaller: Remote<Marshaller>;
20
- metricsOverride?: MetricsNotification;
21
- governedParamOverrides?: Record<string, Amount | undefined>;
22
- }, baggage: Baggage): Promise<{
23
- creatorFacet: import("@endo/exo").Guarded<{
24
- getParamMgrRetriever: () => {
25
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
26
- PerAccountInitialAmount: "amount";
27
- } & {
28
- Electorate: "invitation";
29
- }>;
30
- } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
31
- get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
32
- PerAccountInitialAmount: "amount";
33
- } & {
34
- Electorate: "invitation";
35
- }>;
36
- }>;
37
- getInvitation: (name: any) => Promise<Invitation>;
38
- getLimitedCreatorFacet: () => {
39
- addRevivableAddresses: (oldAddresses: string[]) => void;
40
- getWalletReviver: () => ERef<any>;
41
- setReferences: (erefs: import("./provisionPoolKit.js").ProvisionPoolKitReferences) => Promise<void>;
42
- makeHandler: () => ERef<import("@agoric/vats").BridgeHandler>;
43
- initPSM: (brand: Brand, instance: import("@agoric/zoe/src/zoeService/utils.js").Instance<typeof import("./psm/psm.js").start>) => void;
44
- };
45
- getGovernedApis: () => import("@agoric/governance").GovernedApis;
46
- getGovernedApiNames: () => string[];
47
- setOfferFilter: (strings: any) => Promise<void>;
48
- }>;
49
- publicFacet: import("@endo/exo").Guarded<{
50
- getAmount: (name: string) => Amount;
51
- getBrand: (name: string) => Brand;
52
- getInstance: (name: string) => import("@agoric/zoe").Instance;
53
- getInstallation: (name: string) => import("@agoric/zoe").Installation;
54
- getInvitationAmount: (name: string) => import("@agoric/zoe").InvitationAmount;
55
- getNat: (name: string) => bigint;
56
- getRatio: (name: string) => import("@agoric/ertp").Ratio;
57
- getString: (name: string) => string;
58
- getTimestamp: (name: string) => import("@agoric/time").TimestampRecord;
59
- getRelativeTime: (name: string) => import("@agoric/time").RelativeTimeRecord;
60
- getUnknown: (name: string) => any;
61
- getSubscription: () => import("@agoric/notifier").StoredSubscription<import("@agoric/governance").GovernanceSubscriptionState>;
62
- getGovernedParams: () => ERef<import("@agoric/governance").ParamStateRecord>;
63
- getMetrics(): Promise<any>;
64
- getPublicTopics(): Promise<any>;
65
- }>;
66
- }>;
67
- /**
68
- * TODO: ERef<GovernedCreatorFacet<ProvisionCreator>>
69
- */
70
- export type ProvisionTerms = StandardTerms & GovernanceTerms<{
71
- PerAccountInitialAmount: "amount";
72
- }>;
73
- import type { ContractMeta } from '@agoric/zoe';
74
- import type { ZCF } from '@agoric/zoe';
75
- import type { Bank } from '@agoric/vats/src/vat-bank.js';
76
- import type { ERef } from '@endo/far';
77
- import type { Invitation } from '@agoric/zoe';
78
- import type { StorageNode } from '@agoric/internal/src/lib-chainStorage.js';
79
- import type { Remote } from '@agoric/internal';
80
- import type { Marshaller } from '@agoric/internal/src/lib-chainStorage.js';
81
- import type { MetricsNotification } from './provisionPoolKit.js';
82
- import type { Amount } from '@agoric/ertp';
83
- import type { Baggage } from '@agoric/vat-data';
84
- import type { Brand } from '@agoric/ertp';
85
- import type { StandardTerms } from '@agoric/zoe';
86
- import type { GovernanceTerms } from '@agoric/governance/src/types.js';
87
- //# sourceMappingURL=provisionPool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provisionPool.d.ts","sourceRoot":"","sources":["provisionPool.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;GAWG;AAEH,yCAAyC;AACzC,mBADW,aAAa,OAAO,KAAK,CAAC,CAgBnC;AAoBK,2BAXI,IAAI,cAAc,CAAC,eACnB;IACN,QAAQ,EAAE,KAAK,IAAI,CAAC,CAAC;IACrB,sBAAsB,EAAE,UAAU,CAAC;IACnC,WAAW,EAAE,OAAO,WAAW,CAAC,CAAC;IACjC,UAAU,EAAE,OAAO,UAAU,CAAC,CAAC;IAC/B,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC7D,WACO,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EjB;;;;6BA3FY,aAAa,GACzB,gBAAoB;IACd,uBAAuB,EAAE,QAAQ,CAAC;CACnC,CAAC;kCAjCwD,aAAa;yBAAb,aAAa;0BAGrD,8BAA8B;0BAD9B,WAAW;gCAF6B,aAAa;iCAM9C,0CAA0C;4BAR/C,kBAAkB;gCASd,0CAA0C;yCAHjC,uBAAuB;4BALb,cAAc;6BAMpC,kBAAkB;2BANI,cAAc;mCACC,aAAa;qCAC1C,iCAAiC"}
@@ -1,145 +0,0 @@
1
- import {
2
- handleParamGovernance,
3
- ParamTypes,
4
- publicMixinAPI,
5
- } from '@agoric/governance';
6
- import { InvitationShape } from '@agoric/governance/src/typeGuards.js';
7
- import { wrapRemoteMarshaller } from '@agoric/internal/src/marshal/wrap-marshaller.js';
8
- import { M } from '@agoric/store';
9
- import { prepareExo } from '@agoric/vat-data';
10
- import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js';
11
- import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
12
- import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/topics.js';
13
- import { makeDurableZone } from '@agoric/zone/durable.js';
14
- import {
15
- prepareBridgeProvisionTool,
16
- prepareProvisionPoolKit,
17
- } from './provisionPoolKit.js';
18
-
19
- /**
20
- * @import {Remote} from '@agoric/internal';
21
- * @import {Amount, Brand, Payment, Purse} from '@agoric/ertp';
22
- * @import {ContractMeta, Invitation, StandardTerms, ZCF} from '@agoric/zoe';
23
- * @import {GovernanceTerms} from '@agoric/governance/src/types.js';
24
- * @import {ERef} from '@endo/far';
25
- * @import {Bank} from '@agoric/vats/src/vat-bank.js';
26
- * @import {MetricsNotification} from './provisionPoolKit.js';
27
- * @import {Baggage} from '@agoric/vat-data';
28
- * @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
29
- * @import {Marshaller} from '@agoric/internal/src/lib-chainStorage.js';
30
- */
31
-
32
- /** @type {ContractMeta<typeof start>} */
33
- export const meta = {
34
- // @ts-expect-error splitRecord loses the property keys
35
- privateArgsShape: M.splitRecord(
36
- {
37
- poolBank: M.eref(M.remotable('bank')),
38
- storageNode: M.eref(M.remotable('storageNode')),
39
- marshaller: M.eref(M.remotable('marshaller')),
40
- },
41
- {
42
- // only necessary on first invocation, not subsequent
43
- initialPoserInvitation: InvitationShape,
44
- metricsOverride: M.recordOf(M.string()),
45
- },
46
- ),
47
- upgradability: 'canUpgrade',
48
- };
49
- harden(meta);
50
-
51
- /**
52
- * @typedef {StandardTerms &
53
- * GovernanceTerms<{
54
- * PerAccountInitialAmount: 'amount';
55
- * }>} ProvisionTerms
56
- * TODO: ERef<GovernedCreatorFacet<ProvisionCreator>>
57
- * @param {ZCF<ProvisionTerms>} zcf
58
- * @param {{
59
- * poolBank: ERef<Bank>;
60
- * initialPoserInvitation: Invitation;
61
- * storageNode: Remote<StorageNode>;
62
- * marshaller: Remote<Marshaller>;
63
- * metricsOverride?: MetricsNotification;
64
- * governedParamOverrides?: Record<string, Amount | undefined>;
65
- * }} privateArgs
66
- * @param {Baggage} baggage
67
- */
68
- export const start = async (zcf, privateArgs, baggage) => {
69
- const { poolBank, metricsOverride } = privateArgs;
70
-
71
- const { marshaller: remoteMarshaller } = privateArgs;
72
- const cachingMarshaller = wrapRemoteMarshaller(remoteMarshaller);
73
-
74
- const { makeRecorderKit } = prepareRecorderKitMakers(
75
- baggage,
76
- cachingMarshaller,
77
- );
78
-
79
- // Governance
80
- const { publicMixin, makeDurableGovernorFacet, params } =
81
- await handleParamGovernance(
82
- zcf,
83
- privateArgs.initialPoserInvitation,
84
- {
85
- PerAccountInitialAmount: ParamTypes.AMOUNT,
86
- },
87
- privateArgs.storageNode,
88
- privateArgs.marshaller,
89
- privateArgs.governedParamOverrides,
90
- );
91
-
92
- const zone = makeDurableZone(baggage);
93
-
94
- const makeBridgeProvisionTool = prepareBridgeProvisionTool(zone);
95
- const makeProvisionPoolKit = prepareProvisionPoolKit(zone, {
96
- makeRecorderKit,
97
- params,
98
- poolBank,
99
- zcf,
100
- makeBridgeProvisionTool,
101
- });
102
-
103
- const poolBrand = /** @type {Brand<'nat'>} */ (
104
- params.getPerAccountInitialAmount().brand
105
- );
106
- const provisionPoolKit = await provideSingleton(
107
- baggage,
108
- 'provisionPoolKit',
109
- () =>
110
- makeProvisionPoolKit({
111
- poolBrand,
112
- storageNode: privateArgs.storageNode,
113
- }),
114
- );
115
- provisionPoolKit.helper.start(poolBrand, { metrics: metricsOverride });
116
-
117
- const publicFacet = prepareExo(
118
- baggage,
119
- 'Provisioning Pool public',
120
- M.interface('ProvisionPool', {
121
- getMetrics: M.callWhen().returns(M.remotable('MetricsSubscriber')),
122
- getPublicTopics: M.callWhen().returns(TopicsRecordShape),
123
- ...publicMixinAPI,
124
- }),
125
- {
126
- async getMetrics() {
127
- await null;
128
- return provisionPoolKit.public.getPublicTopics().metrics.subscriber;
129
- },
130
- async getPublicTopics() {
131
- await null;
132
- return provisionPoolKit.public.getPublicTopics();
133
- },
134
- ...publicMixin,
135
- },
136
- );
137
-
138
- return harden({
139
- creatorFacet: makeDurableGovernorFacet(baggage, provisionPoolKit.machine)
140
- .governorFacet,
141
- publicFacet,
142
- });
143
- };
144
-
145
- harden(start);
@@ -1,81 +0,0 @@
1
- export function prepareBridgeProvisionTool(zone: Zone): (bankManager: ERef<import("@endo/exo").Guarded<{
2
- getAssetSubscription(): import("@agoric/notifier").IterableEachTopic<AssetDescriptor>;
3
- getRewardDistributorDepositFacet(denom: string, feeKit: AssetIssuerKit): ERef<import("@endo/far").EOnly<import("@agoric/ertp").DepositFacet>>;
4
- getModuleAccountAddress(moduleName: string): Promise<string | null>;
5
- addAsset(denom: string, issuerName: string, proposedName: string, kit: AssetIssuerKit & {
6
- payment?: ERef<Payment<"nat">>;
7
- }): Promise<void>;
8
- getBankForAddress(address: string): Promise<Bank>;
9
- }>>, walletFactory: ERef<import("@endo/exo").Guarded<{
10
- provideSmartWallet(address: string, bank: ERef<Bank>, namesByAddressAdmin: ERef<NameAdmin>): Promise<[wallet: import("@agoric/smart-wallet/src/smartWallet.js").SmartWallet, isNew: boolean]>;
11
- }>>, namesByAddressAdmin: ERef<NameAdmin>, forHandler: any) => import("@endo/exo").Guarded<{
12
- /** @param {BridgeMessage} obj */
13
- fromBridge(obj: BridgeMessage): Promise<void>;
14
- }>;
15
- export function prepareProvisionPoolKit(zone: Zone, { makeRecorderKit, params, poolBank, zcf, makeBridgeProvisionTool }: {
16
- makeRecorderKit: MakeRecorderKit;
17
- params: any;
18
- poolBank: ERef<Bank>;
19
- zcf: ZCF;
20
- makeBridgeProvisionTool: ReturnType<typeof prepareBridgeProvisionTool>;
21
- }): ({ poolBrand, storageNode }: {
22
- poolBrand: Brand<"nat">;
23
- storageNode: ERemote<StorageNode>;
24
- }) => Promise<ProvisionPoolKit>;
25
- export type ProvisionPoolKit = {
26
- machine: {
27
- addRevivableAddresses: (oldAddresses: string[]) => void;
28
- getWalletReviver: () => ERef<any>;
29
- setReferences: (erefs: ProvisionPoolKitReferences) => Promise<void>;
30
- makeHandler: () => ERef<BridgeHandler>;
31
- initPSM: (brand: Brand, instance: Instance<typeof psmStart>) => void;
32
- };
33
- helper: any;
34
- forHandler: any;
35
- public: any;
36
- };
37
- export type PsmInstance = Instance<typeof psmStart>;
38
- export type ProvisionPoolKitReferences = {
39
- bankManager: ERef<BankManager>;
40
- namesByAddressAdmin: ERef<NameAdmin>;
41
- walletFactory: ERef<WalletFactoryStartResult["creatorFacet"]>;
42
- };
43
- /**
44
- * Metrics naming scheme is that nouns are
45
- * present values and past-participles are accumulative.
46
- */
47
- export type MetricsNotification = {
48
- /**
49
- * count of new wallets provisioned
50
- */
51
- walletsProvisioned: bigint;
52
- /**
53
- * running sum of Minted provided
54
- * to new wallets
55
- */
56
- totalMintedProvided: Amount<"nat">;
57
- /**
58
- * running sum of Minted ever
59
- * received by the contract from PSM
60
- */
61
- totalMintedConverted: Amount<"nat">;
62
- };
63
- import type { Zone } from '@agoric/zone';
64
- import type { AssetDescriptor } from '@agoric/vats/src/vat-bank.js';
65
- import type { ERef } from '@endo/far';
66
- import type { Payment } from '@agoric/ertp';
67
- import type { Bank } from '@agoric/vats/src/vat-bank.js';
68
- import type { NameAdmin } from '@agoric/vats';
69
- import type { BridgeMessage } from '@agoric/cosmic-swingset/src/types.js';
70
- import type { MakeRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js';
71
- import type { ZCF } from '@agoric/zoe';
72
- import type { Brand } from '@agoric/ertp';
73
- import type { StorageNode } from '@agoric/internal/src/lib-chainStorage.js';
74
- import type { ERemote } from '@agoric/internal';
75
- import type { BridgeHandler } from '@agoric/vats';
76
- import type { start as psmStart } from '@agoric/inter-protocol/src/psm/psm.js';
77
- import type { Instance } from '@agoric/zoe/src/zoeService/utils.js';
78
- import type { BankManager } from '@agoric/vats/src/vat-bank.js';
79
- import type { WalletFactoryStartResult } from '@agoric/vats/src/core/startWalletFactory.js';
80
- import type { Amount } from '@agoric/ertp';
81
- //# sourceMappingURL=provisionPoolKit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provisionPoolKit.d.ts","sourceRoot":"","sources":["provisionPoolKit.js"],"names":[],"mappings":"AAiGO,iDAFI,IAAI;;;;;eA2gBgY,CAAC;;;;;;IAtf1Y,iCAAiC;oBAArB,aAAa;GA6B5B;AAYI,8CATI,IAAI,uEACJ;IACN,eAAe,EAAE,eAAe,CAAC;IACjC,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,KAAK,IAAI,CAAC,CAAC;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,uBAAuB,EAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;CACxE,gCA6bC;IAA2B,SAAS,EAA5B,MAAM,KAAK,CAAC;IACe,WAAW,EAAtC,QAAQ,WAAW,CAAC;CAC5B,KAAU,OAAO,CAAC,gBAAgB,CAAC,CAevC;+BAjjBY;IACR,OAAO,EAAE;QACP,qBAAqB,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;QACxD,gBAAgB,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC;QAClC,aAAa,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpE,WAAW,EAAE,MAAM,KAAK,aAAa,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,eAAe,CAAC,KAAK,IAAI,CAAC;KACtE,CAAC;IACF,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;CACb;0BAIS,SAAS,eAAe,CAAC;;iBAKxB,KAAK,WAAW,CAAC;yBACjB,KAAK,SAAS,CAAC;mBACf,KAAK,wBAAwB,CAAC,cAAc,CAAC,CAAC;;;;;;;;;;wBAM9C,MAAM;;;;;yBACN,OAAO,KAAK,CAAC;;;;;0BAEb,OAAO,KAAK,CAAC;;0BA/CJ,cAAc;qCAKH,8BAA8B;0BAZzC,WAAW;6BAJc,cAAc;0BAK1B,8BAA8B;+BAItC,cAAc;mCAVV,sCAAsC;qCAcpC,6CAA6C;yBAVzD,aAAa;2BAHa,cAAc;iCAEhC,0CAA0C;6BADtC,kBAAkB;mCAcpB,cAAc;uCAPV,uCAAuC;8BADhD,qCAAqC;iCAF5B,8BAA8B;8CAKvB,6CAA6C;4BAVxC,cAAc"}
@@ -1,618 +0,0 @@
1
- // @ts-check
2
- import { X, q, Fail } from '@endo/errors';
3
- import { E } from '@endo/far';
4
-
5
- import { AmountMath, BrandShape } from '@agoric/ertp';
6
- import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
7
- import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
8
- import {
9
- observeIteration,
10
- observeNotifier,
11
- subscribeEach,
12
- } from '@agoric/notifier';
13
- import {
14
- M,
15
- makeScalarBigMapStore,
16
- makeScalarBigSetStore,
17
- } from '@agoric/vat-data';
18
- import { makeAtomicProvider, makeScalarMapStore } from '@agoric/store';
19
- import { PowerFlags } from '@agoric/vats/src/walletFlags.js';
20
- import {
21
- PublicTopicShape,
22
- makeRecorderTopic,
23
- } from '@agoric/zoe/src/contractSupport/topics.js';
24
- import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
25
- import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
26
-
27
- /**
28
- * @import {EReturn} from '@endo/far';
29
- * @import {BridgeMessage} from '@agoric/cosmic-swingset/src/types.js';
30
- * @import {Amount, Brand, Payment, Purse} from '@agoric/ertp';
31
- * @import {ERemote, Remote} from '@agoric/internal';
32
- * @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
33
- * @import {ZCF} from '@agoric/zoe';
34
- * @import {ERef} from '@endo/far'
35
- * @import {Bank, BankManager} from '@agoric/vats/src/vat-bank.js'
36
- * @import {MapStore, SetStore} from '@agoric/store';
37
- * @import {Instance} from '@agoric/zoe/src/zoeService/utils.js';
38
- * @import {start as psmStart} from '@agoric/inter-protocol/src/psm/psm.js';
39
- * @import {NameAdmin} from '@agoric/vats';
40
- * @import {WalletFactoryStartResult} from '@agoric/vats/src/core/startWalletFactory.js';
41
- * @import {Zone} from '@agoric/zone';
42
- * @import {start as StartWalletFactory} from '@agoric/smart-wallet/src/walletFactory.js';
43
- * @import {MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js';
44
- * @import {RecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js';
45
- * @import {BridgeHandler} from '@agoric/vats';
46
- * @import {AssetDescriptor} from '@agoric/vats/src/vat-bank.js';
47
- */
48
-
49
- const trace = makeTracer('ProvPool');
50
-
51
- const FIRST_UPPER_KEYWORD = /^[A-Z][a-zA-Z0-9_$]*$/;
52
- // see https://github.com/Agoric/agoric-sdk/issues/8238
53
- const FIRST_LOWER_NEAR_KEYWORD = /^[a-z][a-zA-Z0-9_$]*$/;
54
-
55
- // XXX when inferred, error TS2742: cannot be named without a reference to '../../../node_modules/@endo/exo/src/get-interface.js'. This is likely not portable. A type annotation is necessary.
56
- /**
57
- * @typedef {{
58
- * machine: {
59
- * addRevivableAddresses: (oldAddresses: string[]) => void;
60
- * getWalletReviver: () => ERef<any>;
61
- * setReferences: (erefs: ProvisionPoolKitReferences) => Promise<void>;
62
- * makeHandler: () => ERef<BridgeHandler>;
63
- * initPSM: (brand: Brand, instance: Instance<typeof psmStart>) => void;
64
- * };
65
- * helper: any;
66
- * forHandler: any;
67
- * public: any;
68
- * }} ProvisionPoolKit
69
- */
70
-
71
- /**
72
- * @typedef {Instance<typeof psmStart>} PsmInstance
73
- */
74
-
75
- /**
76
- * @typedef {object} ProvisionPoolKitReferences
77
- * @property {ERef<BankManager>} bankManager
78
- * @property {ERef<NameAdmin>} namesByAddressAdmin
79
- * @property {ERef<WalletFactoryStartResult['creatorFacet']>} walletFactory
80
- */
81
-
82
- /**
83
- * @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
84
- * present values and past-participles are accumulative.
85
- * @property {bigint} walletsProvisioned count of new wallets provisioned
86
- * @property {Amount<'nat'>} totalMintedProvided running sum of Minted provided
87
- * to new wallets
88
- * @property {Amount<'nat'>} totalMintedConverted running sum of Minted ever
89
- * received by the contract from PSM
90
- */
91
-
92
- /**
93
- * Given attenuated access to the funding purse, handle requests to provision
94
- * smart wallets.
95
- *
96
- * @param {Zone} zone
97
- */
98
- export const prepareBridgeProvisionTool = zone =>
99
- zone.exoClass(
100
- 'smartWalletProvisioningHandler',
101
- M.interface('ProvisionBridgeHandlerMaker', {
102
- fromBridge: M.callWhen(M.record()).returns(),
103
- }),
104
- /**
105
- * @param {ERef<BankManager>} bankManager
106
- * @param {ERef<EReturn<StartWalletFactory>['creatorFacet']>} walletFactory
107
- * @param {ERef<NameAdmin>} namesByAddressAdmin
108
- * @param {ProvisionPoolKit['forHandler']} forHandler
109
- */
110
- (bankManager, walletFactory, namesByAddressAdmin, forHandler) => ({
111
- bankManager,
112
- walletFactory,
113
- namesByAddressAdmin,
114
- forHandler,
115
- }),
116
- {
117
- /** @param {BridgeMessage} obj */
118
- async fromBridge(obj) {
119
- if (obj.type !== 'PLEASE_PROVISION')
120
- throw Fail`Unrecognized request ${obj.type}`;
121
- trace('PLEASE_PROVISION', obj);
122
- const { address, powerFlags } = obj;
123
- // XXX expects powerFlags to be an array, but if it's a string then
124
- // this allows a string that has 'SMART_WALLET' in it.
125
- powerFlags.includes(PowerFlags.SMART_WALLET) ||
126
- Fail`missing SMART_WALLET in powerFlags`;
127
-
128
- const { bankManager, walletFactory, namesByAddressAdmin, forHandler } =
129
- this.state;
130
-
131
- const bank = E(bankManager).getBankForAddress(address);
132
- // only proceed if we can provide funds
133
- await forHandler.sendInitialPayment(bank);
134
-
135
- const [_, created] = await E(walletFactory).provideSmartWallet(
136
- address,
137
- bank,
138
- namesByAddressAdmin,
139
- );
140
- if (created) {
141
- forHandler.onProvisioned();
142
- }
143
- trace(created ? 'provisioned' : 're-provisioned', address);
144
- },
145
- },
146
- );
147
-
148
- /**
149
- * @param {Zone} zone
150
- * @param {{
151
- * makeRecorderKit: MakeRecorderKit;
152
- * params: any;
153
- * poolBank: ERef<Bank>;
154
- * zcf: ZCF;
155
- * makeBridgeProvisionTool: ReturnType<typeof prepareBridgeProvisionTool>;
156
- * }} powers
157
- */
158
- export const prepareProvisionPoolKit = (
159
- zone,
160
- { makeRecorderKit, params, poolBank, zcf, makeBridgeProvisionTool },
161
- ) => {
162
- const zoe = zcf.getZoeService();
163
- const ephemeralPurses = makeScalarMapStore('fundingPurseForBrand');
164
- const purseProvider = makeAtomicProvider(ephemeralPurses);
165
- const getFundingPurseForBrand = async poolBrand => {
166
- await null;
167
- try {
168
- const purse = await purseProvider.provideAsync(poolBrand, brand =>
169
- E(poolBank).getPurse(brand),
170
- );
171
- return purse;
172
- } catch (err) {
173
- trace(`🚨 could not get purse for brand ${poolBrand}`, err);
174
- throw err;
175
- }
176
- };
177
-
178
- const makeProvisionPoolKitInternal = zone.exoClassKit(
179
- 'ProvisionPoolKit',
180
- {
181
- machine: M.interface('ProvisionPoolKit machine', {
182
- addRevivableAddresses: M.call(M.arrayOf(M.string())).returns(),
183
- getWalletReviver: M.call().returns(
184
- M.remotable('ProvisionPoolKit wallet reviver'),
185
- ),
186
- setReferences: M.callWhen({
187
- bankManager: M.eref(M.remotable('bankManager')),
188
- namesByAddressAdmin: M.eref(M.remotable('nameAdmin')),
189
- walletFactory: M.eref(M.remotable('walletFactory')),
190
- }).returns(),
191
- makeHandler: M.call().returns(M.remotable('BridgeHandler')),
192
- initPSM: M.call(BrandShape, InstanceHandleShape).returns(),
193
- }),
194
- walletReviver: M.interface('ProvisionPoolKit wallet reviver', {
195
- reviveWallet: M.callWhen(M.string()).returns(
196
- M.remotable('SmartWallet'),
197
- ),
198
- ackWallet: M.call(M.string()).returns(M.boolean()),
199
- }),
200
- helper: UnguardedHelperI,
201
- forHandler: UnguardedHelperI,
202
- public: M.interface('ProvisionPoolKit public', {
203
- getPublicTopics: M.call().returns({ metrics: PublicTopicShape }),
204
- }),
205
- },
206
- /**
207
- * @param {object} opts
208
- * @param {Purse<'nat'>} [opts.fundPurse]
209
- * @param {Brand<'nat'>} opts.poolBrand
210
- * @param {Remote<StorageNode>} opts.metricsNode
211
- */
212
- ({ fundPurse, poolBrand, metricsNode }) => {
213
- /** @type {RecorderKit<MetricsNotification>} */
214
- const metricsRecorderKit = makeRecorderKit(metricsNode);
215
-
216
- /** @type {MapStore<ERef<Brand>, PsmInstance>} */
217
- const brandToPSM = makeScalarBigMapStore('brandToPSM', { durable: true });
218
- const revivableAddresses = makeScalarBigSetStore('revivableAddresses', {
219
- durable: true,
220
- keyShape: M.string(),
221
- });
222
-
223
- /**
224
- * to be set by `setReferences`
225
- *
226
- * @type {Partial<ProvisionPoolKitReferences>}
227
- */
228
- const references = {
229
- bankManager: undefined,
230
- namesByAddressAdmin: undefined,
231
- walletFactory: undefined,
232
- };
233
-
234
- return {
235
- brandToPSM,
236
- fundPurse,
237
- metricsRecorderKit,
238
- poolBrand,
239
- walletsProvisioned: 0n,
240
- totalMintedProvided: AmountMath.makeEmpty(poolBrand),
241
- totalMintedConverted: AmountMath.makeEmpty(poolBrand),
242
- revivableAddresses,
243
- ...references,
244
- };
245
- },
246
- {
247
- // aka "limitedCreatorFacet"
248
- machine: {
249
- /** @param {string[]} oldAddresses */
250
- addRevivableAddresses(oldAddresses) {
251
- trace('revivableAddresses count', oldAddresses.length);
252
- this.state.revivableAddresses.addAll(oldAddresses);
253
- },
254
- getWalletReviver() {
255
- return this.facets.walletReviver;
256
- },
257
- /** @param {ProvisionPoolKitReferences} erefs */
258
- async setReferences(erefs) {
259
- const { bankManager, namesByAddressAdmin, walletFactory } = erefs;
260
- const obj = harden({
261
- bankManager,
262
- namesByAddressAdmin,
263
- walletFactory,
264
- });
265
- const refs = await deeplyFulfilledObject(obj);
266
- Object.assign(this.state, refs);
267
- },
268
- /** @returns {BridgeHandler} */
269
- makeHandler() {
270
- const { bankManager, namesByAddressAdmin, walletFactory } =
271
- this.state;
272
- if (!bankManager || !namesByAddressAdmin || !walletFactory) {
273
- throw Fail`must set references before handling requests`;
274
- }
275
-
276
- const { forHandler } = this.facets;
277
-
278
- const provisionHandler = makeBridgeProvisionTool(
279
- bankManager,
280
- walletFactory,
281
- namesByAddressAdmin,
282
- forHandler,
283
- );
284
-
285
- return provisionHandler;
286
- },
287
- /**
288
- * @param {Brand} brand
289
- * @param {PsmInstance} instance
290
- */
291
- initPSM(brand, instance) {
292
- const { brandToPSM } = this.state;
293
- brandToPSM.init(brand, instance);
294
- },
295
- },
296
- walletReviver: {
297
- /** @param {string} address */
298
- async reviveWallet(address) {
299
- const {
300
- revivableAddresses,
301
- bankManager,
302
- namesByAddressAdmin,
303
- walletFactory,
304
- } = this.state;
305
- if (!bankManager || !namesByAddressAdmin || !walletFactory) {
306
- throw Fail`must set references before handling requests`;
307
- }
308
- revivableAddresses.has(address) ||
309
- Fail`non-revivable address ${address}`;
310
- const bank = E(bankManager).getBankForAddress(address);
311
- const [wallet, _created] = await E(walletFactory).provideSmartWallet(
312
- address,
313
- bank,
314
- namesByAddressAdmin,
315
- );
316
- return wallet;
317
- },
318
- /**
319
- * @param {string} address
320
- * @returns {boolean} isRevive
321
- */
322
- ackWallet(address) {
323
- const { revivableAddresses } = this.state;
324
- if (!revivableAddresses.has(address)) {
325
- return false;
326
- }
327
- revivableAddresses.delete(address);
328
- return true;
329
- },
330
- },
331
- helper: {
332
- publishMetrics() {
333
- const {
334
- metricsRecorderKit,
335
- walletsProvisioned,
336
- totalMintedConverted,
337
- totalMintedProvided,
338
- } = this.state;
339
- void metricsRecorderKit.recorder.write(
340
- harden({
341
- walletsProvisioned,
342
- totalMintedProvided,
343
- totalMintedConverted,
344
- }),
345
- );
346
- },
347
- onTrade(converted) {
348
- const { state, facets } = this;
349
- state.totalMintedConverted = AmountMath.add(
350
- state.totalMintedConverted,
351
- converted,
352
- );
353
- facets.helper.publishMetrics();
354
- },
355
- onSendFunds(provided) {
356
- const { state, facets } = this;
357
- state.totalMintedProvided = AmountMath.add(
358
- state.totalMintedProvided,
359
- provided,
360
- );
361
- facets.helper.publishMetrics();
362
- },
363
- /**
364
- * @param {Amount} amount
365
- * @param {ERef<Purse>} srcPurse
366
- */
367
- async onPoolDeposit(amount, srcPurse) {
368
- const { helper } = this.facets;
369
- const { brandToPSM, poolBrand } = this.state;
370
-
371
- const { brand } = amount;
372
- if (AmountMath.isEmpty(amount) || brand === poolBrand) {
373
- return;
374
- }
375
-
376
- // `amount` doesn't match the current `poolBrand`, so we need to swap
377
- // it.
378
- if (!brandToPSM.has(brand)) {
379
- console.error('funds arrived but no PSM instance', brand);
380
- return;
381
- }
382
- const instance = brandToPSM.get(brand);
383
- const payment = E(srcPurse).withdraw(amount);
384
- await helper.swap(payment, amount, instance).catch(async reason => {
385
- console.error(X`swap failed: ${reason}`);
386
- const resolvedPayment = await payment;
387
- return E(srcPurse).deposit(resolvedPayment);
388
- });
389
- },
390
- /**
391
- * @param {ERef<Purse>} exchangePurse
392
- * @param {ERef<Brand>} brand
393
- */
394
- watchCurrentAmount(exchangePurse, brand) {
395
- const { helper } = this.facets;
396
- void observeNotifier(E(exchangePurse).getCurrentAmountNotifier(), {
397
- updateState: async amount => {
398
- trace('provisionPool balance update', amount);
399
- await helper.onPoolDeposit(amount, exchangePurse);
400
- },
401
- fail: reason => {
402
- if (isUpgradeDisconnection(reason)) {
403
- void helper.watchCurrentAmount(exchangePurse, brand);
404
- } else {
405
- console.error(reason);
406
- }
407
- },
408
- });
409
- },
410
- watchAssetSubscription() {
411
- const { facets } = this;
412
- const { helper } = facets;
413
-
414
- /** @param {AssetDescriptor} desc */
415
- const repairDesc = desc => {
416
- if (desc.issuerName.match(FIRST_UPPER_KEYWORD)) {
417
- trace(`Saving Issuer ${desc.issuerName}`);
418
- return desc;
419
- } else if (desc.issuerName.match(FIRST_LOWER_NEAR_KEYWORD)) {
420
- const bad = desc.issuerName;
421
- const goodName = bad.replace(bad[0], bad[0].toUpperCase());
422
-
423
- trace(
424
- `Saving Issuer ${desc.issuerName} with repaired keyword ${goodName}`,
425
- );
426
- return { ...desc, issuerName: goodName };
427
- } else {
428
- console.error(
429
- `unable to save issuer with illegal keyword: ${desc.issuerName}`,
430
- );
431
- return undefined;
432
- }
433
- };
434
-
435
- return observeIteration(
436
- subscribeEach(E(poolBank).getAssetSubscription()),
437
- {
438
- updateState: async desc => {
439
- await null;
440
- const issuer = zcf.getTerms().issuers[desc.issuerName];
441
- if (issuer === desc.issuer) {
442
- trace('provisionPool re-notified of known asset', desc.brand);
443
- } else {
444
- const goodDesc = repairDesc(desc);
445
- if (goodDesc) {
446
- await zcf.saveIssuer(goodDesc.issuer, goodDesc.issuerName);
447
- } else {
448
- console.error(
449
- `unable to save issuer with illegal keyword: ${desc.issuerName}`,
450
- );
451
- }
452
- }
453
-
454
- /** @type {ERef<Purse>} */
455
- const exchangePurse = E(poolBank).getPurse(desc.brand);
456
- helper.watchCurrentAmount(exchangePurse, desc.brand);
457
- },
458
- fail: _reason => {
459
- void helper.watchAssetSubscription();
460
- },
461
- },
462
- );
463
- },
464
- /**
465
- * @param {Brand<'nat'>} poolBrand
466
- * @param {object} [options]
467
- * @param {MetricsNotification} [options.metrics]
468
- */
469
- start(poolBrand, { metrics } = {}) {
470
- const { facets, state } = this;
471
- const { helper } = facets;
472
- const lastPoolBrand = state.poolBrand;
473
-
474
- // The PerAccountInitialAmount param must use the correct brand for
475
- // this incarnation.
476
- AmountMath.coerce(poolBrand, params.getPerAccountInitialAmount());
477
-
478
- // Restore old metrics.
479
- if (metrics) {
480
- const {
481
- walletsProvisioned,
482
- totalMintedProvided,
483
- totalMintedConverted,
484
- } = metrics;
485
- assert.typeof(walletsProvisioned, 'bigint');
486
- AmountMath.coerce(lastPoolBrand, totalMintedProvided);
487
- AmountMath.coerce(lastPoolBrand, totalMintedConverted);
488
- Object.assign(state, {
489
- walletsProvisioned,
490
- totalMintedProvided,
491
- totalMintedConverted,
492
- });
493
- helper.publishMetrics();
494
- }
495
-
496
- // Update as needed when `poolBrand` changes.
497
- if (poolBrand !== lastPoolBrand) {
498
- state.poolBrand = poolBrand;
499
- state.fundPurse = undefined;
500
- void getFundingPurseForBrand(poolBrand).then(purse =>
501
- helper.updateFundPurse(purse, poolBrand),
502
- );
503
- state.totalMintedProvided = AmountMath.makeEmpty(poolBrand);
504
- state.totalMintedConverted = AmountMath.makeEmpty(poolBrand);
505
- helper.publishMetrics();
506
- }
507
-
508
- void helper.watchAssetSubscription();
509
- },
510
- /**
511
- * @param {ERef<Payment>} payIn
512
- * @param {Amount} amount
513
- * @param {PsmInstance} instance
514
- */
515
- async swap(payIn, amount, instance) {
516
- await null;
517
- const { facets, state } = this;
518
- const { helper } = facets;
519
- const {
520
- poolBrand,
521
- fundPurse = await getFundingPurseForBrand(poolBrand),
522
- } = state;
523
- const psmPub = E(zoe).getPublicFacet(instance);
524
- const proposal = harden({ give: { In: amount } });
525
- const invitation = E(psmPub).makeWantMintedInvitation();
526
- const seat = E(zoe).offer(invitation, proposal, { In: payIn });
527
- const payout = await E(seat).getPayout('Out');
528
- const rxd = await E(fundPurse).deposit(payout);
529
- helper.onTrade(rxd);
530
- return rxd;
531
- },
532
- /**
533
- * @param {Purse<'nat'>} purse
534
- * @param {Brand<'nat'>} brand
535
- */
536
- updateFundPurse(purse, brand) {
537
- const { state } = this;
538
- if (brand !== state.poolBrand || state.fundPurse) return;
539
- state.fundPurse = purse;
540
- },
541
- },
542
- forHandler: {
543
- onProvisioned() {
544
- const { facets, state } = this;
545
- state.walletsProvisioned += 1n;
546
- facets.helper.publishMetrics();
547
- },
548
- /** @param {ERef<Bank>} destBank */
549
- async sendInitialPayment(destBank) {
550
- await null;
551
- const { facets, state } = this;
552
- const { helper } = facets;
553
- const {
554
- poolBrand,
555
- fundPurse = await getFundingPurseForBrand(poolBrand),
556
- } = state;
557
- const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
558
- params.getPerAccountInitialAmount()
559
- );
560
- trace('sendInitialPayment withdrawing', perAccountInitialAmount);
561
- const initialPmt = await E(fundPurse).withdraw(
562
- perAccountInitialAmount,
563
- );
564
-
565
- const destPurse = E(destBank).getPurse(poolBrand);
566
- return E(destPurse)
567
- .deposit(initialPmt)
568
- .then(amt => {
569
- helper.onSendFunds(perAccountInitialAmount);
570
- trace('provisionPool sent', amt);
571
- })
572
- .catch(reason => {
573
- console.error(X`initial deposit failed: ${q(reason)}`);
574
- void E(fundPurse).deposit(initialPmt);
575
- throw reason;
576
- });
577
- },
578
- },
579
- public: {
580
- getPublicTopics() {
581
- return {
582
- metrics: makeRecorderTopic(
583
- 'Provision Pool metrics',
584
- this.state.metricsRecorderKit,
585
- ),
586
- };
587
- },
588
- },
589
- },
590
- {
591
- finish: ({ facets }) => {
592
- facets.helper.publishMetrics();
593
- },
594
- },
595
- );
596
-
597
- /**
598
- * Prepare synchronous values before passing to real Exo maker
599
- *
600
- * @param {object} opts
601
- * @param {Brand<'nat'>} opts.poolBrand
602
- * @param {ERemote<StorageNode>} opts.storageNode
603
- * @returns {Promise<ProvisionPoolKit>}
604
- */
605
- const makeProvisionPoolKit = async ({ poolBrand, storageNode }) => {
606
- const fundPurse = await getFundingPurseForBrand(poolBrand);
607
- /** @type {Remote<StorageNode>} */
608
- const metricsNode = await E(storageNode).makeChildNode('metrics');
609
-
610
- return makeProvisionPoolKitInternal({
611
- fundPurse,
612
- poolBrand,
613
- metricsNode,
614
- });
615
- };
616
-
617
- return makeProvisionPoolKit;
618
- };