diff --git a/src/components/common/Containers/CommonContainer.tsx b/src/components/common/Containers/CommonContainer.tsx
index c8064c4..bee6f14 100644
--- a/src/components/common/Containers/CommonContainer.tsx
+++ b/src/components/common/Containers/CommonContainer.tsx
@@ -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
diff --git a/src/components/common/Header/ConnectedButton.tsx b/src/components/common/Header/ConnectedButton.tsx
index 6947ec7..79574d3 100644
--- a/src/components/common/Header/ConnectedButton.tsx
+++ b/src/components/common/Header/ConnectedButton.tsx
@@ -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: [],
diff --git a/src/components/common/TxModal/Action.tsx b/src/components/common/TxModal/Action.tsx
index 9de23a1..c79208a 100644
--- a/src/components/common/TxModal/Action.tsx
+++ b/src/components/common/TxModal/Action.tsx
@@ -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,
diff --git a/src/components/fields/AvailableVaultsTable/AvailableVaultsTableMobile.tsx b/src/components/fields/AvailableVaultsTable/AvailableVaultsTableMobile.tsx
index 8cde6ea..0a1e768 100644
--- a/src/components/fields/AvailableVaultsTable/AvailableVaultsTableMobile.tsx
+++ b/src/components/fields/AvailableVaultsTable/AvailableVaultsTableMobile.tsx
@@ -23,22 +23,23 @@ export const AvailableVaultsTableMobile = () => {
>
{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 (
{
{t('fields.leverage')}
-
+
{t('fields.vaultCap')}
diff --git a/src/functions/redbank/produceUpdatedAssetData.ts b/src/functions/redbank/produceUpdatedAssetData.ts
index e56d43c..1c97d33 100644
--- a/src/functions/redbank/produceUpdatedAssetData.ts
+++ b/src/functions/redbank/produceUpdatedAssetData.ts
@@ -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,
diff --git a/src/hooks/queries/useEstimateFarmFee.tsx b/src/hooks/queries/useEstimateFarmFee.tsx
index b7513c2..3a54a88 100644
--- a/src/hooks/queries/useEstimateFarmFee.tsx
+++ b/src/hooks/queries/useEstimateFarmFee.tsx
@@ -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,
)
diff --git a/src/hooks/queries/useEstimateFee.tsx b/src/hooks/queries/useEstimateFee.tsx
index 371c9ef..5e53295 100644
--- a/src/hooks/queries/useEstimateFee.tsx
+++ b/src/hooks/queries/useEstimateFee.tsx
@@ -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,
)
diff --git a/src/libs/pyth.ts b/src/libs/pyth.ts
index f87bd75..0f06283 100644
--- a/src/libs/pyth.ts
+++ b/src/libs/pyth.ts
@@ -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,
diff --git a/src/store/interfaces/common.interface.ts b/src/store/interfaces/common.interface.ts
index 4b5fec7..cc68a2c 100644
--- a/src/store/interfaces/common.interface.ts
+++ b/src/store/interfaces/common.interface.ts
@@ -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
// ------------------
diff --git a/src/store/slices/common.ts b/src/store/slices/common.ts
index 02c36e1..c60c83e 100644
--- a/src/store/slices/common.ts
+++ b/src/store/slices/common.ts
@@ -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
// -------------------