Skip to content

Commit

Permalink
chore: clean-ups of bootstrap. start to untangle AMM & reserve
Browse files Browse the repository at this point in the history
These changes are a start at untangle the AMM from the reserve in the
bootstrap. They're incomplete, and some tests continue to fail.

We'll find a way to finish untangling cleanly before merge.
  • Loading branch information
Chris-Hibbert committed Feb 23, 2023
1 parent 9807583 commit 526fd19
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 90 deletions.
6 changes: 1 addition & 5 deletions packages/inter-protocol/src/proposals/core-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const SHARED_MAIN_MANIFEST = harden({
priceAuthority: 'priceAuthority',
economicCommitteeCreatorFacet: 'economicCommittee',
reserveKit: 'reserve',
auction: 'auction',
},
produce: { vaultFactoryKit: 'VaultFactory' },
brand: { consume: { [Stable.symbol]: 'zoe' } },
Expand Down Expand Up @@ -72,7 +71,6 @@ const SHARED_MAIN_MANIFEST = harden({

[econBehaviors.setupReserve.name]: {
consume: {
// ammKit: 'amm',
board: 'board',
chainStorage: true,
feeMintAccess: 'zoe',
Expand Down Expand Up @@ -110,8 +108,7 @@ const SHARED_MAIN_MANIFEST = harden({
produce: { auction: 'auction' },
},
installation: {
consume: { auctionInstallation: 'zoe' },
contractGovernor: 'zoe',
consume: { auction: 'zoe', contractGovernor: 'zoe' },
},
issuer: {
consume: { [Stable.symbol]: 'zoe' },
Expand All @@ -126,7 +123,6 @@ const REWARD_MANIFEST = harden({
bankManager: true,
vaultFactoryKit: true,
periodicFeeCollectors: true,
// ammKit: true,
stakeFactoryKit: true,
reserveKit: true,
zoe: true,
Expand Down
17 changes: 9 additions & 8 deletions packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const MILLI = 1_000_000n;
* @property {AdminFacet} psmAdminFacet
*/

/**
* @typedef {object} AuctionKit
* @property {Awaited<ReturnType<import('../auction/auctioneer.js').start>>['creatorFacet']} creatorFacet
* @property {Awaited<ReturnType<import('../auction/auctioneer.js').start>>['publicFacet']} publicFacet
* @property {GovernedContractFacetAccess<{},{}>} governorCreatorFacet
* @property {AdminFacet} adminFacet
*/

/**
* @typedef { WellKnownSpaces & ChainBootstrapSpace & EconomyBootstrapSpace
* } EconomyBootstrapPowers
Expand Down Expand Up @@ -83,12 +91,7 @@ const MILLI = 1_000_000n;
* governorCreatorFacet: GovernedContractFacetAccess<VaultFactoryPublicFacet, VaultFactoryCreatorFacet>,
* adminFacet: AdminFacet,
* },
* auctionKit: {
* publicFacet: AuctioneerPublicFacet,
* creatorFacet: AuctioneerCreatorFacet,
* governorCreatorFacet: GovernedContractFacetAccess<{},{}>,
* adminFacet: AdminFacet,
* }
* auctionKit: AuctionKit,
* minInitialDebt: NatValue,
* }>} EconomyBootstrapSpace
*/
Expand Down Expand Up @@ -523,7 +526,6 @@ export const startRewardDistributor = async ({
bankManager,
vaultFactoryKit,
periodicFeeCollectors,
// ammKit,
stakeFactoryKit,
reserveKit,
zoe,
Expand Down Expand Up @@ -603,7 +605,6 @@ export const startRewardDistributor = async ({

const collectorKit = {
vaultFactory: E.get(vaultFactoryKit).creatorFacet,
// amm: E.get(ammKit).creatorFacet,
runStake: E.get(stakeFactoryKit).creatorFacet,
};
await Promise.all(
Expand Down
1 change: 0 additions & 1 deletion packages/inter-protocol/src/reserve/assetReserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { E, Far } from '@endo/far';
import { AmountMath } from '@agoric/ertp';
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
import { provideDurableMapStore, prepareKindMulti } from '@agoric/vat-data';

import { makeTracer } from '@agoric/internal';
import { handleParamGovernance } from '@agoric/governance';

Expand Down
8 changes: 2 additions & 6 deletions packages/inter-protocol/src/vpool-xyk-amm/addPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const makeAddIssuer = (
/**
* @param {Baggage} baggage
* @param {import('./multipoolMarketMaker.js').AmmPowers} ammPowers
* @param {(secondaryBrand: Brand, reserveLiquidityTokenSeat: ZCFSeat, liquidityKeyword: Keyword) => Promise<void>} onOfferHandled
* @param {() => Promise<void>} onOfferHandled
* @param {ERef<StorageNode>} storageNode
* @param {ERef<Marshaller>} marshaller
*/
Expand Down Expand Up @@ -175,11 +175,7 @@ export const makeAddPoolInvitation = (
seat.exit();
pool.updateState();

await onOfferHandled(
secondaryBrand,
reserveLiquidityTokenSeat,
liquidityKeyword,
);
await onOfferHandled();
return 'Added liquidity.';
};

Expand Down
69 changes: 3 additions & 66 deletions packages/inter-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import '@agoric/zoe/exported.js';
import { AssetKind, makeIssuerKit } from '@agoric/ertp';
import { handleParamGovernance, ParamTypes } from '@agoric/governance';
import { makeAtomicProvider } from '@agoric/store/src/stores/store-utils.js';
import {
assertIssuerKeywords,
offerTo,
} from '@agoric/zoe/src/contractSupport/index.js';
import { assertIssuerKeywords } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';
Expand Down Expand Up @@ -236,60 +233,12 @@ const start = async (zcf, privateArgs, baggage) => {
() => zcf.makeEmptySeatKit().zcfSeat,
);

/** @type {AssetReservePublicFacet | undefined} */
let reserveFacet = baggage.has('reserveFacet')
? baggage.get('reserveFacet')
: undefined;

/**
* @param {Brand<'nat'>} secondaryBrand
* @param {ZCFSeat} reserveLiquidityTokenSeat
* @param {Keyword} liquidityKeyword
* @returns {Promise<void>} up to caller whether to await or handle rejections
*/
const handlePoolAdded = async (
secondaryBrand,
reserveLiquidityTokenSeat,
liquidityKeyword,
) => {
trace('handlePoolAdded', { secondaryBrand, liquidityKeyword });
const handlePoolAdded = async () => {
trace('handlePoolAdded');
updateMetrics();

assert(reserveFacet, 'Missing reserveFacet');
assert(reserveLiquidityTokenSeat, 'Missing reserveLiquidityTokenSeat');

const secondaryIssuer = await zcf.getIssuerForBrand(secondaryBrand);
trace('ensuring reserve has the liquidity issuer', {
secondaryBrand,
secondaryIssuer,
});

// XXX removed when the vaults release sw
// await E(reserveFacet).addLiquidityIssuer(secondaryIssuer);

trace(
`move ${liquidityKeyword} to the reserve`,
reserveLiquidityTokenSeat.getCurrentAllocation(),
);
const addCollateral = await E(reserveFacet).makeAddCollateralInvitation();
const proposal = harden({
give: {
Collateral:
reserveLiquidityTokenSeat.getCurrentAllocation()[liquidityKeyword],
},
});
const { deposited, userSeatPromise } = await offerTo(
zcf,
addCollateral,
harden({ [liquidityKeyword]: 'Collateral' }),
proposal,
reserveLiquidityTokenSeat,
);
const deposits = await deposited;
trace('handlePoolAdded deposited', deposits);
await E(userSeatPromise).getOfferResult();
reserveLiquidityTokenSeat.exit();
trace('handlePoolAdded done');
};

/**
Expand Down Expand Up @@ -473,18 +422,6 @@ const start = async (zcf, privateArgs, baggage) => {
const { governorFacet, limitedCreatorFacet } = makeVirtualGovernorFacet(
harden({
makeCollectFeesInvitation,
/**
* Must be called before adding pools. Not provided at contract start time
* due to cyclic dependency.
*
* @param {MethodContext} _context
* @param {AssetReservePublicFacet} facet
*/
resolveReserveFacet: (_context, facet) => {
assert(!reserveFacet, 'reserveFacet already resolved');
reserveFacet = facet;
baggage.init('reserveFacet', facet);
},
}),
);

Expand Down
1 change: 0 additions & 1 deletion packages/inter-protocol/src/vpool-xyk-amm/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
/**
* @typedef {object} XYKAMMCreatorFacet
* @property {() => Promise<Invitation>} makeCollectFeesInvitation
* @property {(facet: AssetReservePublicFacet) => void} resolveReserveFacet
*/

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/src/contractSupport/atomicTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const { Fail, quote: q } = assert;
- A giving into a `toSeat`'s allocation. See the `toOnly`
helper.
*
* TODO Refactor `atomicRearrange`from being a helper into being
* zcf's replacement for reallocate. Is currently a helper during
* TODO(6679) Refactor `atomicRearrange`from being a helper into being
* zcf's replacement for reallocate. It was made a helper during
* the transition, to avoid interference with progress on Zoe durability.
*
* See the helpers below, `fromOnly`, `toOnly`, and `atomicTransfer`,
* which will remain helpers. These helper are for convenience
* in expressing atomic rearragements clearly.
* in expressing atomic rearrangements clearly.
*
* @param {ZCF} zcf
* @param {TransferPart[]} transfers
Expand Down

0 comments on commit 526fd19

Please sign in to comment.