Skip to content

Commit

Permalink
Merge pull request #130 from ThalaLabs/stable-6
Browse files Browse the repository at this point in the history
Use 6 coins for v2 stable pool
  • Loading branch information
SamuelQZQ authored Oct 31, 2024
2 parents 084757a + e0486c4 commit 7481b11
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-kiwis-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thalalabs/router-sdk": patch
---

Use 6 coins for v2 stable pool
17 changes: 14 additions & 3 deletions packages/thalaswap-router/src/PoolDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ class PoolDataClient {
);

return rawPools.map<Pool>((pool) => {
const [coin0, coin1, coin2, coin3] = pool.assets_metadata.map((o) =>
this.coins.find((c) => c.address === o.inner),
);
const [coin0, coin1, coin2, coin3, coin4, coin5] =
pool.assets_metadata.map((o) =>
this.coins.find((c) => c.address === o.inner),
);
return {
poolType: pool.pool_type === 100 ? "Stable" : "Weighted",
type: pool.pool.inner,
Expand All @@ -233,6 +234,8 @@ class PoolDataClient {
asset1: coin1!,
asset2: coin2,
asset3: coin3,
asset4: coin4,
asset5: coin5,
balance0: scaleDown(pool.balances[0], coin0!.decimals),
balance1: scaleDown(pool.balances[1], coin1!.decimals),
balance2:
Expand All @@ -243,6 +246,14 @@ class PoolDataClient {
pool.balances.length > 3
? scaleDown(pool.balances[3], coin3!.decimals)
: undefined,
balance4:
pool.balances.length > 4
? scaleDown(pool.balances[4], coin4!.decimals)
: undefined,
balance5:
pool.balances.length > 5
? scaleDown(pool.balances[5], coin5!.decimals)
: undefined,
swapFee: Number(pool.swap_fee_bps) / 10000,
isV2: true,
};
Expand Down
18 changes: 16 additions & 2 deletions packages/thalaswap-router/src/ThalaswapRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,25 @@ class ThalaswapRouter {
}

// Convert pool data to LiquidityPool type
const assets = ["asset0", "asset1", "asset2", "asset3"]
const assets = [
"asset0",
"asset1",
"asset2",
"asset3",
"asset4",
"asset5",
]
.filter((a) => pool[a as AssetIndex])
.map((a) => pool[a as AssetIndex]!);

const balances = ["balance0", "balance1", "balance2", "balance3"]
const balances = [
"balance0",
"balance1",
"balance2",
"balance3",
"balance4",
"balance5",
]
.filter((b, i) => assets[i])
.map((b) => pool[b as BalanceIndex] as number);

Expand Down
20 changes: 18 additions & 2 deletions packages/thalaswap-router/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ type Pool = {
asset1: Coin;
asset2?: Coin;
asset3?: Coin;
asset4?: Coin;
asset5?: Coin;
type: string;
poolType: "Weighted" | "Stable";
balance0: number;
balance1: number;
balance2?: number;
balance3?: number;
balance4?: number;
balance5?: number;
weights: number[];
swapFee: number;
amp?: number;
Expand All @@ -66,8 +70,20 @@ type Predecessors = Record<
Record<number, { token: string; pool: LiquidityPool } | null>
>;

type AssetIndex = "asset0" | "asset1" | "asset2" | "asset3";
type BalanceIndex = "balance0" | "balance1" | "balance2" | "balance3";
type AssetIndex =
| "asset0"
| "asset1"
| "asset2"
| "asset3"
| "asset4"
| "asset5";
type BalanceIndex =
| "balance0"
| "balance1"
| "balance2"
| "balance3"
| "balance4"
| "balance5";

export type {
Edge,
Expand Down

0 comments on commit 7481b11

Please sign in to comment.