@agoric/inter-protocol 0.13.2-dev-65d3f14.0 → 0.13.2-pismo-dev-12e97f1.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/bundles/bundle-amm-meta.js +168 -188
- package/bundles/bundle-amm.js +1 -1
- package/bundles/bundle-feeDistributor-meta.js +92 -92
- package/bundles/bundle-feeDistributor.js +1 -1
- package/bundles/bundle-interchainPool-meta.js +174 -190
- package/bundles/bundle-interchainPool.js +1 -1
- package/bundles/bundle-liquidateIncrementally-meta.js +149 -109
- package/bundles/bundle-liquidateIncrementally.js +1 -1
- package/bundles/bundle-liquidateMinimum-meta.js +149 -109
- package/bundles/bundle-liquidateMinimum.js +1 -1
- package/bundles/bundle-psm-meta.js +148 -168
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-psmCharter-meta.js +418 -0
- package/bundles/bundle-psmCharter.js +1 -0
- package/bundles/bundle-reserve-meta.js +176 -192
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-meta.js +173 -133
- package/bundles/bundle-scaledPriceAuthority.js +1 -1
- package/bundles/bundle-stakeFactory-meta.js +186 -206
- package/bundles/bundle-stakeFactory.js +1 -1
- package/bundles/bundle-vaultFactory-meta.js +197 -217
- package/bundles/bundle-vaultFactory.js +1 -1
- package/package.json +23 -25
- package/scripts/add-collateral-core.js +3 -52
- package/scripts/add-initial-liquidity.js +1 -0
- package/scripts/build-bundles.js +1 -4
- package/scripts/deploy-contracts.js +1 -0
- package/scripts/init-core.js +9 -11
- package/scripts/invite-committee-core.js +1 -0
- package/scripts/manual-price-feed.js +1 -1
- package/scripts/price-feed-core.js +2 -2
- package/src/collect.js +2 -0
- package/src/collectFees.js +4 -3
- package/src/contractSupport.js +27 -13
- package/src/econCommitteeCharter.js +80 -110
- package/src/feeDistributor.js +8 -6
- package/src/interchainPool.js +8 -7
- package/src/interest-math.js +2 -0
- package/src/interest.js +10 -6
- package/src/makeTracer.js +0 -5
- package/src/my-lien.js +7 -3
- package/src/proposals/addAssetToVault.js +5 -3
- package/src/proposals/committee-proposal.js +42 -112
- package/src/proposals/core-proposal.js +30 -17
- package/src/proposals/demoIssuers.js +16 -17
- package/src/proposals/econ-behaviors.js +115 -156
- package/src/proposals/price-feed-proposal.js +6 -118
- package/src/proposals/sim-behaviors.js +1 -0
- package/src/proposals/startEconCommittee.js +2 -1
- package/src/proposals/startPSM.js +117 -77
- package/src/proposals/utils.js +12 -23
- package/src/psm/psm.js +55 -37
- package/src/psm/psmCharter.js +139 -0
- package/src/reserve/assetReserve.js +35 -28
- package/src/reserve/params.js +2 -0
- package/src/stakeFactory/attestation.js +9 -4
- package/src/stakeFactory/attestationTool.js +1 -0
- package/src/stakeFactory/params.js +1 -0
- package/src/stakeFactory/stakeFactory.js +1 -1
- package/src/stakeFactory/stakeFactoryKit.js +20 -13
- package/src/stakeFactory/stakeFactoryManager.js +3 -2
- package/src/vaultFactory/burn.js +1 -0
- package/src/vaultFactory/liquidateIncrementally.js +8 -5
- package/src/vaultFactory/liquidateMinimum.js +6 -2
- package/src/vaultFactory/liquidation.js +2 -2
- package/src/vaultFactory/orderedVaultStore.js +1 -0
- package/src/vaultFactory/params.js +12 -7
- package/src/vaultFactory/prioritizedVaults.js +1 -0
- package/src/vaultFactory/storeUtils.js +1 -0
- package/src/vaultFactory/types.js +2 -0
- package/src/vaultFactory/vault.js +40 -26
- package/src/vaultFactory/vaultDirector.js +18 -15
- package/src/vaultFactory/vaultFactory.js +20 -19
- package/src/vaultFactory/vaultHolder.js +3 -4
- package/src/vaultFactory/vaultKit.js +1 -0
- package/src/vaultFactory/vaultManager.js +10 -7
- package/src/vpool-xyk-amm/addLiquidity.js +4 -3
- package/src/vpool-xyk-amm/addPool.js +20 -23
- package/src/vpool-xyk-amm/constantProduct/calcFees.js +12 -6
- package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +2 -0
- package/src/vpool-xyk-amm/constantProduct/core.js +24 -16
- package/src/vpool-xyk-amm/constantProduct/defaults.js +2 -0
- package/src/vpool-xyk-amm/constantProduct/getXY.js +6 -2
- package/src/vpool-xyk-amm/constantProduct/internal-types.js +14 -12
- package/src/vpool-xyk-amm/constantProduct/invariants.js +8 -4
- package/src/vpool-xyk-amm/constantProduct/swap.js +19 -17
- package/src/vpool-xyk-amm/constantProduct/types.js +2 -0
- package/src/vpool-xyk-amm/doublePool.js +14 -20
- package/src/vpool-xyk-amm/estimate.js +2 -0
- package/src/vpool-xyk-amm/multipoolMarketMaker.js +5 -3
- package/src/vpool-xyk-amm/params.js +2 -0
- package/src/vpool-xyk-amm/pool.js +14 -16
- package/src/vpool-xyk-amm/priceAuthority.js +3 -1
- package/src/vpool-xyk-amm/removeLiquidity.js +2 -0
- package/src/vpool-xyk-amm/singlePool.js +14 -29
- package/src/vpool-xyk-amm/swap.js +1 -0
- package/src/vpool-xyk-amm/types.js +12 -10
- package/bundles/bundle-econCommitteeCharter-meta.js +0 -418
- package/bundles/bundle-econCommitteeCharter.js +0 -1
- package/scripts/start-local-chain-boot.js +0 -96
- package/scripts/start-local-chain-config.json +0 -83
- package/scripts/start-local-chain.sh +0 -69
- package/src/psm/README.md +0 -71
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import '@agoric/zoe/exported.js';
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -5,7 +6,6 @@ import {
|
|
|
5
6
|
makeRatioFromAmounts,
|
|
6
7
|
ceilMultiplyBy,
|
|
7
8
|
floorMultiplyBy,
|
|
8
|
-
atomicTransfer,
|
|
9
9
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
10
10
|
import { AmountMath } from '@agoric/ertp';
|
|
11
11
|
import {
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
stageDelta,
|
|
24
24
|
} from '../contractSupport.js';
|
|
25
25
|
|
|
26
|
-
const { quote: q
|
|
26
|
+
const { details: X, quote: q } = assert;
|
|
27
27
|
|
|
28
28
|
const trace = makeTracer('IV', false);
|
|
29
29
|
|
|
@@ -198,10 +198,12 @@ const checkRestart = (newCollateralPre, maxDebtPre, newCollateral, newDebt) => {
|
|
|
198
198
|
);
|
|
199
199
|
// `floorMultiply` because the debt ceiling should be tight
|
|
200
200
|
const maxDebtAfter = floorMultiplyBy(newCollateral, debtPerCollateral);
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
assert(
|
|
202
|
+
AmountMath.isGTE(maxDebtAfter, newDebt),
|
|
203
|
+
X`The requested debt ${q(
|
|
203
204
|
newDebt,
|
|
204
|
-
)} is more than the collateralization ratio allows: ${q(maxDebtAfter)}
|
|
205
|
+
)} is more than the collateralization ratio allows: ${q(maxDebtAfter)}`,
|
|
206
|
+
);
|
|
205
207
|
// The `collateralAfter` can still cover the `newDebt`, so don't restart.
|
|
206
208
|
return false;
|
|
207
209
|
}
|
|
@@ -229,7 +231,9 @@ const helperBehavior = {
|
|
|
229
231
|
const { phase } = state;
|
|
230
232
|
const validNewPhases = validTransitions[phase];
|
|
231
233
|
validNewPhases.includes(newPhase) ||
|
|
232
|
-
|
|
234
|
+
assert.fail(
|
|
235
|
+
X`Vault cannot transition from ${q(phase)} to ${q(newPhase)}`,
|
|
236
|
+
);
|
|
233
237
|
state.phase = newPhase;
|
|
234
238
|
},
|
|
235
239
|
|
|
@@ -242,7 +246,9 @@ const helperBehavior = {
|
|
|
242
246
|
const { phase } = state;
|
|
243
247
|
phase === Phase.ACTIVE ||
|
|
244
248
|
phase === Phase.LIQUIDATED ||
|
|
245
|
-
|
|
249
|
+
assert.fail(
|
|
250
|
+
X`to be closed a vault must be active or liquidated, not ${phase}`,
|
|
251
|
+
);
|
|
246
252
|
},
|
|
247
253
|
// #endregion
|
|
248
254
|
|
|
@@ -251,7 +257,7 @@ const helperBehavior = {
|
|
|
251
257
|
* but not for interest accrual.
|
|
252
258
|
*
|
|
253
259
|
* @param {MethodContext} context
|
|
254
|
-
* @param {Amount
|
|
260
|
+
* @param {Amount} newDebt - principal and all accrued interest
|
|
255
261
|
*/
|
|
256
262
|
updateDebtSnapshot: ({ state }, newDebt) => {
|
|
257
263
|
// update local state
|
|
@@ -299,7 +305,7 @@ const helperBehavior = {
|
|
|
299
305
|
assertVaultHoldsNoMinted: ({ state, facets }) => {
|
|
300
306
|
const { vaultSeat } = state;
|
|
301
307
|
AmountMath.isEmpty(facets.helper.getMintedAllocated(vaultSeat)) ||
|
|
302
|
-
|
|
308
|
+
assert.fail(X`Vault should be empty of Minted`);
|
|
303
309
|
},
|
|
304
310
|
|
|
305
311
|
/**
|
|
@@ -314,10 +320,12 @@ const helperBehavior = {
|
|
|
314
320
|
proposedRunDebt,
|
|
315
321
|
) => {
|
|
316
322
|
const maxRun = await state.manager.maxDebtFor(collateralAmount);
|
|
317
|
-
|
|
318
|
-
|
|
323
|
+
assert(
|
|
324
|
+
AmountMath.isGTE(maxRun, proposedRunDebt, facets.helper.debtBrand()),
|
|
325
|
+
X`Requested ${q(proposedRunDebt)} exceeds max ${q(maxRun)} for ${q(
|
|
319
326
|
collateralAmount,
|
|
320
|
-
)} collateral
|
|
327
|
+
)} collateral`,
|
|
328
|
+
);
|
|
321
329
|
},
|
|
322
330
|
|
|
323
331
|
/**
|
|
@@ -396,18 +404,20 @@ const helperBehavior = {
|
|
|
396
404
|
// you must pay off the entire remainder but if you offer too much, we won't
|
|
397
405
|
// take more than you owe
|
|
398
406
|
AmountMath.isGTE(given, debt) ||
|
|
399
|
-
|
|
407
|
+
assert.fail(
|
|
408
|
+
X`Offer ${given} is not sufficient to pay off debt ${debt}`,
|
|
409
|
+
);
|
|
400
410
|
|
|
401
411
|
// Return any overpayment
|
|
402
|
-
|
|
403
|
-
|
|
412
|
+
seat.incrementBy(vaultSeat.decrementBy(vaultSeat.getCurrentAllocation()));
|
|
413
|
+
zcf.reallocate(seat, vaultSeat);
|
|
404
414
|
state.manager.burnAndRecord(debt, seat);
|
|
405
415
|
} else if (phase === Phase.LIQUIDATED) {
|
|
406
416
|
// Simply reallocate vault assets to the offer seat.
|
|
407
417
|
// Don't take anything from the offer, even if vault is underwater.
|
|
408
418
|
// TODO verify that returning Minted here doesn't mess up debt limits
|
|
409
|
-
|
|
410
|
-
|
|
419
|
+
seat.incrementBy(vaultSeat.decrementBy(vaultSeat.getCurrentAllocation()));
|
|
420
|
+
zcf.reallocate(seat, vaultSeat);
|
|
411
421
|
} else {
|
|
412
422
|
throw new Error('only active and liquidated vaults can be closed');
|
|
413
423
|
}
|
|
@@ -439,9 +449,9 @@ const helperBehavior = {
|
|
|
439
449
|
* so the simple math works.
|
|
440
450
|
*
|
|
441
451
|
* @param {MethodContext} context
|
|
442
|
-
* @param {Amount
|
|
443
|
-
* @param {Amount
|
|
444
|
-
* @param {Amount
|
|
452
|
+
* @param {Amount} currentDebt
|
|
453
|
+
* @param {Amount} giveAmount
|
|
454
|
+
* @param {Amount} wantAmount
|
|
445
455
|
*/
|
|
446
456
|
loanFee: ({ state }, currentDebt, giveAmount, wantAmount) => {
|
|
447
457
|
const fee = ceilMultiplyBy(
|
|
@@ -482,7 +492,7 @@ const helperBehavior = {
|
|
|
482
492
|
// max debt supported by current Collateral as modified by proposal
|
|
483
493
|
const maxDebtPre = await state.manager.maxDebtFor(newCollateralPre);
|
|
484
494
|
updaterPre === ephemera.outerUpdater ||
|
|
485
|
-
|
|
495
|
+
assert.fail(X`Transfer during vault adjustment`);
|
|
486
496
|
helper.assertActive();
|
|
487
497
|
|
|
488
498
|
// After the `await`, we retrieve the vault's allocations again,
|
|
@@ -589,9 +599,11 @@ const selfBehavior = {
|
|
|
589
599
|
|
|
590
600
|
const normalizedDebtPre = self.getNormalizedDebt();
|
|
591
601
|
const actualDebtPre = self.getCurrentDebt();
|
|
592
|
-
(
|
|
593
|
-
AmountMath.isEmpty(
|
|
594
|
-
|
|
602
|
+
assert(
|
|
603
|
+
AmountMath.isEmpty(normalizedDebtPre) &&
|
|
604
|
+
AmountMath.isEmpty(actualDebtPre),
|
|
605
|
+
X`vault must be empty initially`,
|
|
606
|
+
);
|
|
595
607
|
|
|
596
608
|
const collateralPre = self.getCollateralAmount();
|
|
597
609
|
trace('initVaultKit start: collateral', state.idInManager, {
|
|
@@ -612,8 +624,10 @@ const selfBehavior = {
|
|
|
612
624
|
toMint,
|
|
613
625
|
} = helper.loanFee(actualDebtPre, helper.emptyDebt(), wantMinted);
|
|
614
626
|
!AmountMath.isEmpty(fee) ||
|
|
615
|
-
|
|
616
|
-
|
|
627
|
+
assert.fail(
|
|
628
|
+
X`loan requested (${wantMinted}) is too small; cannot accrue interest`,
|
|
629
|
+
);
|
|
630
|
+
assert(AmountMath.isEqual(newDebtPre, toMint), X`fee mismatch for vault`);
|
|
617
631
|
trace(
|
|
618
632
|
'initVault',
|
|
619
633
|
state.idInManager,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import '@agoric/zoe/exported.js';
|
|
2
4
|
import '@agoric/zoe/src/contracts/exported.js';
|
|
3
5
|
|
|
4
|
-
import '@agoric/governance/exported.js';
|
|
6
|
+
import '@agoric/governance/src/exported.js';
|
|
5
7
|
import { E } from '@endo/eventual-send';
|
|
6
8
|
|
|
7
9
|
import { fit, keyEQ, M, makeScalarMap } from '@agoric/store';
|
|
@@ -32,7 +34,7 @@ import {
|
|
|
32
34
|
} from './params.js';
|
|
33
35
|
import { makeVaultManager } from './vaultManager.js';
|
|
34
36
|
|
|
35
|
-
const { details: X, quote: q
|
|
37
|
+
const { details: X, quote: q } = assert;
|
|
36
38
|
|
|
37
39
|
/** @typedef {{
|
|
38
40
|
* debtMint: ZCFMint<'nat'>,
|
|
@@ -216,15 +218,17 @@ const makeVaultInvitation = ({ state }) => {
|
|
|
216
218
|
} = seat.getProposal();
|
|
217
219
|
const { brand: brandIn } = collateralAmount;
|
|
218
220
|
collateralTypes.has(brandIn) ||
|
|
219
|
-
|
|
221
|
+
assert.fail(X`Not a supported collateral type ${brandIn}`);
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
assert(
|
|
224
|
+
AmountMath.isGTE(
|
|
225
|
+
requestedAmount,
|
|
226
|
+
ephemera.directorParamManager.getMinInitialDebt(),
|
|
227
|
+
),
|
|
228
|
+
X`The request must be for at least ${
|
|
226
229
|
ephemera.directorParamManager.getMinInitialDebt().value
|
|
227
|
-
}. ${requestedAmount.value} is too small
|
|
230
|
+
}. ${requestedAmount.value} is too small`,
|
|
231
|
+
);
|
|
228
232
|
|
|
229
233
|
/** @type {VaultManager} */
|
|
230
234
|
const mgr = collateralTypes.get(brandIn);
|
|
@@ -295,7 +299,7 @@ const machineBehavior = {
|
|
|
295
299
|
// TODO move this under governance #3924
|
|
296
300
|
/**
|
|
297
301
|
* @param {MethodContext} context
|
|
298
|
-
* @param {Issuer
|
|
302
|
+
* @param {Issuer} collateralIssuer
|
|
299
303
|
* @param {Keyword} collateralKeyword
|
|
300
304
|
* @param {VaultManagerParamValues} initialParamValues
|
|
301
305
|
*/
|
|
@@ -321,7 +325,9 @@ const machineBehavior = {
|
|
|
321
325
|
const collateralBrand = zcf.getBrandForIssuer(collateralIssuer);
|
|
322
326
|
// We create only one vault per collateralType.
|
|
323
327
|
!collateralTypes.has(collateralBrand) ||
|
|
324
|
-
|
|
328
|
+
assert.fail(
|
|
329
|
+
X`Collateral brand ${q(collateralBrand)} has already been added`,
|
|
330
|
+
);
|
|
325
331
|
|
|
326
332
|
const managerStorageNode =
|
|
327
333
|
storageNode &&
|
|
@@ -390,9 +396,6 @@ const machineBehavior = {
|
|
|
390
396
|
const factoryPowers = Far('vault factory powers', {
|
|
391
397
|
getGovernedParams: () => ({
|
|
392
398
|
...vaultParamManager.readonly(),
|
|
393
|
-
/** @type {() => Amount<'nat'>} */
|
|
394
|
-
// @ts-expect-error cast
|
|
395
|
-
getDebtLimit: vaultParamManager.readonly().getDebtLimit,
|
|
396
399
|
getChargingPeriod: () => loanTimingParams[CHARGING_PERIOD_KEY].value,
|
|
397
400
|
getRecordingPeriod: () => loanTimingParams[RECORDING_PERIOD_KEY].value,
|
|
398
401
|
}),
|
|
@@ -485,7 +488,7 @@ const publicBehavior = {
|
|
|
485
488
|
getCollateralManager: ({ state }, brandIn) => {
|
|
486
489
|
const { collateralTypes } = state;
|
|
487
490
|
collateralTypes.has(brandIn) ||
|
|
488
|
-
|
|
491
|
+
assert.fail(X`Not a supported collateral type ${brandIn}`);
|
|
489
492
|
/** @type {VaultManager} */
|
|
490
493
|
return collateralTypes.get(brandIn).getPublicFacet();
|
|
491
494
|
},
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import '@agoric/governance/src/exported.js';
|
|
2
4
|
import '@agoric/zoe/exported.js';
|
|
3
5
|
import '@agoric/zoe/src/contracts/exported.js';
|
|
4
6
|
|
|
@@ -19,7 +21,6 @@ import '@agoric/zoe/src/contracts/exported.js';
|
|
|
19
21
|
|
|
20
22
|
import { assertElectorateMatches } from '@agoric/governance';
|
|
21
23
|
import { makeStoredPublisherKit } from '@agoric/notifier';
|
|
22
|
-
import { assertAllDefined } from '@agoric/internal';
|
|
23
24
|
import {
|
|
24
25
|
makeVaultDirectorParamManager,
|
|
25
26
|
LIQUIDATION_INSTALL_KEY,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
MIN_INITIAL_DEBT_KEY,
|
|
28
29
|
} from './params.js';
|
|
29
30
|
import { makeVaultDirector } from './vaultDirector.js';
|
|
31
|
+
import { assertKeysDefined } from '../contractSupport.js';
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
|
|
@@ -52,20 +54,15 @@ import { makeVaultDirector } from './vaultDirector.js';
|
|
|
52
54
|
* }} privateArgs
|
|
53
55
|
*/
|
|
54
56
|
export const start = async (zcf, privateArgs) => {
|
|
55
|
-
|
|
56
|
-
feeMintAccess,
|
|
57
|
-
initialPoserInvitation,
|
|
58
|
-
initialShortfallInvitation,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
initialPoserInvitation,
|
|
65
|
-
initialShortfallInvitation,
|
|
66
|
-
marshaller,
|
|
67
|
-
storageNode,
|
|
68
|
-
});
|
|
57
|
+
assertKeysDefined(privateArgs, [
|
|
58
|
+
'feeMintAccess',
|
|
59
|
+
'initialPoserInvitation',
|
|
60
|
+
'initialShortfallInvitation',
|
|
61
|
+
'storageNode',
|
|
62
|
+
'marshaller',
|
|
63
|
+
]);
|
|
64
|
+
const { feeMintAccess, initialPoserInvitation, initialShortfallInvitation } =
|
|
65
|
+
privateArgs;
|
|
69
66
|
const debtMint = await zcf.registerFeeMint('Minted', feeMintAccess);
|
|
70
67
|
zcf.setTestJig(() => ({
|
|
71
68
|
mintedIssuerRecord: debtMint.getIssuerRecord(),
|
|
@@ -78,7 +75,11 @@ export const start = async (zcf, privateArgs) => {
|
|
|
78
75
|
} = zcf.getTerms().governedParams;
|
|
79
76
|
/** a powerful object; can modify the invitation */
|
|
80
77
|
const vaultDirectorParamManager = await makeVaultDirectorParamManager(
|
|
81
|
-
makeStoredPublisherKit(
|
|
78
|
+
makeStoredPublisherKit(
|
|
79
|
+
privateArgs.storageNode,
|
|
80
|
+
privateArgs.marshaller,
|
|
81
|
+
'governance',
|
|
82
|
+
),
|
|
82
83
|
zcf.getZoeService(),
|
|
83
84
|
initialPoserInvitation,
|
|
84
85
|
liqInstall,
|
|
@@ -96,8 +97,8 @@ export const start = async (zcf, privateArgs) => {
|
|
|
96
97
|
zcf,
|
|
97
98
|
vaultDirectorParamManager,
|
|
98
99
|
debtMint,
|
|
99
|
-
storageNode,
|
|
100
|
-
marshaller,
|
|
100
|
+
privateArgs.storageNode,
|
|
101
|
+
privateArgs.marshaller,
|
|
101
102
|
);
|
|
102
103
|
|
|
103
104
|
return harden({
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Use-object for the owner of a vault
|
|
3
3
|
*/
|
|
4
|
+
// @ts-check
|
|
4
5
|
import '@agoric/zoe/exported.js';
|
|
5
6
|
|
|
6
7
|
import { makeStoredPublishKit } from '@agoric/notifier';
|
|
7
8
|
import { defineDurableKindMulti, makeKindHandle } from '@agoric/vat-data';
|
|
8
9
|
import { makeEphemeraProvider } from '../contractSupport.js';
|
|
9
10
|
|
|
10
|
-
const {
|
|
11
|
+
const { details: X } = assert;
|
|
11
12
|
|
|
12
13
|
// XXX durable key to an ephemeral object
|
|
13
14
|
// UNTIL https://github.com/Agoric/agoric-sdk/issues/4567
|
|
@@ -64,9 +65,7 @@ const helper = {
|
|
|
64
65
|
*/
|
|
65
66
|
owned: ({ state }) => {
|
|
66
67
|
const { vault } = state;
|
|
67
|
-
|
|
68
|
-
throw Fail`Using vault holder after transfer`;
|
|
69
|
-
}
|
|
68
|
+
assert(vault, X`Using vault holder after transfer`);
|
|
70
69
|
return vault;
|
|
71
70
|
},
|
|
72
71
|
/** @param {MethodContext} context */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
|
+
// @ts-check
|
|
2
3
|
/**
|
|
3
4
|
* @file Vault Manager object manages vault-based debts for a collateral type.
|
|
4
5
|
*
|
|
@@ -31,7 +32,6 @@ import {
|
|
|
31
32
|
getAmountOut,
|
|
32
33
|
makeRatio,
|
|
33
34
|
makeRatioFromAmounts,
|
|
34
|
-
atomicTransfer,
|
|
35
35
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
36
36
|
import { E } from '@endo/eventual-send';
|
|
37
37
|
import { unitAmount } from '@agoric/zoe/src/contractSupport/priceQuote.js';
|
|
@@ -164,7 +164,7 @@ const provideEphemera = makeEphemeraProvider(() => ({
|
|
|
164
164
|
*
|
|
165
165
|
* @param {import('./vaultFactory.js').VaultFactoryZCF} zcf
|
|
166
166
|
* @param {ZCFMint<'nat'>} debtMint
|
|
167
|
-
* @param {Brand
|
|
167
|
+
* @param {Brand} collateralBrand
|
|
168
168
|
* @param {ERef<PriceAuthority>} priceAuthority
|
|
169
169
|
* @param {import('./vaultDirector.js').FactoryPowersFacet} factoryPowers
|
|
170
170
|
* @param {ERef<TimerService>} timerService
|
|
@@ -538,9 +538,12 @@ const helperBehavior = {
|
|
|
538
538
|
// it. We could hold it until it crosses some threshold, then sell it
|
|
539
539
|
// to the AMM, or we could transfer it to the reserve. At least it's
|
|
540
540
|
// visible in the accounting.
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
541
|
+
vaultSeat.decrementBy(
|
|
542
|
+
state.retainedCollateralSeat.incrementBy({
|
|
543
|
+
Collateral: collateralPost,
|
|
544
|
+
}),
|
|
545
|
+
);
|
|
546
|
+
zcf.reallocate(vaultSeat, state.retainedCollateralSeat);
|
|
544
547
|
}
|
|
545
548
|
|
|
546
549
|
// Reduce totalCollateral by collateralPre, since all the collateral was
|
|
@@ -624,8 +627,8 @@ const managerBehavior = {
|
|
|
624
627
|
* was type {MintAndReallocate}
|
|
625
628
|
*
|
|
626
629
|
* @param {MethodContext} context
|
|
627
|
-
* @param {Amount
|
|
628
|
-
* @param {Amount
|
|
630
|
+
* @param {Amount} toMint
|
|
631
|
+
* @param {Amount} fee
|
|
629
632
|
* @param {ZCFSeat} seat
|
|
630
633
|
* @param {...ZCFSeat} otherSeats
|
|
631
634
|
* @returns {void}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
assertProposalShape,
|
|
3
5
|
calcSecondaryRequired,
|
|
@@ -7,7 +9,7 @@ import { AmountMath } from '@agoric/ertp';
|
|
|
7
9
|
|
|
8
10
|
import '@agoric/zoe/exported.js';
|
|
9
11
|
|
|
10
|
-
const {
|
|
12
|
+
const { details: X, quote: q } = assert;
|
|
11
13
|
|
|
12
14
|
const { add, multiply } = natSafeMath;
|
|
13
15
|
/**
|
|
@@ -29,7 +31,7 @@ const makeMakeAddLiquidityInvitation = (zcf, getPool) => {
|
|
|
29
31
|
const liquidityIssuer = pool.getLiquidityIssuer();
|
|
30
32
|
const liquidityBrand = zcf.getBrandForIssuer(liquidityIssuer);
|
|
31
33
|
seat.getProposal().want.Liquidity.brand === liquidityBrand ||
|
|
32
|
-
|
|
34
|
+
assert.fail(X`liquidity brand must be ${q(liquidityBrand)}`);
|
|
33
35
|
|
|
34
36
|
return pool.addLiquidity(seat);
|
|
35
37
|
};
|
|
@@ -131,7 +133,6 @@ const makeMakeAddLiquidityAtRateInvitation = (
|
|
|
131
133
|
});
|
|
132
134
|
|
|
133
135
|
const giveAlloc = seat.getProposal().give;
|
|
134
|
-
/** @type {Amount<'nat'>} */
|
|
135
136
|
const secondaryAmount = giveAlloc.Secondary;
|
|
136
137
|
const secondaryBrand = secondaryAmount.brand;
|
|
137
138
|
const centralBrand = giveAlloc.Central.brand;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import { E } from '@endo/eventual-send';
|
|
2
4
|
import { AmountMath, AssetKind } from '@agoric/ertp';
|
|
3
|
-
import {
|
|
4
|
-
assertProposalShape,
|
|
5
|
-
atomicTransfer,
|
|
6
|
-
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
5
|
+
import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
|
|
7
6
|
|
|
8
7
|
import { definePoolKind } from './pool.js';
|
|
9
8
|
|
|
10
|
-
const { quote: q
|
|
9
|
+
const { details: X, quote: q } = assert;
|
|
11
10
|
|
|
12
11
|
const DISPLAY_INFO = harden({ decimalPlaces: 6 });
|
|
13
12
|
|
|
@@ -17,7 +16,7 @@ const DISPLAY_INFO = harden({ decimalPlaces: 6 });
|
|
|
17
16
|
* @param {ZCF} zcf
|
|
18
17
|
* @param {(Brand) => boolean} isInSecondaries
|
|
19
18
|
* @param {import('@agoric/store/src/stores/store-utils.js').AtomicProvider<Brand, ZCFMint>} brandToLiquidityMintProvider
|
|
20
|
-
* @param {() => (secondaryBrand: Brand
|
|
19
|
+
* @param {() => (secondaryBrand: Brand) => Promise<void>} getAddIssuerToReserve
|
|
21
20
|
*/
|
|
22
21
|
export const makeAddIssuer = (
|
|
23
22
|
zcf,
|
|
@@ -40,12 +39,12 @@ export const makeAddIssuer = (
|
|
|
40
39
|
]);
|
|
41
40
|
// AWAIT ///////////////
|
|
42
41
|
secondaryAssetKind === AssetKind.NAT ||
|
|
43
|
-
|
|
42
|
+
assert.fail(X`${q(keyword)} asset not fungible (must use NAT math)`);
|
|
44
43
|
|
|
45
44
|
/** @type {(brand: Brand) => Promise<ZCFMint>} */
|
|
46
45
|
const makeLiquidityMint = brand => {
|
|
47
46
|
!isInSecondaries(brand) ||
|
|
48
|
-
|
|
47
|
+
assert.fail(X`issuer ${secondaryIssuer} already has a pool`);
|
|
49
48
|
|
|
50
49
|
const liquidityKeyword = `${keyword}Liquidity`;
|
|
51
50
|
zcf.assertUniqueKeyword(liquidityKeyword);
|
|
@@ -57,19 +56,19 @@ export const makeAddIssuer = (
|
|
|
57
56
|
]),
|
|
58
57
|
([issuer, mint]) => {
|
|
59
58
|
console.log(
|
|
60
|
-
`Saved issuer ${secondaryIssuer} to keyword ${keyword} and got back ${issuer}`,
|
|
59
|
+
X`Saved issuer ${secondaryIssuer} to keyword ${keyword} and got back ${issuer}`,
|
|
61
60
|
);
|
|
62
61
|
return mint;
|
|
63
62
|
},
|
|
64
63
|
).catch(e => {
|
|
65
64
|
console.error(
|
|
66
|
-
`Failure Saving issuer ${secondaryIssuer}. Not added to Reserve`,
|
|
65
|
+
X`Failure Saving issuer ${secondaryIssuer}. Not added to Reserve`,
|
|
67
66
|
);
|
|
68
67
|
throw e;
|
|
69
68
|
});
|
|
70
69
|
};
|
|
71
70
|
|
|
72
|
-
/** @type {(brand: Brand
|
|
71
|
+
/** @type {(brand: Brand) => Promise<void>} */
|
|
73
72
|
const finish = brand => {
|
|
74
73
|
// defer lookup until necessary. more aligned with governed
|
|
75
74
|
// param we expect this to be eventually.
|
|
@@ -134,8 +133,6 @@ export const makeAddPoolInvitation = (
|
|
|
134
133
|
.get(secondaryBrand)
|
|
135
134
|
.getIssuerRecord();
|
|
136
135
|
|
|
137
|
-
/** @type {Amount<'nat'>} */
|
|
138
|
-
// @ts-expect-error cast governance types
|
|
139
136
|
const minPoolLiquidity = ammPowers.params.getMinInitialPoolLiquidity();
|
|
140
137
|
|
|
141
138
|
if (proposalWant.Liquidity) {
|
|
@@ -150,12 +147,17 @@ export const makeAddPoolInvitation = (
|
|
|
150
147
|
centralAboveMinimum,
|
|
151
148
|
);
|
|
152
149
|
AmountMath.isGTE(funderLiquidityAmount, wantLiquidityAmount) ||
|
|
153
|
-
|
|
150
|
+
assert.fail(
|
|
151
|
+
X`Requested too many liquidity tokens (${wantLiquidityAmount}, max: ${funderLiquidityAmount}`,
|
|
152
|
+
);
|
|
154
153
|
}
|
|
155
154
|
AmountMath.isGTE(centralAmount, minPoolLiquidity) ||
|
|
156
|
-
|
|
155
|
+
assert.fail(
|
|
156
|
+
X`The minimum initial liquidity is ${minPoolLiquidity}, rejecting ${centralAmount}`,
|
|
157
|
+
);
|
|
157
158
|
const minLiqAmount = AmountMath.make(
|
|
158
159
|
liquidityBrand,
|
|
160
|
+
// @ts-expect-error known nat
|
|
159
161
|
minPoolLiquidity.value,
|
|
160
162
|
);
|
|
161
163
|
|
|
@@ -176,15 +178,10 @@ export const makeAddPoolInvitation = (
|
|
|
176
178
|
// transfer minPoolLiquidity in tokens from the funder to the reserve.
|
|
177
179
|
helper.addLiquidityInternal(seat, secondaryAmount, centralAmount);
|
|
178
180
|
|
|
181
|
+
seat.decrementBy({ Liquidity: minLiqAmount });
|
|
179
182
|
const { zcfSeat: reserveLiquidityTokenSeat } = zcf.makeEmptySeatKit();
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
seat,
|
|
183
|
-
reserveLiquidityTokenSeat,
|
|
184
|
-
{ Liquidity: minLiqAmount },
|
|
185
|
-
{ [liquidityKeyword]: minLiqAmount },
|
|
186
|
-
);
|
|
187
|
-
|
|
183
|
+
reserveLiquidityTokenSeat.incrementBy({ [liquidityKeyword]: minLiqAmount });
|
|
184
|
+
zcf.reallocate(reserveLiquidityTokenSeat, seat);
|
|
188
185
|
seat.exit();
|
|
189
186
|
pool.updateState();
|
|
190
187
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import { AmountMath } from '@agoric/ertp';
|
|
2
4
|
import {
|
|
3
5
|
ceilMultiplyBy,
|
|
@@ -9,7 +11,7 @@ import './internal-types.js';
|
|
|
9
11
|
|
|
10
12
|
import { BASIS_POINTS } from './defaults.js';
|
|
11
13
|
|
|
12
|
-
const {
|
|
14
|
+
const { details: X } = assert;
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Make a ratio given a nat representing basis points and a brand.
|
|
@@ -33,14 +35,16 @@ const amountGT = (left, right) =>
|
|
|
33
35
|
* Apply the feeRatio to the amount that has a matching brand. This used to
|
|
34
36
|
* calculate fees in the single pool case.
|
|
35
37
|
*
|
|
36
|
-
* @param {{ amountIn: Amount
|
|
38
|
+
* @param {{ amountIn: Amount, amountOut: Amount}} amounts - a record with two
|
|
37
39
|
* amounts in different brands.
|
|
38
40
|
* @param {Ratio} feeRatio
|
|
39
|
-
* @returns {Amount
|
|
41
|
+
* @returns {Amount}
|
|
40
42
|
*/
|
|
41
43
|
const calcFee = ({ amountIn, amountOut }, feeRatio) => {
|
|
42
44
|
feeRatio.numerator.brand === feeRatio.denominator.brand ||
|
|
43
|
-
|
|
45
|
+
assert.fail(
|
|
46
|
+
X`feeRatio numerator and denominator must use the same brand ${feeRatio}`,
|
|
47
|
+
);
|
|
44
48
|
|
|
45
49
|
let sameBrandAmount;
|
|
46
50
|
if (amountIn.brand === feeRatio.numerator.brand) {
|
|
@@ -48,7 +52,9 @@ const calcFee = ({ amountIn, amountOut }, feeRatio) => {
|
|
|
48
52
|
} else if (amountOut.brand === feeRatio.numerator.brand) {
|
|
49
53
|
sameBrandAmount = amountOut;
|
|
50
54
|
} else {
|
|
51
|
-
|
|
55
|
+
assert.fail(
|
|
56
|
+
X`feeRatio's brand (${feeRatio.numerator.brand}) must match one of the amounts [${amountIn}, ${amountOut}].`,
|
|
57
|
+
);
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
// Always round fees up
|
|
@@ -56,7 +62,7 @@ const calcFee = ({ amountIn, amountOut }, feeRatio) => {
|
|
|
56
62
|
|
|
57
63
|
// Fee cannot exceed the amount on which it is levied
|
|
58
64
|
AmountMath.isGTE(sameBrandAmount, fee) ||
|
|
59
|
-
|
|
65
|
+
assert.fail(X`The feeRatio can't be greater than 1 ${feeRatio}`);
|
|
60
66
|
|
|
61
67
|
return fee;
|
|
62
68
|
};
|