@agoric/inter-protocol 0.13.3 → 0.13.4-dev-d32a66a.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 +26 -20
- package/bundles/bundle-auctioneer-js-meta.json +722 -0
- package/bundles/bundle-auctioneer.js +1 -0
- package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
- package/bundles/bundle-econCommitteeCharter.js +1 -0
- package/bundles/bundle-feeDistributor-js-meta.json +458 -0
- package/bundles/bundle-feeDistributor.js +1 -1
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
- package/bundles/bundle-fluxAggregatorKit.js +1 -0
- package/bundles/bundle-psm-js-meta.json +666 -0
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-js-meta.json +662 -0
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
- package/bundles/bundle-scaledPriceAuthority.js +1 -1
- package/bundles/bundle-vaultFactory-js-meta.json +786 -0
- package/bundles/bundle-vaultFactory.js +1 -1
- package/exported.js +0 -2
- package/package.json +34 -31
- package/scripts/add-collateral-core.js +14 -4
- package/scripts/build-bundles.js +9 -2
- package/scripts/deploy-contracts.js +1 -4
- package/scripts/init-core.js +20 -38
- package/scripts/invite-committee-core.js +1 -1
- package/scripts/manual-price-feed.js +2 -2
- package/scripts/price-feed-core.js +7 -6
- package/scripts/start-local-chain.sh +84 -0
- package/src/auction/auctionBook.js +755 -0
- package/src/auction/auctioneer.js +720 -0
- package/src/auction/offerBook.js +221 -0
- package/src/auction/params.js +174 -0
- package/src/auction/scheduleMath.js +167 -0
- package/src/auction/scheduler.js +370 -0
- package/src/auction/sortedOffers.js +136 -0
- package/src/auction/util.js +55 -0
- package/src/clientSupport.js +324 -0
- package/src/collectFees.js +8 -14
- package/src/contractSupport.js +24 -68
- package/src/econCommitteeCharter.js +161 -77
- package/src/feeDistributor.js +60 -20
- package/src/index.js +2 -0
- package/src/interest-math.js +1 -4
- package/src/interest.js +20 -13
- package/src/price/README.md +57 -0
- package/src/price/fluxAggregatorContract.js +190 -0
- package/src/price/fluxAggregatorKit.js +375 -0
- package/src/price/priceOracleKit.js +127 -0
- package/src/price/roundsManager.js +726 -0
- package/src/proposals/addAssetToVault.js +89 -94
- package/src/proposals/committee-proposal.js +141 -40
- package/src/proposals/core-proposal.js +100 -167
- package/src/proposals/econ-behaviors.js +320 -564
- package/src/proposals/price-feed-proposal.js +175 -78
- package/src/proposals/startEconCommittee.js +25 -12
- package/src/proposals/startPSM.js +231 -211
- package/src/proposals/utils.js +31 -17
- package/src/psm/README.md +71 -0
- package/src/psm/psm.js +272 -160
- package/src/psm/types.js +2 -0
- package/src/reserve/assetReserve.js +56 -413
- package/src/reserve/assetReserveKit.js +303 -0
- package/src/reserve/doc.md +1 -3
- package/src/reserve/params.js +2 -5
- package/src/typeGuards.js +13 -0
- package/src/vaultFactory/Liquidation.md +100 -0
- package/src/vaultFactory/burn.js +2 -1
- package/src/vaultFactory/liquidation.js +270 -108
- package/src/vaultFactory/math.js +95 -0
- package/src/vaultFactory/orderedVaultStore.js +0 -1
- package/src/vaultFactory/params.js +133 -112
- package/src/vaultFactory/prioritizedVaults.js +36 -79
- package/src/vaultFactory/storeUtils.js +67 -9
- package/src/vaultFactory/type-imports.js +2 -0
- package/src/vaultFactory/types.js +22 -26
- package/src/vaultFactory/vault.js +772 -709
- package/src/vaultFactory/vaultDirector.js +480 -483
- package/src/vaultFactory/vaultFactory.js +99 -60
- package/src/vaultFactory/vaultHolder.js +121 -95
- package/src/vaultFactory/vaultKit.js +39 -31
- package/src/vaultFactory/vaultManager.js +1249 -868
- package/bundles/bundle-amm-meta.js +0 -618
- package/bundles/bundle-amm.js +0 -1
- package/bundles/bundle-feeDistributor-meta.js +0 -346
- package/bundles/bundle-interchainPool-meta.js +0 -534
- package/bundles/bundle-interchainPool.js +0 -1
- package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
- package/bundles/bundle-liquidateIncrementally.js +0 -1
- package/bundles/bundle-liquidateMinimum-meta.js +0 -442
- package/bundles/bundle-liquidateMinimum.js +0 -1
- package/bundles/bundle-psm-meta.js +0 -538
- package/bundles/bundle-psmCharter-meta.js +0 -418
- package/bundles/bundle-psmCharter.js +0 -1
- package/bundles/bundle-reserve-meta.js +0 -542
- package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
- package/bundles/bundle-stakeFactory-meta.js +0 -574
- package/bundles/bundle-stakeFactory.js +0 -1
- package/bundles/bundle-vaultFactory-meta.js +0 -598
- package/scripts/add-initial-liquidity.js +0 -180
- package/src/collect.js +0 -13
- package/src/interchainPool.js +0 -135
- package/src/makeTracer.js +0 -36
- package/src/my-lien.js +0 -85
- package/src/proposals/demoIssuers.js +0 -685
- package/src/proposals/sim-behaviors.js +0 -40
- package/src/psm/psmCharter.js +0 -139
- package/src/stakeFactory/README.md +0 -62
- package/src/stakeFactory/attestation.js +0 -267
- package/src/stakeFactory/attestationTool.js +0 -66
- package/src/stakeFactory/constants.js +0 -16
- package/src/stakeFactory/params.js +0 -31
- package/src/stakeFactory/stakeFactory.js +0 -236
- package/src/stakeFactory/stakeFactoryKit.js +0 -455
- package/src/stakeFactory/stakeFactoryManager.js +0 -296
- package/src/stakeFactory/types.js +0 -42
- package/src/vaultFactory/liquidateIncrementally.js +0 -350
- package/src/vaultFactory/liquidateMinimum.js +0 -100
- package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
- package/src/vpool-xyk-amm/addLiquidity.js +0 -222
- package/src/vpool-xyk-amm/addPool.js +0 -197
- package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
- package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
- package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
- package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
- package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
- package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
- package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
- package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
- package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
- package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
- package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
- package/src/vpool-xyk-amm/doublePool.js +0 -194
- package/src/vpool-xyk-amm/estimate.js +0 -155
- package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
- package/src/vpool-xyk-amm/params.js +0 -61
- package/src/vpool-xyk-amm/pool.js +0 -396
- package/src/vpool-xyk-amm/priceAuthority.js +0 -94
- package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
- package/src/vpool-xyk-amm/singlePool.js +0 -73
- package/src/vpool-xyk-amm/swap.js +0 -69
- package/src/vpool-xyk-amm/types.js +0 -154
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
|
-
import '@agoric/governance/
|
|
3
|
+
import '@agoric/governance/exported.js';
|
|
4
4
|
import '@agoric/zoe/exported.js';
|
|
5
5
|
import '@agoric/zoe/src/contracts/exported.js';
|
|
6
6
|
|
|
@@ -8,10 +8,8 @@ import '@agoric/zoe/src/contracts/exported.js';
|
|
|
8
8
|
//
|
|
9
9
|
// addVaultType is a closely held method that adds a brand new collateral type.
|
|
10
10
|
// It specifies the initial exchange rate for that type. It depends on a
|
|
11
|
-
// separately specified
|
|
12
|
-
// in arrears.
|
|
13
|
-
// moment leave that to those participating in the governance process for adding
|
|
14
|
-
// new collateral type to ascertain.
|
|
11
|
+
// separately specified mechanism to liquidate vaults that are
|
|
12
|
+
// in arrears.
|
|
15
13
|
|
|
16
14
|
// This contract wants to be managed by a contractGovernor, but it isn't
|
|
17
15
|
// compatible with contractGovernor, since it has a separate paramManager for
|
|
@@ -19,30 +17,45 @@ import '@agoric/zoe/src/contracts/exported.js';
|
|
|
19
17
|
// to satisfy contractGovernor. It needs to return a creatorFacet with
|
|
20
18
|
// { getParamMgrRetriever, getInvitation, getLimitedCreatorFacet }.
|
|
21
19
|
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from '
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
20
|
+
import { CONTRACT_ELECTORATE } from '@agoric/governance';
|
|
21
|
+
import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js';
|
|
22
|
+
import { validateElectorate } from '@agoric/governance/src/contractHelper.js';
|
|
23
|
+
import { makeTracer, StorageNodeShape } from '@agoric/internal';
|
|
24
|
+
import { makeStoredSubscription, makeSubscriptionKit } from '@agoric/notifier';
|
|
25
|
+
import { M } from '@agoric/store';
|
|
26
|
+
import { provideAll } from '@agoric/zoe/src/contractSupport/durability.js';
|
|
27
|
+
import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
|
|
28
|
+
import { E } from '@endo/eventual-send';
|
|
29
|
+
import { FeeMintAccessShape } from '@agoric/zoe/src/typeGuards.js';
|
|
30
|
+
import { InvitationShape } from '../auction/params.js';
|
|
31
|
+
import { SHORTFALL_INVITATION_KEY, vaultDirectorParamTypes } from './params.js';
|
|
32
|
+
import { provideDirector } from './vaultDirector.js';
|
|
33
|
+
|
|
34
|
+
const trace = makeTracer('VF', true);
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
|
|
35
|
-
*
|
|
36
|
-
* liquidationInstall: Installation<import('./liquidateMinimum.js').start>,
|
|
37
|
-
* loanTimingParams: {ChargingPeriod: ParamValueTyped<'nat'>, RecordingPeriod: ParamValueTyped<'nat'>},
|
|
38
|
-
* minInitialDebt: Amount,
|
|
38
|
+
* auctioneerPublicFacet: import('../auction/auctioneer.js').AuctioneerPublicFacet,
|
|
39
39
|
* priceAuthority: ERef<PriceAuthority>,
|
|
40
40
|
* reservePublicFacet: AssetReservePublicFacet,
|
|
41
|
-
* timerService: TimerService,
|
|
42
|
-
* shortfallInvitation: 'invitation',
|
|
41
|
+
* timerService: import('@agoric/time/src/types').TimerService,
|
|
43
42
|
* }>} VaultFactoryZCF
|
|
44
43
|
*/
|
|
45
44
|
|
|
45
|
+
export const privateArgsShape = M.splitRecord(
|
|
46
|
+
harden({
|
|
47
|
+
marshaller: M.remotable('Marshaller'),
|
|
48
|
+
storageNode: StorageNodeShape,
|
|
49
|
+
}),
|
|
50
|
+
harden({
|
|
51
|
+
// only necessary on first invocation, not subsequent
|
|
52
|
+
feeMintAccess: FeeMintAccessShape,
|
|
53
|
+
initialPoserInvitation: InvitationShape,
|
|
54
|
+
initialShortfallInvitation: InvitationShape,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
harden(privateArgsShape);
|
|
58
|
+
|
|
46
59
|
/**
|
|
47
60
|
* @param {VaultFactoryZCF} zcf
|
|
48
61
|
* @param {{
|
|
@@ -52,59 +65,85 @@ import { assertKeysDefined } from '../contractSupport.js';
|
|
|
52
65
|
* storageNode: ERef<StorageNode>,
|
|
53
66
|
* marshaller: ERef<Marshaller>,
|
|
54
67
|
* }} privateArgs
|
|
68
|
+
* @param {import('@agoric/ertp').Baggage} baggage
|
|
55
69
|
*/
|
|
56
|
-
export const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const debtMint = await
|
|
70
|
+
export const prepare = async (zcf, privateArgs, baggage) => {
|
|
71
|
+
trace('prepare start', privateArgs, [...baggage.keys()]);
|
|
72
|
+
const {
|
|
73
|
+
initialPoserInvitation,
|
|
74
|
+
initialShortfallInvitation,
|
|
75
|
+
marshaller,
|
|
76
|
+
storageNode,
|
|
77
|
+
} = privateArgs;
|
|
78
|
+
|
|
79
|
+
trace('awaiting debtMint');
|
|
80
|
+
const { debtMint } = await provideAll(baggage, {
|
|
81
|
+
debtMint: () => zcf.registerFeeMint('Minted', privateArgs.feeMintAccess),
|
|
82
|
+
});
|
|
83
|
+
|
|
67
84
|
zcf.setTestJig(() => ({
|
|
68
85
|
mintedIssuerRecord: debtMint.getIssuerRecord(),
|
|
69
86
|
}));
|
|
70
87
|
|
|
71
|
-
const {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/** a powerful object; can modify the invitation */
|
|
77
|
-
const vaultDirectorParamManager = await makeVaultDirectorParamManager(
|
|
78
|
-
makeStoredPublisherKit(
|
|
79
|
-
privateArgs.storageNode,
|
|
80
|
-
privateArgs.marshaller,
|
|
81
|
-
'governance',
|
|
82
|
-
),
|
|
83
|
-
zcf.getZoeService(),
|
|
84
|
-
initialPoserInvitation,
|
|
85
|
-
liqInstall,
|
|
86
|
-
liqTerms,
|
|
87
|
-
minInitialDebt,
|
|
88
|
-
initialShortfallInvitation,
|
|
88
|
+
const { timerService, auctioneerPublicFacet } = zcf.getTerms();
|
|
89
|
+
|
|
90
|
+
const { makeRecorderKit, makeERecorderKit } = prepareRecorderKitMakers(
|
|
91
|
+
baggage,
|
|
92
|
+
marshaller,
|
|
89
93
|
);
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
trace('making non-durable publishers');
|
|
96
|
+
// XXX non-durable, will sever upon vat restart
|
|
97
|
+
const governanceSubscriptionKit = makeSubscriptionKit();
|
|
98
|
+
const governanceNode = E(storageNode).makeChildNode('governance');
|
|
99
|
+
const governanceSubscriber = makeStoredSubscription(
|
|
100
|
+
governanceSubscriptionKit.subscription,
|
|
101
|
+
governanceNode,
|
|
102
|
+
marshaller,
|
|
103
|
+
);
|
|
104
|
+
/** a powerful object; can modify the invitation */
|
|
105
|
+
trace('awaiting makeParamManagerFromTerms');
|
|
106
|
+
const vaultDirectorParamManager = await makeParamManagerFromTerms(
|
|
107
|
+
{
|
|
108
|
+
publisher: governanceSubscriptionKit.publication,
|
|
109
|
+
subscriber: governanceSubscriber,
|
|
110
|
+
},
|
|
111
|
+
zcf,
|
|
112
|
+
{
|
|
113
|
+
[CONTRACT_ELECTORATE]: initialPoserInvitation,
|
|
114
|
+
[SHORTFALL_INVITATION_KEY]: initialShortfallInvitation,
|
|
115
|
+
},
|
|
116
|
+
vaultDirectorParamTypes,
|
|
94
117
|
);
|
|
95
118
|
|
|
96
|
-
const
|
|
119
|
+
const director = provideDirector(
|
|
120
|
+
baggage,
|
|
97
121
|
zcf,
|
|
98
122
|
vaultDirectorParamManager,
|
|
99
123
|
debtMint,
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
timerService,
|
|
125
|
+
auctioneerPublicFacet,
|
|
126
|
+
storageNode,
|
|
127
|
+
// XXX remove Recorder makers; remove once we excise deprecated kits for governance
|
|
128
|
+
marshaller,
|
|
129
|
+
makeRecorderKit,
|
|
130
|
+
makeERecorderKit,
|
|
102
131
|
);
|
|
103
132
|
|
|
133
|
+
// cannot await because it would make remote calls during vat restart
|
|
134
|
+
director.helper.start().catch(err => {
|
|
135
|
+
console.error('💀 vaultDirector failed to start:', err);
|
|
136
|
+
zcf.shutdownWithFailure(err);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// validate async to wait for params to be finished
|
|
140
|
+
// UNTIL https://github.com/Agoric/agoric-sdk/issues/4343
|
|
141
|
+
void validateElectorate(zcf, vaultDirectorParamManager);
|
|
142
|
+
|
|
104
143
|
return harden({
|
|
105
|
-
creatorFacet:
|
|
106
|
-
publicFacet:
|
|
144
|
+
creatorFacet: director.creator,
|
|
145
|
+
publicFacet: director.public,
|
|
107
146
|
});
|
|
108
147
|
};
|
|
109
148
|
|
|
110
|
-
/** @typedef {ContractOf<typeof
|
|
149
|
+
/** @typedef {ContractOf<typeof prepare>} VaultFactoryContract */
|
|
@@ -1,111 +1,137 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Use-object for the owner of a vault
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import '@agoric/
|
|
4
|
+
import { AmountShape } from '@agoric/ertp';
|
|
5
|
+
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
6
|
+
import {
|
|
7
|
+
SubscriberShape,
|
|
8
|
+
TopicsRecordShape,
|
|
9
|
+
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
10
|
+
import { UnguardedHelperI } from '../typeGuards.js';
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
import { defineDurableKindMulti, makeKindHandle } from '@agoric/vat-data';
|
|
9
|
-
import { makeEphemeraProvider } from '../contractSupport.js';
|
|
10
|
-
|
|
11
|
-
const { details: X } = assert;
|
|
12
|
-
|
|
13
|
-
// XXX durable key to an ephemeral object
|
|
14
|
-
// UNTIL https://github.com/Agoric/agoric-sdk/issues/4567
|
|
15
|
-
let holderId = 0n;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @type {(key: bigint) => {
|
|
19
|
-
* publisher: StoredPublishKit<VaultNotification>['publisher'],
|
|
20
|
-
* subscriber: StoredPublishKit<VaultNotification>['subscriber'],
|
|
21
|
-
* }} */
|
|
22
|
-
// @ts-expect-error not yet defined
|
|
23
|
-
const provideEphemera = makeEphemeraProvider(() => ({}));
|
|
12
|
+
const { Fail } = assert;
|
|
24
13
|
|
|
25
14
|
/**
|
|
26
15
|
* @typedef {{
|
|
27
|
-
*
|
|
16
|
+
* topicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<VaultNotification>,
|
|
28
17
|
* vault: Vault | null,
|
|
29
18
|
* }} State
|
|
30
|
-
* @typedef {Readonly<{
|
|
31
|
-
* state: State,
|
|
32
|
-
* facets: {
|
|
33
|
-
* helper: import('@agoric/vat-data/src/types').KindFacet<typeof helper>,
|
|
34
|
-
* self: import('@agoric/vat-data/src/types').KindFacet<typeof holder>,
|
|
35
|
-
* },
|
|
36
|
-
* }>} MethodContext
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {Vault} vault
|
|
42
|
-
* @param {ERef<StorageNode>} storageNode
|
|
43
|
-
* @param {ERef<Marshaller>} marshaller
|
|
44
|
-
* @returns {State}
|
|
45
19
|
*/
|
|
46
|
-
const initState = (vault, storageNode, marshaller) => {
|
|
47
|
-
/** @type {StoredPublishKit<VaultNotification>} */
|
|
48
|
-
const { subscriber, publisher } = makeStoredPublishKit(
|
|
49
|
-
storageNode,
|
|
50
|
-
marshaller,
|
|
51
|
-
);
|
|
52
20
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
21
|
+
const HolderI = M.interface('holder', {
|
|
22
|
+
getCollateralAmount: M.call().returns(AmountShape),
|
|
23
|
+
getCurrentDebt: M.call().returns(AmountShape),
|
|
24
|
+
getNormalizedDebt: M.call().returns(AmountShape),
|
|
25
|
+
getSubscriber: M.call().returns(SubscriberShape),
|
|
26
|
+
getPublicTopics: M.call().returns(TopicsRecordShape),
|
|
27
|
+
makeAdjustBalancesInvitation: M.call().returns(M.promise()),
|
|
28
|
+
makeCloseInvitation: M.call().returns(M.promise()),
|
|
29
|
+
makeTransferInvitation: M.call().returns(M.promise()),
|
|
30
|
+
});
|
|
57
31
|
|
|
58
|
-
|
|
32
|
+
/** @type {{ [name: string]: [ description: string, valueShape: Pattern ] }} */
|
|
33
|
+
const PUBLIC_TOPICS = {
|
|
34
|
+
vault: ['Vault holder status', M.any()],
|
|
59
35
|
};
|
|
60
36
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @param {import('@agoric/ertp').Baggage} baggage
|
|
39
|
+
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
|
|
40
|
+
*/
|
|
41
|
+
export const prepareVaultHolder = (baggage, makeRecorderKit) => {
|
|
42
|
+
const makeVaultHolderKit = prepareExoClassKit(
|
|
43
|
+
baggage,
|
|
44
|
+
'Vault Holder',
|
|
45
|
+
{
|
|
46
|
+
helper: UnguardedHelperI,
|
|
47
|
+
holder: HolderI,
|
|
48
|
+
invitationMakers: M.interface('invitationMakers', {
|
|
49
|
+
AdjustBalances: M.call().returns(M.promise()),
|
|
50
|
+
CloseVault: M.call().returns(M.promise()),
|
|
51
|
+
TransferVault: M.call().returns(M.promise()),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {Vault} vault
|
|
57
|
+
* @param {StorageNode} storageNode
|
|
58
|
+
* @returns {State}
|
|
59
|
+
*/
|
|
60
|
+
(vault, storageNode) => {
|
|
61
|
+
// must be the fully synchronous maker because the kit is held in durable state
|
|
62
|
+
const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.vault[1]);
|
|
74
63
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
64
|
+
return { topicKit, vault };
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
helper: {
|
|
68
|
+
/**
|
|
69
|
+
* @throws if this holder no longer owns the vault
|
|
70
|
+
*/
|
|
71
|
+
owned() {
|
|
72
|
+
const { vault } = this.state;
|
|
73
|
+
if (!vault) {
|
|
74
|
+
throw Fail`Using vault holder after transfer`;
|
|
75
|
+
}
|
|
76
|
+
return vault;
|
|
77
|
+
},
|
|
78
|
+
getUpdater() {
|
|
79
|
+
return this.state.topicKit.recorder;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
invitationMakers: {
|
|
83
|
+
AdjustBalances() {
|
|
84
|
+
return this.facets.holder.makeAdjustBalancesInvitation();
|
|
85
|
+
},
|
|
86
|
+
CloseVault() {
|
|
87
|
+
return this.facets.holder.makeCloseInvitation();
|
|
88
|
+
},
|
|
89
|
+
TransferVault() {
|
|
90
|
+
return this.facets.holder.makeTransferInvitation();
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
holder: {
|
|
94
|
+
/** @deprecated use getPublicTopics */
|
|
95
|
+
getSubscriber() {
|
|
96
|
+
return this.state.topicKit.subscriber;
|
|
97
|
+
},
|
|
98
|
+
getPublicTopics() {
|
|
99
|
+
const { topicKit } = this.state;
|
|
100
|
+
return harden({
|
|
101
|
+
vault: {
|
|
102
|
+
description: PUBLIC_TOPICS.vault[0],
|
|
103
|
+
subscriber: topicKit.subscriber,
|
|
104
|
+
storagePath: topicKit.recorder.getStoragePath(),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
makeAdjustBalancesInvitation() {
|
|
109
|
+
return this.facets.helper.owned().makeAdjustBalancesInvitation();
|
|
110
|
+
},
|
|
111
|
+
makeCloseInvitation() {
|
|
112
|
+
return this.facets.helper.owned().makeCloseInvitation();
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Starting a transfer revokes the vault holder. The associated updater will
|
|
116
|
+
* get a special notification that the vault is being transferred.
|
|
117
|
+
*/
|
|
118
|
+
makeTransferInvitation() {
|
|
119
|
+
const vault = this.facets.helper.owned();
|
|
120
|
+
this.state.vault = null;
|
|
121
|
+
return vault.makeTransferInvitation();
|
|
122
|
+
},
|
|
123
|
+
// for status/debugging
|
|
124
|
+
getCollateralAmount() {
|
|
125
|
+
return this.facets.helper.owned().getCollateralAmount();
|
|
126
|
+
},
|
|
127
|
+
getCurrentDebt() {
|
|
128
|
+
return this.facets.helper.owned().getCurrentDebt();
|
|
129
|
+
},
|
|
130
|
+
getNormalizedDebt() {
|
|
131
|
+
return this.facets.helper.owned().getNormalizedDebt();
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
return makeVaultHolderKit;
|
|
103
137
|
};
|
|
104
|
-
|
|
105
|
-
const behavior = { helper, holder };
|
|
106
|
-
|
|
107
|
-
export const makeVaultHolder = defineDurableKindMulti(
|
|
108
|
-
makeKindHandle('VaultHolder'),
|
|
109
|
-
initState,
|
|
110
|
-
behavior,
|
|
111
|
-
);
|
|
@@ -1,38 +1,46 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
|
+
|
|
2
3
|
import '@agoric/zoe/exported.js';
|
|
3
|
-
|
|
4
|
-
import {
|
|
4
|
+
|
|
5
|
+
import { makeTracer } from '@agoric/internal';
|
|
6
|
+
import { prepareVaultHolder } from './vaultHolder.js';
|
|
7
|
+
|
|
8
|
+
const trace = makeTracer('VK', true);
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Wrap the VaultHolder duration object in a record suitable for the result of an invitation.
|
|
8
12
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {ERef<Marshaller>} marshaller
|
|
12
|
-
* @param {Subscriber<import('./vaultManager').AssetState>} assetSubscriber
|
|
13
|
+
* @param {import('@agoric/ertp').Baggage} baggage
|
|
14
|
+
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
|
|
13
15
|
*/
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
export const prepareVaultKit = (baggage, makeRecorderKit) => {
|
|
17
|
+
trace('prepareVaultKit', [...baggage.keys()]);
|
|
18
|
+
|
|
19
|
+
const makeVaultHolder = prepareVaultHolder(baggage, makeRecorderKit);
|
|
20
|
+
/**
|
|
21
|
+
* Create a kit of utilities for use of the vault.
|
|
22
|
+
*
|
|
23
|
+
* @param {Vault} vault
|
|
24
|
+
* @param {StorageNode} storageNode
|
|
25
|
+
*/
|
|
26
|
+
const makeVaultKit = (vault, storageNode) => {
|
|
27
|
+
trace('prepareVaultKit makeVaultKit');
|
|
28
|
+
const { holder, helper, invitationMakers } = makeVaultHolder(
|
|
29
|
+
vault,
|
|
30
|
+
storageNode,
|
|
31
|
+
);
|
|
32
|
+
const holderTopics = holder.getPublicTopics();
|
|
33
|
+
const vaultKit = harden({
|
|
34
|
+
publicSubscribers: {
|
|
35
|
+
vault: holderTopics.vault,
|
|
36
|
+
},
|
|
37
|
+
invitationMakers,
|
|
38
|
+
vault: holder,
|
|
39
|
+
vaultUpdater: helper.getUpdater(),
|
|
40
|
+
});
|
|
41
|
+
return vaultKit;
|
|
42
|
+
};
|
|
43
|
+
return makeVaultKit;
|
|
36
44
|
};
|
|
37
45
|
|
|
38
|
-
/** @typedef {(ReturnType<typeof
|
|
46
|
+
/** @typedef {(ReturnType<ReturnType<typeof prepareVaultKit>>)} VaultKit */
|