-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathvaultFactory.js
110 lines (99 loc) · 3.58 KB
/
vaultFactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
103
104
105
106
107
108
109
110
// @ts-check
import '@agoric/governance/src/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';
// The vaultFactory owns a number of VaultManagers and a mint for Minted.
//
// addVaultType is a closely held method that adds a brand new collateral type.
// It specifies the initial exchange rate for that type. It depends on a
// separately specified AMM to provide the ability to liquidate loans that are
// in arrears. We could check that the AMM has sufficient liquidity, but for the
// moment leave that to those participating in the governance process for adding
// new collateral type to ascertain.
// This contract wants to be managed by a contractGovernor, but it isn't
// compatible with contractGovernor, since it has a separate paramManager for
// each Vault. This requires it to manually replicate the API of contractHelper
// to satisfy contractGovernor. It needs to return a creatorFacet with
// { getParamMgrRetriever, getInvitation, getLimitedCreatorFacet }.
import { assertElectorateMatches } from '@agoric/governance';
import { makeStoredPublisherKit } from '@agoric/notifier';
import {
makeVaultDirectorParamManager,
LIQUIDATION_INSTALL_KEY,
LIQUIDATION_TERMS_KEY,
MIN_INITIAL_DEBT_KEY,
} from './params.js';
import { makeVaultDirector } from './vaultDirector.js';
import { assertKeysDefined } from '../contractSupport.js';
/**
* @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
* ammPublicFacet: AutoswapPublicFacet,
* liquidationInstall: Installation<import('./liquidateMinimum.js').start>,
* loanTimingParams: {ChargingPeriod: ParamValueTyped<'nat'>, RecordingPeriod: ParamValueTyped<'nat'>},
* minInitialDebt: Amount,
* priceAuthority: ERef<PriceAuthority>,
* reservePublicFacet: AssetReservePublicFacet,
* timerService: TimerService,
* shortfallInvitation: 'invitation',
* }>} VaultFactoryZCF
*/
/**
* @param {VaultFactoryZCF} zcf
* @param {{
* feeMintAccess: FeeMintAccess,
* initialPoserInvitation: Invitation,
* initialShortfallInvitation: Invitation,
* storageNode: ERef<StorageNode>,
* marshaller: ERef<Marshaller>,
* }} privateArgs
*/
export const start = async (zcf, privateArgs) => {
assertKeysDefined(privateArgs, [
'feeMintAccess',
'initialPoserInvitation',
'initialShortfallInvitation',
'storageNode',
'marshaller',
]);
const { feeMintAccess, initialPoserInvitation, initialShortfallInvitation } =
privateArgs;
const debtMint = await zcf.registerFeeMint('Minted', feeMintAccess);
zcf.setTestJig(() => ({
mintedIssuerRecord: debtMint.getIssuerRecord(),
}));
const {
[LIQUIDATION_INSTALL_KEY]: { value: liqInstall },
[LIQUIDATION_TERMS_KEY]: { value: liqTerms },
[MIN_INITIAL_DEBT_KEY]: { value: minInitialDebt },
} = zcf.getTerms().governedParams;
/** a powerful object; can modify the invitation */
const vaultDirectorParamManager = await makeVaultDirectorParamManager(
makeStoredPublisherKit(
privateArgs.storageNode,
privateArgs.marshaller,
'governance',
),
zcf.getZoeService(),
initialPoserInvitation,
liqInstall,
liqTerms,
minInitialDebt,
initialShortfallInvitation,
);
assertElectorateMatches(
vaultDirectorParamManager,
zcf.getTerms().governedParams,
);
const factory = makeVaultDirector(
zcf,
vaultDirectorParamManager,
debtMint,
privateArgs.storageNode,
privateArgs.marshaller,
);
return harden({
creatorFacet: factory.creator,
publicFacet: factory.public,
});
};
/** @typedef {ContractOf<typeof start>} VaultFactoryContract */