Skip to content

Commit

Permalink
fix: filter out low liquidity pools
Browse files Browse the repository at this point in the history
  • Loading branch information
marslavish committed Apr 17, 2023
1 parent 0c35f6b commit 80f1323
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 153 deletions.
96 changes: 23 additions & 73 deletions packages/math/__tests__/__snapshots__/apr.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -433,94 +433,44 @@ exports[`Test pool calculations makePoolPairs 1`] = `
"quoteSymbol": "OSMO",
},
{
"baseAddress": "uion",
"baseName": "ion",
"baseSymbol": "ION",
"poolAddress": "osmo1500hy75krs9e8t50aav6fahk8sxhajn9ctp40qwvvn8tcprkk6wszun4a5",
"poolId": "2",
"baseAddress": "ibc/46B44899322F3CD854D2D46DEEF881958467CDD4B3B10086DA49296BBED94BED",
"baseName": "juno",
"baseSymbol": "JUNO",
"poolAddress": "osmo1h7yfu7x4qsv2urnkl4kzydgxegdfyjdry5ee4xzj98jwz0uh07rqdkmprr",
"poolId": "497",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4",
"baseName": "akt",
"baseSymbol": "AKT",
"poolAddress": "osmo1c9gj5nwxhuh2gz7wwg4r8e8tw8v7ggy9lh2hu7kkdgh0t450754qh9cpvd",
"poolId": "3",
"baseAddress": "ibc/BE1BB42D4BE3C30D50B68D7C41DB4DFCE9678E8EF8C539F6E6A9345048894FCC",
"baseName": "ust",
"baseSymbol": "USTC",
"poolAddress": "osmo10d8ddsydag5xrnl2kacmkjtdxddstvz4jvraqqpf6ss2n7fy6lkqw4sx2f",
"poolId": "560",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4",
"baseName": "akt",
"baseSymbol": "AKT",
"poolAddress": "osmo1lzwv0glchfcw0fpwzdwfdsepmvluv6z6eh4qunxdml33sj06q3yq7xwtde",
"poolId": "4",
"quoteAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"quoteName": "atom",
"quoteSymbol": "ATOM",
},
{
"baseAddress": "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
"baseName": "dvpn",
"baseSymbol": "DVPN",
"poolAddress": "osmo1j5l9ysw5xv0uqz9uh7mcg0l5rlerqm695ec9kkg2t8rp600zv47q82eqwa",
"poolId": "5",
"baseAddress": "ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0",
"baseName": "luna",
"baseSymbol": "LUNC",
"poolAddress": "osmo1f7x8t6zv4tdmu2txgztqc9jwfa0kmx2jpgcmah69njaxc6h5gszsp8884g",
"poolId": "561",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1p0rpttlp8v2hy7m82l2t9p6545788f2ac3yksgrlycke2wr4mu0qdr7ytu",
"poolId": "6",
"quoteAddress": "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
"quoteName": "dvpn",
"quoteSymbol": "DVPN",
},
{
"baseAddress": "ibc/7C4D60AA95E5A7558B0A364860979CA34B7FF8AAF255B87AF9E879374470CEC0",
"baseName": "iris",
"baseSymbol": "IRIS",
"poolAddress": "osmo13jr3p5p070h4pu7sxhtldag9899sev9pwx0r2vlvpkyravpxlqssnzsuq9",
"poolId": "7",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1605py4r32r73csszlqpz6n5t5sgax9gjjfnm68jnd7pv6qe4l54ql0w8ku",
"poolId": "8",
"quoteAddress": "ibc/7C4D60AA95E5A7558B0A364860979CA34B7FF8AAF255B87AF9E879374470CEC0",
"quoteName": "iris",
"quoteSymbol": "IRIS",
},
{
"baseAddress": "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1",
"baseName": "cro",
"baseSymbol": "CRO",
"poolAddress": "osmo19fm8jtzyw8ujsnsqm5rznudn8fhhkykjh4ra8rvx9lsfslw2pc2sp36h3r",
"poolId": "9",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1krp38zzc3zz5as9ndqkyskhkzv6x9e30ckcq5g4lcsu5wpwcqy0sa3dea2",
"poolId": "10",
"quoteAddress": "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1",
"quoteName": "cro",
"quoteSymbol": "CRO",
"baseAddress": "ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0",
"baseName": "luna",
"baseSymbol": "LUNC",
"poolAddress": "osmo1yggqusvjqscjy03ysdmjh5hxmt6tv20u5ufrsuy67ksnw2xqsvzql2j70s",
"poolId": "562",
"quoteAddress": "ibc/BE1BB42D4BE3C30D50B68D7C41DB4DFCE9678E8EF8C539F6E6A9345048894FCC",
"quoteName": "ust",
"quoteSymbol": "USTC",
},
]
`;
96 changes: 23 additions & 73 deletions packages/math/__tests__/__snapshots__/pools.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -245,94 +245,44 @@ exports[`Test pool calculations makePoolPairs 1`] = `
"quoteSymbol": "OSMO",
},
{
"baseAddress": "uion",
"baseName": "ion",
"baseSymbol": "ION",
"poolAddress": "osmo1500hy75krs9e8t50aav6fahk8sxhajn9ctp40qwvvn8tcprkk6wszun4a5",
"poolId": "2",
"baseAddress": "ibc/46B44899322F3CD854D2D46DEEF881958467CDD4B3B10086DA49296BBED94BED",
"baseName": "juno",
"baseSymbol": "JUNO",
"poolAddress": "osmo1h7yfu7x4qsv2urnkl4kzydgxegdfyjdry5ee4xzj98jwz0uh07rqdkmprr",
"poolId": "497",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4",
"baseName": "akt",
"baseSymbol": "AKT",
"poolAddress": "osmo1c9gj5nwxhuh2gz7wwg4r8e8tw8v7ggy9lh2hu7kkdgh0t450754qh9cpvd",
"poolId": "3",
"baseAddress": "ibc/BE1BB42D4BE3C30D50B68D7C41DB4DFCE9678E8EF8C539F6E6A9345048894FCC",
"baseName": "ust",
"baseSymbol": "USTC",
"poolAddress": "osmo10d8ddsydag5xrnl2kacmkjtdxddstvz4jvraqqpf6ss2n7fy6lkqw4sx2f",
"poolId": "560",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4",
"baseName": "akt",
"baseSymbol": "AKT",
"poolAddress": "osmo1lzwv0glchfcw0fpwzdwfdsepmvluv6z6eh4qunxdml33sj06q3yq7xwtde",
"poolId": "4",
"quoteAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"quoteName": "atom",
"quoteSymbol": "ATOM",
},
{
"baseAddress": "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
"baseName": "dvpn",
"baseSymbol": "DVPN",
"poolAddress": "osmo1j5l9ysw5xv0uqz9uh7mcg0l5rlerqm695ec9kkg2t8rp600zv47q82eqwa",
"poolId": "5",
"baseAddress": "ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0",
"baseName": "luna",
"baseSymbol": "LUNC",
"poolAddress": "osmo1f7x8t6zv4tdmu2txgztqc9jwfa0kmx2jpgcmah69njaxc6h5gszsp8884g",
"poolId": "561",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1p0rpttlp8v2hy7m82l2t9p6545788f2ac3yksgrlycke2wr4mu0qdr7ytu",
"poolId": "6",
"quoteAddress": "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
"quoteName": "dvpn",
"quoteSymbol": "DVPN",
},
{
"baseAddress": "ibc/7C4D60AA95E5A7558B0A364860979CA34B7FF8AAF255B87AF9E879374470CEC0",
"baseName": "iris",
"baseSymbol": "IRIS",
"poolAddress": "osmo13jr3p5p070h4pu7sxhtldag9899sev9pwx0r2vlvpkyravpxlqssnzsuq9",
"poolId": "7",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1605py4r32r73csszlqpz6n5t5sgax9gjjfnm68jnd7pv6qe4l54ql0w8ku",
"poolId": "8",
"quoteAddress": "ibc/7C4D60AA95E5A7558B0A364860979CA34B7FF8AAF255B87AF9E879374470CEC0",
"quoteName": "iris",
"quoteSymbol": "IRIS",
},
{
"baseAddress": "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1",
"baseName": "cro",
"baseSymbol": "CRO",
"poolAddress": "osmo19fm8jtzyw8ujsnsqm5rznudn8fhhkykjh4ra8rvx9lsfslw2pc2sp36h3r",
"poolId": "9",
"quoteAddress": "uosmo",
"quoteName": "osmo",
"quoteSymbol": "OSMO",
},
{
"baseAddress": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"baseName": "atom",
"baseSymbol": "ATOM",
"poolAddress": "osmo1krp38zzc3zz5as9ndqkyskhkzv6x9e30ckcq5g4lcsu5wpwcqy0sa3dea2",
"poolId": "10",
"quoteAddress": "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1",
"quoteName": "cro",
"quoteSymbol": "CRO",
"baseAddress": "ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0",
"baseName": "luna",
"baseSymbol": "LUNC",
"poolAddress": "osmo1yggqusvjqscjy03ysdmjh5hxmt6tv20u5ufrsuy67ksnw2xqsvzql2j70s",
"poolId": "562",
"quoteAddress": "ibc/BE1BB42D4BE3C30D50B68D7C41DB4DFCE9678E8EF8C539F6E6A9345048894FCC",
"quoteName": "ust",
"quoteSymbol": "USTC",
},
]
`;
16 changes: 13 additions & 3 deletions packages/math/__tests__/pools.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOsmoAssetByDenom } from "../src/utils";
import priceResponse from "../../../__fixtures__/coingecko/api/v3/simple/price/data.json";
import poolResponse from "../../../__fixtures__/rpc/osmosis/gamm/v1beta1/pools/data.json";
import {
Expand All @@ -13,7 +14,6 @@ import {
} from "../src/pool";
import cases from "jest-in-case";
import { noDecimals, convertGeckoPricesToDenomPriceHash } from "../src/utils";
import Long from "long";

const fakeBalances = [
{
Expand Down Expand Up @@ -231,7 +231,17 @@ describe("Test pool calculations", () => {
);

test("makePoolPairs", () => {
const poolPairs = makePoolPairs(pools);
expect(poolPairs.slice(0, 10)).toMatchSnapshot();
const poolsFiltered = pools.filter((pool) =>
pool.poolAssets.every(({ token }) => {
try {
return !!getOsmoAssetByDenom(token.denom);
} catch (error) {
return false;
}
})
);
const LIQUIDITY_LIMIT = 50000000;
const poolPairs = makePoolPairs(poolsFiltered, prices, LIQUIDITY_LIMIT);
expect(poolPairs).toMatchSnapshot();
});
});
9 changes: 7 additions & 2 deletions packages/math/src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,17 @@ export const calcShareOutAmount = (
.sort()[0];
};

export const makePoolPairs = (pools: Pool[]): PrettyPair[] => {
export const makePoolPairs = (
pools: Pool[],
prices: PriceHash,
liquidityLimit = 100_000
): PrettyPair[] => {
return pools
.filter(
(pool) =>
pool.poolAssets.length === 2 &&
pool.poolAssets.every(({ token }) => !token.denom.startsWith("gamm"))
pool.poolAssets.every(({ token }) => !token.denom.startsWith("gamm")) &&
new BigNumber(calcPoolLiquidity(pool, prices)).gte(liquidityLimit)
)
.map((pool) => {
const assetA = pool.poolAssets[0].token;
Expand Down
8 changes: 6 additions & 2 deletions packages/math/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { Asset as OsmosisAsset } from "@chain-registry/types";
import BigNumber from "bignumber.js";

export const getOsmoAssetByDenom = (denom: CoinDenom): OsmosisAsset => {
return osmosisAssets.find((asset) => asset.base === denom) as OsmosisAsset;
const asset = osmosisAssets.find((asset) => asset.base === denom);
if (!asset) {
throw new Error(`Asset not found: ${denom}`);
}
return asset;
};

export const getDenomForCoinGeckoId = (
Expand Down Expand Up @@ -42,7 +46,7 @@ export const symbolToOsmoDenom = (token: CoinSymbol): CoinDenom => {
export const getExponentByDenom = (denom: CoinDenom): Exponent => {
const asset = getOsmoAssetByDenom(denom);
const unit = asset.denom_units.find(({ denom }) => denom === asset.display);
return unit.exponent;
return unit?.exponent || 0;
};

export const convertGeckoPricesToDenomPriceHash = (
Expand Down

0 comments on commit 80f1323

Please sign in to comment.