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 (#4476)

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

* Update packages/run-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js

Co-authored-by: Dan Connolly <dckc@madmode.com>

* Update packages/run-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js

Co-authored-by: Dan Connolly <dckc@madmode.com>

* Update packages/run-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js

Co-authored-by: Dan Connolly <dckc@madmode.com>

* review changes

* review changes

Co-authored-by: Dan Connolly <dckc@madmode.com>
  • Loading branch information
b4d2 and dckc authored Feb 14, 2022
1 parent ee44598 commit 4f2d036
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
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

0 comments on commit 4f2d036

Please sign in to comment.