-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathparams.js
196 lines (183 loc) · 5.68 KB
/
params.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// @ts-check
import './types.js';
import {
CONTRACT_ELECTORATE,
makeParamManagerSync,
makeParamManager,
ParamTypes,
} from '@agoric/governance';
import { makeStoredPublisherKit } from '@agoric/notifier';
import { M } from '@agoric/store';
import { TimeMath } from '@agoric/swingset-vat/src/vats/timer/timeMath.js';
import { amountPattern, ratioPattern } from '../contractSupport.js';
export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
export const RECORDING_PERIOD_KEY = 'RecordingPeriod';
export const DEBT_LIMIT_KEY = 'DebtLimit';
export const LIQUIDATION_MARGIN_KEY = 'LiquidationMargin';
export const LIQUIDATION_PENALTY_KEY = 'LiquidationPenalty';
export const INTEREST_RATE_KEY = 'InterestRate';
export const LOAN_FEE_KEY = 'LoanFee';
export const LIQUIDATION_INSTALL_KEY = 'LiquidationInstall';
export const LIQUIDATION_TERMS_KEY = 'LiquidationTerms';
export const MIN_INITIAL_DEBT_KEY = 'MinInitialDebt';
export const SHORTFALL_INVITATION_KEY = 'ShortfallInvitation';
/**
* @param {Amount} electorateInvitationAmount
* @param {Installation} liquidationInstall
* @param {import('./liquidation.js').LiquidationTerms} liquidationTerms
* @param {Amount} minInitialDebt
* @param {Amount} shortfallInvitationAmount
*/
const makeVaultDirectorParams = (
electorateInvitationAmount,
liquidationInstall,
liquidationTerms,
minInitialDebt,
shortfallInvitationAmount,
) => {
return harden({
[CONTRACT_ELECTORATE]: {
type: ParamTypes.INVITATION,
value: electorateInvitationAmount,
},
[LIQUIDATION_INSTALL_KEY]: {
type: ParamTypes.INSTALLATION,
value: liquidationInstall,
},
[LIQUIDATION_TERMS_KEY]: {
type: ParamTypes.UNKNOWN,
value: liquidationTerms,
},
[MIN_INITIAL_DEBT_KEY]: {
type: ParamTypes.AMOUNT,
value: minInitialDebt,
},
[SHORTFALL_INVITATION_KEY]: {
type: ParamTypes.INVITATION,
value: shortfallInvitationAmount,
},
});
};
/** @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').ParamTypesMapFromRecord<ReturnType<typeof makeVaultDirectorParams>>} VaultDirectorParams */
/**
* @param {import('@agoric/notifier').StoredPublisherKit<GovernanceSubscriptionState>} publisherKit
* @param {VaultManagerParamValues} initial
*/
const makeVaultParamManager = (publisherKit, initial) =>
makeParamManagerSync(publisherKit, {
[DEBT_LIMIT_KEY]: [ParamTypes.AMOUNT, initial.debtLimit],
[LIQUIDATION_MARGIN_KEY]: [ParamTypes.RATIO, initial.liquidationMargin],
[LIQUIDATION_PENALTY_KEY]: [ParamTypes.RATIO, initial.liquidationPenalty],
[INTEREST_RATE_KEY]: [ParamTypes.RATIO, initial.interestRate],
[LOAN_FEE_KEY]: [ParamTypes.RATIO, initial.loanFee],
});
/** @typedef {ReturnType<typeof makeVaultParamManager>} VaultParamManager */
export const vaultParamPattern = M.split(
{
liquidationMargin: ratioPattern,
liquidationPenalty: ratioPattern,
interestRate: ratioPattern,
loanFee: ratioPattern,
debtLimit: amountPattern,
},
M.any(),
);
/**
* @param {import('@agoric/notifier').StoredPublisherKit<GovernanceSubscriptionState>} publisherKit
* @param {ERef<ZoeService>} zoe
* @param {Invitation} electorateInvitation
* @param {Installation} liquidationInstall
* @param {object} liquidationTerms
* @param {Amount} minInitialDebt
* @param {Invitation} shortfallInvitation
*/
const makeVaultDirectorParamManager = async (
publisherKit,
zoe,
electorateInvitation,
liquidationInstall,
liquidationTerms,
minInitialDebt,
shortfallInvitation,
) => {
return makeParamManager(
publisherKit,
{
[CONTRACT_ELECTORATE]: [ParamTypes.INVITATION, electorateInvitation],
[LIQUIDATION_INSTALL_KEY]: [ParamTypes.INSTALLATION, liquidationInstall],
[LIQUIDATION_TERMS_KEY]: [ParamTypes.UNKNOWN, liquidationTerms],
[MIN_INITIAL_DEBT_KEY]: [ParamTypes.AMOUNT, minInitialDebt],
[SHORTFALL_INVITATION_KEY]: [ParamTypes.INVITATION, shortfallInvitation],
},
zoe,
);
};
/**
* @param {{storageNode: ERef<StorageNode>, marshaller: ERef<Marshaller>}} caps
* @param {{
* electorateInvitationAmount: Amount,
* minInitialDebt: Amount,
* bootstrapPaymentValue: bigint,
* priceAuthority: ERef<PriceAuthority>,
* timer: ERef<TimerService>,
* reservePublicFacet: AssetReservePublicFacet,
* liquidationInstall: Installation,
* loanTiming: LoanTiming,
* liquidationTerms: import('./liquidation.js').LiquidationTerms,
* ammPublicFacet: XYKAMMPublicFacet,
* shortfallInvitationAmount: Amount,
* }} opts
*/
const makeGovernedTerms = (
{ storageNode, marshaller },
{
ammPublicFacet,
bootstrapPaymentValue,
electorateInvitationAmount,
liquidationInstall,
liquidationTerms,
loanTiming,
minInitialDebt,
priceAuthority,
reservePublicFacet,
timer,
shortfallInvitationAmount,
},
) => {
const loanTimingParams = makeParamManagerSync(
makeStoredPublisherKit(storageNode, marshaller, 'timingParams'),
{
[CHARGING_PERIOD_KEY]: [
'nat',
TimeMath.relValue(loanTiming.chargingPeriod),
],
[RECORDING_PERIOD_KEY]: [
'nat',
TimeMath.relValue(loanTiming.recordingPeriod),
],
},
).getParams();
return harden({
ammPublicFacet,
priceAuthority,
loanTimingParams,
reservePublicFacet,
timerService: timer,
governedParams: makeVaultDirectorParams(
electorateInvitationAmount,
liquidationInstall,
liquidationTerms,
minInitialDebt,
shortfallInvitationAmount,
),
bootstrapPaymentValue,
});
};
harden(makeVaultParamManager);
harden(makeVaultDirectorParamManager);
harden(makeGovernedTerms);
export {
makeVaultDirectorParamManager,
makeVaultParamManager,
makeGovernedTerms,
};