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