Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USDC Noble support for Pool Stats, Pool and Balances #850

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "2.14.20",
"version": "2.14.21",
"private": true,
"scripts": {
"bump": "bump patch --tag --commit 'testnet release '",
Expand Down
Binary file added app/public/images/noble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
210 changes: 210 additions & 0 deletions app/public/images/tokens/NOBLE.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 4 additions & 22 deletions app/src/hooks/usePoolStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PoolStatsResponseData {
}

export interface PoolStat {
denom: string;
symbol: string;
priceToken: number;
poolDepth: number;
Expand Down Expand Up @@ -130,8 +131,8 @@ export function usePoolStats() {

poolStatsRes.data.value?.poolData.pools?.forEach((poolStat) => {
const asset =
assetLookup[poolStat.symbol.toLowerCase()] ||
assetLookup[poolStat.symbol];
assetLookup[poolStat.denom.toLowerCase()] ||
assetLookup[poolStat.denom];

if (!asset) {
if (!hasLoggedError[poolStat.symbol]) {
Expand All @@ -151,26 +152,7 @@ export function usePoolStats() {
};
});

// poolStats endpoint might not have data for EVERY pool that exists
// in store.pools. so use store.pools as source of truth for which pools
// exist, then if poolStats doesn't have data default to empty.
const pools = Object.values(store.pools).map((pool) => ({
...pool,
rowanUSD: poolStatsRes.data.value?.rowanUSD || 0,
}));
return pools.map((pool) => {
const [, externalAssetAmount] = pool.amounts;
return (
poolStatLookup[externalAssetAmount.asset.symbol] || {
symbol: externalAssetAmount.asset.symbol,
priceToken: null,
rowanUSD: null,
poolDepth: null,
volume: null,
arb: null,
}
);
});
return poolStatLookup;
});

const wrappedData = computed(() => {
Expand Down
6 changes: 1 addition & 5 deletions app/src/views/PoolPage/PoolPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ export default defineComponent({
return;
}

if (
isAssetFlaggedDisabled(asset) ||
// TODO: remove this once atom pool is enabled
(this.isATOMPoolsDisabled && item.pool.symbol() === "rowan_uatom")
) {
if (isAssetFlaggedDisabled(asset)) {
return false;
}

Expand Down
84 changes: 49 additions & 35 deletions app/src/views/PoolPage/usePoolPageData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,43 +135,57 @@ export const usePoolPageData = () => {
const allPoolsData = computed(() => {
const sifchainChain = useChains().get(Network.SIFCHAIN);

return (statsRes.data?.value?.poolData?.pools || []).map((poolStat) => {
const poolKey = createPoolKey(
sifchainChain.lookupAssetOrThrow("rowan"),
sifchainChain.lookupAssetOrThrow(poolStat.symbol),
);
let accountPool: AccountPool | undefined = undefined;
if (sifAddress.value) {
accountPool = useCore().store.accountpools[sifAddress.value][poolKey];
}

const liquidityProvider =
liquidityProvidersQuery.data.value?.liquidityProviderData.find((x) => {
const tokenRegistryEntry =
tokenRegistryEntriesQuery.data.value?.registry?.entries.find(
(y) => y.denom === x.liquidityProvider?.asset?.symbol,
);

return tokenRegistryEntry?.baseDenom === poolStat.symbol;
});

const pool = useCore().store.pools[poolKey];

const denomOrSymbol =
pool.externalAmount.ibcDenom ?? pool.externalAmount.symbol;

const lppdPoolRewards = lppdRewards?.value?.hasRewards
? lppdRewards.value.rewards.byPool[denomOrSymbol]
: undefined;

if (!statsRes.data.value) {
return {
poolStat,
pool,
accountPool,
liquidityProvider,
lppdRewards: lppdPoolRewards,
poolStat: null,
pool: null,
accountPool: null,
liquidityProvider: null,
lppdRewards: null,
};
});
} else {
const { poolData } = statsRes.data.value;
const pools = poolData.pools as Record<string, PoolStat>;
return Object.entries(pools).map(([key, poolStat]) => {
const poolKey = createPoolKey(
sifchainChain.lookupAssetOrThrow("rowan"),
sifchainChain.lookupAssetOrThrow(poolStat.symbol),
);
let accountPool: AccountPool | undefined = undefined;
if (sifAddress.value) {
accountPool = useCore().store.accountpools[sifAddress.value][poolKey];
}

const liquidityProvider =
liquidityProvidersQuery.data.value?.liquidityProviderData.find(
(x) => {
const tokenRegistryEntry =
tokenRegistryEntriesQuery.data.value?.registry?.entries.find(
(y) => y.denom === x.liquidityProvider?.asset?.symbol,
);

return tokenRegistryEntry?.baseDenom === poolStat.symbol;
},
);

const pool = useCore().store.pools[poolKey];

const denomOrSymbol =
pool.externalAmount.ibcDenom ?? pool.externalAmount.symbol;

const lppdPoolRewards = lppdRewards?.value?.hasRewards
? lppdRewards.value.rewards.byPool[denomOrSymbol]
: undefined;

return {
poolStat,
pool,
accountPool,
liquidityProvider,
lppdRewards: lppdPoolRewards,
};
});
}
});

return {
Expand Down
8 changes: 4 additions & 4 deletions app/src/views/StatsPage/useStatsPageData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { reactive, computed, onMounted, onUnmounted } from "vue";
import { Asset } from "@sifchain/sdk";

import { usePoolStats } from "~/hooks/usePoolStats";
import { PoolStat, usePoolStats } from "~/hooks/usePoolStats";
import { useCore } from "~/hooks/useCore";
import { isAssetFlaggedDisabled } from "~/store/modules/flags";

Expand Down Expand Up @@ -33,9 +33,9 @@ export function useStatsPageData(initialState: StatsPageState) {
const statsRef = computed(() => {
if (!res.data.value) return [];
const { poolData } = res.data.value;

const array = poolData.pools
.map((pool) => {
const pools = poolData.pools as Record<string, PoolStat>;
const array = Object.entries(pools)
.map(([key, pool]) => {
const asset = Asset.get(pool.symbol);
const item = {
asset,
Expand Down
1 change: 1 addition & 0 deletions app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@vue/tsconfig/tsconfig.json",
"compilerOptions": {
"jsx": "react",
"importHelpers": true,
"allowSyntheticDefaultImports": true,
"importsNotUsedAsValues": "remove",
Expand Down
13 changes: 13 additions & 0 deletions core/src/clients/chains/NobleChain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { urlJoin } from "url-join-ts";

import { Chain, IAssetAmount } from "../../entities";
import { BaseChain } from "./_BaseChain";

export class NobleChain extends BaseChain implements Chain {
getBlockExplorerUrlForTxHash(hash: string) {
return urlJoin(this.chainConfig.blockExplorerUrl, "txs", hash);
}
getBlockExplorerUrlForAddress(hash: string) {
return urlJoin(this.chainConfig.blockExplorerUrl, "account", hash);
}
}
5 changes: 4 additions & 1 deletion core/src/clients/chains/_BaseChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class BaseChain implements Chain {
}

findAssetWithLikeSymbol(symbol: string) {
return this.assets.find((asset) => isLikeSymbol(asset.symbol, symbol));
return this.assets.find(
(asset) => asset.symbol.toLowerCase() === symbol.toLowerCase(),
);
// return this.assets.find((asset) => isLikeSymbol(asset.symbol, symbol));
}

findAssetWithLikeSymbolOrThrow(symbol: string) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "../clients/chains";

import { Network } from "..";
import { NobleChain } from "./chains/NobleChain";

export const networkChainCtorLookup = {
[Network.SIFCHAIN]: SifchainChain,
Expand All @@ -40,6 +41,7 @@ export const networkChainCtorLookup = {
[Network.PERSISTENCE]: PersistenceChain,
[Network.REGEN]: RegenChain,
[Network.OSMOSIS]: OsmosisChain,
[Network.NOBLE]: NobleChain,
[Network.TERRA]: TerraChain,
[Network.JUNO]: JunoChain,
[Network.IXO]: IxoChain,
Expand Down
16 changes: 12 additions & 4 deletions core/src/clients/wallets/cosmos/CosmosWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,23 @@ export abstract class CosmosWalletProvider extends WalletProvider<EncodeObject>
// invalid token, ignore
}
}

if (!denomTrace) {
continue; // Ignore, it's an invalid coin from invalid chain
}

const registry = await this.tokenRegistry.load();
const entry = registry.find((e) => {
return e.baseDenom === denomTrace.baseDenom;
});
// TODO - refactor (this logic should be redundant) - special handling for Osmosis USDC.axl
const entry =
denomTrace.baseDenom === "uusdc" &&
coin.denom !==
"ibc/8FCD92E4B97E69EC1A334EADDFF903A6C44408A8C9B03A40B3FBCABE575A8359"
? registry.find((e) => {
return e.baseDenom === "uaxlusdc";
})
: registry.find((e) => {
return e.baseDenom === denomTrace.baseDenom;
});
console.log("entry=", entry);
if (!entry) continue;

try {
Expand Down
2 changes: 2 additions & 0 deletions core/src/config/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import cryptoOrg from "./crypto-org";
import persistence from "./persistence";
import regen from "./regen";
import osmosis from "./osmosis";
import noble from "./noble";
import terra from "./terra";
import juno from "./juno";
import ixo from "./ixo";
Expand Down Expand Up @@ -40,6 +41,7 @@ export const chainConfigByNetworkEnv = Object.fromEntries(
[Network.ETHEREUM]: ethereum[env],
[Network.CRYPTO_ORG]: cryptoOrg[env],
[Network.OSMOSIS]: osmosis[env],
[Network.NOBLE]: noble[env],
[Network.PERSISTENCE]: persistence[env],
[Network.REGEN]: regen[env],
[Network.TERRA]: terra[env],
Expand Down
12 changes: 12 additions & 0 deletions core/src/config/chains/noble/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NetworkEnv } from "../../getEnv";
import { NetEnvChainConfigLookup } from "../NetEnvChainConfigLookup";
import { NOBLE_MAINNET } from "./noble-mainnet";

export default <NetEnvChainConfigLookup>{
[NetworkEnv.LOCALNET]: NOBLE_MAINNET,
[NetworkEnv.DEVNET]: NOBLE_MAINNET,
[NetworkEnv.TESTNET]: NOBLE_MAINNET,
[NetworkEnv.MAINNET]: NOBLE_MAINNET,
[NetworkEnv.TEMPNET]: NOBLE_MAINNET,
[NetworkEnv.STAGING]: NOBLE_MAINNET,
};
58 changes: 58 additions & 0 deletions core/src/config/chains/noble/noble-mainnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Network, IBCChainConfig } from "../../../entities";

export const NOBLE_MAINNET: IBCChainConfig = {
chainType: "ibc",
network: Network.NOBLE,
displayName: "Noble",
blockExplorerUrl: "https://www.mintscan.io/noble",
nativeAssetSymbol: "uusdc",
chainId: "noble-1",
rpcUrl: "https://proxies.sifchain.finance/api/noble-1/rpc",
restUrl: "https://proxies.sifchain.finance/api/noble-1/rest",
features: {
erc20Transfers: false,
},
keplrChainInfo: {
rpc: "https://proxies.sifchain.finance/api/noble-1/rpc",
rest: "https://proxies.sifchain.finance/api/noble-1/rest",
chainId: "noble-1",
chainName: "Noble",
stakeCurrency: {
coinDenom: "USDC (Noble)",
coinMinimalDenom: "uusdc",
coinDecimals: 6,
coinGeckoId: "usdc",
},
walletUrl: "https://wallet.keplr.app/#/noble/stake",
walletUrlForStaking: "https://wallet.keplr.app/#/cosmoshub/stake",
bip44: {
coinType: 118,
},
bech32Config: {
bech32PrefixAccAddr: "noble",
bech32PrefixAccPub: "noblepub",
bech32PrefixValAddr: "noblevaloper",
bech32PrefixValPub: "noblevaloperpub",
bech32PrefixConsAddr: "noblevalcons",
bech32PrefixConsPub: "noblevalconspub",
},
currencies: [
{
coinDenom: "USDC (Noble)",
coinMinimalDenom: "uusdc",
coinDecimals: 6,
coinGeckoId: "usdc",
},
],
feeCurrencies: [
{
coinDenom: "USDC",
coinMinimalDenom: "uusdc",
coinDecimals: 6,
coinGeckoId: "usdc",
},
],
coinType: 118,
features: ["stargate", "ibc-transfer"],
},
};
18 changes: 18 additions & 0 deletions core/src/config/networks/sifchain/assets.sifchain.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,24 @@
"network": "sifchain",
"imageUrl": "https://assets.coingecko.com/coins/images/22363/small/stars.png?1645256657",
"homeNetwork": "stargaze"
},
{
"symbol": "uaxlusdc",
"displaySymbol": "USDC (Axelar)",
"decimals": 6,
"name": "USD Coin (Axelar)",
"network": "sifchain",
"imageUrl": "https://assets.coingecko.com/coins/images/6319/thumb/USD_Coin_icon.png?1547042389",
"homeNetwork": "osmosis"
},
{
"symbol": "uusdc",
"displaySymbol": "USDC (Noble)",
"decimals": 6,
"name": "USD Coin (Noble)",
"network": "sifchain",
"imageUrl": "https://assets.coingecko.com/coins/images/6319/thumb/USD_Coin_icon.png?1547042389",
"homeNetwork": "noble"
}
]
}
1 change: 1 addition & 0 deletions core/src/entities/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum Network {
JUNO = "juno",
LIKECOIN = "likecoin",
OSMOSIS = "osmosis",
NOBLE = "noble",
PERSISTENCE = "persistence",
REGEN = "regen",
SENTINEL = "sentinel",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9846,9 +9846,9 @@ __metadata:
linkType: hard

"caniuse-lite@npm:^1.0.30001286, caniuse-lite@npm:^1.0.30001317, caniuse-lite@npm:^1.0.30001332, caniuse-lite@npm:^1.0.30001335":
version: 1.0.30001481
resolution: "caniuse-lite@npm:1.0.30001481"
checksum: 8200a043c191b4fd4fe0beda37a58fd61869c895ab93f87bdd0420e5927453f48434d716ce9da8552ff6c3ecc4dcd1366354cda3a134f3cc844af741574a7cab
version: 1.0.30001565
resolution: "caniuse-lite@npm:1.0.30001565"
checksum: 7621f358d0e1158557430a111ca5506008ae0b2c796039ef53aeebf4e2ba15e5241cb89def21ea3a633b6a609273085835b44a522165d871fa44067cdf29cccd
languageName: node
linkType: hard

Expand Down
Loading