Skip to content

Commit

Permalink
upgrade swap
Browse files Browse the repository at this point in the history
  • Loading branch information
theothersideofgods committed May 6, 2024
1 parent 1bd2e1b commit 2b704ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
24 changes: 12 additions & 12 deletions packages/math/__tests__/__snapshots__/swap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ exports[`Test pool calculations calcCoinsNeededForValue 10 for pool#1 1`] = `
{
"amount": "136500",
"denom": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"displayAmount": "0.13650013650013650014",
"displayAmount": "0.1365",
"shareTotalValue": "5",
"symbol": "ATOM",
"totalDollarValue": "226964145.58592049",
"unitRatio": "2.202991131966e-8",
"unitRatio": "2.202988928975e-8",
},
{
"amount": "549450",
"denom": "uosmo",
"displayAmount": "0.54945054945054945055",
"displayAmount": "0.54945",
"shareTotalValue": "5",
"symbol": "OSMO",
"totalDollarValue": "219898456.741054",
"unitRatio": "2.273776757737e-8",
"unitRatio": "2.27377448396e-8",
},
]
`;
Expand All @@ -51,20 +51,20 @@ exports[`Test pool calculations calcCoinsNeededForValue 10 for pool#497 1`] = `
{
"amount": "275633",
"denom": "ibc/46B44899322F3CD854D2D46DEEF881958467CDD4B3B10086DA49296BBED94BED",
"displayAmount": "0.27563395810363836825",
"displayAmount": "0.275633",
"shareTotalValue": "5",
"symbol": "JUNO",
"totalDollarValue": "33383106.20983148",
"unitRatio": "1.4977635599792e-7",
"unitRatio": "1.497758353753e-7",
},
{
"amount": "549450",
"denom": "uosmo",
"displayAmount": "0.54945054945054945055",
"displayAmount": "0.54945",
"shareTotalValue": "5",
"symbol": "OSMO",
"totalDollarValue": "32326707.4682188",
"unitRatio": "1.5467087097922e-7",
"unitRatio": "1.5467071630835e-7",
},
]
`;
Expand All @@ -74,20 +74,20 @@ exports[`Test pool calculations calcCoinsNeededForValue 10 for pool#604 1`] = `
{
"amount": "7051808",
"denom": "ibc/987C17B11ABC2B20019178ACE62929FE9840202CE79498E29FE8E5CB02B7C0A4",
"displayAmount": "7.05180822466496859125",
"displayAmount": "7.051808",
"shareTotalValue": "5",
"symbol": "STARS",
"totalDollarValue": "13817947.976249658516",
"unitRatio": "3.6184822873802e-7",
"unitRatio": "3.6184821720982e-7",
},
{
"amount": "549450",
"denom": "uosmo",
"displayAmount": "0.54945054945054945055",
"displayAmount": "0.54945",
"shareTotalValue": "5",
"symbol": "OSMO",
"totalDollarValue": "11087098.9624122",
"unitRatio": "4.5097459822007e-7",
"unitRatio": "4.5097414724547e-7",
},
]
`;
Expand Down
7 changes: 2 additions & 5 deletions packages/math/__tests__/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ import poolResponse from "../../../__fixtures__/rpc/osmosis/gamm/v1beta1/pools/d
import { omit } from "./pool-utils.test";
import BigNumber from "bignumber.js";

const osmosisAssets = [
...(assets.find(({ chain_name }) => chain_name === 'osmosis')?.assets || []),
...(asset_lists.find(({ chain_name }) => chain_name === 'osmosis')?.assets || [])
];
const osmosisAssets = assets.filter(a => a.chain_name === 'osmosis')

describe("Test swap calculations", () => {
let pools, prices;
beforeAll(() => {
pools = poolResponse.pools.map((p) => omit(p, "@type"));
prices = convertGeckoPricesToDenomPriceHash(osmosisAssets, priceResponse);
prices = convertGeckoPricesToDenomPriceHash([...assets, ...asset_lists], priceResponse);
});

cases(
Expand Down
4 changes: 2 additions & 2 deletions packages/math/src/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Asset } from "@chain-registry/types";
import { AssetList } from "@chain-registry/types";
import { BigNumber } from "bignumber.js";
import { CoinDenom, Trade, PrettyPair } from "./types";
import { symbolToOsmoDenom } from "./utils";
Expand Down Expand Up @@ -47,7 +47,7 @@ export const routesThroughPools = ({
};

export const getRoutesForTrade = (
assets: Asset[],
assets: AssetList[],
{
trade,
pairs,
Expand Down

0 comments on commit 2b704ce

Please sign in to comment.