Skip to content

Commit

Permalink
feat(run-protocol): support $MIN_INITIAL_POOL_LIQUIDITY esp 0
Browse files Browse the repository at this point in the history
 - restore support for $INTERCHAIN_DENOM
 - allow passing env explicitly with process.env as a default
 - fix: minInitialPoolLiquidity goes inside options
 - addPool in publishInterchainAssetFromBank in proposals/addAssetToVault.js
  • Loading branch information
dckc committed May 26, 2022
1 parent d37dd78 commit 1507ed6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/run-protocol/scripts/add-collateral-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const defaultProposalBuilder = async (
/** @type {import('../src/proposals/addAssetToVault.js').InterchainAssetOptions} */
const {
issuerBoardId = env.INTERCHAIN_ISSUER_BOARD_ID,
denom,
denom = env.INTERCHAIN_DENOM,
oracleBrand = 'ATOM',
decimalPlaces = 6,
keyword = 'IbcATOM',
Expand Down
13 changes: 9 additions & 4 deletions packages/run-protocol/scripts/init-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,22 @@ export const mainProposalBuilder = async ({
export const defaultProposalBuilder = async (
{ publishRef, install },
options = {},
{ env = process.env } = {},
) => {
/** @param {string|undefined} s */
const optBigInt = s => s && BigInt(s);
const {
ROLE = process.env.ROLE || 'chain',
vaultFactoryControllerAddress = process.env.VAULT_FACTORY_CONTROLLER_ADDR,
ROLE = env.ROLE || 'chain',
vaultFactoryControllerAddress = env.VAULT_FACTORY_CONTROLLER_ADDR,
minInitialPoolLiquidity = env.MIN_INITIAL_POOL_LIQUIDITY,
anchorOptions: {
anchorDenom = process.env.ANCHOR_DENOM,
anchorDenom = env.ANCHOR_DENOM,
anchorDecimalPlaces = '6',
anchorKeyword = 'AUSD',
anchorProposedName = anchorKeyword,
} = {},
econCommitteeOptions: {
committeeSize: econCommitteeSize = process.env.ECON_COMMITTEE_SIZE || '3',
committeeSize: econCommitteeSize = env.ECON_COMMITTEE_SIZE || '3',
} = {},
} = options;

Expand All @@ -180,6 +184,7 @@ export const defaultProposalBuilder = async (
{
ROLE,
vaultFactoryControllerAddress,
minInitialPoolLiquidity: optBigInt(minInitialPoolLiquidity),
anchorOptions,
econCommitteeOptions,
installKeys: {
Expand Down
5 changes: 4 additions & 1 deletion packages/run-protocol/src/proposals/core-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const getManifestForEconCommittee = (

export const getManifestForMain = (
{ restoreRef },
{ installKeys, vaultFactoryControllerAddress },
{ installKeys, vaultFactoryControllerAddress, minInitialPoolLiquidity },
) => {
return {
manifest: SHARED_MAIN_MANIFEST,
Expand All @@ -269,6 +269,7 @@ export const getManifestForMain = (
},
options: {
vaultFactoryControllerAddress,
minInitialPoolLiquidity,
},
};
};
Expand All @@ -289,6 +290,7 @@ export const getManifestForRunProtocol = (
econCommitteeOptions,
installKeys,
vaultFactoryControllerAddress,
minInitialPoolLiquidity,
},
) => {
const econCommitteeManifest = getManifestForEconCommittee(
Expand All @@ -300,6 +302,7 @@ export const getManifestForRunProtocol = (
{
installKeys,
vaultFactoryControllerAddress,
minInitialPoolLiquidity,
},
);
return {
Expand Down
6 changes: 3 additions & 3 deletions packages/run-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ harden(startInterchainPool);

/**
* @param { EconomyBootstrapPowers } powers
* @param {object} opts
* @param {{ options?: { minInitialPoolLiquidity?: bigint }}} opts
*/
export const setupAmm = async (
{
Expand All @@ -183,15 +183,15 @@ export const setupAmm = async (
consume: { contractGovernor: governorInstallation, amm: ammInstallation },
},
},
opts,
{ options = {} } = {},
) => {
const poserInvitationP = E(committeeCreator).getPoserInvitation();
const [poserInvitation, poserInvitationAmount, runBrand] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
runBrandP,
]);
const { minInitialPoolLiquidity = 1_000_000_000n } = opts;
const { minInitialPoolLiquidity = 1_000_000_000n } = options;

const timer = await chainTimerService; // avoid promise for legibility

Expand Down
4 changes: 3 additions & 1 deletion packages/run-protocol/test/amm/vpool-xyk-amm/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export const setupAmmServices = async (
options: { econCommitteeOptions: electorateTerms },
}),
setupAmm(space, {
minInitialPoolLiquidity: 1000n,
options: {
minInitialPoolLiquidity: 1000n,
},
}),
]);

Expand Down
28 changes: 19 additions & 9 deletions packages/run-protocol/test/test-gov-collateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ test.before(async t => {

/**
* @param {import('ava').ExecutionContext<Awaited<ReturnType<makeTestContext>>>} t
* @param {{ env?: Record<string, string|undefined> }} [io]
*/
const makeScenario = async t => {
const makeScenario = async (t, { env = process.env } = {}) => {
const space = await setupBootstrap(t);

const loadVat = name =>
Expand Down Expand Up @@ -273,6 +274,7 @@ const makeScenario = async t => {
undefined,
harden({ decimalPlaces: 6 }),
);
env.MIN_INITIAL_POOL_LIQUIDITY = '0';
await Promise.all([
E(E(space.consume.agoricNamesAdmin).lookupAdmin('oracleBrand')).update(
'ATOM',
Expand All @@ -286,13 +288,12 @@ const makeScenario = async t => {
const atomIssuerPK = makePromiseKit();

const enactVaultAssetProposal = async () => {
const boardId = await atomIssuerPK.promise;
process.env.INTERCHAIN_ISSUER_BOARD_ID = boardId;
env.INTERCHAIN_DENOM = 'ibc/abc123';
await evalProposals([coreProposals.addCollateral]);
};

const enactInviteEconCommitteeProposal = async () => {
process.env.ECON_COMMITTEE_ADDRESSES = JSON.stringify(voterAddresses);
env.ECON_COMMITTEE_ADDRESSES = JSON.stringify(voterAddresses);
await evalProposals([coreProposals.inviteCommittee]);
};

Expand All @@ -318,6 +319,10 @@ const makeScenario = async t => {
} = home;

return harden({
// This isn't used now that we make the pool from a denom
// in publishInterchainAssetFromBank in addAssetToVault.js
// But it should still work. TODO: Perhaps we should test both ways?
// i.e. from a board ID as well?
makePool: async (atomQty = 500n, istQty = 1000n) => {
const istBrand = await E(agoricNames).lookup('brand', 'RUN');
const istAmt = qty => AmountMath.make(istBrand, qty * 1_000_000n);
Expand Down Expand Up @@ -388,8 +393,13 @@ const makeScenario = async t => {
);
};
const makeAtomPurse = async value => {
const { issuer, mint, brand } = await ibcKitP.promise;
// when using benefactor.makePool:
// const { issuer, mint, brand } = await ibcKitP.promise;
const { bankMints } = space.consume;
const mint = E.get(bankMints)[0];
const issuer = E(mint).getIssuer();
const purseP = E(issuer).makeEmptyPurse();
const brand = await E(issuer).getBrand();
const pmt = await E(mint).mintPayment(AmountMath.make(brand, value));
await E(purseP).deposit(pmt);
return purseP;
Expand All @@ -415,7 +425,7 @@ test('Benefactor can add to reserve', async t => {
await s.startDevNet();
await s.provisionMembers();
await s.startRunPreview();
await s.benefactor.makePool(2000n, 1000n);
// await s.benefactor.makePool(2000n, 1000n);
await Promise.all([
s.enactVaultAssetProposal(),
s.enactInviteEconCommitteeProposal(),
Expand All @@ -430,7 +440,7 @@ test('voters get invitations', async t => {
await s.startDevNet();
const purses = await s.provisionMembers();
await s.startRunPreview();
await s.benefactor.makePool();
// await s.benefactor.makePool();
await Promise.all([
s.enactVaultAssetProposal(),
s.enactInviteEconCommitteeProposal(),
Expand Down Expand Up @@ -462,7 +472,7 @@ test('assets are in AMM, Vaults', async t => {
await s.startDevNet();
await s.provisionMembers();
await s.startRunPreview();
await s.benefactor.makePool(2000n, 1000n);
// await s.benefactor.makePool(2000n, 1000n);

await Promise.all([
s.enactVaultAssetProposal(),
Expand Down Expand Up @@ -498,7 +508,7 @@ test('Committee can raise debt limit', async t => {
await s.startDevNet();
const purses = await s.provisionMembers();
await s.startRunPreview();
await s.benefactor.makePool(2000n, 1000n);
// await s.benefactor.makePool(2000n, 1000n);

await Promise.all([
s.enactVaultAssetProposal(),
Expand Down
2 changes: 1 addition & 1 deletion packages/run-protocol/test/vaultFactory/test-liquidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const setupAmmAndElectorate = async (t, aethLiquidity, runLiquidity) => {
options: { econCommitteeOptions: electorateTerms },
});
setupAmm(space, {
minInitialPoolLiquidity: 1000n,
options: { minInitialPoolLiquidity: 1000n },
});

const governorCreatorFacet = consume.ammGovernorCreatorFacet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const setupAmmAndElectorate = async (t, aethLiquidity, runLiquidity) => {
space.installation.produce.amm.resolve(t.context.installation.amm);
await startEconomicCommittee(space, electorateTerms);
await setupAmm(space, {
minInitialPoolLiquidity: 300n,
options: { minInitialPoolLiquidity: 300n },
});

const governorCreatorFacet = consume.ammGovernorCreatorFacet;
Expand Down

0 comments on commit 1507ed6

Please sign in to comment.