From 9c66e0ee2e82056dc66e12b980927966352af538 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Mon, 5 Apr 2021 11:49:53 -0700 Subject: [PATCH 1/2] feat: add a method to multipoolAutoSwap to return the pool brands --- .../multipoolAutoswap/multipoolAutoswap.js | 11 +++++++++ .../src/contracts/multipoolAutoswap/types.js | 2 ++ .../contracts/test-multipoolAutoswap.js | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js b/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js index c60bcdc403a..859d28ddf0f 100644 --- a/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js +++ b/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js @@ -122,6 +122,16 @@ const start = zcf => { return { amountIn, amountOut }; }; + const getAllPoolBrands = () => { + const brands = []; + const allBrands = zcf.getTerms().brands; + for (const name of Object.getOwnPropertyNames(allBrands)) { + if (isSecondary(allBrands[name])) { + brands.push(allBrands[name]); + } + } + return brands; + }; const { makeSwapInInvitation, makeSwapOutInvitation, @@ -160,6 +170,7 @@ const start = zcf => { makeRemoveLiquidityInvitation, getQuoteIssuer: () => quoteIssuerKit.issuer, getPriceAuthorities, + getAllPoolBrands, }); return harden({ publicFacet }); diff --git a/packages/zoe/src/contracts/multipoolAutoswap/types.js b/packages/zoe/src/contracts/multipoolAutoswap/types.js index 1036b16a2cb..051f76ec0f6 100644 --- a/packages/zoe/src/contracts/multipoolAutoswap/types.js +++ b/packages/zoe/src/contracts/multipoolAutoswap/types.js @@ -23,6 +23,8 @@ * using makeSwapOutInvitation at the current price * @property {() => Record} getPoolAllocation get an * AmountKeywordRecord showing the current balances in the pool. + * @property {() => Array} getAllPoolBrands get a list of all the brands + * that have associated pools. */ /** diff --git a/packages/zoe/test/unitTests/contracts/test-multipoolAutoswap.js b/packages/zoe/test/unitTests/contracts/test-multipoolAutoswap.js index ae67f309f25..ffe42ba0400 100644 --- a/packages/zoe/test/unitTests/contracts/test-multipoolAutoswap.js +++ b/packages/zoe/test/unitTests/contracts/test-multipoolAutoswap.js @@ -530,6 +530,11 @@ test('multipoolAutoSwap with valid offers', async t => { }), `liquidity is empty`, ); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [ + moolaR.brand, + simoleanR.brand, + ]); }); test('multipoolAutoSwap get detailed prices', async t => { @@ -707,6 +712,11 @@ test('multipoolAutoSwap get detailed prices', async t => { { amountIn: simoleans(159), amountOut: moola(36) }, `price is as expected for secondary token to secondary token`, ); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [ + moolaR.brand, + simoleanR.brand, + ]); }); test('multipoolAutoSwap with some invalid offers', async t => { @@ -766,6 +776,8 @@ test('multipoolAutoSwap with some invalid offers', async t => { { message: 'pool not initialized' }, 'pool not initialized', ); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [moolaR.brand]); }); test('multipoolAutoSwap jig - addLiquidity', async t => { @@ -898,6 +910,8 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { { message: 'insufficient Secondary deposited' }, `insufficient secondary is unsuccessful`, ); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [moolaR.brand]); }); test('multipoolAutoSwap jig - check liquidity', async t => { @@ -1031,6 +1045,8 @@ test('multipoolAutoSwap jig - check liquidity', async t => { ); t.is(newMoolaAllocations.Central.value, moolaPoolState.c); t.is(newMoolaAllocations.Secondary.value, moolaPoolState.s); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [moolaR.brand]); }); test('multipoolAutoSwap jig - swapOut', async t => { @@ -1062,10 +1078,12 @@ test('multipoolAutoSwap jig - swapOut', async t => { const { /** @type {MultipoolAutoswapPublicFacet} */ publicFacet, } = startRecord; + t.deepEqual(await E(publicFacet).getAllPoolBrands(), []); const moolaLiquidityIssuer = await E(publicFacet).addPool( moolaR.issuer, 'Moola', ); + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [moolaR.brand]); const moolaLiquidityBrand = await E(moolaLiquidityIssuer).getBrand(); const moolaLiquidity = value => amountMath.make(value, moolaLiquidityBrand); @@ -1236,6 +1254,11 @@ test('multipoolAutoSwap jig - swapOut', async t => { mIssuerKeywordRecord, ); mPoolState = updatePoolState(mPoolState, expectedD); + + t.deepEqual(await E(publicFacet).getAllPoolBrands(), [ + moolaR.brand, + simoleanR.brand, + ]); }); test('multipoolAutoSwap jig - swapOut uneven', async t => { From 31f86f87f4d46721c5b00a05659a64602507ee4a Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 6 Apr 2021 09:42:43 -0700 Subject: [PATCH 2/2] chore: simplify filter --- .../multipoolAutoswap/multipoolAutoswap.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js b/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js index 859d28ddf0f..39c826988f7 100644 --- a/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js +++ b/packages/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js @@ -122,16 +122,6 @@ const start = zcf => { return { amountIn, amountOut }; }; - const getAllPoolBrands = () => { - const brands = []; - const allBrands = zcf.getTerms().brands; - for (const name of Object.getOwnPropertyNames(allBrands)) { - if (isSecondary(allBrands[name])) { - brands.push(allBrands[name]); - } - } - return brands; - }; const { makeSwapInInvitation, makeSwapOutInvitation, @@ -170,7 +160,8 @@ const start = zcf => { makeRemoveLiquidityInvitation, getQuoteIssuer: () => quoteIssuerKit.issuer, getPriceAuthorities, - getAllPoolBrands, + getAllPoolBrands: () => + Object.values(zcf.getTerms().brands).filter(isSecondary), }); return harden({ publicFacet });