@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.
Files changed (140) hide show
  1. package/README.md +26 -20
  2. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  3. package/bundles/bundle-auctioneer.js +1 -0
  4. package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
  5. package/bundles/bundle-econCommitteeCharter.js +1 -0
  6. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  7. package/bundles/bundle-feeDistributor.js +1 -1
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -0
  10. package/bundles/bundle-psm-js-meta.json +666 -0
  11. package/bundles/bundle-psm.js +1 -1
  12. package/bundles/bundle-reserve-js-meta.json +662 -0
  13. package/bundles/bundle-reserve.js +1 -1
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  16. package/bundles/bundle-vaultFactory-js-meta.json +786 -0
  17. package/bundles/bundle-vaultFactory.js +1 -1
  18. package/exported.js +0 -2
  19. package/package.json +34 -31
  20. package/scripts/add-collateral-core.js +14 -4
  21. package/scripts/build-bundles.js +9 -2
  22. package/scripts/deploy-contracts.js +1 -4
  23. package/scripts/init-core.js +20 -38
  24. package/scripts/invite-committee-core.js +1 -1
  25. package/scripts/manual-price-feed.js +2 -2
  26. package/scripts/price-feed-core.js +7 -6
  27. package/scripts/start-local-chain.sh +84 -0
  28. package/src/auction/auctionBook.js +755 -0
  29. package/src/auction/auctioneer.js +720 -0
  30. package/src/auction/offerBook.js +221 -0
  31. package/src/auction/params.js +174 -0
  32. package/src/auction/scheduleMath.js +167 -0
  33. package/src/auction/scheduler.js +370 -0
  34. package/src/auction/sortedOffers.js +136 -0
  35. package/src/auction/util.js +55 -0
  36. package/src/clientSupport.js +324 -0
  37. package/src/collectFees.js +8 -14
  38. package/src/contractSupport.js +24 -68
  39. package/src/econCommitteeCharter.js +161 -77
  40. package/src/feeDistributor.js +60 -20
  41. package/src/index.js +2 -0
  42. package/src/interest-math.js +1 -4
  43. package/src/interest.js +20 -13
  44. package/src/price/README.md +57 -0
  45. package/src/price/fluxAggregatorContract.js +190 -0
  46. package/src/price/fluxAggregatorKit.js +375 -0
  47. package/src/price/priceOracleKit.js +127 -0
  48. package/src/price/roundsManager.js +726 -0
  49. package/src/proposals/addAssetToVault.js +89 -94
  50. package/src/proposals/committee-proposal.js +141 -40
  51. package/src/proposals/core-proposal.js +100 -167
  52. package/src/proposals/econ-behaviors.js +320 -564
  53. package/src/proposals/price-feed-proposal.js +175 -78
  54. package/src/proposals/startEconCommittee.js +25 -12
  55. package/src/proposals/startPSM.js +231 -211
  56. package/src/proposals/utils.js +31 -17
  57. package/src/psm/README.md +71 -0
  58. package/src/psm/psm.js +272 -160
  59. package/src/psm/types.js +2 -0
  60. package/src/reserve/assetReserve.js +56 -413
  61. package/src/reserve/assetReserveKit.js +303 -0
  62. package/src/reserve/doc.md +1 -3
  63. package/src/reserve/params.js +2 -5
  64. package/src/typeGuards.js +13 -0
  65. package/src/vaultFactory/Liquidation.md +100 -0
  66. package/src/vaultFactory/burn.js +2 -1
  67. package/src/vaultFactory/liquidation.js +270 -108
  68. package/src/vaultFactory/math.js +95 -0
  69. package/src/vaultFactory/orderedVaultStore.js +0 -1
  70. package/src/vaultFactory/params.js +133 -112
  71. package/src/vaultFactory/prioritizedVaults.js +36 -79
  72. package/src/vaultFactory/storeUtils.js +67 -9
  73. package/src/vaultFactory/type-imports.js +2 -0
  74. package/src/vaultFactory/types.js +22 -26
  75. package/src/vaultFactory/vault.js +772 -709
  76. package/src/vaultFactory/vaultDirector.js +480 -483
  77. package/src/vaultFactory/vaultFactory.js +99 -60
  78. package/src/vaultFactory/vaultHolder.js +121 -95
  79. package/src/vaultFactory/vaultKit.js +39 -31
  80. package/src/vaultFactory/vaultManager.js +1249 -868
  81. package/bundles/bundle-amm-meta.js +0 -618
  82. package/bundles/bundle-amm.js +0 -1
  83. package/bundles/bundle-feeDistributor-meta.js +0 -346
  84. package/bundles/bundle-interchainPool-meta.js +0 -534
  85. package/bundles/bundle-interchainPool.js +0 -1
  86. package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
  87. package/bundles/bundle-liquidateIncrementally.js +0 -1
  88. package/bundles/bundle-liquidateMinimum-meta.js +0 -442
  89. package/bundles/bundle-liquidateMinimum.js +0 -1
  90. package/bundles/bundle-psm-meta.js +0 -538
  91. package/bundles/bundle-psmCharter-meta.js +0 -418
  92. package/bundles/bundle-psmCharter.js +0 -1
  93. package/bundles/bundle-reserve-meta.js +0 -542
  94. package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
  95. package/bundles/bundle-stakeFactory-meta.js +0 -574
  96. package/bundles/bundle-stakeFactory.js +0 -1
  97. package/bundles/bundle-vaultFactory-meta.js +0 -598
  98. package/scripts/add-initial-liquidity.js +0 -180
  99. package/src/collect.js +0 -13
  100. package/src/interchainPool.js +0 -135
  101. package/src/makeTracer.js +0 -36
  102. package/src/my-lien.js +0 -85
  103. package/src/proposals/demoIssuers.js +0 -685
  104. package/src/proposals/sim-behaviors.js +0 -40
  105. package/src/psm/psmCharter.js +0 -139
  106. package/src/stakeFactory/README.md +0 -62
  107. package/src/stakeFactory/attestation.js +0 -267
  108. package/src/stakeFactory/attestationTool.js +0 -66
  109. package/src/stakeFactory/constants.js +0 -16
  110. package/src/stakeFactory/params.js +0 -31
  111. package/src/stakeFactory/stakeFactory.js +0 -236
  112. package/src/stakeFactory/stakeFactoryKit.js +0 -455
  113. package/src/stakeFactory/stakeFactoryManager.js +0 -296
  114. package/src/stakeFactory/types.js +0 -42
  115. package/src/vaultFactory/liquidateIncrementally.js +0 -350
  116. package/src/vaultFactory/liquidateMinimum.js +0 -100
  117. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  118. package/src/vpool-xyk-amm/addLiquidity.js +0 -222
  119. package/src/vpool-xyk-amm/addPool.js +0 -197
  120. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  121. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  122. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
  123. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
  124. package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
  125. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
  126. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
  127. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
  128. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
  129. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
  130. package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
  131. package/src/vpool-xyk-amm/doublePool.js +0 -194
  132. package/src/vpool-xyk-amm/estimate.js +0 -155
  133. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
  134. package/src/vpool-xyk-amm/params.js +0 -61
  135. package/src/vpool-xyk-amm/pool.js +0 -396
  136. package/src/vpool-xyk-amm/priceAuthority.js +0 -94
  137. package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
  138. package/src/vpool-xyk-amm/singlePool.js +0 -73
  139. package/src/vpool-xyk-amm/swap.js +0 -69
  140. package/src/vpool-xyk-amm/types.js +0 -154
@@ -1,139 +0,0 @@
1
- // @ts-check
2
-
3
- import '@agoric/governance/src/exported.js';
4
- import { makeScalarMapStore, M, makeHeapFarInstance, fit } from '@agoric/store';
5
- import '@agoric/zoe/exported.js';
6
- import '@agoric/zoe/src/contracts/exported.js';
7
- import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
8
- import { BrandShape } from '@agoric/ertp';
9
- import { TimestampShape } from '@agoric/swingset-vat/src/vats/timer/typeGuards.js';
10
- import { E } from '@endo/far';
11
-
12
- /**
13
- * @file
14
- *
15
- * This contract makes it possible for those who govern the PSM to call for
16
- * votes on changes. A more complete implementation would validate parameters,
17
- * constrain deadlines and possibly split the ability to call for votes into
18
- * separate capabilities for finer grain encapsulation.
19
- */
20
-
21
- /**
22
- * @typedef {object} ParamChangesOfferArgs
23
- * @property {bigint} deadline
24
- * @property {Instance} instance
25
- * @property {Record<string, unknown>} params
26
- * @property {{paramPath: { key: string }}} [path]
27
- */
28
- const ParamChangesOfferArgsShape = harden(
29
- M.split(
30
- {
31
- deadline: TimestampShape,
32
- instance: InstanceHandleShape,
33
- params: M.recordOf(M.string(), M.any()),
34
- },
35
- M.partial({
36
- path: { paramPath: { key: M.string() } },
37
- }),
38
- ),
39
- );
40
-
41
- /**
42
- * @param {ZCF<{binaryVoteCounterInstallation:Installation}>} zcf
43
- */
44
- export const start = async zcf => {
45
- const { binaryVoteCounterInstallation: counter } = zcf.getTerms();
46
- /** @type {MapStore<Instance,GovernedContractFacetAccess<{},{}>>} */
47
- const instanceToGovernor = makeScalarMapStore();
48
-
49
- const makeParamInvitation = () => {
50
- /**
51
- * @param {ZCFSeat} seat
52
- * @param {ParamChangesOfferArgs} args
53
- */
54
- const voteOnParamChanges = (seat, args) => {
55
- fit(args, ParamChangesOfferArgsShape);
56
- seat.exit();
57
-
58
- const {
59
- params,
60
- instance,
61
- deadline,
62
- path = { paramPath: { key: 'governedApi' } },
63
- } = args;
64
- const psmGovernor = instanceToGovernor.get(instance);
65
- return E(psmGovernor).voteOnParamChanges(counter, deadline, {
66
- ...path,
67
- changes: params,
68
- });
69
- };
70
-
71
- return zcf.makeInvitation(voteOnParamChanges, 'vote on param changes');
72
- };
73
-
74
- const makeOfferFilterInvitation = (instance, strings, deadline) => {
75
- const voteOnOfferFilterHandler = seat => {
76
- seat.exit();
77
-
78
- const psmGovernor = instanceToGovernor.get(instance);
79
- return E(psmGovernor).voteOnOfferFilter(counter, deadline, strings);
80
- };
81
-
82
- return zcf.makeInvitation(voteOnOfferFilterHandler, 'vote on offer filter');
83
- };
84
-
85
- const MakerShape = M.interface('PSM Charter InvitationMakers', {
86
- VoteOnParamChange: M.call().returns(M.promise()),
87
- VoteOnPauseOffers: M.call(
88
- InstanceHandleShape,
89
- M.arrayOf(M.string()),
90
- TimestampShape,
91
- ).returns(M.promise()),
92
- });
93
- const invitationMakers = makeHeapFarInstance(
94
- 'PSM Invitation Makers',
95
- MakerShape,
96
- {
97
- VoteOnParamChange: makeParamInvitation,
98
- VoteOnPauseOffers: makeOfferFilterInvitation,
99
- },
100
- );
101
-
102
- const charterMemberHandler = seat => {
103
- seat.exit();
104
- return harden({ invitationMakers });
105
- };
106
-
107
- const psmCharterCreatorI = M.interface('PSM Charter creatorFacet', {
108
- addInstance: M.call(InstanceHandleShape, M.any())
109
- .optional(BrandShape, BrandShape)
110
- .returns(),
111
- makeCharterMemberInvitation: M.call().returns(M.promise()),
112
- });
113
-
114
- const creatorFacet = makeHeapFarInstance(
115
- 'PSM Charter creatorFacet',
116
- psmCharterCreatorI,
117
- {
118
- /**
119
- * @param {Instance} psmInstance
120
- * @param {GovernedContractFacetAccess<{},{}>} psmGovernorFacet
121
- * @param {Brand} [anchor] for diagnostic use only
122
- * @param {Brand} [minted] for diagnostic use only
123
- */
124
- addInstance: (psmInstance, psmGovernorFacet, anchor, minted) => {
125
- console.log('psmCharter: adding instance', { minted, anchor });
126
- instanceToGovernor.init(psmInstance, psmGovernorFacet);
127
- },
128
- makeCharterMemberInvitation: () =>
129
- zcf.makeInvitation(
130
- charterMemberHandler,
131
- 'PSM charter member invitation',
132
- ),
133
- },
134
- );
135
-
136
- return harden({ creatorFacet });
137
- };
138
-
139
- export const INVITATION_MAKERS_DESC = 'PSM charter member invitation';
@@ -1,62 +0,0 @@
1
- # stakeFactory design notes
2
-
3
- The stakeFactory contract provides loans on the basis of
4
- staked assets that earn rewards.
5
-
6
- The following sequence diagram shows an interaction between stakeFactory and:
7
- - dapp: with rich interaction but low privilege
8
- - walletBridge: with high privilege and constrained interaction
9
- - attestation: a service within the stakeFactory contract
10
- - Cosmos_SDK: the Cosmos SDK layer, including the `x/lien` module
11
-
12
- Before this interaction, an `ag123` account has been provisioned,
13
- which provides an `AttestationMaker` for that account to the wallet.
14
-
15
- Note that the account already has 4000 BLD liened before this interaction.
16
-
17
- ```mermaid
18
- sequenceDiagram
19
- actor dapp
20
- participant walletBridge
21
- participant attestation
22
- participant stakeFactory
23
- participant Cosmos_SDK
24
-
25
- note right of dapp: How dapp finds the current state
26
-
27
- note right of walletBridge: walletBridge is provided to dapps and controlled by Wallet UI
28
- dapp ->>+ walletBridge: getPurseBalance("BLD")
29
- dapp -->> walletBridge: 5000
30
-
31
- note right of attestation: ag123 is a cosmos address
32
- dapp ->> attestation: getMax(ag123)
33
- attestation ->> Cosmos_SDK: getAccountState(ag123)
34
- note right of Cosmos_SDK: Cosmos supports lien
35
- Cosmos_SDK -->> attestation: account status in which 4000 BLD liened
36
- attestation -->> dapp: account status in which 4000 BLD liened
37
- note right of dapp: Treasury now knows
38
-
39
- note right of dapp: Want to get 450 IST by liening 500 BLD
40
- dapp ->> walletBridge: getReturnableAttestation(want: 450 IST, give: 500 BLD-Att)
41
- note right of walletBridge: Blocks on user approval in wallet
42
- walletBridge ->> attestation: makeAttestation(500 BLD)
43
- attestation ->> Cosmos_SDK: increaseLiened(+500 BLD)
44
- Cosmos_SDK -->> attestation: new lien balance or throws
45
-
46
- attestation -->> walletBridge: Payment of 500 BLD-Att liened on ag123
47
-
48
- walletBridge ->> stakeFactory: offer w/payment for {give: 500 BLD-Att, want: 450 IST}
49
-
50
- stakeFactory --> walletBridge: Payment for 450 IST and offerResult
51
- walletBridge --> dapp: notifiers from offerResult
52
- ```
53
-
54
- ## Components
55
-
56
- In addition to the `stakeFactory.js` module with the contract `start` function:
57
-
58
- - `params.js`: utilities for governance parameters
59
- - `stakeFactoryKit.js`: `makeStakeFactoryKit` is called once per loan
60
- - `stakeFactoryManager.js`: handles interest etc. for all loans
61
- - `attestation.js`: minting tokens that attest to liens,
62
- and wrapping them in per-user attestation maker authorities.
@@ -1,267 +0,0 @@
1
- // @ts-check
2
- // @jessie-check
3
-
4
- import { AmountMath, AssetKind } from '@agoric/ertp';
5
- import { E, Far } from '@endo/far';
6
- import { fit, M, makeCopyBag, makeStore, provideLazy } from '@agoric/store';
7
- import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
8
- import { AttKW as KW } from './constants.js';
9
- import { makeAttestationTool } from './attestationTool.js';
10
-
11
- const { details: X } = assert;
12
-
13
- /**
14
- * @typedef {{
15
- * mintAttestation: unknown,
16
- * returnAttestation: OfferHandler,
17
- * getLiened: (address: Address, brand: Brand<'nat'>) => Amount<'nat'>,
18
- * getAccountState: unknown,
19
- * wrapLienedAmount: unknown,
20
- * unwrapLienedAmount: unknown,
21
- * }} LienMint
22
- */
23
-
24
- /**
25
- * To support `makeAttestation`, we directly mint attestation payments.
26
- * We still use a ZCFMint because returning attestations is done
27
- * through Zoe offers.
28
- *
29
- * @param {ZCF} zcf
30
- * @template {AssetKind} K
31
- * @param {ZCFMint<K>} zcfMint
32
- * @param {Amount<K>} amountToMint
33
- * @returns {Promise<Payment<K>>}
34
- */
35
- const mintZCFMintPayment = (zcf, zcfMint, amountToMint) => {
36
- const { userSeat, zcfSeat } = zcf.makeEmptySeatKit();
37
- zcfMint.mintGains(harden({ [KW.Attestation]: amountToMint }), zcfSeat);
38
- zcfSeat.exit();
39
- return E(userSeat).getPayout(KW.Attestation);
40
- };
41
-
42
- /**
43
- * Make a ZCFMint attentuated so that minting represents
44
- * putting a lien on staked assets. Payments can be returned,
45
- * releasing (part of) the lien.
46
- *
47
- * NOTE: Using Issuer.combine or AmountMath.add could result in
48
- * Payments / Amounts with multiple addresses.
49
- * Callers are responsible to split any such payment before returning.
50
- *
51
- * @param {ZCF} zcf
52
- * @param {Brand<'nat'>} stakeBrand brand of the staked assets
53
- * @param {ERef<StakingAuthority>} lienBridge bridge to account state
54
- */
55
- const makeAttestationIssuerKit = async (zcf, stakeBrand, lienBridge) => {
56
- const { subtract, makeEmpty, isGTE, coerce } = AmountMath;
57
- const empty = makeEmpty(stakeBrand);
58
- /** @type { ZCFMint<'copyBag'> } */
59
- const attMint = await zcf.makeZCFMint(KW.Attestation, AssetKind.COPY_BAG);
60
- /** @type {{ issuer: Issuer<'copyBag'>, brand: Brand<'copyBag'>}} */
61
- const { issuer, brand: attBrand } = attMint.getIssuerRecord();
62
-
63
- /**
64
- * @param {Address} address
65
- * @param {Amount<'nat'>} lienedAmount
66
- * @returns {Amount<'copyBag'>}
67
- */
68
- const wrapLienedAmount = (address, lienedAmount) =>
69
- AmountMath.make(attBrand, makeCopyBag([[address, lienedAmount.value]]));
70
-
71
- /** @param {Amount<'copyBag'>} attestationAmount */
72
- const unwrapLienedAmount = attestationAmount => {
73
- attestationAmount.brand === attBrand ||
74
- assert.fail(
75
- X`The escrowed attestation ${attestationAmount} was not of the attestation brand ${attBrand}`,
76
- );
77
- fit(
78
- attestationAmount.value.payload,
79
- harden([[M.string(), M.bigint()]]),
80
- 'attestationAmount',
81
- );
82
- /** @type {[Address, bigint][]} */
83
- const [[address, valueReturned]] = attestationAmount.value.payload;
84
- const lienedAmount = AmountMath.make(stakeBrand, valueReturned);
85
- return { address, lienedAmount };
86
- };
87
-
88
- /**
89
- * Non-authoritative store of nonzero lien amounts.
90
- *
91
- * @type {Store<Address, Amount<'nat'>>}
92
- */
93
- const amountByAddress = makeStore('amount');
94
-
95
- /**
96
- * Get non-authoritative liened amount from the JS store, without using the lienBridge.
97
- *
98
- * @param {Address} address
99
- * @param {Brand<'nat'>} brand
100
- */
101
- const getLiened = (address, brand) => {
102
- assert.typeof(address, 'string');
103
- assert.equal(brand, stakeBrand);
104
- if (amountByAddress.has(address)) {
105
- return amountByAddress.get(address);
106
- }
107
- // Don't bother storing empty amounts.
108
- return empty;
109
- };
110
-
111
- const getAccountState = async (address, brand) => {
112
- const liened = getLiened(address, brand);
113
- const s = await E(lienBridge).getAccountState(address, brand);
114
- assert(AmountMath.isEqual(liened, s.liened));
115
- return s;
116
- };
117
-
118
- /** @type {(m: Amount, s: Amount) => Amount} */
119
- const subtractOrZero = (m, s) => (isGTE(m, s) ? subtract(m, s) : empty);
120
- // check that x <= hi - lo
121
- const checkDelta = (x, label, hi, lo) => {
122
- const bound = subtractOrZero(hi, lo);
123
- assert(
124
- isGTE(bound, coerce(stakeBrand, x)),
125
- // TODO: X`...${raw(label)}...`
126
- X`Only ${bound} was ${label}, but an attestation was attempted for ${x}`,
127
- );
128
- };
129
- const assertAccountStateOK = async (address, toLien) => {
130
- const s = await getAccountState(address, stakeBrand);
131
- const unlocked = subtractOrZero(s.total, s.locked);
132
- checkDelta(toLien, 'unliened', s.total, s.liened);
133
- checkDelta(toLien, 'bonded and unliened', s.bonded, s.liened);
134
- checkDelta(toLien, 'unlocked and unliened', unlocked, s.liened);
135
- };
136
-
137
- /**
138
- * @param {Address} address
139
- * @param {Amount<'nat'>} lienDelta
140
- */
141
- const mintAttestation = async (address, lienDelta) => {
142
- // This account state check is primarily to provide useful diagnostics.
143
- // Since things like the bonded amount can change out from under us,
144
- // we shouldn't rely on it completely.
145
- // PERFORMANCE NOTE: this check shouldn't be necessary and skipping it
146
- // may speed things up.
147
- await assertAccountStateOK(address, lienDelta);
148
-
149
- // Since our mint is not subject to normal supply/demand,
150
- // minting here and failing in changeLiened below does no harm.
151
- const attestationPayment = await mintZCFMintPayment(
152
- zcf,
153
- attMint,
154
- wrapLienedAmount(address, lienDelta),
155
- );
156
-
157
- const newLiened = await E(lienBridge).increaseLiened(address, lienDelta);
158
- // COMMIT: update the stored liened amount and issue the attestation.
159
- if (amountByAddress.has(address)) {
160
- amountByAddress.set(address, newLiened);
161
- } else {
162
- amountByAddress.init(address, newLiened);
163
- }
164
- return attestationPayment;
165
- };
166
-
167
- /** @param {ZCFSeat} seat */
168
- const returnAttestation = async seat => {
169
- assertProposalShape(seat, {
170
- give: { [KW.Attestation]: null },
171
- want: {},
172
- });
173
-
174
- const {
175
- give: { [KW.Attestation]: attestationAmount },
176
- } = seat.getProposal();
177
- if (AmountMath.isEmpty(attestationAmount)) {
178
- seat.exit();
179
- return;
180
- }
181
- const { address, lienedAmount: amountReturned } =
182
- unwrapLienedAmount(attestationAmount);
183
- const newLiened = await E(lienBridge).decreaseLiened(
184
- address,
185
- amountReturned,
186
- );
187
- // COMMIT. Burn the escrowed attestation payment and exit the seat.
188
- if (newLiened === empty) {
189
- amountByAddress.delete(address);
190
- } else {
191
- amountByAddress.set(address, newLiened);
192
- }
193
- attMint.burnLosses(harden({ Attestation: attestationAmount }), seat);
194
- seat.exit();
195
- };
196
-
197
- /** @type {ERef<LienMint>} */
198
- const lienMint = Far('LienMint', {
199
- mintAttestation,
200
- returnAttestation,
201
- getLiened,
202
- getAccountState,
203
- wrapLienedAmount,
204
- /**
205
- * @param {Amount<'copyBag'>} attAmt
206
- * @throws if `attAmt` payload length is not 1
207
- */
208
- unwrapLienedAmount: attAmt => unwrapLienedAmount(attAmt).lienedAmount,
209
- });
210
- return harden({ issuer, brand: attBrand, lienMint });
211
- };
212
-
213
- /**
214
- * Authorize each account holder to lien some of their staked assets
215
- * and get an attestation that the lien is in place.
216
- *
217
- * @param {ZCF} zcf
218
- * @param {Brand<'nat'>} stakeBrand
219
- * @param {ERef<StakingAuthority>} lienBridge
220
- *
221
- * NOTE: the liened amount is kept both here in JS and on the
222
- * other side of the lienBridge. The mint created here
223
- * is the authority on the liened amount. The liened amount
224
- * on the other side of the bridge may lag. Do not create two
225
- * mints that share a bridge.
226
- *
227
- * The provideAttestationMaker method on the returned creatorFacet
228
- * provides the authorization for an address. The account holder
229
- * can then use attMaker.makeAttestation(lienDelta).
230
- *
231
- * The keyword for use in returnAttestation offers is `Attestation`.
232
- */
233
- export const makeAttestationFacets = async (zcf, stakeBrand, lienBridge) => {
234
- /** @type {Store<Address, AttestationTool>} */
235
- const attMakerByAddress = makeStore('address');
236
-
237
- const { issuer, brand, lienMint } = await makeAttestationIssuerKit(
238
- zcf,
239
- stakeBrand,
240
- lienBridge,
241
- );
242
-
243
- return harden({
244
- publicFacet: Far('attestation publicFacet', {
245
- getIssuer: () => issuer,
246
- getBrand: () => brand,
247
- makeReturnAttInvitation: () =>
248
- zcf.makeInvitation(lienMint.returnAttestation, 'returnAttestation'),
249
- }),
250
- creatorFacet: Far('creator', {
251
- /**
252
- * IMPORTANT: The attestation maker should only be given to the owner of the
253
- * address. Only the owner can authorize creation of attestations and
254
- * the resulting liens on their underlying tokens.
255
- *
256
- * @param {Address} address
257
- */
258
- provideAttestationTool: address => {
259
- assert.typeof(address, 'string');
260
- return provideLazy(attMakerByAddress, address, () =>
261
- makeAttestationTool(address, lienMint, stakeBrand, zcf),
262
- );
263
- },
264
- getLiened: lienMint.getLiened,
265
- }),
266
- });
267
- };
@@ -1,66 +0,0 @@
1
- // @ts-check
2
- /**
3
- * @typedef {Readonly<{
4
- * address: Address,
5
- * lienMint: *,
6
- * stakeBrand: Brand<'nat'>,
7
- * zcf: ZCF,
8
- * }>} State
9
- * @typedef {{
10
- * state: State,
11
- * }} MethodContext
12
- */
13
-
14
- import { defineKind } from '@agoric/vat-data';
15
- /**
16
- * @param {Address} address
17
- * @param {import('./attestation').LienMint} lienMint
18
- * @param {Brand<'nat'>} stakeBrand
19
- * @param {ZCF} zcf
20
- */
21
- const initState = (address, lienMint, stakeBrand, zcf) => {
22
- return { address, lienMint, stakeBrand, zcf };
23
- };
24
-
25
- const behavior = {
26
- /**
27
- * @param {MethodContext} context
28
- * @param {Amount<'nat'>} lienedDelta
29
- */
30
- makeAttestation: ({ state }, lienedDelta) =>
31
- state.lienMint.mintAttestation(state.address, lienedDelta),
32
-
33
- /** @param {MethodContext} context */
34
- getAccountState: ({ state }) =>
35
- state.lienMint.getAccountState(state.address, state.stakeBrand),
36
-
37
- /** @param {MethodContext} context */
38
- makeReturnAttInvitation: ({ state }) =>
39
- state.zcf.makeInvitation(
40
- state.lienMint.returnAttestation,
41
- 'returnAttestation',
42
- ),
43
-
44
- /**
45
- * @param {MethodContext} context
46
- * @param {Amount<'nat'>} lienedAmount
47
- */
48
- wrapLienedAmount: ({ state }, lienedAmount) =>
49
- state.lienMint.wrapLienedAmount(state.address, lienedAmount),
50
-
51
- /**
52
- * @param {MethodContext} context
53
- * @param {Amount<'copyBag'>} attAmount
54
- */
55
- unwrapLienedAmount: ({ state }, attAmount) =>
56
- state.lienMint.unwrapLienedAmount(attAmount),
57
- };
58
-
59
- /**
60
- * @returns {AttestationTool}
61
- */
62
- export const makeAttestationTool = defineKind(
63
- 'AttestationTool',
64
- initState,
65
- behavior,
66
- );
@@ -1,16 +0,0 @@
1
- export const AttKW = /** @type { const } */ ({
2
- /** seat keyword for use in offers to return an attestation. */
3
- Attestation: 'Attestation',
4
- });
5
-
6
- export const ManagerKW = /** @type { const } */ ({
7
- [AttKW.Attestation]: AttKW.Attestation,
8
- Debt: 'Debt',
9
- });
10
-
11
- export const ParamKW = /** @type { const } */ ({
12
- DebtLimit: 'DebtLimit',
13
- MintingRatio: 'MintingRatio',
14
- InterestRate: 'InterestRate',
15
- LoanFee: 'LoanFee',
16
- });
@@ -1,31 +0,0 @@
1
- // @ts-check
2
- // @jessie-check
3
-
4
- import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
5
- import { ParamKW as PKey } from './constants.js';
6
-
7
- export const makeStakeFactoryTerms = (
8
- { timerService, chargingPeriod, recordingPeriod },
9
- {
10
- electorateInvitationAmount,
11
- debtLimit,
12
- mintingRatio,
13
- interestRate,
14
- loanFee,
15
- },
16
- ) => ({
17
- timerService,
18
- chargingPeriod,
19
- recordingPeriod,
20
- governedParams: harden({
21
- [PKey.DebtLimit]: { type: ParamTypes.AMOUNT, value: debtLimit },
22
- [PKey.MintingRatio]: { type: ParamTypes.RATIO, value: mintingRatio },
23
- [PKey.InterestRate]: { type: ParamTypes.RATIO, value: interestRate },
24
- [PKey.LoanFee]: { type: ParamTypes.RATIO, value: loanFee },
25
- [CONTRACT_ELECTORATE]: {
26
- type: ParamTypes.INVITATION,
27
- value: electorateInvitationAmount,
28
- },
29
- }),
30
- });
31
- harden(makeStakeFactoryTerms);