Remove Pyth for testnet/devnet (#495)

* vaults: multiple bug fixes

* fixed relative import
This commit is contained in:
Bob van der Helm 2023-09-21 12:53:08 +02:00 committed by GitHub
parent 6c193c1a9b
commit 851aeac233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 87 additions and 98 deletions

View File

@ -1,33 +0,0 @@
import { getVaultMetaData } from 'utils/vaults'
import * as constants from 'constants/env'
jest.mock('constants/env', () => ({
__esModule: true,
get IS_TESTNET() {
return true
},
}))
describe('getVaultMetaData()', () => {
afterAll(() => {
jest.restoreAllMocks()
})
it('returns the MAINNET vault of given address WHEN environment configured to mainnet', () => {
jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(false)
const testAddress = 'osmo1g3kmqpp8608szfp0pdag3r6z85npph7wmccat8lgl3mp407kv73qlj7qwp'
const testVaultName = 'OSMO-ATOM'
expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName)
})
it('returns the TESTNET vault of given address WHEN environment configured to testnet', () => {
jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(true)
const testAddress = 'osmo1m45ap4rq4m2mfjkcqu9ks9mxmyx2hvx0cdca9sjmrg46q7lghzqqhxxup5'
const testVaultName = 'OSMO-ATOM'
expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName)
})
})

View File

@ -1,9 +1,9 @@
import getPrice from 'api/prices/getPrice'
import { ENV } from 'constants/env'
import { BN_ONE } from 'constants/math'
import { BNCoin } from 'types/classes/BNCoin'
import { byDenom, byTokenDenom, partition } from 'utils/array'
import { BN } from 'utils/helpers'
import getPrice from 'api/prices/getPrice'
import { BNCoin } from 'types/classes/BNCoin'
import { BN_ONE } from 'constants/math'
interface PoolToken {
denom: string
@ -33,9 +33,8 @@ export default async function getPoolPrice(
}
const getAssetRate = async (asset: Asset) => {
const url = `${ENV.MAINNET_REST_API}osmosis/gamm/v1beta1/pools/${asset.poolId}`
const url = `${ENV.URL_REST}osmosis/gamm/v1beta1/pools/${asset.poolId}`
const response = await fetch(url).then((res) => res.json())
return calculateSpotPrice(response.pool.pool_assets, asset)
}
@ -44,7 +43,9 @@ const calculateSpotPrice = (poolAssets: PoolAsset[], asset: Asset): [BigNumber,
const numerator = BN(assetIn.token.amount).dividedBy(assetIn.weight)
const denominator = BN(assetOut.token.amount).dividedBy(assetOut.weight)
const spotPrice = BN_ONE.dividedBy(numerator.dividedBy(denominator))
const additionalDecimals = asset.decimals - 6
const spotPrice = BN_ONE.dividedBy(numerator.dividedBy(denominator)).shiftedBy(additionalDecimals)
return [spotPrice, assetOut]
}

View File

@ -1,7 +1,9 @@
import getOraclePrices from 'api/prices/getOraclePrices'
import getPoolPrice from 'api/prices/getPoolPrice'
import fetchPythPrices from 'api/prices/getPythPrices'
import { ENV } from 'constants/env'
import { BNCoin } from 'types/classes/BNCoin'
import { NETWORK } from 'types/enums/network'
import { partition } from 'utils/array'
import { getAssetsMustHavePriceInfo } from 'utils/assets'
@ -19,6 +21,7 @@ export default async function getPrices(): Promise<BNCoin[]> {
])
).flat()
const poolPrices = await requestPoolPrices(assetsWithPoolIds, pythAndOraclePrices)
return [...pythAndOraclePrices, ...poolPrices, usdPrice]
} catch (ex) {
console.error(ex)
@ -27,8 +30,9 @@ export default async function getPrices(): Promise<BNCoin[]> {
}
async function requestPythPrices(assets: Asset[]): Promise<BNCoin[]> {
const priceFeedIds = assets.map((a) => a.pythPriceFeedId) as string[]
if (!assets.length) return []
const priceFeedIds = assets.map((a) => a.pythPriceFeedId) as string[]
return await fetchPythPrices(...priceFeedIds).then(mapResponseToBnCoin(assets))
}
@ -44,13 +48,16 @@ const mapResponseToBnCoin = (assets: Asset[]) => (prices: BigNumber[]) =>
)
function separateAssetsByPriceSources(assets: Asset[]) {
// Only fetch Pyth prices for mainnet
const [assetsWithPythPriceFeedId, assetsWithoutPythPriceFeedId] = partition(
assets,
(asset) => !!asset.pythPriceFeedId,
(asset) => !!asset.pythPriceFeedId && ENV.NETWORK === NETWORK.MAINNET,
)
// Don't get oracle price if it's not mainnet and there is a poolId
const [assetsWithOraclePrice, assetsWithoutOraclePrice] = partition(
assetsWithoutPythPriceFeedId,
(asset) => asset.hasOraclePrice,
(asset) => (asset.hasOraclePrice && ENV.NETWORK === NETWORK.MAINNET) || !asset.poolId,
)
const assetsWithPoolId = assetsWithoutOraclePrice.filter((asset) => !!asset.poolId)

View File

@ -1,16 +1,18 @@
import { convertAprToApy } from 'utils/parsers'
import getAprs from 'api/vaults/getVaultAprs'
import { getVaultConfigs } from 'api/vaults/getVaultConfigs'
import { getVaultUtilizations } from 'api/vaults/getVaultUtilizations'
import { ENV } from 'constants/env'
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import { NETWORK } from 'types/enums/network'
import { BN } from 'utils/helpers'
import { convertAprToApy } from 'utils/parsers'
export default async function getVaults(): Promise<Vault[]> {
const vaultConfigs = await getVaultConfigs()
const $vaultUtilizations = getVaultUtilizations(vaultConfigs)
const $aprs = getAprs()
const vaultMetaDatas = ENV.NETWORK === 'testnet' ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const vaultMetaDatas =
ENV.NETWORK === NETWORK.TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const vaults: Vault[] = []
await Promise.all([$vaultUtilizations, $aprs]).then(([vaultUtilizations, aprs]) => {

View File

@ -3,12 +3,13 @@ import { Suspense, useMemo } from 'react'
import Card from 'components/Card'
import { VaultTable } from 'components/Earn/Farm/VaultTable'
import VaultUnlockBanner from 'components/Earn/Farm/VaultUnlockBanner'
import { IS_TESTNET } from 'constants/env'
import { ENV } from 'constants/env'
import { BN_ZERO } from 'constants/math'
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import useAccountId from 'hooks/useAccountId'
import useDepositedVaults from 'hooks/useDepositedVaults'
import useVaults from 'hooks/useVaults'
import { NETWORK } from 'types/enums/network'
import { VaultStatus } from 'types/enums/vault'
interface Props {
@ -21,7 +22,8 @@ function Content(props: Props) {
const { data: depositedVaults } = useDepositedVaults(accountId || '')
const isAvailable = props.type === 'available'
const vaultsMetaData = IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const vaultsMetaData =
ENV.NETWORK === NETWORK.TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const { deposited, available } = useMemo(() => {
return vaultsMetaData.reduce(
@ -70,7 +72,7 @@ function Content(props: Props) {
}
function Fallback() {
const vaults = IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const vaults = ENV.NETWORK === NETWORK.TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const mockVaults: Vault[] = vaults.map((vault) => ({
...vault,
apy: null,

View File

@ -10,11 +10,12 @@ import WalletFetchBalancesAndAccounts from 'components/Wallet/WalletFetchBalance
import WalletSelect from 'components/Wallet/WalletSelect'
import { BRIDGES } from 'constants/bridges'
import { CHAINS } from 'constants/chains'
import { ENV, IS_TESTNET } from 'constants/env'
import { ENV } from 'constants/env'
import useCurrentWallet from 'hooks/useCurrentWallet'
import useToggle from 'hooks/useToggle'
import useWalletBalances from 'hooks/useWalletBalances'
import useStore from 'store'
import { NETWORK } from 'types/enums/network'
import { byDenom } from 'utils/array'
import { getBaseAsset } from 'utils/assets'
import { defaultFee } from 'utils/constants'
@ -87,7 +88,7 @@ export default function WalletBridges() {
<Bridge key={bridge.name} {...bridge} />
))}
</div>
{ENV.NETWORK !== 'mainnet' && (
{ENV.NETWORK !== NETWORK.MAINNET && (
<div className='flex flex-wrap w-full gap-3'>
<Text size='lg' className='mt-4 text-white'>
Need Testnet Funds?
@ -96,7 +97,7 @@ export default function WalletBridges() {
key='osmosis-faucet'
name='Osmosis Testnet Faucet'
url={
IS_TESTNET
ENV.NETWORK === NETWORK.TESTNET
? 'https://faucet.osmotest5.osmosis.zone/'
: 'https://faucet.devnet.osmosis.zone/'
}

View File

@ -19,6 +19,7 @@ import useCurrentWallet from 'hooks/useCurrentWallet'
import useToggle from 'hooks/useToggle'
import useWalletBalances from 'hooks/useWalletBalances'
import useStore from 'store'
import { NETWORK } from 'types/enums/network'
import { ChainInfoID } from 'types/enums/wallet'
import { getBaseAsset, getEnabledMarketAssets } from 'utils/assets'
import { truncate } from 'utils/formatters'
@ -91,7 +92,7 @@ export default function WalletConnectedButton() {
return (
<div className={'relative'}>
{ENV.NETWORK !== 'mainnet' && (
{ENV.NETWORK !== NETWORK.MAINNET && (
<Text
className='absolute -right-2 -top-2.5 z-10 rounded-sm p-0.5 px-2 gradient-primary-to-secondary'
size='3xs'

View File

@ -1,4 +1,6 @@
import { IS_TESTNET } from 'constants/env'
import { ENV } from 'constants/env'
import { NETWORK } from 'types/enums/network'
export const MARS_MAINNET_DENOM =
'ibc/573FCD90FACEE750F55A8864EF7D38265F07E5A9273FA0E8DAFD39951332B580'
@ -24,9 +26,10 @@ export const ASSETS: Asset[] = [
symbol: 'ATOM',
name: 'Atom',
id: 'ATOM',
denom: IS_TESTNET
? 'ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477'
: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
denom:
ENV.NETWORK === NETWORK.TESTNET
? 'ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477'
: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
mainnetDenom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
color: '#6f7390',
logo: '/images/tokens/atom.svg',
@ -48,10 +51,10 @@ export const ASSETS: Asset[] = [
color: '#e50571',
logo: '/images/tokens/statom.svg',
decimals: 6,
hasOraclePrice: !IS_TESTNET,
isEnabled: !IS_TESTNET,
isMarket: !IS_TESTNET,
isDisplayCurrency: !IS_TESTNET,
hasOraclePrice: ENV.NETWORK !== NETWORK.TESTNET,
isEnabled: ENV.NETWORK !== NETWORK.TESTNET,
isMarket: ENV.NETWORK !== NETWORK.TESTNET,
isDisplayCurrency: ENV.NETWORK !== NETWORK.TESTNET,
isAutoLendEnabled: false,
poolId: 803,
},
@ -65,9 +68,9 @@ export const ASSETS: Asset[] = [
logo: '/images/tokens/axlwbtc.svg',
decimals: 8,
hasOraclePrice: true,
isEnabled: !IS_TESTNET,
isMarket: !IS_TESTNET,
isDisplayCurrency: !IS_TESTNET,
isEnabled: ENV.NETWORK !== NETWORK.TESTNET,
isMarket: ENV.NETWORK !== NETWORK.TESTNET,
isDisplayCurrency: ENV.NETWORK !== NETWORK.TESTNET,
isAutoLendEnabled: true,
pythPriceFeedId: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
poolId: 712,
@ -82,9 +85,9 @@ export const ASSETS: Asset[] = [
logo: '/images/tokens/axlweth.svg',
decimals: 18,
hasOraclePrice: true,
isEnabled: !IS_TESTNET,
isMarket: !IS_TESTNET,
isDisplayCurrency: !IS_TESTNET,
isEnabled: ENV.NETWORK !== NETWORK.TESTNET,
isMarket: ENV.NETWORK !== NETWORK.TESTNET,
isDisplayCurrency: ENV.NETWORK !== NETWORK.TESTNET,
isAutoLendEnabled: true,
pythPriceFeedId: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
poolId: 704,
@ -93,9 +96,10 @@ export const ASSETS: Asset[] = [
symbol: 'MARS',
name: 'Mars',
id: 'MARS',
denom: IS_TESTNET
? 'ibc/DB9D326CF53EA07610C394D714D78F8BB4DC7E312D4213193791A9046BF45E20'
: MARS_MAINNET_DENOM,
denom:
ENV.NETWORK === NETWORK.TESTNET
? 'ibc/DB9D326CF53EA07610C394D714D78F8BB4DC7E312D4213193791A9046BF45E20'
: MARS_MAINNET_DENOM,
mainnetDenom: MARS_MAINNET_DENOM,
color: '#a03b45',
logo: '/images/tokens/mars.svg',
@ -110,9 +114,10 @@ export const ASSETS: Asset[] = [
symbol: 'USDC.axl',
name: 'Axelar USDC',
id: 'axlUSDC',
denom: IS_TESTNET
? 'ibc/6F34E1BD664C36CE49ACC28E60D62559A5F96C4F9A6CCE4FC5A67B2852E24CFE'
: 'ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858',
denom:
ENV.NETWORK === NETWORK.TESTNET
? 'ibc/6F34E1BD664C36CE49ACC28E60D62559A5F96C4F9A6CCE4FC5A67B2852E24CFE'
: 'ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858',
mainnetDenom: 'ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858',
color: '#478edc',
logo: '/images/tokens/axlusdc.svg',
@ -136,9 +141,9 @@ export const ASSETS: Asset[] = [
logo: '/images/tokens/axl.svg',
decimals: 6,
hasOraclePrice: true,
isEnabled: !IS_TESTNET,
isMarket: !IS_TESTNET,
isDisplayCurrency: !IS_TESTNET,
isEnabled: ENV.NETWORK !== NETWORK.TESTNET,
isMarket: ENV.NETWORK !== NETWORK.TESTNET,
isDisplayCurrency: ENV.NETWORK !== NETWORK.TESTNET,
isAutoLendEnabled: false,
pythPriceFeedId: '60144b1d5c9e9851732ad1d9760e3485ef80be39b984f6bf60f82b28a2b7f126',
poolId: 812,
@ -162,9 +167,9 @@ export const ASSETS: Asset[] = [
{
symbol: 'OSMO-ATOM',
name: 'OSMO-ATOM LP',
id: IS_TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
denom: IS_TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
mainnetDenom: IS_TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
id: ENV.NETWORK === NETWORK.TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
denom: ENV.NETWORK === NETWORK.TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
mainnetDenom: ENV.NETWORK === NETWORK.TESTNET ? 'gamm/pool/12' : 'gamm/pool/1',
color: '',
logo: '',
decimals: 6,
@ -184,8 +189,8 @@ export const ASSETS: Asset[] = [
decimals: 6,
isEnabled: false,
isMarket: false,
hasOraclePrice: !IS_TESTNET,
forceFetchPrice: !IS_TESTNET,
hasOraclePrice: ENV.NETWORK !== NETWORK.TESTNET,
forceFetchPrice: ENV.NETWORK !== NETWORK.TESTNET,
},
{
symbol: 'OSMO-WETH.axl',
@ -198,8 +203,8 @@ export const ASSETS: Asset[] = [
decimals: 6,
isEnabled: false,
isMarket: false,
hasOraclePrice: !IS_TESTNET,
forceFetchPrice: !IS_TESTNET,
hasOraclePrice: ENV.NETWORK !== NETWORK.TESTNET,
forceFetchPrice: ENV.NETWORK !== NETWORK.TESTNET,
},
{
symbol: 'OSMO-WBTC.axl',
@ -212,8 +217,8 @@ export const ASSETS: Asset[] = [
decimals: 6,
isEnabled: false,
isMarket: false,
hasOraclePrice: !IS_TESTNET,
forceFetchPrice: !IS_TESTNET,
hasOraclePrice: ENV.NETWORK !== NETWORK.TESTNET,
forceFetchPrice: ENV.NETWORK !== NETWORK.TESTNET,
},
{
symbol: 'stATOM-ATOM',
@ -226,7 +231,7 @@ export const ASSETS: Asset[] = [
decimals: 6,
isEnabled: false,
isMarket: false,
hasOraclePrice: !IS_TESTNET,
forceFetchPrice: !IS_TESTNET,
hasOraclePrice: ENV.NETWORK !== NETWORK.TESTNET,
forceFetchPrice: ENV.NETWORK !== NETWORK.TESTNET,
},
]

View File

@ -49,5 +49,3 @@ export const ENV: EnvironmentVariables = {
export const VERCEL_BYPASS = process.env.NEXT_PUBLIC_BYPASS
? `?x-vercel-protection-bypass=${process.env.NEXT_PUBLIC_BYPASS}`
: ''
export const IS_TESTNET = ENV.NETWORK === 'testnet'

View File

@ -1,6 +1,8 @@
import { IS_TESTNET } from 'constants/env'
import { ENV } from 'constants/env'
import { NETWORK } from 'types/enums/network'
export const EXPLORER_NAME = 'Mintscan'
export const EXPLORER_TX_URL = IS_TESTNET
? 'https://testnet.mintscan.io/osmosis-testnet/txs/'
: 'https://www.mintscan.io/osmosis/transactions/'
export const EXPLORER_TX_URL =
ENV.NETWORK === NETWORK.TESTNET
? 'https://testnet.mintscan.io/osmosis-testnet/txs/'
: 'https://www.mintscan.io/osmosis/transactions/'

View File

@ -8,7 +8,6 @@ import usePrices from 'hooks/usePrices'
import { BNCoin } from 'types/classes/BNCoin'
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getLendEnabledAssets } from 'utils/assets'
import { getDenomsFromBNCoins } from 'utils/tokens'
import {
getEnterVaultActions,
getVaultDepositCoinsAndValue,
@ -74,9 +73,7 @@ export default function useDepositVault(props: Props): {
const lendActions: Action[] = useMemo(() => {
if (!isAutoLend) return []
const denoms = Array.from(
new Set(getDenomsFromBNCoins([...props.reclaims, ...props.deposits, ...props.borrowings])),
)
const denoms = [props.vault.denoms.primary, props.vault.denoms.secondary]
const denomsForLend = getLendEnabledAssets()
.filter((asset) => denoms.includes(asset.denom))
.map((asset) => asset.denom)

View File

@ -0,0 +1,5 @@
export enum NETWORK {
MAINNET = 'mainnet',
DEVNET = 'devnet',
TESTNET = 'testnet',
}

View File

@ -1,8 +1,9 @@
import { ASSETS } from 'constants/assets'
import { IS_TESTNET } from 'constants/env'
import { ENV } from 'constants/env'
import { BN_ZERO } from 'constants/math'
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import { BNCoin } from 'types/classes/BNCoin'
import { NETWORK } from 'types/enums/network'
import { Action, Uint128 } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getAssetByDenom } from 'utils/assets'
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
@ -11,11 +12,11 @@ import { getValueFromBNCoins, mergeBNCoinArrays } from 'utils/helpers'
import { getTokenPrice } from 'utils/tokens'
export function getVaultsMetaData() {
return IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
return ENV.NETWORK === NETWORK.TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
}
export function getVaultMetaData(address: string) {
const vaults = IS_TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
const vaults = ENV.NETWORK === NETWORK.TESTNET ? TESTNET_VAULTS_META_DATA : VAULTS_META_DATA
return vaults.find((vault) => vault.address === address)
}