Skip to content

Commit

Permalink
chore(addAssetToVault): add AMM pool for interchain asset from bank
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed May 26, 2022
1 parent a7b44b5 commit 611a7d3
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion packages/run-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,44 @@ export const publishInterchainAssetFromBoardId = async (
E(E(agoricNamesAdmin).lookupAdmin('brand')).update(keyword, brand);
};

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 @@ -53,6 +91,15 @@ export const publishInterchainAssetFromBank = async (
installation: {
consume: { mintHolder },
},
instance: {
consume: { amm },
},
issuer: {
consume: { RUN: runIssuer },
},
brand: {
consume: { RUN: runBrandP },
},
},
{ options: { interchainAssetOptions } },
) => {
Expand All @@ -79,9 +126,14 @@ export const publishInterchainAssetFromBank = async (
E(zoe).startInstance(mintHolder, {}, terms),
);

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

await addPool(zoe, amm, issuer, keyword, brand, runBrand, runIssuer);

// Create the mint list if it doesn't exist and wasn't already rejected.
produceBankMints.resolve([]);
await Promise.all([
Expand Down Expand Up @@ -241,6 +293,9 @@ export const getManifestForAddAssetToVault = (
installation: {
consume: { mintHolder: true },
},
instance: { consume: { amm: 'amm' } },
issuer: { consume: { RUN: 'zoe' } },
brand: { consume: { RUN: 'zoe' } },
},
}),
[registerScaledPriceAuthority.name]: {
Expand Down

0 comments on commit 611a7d3

Please sign in to comment.