Skip to content

Commit

Permalink
Merge branch 'master' into gibson-4558-chainStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Jun 3, 2022
2 parents 3c7c270 + fcfa293 commit c2df386
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/run-protocol/src/vpool-xyk-amm/addPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ export const makeAddPoolInvitation = (
);
}

const {
poolFacets: { pool, helper },
} = await addPool(secondaryBrand);

assert(
AmountMath.isGTE(centralAmount, minPoolLiquidity),
`The minimum initial liquidity is ${minPoolLiquidity}, rejecting ${centralAmount}`,
Expand All @@ -164,6 +160,13 @@ export const makeAddPoolInvitation = (
const [liquidityKeyword] = Object.entries(zcf.getTerms().issuers).find(
([_, i]) => i === issuer,
);
assert(liquidityKeyword, 'liquidity brand required');

// COMMIT POINT /////////////////////

const {
poolFacets: { pool, helper },
} = await addPool(secondaryBrand);

// in addLiquidityInternal, funder provides centralAmount & secondaryAmount,
// and receives liquidity tokens equal to centralAmount. Afterward, we'll
Expand Down
55 changes: 55 additions & 0 deletions packages/run-protocol/test/amm/vpool-xyk-amm/test-liquidity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { E } from '@endo/eventual-send';

import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { assertPayoutAmount } from '@agoric/zoe/test/zoeTestHelpers.js';
import { setup } from '@agoric/zoe/test/unitTests/setupBasicMints.js';
import { setupAmmServices } from './setup.js';
import { unsafeMakeBundleCache } from '../../bundleTool.js';
import { subscriptionTracker } from '../../metrics.js';
Expand Down Expand Up @@ -608,3 +609,57 @@ test('amm remove zero liquidity', async t => {
`No liquidity removed`,
);
});

test('amm bad add liquidity offer', async t => {
const centralLiquidityValue = 1_500_000_000n;
const secondaryLiquidityValue = 300_000_000n;

const { moolaR, simoleanR, bucksR, moola, bucks } = setup();

const electorateTerms = { committeeName: 'EnBancPanel', committeeSize: 3 };
// This timer is only used to build quotes. Let's make it non-zero
const timer = buildManualTimer(console.log, 30n);

const { zoe, amm } = await setupAmmServices(
t,
electorateTerms,
simoleanR,
timer,
);

await E(amm.ammPublicFacet).addIssuer(bucksR.issuer, 'Bucks');

const liquidityIssuer = await E(amm.ammPublicFacet).addIssuer(
moolaR.issuer,
'Moola',
);
const liquidityBrand = await E(liquidityIssuer).getBrand();
const addPoolInvitation = await E(amm.ammPublicFacet).addPoolInvitation();

const fundPoolProposal = harden({
give: {
Secondary: moola(secondaryLiquidityValue),
Central: bucks(centralLiquidityValue),
},
want: { Liquidity: AmountMath.make(liquidityBrand, 1000n) },
});
const payments = {
Secondary: moolaR.mint.mintPayment(moola(secondaryLiquidityValue)),
Central: bucksR.mint.mintPayment(bucks(centralLiquidityValue)),
};

const addLiquiditySeat = await E(zoe).offer(
addPoolInvitation,
fundPoolProposal,
payments,
);
await t.throwsAsync(async () => E(addLiquiditySeat).getOfferResult(), {
message:
'Brands in left "[Alleged: bucks brand]" and right "[Alleged: simoleans brand]" should match but do not',
});

await t.throwsAsync(
async () => E(amm.ammPublicFacet).getPoolMetrics(moolaR.brand),
{ message: '"secondaryBrand" not found: "[Alleged: moola brand]"' },
);
});

0 comments on commit c2df386

Please sign in to comment.