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

Add a method to multipoolAutoSwap to return the pool brands #2810

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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