@agoric/inter-protocol 0.13.2-dev-eb9fb38.0 → 0.13.2-dev-a9d6a3b.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 +0 -2
- package/bundles/bundle-auctioneer-js-meta.json +147 -147
- package/bundles/bundle-econCommitteeCharter-js-meta.json +71 -71
- package/bundles/bundle-feeDistributor-js-meta.json +57 -57
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +110 -110
- package/bundles/bundle-psm-js-meta.json +108 -108
- package/bundles/bundle-reserve-js-meta.json +107 -107
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +77 -77
- package/bundles/bundle-vaultFactory-js-meta.json +131 -131
- package/bundles/bundle-vaultFactory.js +1 -1
- package/exported.js +0 -1
- package/package.json +17 -17
- package/scripts/deploy-contracts.js +0 -1
- package/scripts/init-core.js +0 -8
- package/src/proposals/core-proposal.js +0 -42
- package/src/proposals/econ-behaviors.js +3 -198
- package/src/vaultFactory/types.js +1 -0
- package/bundles/bundle-stakeFactory-js-meta.json +0 -690
- package/bundles/bundle-stakeFactory.js +0 -1
- package/src/my-lien.js +0 -84
- package/src/stakeFactory/README.md +0 -62
- package/src/stakeFactory/attestation.js +0 -271
- package/src/stakeFactory/attestationTool.js +0 -67
- package/src/stakeFactory/constants.js +0 -18
- package/src/stakeFactory/params.js +0 -30
- package/src/stakeFactory/stakeFactory.js +0 -225
- package/src/stakeFactory/stakeFactoryKit.js +0 -465
- package/src/stakeFactory/stakeFactoryManager.js +0 -300
- package/src/stakeFactory/types.js +0 -45
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
|
-
import { AmountMath } from '@agoric/ertp';
|
|
4
|
-
import { makePublishKit, observeNotifier } from '@agoric/notifier';
|
|
5
|
-
import { mustMatch, getCopyBagEntries, M } from '@agoric/store';
|
|
6
|
-
import { defineKindMulti } from '@agoric/vat-data';
|
|
7
|
-
import { floorMultiplyBy } from '@agoric/zoe/src/contractSupport/index.js';
|
|
8
|
-
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
|
|
9
|
-
import { E } from '@endo/far';
|
|
10
|
-
import { makeTracer } from '@agoric/internal';
|
|
11
|
-
import { checkDebtLimit } from '../contractSupport.js';
|
|
12
|
-
import { chargeInterest } from '../interest.js';
|
|
13
|
-
import { ManagerKW as KW } from './constants.js';
|
|
14
|
-
|
|
15
|
-
const { details: X } = assert;
|
|
16
|
-
|
|
17
|
-
const trace = makeTracer('RSM', false);
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {import('@agoric/time/src/types').Timestamp} Timestamp
|
|
20
|
-
* @typedef {import('@agoric/time/src/types').RelativeTime} RelativeTime
|
|
21
|
-
* @typedef {import('@agoric/time/src/types').TimerService} TimerService
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {{
|
|
26
|
-
* getDebtLimit: () => Amount<'nat'>,
|
|
27
|
-
* getInterestRate: () => Ratio,
|
|
28
|
-
* getMintingRatio: () => Ratio,
|
|
29
|
-
* getMintFee: () => Ratio,
|
|
30
|
-
* }} ParamManager
|
|
31
|
-
* @typedef {{
|
|
32
|
-
* compoundedInterest: Ratio,
|
|
33
|
-
* latestInterestUpdate: Timestamp,
|
|
34
|
-
* totalDebt: Amount<'nat'>,
|
|
35
|
-
* }} AssetState
|
|
36
|
-
* @typedef {Readonly<{
|
|
37
|
-
* assetPublisher: Publisher<AssetState>,
|
|
38
|
-
* assetSubscriber: Subscriber<AssetState>,
|
|
39
|
-
* brands: { debt: Brand<'nat'>, Attestation: Brand<'copyBag'>, Stake: Brand<'nat'> },
|
|
40
|
-
* mintPowers: { burnDebt: BurnDebt, getGovernedParams: () => ParamManager, mintAndTransfer: MintAndTransfer },
|
|
41
|
-
* chargingPeriod: RelativeTime,
|
|
42
|
-
* debtMint: ZCFMint<'nat'>,
|
|
43
|
-
* poolIncrementSeat: ZCFSeat,
|
|
44
|
-
* recordingPeriod: RelativeTime,
|
|
45
|
-
* startTimeStamp: Timestamp,
|
|
46
|
-
* timerService: ERef<TimerService>,
|
|
47
|
-
* zcf: ZCF,
|
|
48
|
-
* }>} ImmutableState
|
|
49
|
-
* @typedef {AssetState & {
|
|
50
|
-
* }} MutableState
|
|
51
|
-
* @typedef {ImmutableState & MutableState} State
|
|
52
|
-
* @typedef {Readonly<{
|
|
53
|
-
* state: State,
|
|
54
|
-
* facets: import('@agoric/vat-data/src/types').KindFacets<typeof behavior>,
|
|
55
|
-
* }>} MethodContext
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {ZCF} zcf
|
|
60
|
-
* @param {ZCFMint<'nat'>} debtMint
|
|
61
|
-
* @param {{ debt: Brand<'nat'>, Attestation: Brand<'copyBag'>, Stake: Brand<'nat'> }} brands
|
|
62
|
-
* @param {{ burnDebt: BurnDebt, getGovernedParams: () => ParamManager, mintAndTransfer: MintAndTransfer }} mintPowers
|
|
63
|
-
* @param {object} timing
|
|
64
|
-
* @param {ERef<TimerService>} timing.timerService
|
|
65
|
-
* @param {RelativeTime} timing.chargingPeriod
|
|
66
|
-
* @param {RelativeTime} timing.recordingPeriod
|
|
67
|
-
* @param {Timestamp} timing.startTimeStamp
|
|
68
|
-
*
|
|
69
|
-
* @returns {State}
|
|
70
|
-
*/
|
|
71
|
-
const initState = (
|
|
72
|
-
zcf,
|
|
73
|
-
debtMint,
|
|
74
|
-
brands,
|
|
75
|
-
mintPowers,
|
|
76
|
-
{ chargingPeriod, recordingPeriod, startTimeStamp, timerService },
|
|
77
|
-
) => {
|
|
78
|
-
const totalDebt = AmountMath.makeEmpty(brands.debt, 'nat');
|
|
79
|
-
const compoundedInterest = makeRatio(100n, brands.debt); // starts at 1.0, no interest
|
|
80
|
-
const latestInterestUpdate = startTimeStamp;
|
|
81
|
-
|
|
82
|
-
const { publisher: assetPublisher, subscriber: assetSubscriber } =
|
|
83
|
-
makePublishKit();
|
|
84
|
-
assetPublisher.publish(
|
|
85
|
-
harden({
|
|
86
|
-
compoundedInterest,
|
|
87
|
-
interestRate: mintPowers.getGovernedParams().getInterestRate(),
|
|
88
|
-
latestInterestUpdate,
|
|
89
|
-
totalDebt,
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const { zcfSeat: poolIncrementSeat } = zcf.makeEmptySeatKit();
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
assetSubscriber,
|
|
97
|
-
assetPublisher,
|
|
98
|
-
brands,
|
|
99
|
-
chargingPeriod,
|
|
100
|
-
compoundedInterest,
|
|
101
|
-
debtMint,
|
|
102
|
-
latestInterestUpdate,
|
|
103
|
-
mintPowers,
|
|
104
|
-
poolIncrementSeat,
|
|
105
|
-
recordingPeriod,
|
|
106
|
-
startTimeStamp,
|
|
107
|
-
timerService,
|
|
108
|
-
totalDebt,
|
|
109
|
-
zcf,
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param {MethodContext} context
|
|
115
|
-
*/
|
|
116
|
-
const finish = ({ state, facets }) => {
|
|
117
|
-
const { recordingPeriod, timerService, zcf } = state;
|
|
118
|
-
const { helper } = facets;
|
|
119
|
-
|
|
120
|
-
const periodNotifier = E(timerService).makeNotifier(0n, recordingPeriod);
|
|
121
|
-
|
|
122
|
-
void observeNotifier(periodNotifier, {
|
|
123
|
-
updateState: updateTime =>
|
|
124
|
-
helper
|
|
125
|
-
.chargeAllVaults(updateTime)
|
|
126
|
-
.catch(e =>
|
|
127
|
-
console.error('🚨 stakeFactoryManager failed to charge interest', e),
|
|
128
|
-
),
|
|
129
|
-
fail: reason => {
|
|
130
|
-
zcf.shutdownWithFailure(
|
|
131
|
-
assert.error(X`Unable to continue without a timer: ${reason}`),
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
finish: done => {
|
|
135
|
-
zcf.shutdownWithFailure(
|
|
136
|
-
assert.error(X`Unable to continue without a timer: ${done}`),
|
|
137
|
-
);
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const helper = {
|
|
143
|
-
/**
|
|
144
|
-
* @param {MethodContext} context
|
|
145
|
-
* @param {Timestamp} updateTime
|
|
146
|
-
*/
|
|
147
|
-
chargeAllVaults: async ({ state }, updateTime) => {
|
|
148
|
-
const { debtMint, mintPowers, poolIncrementSeat } = state;
|
|
149
|
-
trace('chargeAllVaults', { updateTime });
|
|
150
|
-
const interestRate = mintPowers.getGovernedParams().getInterestRate();
|
|
151
|
-
|
|
152
|
-
const changes = chargeInterest(
|
|
153
|
-
{
|
|
154
|
-
mint: debtMint,
|
|
155
|
-
mintAndTransferWithFee: mintPowers.mintAndTransfer,
|
|
156
|
-
poolIncrementSeat,
|
|
157
|
-
seatAllocationKeyword: KW.Debt,
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
interestRate,
|
|
161
|
-
chargingPeriod: state.chargingPeriod,
|
|
162
|
-
recordingPeriod: state.recordingPeriod,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
latestInterestUpdate: state.latestInterestUpdate,
|
|
166
|
-
compoundedInterest: state.compoundedInterest,
|
|
167
|
-
totalDebt: state.totalDebt,
|
|
168
|
-
},
|
|
169
|
-
updateTime,
|
|
170
|
-
);
|
|
171
|
-
state.compoundedInterest = changes.compoundedInterest;
|
|
172
|
-
state.latestInterestUpdate = changes.latestInterestUpdate;
|
|
173
|
-
state.totalDebt = changes.totalDebt;
|
|
174
|
-
|
|
175
|
-
const payload = harden({
|
|
176
|
-
compoundedInterest: state.compoundedInterest,
|
|
177
|
-
interestRate,
|
|
178
|
-
latestInterestUpdate: state.latestInterestUpdate,
|
|
179
|
-
totalDebt: state.totalDebt,
|
|
180
|
-
});
|
|
181
|
-
const { assetPublisher: assetUpdater } = state;
|
|
182
|
-
assetUpdater.publish(payload);
|
|
183
|
-
|
|
184
|
-
trace('chargeAllVaults complete', payload);
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const manager = {
|
|
189
|
-
/**
|
|
190
|
-
* @param {MethodContext} context
|
|
191
|
-
* @param { Amount<'copyBag'>} attestationGiven
|
|
192
|
-
*/
|
|
193
|
-
maxDebtForLien: ({ state }, attestationGiven) => {
|
|
194
|
-
const { brands, mintPowers } = state;
|
|
195
|
-
const mintingRatio = mintPowers.getGovernedParams().getMintingRatio();
|
|
196
|
-
assert.equal(
|
|
197
|
-
mintingRatio.numerator.brand,
|
|
198
|
-
brands.debt,
|
|
199
|
-
X`${mintingRatio} not in Debt / Stake`,
|
|
200
|
-
);
|
|
201
|
-
assert.equal(
|
|
202
|
-
mintingRatio.denominator.brand,
|
|
203
|
-
brands.Stake,
|
|
204
|
-
X`${mintingRatio} not in Debt / Stake`,
|
|
205
|
-
);
|
|
206
|
-
assert.equal(
|
|
207
|
-
attestationGiven.brand,
|
|
208
|
-
brands.Attestation,
|
|
209
|
-
X`Invalid Attestation ${attestationGiven}. Expected brand ${brands.Attestation}`,
|
|
210
|
-
);
|
|
211
|
-
mustMatch(attestationGiven.value, M.bagOf(M.string()), 'attestationGiven');
|
|
212
|
-
const [[_addr, valueLiened]] = getCopyBagEntries(attestationGiven.value);
|
|
213
|
-
const amountLiened = AmountMath.make(brands.Stake, valueLiened);
|
|
214
|
-
const maxDebt = floorMultiplyBy(amountLiened, mintingRatio);
|
|
215
|
-
return { maxDebt, amountLiened };
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Update total debt of this manager given the change in debt on a vault
|
|
220
|
-
*
|
|
221
|
-
* @param {MethodContext} context
|
|
222
|
-
* @param {Amount<'nat'>} oldDebtOnVault
|
|
223
|
-
* @param {Amount<'nat'>} newDebtOnVault
|
|
224
|
-
*/
|
|
225
|
-
// TODO: Add limits for amounts between vault and vault manager
|
|
226
|
-
// https://github.com/Agoric/agoric-sdk/issues/4599
|
|
227
|
-
applyDebtDelta: ({ state }, oldDebtOnVault, newDebtOnVault) => {
|
|
228
|
-
// This does not use AmountMath because it could be validly negative
|
|
229
|
-
const delta = newDebtOnVault.value - oldDebtOnVault.value;
|
|
230
|
-
trace(`updating total debt ${state.totalDebt} by ${delta}`);
|
|
231
|
-
if (delta === 0n) {
|
|
232
|
-
// nothing to do
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const { brands } = state;
|
|
237
|
-
// totalDebt += delta (Amount type ensures natural value)
|
|
238
|
-
state.totalDebt = AmountMath.make(
|
|
239
|
-
brands.debt,
|
|
240
|
-
state.totalDebt.value + delta,
|
|
241
|
-
);
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @param {MethodContext} context
|
|
246
|
-
* @param {ZCFSeat} seat
|
|
247
|
-
* @param {Amount<'nat'>} toMint
|
|
248
|
-
* @param {Amount<'nat'>} fee
|
|
249
|
-
* @param {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} transfers
|
|
250
|
-
* @returns {void}
|
|
251
|
-
*/
|
|
252
|
-
mintAndReallocate: ({ state }, seat, toMint, fee, transfers) => {
|
|
253
|
-
const { mintPowers } = state;
|
|
254
|
-
checkDebtLimit(
|
|
255
|
-
mintPowers.getGovernedParams().getDebtLimit(),
|
|
256
|
-
state.totalDebt,
|
|
257
|
-
toMint,
|
|
258
|
-
);
|
|
259
|
-
mintPowers.mintAndTransfer(seat, toMint, fee, transfers);
|
|
260
|
-
state.totalDebt = AmountMath.add(state.totalDebt, toMint);
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
/** @param {MethodContext} context */
|
|
264
|
-
getMintingRatio: ({ state }) =>
|
|
265
|
-
state.mintPowers.getGovernedParams().getMintingRatio(),
|
|
266
|
-
/** @param {MethodContext} context */
|
|
267
|
-
getInterestRate: ({ state }) =>
|
|
268
|
-
state.mintPowers.getGovernedParams().getInterestRate(),
|
|
269
|
-
/** @param {MethodContext} context */
|
|
270
|
-
getMintFee: ({ state }) => state.mintPowers.getGovernedParams().getMintFee(),
|
|
271
|
-
/**
|
|
272
|
-
* @param {MethodContext} context
|
|
273
|
-
* @param {Amount} toBurn
|
|
274
|
-
* @param {ZCFSeat} seat
|
|
275
|
-
*/
|
|
276
|
-
burnDebt: ({ state }, toBurn, seat) =>
|
|
277
|
-
state.mintPowers.burnDebt(toBurn, seat),
|
|
278
|
-
|
|
279
|
-
/** @param {MethodContext} context */
|
|
280
|
-
getDebtBrand: ({ state }) => state.brands.debt,
|
|
281
|
-
/** @param {MethodContext} context */
|
|
282
|
-
getCollateralBrand: ({ state }) => state.brands.Attestation,
|
|
283
|
-
|
|
284
|
-
/** @param {MethodContext} context */
|
|
285
|
-
getCompoundedInterest: ({ state }) => state.compoundedInterest,
|
|
286
|
-
/** @param {MethodContext} context */
|
|
287
|
-
getAssetSubscriber: ({ state }) => state.assetSubscriber,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
const behavior = { helper, manager };
|
|
291
|
-
|
|
292
|
-
export const makeStakeFactoryManager = defineKindMulti(
|
|
293
|
-
'StakeFactoryManager',
|
|
294
|
-
initState,
|
|
295
|
-
behavior,
|
|
296
|
-
{ finish },
|
|
297
|
-
);
|
|
298
|
-
/**
|
|
299
|
-
* @typedef {ReturnType<typeof makeStakeFactoryManager>['manager']} StakeFactoryManager
|
|
300
|
-
*/
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* For example, an agoric1... Cosmos address
|
|
5
|
-
*
|
|
6
|
-
* @typedef {string} Address
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef AttestationTool
|
|
11
|
-
* @property {(amountToLien: Amount<'nat'>) => Promise<Payment>} makeAttestation
|
|
12
|
-
* @property {() => Promise<AccountState>} getAccountState
|
|
13
|
-
* @property {() => Promise<Invitation>} makeReturnAttInvitation Make an invitation for returning an attestation.
|
|
14
|
-
* @property {(lienedAmount: Amount<'nat'>) => Amount<'copyBag'>} wrapLienedAmount
|
|
15
|
-
* @property {(attAmount: Amount<'copyBag'>) => Amount<'nat'>} unwrapLienedAmount
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {CopyBag<Address>} ReturnableAttValue
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @typedef {import('@agoric/time/src/types').Timestamp} Timestamp
|
|
24
|
-
* @typedef {{getTime: () => Timestamp, updateTime: (currentTime:
|
|
25
|
-
* Timestamp) => void}} StoredTime
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @typedef {object} StakingAuthority
|
|
30
|
-
* @property {(address: Address, increase: Amount<'nat'>) => Promise<Amount<'nat'>>} increaseLiened
|
|
31
|
-
* @property {(address: Address, decrease: Amount<'nat'>) => Promise<Amount<'nat'>>} decreaseLiened
|
|
32
|
-
* @property {(address: Address, brand: Brand<'nat'>) => ERef<AccountState> } getAccountState
|
|
33
|
-
* @typedef {object} AccountState
|
|
34
|
-
* @property {Amount<'nat'>} bonded
|
|
35
|
-
* @property {Amount<'nat'>} liened
|
|
36
|
-
* @property {Amount<'nat'>} locked
|
|
37
|
-
* @property {Amount<'nat'>} total
|
|
38
|
-
* @property {Amount<'nat'>} unbonding
|
|
39
|
-
* @property {bigint} currentTime
|
|
40
|
-
*
|
|
41
|
-
* Performance note: getAccountState is expensive, as it has to iterate over all
|
|
42
|
-
* delegations.
|
|
43
|
-
*
|
|
44
|
-
* @typedef {(address: Address, brand: Brand<'nat'>) => Amount} GetLiened
|
|
45
|
-
*/
|