Skip to content

Commit

Permalink
feat: add a method to multipoolAutoSwap to return the pool brands (#2810
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Chris-Hibbert authored Apr 6, 2021
1 parent 95d010c commit 16755d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const start = zcf => {
makeRemoveLiquidityInvitation,
getQuoteIssuer: () => quoteIssuerKit.issuer,
getPriceAuthorities,
getAllPoolBrands: () =>
Object.values(zcf.getTerms().brands).filter(isSecondary),
});

return harden({ publicFacet });
Expand Down
2 changes: 2 additions & 0 deletions packages/zoe/src/contracts/multipoolAutoswap/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* using makeSwapOutInvitation at the current price
* @property {() => Record<string, Amount>} getPoolAllocation get an
* AmountKeywordRecord showing the current balances in the pool.
* @property {() => Array<Brand>} getAllPoolBrands get a list of all the brands
* that have associated pools.
*/

/**
Expand Down
23 changes: 23 additions & 0 deletions packages/zoe/test/unitTests/contracts/test-multipoolAutoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 16755d0

Please sign in to comment.