Skip to content

Commit

Permalink
feat(AMM)!: remove the AMM and cleanup bootstrap etc. dependencies
Browse files Browse the repository at this point in the history
The most visible consequence is to vault liquidation. Some pieces are
left hanging, and will be repaired by #7047.
  • Loading branch information
Chris-Hibbert committed Feb 24, 2023
1 parent 4f17b91 commit afd8d53
Show file tree
Hide file tree
Showing 80 changed files with 153 additions and 9,684 deletions.
10 changes: 3 additions & 7 deletions packages/SwingSet/misc-tools/measure-metering/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ async function run() {
const bootFn = new URL('measurement-bootstrap.js', import.meta.url).pathname;
const targetFn = new URL('measurement-target.js', import.meta.url).pathname;
const zoeFn = new URL('measurement-zoe.js', import.meta.url).pathname;
const autoswapFn = new URL(
'../../../inter-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js',
import.meta.url,
).pathname;
const autoswapBundle = await bundleSource(autoswapFn);
const config = {
defaultManagerType: 'xs-worker',
bootstrap: 'bootstrap',
Expand Down Expand Up @@ -139,8 +134,9 @@ async function run() {
const zoeInstallVaultFactory = await doCounted('zoeInstallVaultFactory');
console.log(`zoe install (vaultFactory): ${zoeInstallVaultFactory}`);

const zoeInstallAMM = await doCounted('zoeInstallBundle', [autoswapBundle]);
console.log(`zoe install (AMM): ${zoeInstallAMM}`);
// XXX Does this need to be replace by something else in order to be useful?
// const zoeInstallAMM = await doCounted('zoeInstallBundle', [autoswapBundle]);
// console.log(`zoe install (AMM): ${zoeInstallAMM}`);
const zoeInstantiate = await doCounted('zoeInstantiate');
console.log(`zoe instantiate (AMM): ${zoeInstantiate}`);

Expand Down
1 change: 0 additions & 1 deletion packages/inter-protocol/exported.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './src/stakeFactory/types.js';
import './src/psm/types.js';
import './src/vaultFactory/types.js';
import './src/vpool-xyk-amm/types.js';
2 changes: 0 additions & 2 deletions packages/inter-protocol/scripts/deploy-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const contractRefs = [
'../../governance/bundles/bundle-committee.js',
'../../governance/bundles/bundle-binaryVoteCounter.js',
'../bundles/bundle-stakeFactory.js',
'../bundles/bundle-amm.js',
'../bundles/bundle-vaultFactory.js',
'../bundles/bundle-liquidateMinimum.js',
'../bundles/bundle-reserve.js',
'../bundles/bundle-psm.js',
'../../vats/bundles/bundle-mintHolder.js',
Expand Down
12 changes: 0 additions & 12 deletions packages/inter-protocol/scripts/init-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ const installKeyGroups = {
],
},
main: {
amm: [
'../src/vpool-xyk-amm/multipoolMarketMaker.js',
'../bundles/bundle-amm.js',
],
interchainPool: [
'../src/interchainPool.js',
'../bundles/bundle-interchainPool.js',
Expand All @@ -52,14 +48,6 @@ const installKeyGroups = {
'../src/feeDistributor.js',
'../bundles/bundle-feeDistributor.js',
],
liquidateMinimum: [
'../src/vaultFactory/liquidateMinimum.js',
'../bundles/bundle-liquidateMinimum.js',
],
liquidate: [
'../src/vaultFactory/liquidateIncrementally.js',
'../bundles/bundle-liquidateIncrementally.js',
],
reserve: ['../src/reserve/assetReserve.js', '../bundles/bundle-reserve.js'],
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/collectFees.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { atomicTransfer } from '@agoric/zoe/src/contractSupport';
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';

/**
* Provide shared support for providing access to fees from a service contract.
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/feeDistributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const customTermsShape = harden({
*/

/**
* wrapper to take the vaultFactory or AMM's creatorFacet, and make a call that
* wrapper to take the vaultFactory's creatorFacet, and make a call that
* will request an invitation and return a promise for a payment.
*
* @param {ERef<ZoeService>} zoe
Expand Down
50 changes: 1 addition & 49 deletions packages/inter-protocol/src/interchainPool.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import { E, Far } from '@endo/far';
import { AmountMath, AssetKind, makeIssuerKit } from '@agoric/ertp';
import {
offerTo,
atomicTransfer,
} from '@agoric/zoe/src/contractSupport/index.js';
import { MIN_INITIAL_POOL_LIQUIDITY_KEY } from './vpool-xyk-amm/params.js';

const { Fail, quote: q } = assert;
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';

const COSMOS_DECIMALS = 6;

/**
* Given sufficient IST, create an issuer for an IBC denom
* and an invitation to add a pool for it to the AMM.
*
* @param {ZCF<InterchainPoolTerms>} zcf
* @param {{
* bankManager: ERef<BankManager>,
* }} privateArgs
*
* @typedef {{
* amm: Instance,
* }} InterchainPoolTerms
*
* @typedef {{
Expand All @@ -29,12 +21,6 @@ const COSMOS_DECIMALS = 6;
* }} AssetDetail
*/
export const start = (zcf, { bankManager }) => {
const { amm } = zcf.getTerms();

const zoe = zcf.getZoeService();
/** @type {ERef<GovernedPublicFacet<XYKAMMPublicFacet>>} */
const ammPub = E(zoe).getPublicFacet(amm);

let kwNonce = 0;

/**
Expand All @@ -51,15 +37,9 @@ export const start = (zcf, { bankManager }) => {
assert.typeof(denom, 'string');
assert.typeof(decimalPlaces, 'number');

const minimumCentral = await E(ammPub).getAmount(
MIN_INITIAL_POOL_LIQUIDITY_KEY,
);

const {
give: { Central: centralAmt },
} = seat.getProposal();
AmountMath.isGTE(centralAmt, minimumCentral) ||
Fail`at least ${q(minimumCentral)} required; only ${q(centralAmt)} given`;

const interAsset = makeIssuerKit(
denom,
Expand All @@ -77,35 +57,7 @@ export const start = (zcf, { bankManager }) => {
} = seat2.getProposal();
AmountMath.coerce(interAsset.brand, secondaryAmt);

const liquidityIssuer = await E(ammPub).addIssuer(
interAsset.issuer,
`Interchain${kwNonce}`,
);
await zcf.saveIssuer(liquidityIssuer, `Liquidity${kwNonce}`);

const proposal = harden({
give: {
Central: centralAmt,
Secondary: secondaryAmt,
},
});

atomicTransfer(zcf, seat, seat2, { Central: centralAmt });

const invitation = await E(ammPub).addPoolInvitation();
const { userSeatPromise, deposited } = await offerTo(
zcf,
invitation,
undefined,
proposal,
seat2,
);
return E.when(deposited, _ => {
seat.exit();
seat2.exit();

return E(userSeatPromise).getOfferResult();
});
};

const keyword = denom; // ISSUE #5412: should not show up in all wallets.
Expand Down
61 changes: 4 additions & 57 deletions packages/inter-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,6 @@ export const publishInterchainAssetFromBoardId = async (
]);
};

const addPool = async (
zoe,
amm,
issuer,
keyword,
brand,
runBrand,
runIssuer,
) => {
const ammPub = E(zoe).getPublicFacet(amm);
const [addPoolInvitation] = await Promise.all([
E(ammPub).addPoolInvitation(),
E(ammPub).addIssuer(issuer, keyword),
]);
const proposal = harden({
give: {
Secondary: AmountMath.makeEmpty(brand),
Central: AmountMath.makeEmpty(runBrand),
},
});
const centralPurse = E(runIssuer).makeEmptyPurse();
const secondaryPurse = E(issuer).makeEmptyPurse();
const [emptyCentral, emptySecondary] = await Promise.all([
E(centralPurse).withdraw(proposal.give.Central),
E(secondaryPurse).withdraw(proposal.give.Secondary),
]);
const payments = harden({
Central: emptyCentral,
Secondary: emptySecondary,
});
const addLiquiditySeat = await E(zoe).offer(
addPoolInvitation,
proposal,
payments,
);
await E(addLiquiditySeat).getOfferResult();
};

/**
* @param {EconomyBootstrapPowers} powers
* @param {object} config
Expand All @@ -90,20 +52,11 @@ const addPool = async (
*/
export const publishInterchainAssetFromBank = async (
{
consume: { zoe, bankManager, agoricNamesAdmin, bankMints },
consume: { zoe, bankManager, agoricNamesAdmin, bankMints, reserveKit },
produce: { bankMints: produceBankMints },
installation: {
consume: { mintHolder },
},
instance: {
consume: { amm },
},
issuer: {
consume: { [Stable.symbol]: runIssuer },
},
brand: {
consume: { [Stable.symbol]: stableBrandP },
},
},
{ options: { interchainAssetOptions } },
) => {
Expand All @@ -129,14 +82,10 @@ export const publishInterchainAssetFromBank = async (
E(zoe).startInstance(mintHolder, {}, terms),
);

const [issuer, brand, runBrand] = await Promise.all([
issuerP,
E(issuerP).getBrand(),
stableBrandP,
]);
const [issuer, brand] = await Promise.all([issuerP, E(issuerP).getBrand()]);
const kit = { mint: mintP, issuer, brand };

await addPool(zoe, amm, issuer, keyword, brand, runBrand, runIssuer);
await E(E.get(reserveKit).creatorFacet).addIssuer(issuer, keyword);

// Create the mint list if it doesn't exist and wasn't already rejected.
produceBankMints.resolve([]);
Expand Down Expand Up @@ -318,14 +267,12 @@ export const getManifestForAddAssetToVault = (
bankManager: true,
agoricNamesAdmin: true,
bankMints: true,
reserveKit: true,
},
produce: { bankMints: true },
installation: {
consume: { mintHolder: true },
},
instance: { consume: { amm: 'amm' } },
issuer: { consume: { [Stable.symbol]: 'zoe' } },
brand: { consume: { [Stable.symbol]: 'zoe' } },
},
}),
[registerScaledPriceAuthority.name]: {
Expand Down
9 changes: 3 additions & 6 deletions packages/inter-protocol/src/proposals/committee-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,16 @@ harden(startEconCharter);
* @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
*/
export const addGovernorsToEconCharter = async ({
consume: { reserveKit, ammKit, vaultFactoryKit, econCharterKit },
consume: { reserveKit, vaultFactoryKit, econCharterKit },
instance: {
consume: { amm, reserve, VaultFactory },
consume: { reserve, VaultFactory },
},
}) => {
const { creatorFacet } = E.get(econCharterKit);

// Introduce charter to governed creator facets.
await Promise.all(
[
{ instanceP: amm, facetP: E.get(ammKit).governorCreatorFacet },
{ instanceP: reserve, facetP: E.get(reserveKit).governorCreatorFacet },
{
instanceP: VaultFactory,
Expand Down Expand Up @@ -148,22 +147,20 @@ export const getManifestForInviteCommittee = async (
[addGovernorsToEconCharter.name]: {
consume: {
reserveGovernorCreatorFacet: t,
ammGovernorCreatorFacet: t,
vaultFactoryGovernorCreator: t,
econCharterKit: t,
zoe: t,
agoricNames: t,
namesByAddressAdmin: t,
economicCommitteeCreatorFacet: t,
reserveKit: t,
ammKit: t,
vaultFactoryKit: t,
},
installation: {
consume: { binaryVoteCounter: t },
},
instance: {
consume: { amm: t, reserve: t, VaultFactory: t },
consume: { reserve: t, VaultFactory: t },
},
},
[inviteToEconCharter.name]: {
Expand Down
Loading

0 comments on commit afd8d53

Please sign in to comment.