mirror of
https://github.com/cerc-io/mars-interface.git
synced 2024-12-22 04:07:44 +00:00
commit
397a1bf49a
@ -66,8 +66,6 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
|
||||
const setLcdClient = useStore((s) => s.setLcdClient)
|
||||
const setChainInfo = useStore((s) => s.setChainInfo)
|
||||
const setUserBalancesState = useStore((s) => s.setUserBalancesState)
|
||||
const setUserWalletAddress = useStore((s) => s.setUserWalletAddress)
|
||||
const pythVaa = useStore((s) => s.pythVaa)
|
||||
|
||||
// ------------------
|
||||
// SETTERS
|
||||
@ -95,8 +93,11 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!connectedWallet || connectedWallet.network.chainId !== chainId) return
|
||||
setUserWalletAddress(connectedWallet.account.address)
|
||||
}, [setUserWalletAddress, connectedWallet, chainId])
|
||||
useStore.setState({
|
||||
userWalletAddress: connectedWallet.account.address,
|
||||
isLedger: connectedWallet.account.isLedger,
|
||||
})
|
||||
}, [connectedWallet, chainId])
|
||||
|
||||
useEffect(() => {
|
||||
if (!rpc || !chainId) return
|
||||
|
@ -73,6 +73,7 @@ export const ConnectedButton = () => {
|
||||
useEffect(() => {
|
||||
if (userWalletAddress === connectedWallet?.account.address) return
|
||||
useStore.setState({
|
||||
isLedger: !!connectedWallet?.account.isLedger,
|
||||
userWalletAddress: connectedWallet?.account.address,
|
||||
marketAssetLiquidity: [],
|
||||
marketInfo: [],
|
||||
|
@ -224,13 +224,7 @@ export const Action = ({
|
||||
const calculateMaxBorrowableAmount = useMemo((): number => {
|
||||
const assetLiquidity = Number(findByDenom(marketAssetLiquidity, denom)?.amount || 0)
|
||||
|
||||
return maxBorrowableAmount(
|
||||
assetLiquidity,
|
||||
availableBalanceBaseCurrency,
|
||||
new BigNumber(currentAssetPrice)
|
||||
.shiftedBy(baseCurrency.decimals - (currentAsset?.decimals || 0))
|
||||
.toNumber(),
|
||||
)
|
||||
return maxBorrowableAmount(assetLiquidity, availableBalanceBaseCurrency, currentAssetPrice)
|
||||
}, [
|
||||
denom,
|
||||
availableBalanceBaseCurrency,
|
||||
|
@ -23,22 +23,23 @@ export const AvailableVaultsTableMobile = () => {
|
||||
>
|
||||
<div className={styles.container}>
|
||||
{availableVaults.map((vault, i) => {
|
||||
const maxLeverage = ltvToLeverage(vault.ltv.contract)
|
||||
const primaryBorrowAsset = redBankAssets.find(
|
||||
(asset) => asset.denom === vault.denoms.primary,
|
||||
)
|
||||
const secondaryBorrowAsset = redBankAssets.find(
|
||||
(asset) => asset.denom === vault.denoms.secondary,
|
||||
)
|
||||
const borrowRate = Math.min(
|
||||
Number(primaryBorrowAsset?.borrowRate || 1000),
|
||||
Number(secondaryBorrowAsset?.borrowRate || 1000),
|
||||
)
|
||||
const maxBorrowRate = borrowRate * (ltvToLeverage(vault.ltv.contract) - 1)
|
||||
const minAPY = new BigNumber(vault.apy.total || 0).toNumber()
|
||||
|
||||
const leverage = ltvToLeverage(vault.ltv.contract)
|
||||
const maxAPY =
|
||||
new BigNumber(minAPY).times(leverage).decimalPlaces(2).toNumber() - maxBorrowRate
|
||||
const borrowRates = [0]
|
||||
if (primaryBorrowAsset?.borrowEnabled) borrowRates.push(primaryBorrowAsset.borrowRate)
|
||||
if (secondaryBorrowAsset?.borrowEnabled) borrowRates.push(secondaryBorrowAsset.borrowRate)
|
||||
|
||||
const borrowRate = Math.min(...borrowRates)
|
||||
|
||||
const maxBorrowRate = borrowRate * (ltvToLeverage(vault.ltv.contract) - 1)
|
||||
const minAPY = vault.apy.total ?? 0
|
||||
const maxAPY = new BigNumber(minAPY).times(maxLeverage).toNumber() - maxBorrowRate
|
||||
|
||||
return (
|
||||
<Link
|
||||
@ -81,7 +82,7 @@ export const AvailableVaultsTableMobile = () => {
|
||||
</div>
|
||||
<div className='s'>
|
||||
<span className='faded'>{t('fields.leverage')} </span>
|
||||
<AnimatedNumber amount={leverage} suffix='x' />
|
||||
<AnimatedNumber amount={maxLeverage} suffix='x' />
|
||||
</div>
|
||||
<div className='s'>
|
||||
<span className='faded'>{t('fields.vaultCap')} </span>
|
||||
|
@ -16,8 +16,7 @@ export const produceUpdatedAssetData = (
|
||||
const asset = redBankAssets.find((redBankAsset) => redBankAsset.denom === denom)
|
||||
if (!asset) return assetData
|
||||
|
||||
const additionalDecimals = asset.decimals - baseCurrencyDecimals
|
||||
const amountAdjustedForDecimals = demagnify(updateAmount, additionalDecimals)
|
||||
const amountAdjustedForDecimals = updateAmount
|
||||
// We are only interested in display currency balance. The asset will update post tx.
|
||||
assetData.push({
|
||||
...asset,
|
||||
|
@ -21,9 +21,11 @@ export const useEstimateFarmFee = (props: Props) => {
|
||||
const networkConfig = useStore((s) => s.networkConfig)
|
||||
const pythVaa = useStore((s) => s.pythVaa)
|
||||
const pythContractAddress = useStore((s) => s.networkConfig.contracts?.pyth)
|
||||
const isLedger = useStore((s) => s.isLedger)
|
||||
const pythVaaMessage = getPythVaaMessage(
|
||||
pythVaa,
|
||||
networkConfig.assets.base.denom,
|
||||
isLedger,
|
||||
pythContractAddress,
|
||||
userWalletAddress,
|
||||
)
|
||||
|
@ -24,9 +24,11 @@ export const useEstimateFee = (props: Props) => {
|
||||
const networkConfig = useStore((s) => s.networkConfig)
|
||||
const baseCurrencyDenom = networkConfig.assets.base.denom
|
||||
const pythContractAddress = networkConfig.contracts?.pyth
|
||||
const isLedger = useStore((s) => s.isLedger)
|
||||
const pythVaaMessage = getPythVaaMessage(
|
||||
pythVaa,
|
||||
baseCurrencyDenom,
|
||||
isLedger,
|
||||
pythContractAddress,
|
||||
userWalletAddress,
|
||||
)
|
||||
|
@ -3,10 +3,11 @@ import { MsgExecuteContract } from '@marsprotocol/wallet-connector'
|
||||
export const getPythVaaMessage = (
|
||||
pythVaa: VaaInformation,
|
||||
baseCurrencyDenom: string,
|
||||
isLedger: boolean,
|
||||
pythContractAddress?: string,
|
||||
sender?: string,
|
||||
): MsgExecuteContract | undefined => {
|
||||
if (!sender || pythVaa.data.length === 0 || !pythContractAddress) return
|
||||
if (!sender || pythVaa.data.length === 0 || !pythContractAddress || isLedger) return
|
||||
|
||||
return new MsgExecuteContract({
|
||||
sender,
|
||||
|
@ -37,6 +37,7 @@ export interface CommonSlice {
|
||||
}
|
||||
latestBlockHeight: number
|
||||
lcdClient?: LcdClient
|
||||
isLedger: boolean
|
||||
marketDeposits: Coin[]
|
||||
networkConfig: NetworkConfig
|
||||
otherAssets: OtherAsset[]
|
||||
@ -81,7 +82,6 @@ export interface CommonSlice {
|
||||
setNetworkError: (isError: boolean) => void
|
||||
setQueryError: (name: string, isError: boolean) => void
|
||||
setServerError: (isError: boolean) => void
|
||||
setUserWalletAddress: (address: string) => void
|
||||
// ------------------
|
||||
// QUERY RELATED
|
||||
// ------------------
|
||||
|
@ -40,6 +40,7 @@ const commonSlice = (
|
||||
query: false,
|
||||
server: false,
|
||||
},
|
||||
isLedger: false,
|
||||
latestBlockHeight: 0,
|
||||
networkConfig: getNetworkConfig(SUPPORTED_CHAINS[0].chainId),
|
||||
marketDeposits: [],
|
||||
@ -116,6 +117,7 @@ const commonSlice = (
|
||||
const pythVaaMessage = getPythVaaMessage(
|
||||
get().pythVaa,
|
||||
baseCurrencyDenom,
|
||||
get().isLedger,
|
||||
pythContractAddress,
|
||||
get().userWalletAddress,
|
||||
)
|
||||
@ -252,7 +254,6 @@ const commonSlice = (
|
||||
tutorialSteps[type] = step ? step : tutorialSteps[type] + 1
|
||||
set({ tutorialSteps })
|
||||
},
|
||||
setUserWalletAddress: (address: string) => set({ userWalletAddress: address }),
|
||||
// -------------------
|
||||
// QUERY RELATED
|
||||
// -------------------
|
||||
|
Loading…
Reference in New Issue
Block a user