Skip to content

Commit

Permalink
fix(amm): Prevent creation of constant product AMM with non-fungible …
Browse files Browse the repository at this point in the history
…central token
  • Loading branch information
b4d2 committed Feb 8, 2022
1 parent 2583ce0 commit 4aeb93e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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 '@agoric/eventual-send';
import { makeAddPool } from './pool.js';
import { makeMakeAddLiquidityInvitation } from './addLiquidity.js';
import { makeMakeRemoveLiquidityInvitation } from './removeLiquidity.js';
Expand Down Expand Up @@ -115,6 +116,13 @@ const start = async (zcf, privateArgs) => {
} = /** @type { Terms & AMMTerms } */ (zcf.getTerms());
assertIssuerKeywords(zcf, ['Central']);
assert(centralBrand !== undefined, X`centralBrand must be present`);

const centralDisplayInfo = await E(centralBrand).getDisplayInfo();
assert(
centralDisplayInfo.assetKind === AssetKind.NAT,
X`Central must be of kind AssetKind.NAT`,
);

const { initialPoserInvitation } = privateArgs;

const paramManager = await makeParamManager(
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,21 @@ 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 AssetKind.NAT',
},
'test AssetKind.SET as central brand',
);
});

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

0 comments on commit 4aeb93e

Please sign in to comment.