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 way to filter liquidity pools by participating account #727

Merged
merged 2 commits into from
Nov 16, 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
13 changes: 12 additions & 1 deletion src/liquidity_pool_call_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@ export class LiquidityPoolCallBuilder extends CallBuilder<
return this;
}

/**
* Retrieves all pools an account is participating in.
*
* @param {string} id the participant account to filter by
* @returns {LiquidityPoolCallBuilder} current LiquidityPoolCallBuilder instance
*/
public forAccount(id: string): this {
this.url.setQuery("account", id);
return this;
}

/**
* Retrieves a specific liquidity pool by ID.
*
* @param {string} id
* @param {string} id the hash/ID of the liquidity pool
* @returns {CallBuilder} a new CallBuilder instance for the /liquidity_pools/:id endpoint
*/
public liquidityPoolId(
Expand Down
28 changes: 22 additions & 6 deletions test/unit/liquidity_pool_endpoints_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('/liquidity_pools tests', function() {
.catch(done);
});

describe('filtering by asset', function() {
describe('filters', function() {
const testCases = [
{
assets: [StellarSdk.Asset.native()],
Expand Down Expand Up @@ -141,6 +141,26 @@ describe('/liquidity_pools tests', function() {
});
});

it('filters by account', function(done) {
const accountId = "GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S";
this.axiosMock
.expects('get')
.withArgs(sinon.match(`${LP_URL}?account=${accountId}`))
.returns(Promise.resolve({ data: rootResponse }))

this.server
.liquidityPools()
.forAccount(accountId)
.call()
.then((pools) => {
expect(pools.records).to.deep.equal(rootResponse._embedded.records);
done();
})
.catch(done);
});
});

describe('querying a specific pool', function() {
const lpId = "ae44a51f6191ce24414fbd1326e93ccb0ae656f07fc1e37602b11d0802f74b9a";

it('checks for valid IDs', function() {
Expand All @@ -150,7 +170,7 @@ describe('/liquidity_pools tests', function() {

it('filters by specific ID', function(done) {
const poolResponse = {
"id": "ae44a51f6191ce24414fbd1326e93ccb0ae656f07fc1e37602b11d0802f74b9a",
"id": lpId,
"paging_token": "113725249324879873",
"fee_bp": 30,
"type": "constant_product",
Expand Down Expand Up @@ -183,10 +203,6 @@ describe('/liquidity_pools tests', function() {
})
.catch(done);
});
});

describe('querying a specific pool', function() {
const lpId = "ae44a51f6191ce24414fbd1326e93ccb0ae656f07fc1e37602b11d0802f74b9a";

const poolOpsResponse = {
"_links": {
Expand Down