Skip to content

Commit

Permalink
rename, fix imports, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Nov 1, 2024
1 parent 514a1e7 commit 0893833
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 340 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Dec } from "@keplr-wallet/unit";
import { Asset } from "@osmosis-labs/types";

import { AssetLists as assetLists } from "../../../__tests__/mock-asset-lists";
import { AllocationResponse } from "../../../sidecar/allocation";
import { calculatePercentAndFiatValues, getAll } from "../allocation";
import { checkAssetVariants } from "../allocation";
import { PortfolioAssetsResponse } from "../../../sidecar";
import { calculatePercentAndFiatValues, getAllocations } from "../assets";
import { checkAssetVariants } from "../assets";

const MOCK_DATA: AllocationResponse = {
const MOCK_DATA: PortfolioAssetsResponse = {
categories: {
"in-locks": {
capitalization: "5.000000000000000000",
Expand Down Expand Up @@ -84,7 +81,7 @@ const MOCK_DATA: AllocationResponse = {
describe("Allocation Functions", () => {
describe("getAll", () => {
it("should calculate the correct allocation percentages and fiat values", () => {
const result = getAll(MOCK_DATA.categories).map((allocation) => ({
const result = getAllocations(MOCK_DATA.categories).map((allocation) => ({
...allocation,
percentage: allocation.percentage.toString(),
fiatValue: allocation.fiatValue.toString(),
Expand Down Expand Up @@ -247,193 +244,27 @@ describe("Allocation Functions", () => {
});
});

const ASSET_OSMO: Asset = {
chainName: "osmosis",
sourceDenom: "uosmo",
coinMinimalDenom: "uosmo",
symbol: "OSMO",
decimals: 6,
logoURIs: {
png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png",
svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.svg",
},
coingeckoId: "osmosis",
price: {
poolId: "1464",
denom:
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
},
categories: ["defi"],
transferMethods: [],
counterparty: [],
variantGroupKey: "uosmo",
name: "Osmosis",
isAlloyed: false,
verified: true,
unstable: false,
disabled: false,
preview: false,
relative_image_url: "/tokens/generated/osmo.svg",
};

const ASSET_SAIL: Asset = {
chainName: "osmosis",
sourceDenom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
coinMinimalDenom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
symbol: "SAIL",
decimals: 6,
logoURIs: {
png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/sail.png",
},
coingeckoId: "sail-dao",
price: {
poolId: "1745",
denom: "uosmo",
},
categories: ["sail_initiative"],
transferMethods: [],
counterparty: [],
variantGroupKey:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
name: "Sail",
isAlloyed: false,
verified: true,
unstable: false,
disabled: false,
preview: false,
listingDate: "2024-03-14T22:20:00.000Z",
relative_image_url: "/tokens/generated/sail.png",
};

const ASSET_ETH_AXL: Asset = {
chainName: "axelar",
sourceDenom: "weth-wei",
coinMinimalDenom:
"ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
symbol: "ETH.axl",
decimals: 18,
logoURIs: {
png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/eth.axl.png",
svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/eth.axl.svg",
},
price: {
poolId: "1431",
denom:
"ibc/2F21E6D4271DE3F561F20A02CD541DAF7405B1E9CB3B9B07E3C2AC7D8A4338A5",
},
categories: [],
transferMethods: [
{
name: "Satellite",
type: "external_interface",
depositUrl:
"https://satellite.money/?source=ethereum&destination=osmosis&asset_denom=weth-wei",
withdrawUrl:
"https://satellite.money/?source=osmosis&destination=ethereum&asset_denom=weth-wei",
},
{
name: "Osmosis IBC Transfer",
type: "ibc",
counterparty: {
chainName: "axelar",
chainId: "axelar-dojo-1",
sourceDenom: "weth-wei",
port: "transfer",
channelId: "channel-3",
},
chain: {
port: "transfer",
channelId: "channel-208",
path: "transfer/channel-208/weth-wei",
},
},
],
counterparty: [
{
chainName: "axelar",
sourceDenom: "weth-wei",
chainType: "cosmos",
chainId: "axelar-dojo-1",
symbol: "WETH",
decimals: 18,
logoURIs: {
png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png",
},
},
{
chainName: "ethereum",
sourceDenom: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
chainType: "evm",
chainId: 1,
address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
symbol: "WETH",
decimals: 18,
logoURIs: {
svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ethereum/images/weth.svg",
},
},
{
chainName: "ethereum",
sourceDenom: "wei",
chainType: "evm",
chainId: 1,
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
symbol: "ETH",
decimals: 18,
logoURIs: {
png: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ethereum/images/eth-white.png",
svg: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ethereum/images/eth-white.svg",
},
},
],
variantGroupKey:
"factory/osmo1k6c8jln7ejuqwtqmay3yvzrg3kueaczl96pk067ldg8u835w0yhsw27twm/alloyed/allETH",
name: "Ethereum (Axelar)",
isAlloyed: false,
verified: true,
unstable: false,
disabled: false,
preview: false,
sortWith: {
chainName: "axelar",
sourceDenom: "uaxl",
},
relative_image_url: "/tokens/generated/eth.axl.svg",
};

describe("Has Asset Variants", () => {
it("should return true when there are asset variants", () => {
const userCoinMinimalDenoms = [
{
denom:
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", // OSMO
amount: new Dec(0.2),
amount: "0.2",
},
{
denom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail", // SAIL
amount: new Dec(0.2),
amount: "0.2",
},
{
denom:
"ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", // ETH.axl <- this is the variant
amount: new Dec(0.2),
amount: "0.2",
},
];
const assetListAssets: Asset[] = [
ASSET_OSMO, // OSMO
ASSET_SAIL, // SAIL
ASSET_ETH_AXL, // <- this is the variant
];

const result = checkAssetVariants(
// @ts-ignore
userCoinMinimalDenoms,
assetListAssets,
assetLists
);
const result = checkAssetVariants(userCoinMinimalDenoms, assetLists);
expect(result.length).toBe(1);
});

Expand All @@ -442,45 +273,23 @@ describe("Has Asset Variants", () => {
{
denom:
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", // OSMO
amount: new Dec(0.2),
amount: "0.2",
},
{
denom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail", // SAIL
amount: new Dec(0.2),
amount: "0.2",
},
];
const assetListAssets: Asset[] = [
ASSET_OSMO, // OSMO
ASSET_SAIL, // SAIL
];

// TODO - update tests
// @ts-ignore
const result = checkAssetVariants(
// @ts-ignore
userCoinMinimalDenoms,
assetListAssets,
assetLists
);
const result = checkAssetVariants(userCoinMinimalDenoms, assetLists);
expect(result.length).toBe(0);
});

it("should return empty array when user has no asset variants", () => {
const userCoinMinimalDenoms: { denom: string; amount: Dec }[] = [];
const assetListAssets: Asset[] = [
ASSET_OSMO, // OSMO
ASSET_SAIL, // SAIL
];
const userCoinMinimalDenoms: { denom: string; amount: string }[] = [];

// TODO - update tests
// @ts-ignore
const result = checkAssetVariants(
// @ts-ignore
userCoinMinimalDenoms,
assetListAssets,
assetLists
);
const result = checkAssetVariants(userCoinMinimalDenoms, assetLists);
expect(result.length).toBe(0);
});
});
Loading

0 comments on commit 0893833

Please sign in to comment.