Mp depostied vaults table (#271)
* added correct resolving of account positions * solve rendering bug for lp amount * bugfix: add slippage to minlpamount * fix DisplayCurrency to accept only BNCoin * bugfix: remove prices from store * add basic depostied vaults table * Farm: Added deposited table * finish deposited table, remove featured vaults:
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getCreditManagerQueryClient } from 'api/cosmwasm-client'
|
||||
import { BNCoin } from 'types/classes/BNCoin'
|
||||
import { Positions } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||
import { resolvePositionResponse } from 'utils/resolvers'
|
||||
|
||||
export default async function getAccount(accountId: string): Promise<Account> {
|
||||
const creditManagerQueryClient = await getCreditManagerQueryClient()
|
||||
@@ -8,17 +9,7 @@ export default async function getAccount(accountId: string): Promise<Account> {
|
||||
const accountPosition: Positions = await creditManagerQueryClient.positions({ accountId })
|
||||
|
||||
if (accountPosition) {
|
||||
const debts = accountPosition.debts.map((debt) => new BNCoin(debt))
|
||||
const lends = accountPosition.lends.map((lend) => new BNCoin(lend))
|
||||
const deposits = accountPosition.deposits.map((deposit) => new BNCoin(deposit))
|
||||
|
||||
return {
|
||||
id: accountPosition.account_id,
|
||||
debts,
|
||||
deposits,
|
||||
lends,
|
||||
vaults: accountPosition.vaults,
|
||||
}
|
||||
return resolvePositionResponse(accountPosition)
|
||||
}
|
||||
|
||||
return new Promise((_, reject) => reject('No account found'))
|
||||
|
||||
@@ -2,8 +2,12 @@ import { getCreditManagerQueryClient } from 'api/cosmwasm-client'
|
||||
import { ENV } from 'constants/env'
|
||||
import { BN } from 'utils/helpers'
|
||||
|
||||
export default async function getVaultConfigs(coins: Coin[], lpDenom: string): Promise<BigNumber> {
|
||||
if (!ENV.ADDRESS_CREDIT_MANAGER) return BN(0)
|
||||
export default async function getVaultConfigs(
|
||||
coins: Coin[],
|
||||
lpDenom: string,
|
||||
slippage: number,
|
||||
): Promise<BigNumber> {
|
||||
if (!ENV.ADDRESS_CREDIT_MANAGER) return BN(Infinity)
|
||||
|
||||
const creditManagerQueryClient = await getCreditManagerQueryClient()
|
||||
try {
|
||||
@@ -13,6 +17,8 @@ export default async function getVaultConfigs(coins: Coin[], lpDenom: string): P
|
||||
lpTokenOut: lpDenom,
|
||||
}),
|
||||
)
|
||||
.times(1 - slippage)
|
||||
.integerValue()
|
||||
} catch (ex) {
|
||||
throw ex
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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 { BN } from 'utils/helpers'
|
||||
|
||||
export default async function getVaults(): Promise<Vault[]> {
|
||||
const vaultConfigs = await getVaultConfigs([])
|
||||
@@ -24,12 +25,12 @@ export default async function getVaults(): Promise<Vault[]> {
|
||||
const vault: Vault = {
|
||||
...vaultMetaData,
|
||||
cap: {
|
||||
max: Number(vaultConfig.deposit_cap.amount),
|
||||
max: BN(vaultConfig.deposit_cap.amount),
|
||||
denom: vaultConfig.deposit_cap.denom,
|
||||
used: Number(
|
||||
used: BN(
|
||||
vaultUtilizations.find(
|
||||
(vaultUtilization) => vaultUtilization.vault.address === vaultConfig.addr,
|
||||
) || 0,
|
||||
)?.utilization.amount || 0,
|
||||
),
|
||||
},
|
||||
apy: apr ? convertAprToApy(apr.apr, 365) : null,
|
||||
|
||||
Reference in New Issue
Block a user