Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amm): Prevent creation of constant product AMM with non-fungible central token #4476

Merged
merged 8 commits into from
Feb 14, 2022
27 changes: 20 additions & 7 deletions packages/run-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AssetKind, makeIssuerKit } from '@agoric/ertp';
import { CONTRACT_ELECTORATE, handleParamGovernance } from '@agoric/governance';

import { assertIssuerKeywords } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import { makeAddPool } from './pool.js';
import { makeMakeAddLiquidityInvitation } from './addLiquidity.js';
import { makeMakeRemoveLiquidityInvitation } from './removeLiquidity.js';
Expand All @@ -17,8 +18,7 @@ import { makeMakeSwapInvitation } from './swap.js';
import { makeDoublePool } from './doublePool.js';
import { makeParamManager, POOL_FEE_KEY, PROTOCOL_FEE_KEY } from './params.js';

const { details: X } = assert;

const { quote: q, details: X } = assert;
/**
* Multipool AMM is a rewrite of Uniswap that supports multiple liquidity pools,
* and direct exchanges across pools. Please see the documentation for more:
Expand Down Expand Up @@ -115,14 +115,27 @@ const start = async (zcf, privateArgs) => {
} = /** @type { Terms & AMMTerms } */ (zcf.getTerms());
assertIssuerKeywords(zcf, ['Central']);
assert(centralBrand !== undefined, X`centralBrand must be present`);

const { initialPoserInvitation } = privateArgs;

const paramManager = await makeParamManager(
zcf.getZoeService(),
poolFeeParam.value,
protocolFeeParam.value,
initialPoserInvitation,
const [paramManager, centralDisplayInfo] = await Promise.all([
makeParamManager(
zcf.getZoeService(),
poolFeeParam.value,
protocolFeeParam.value,
initialPoserInvitation,
),
E(centralBrand).getDisplayInfo(),
]);

assert.equal(
centralDisplayInfo.assetKind,
AssetKind.NAT,
X`Central must be of kind ${q(AssetKind.NAT)}, not ${q(
centralDisplayInfo.assetKind,
)}`,
);

const { wrapPublicFacet, wrapCreatorFacet, getNat, getInvitationAmount } =
handleParamGovernance(zcf, paramManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { makeIssuerKit, AmountMath } from '@agoric/ertp';
import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp';
import { E } from '@agoric/eventual-send';

import {
Expand All @@ -29,6 +29,23 @@ import { setupAmmServices } from './setup.js';
const { quote: q } = assert;
const { ceilDivide } = natSafeMath;

test('amm with non-fungible central token', async t => {
// Set up central token
const centralR = makeIssuerKit('central', AssetKind.SET);
const electorateTerms = { committeeName: 'EnBancPanel', committeeSize: 3 };
const timer = buildManualTimer(console.log, 30n);

await t.throwsAsync(
() => setupAmmServices(electorateTerms, centralR, timer),
{
message: `Central must be of kind ${q(AssetKind.NAT)}, not ${q(
AssetKind.SET,
)}`,
},
'test AssetKind.SET as central brand',
);
});

test('amm with valid offers', async t => {
// Set up central token
const centralR = makeIssuerKit('central');
Expand Down