Skip to content

Commit

Permalink
Merge pull request #115 from ThalaLabs/pool-filter
Browse files Browse the repository at this point in the history
Add pool filter in ThalaswapRouter Option argument. So that user can filter out some pools for the router
  • Loading branch information
SamuelQZQ authored Aug 12, 2024
2 parents 9fe467c + 9e6b60c commit 7961f25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-garlics-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thalalabs/router-sdk": minor
---

Add pool filter in ThalaswapRouter Option argument. So that user can filter out some pools for the router.
6 changes: 6 additions & 0 deletions packages/thalaswap-router/src/ThalaswapRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const scaleUp = (amount: number, decimals: number): number => {

type Options = {
maxAllowedSwapPercentage?: number;
poolFilter?: (pool: Pool) => boolean;
};

class ThalaswapRouter {
Expand Down Expand Up @@ -102,6 +103,11 @@ class ThalaswapRouter {
const graph: Graph = {};

for (const pool of pools) {
// Apply pool filter if provided
if (this.options.poolFilter && !this.options.poolFilter(pool)) {
continue;
}

// Convert pool data to LiquidityPool type
const assets = ["asset0", "asset1", "asset2", "asset3"]
.filter((a) => pool[a as AssetIndex])
Expand Down

0 comments on commit 7961f25

Please sign in to comment.