fix: replaced apollo vault APR api with true APR api (#511)

This commit is contained in:
Linkie Link 2023-09-28 09:11:45 +02:00 committed by GitHub
parent 5bbb59d5dc
commit f20ae553d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 64 deletions

View File

@ -4,7 +4,7 @@ NEXT_PUBLIC_RPC=https://rpc.devnet.osmosis.zone/
NEXT_PUBLIC_GQL=https://devnet-osmosis-gql.marsprotocol.io/graphql
NEXT_PUBLIC_REST=https://lcd.devnet.osmosis.zone/
NEXT_PUBLIC_SWAP=https://testnet.osmosis.zone
NEXT_PUBLIC_APOLLO_APR=https://api.apollo.farm/api/vault_infos/v2/osmosis-1
NEXT_PUBLIC_VAULT_APR=https://api.marsprotocol.io/v1/vaults/osmosis
NEXT_PUBLIC_ACCOUNT_NFT=osmo1pdr8mvj2ky9hzj5pjp026apfmd0pacd3xrzx3mzazy7lulnsdrkq96gzk3
NEXT_PUBLIC_ORACLE=osmo156elt2tp5455q9a6vfrvnpncxyd33cxm9z2lgguwg6dgws9tedps5tq3rc
NEXT_PUBLIC_RED_BANK=osmo1vxpdcw092n9rngvekve8g324c2yjx56496ck98ag4sdxr4p4zd4q0wr7x6
@ -30,7 +30,7 @@ CHARTING_LIBRARY_USERNAME=mars-git-demo
# NEXT_PUBLIC_GQL=https://testnet-osmosis-node.marsprotocol.io/XF32UOOU55CX/osmosis-hive-front/graphql
# NEXT_PUBLIC_REST=https://testnet-osmosis-node.marsprotocol.io/XF32UOOU55CX/osmosis-lcd-front/
# NEXT_PUBLIC_SWAP=https://testnet.osmosis.zone
# NEXT_PUBLIC_APOLLO_APR=https://api.apollo.farm/api/vault_infos/v2/osmo-test-5
# NEXT_PUBLIC_VAULT_APR=https://testnet-api.marsprotocol.io/v1/vaults/osmosis
# NEXT_PUBLIC_ACCOUNT_NFT=osmo1hdk6nps2l2tdfgly0tegcgwl239l45etuae7nsc6s93u0yrqk4rqv489kl
# NEXT_PUBLIC_ORACLE=osmo1dxu93scjdnx42txdp9d4hm3snffvnzmkp4jpc9sml8xlu3ncgamsl2lx58
# NEXT_PUBLIC_RED_BANK=osmo1hs4sm0fah9rk4mz8e56v4n76g0q9fffdkkjm3f8tjagkdx78pqcq75pk0a
@ -55,7 +55,7 @@ CHARTING_LIBRARY_USERNAME=mars-git-demo
# NEXT_PUBLIC_GQL=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-hive-front/graphql
# NEXT_PUBLIC_REST=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/
# NEXT_PUBLIC_SWAP=https://app.osmosis.zone
# NEXT_PUBLIC_APOLLO_APR=https://api.apollo.farm/api/vault_infos/v2/osmosis-1
# NEXT_PUBLIC_VAULT_APR=https://api.marsprotocol.io/v1/vaults/osmosis
# NEXT_PUBLIC_ACCOUNT_NFT=osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09
# NEXT_PUBLIC_ORACLE=osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g
# NEXT_PUBLIC_RED_BANK=osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg

View File

@ -2,28 +2,15 @@ import { ENV } from 'constants/env'
export default async function getAprs() {
try {
const response = await fetch(ENV.URL_APOLLO_APR)
const response = await fetch(ENV.URL_VAULT_APR)
if (response.ok) {
const data: FlatApr[] | NestedApr[] = await response.json()
const data: AprResponse = await response.json()
const newAprs = data.map((aprData) => {
try {
const apr = aprData as FlatApr
const aprTotal = apr.apr.reduce((prev, curr) => Number(curr.value) + prev, 0)
const feeTotal = apr.fees.reduce((prev, curr) => Number(curr.value) + prev, 0)
const newAprs = data.vaults.map((aprData) => {
const finalApr = aprData.apr.projected_apr * 100
const finalApr = aprTotal + feeTotal
return { address: aprData.contract_address, apr: finalApr }
} catch {
const apr = aprData as NestedApr
const aprTotal = apr.apr.aprs.reduce((prev, curr) => Number(curr.value) + prev, 0)
const feeTotal = apr.apr.fees.reduce((prev, curr) => Number(curr.value) + prev, 0)
const finalApr = aprTotal + feeTotal
return { address: aprData.contract_address, apr: finalApr }
}
return { address: aprData.address, apr: finalApr }
})
return newAprs
@ -34,17 +21,3 @@ export default async function getAprs() {
return []
}
}
interface FlatApr {
contract_address: string
apr: { type: string; value: number | string }[]
fees: { type: string; value: number | string }[]
}
interface NestedApr {
contract_address: string
apr: {
aprs: { type: string; value: number | string }[]
fees: { type: string; value: number | string }[]
}
}

View File

@ -123,7 +123,7 @@ export const VaultTable = (props: Props) => {
if (vault.apy === null) return <Loading />
return (
<FormattedNumber
amount={(vault.apy ?? 0) * 100}
amount={vault.apy ?? 0}
options={{ minDecimals: 2, maxDecimals: 2, suffix: '%' }}
className='text-xs'
animate

View File

@ -31,30 +31,22 @@ export default function VaultModalContentHeader({ vault }: Props) {
return (
<div className='flex gap-6 px-6 py-4 border-b border-white/5 gradient-header'>
{vault.apy && (
<>
<TitleAndSubCell
title={
<div className='flex flex-row'>
<FormattedNumber
amount={vault.apy}
options={{ suffix: '%', decimals: -2 }}
animate
/>
<FormattedNumber
className='ml-2 text-xs'
amount={vault.apy / 365}
options={{ suffix: '%/day', decimals: -2 }}
parentheses
animate
/>
</div>
}
sub={'Deposit APY'}
/>
<div className='h-100 w-[1px] bg-white/10'></div>
</>
)}
<TitleAndSubCell
title={
<div className='flex flex-row'>
<FormattedNumber amount={vault?.apy ?? 0} options={{ suffix: '%' }} animate />
<FormattedNumber
className='ml-2 text-xs'
amount={vault?.apy ?? 0 / 365}
options={{ suffix: '%/day' }}
parentheses
animate
/>
</div>
}
sub={'Deposit APY'}
/>
<div className='h-100 w-[1px] bg-white/10'></div>
{!depositedValue.isZero() && (
<>
<TitleAndSubCell

View File

@ -14,7 +14,7 @@ interface EnvironmentVariables {
URL_REST: string
URL_RPC: string
URL_API: string
URL_APOLLO_APR: string
URL_VAULT_APR: string
WALLETS: string[]
PYTH_ENDPOINT: string
MAINNET_REST_API: string
@ -39,7 +39,7 @@ export const ENV: EnvironmentVariables = {
URL_API: process.env.NEXT_PUBLIC_VERCEL_URL
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}/api`
: process.env.NEXT_PUBLIC_API || '',
URL_APOLLO_APR: process.env.NEXT_PUBLIC_APOLLO_APR || '',
URL_VAULT_APR: process.env.NEXT_PUBLIC_VAULT_APR || '',
WALLETS: process.env.NEXT_PUBLIC_WALLETS?.split(',') || [],
PYTH_ENDPOINT: process.env.NEXT_PUBLIC_PYTH_ENDPOINT || '',
MAINNET_REST_API: process.env.NEXT_PUBLIC_MAINNET_REST || '',

View File

@ -89,3 +89,24 @@ interface ProvideLiquidityAction {
minimum_receive: import('../generated/mars-credit-manager/MarsCreditManager.types').Uint128
}
}
interface AprResponse {
vaults: AprVault[]
}
interface AprVault {
chain: string
address: string
apr: AprBreakdown
}
interface AprBreakdown {
start_timestamp: number
end_timestamp: number
period_diff: number
start_vault_token_price: number
end_vault_token_price: number
period_yield: number
period_daily_return: number
projected_apr: number
}

View File

@ -30,8 +30,8 @@ if (!process.env.NEXT_PUBLIC_GQL) {
if (!process.env.NEXT_PUBLIC_REST) {
throw 'NEXT_PUBLIC_REST is not defined'
}
if (!process.env.NEXT_PUBLIC_APOLLO_APR) {
throw 'NEXT_PUBLIC_APOLLO_APR is not defined'
if (!process.env.NEXT_PUBLIC_VAULT_APR) {
throw 'NEXT_PUBLIC_VAULT_APR is not defined'
}
if (!process.env.NEXT_PUBLIC_PARAMS) {
throw 'NEXT_PUBLIC_PARAMS is not defined'