@agoric/inter-protocol 0.16.2-other-dev-1f26562.0 → 0.16.2-other-dev-3eb1a1d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/package.json +42 -36
- package/scripts/build-bundles.js +5 -21
- package/src/auction/auctionBook.d.ts +147 -0
- package/src/auction/auctionBook.d.ts.map +1 -0
- package/src/auction/auctionBook.js +156 -150
- package/src/auction/auctionMath.d.ts +17 -0
- package/src/auction/auctionMath.d.ts.map +1 -0
- package/src/auction/auctionMath.js +81 -0
- package/src/auction/auctioneer.d.ts +69 -0
- package/src/auction/auctioneer.d.ts.map +1 -0
- package/src/auction/auctioneer.js +70 -59
- package/src/auction/offerBook.d.ts +45 -0
- package/src/auction/offerBook.d.ts.map +1 -0
- package/src/auction/offerBook.js +13 -12
- package/src/auction/params.d.ts +144 -0
- package/src/auction/params.d.ts.map +1 -0
- package/src/auction/params.js +10 -9
- package/src/auction/scheduleMath.d.ts +5 -0
- package/src/auction/scheduleMath.d.ts.map +1 -0
- package/src/auction/scheduleMath.js +18 -16
- package/src/auction/scheduler.d.ts +50 -0
- package/src/auction/scheduler.d.ts.map +1 -0
- package/src/auction/scheduler.js +53 -47
- package/src/auction/sortedOffers.d.ts +8 -0
- package/src/auction/sortedOffers.d.ts.map +1 -0
- package/src/auction/sortedOffers.js +10 -9
- package/src/auction/util.d.ts +30 -0
- package/src/auction/util.d.ts.map +1 -0
- package/src/auction/util.js +9 -6
- package/src/clientSupport.d.ts +167 -0
- package/src/clientSupport.d.ts.map +1 -0
- package/src/clientSupport.js +155 -97
- package/src/collectFees.d.ts +2 -0
- package/src/collectFees.d.ts.map +1 -0
- package/src/contractSupport.d.ts +28 -0
- package/src/contractSupport.d.ts.map +1 -0
- package/src/contractSupport.js +19 -13
- package/src/econCommitteeCharter.d.ts +40 -0
- package/src/econCommitteeCharter.d.ts.map +1 -0
- package/src/econCommitteeCharter.js +21 -20
- package/src/feeDistributor.d.ts +224 -0
- package/src/feeDistributor.d.ts.map +1 -0
- package/src/feeDistributor.js +37 -33
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +1 -0
- package/src/interest-math.d.ts +3 -0
- package/src/interest-math.d.ts.map +1 -0
- package/src/interest.d.ts +28 -0
- package/src/interest.d.ts.map +1 -0
- package/src/interest.js +23 -18
- package/src/price/README.md +13 -0
- package/src/price/fluxAggregatorContract.d.ts +71 -0
- package/src/price/fluxAggregatorContract.d.ts.map +1 -0
- package/src/price/fluxAggregatorContract.js +64 -55
- package/src/price/fluxAggregatorKit.d.ts +103 -0
- package/src/price/fluxAggregatorKit.d.ts.map +1 -0
- package/src/price/fluxAggregatorKit.js +52 -40
- package/src/price/priceOracleKit.d.ts +38 -0
- package/src/price/priceOracleKit.d.ts.map +1 -0
- package/src/price/priceOracleKit.js +12 -14
- package/src/price/roundsManager.d.ts +204 -0
- package/src/price/roundsManager.d.ts.map +1 -0
- package/src/price/roundsManager.js +131 -85
- package/src/proposals/README.md +2 -3
- package/src/proposals/add-auction.d.ts +109 -0
- package/src/proposals/add-auction.d.ts.map +1 -0
- package/src/proposals/add-auction.js +256 -0
- package/src/proposals/addAssetToVault.d.ts +173 -0
- package/src/proposals/addAssetToVault.d.ts.map +1 -0
- package/src/proposals/addAssetToVault.js +192 -40
- package/src/proposals/committee-proposal.d.ts +113 -0
- package/src/proposals/committee-proposal.d.ts.map +1 -0
- package/src/proposals/committee-proposal.js +25 -31
- package/src/proposals/core-proposal.d.ts +149 -0
- package/src/proposals/core-proposal.d.ts.map +1 -0
- package/src/proposals/core-proposal.js +9 -11
- package/src/proposals/deploy-price-feeds.d.ts +76 -0
- package/src/proposals/deploy-price-feeds.d.ts.map +1 -0
- package/src/proposals/deploy-price-feeds.js +316 -0
- package/src/proposals/econ-behaviors.d.ts +541 -0
- package/src/proposals/econ-behaviors.d.ts.map +1 -0
- package/src/proposals/econ-behaviors.js +64 -45
- package/src/proposals/price-feed-proposal.d.ts +84 -0
- package/src/proposals/price-feed-proposal.d.ts.map +1 -0
- package/src/proposals/price-feed-proposal.js +109 -51
- package/src/proposals/replace-fee-distributor.d.ts +48 -0
- package/src/proposals/replace-fee-distributor.d.ts.map +1 -0
- package/src/proposals/replace-fee-distributor.js +195 -0
- package/src/proposals/replace-scaledPriceAuthorities.d.ts +30 -0
- package/src/proposals/replace-scaledPriceAuthorities.d.ts.map +1 -0
- package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
- package/src/proposals/replaceElectorate.d.ts +55 -0
- package/src/proposals/replaceElectorate.d.ts.map +1 -0
- package/src/proposals/replaceElectorate.js +521 -0
- package/src/proposals/startEconCommittee.d.ts +34 -0
- package/src/proposals/startEconCommittee.d.ts.map +1 -0
- package/src/proposals/startEconCommittee.js +2 -2
- package/src/proposals/startPSM.d.ts +59 -0
- package/src/proposals/startPSM.d.ts.map +1 -0
- package/src/proposals/startPSM.js +44 -29
- package/src/proposals/upgrade-scaledPriceAuthorities.d.ts +24 -0
- package/src/proposals/upgrade-scaledPriceAuthorities.d.ts.map +1 -0
- package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
- package/src/proposals/upgrade-vaults.d.ts +41 -0
- package/src/proposals/upgrade-vaults.d.ts.map +1 -0
- package/src/proposals/upgrade-vaults.js +202 -0
- package/src/proposals/utils.d.ts +19 -0
- package/src/proposals/utils.d.ts.map +1 -0
- package/src/proposals/utils.js +43 -9
- package/src/provisionPool.d.ts +163 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +122 -0
- package/src/provisionPoolKit.d.ts +359 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +522 -0
- package/src/psm/psm.d.ts +125 -0
- package/src/psm/psm.d.ts.map +1 -0
- package/src/psm/psm.js +80 -79
- package/src/psm/types-ambient.d.ts +2 -0
- package/src/psm/types-ambient.d.ts.map +1 -0
- package/src/psm/types-ambient.js +3 -0
- package/src/reserve/assetReserve.d.ts +47 -0
- package/src/reserve/assetReserve.d.ts.map +1 -0
- package/src/reserve/assetReserve.js +28 -19
- package/src/reserve/assetReserveKit.d.ts +74 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -0
- package/src/reserve/assetReserveKit.js +24 -30
- package/src/reserve/params.d.ts +10 -0
- package/src/reserve/params.d.ts.map +1 -0
- package/src/tokens.d.ts +3 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +5 -0
- package/src/vaultFactory/burn.d.ts +2 -0
- package/src/vaultFactory/burn.d.ts.map +1 -0
- package/src/vaultFactory/burn.js +1 -1
- package/src/vaultFactory/liquidation.d.ts +23 -0
- package/src/vaultFactory/liquidation.d.ts.map +1 -0
- package/src/vaultFactory/liquidation.js +37 -24
- package/src/vaultFactory/math.d.ts +11 -0
- package/src/vaultFactory/math.d.ts.map +1 -0
- package/src/vaultFactory/math.js +10 -9
- package/src/vaultFactory/orderedVaultStore.d.ts +93 -0
- package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
- package/src/vaultFactory/orderedVaultStore.js +8 -11
- package/src/vaultFactory/params.d.ts +140 -0
- package/src/vaultFactory/params.d.ts.map +1 -0
- package/src/vaultFactory/params.js +52 -24
- package/src/vaultFactory/prioritizedVaults.d.ts +279 -0
- package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
- package/src/vaultFactory/prioritizedVaults.js +4 -4
- package/src/vaultFactory/proceeds.d.ts +35 -0
- package/src/vaultFactory/proceeds.d.ts.map +1 -0
- package/src/vaultFactory/proceeds.js +26 -18
- package/src/vaultFactory/storeUtils.d.ts +25 -0
- package/src/vaultFactory/storeUtils.d.ts.map +1 -0
- package/src/vaultFactory/storeUtils.js +10 -12
- package/src/vaultFactory/types-ambient.d.ts +137 -0
- package/src/vaultFactory/types-ambient.d.ts.map +1 -0
- package/src/vaultFactory/{types.js → types-ambient.js} +42 -42
- package/src/vaultFactory/vault.d.ts +343 -0
- package/src/vaultFactory/vault.d.ts.map +1 -0
- package/src/vaultFactory/vault.js +105 -99
- package/src/vaultFactory/vaultDirector.d.ts +341 -0
- package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
- package/src/vaultFactory/vaultDirector.js +86 -64
- package/src/vaultFactory/vaultFactory.d.ts +202 -0
- package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
- package/src/vaultFactory/vaultFactory.js +52 -33
- package/src/vaultFactory/vaultHolder.d.ts +126 -0
- package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
- package/src/vaultFactory/vaultHolder.js +11 -16
- package/src/vaultFactory/vaultKit.d.ts +32 -0
- package/src/vaultFactory/vaultKit.d.ts.map +1 -0
- package/src/vaultFactory/vaultKit.js +5 -4
- package/src/vaultFactory/vaultManager.d.ts +674 -0
- package/src/vaultFactory/vaultManager.d.ts.map +1 -0
- package/src/vaultFactory/vaultManager.js +257 -158
- package/CHANGELOG.md +0 -1041
- package/exported.js +0 -2
- package/scripts/add-collateral-core.js +0 -112
- package/scripts/deploy-contracts.js +0 -100
- package/scripts/init-core.js +0 -198
- package/scripts/invite-committee-core.js +0 -42
- package/scripts/manual-price-feed.js +0 -117
- package/scripts/price-feed-core.js +0 -104
- package/scripts/start-local-chain.sh +0 -84
- package/src/psm/types.js +0 -3
- package/src/typeGuards.js +0 -13
- package/src/vaultFactory/type-imports.js +0 -4
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { X, q, Fail } from '@endo/errors';
|
|
3
|
+
import { E } from '@endo/far';
|
|
4
|
+
import { Far } from '@endo/marshal';
|
|
5
|
+
|
|
6
|
+
import { AmountMath, BrandShape } from '@agoric/ertp';
|
|
7
|
+
import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
|
|
8
|
+
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
9
|
+
import {
|
|
10
|
+
observeIteration,
|
|
11
|
+
observeNotifier,
|
|
12
|
+
subscribeEach,
|
|
13
|
+
} from '@agoric/notifier';
|
|
14
|
+
import {
|
|
15
|
+
M,
|
|
16
|
+
makeScalarBigMapStore,
|
|
17
|
+
makeScalarBigSetStore,
|
|
18
|
+
prepareExoClassKit,
|
|
19
|
+
} from '@agoric/vat-data';
|
|
20
|
+
import { PowerFlags } from '@agoric/vats/src/walletFlags.js';
|
|
21
|
+
import {
|
|
22
|
+
PublicTopicShape,
|
|
23
|
+
makeRecorderTopic,
|
|
24
|
+
} from '@agoric/zoe/src/contractSupport/topics.js';
|
|
25
|
+
import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
|
|
26
|
+
import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
|
|
27
|
+
|
|
28
|
+
const trace = makeTracer('ProvPool');
|
|
29
|
+
|
|
30
|
+
const FIRST_UPPER_KEYWORD = /^[A-Z][a-zA-Z0-9_$]*$/;
|
|
31
|
+
// see https://github.com/Agoric/agoric-sdk/issues/8238
|
|
32
|
+
const FIRST_LOWER_NEAR_KEYWORD = /^[a-z][a-zA-Z0-9_$]*$/;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @import {ERef} from '@endo/far'
|
|
36
|
+
* @import {Amount} from '@agoric/ertp/src/types.js'
|
|
37
|
+
* @import {Bank, BankManager} from '@agoric/vats/src/vat-bank.js'
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {import('@agoric/zoe/src/zoeService/utils.js').Instance<
|
|
42
|
+
* import('@agoric/inter-protocol/src/psm/psm.js').start
|
|
43
|
+
* >} PsmInstance
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {object} ProvisionPoolKitReferences
|
|
48
|
+
* @property {ERef<BankManager>} bankManager
|
|
49
|
+
* @property {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
|
|
50
|
+
* @property {ERef<
|
|
51
|
+
* import('@agoric/vats/src/core/startWalletFactory.js').WalletFactoryStartResult['creatorFacet']
|
|
52
|
+
* >} walletFactory
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
|
|
57
|
+
* present values and past-participles are accumulative.
|
|
58
|
+
* @property {bigint} walletsProvisioned count of new wallets provisioned
|
|
59
|
+
* @property {Amount<'nat'>} totalMintedProvided running sum of Minted provided
|
|
60
|
+
* to new wallets
|
|
61
|
+
* @property {Amount<'nat'>} totalMintedConverted running sum of Minted ever
|
|
62
|
+
* received by the contract from PSM
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Given attenuated access to the funding purse, handle requests to provision
|
|
67
|
+
* smart wallets.
|
|
68
|
+
*
|
|
69
|
+
* @param {(depositBank: ERef<Bank>) => Promise<void>} sendInitialPayment
|
|
70
|
+
* @param {() => void} onProvisioned
|
|
71
|
+
*/
|
|
72
|
+
export const makeBridgeProvisionTool = (sendInitialPayment, onProvisioned) => {
|
|
73
|
+
/** @param {ProvisionPoolKitReferences} refs */
|
|
74
|
+
const makeBridgeHandler = ({
|
|
75
|
+
bankManager,
|
|
76
|
+
namesByAddressAdmin,
|
|
77
|
+
walletFactory,
|
|
78
|
+
}) =>
|
|
79
|
+
Far('provisioningHandler', {
|
|
80
|
+
fromBridge: async obj => {
|
|
81
|
+
obj.type === 'PLEASE_PROVISION' ||
|
|
82
|
+
Fail`Unrecognized request ${obj.type}`;
|
|
83
|
+
trace('PLEASE_PROVISION', obj);
|
|
84
|
+
const { address, powerFlags } = obj;
|
|
85
|
+
powerFlags.includes(PowerFlags.SMART_WALLET) ||
|
|
86
|
+
Fail`missing SMART_WALLET in powerFlags`;
|
|
87
|
+
|
|
88
|
+
const bank = E(bankManager).getBankForAddress(address);
|
|
89
|
+
// only proceed if we can provide funds
|
|
90
|
+
await sendInitialPayment(bank);
|
|
91
|
+
|
|
92
|
+
const [_, created] = await E(walletFactory).provideSmartWallet(
|
|
93
|
+
address,
|
|
94
|
+
bank,
|
|
95
|
+
namesByAddressAdmin,
|
|
96
|
+
);
|
|
97
|
+
if (created) {
|
|
98
|
+
onProvisioned();
|
|
99
|
+
}
|
|
100
|
+
trace(created ? 'provisioned' : 're-provisioned', address);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return makeBridgeHandler;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
108
|
+
* @param {{
|
|
109
|
+
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit;
|
|
110
|
+
* params: any;
|
|
111
|
+
* poolBank: import('@endo/far').ERef<Bank>;
|
|
112
|
+
* zcf: ZCF;
|
|
113
|
+
* }} powers
|
|
114
|
+
*/
|
|
115
|
+
export const prepareProvisionPoolKit = (
|
|
116
|
+
baggage,
|
|
117
|
+
{ makeRecorderKit, params, poolBank, zcf },
|
|
118
|
+
) => {
|
|
119
|
+
const zoe = zcf.getZoeService();
|
|
120
|
+
|
|
121
|
+
const makeProvisionPoolKitInternal = prepareExoClassKit(
|
|
122
|
+
baggage,
|
|
123
|
+
'ProvisionPoolKit',
|
|
124
|
+
{
|
|
125
|
+
machine: M.interface('ProvisionPoolKit machine', {
|
|
126
|
+
addRevivableAddresses: M.call(M.arrayOf(M.string())).returns(),
|
|
127
|
+
getWalletReviver: M.call().returns(
|
|
128
|
+
M.remotable('ProvisionPoolKit wallet reviver'),
|
|
129
|
+
),
|
|
130
|
+
setReferences: M.callWhen({
|
|
131
|
+
bankManager: M.eref(M.remotable('bankManager')),
|
|
132
|
+
namesByAddressAdmin: M.eref(M.remotable('nameAdmin')),
|
|
133
|
+
walletFactory: M.eref(M.remotable('walletFactory')),
|
|
134
|
+
}).returns(),
|
|
135
|
+
makeHandler: M.call().returns(M.remotable('BridgeHandler')),
|
|
136
|
+
initPSM: M.call(BrandShape, InstanceHandleShape).returns(),
|
|
137
|
+
}),
|
|
138
|
+
walletReviver: M.interface('ProvisionPoolKit wallet reviver', {
|
|
139
|
+
reviveWallet: M.callWhen(M.string()).returns(
|
|
140
|
+
M.remotable('SmartWallet'),
|
|
141
|
+
),
|
|
142
|
+
ackWallet: M.call(M.string()).returns(M.boolean()),
|
|
143
|
+
}),
|
|
144
|
+
helper: UnguardedHelperI,
|
|
145
|
+
public: M.interface('ProvisionPoolKit public', {
|
|
146
|
+
getPublicTopics: M.call().returns({ metrics: PublicTopicShape }),
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* @param {object} opts
|
|
151
|
+
* @param {Purse<'nat'>} opts.fundPurse
|
|
152
|
+
* @param {Brand<'nat'>} opts.poolBrand
|
|
153
|
+
* @param {StorageNode} opts.metricsNode
|
|
154
|
+
*/
|
|
155
|
+
({ fundPurse, poolBrand, metricsNode }) => {
|
|
156
|
+
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification>} */
|
|
157
|
+
const metricsRecorderKit = makeRecorderKit(metricsNode);
|
|
158
|
+
|
|
159
|
+
/** @type {MapStore<ERef<Brand>, PsmInstance>} */
|
|
160
|
+
const brandToPSM = makeScalarBigMapStore('brandToPSM', { durable: true });
|
|
161
|
+
const revivableAddresses = makeScalarBigSetStore('revivableAddresses', {
|
|
162
|
+
durable: true,
|
|
163
|
+
keyShape: M.string(),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* to be set by `setReferences`
|
|
168
|
+
*
|
|
169
|
+
* @type {Partial<ProvisionPoolKitReferences>}
|
|
170
|
+
*/
|
|
171
|
+
const references = {
|
|
172
|
+
bankManager: undefined,
|
|
173
|
+
namesByAddressAdmin: undefined,
|
|
174
|
+
walletFactory: undefined,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
brandToPSM,
|
|
179
|
+
fundPurse,
|
|
180
|
+
metricsRecorderKit,
|
|
181
|
+
poolBrand,
|
|
182
|
+
walletsProvisioned: 0n,
|
|
183
|
+
totalMintedProvided: AmountMath.makeEmpty(poolBrand),
|
|
184
|
+
totalMintedConverted: AmountMath.makeEmpty(poolBrand),
|
|
185
|
+
revivableAddresses,
|
|
186
|
+
...references,
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
// aka "limitedCreatorFacet"
|
|
191
|
+
machine: {
|
|
192
|
+
/** @param {string[]} oldAddresses */
|
|
193
|
+
addRevivableAddresses(oldAddresses) {
|
|
194
|
+
trace('revivableAddresses count', oldAddresses.length);
|
|
195
|
+
this.state.revivableAddresses.addAll(oldAddresses);
|
|
196
|
+
},
|
|
197
|
+
getWalletReviver() {
|
|
198
|
+
return this.facets.walletReviver;
|
|
199
|
+
},
|
|
200
|
+
/** @param {ProvisionPoolKitReferences} erefs */
|
|
201
|
+
async setReferences(erefs) {
|
|
202
|
+
const { bankManager, namesByAddressAdmin, walletFactory } = erefs;
|
|
203
|
+
const obj = harden({
|
|
204
|
+
bankManager,
|
|
205
|
+
namesByAddressAdmin,
|
|
206
|
+
walletFactory,
|
|
207
|
+
});
|
|
208
|
+
const refs = await deeplyFulfilledObject(obj);
|
|
209
|
+
Object.assign(this.state, refs);
|
|
210
|
+
},
|
|
211
|
+
makeHandler() {
|
|
212
|
+
const { bankManager, namesByAddressAdmin, walletFactory } =
|
|
213
|
+
this.state;
|
|
214
|
+
if (!bankManager || !namesByAddressAdmin || !walletFactory) {
|
|
215
|
+
throw Fail`must set references before handling requests`;
|
|
216
|
+
}
|
|
217
|
+
const { helper } = this.facets;
|
|
218
|
+
// a bit obtuse but leave for backwards compatibility with tests
|
|
219
|
+
const innerMaker = makeBridgeProvisionTool(
|
|
220
|
+
bank => helper.sendInitialPayment(bank),
|
|
221
|
+
() => helper.onProvisioned(),
|
|
222
|
+
);
|
|
223
|
+
return innerMaker({
|
|
224
|
+
bankManager,
|
|
225
|
+
namesByAddressAdmin,
|
|
226
|
+
walletFactory,
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* @param {Brand} brand
|
|
231
|
+
* @param {PsmInstance} instance
|
|
232
|
+
*/
|
|
233
|
+
initPSM(brand, instance) {
|
|
234
|
+
const { brandToPSM } = this.state;
|
|
235
|
+
brandToPSM.init(brand, instance);
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
walletReviver: {
|
|
239
|
+
/** @param {string} address */
|
|
240
|
+
async reviveWallet(address) {
|
|
241
|
+
const {
|
|
242
|
+
revivableAddresses,
|
|
243
|
+
bankManager,
|
|
244
|
+
namesByAddressAdmin,
|
|
245
|
+
walletFactory,
|
|
246
|
+
} = this.state;
|
|
247
|
+
if (!bankManager || !namesByAddressAdmin || !walletFactory) {
|
|
248
|
+
throw Fail`must set references before handling requests`;
|
|
249
|
+
}
|
|
250
|
+
revivableAddresses.has(address) ||
|
|
251
|
+
Fail`non-revivable address ${address}`;
|
|
252
|
+
const bank = E(bankManager).getBankForAddress(address);
|
|
253
|
+
const [wallet, _created] = await E(walletFactory).provideSmartWallet(
|
|
254
|
+
address,
|
|
255
|
+
bank,
|
|
256
|
+
namesByAddressAdmin,
|
|
257
|
+
);
|
|
258
|
+
return wallet;
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* @param {string} address
|
|
262
|
+
* @returns {boolean} isRevive
|
|
263
|
+
*/
|
|
264
|
+
ackWallet(address) {
|
|
265
|
+
const { revivableAddresses } = this.state;
|
|
266
|
+
if (!revivableAddresses.has(address)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
revivableAddresses.delete(address);
|
|
270
|
+
return true;
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
helper: {
|
|
274
|
+
publishMetrics() {
|
|
275
|
+
const {
|
|
276
|
+
metricsRecorderKit,
|
|
277
|
+
walletsProvisioned,
|
|
278
|
+
totalMintedConverted,
|
|
279
|
+
totalMintedProvided,
|
|
280
|
+
} = this.state;
|
|
281
|
+
void metricsRecorderKit.recorder.write(
|
|
282
|
+
harden({
|
|
283
|
+
walletsProvisioned,
|
|
284
|
+
totalMintedProvided,
|
|
285
|
+
totalMintedConverted,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
},
|
|
289
|
+
onTrade(converted) {
|
|
290
|
+
const { state, facets } = this;
|
|
291
|
+
state.totalMintedConverted = AmountMath.add(
|
|
292
|
+
state.totalMintedConverted,
|
|
293
|
+
converted,
|
|
294
|
+
);
|
|
295
|
+
facets.helper.publishMetrics();
|
|
296
|
+
},
|
|
297
|
+
onSendFunds(provided) {
|
|
298
|
+
const { state, facets } = this;
|
|
299
|
+
state.totalMintedProvided = AmountMath.add(
|
|
300
|
+
state.totalMintedProvided,
|
|
301
|
+
provided,
|
|
302
|
+
);
|
|
303
|
+
facets.helper.publishMetrics();
|
|
304
|
+
},
|
|
305
|
+
onProvisioned() {
|
|
306
|
+
const { state, facets } = this;
|
|
307
|
+
state.walletsProvisioned += 1n;
|
|
308
|
+
facets.helper.publishMetrics();
|
|
309
|
+
},
|
|
310
|
+
/** @param {ERef<Bank>} destBank */
|
|
311
|
+
async sendInitialPayment(destBank) {
|
|
312
|
+
const {
|
|
313
|
+
facets: { helper },
|
|
314
|
+
state: { fundPurse, poolBrand },
|
|
315
|
+
} = this;
|
|
316
|
+
const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
|
|
317
|
+
params.getPerAccountInitialAmount()
|
|
318
|
+
);
|
|
319
|
+
const initialPmt = await E(fundPurse).withdraw(
|
|
320
|
+
perAccountInitialAmount,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const destPurse = E(destBank).getPurse(poolBrand);
|
|
324
|
+
return E(destPurse)
|
|
325
|
+
.deposit(initialPmt)
|
|
326
|
+
.then(amt => {
|
|
327
|
+
helper.onSendFunds(perAccountInitialAmount);
|
|
328
|
+
trace('provisionPool sent', amt);
|
|
329
|
+
})
|
|
330
|
+
.catch(reason => {
|
|
331
|
+
console.error(X`initial deposit failed: ${q(reason)}`);
|
|
332
|
+
void E(fundPurse).deposit(initialPmt);
|
|
333
|
+
throw reason;
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
/**
|
|
337
|
+
* @param {ERef<Purse>} exchangePurse
|
|
338
|
+
* @param {ERef<Brand>} brand
|
|
339
|
+
*/
|
|
340
|
+
watchCurrentAmount(exchangePurse, brand) {
|
|
341
|
+
const {
|
|
342
|
+
state: { brandToPSM, poolBrand },
|
|
343
|
+
facets: { helper },
|
|
344
|
+
} = this;
|
|
345
|
+
|
|
346
|
+
void observeNotifier(E(exchangePurse).getCurrentAmountNotifier(), {
|
|
347
|
+
updateState: async amount => {
|
|
348
|
+
trace('provisionPool balance update', amount);
|
|
349
|
+
if (AmountMath.isEmpty(amount) || amount.brand === poolBrand) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (!brandToPSM.has(brand)) {
|
|
353
|
+
console.error('funds arrived but no PSM instance', brand);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const instance = brandToPSM.get(brand);
|
|
357
|
+
const payment = E(exchangePurse).withdraw(amount);
|
|
358
|
+
await helper
|
|
359
|
+
.swap(payment, amount, instance)
|
|
360
|
+
.catch(async reason => {
|
|
361
|
+
console.error(X`swap failed: ${reason}`);
|
|
362
|
+
const resolvedPayment = await payment;
|
|
363
|
+
return E(exchangePurse).deposit(resolvedPayment);
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
|
+
fail: reason => {
|
|
367
|
+
if (isUpgradeDisconnection(reason)) {
|
|
368
|
+
void helper.watchCurrentAmount(exchangePurse, brand);
|
|
369
|
+
} else {
|
|
370
|
+
console.error(reason);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
watchAssetSubscription() {
|
|
376
|
+
const { facets } = this;
|
|
377
|
+
const { helper } = facets;
|
|
378
|
+
|
|
379
|
+
/** @param {import('@agoric/vats/src/vat-bank.js').AssetDescriptor} desc */
|
|
380
|
+
const repairDesc = desc => {
|
|
381
|
+
if (desc.issuerName.match(FIRST_UPPER_KEYWORD)) {
|
|
382
|
+
trace(`Saving Issuer ${desc.issuerName}`);
|
|
383
|
+
return desc;
|
|
384
|
+
} else if (desc.issuerName.match(FIRST_LOWER_NEAR_KEYWORD)) {
|
|
385
|
+
const bad = desc.issuerName;
|
|
386
|
+
const goodName = bad.replace(bad[0], bad[0].toUpperCase());
|
|
387
|
+
|
|
388
|
+
trace(
|
|
389
|
+
`Saving Issuer ${desc.issuerName} with repaired keyword ${goodName}`,
|
|
390
|
+
);
|
|
391
|
+
return { ...desc, issuerName: goodName };
|
|
392
|
+
} else {
|
|
393
|
+
console.error(
|
|
394
|
+
`unable to save issuer with illegal keyword: ${desc.issuerName}`,
|
|
395
|
+
);
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
return observeIteration(
|
|
401
|
+
subscribeEach(E(poolBank).getAssetSubscription()),
|
|
402
|
+
{
|
|
403
|
+
updateState: async desc => {
|
|
404
|
+
await null;
|
|
405
|
+
const issuer = zcf.getTerms().issuers[desc.issuerName];
|
|
406
|
+
if (issuer === desc.issuer) {
|
|
407
|
+
trace('provisionPool re-notified of known asset', desc.brand);
|
|
408
|
+
} else {
|
|
409
|
+
const goodDesc = repairDesc(desc);
|
|
410
|
+
if (goodDesc) {
|
|
411
|
+
await zcf.saveIssuer(goodDesc.issuer, goodDesc.issuerName);
|
|
412
|
+
} else {
|
|
413
|
+
console.error(
|
|
414
|
+
`unable to save issuer with illegal keyword: ${desc.issuerName}`,
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** @type {ERef<Purse>} */
|
|
420
|
+
const exchangePurse = E(poolBank).getPurse(desc.brand);
|
|
421
|
+
helper.watchCurrentAmount(exchangePurse, desc.brand);
|
|
422
|
+
},
|
|
423
|
+
fail: _reason => {
|
|
424
|
+
void helper.watchAssetSubscription();
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
);
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* @param {object} [options]
|
|
431
|
+
* @param {MetricsNotification} [options.metrics]
|
|
432
|
+
*/
|
|
433
|
+
start({ metrics } = {}) {
|
|
434
|
+
const {
|
|
435
|
+
state: { poolBrand },
|
|
436
|
+
facets: { helper },
|
|
437
|
+
} = this;
|
|
438
|
+
|
|
439
|
+
// Must match. poolBrand is from durable state and the param is from
|
|
440
|
+
// the contract, so it technically can change between incarnations.
|
|
441
|
+
// That would be a severe bug.
|
|
442
|
+
AmountMath.coerce(poolBrand, params.getPerAccountInitialAmount());
|
|
443
|
+
|
|
444
|
+
void helper.watchAssetSubscription();
|
|
445
|
+
|
|
446
|
+
if (metrics) {
|
|
447
|
+
// Restore state.
|
|
448
|
+
// we publishMetrics() below
|
|
449
|
+
const {
|
|
450
|
+
walletsProvisioned,
|
|
451
|
+
totalMintedProvided,
|
|
452
|
+
totalMintedConverted,
|
|
453
|
+
} = metrics;
|
|
454
|
+
assert.typeof(walletsProvisioned, 'bigint');
|
|
455
|
+
AmountMath.coerce(poolBrand, totalMintedProvided);
|
|
456
|
+
AmountMath.coerce(poolBrand, totalMintedConverted);
|
|
457
|
+
Object.assign(this.state, {
|
|
458
|
+
walletsProvisioned,
|
|
459
|
+
totalMintedProvided,
|
|
460
|
+
totalMintedConverted,
|
|
461
|
+
});
|
|
462
|
+
helper.publishMetrics();
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
/**
|
|
466
|
+
* @param {ERef<Payment>} payIn
|
|
467
|
+
* @param {Amount} amount
|
|
468
|
+
* @param {PsmInstance} instance
|
|
469
|
+
*/
|
|
470
|
+
async swap(payIn, amount, instance) {
|
|
471
|
+
const {
|
|
472
|
+
facets: { helper },
|
|
473
|
+
state: { fundPurse },
|
|
474
|
+
} = this;
|
|
475
|
+
const psmPub = E(zoe).getPublicFacet(instance);
|
|
476
|
+
const proposal = harden({ give: { In: amount } });
|
|
477
|
+
const invitation = E(psmPub).makeWantMintedInvitation();
|
|
478
|
+
const seat = E(zoe).offer(invitation, proposal, { In: payIn });
|
|
479
|
+
const payout = await E(seat).getPayout('Out');
|
|
480
|
+
const rxd = await E(fundPurse).deposit(payout);
|
|
481
|
+
helper.onTrade(rxd);
|
|
482
|
+
return rxd;
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
public: {
|
|
486
|
+
getPublicTopics() {
|
|
487
|
+
return {
|
|
488
|
+
metrics: makeRecorderTopic(
|
|
489
|
+
'Provision Pool metrics',
|
|
490
|
+
this.state.metricsRecorderKit,
|
|
491
|
+
),
|
|
492
|
+
};
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
finish: ({ facets }) => {
|
|
498
|
+
facets.helper.publishMetrics();
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Prepare synchronous values before passing to real Exo maker
|
|
505
|
+
*
|
|
506
|
+
* @param {object} opts
|
|
507
|
+
* @param {Brand<'nat'>} opts.poolBrand
|
|
508
|
+
* @param {ERef<StorageNode>} opts.storageNode
|
|
509
|
+
*/
|
|
510
|
+
const makeProvisionPoolKit = async ({ poolBrand, storageNode }) => {
|
|
511
|
+
const fundPurse = await E(poolBank).getPurse(poolBrand);
|
|
512
|
+
const metricsNode = await E(storageNode).makeChildNode('metrics');
|
|
513
|
+
|
|
514
|
+
return makeProvisionPoolKitInternal({
|
|
515
|
+
fundPurse,
|
|
516
|
+
poolBrand,
|
|
517
|
+
metricsNode,
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
return makeProvisionPoolKit;
|
|
522
|
+
};
|
package/src/psm/psm.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
/**
|
|
23
|
+
* @import {TypedPattern} from '@agoric/internal';
|
|
24
|
+
* @import {Baggage} from '@agoric/vat-data'
|
|
25
|
+
*/
|
|
26
|
+
/** @type {ContractMeta} */
|
|
27
|
+
export const meta: ContractMeta;
|
|
28
|
+
export function start(zcf: ZCF<GovernanceTerms<{
|
|
29
|
+
GiveMintedFee: "ratio";
|
|
30
|
+
WantMintedFee: "ratio";
|
|
31
|
+
MintLimit: "amount";
|
|
32
|
+
}> & {
|
|
33
|
+
anchorBrand: Brand<"nat">;
|
|
34
|
+
anchorPerMinted: Ratio;
|
|
35
|
+
}>, privateArgs: {
|
|
36
|
+
feeMintAccess: FeeMintAccess;
|
|
37
|
+
initialPoserInvitation: Invitation;
|
|
38
|
+
storageNode: StorageNode;
|
|
39
|
+
marshaller: Marshaller;
|
|
40
|
+
}, baggage: Baggage): Promise<{
|
|
41
|
+
creatorFacet: import("@endo/exo").Guarded<{
|
|
42
|
+
getParamMgrRetriever: () => {
|
|
43
|
+
get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
|
|
44
|
+
GiveMintedFee: "ratio";
|
|
45
|
+
MintLimit: "amount";
|
|
46
|
+
WantMintedFee: "ratio";
|
|
47
|
+
} & {
|
|
48
|
+
Electorate: "invitation";
|
|
49
|
+
}>;
|
|
50
|
+
} & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
51
|
+
get: () => import("@agoric/governance/src/contractGovernance/typedParamManager.js").TypedParamManager<{
|
|
52
|
+
GiveMintedFee: "ratio";
|
|
53
|
+
MintLimit: "amount";
|
|
54
|
+
WantMintedFee: "ratio";
|
|
55
|
+
} & {
|
|
56
|
+
Electorate: "invitation";
|
|
57
|
+
}>;
|
|
58
|
+
}>;
|
|
59
|
+
getInvitation: (name: any) => Promise<Invitation<unknown, undefined>>;
|
|
60
|
+
getLimitedCreatorFacet: () => import("@endo/exo").Guarded<{
|
|
61
|
+
getRewardAllocation(): Allocation;
|
|
62
|
+
makeCollectFeesInvitation(): Promise<Invitation<string, undefined>>;
|
|
63
|
+
makeRestoreMetricsInvitation(): Promise<Invitation<void, Omit<MetricsNotification, "anchorPoolBalance">>>;
|
|
64
|
+
}>;
|
|
65
|
+
getGovernedApis: () => GovernedApis;
|
|
66
|
+
getGovernedApiNames: () => string[];
|
|
67
|
+
setOfferFilter: (strings: any) => Promise<void>;
|
|
68
|
+
}>;
|
|
69
|
+
publicFacet: import("@endo/exo").Guarded<{
|
|
70
|
+
getAmount: (name: string) => Amount;
|
|
71
|
+
getBrand: (name: string) => Brand;
|
|
72
|
+
getInstance: (name: string) => Instance;
|
|
73
|
+
getInstallation: (name: string) => Installation;
|
|
74
|
+
getInvitationAmount: (name: string) => InvitationAmount;
|
|
75
|
+
getNat: (name: string) => bigint;
|
|
76
|
+
getRatio: (name: string) => Ratio;
|
|
77
|
+
getString: (name: string) => string;
|
|
78
|
+
getTimestamp: (name: string) => import("@agoric/time").TimestampRecord;
|
|
79
|
+
getRelativeTime: (name: string) => import("@agoric/time").RelativeTimeRecord;
|
|
80
|
+
getUnknown: (name: string) => any;
|
|
81
|
+
getSubscription: () => globalThis.StoredSubscription<globalThis.GovernanceSubscriptionState>;
|
|
82
|
+
getGovernedParams: () => globalThis.ERef<globalThis.ParamStateRecord>;
|
|
83
|
+
getMetrics(): globalThis.Subscriber<MetricsNotification>;
|
|
84
|
+
getPoolBalance(): import("@agoric/ertp").NatAmount;
|
|
85
|
+
getPublicTopics(): {
|
|
86
|
+
metrics: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<MetricsNotification>;
|
|
87
|
+
};
|
|
88
|
+
makeWantMintedInvitation(): Promise<Invitation<void, undefined>>;
|
|
89
|
+
makeGiveMintedInvitation(): Promise<Invitation<void, undefined>>;
|
|
90
|
+
}>;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Metrics naming scheme is that nouns are
|
|
94
|
+
* present values and past-participles are accumulative.
|
|
95
|
+
*/
|
|
96
|
+
export type MetricsNotification = {
|
|
97
|
+
/**
|
|
98
|
+
* amount of Anchor token available
|
|
99
|
+
* to be swapped
|
|
100
|
+
*/
|
|
101
|
+
anchorPoolBalance: Amount<"nat">;
|
|
102
|
+
/**
|
|
103
|
+
* amount of Minted token
|
|
104
|
+
* outstanding (the amount minted minus the amount burned).
|
|
105
|
+
*/
|
|
106
|
+
mintedPoolBalance: Amount<"nat">;
|
|
107
|
+
/**
|
|
108
|
+
* amount of Minted token fees
|
|
109
|
+
* available to be collected
|
|
110
|
+
*/
|
|
111
|
+
feePoolBalance: Amount<"nat">;
|
|
112
|
+
/**
|
|
113
|
+
* running sum of Anchor ever
|
|
114
|
+
* given by this contract
|
|
115
|
+
*/
|
|
116
|
+
totalAnchorProvided: Amount<"nat">;
|
|
117
|
+
/**
|
|
118
|
+
* running sum of Minted ever
|
|
119
|
+
* given by this contract
|
|
120
|
+
*/
|
|
121
|
+
totalMintedProvided: Amount<"nat">;
|
|
122
|
+
};
|
|
123
|
+
export type PsmPublicFacet = Awaited<ReturnType<typeof start>>["publicFacet"];
|
|
124
|
+
import type { Baggage } from '@agoric/vat-data';
|
|
125
|
+
//# sourceMappingURL=psm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psm.d.ts","sourceRoot":"","sources":["psm.js"],"names":[],"mappings":"AAqCA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AAEH,2BAA2B;AAC3B,mBADW,YAAY,CAkCrB;AAsBK,2BAlBI,GAAG,CACT,eAAe,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,QAAQ,CAAC;CACrB,CAAC,GAAG;IACH,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,eAAe,EAAE,KAAK,CAAC;CACxB,CACF,eACO;IACN,aAAa,EAAE,aAAa,CAAC;IAC7B,sBAAsB,EAAE,UAAU,CAAC;IACnC,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB,WACO,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CAsU4F,cAAc;kDAAuE,cAAc;;;;;;;;;;;;GAJhN;;;;;;;;;;uBAzYa,MAAM,CAAC,KAAK,CAAC;;;;;uBAEb,MAAM,CAAC,KAAK,CAAC;;;;;oBAEb,MAAM,CAAC,KAAK,CAAC;;;;;yBAEb,MAAM,CAAC,KAAK,CAAC;;;;;yBAEb,MAAM,CAAC,KAAK,CAAC;;6BAoYb,OAAO,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;6BA9XpC,kBAAkB"}
|