Skip to content

Commit

Permalink
Add a way to filter liquidity pools by participating account (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Nov 16, 2021
1 parent 71213a7 commit 3b3ea64
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
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

0 comments on commit 3b3ea64

Please sign in to comment.