feat: replaced all possible BN(0) & BN(1) occurrences with constants (#320)
This commit is contained in:
parent
e09c2f9d53
commit
d4a2f19db2
@ -2,6 +2,7 @@ import { render } from '@testing-library/react'
|
|||||||
|
|
||||||
import Modal from 'components/Modal'
|
import Modal from 'components/Modal'
|
||||||
import UnlockModal from 'components/Modals/Unlock'
|
import UnlockModal from 'components/Modals/Unlock'
|
||||||
|
import { BN_ONE, BN_ZERO } from 'constants/math'
|
||||||
import { TESTNET_VAULTS_META_DATA } from 'constants/vaults'
|
import { TESTNET_VAULTS_META_DATA } from 'constants/vaults'
|
||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
@ -18,20 +19,20 @@ const mockedDepositedVault: DepositedVault = {
|
|||||||
liq: 0.7,
|
liq: 0.7,
|
||||||
},
|
},
|
||||||
amounts: {
|
amounts: {
|
||||||
primary: BN(1),
|
primary: BN_ONE,
|
||||||
secondary: BN(1),
|
secondary: BN_ONE,
|
||||||
locked: BN(1),
|
locked: BN_ONE,
|
||||||
unlocked: BN(1),
|
unlocked: BN_ONE,
|
||||||
unlocking: BN(1),
|
unlocking: BN_ONE,
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
primary: BN(0),
|
primary: BN_ZERO,
|
||||||
secondary: BN(0),
|
secondary: BN_ZERO,
|
||||||
},
|
},
|
||||||
cap: {
|
cap: {
|
||||||
denom: 'mock',
|
denom: 'mock',
|
||||||
max: BN(10),
|
max: BN(10),
|
||||||
used: BN(1),
|
used: BN_ONE,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { byDenom, byTokenDenom, partition } from 'utils/array'
|
|||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
import getPrice from 'api/prices/getPrice'
|
import getPrice from 'api/prices/getPrice'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
|
import { BN_ONE } from 'constants/math'
|
||||||
|
|
||||||
interface PoolToken {
|
interface PoolToken {
|
||||||
denom: string
|
denom: string
|
||||||
@ -43,7 +44,7 @@ const calculateSpotPrice = (poolAssets: PoolAsset[], asset: Asset): [BigNumber,
|
|||||||
|
|
||||||
const numerator = BN(assetIn.token.amount).dividedBy(assetIn.weight)
|
const numerator = BN(assetIn.token.amount).dividedBy(assetIn.weight)
|
||||||
const denominator = BN(assetOut.token.amount).dividedBy(assetOut.weight)
|
const denominator = BN(assetOut.token.amount).dividedBy(assetOut.weight)
|
||||||
const spotPrice = BN(1).dividedBy(numerator.dividedBy(denominator))
|
const spotPrice = BN_ONE.dividedBy(numerator.dividedBy(denominator))
|
||||||
|
|
||||||
return [spotPrice, assetOut]
|
return [spotPrice, assetOut]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { getSwapperQueryClient } from 'api/cosmwasm-client'
|
import { getSwapperQueryClient } from 'api/cosmwasm-client'
|
||||||
import { ZERO } from 'constants/math'
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
export default async function estimateExactIn(coinIn: Coin, denomOut: string) {
|
export default async function estimateExactIn(coinIn: Coin, denomOut: string) {
|
||||||
@ -9,6 +9,6 @@ export default async function estimateExactIn(coinIn: Coin, denomOut: string) {
|
|||||||
|
|
||||||
return BN(estimatedAmount)
|
return BN(estimatedAmount)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return ZERO
|
return BN_ZERO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
VaultPositionAmount,
|
VaultPositionAmount,
|
||||||
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
async function getUnlocksAtTimestamp(unlockingId: number, vaultAddress: string) {
|
async function getUnlocksAtTimestamp(unlockingId: number, vaultAddress: string) {
|
||||||
try {
|
try {
|
||||||
@ -49,9 +50,9 @@ function flatVaultPositionAmount(
|
|||||||
vaultPositionAmount: VaultPositionAmount,
|
vaultPositionAmount: VaultPositionAmount,
|
||||||
): VaultPositionFlatAmounts {
|
): VaultPositionFlatAmounts {
|
||||||
const amounts = {
|
const amounts = {
|
||||||
locked: BN(0),
|
locked: BN_ZERO,
|
||||||
unlocking: BN(0),
|
unlocking: BN_ZERO,
|
||||||
unlocked: BN(0),
|
unlocked: BN_ZERO,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('locking' in vaultPositionAmount) {
|
if ('locking' in vaultPositionAmount) {
|
||||||
|
@ -5,6 +5,7 @@ import DisplayCurrency from 'components/DisplayCurrency'
|
|||||||
import { FormattedNumber } from 'components/FormattedNumber'
|
import { FormattedNumber } from 'components/FormattedNumber'
|
||||||
import { ArrowRight } from 'components/Icons'
|
import { ArrowRight } from 'components/Icons'
|
||||||
import Text from 'components/Text'
|
import Text from 'components/Text'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
import usePrices from 'hooks/usePrices'
|
import usePrices from 'hooks/usePrices'
|
||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
@ -15,7 +16,6 @@ import {
|
|||||||
calculateAccountDeposits,
|
calculateAccountDeposits,
|
||||||
calculateAccountPnL,
|
calculateAccountPnL,
|
||||||
} from 'utils/accounts'
|
} from 'utils/accounts'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
account: Account
|
account: Account
|
||||||
@ -34,15 +34,15 @@ interface ItemProps {
|
|||||||
export default function AccountComposition(props: Props) {
|
export default function AccountComposition(props: Props) {
|
||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
const balance = calculateAccountDeposits(props.account, prices)
|
const balance = calculateAccountDeposits(props.account, prices)
|
||||||
const balanceChange = props.change ? calculateAccountDeposits(props.change, prices) : BN(0)
|
const balanceChange = props.change ? calculateAccountDeposits(props.change, prices) : BN_ZERO
|
||||||
const debtBalance = calculateAccountDebt(props.account, prices)
|
const debtBalance = calculateAccountDebt(props.account, prices)
|
||||||
const debtBalanceChange = props.change ? calculateAccountDebt(props.change, prices) : BN(0)
|
const debtBalanceChange = props.change ? calculateAccountDebt(props.change, prices) : BN_ZERO
|
||||||
const pnL = calculateAccountPnL(props.account, prices)
|
const pnL = calculateAccountPnL(props.account, prices)
|
||||||
const pnLChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0)
|
const pnLChange = props.change ? calculateAccountPnL(props.change, prices) : BN_ZERO
|
||||||
const apr = calculateAccountApr(props.account, prices)
|
const apr = calculateAccountApr(props.account, prices)
|
||||||
const aprChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0)
|
const aprChange = props.change ? calculateAccountPnL(props.change, prices) : BN_ZERO
|
||||||
const borrowRate = calculateAccountBorrowRate(props.account, prices)
|
const borrowRate = calculateAccountBorrowRate(props.account, prices)
|
||||||
const borrowRateChange = props.change ? calculateAccountPnL(props.change, prices) : BN(0)
|
const borrowRateChange = props.change ? calculateAccountPnL(props.change, prices) : BN_ZERO
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full flex-wrap p-4'>
|
<div className='w-full flex-wrap p-4'>
|
||||||
|
@ -12,10 +12,10 @@ import Text from 'components/Text'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { calculateAccountDeposits } from 'utils/accounts'
|
import { calculateAccountDeposits } from 'utils/accounts'
|
||||||
import { hardcodedFee } from 'utils/constants'
|
import { hardcodedFee } from 'utils/constants'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import { getPage, getRoute } from 'utils/route'
|
import { getPage, getRoute } from 'utils/route'
|
||||||
import usePrices from 'hooks/usePrices'
|
import usePrices from 'hooks/usePrices'
|
||||||
import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
|
import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
setShowFundAccount: (showFundAccount: boolean) => void
|
setShowFundAccount: (showFundAccount: boolean) => void
|
||||||
@ -39,7 +39,7 @@ export default function AccountList(props: Props) {
|
|||||||
const selectedAccountDetails = props.accounts.find((account) => account.id === accountId)
|
const selectedAccountDetails = props.accounts.find((account) => account.id === accountId)
|
||||||
const selectedAccountBalance = selectedAccountDetails
|
const selectedAccountBalance = selectedAccountDetails
|
||||||
? calculateAccountDeposits(selectedAccountDetails, prices)
|
? calculateAccountDeposits(selectedAccountDetails, prices)
|
||||||
: BN(0)
|
: BN_ZERO
|
||||||
|
|
||||||
async function deleteAccountHandler() {
|
async function deleteAccountHandler() {
|
||||||
if (!accountSelected) return
|
if (!accountSelected) return
|
||||||
|
@ -6,12 +6,12 @@ import Card from 'components/Card'
|
|||||||
import DisplayCurrency from 'components/DisplayCurrency'
|
import DisplayCurrency from 'components/DisplayCurrency'
|
||||||
import { ArrowChartLineUp } from 'components/Icons'
|
import { ArrowChartLineUp } from 'components/Icons'
|
||||||
import Text from 'components/Text'
|
import Text from 'components/Text'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
import useIsOpenArray from 'hooks/useIsOpenArray'
|
import useIsOpenArray from 'hooks/useIsOpenArray'
|
||||||
import usePrices from 'hooks/usePrices'
|
import usePrices from 'hooks/usePrices'
|
||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { calculateAccountDeposits } from 'utils/accounts'
|
import { calculateAccountDeposits } from 'utils/accounts'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
account?: Account
|
account?: Account
|
||||||
@ -22,7 +22,7 @@ export default function AccountSummary(props: Props) {
|
|||||||
const [isOpen, toggleOpen] = useIsOpenArray(2, true)
|
const [isOpen, toggleOpen] = useIsOpenArray(2, true)
|
||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
const baseCurrency = useStore((s) => s.baseCurrency)
|
const baseCurrency = useStore((s) => s.baseCurrency)
|
||||||
const accountBalance = props.account ? calculateAccountDeposits(props.account, prices) : BN(0)
|
const accountBalance = props.account ? calculateAccountDeposits(props.account, prices) : BN_ZERO
|
||||||
if (!props.account) return null
|
if (!props.account) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -12,8 +12,8 @@ import useToggle from 'hooks/useToggle'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { getAmount } from 'utils/accounts'
|
import { getAmount } from 'utils/accounts'
|
||||||
import { hardcodedFee } from 'utils/constants'
|
import { hardcodedFee } from 'utils/constants'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
|
import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
setShowFundAccount: (show: boolean) => void
|
setShowFundAccount: (show: boolean) => void
|
||||||
@ -25,7 +25,7 @@ export default function FundAccount(props: Props) {
|
|||||||
const deposit = useStore((s) => s.deposit)
|
const deposit = useStore((s) => s.deposit)
|
||||||
const balances = useStore((s) => s.balances)
|
const balances = useStore((s) => s.balances)
|
||||||
|
|
||||||
const [amount, setAmount] = useState(BN(0))
|
const [amount, setAmount] = useState(BN_ZERO)
|
||||||
const [asset, setAsset] = useState<Asset>(ASSETS[0])
|
const [asset, setAsset] = useState<Asset>(ASSETS[0])
|
||||||
const { autoLendEnabledAccountIds, toggleAutoLend } = useAutoLendEnabledAccountIds()
|
const { autoLendEnabledAccountIds, toggleAutoLend } = useAutoLendEnabledAccountIds()
|
||||||
const [isFunding, setIsFunding] = useToggle()
|
const [isFunding, setIsFunding] = useToggle()
|
||||||
|
@ -15,11 +15,11 @@ import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
|
|||||||
import { REDUCE_MOTION_KEY } from 'constants/localStore'
|
import { REDUCE_MOTION_KEY } from 'constants/localStore'
|
||||||
import useLocalStorage from 'hooks/useLocalStorage'
|
import useLocalStorage from 'hooks/useLocalStorage'
|
||||||
import { formatValue } from 'utils/formatters'
|
import { formatValue } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
export const RiskChart = ({ data }: RiskChartProps) => {
|
export const RiskChart = ({ data }: RiskChartProps) => {
|
||||||
const [reduceMotion] = useLocalStorage<boolean>(REDUCE_MOTION_KEY, DEFAULT_SETTINGS.reduceMotion)
|
const [reduceMotion] = useLocalStorage<boolean>(REDUCE_MOTION_KEY, DEFAULT_SETTINGS.reduceMotion)
|
||||||
const currentRisk = BN(0)
|
const currentRisk = BN_ZERO
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex w-full flex-wrap overflow-hidden py-2'>
|
<div className='flex w-full flex-wrap overflow-hidden py-2'>
|
||||||
|
@ -12,7 +12,7 @@ import MarketAssetTableRow from 'components/MarketAssetTable/MarketAssetTableRow
|
|||||||
import MarketDetails from 'components/MarketAssetTable/MarketDetails'
|
import MarketDetails from 'components/MarketAssetTable/MarketDetails'
|
||||||
import TitleAndSubCell from 'components/TitleAndSubCell'
|
import TitleAndSubCell from 'components/TitleAndSubCell'
|
||||||
import { getEnabledMarketAssets } from 'utils/assets'
|
import { getEnabledMarketAssets } from 'utils/assets'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string
|
title: string
|
||||||
@ -72,7 +72,7 @@ export default function BorrowTable(props: Props) {
|
|||||||
|
|
||||||
if (!asset) return null
|
if (!asset) return null
|
||||||
|
|
||||||
return <AmountAndValue asset={asset} amount={borrowAsset?.debt ?? BN(0)} />
|
return <AmountAndValue asset={asset} amount={borrowAsset?.debt ?? BN_ZERO} />
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -108,7 +108,7 @@ export default function BorrowTable(props: Props) {
|
|||||||
return <Loading />
|
return <Loading />
|
||||||
}
|
}
|
||||||
|
|
||||||
return <AmountAndValue asset={asset} amount={liquidity.amount ?? BN(0)} />
|
return <AmountAndValue asset={asset} amount={liquidity.amount ?? BN_ZERO} />
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
|||||||
import useDepositedVaults from 'hooks/useDepositedVaults'
|
import useDepositedVaults from 'hooks/useDepositedVaults'
|
||||||
import useVaults from 'hooks/useVaults'
|
import useVaults from 'hooks/useVaults'
|
||||||
import { VaultStatus } from 'types/enums/vault'
|
import { VaultStatus } from 'types/enums/vault'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
type: 'available' | 'deposited'
|
type: 'available' | 'deposited'
|
||||||
@ -79,8 +79,8 @@ function Fallback() {
|
|||||||
},
|
},
|
||||||
cap: {
|
cap: {
|
||||||
denom: 'denom',
|
denom: 'denom',
|
||||||
used: BN(0),
|
used: BN_ZERO,
|
||||||
max: BN(0),
|
max: BN_ZERO,
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import Text from 'components/Text'
|
|||||||
import TokenInputWithSlider from 'components/TokenInputWithSlider'
|
import TokenInputWithSlider from 'components/TokenInputWithSlider'
|
||||||
import { byDenom } from 'utils/array'
|
import { byDenom } from 'utils/array'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
asset: Asset
|
asset: Asset
|
||||||
@ -38,7 +39,7 @@ export default function AssetAmountSelectActionModal(props: Props) {
|
|||||||
onChange,
|
onChange,
|
||||||
onAction,
|
onAction,
|
||||||
} = props
|
} = props
|
||||||
const [amount, setAmount] = useState(BN(0))
|
const [amount, setAmount] = useState(BN_ZERO)
|
||||||
const maxAmount = BN(coinBalances.find(byDenom(asset.denom))?.amount ?? 0)
|
const maxAmount = BN(coinBalances.find(byDenom(asset.denom))?.amount ?? 0)
|
||||||
|
|
||||||
const handleAmountChange = useCallback(
|
const handleAmountChange = useCallback(
|
||||||
|
@ -21,6 +21,7 @@ import { formatPercent, formatValue } from 'utils/formatters'
|
|||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
import useHealthComputer from 'hooks/useHealthComputer'
|
import useHealthComputer from 'hooks/useHealthComputer'
|
||||||
import { BorrowTarget } from 'types/enums/borrowTarget'
|
import { BorrowTarget } from 'types/enums/borrowTarget'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
function getDebtAmount(modal: BorrowModal | null) {
|
function getDebtAmount(modal: BorrowModal | null) {
|
||||||
return BN((modal?.marketData as BorrowMarketTableData)?.debt ?? 0).toString()
|
return BN((modal?.marketData as BorrowMarketTableData)?.debt ?? 0).toString()
|
||||||
@ -44,7 +45,7 @@ export default function BorrowModalController() {
|
|||||||
|
|
||||||
function BorrowModal(props: Props) {
|
function BorrowModal(props: Props) {
|
||||||
const [percentage, setPercentage] = useState(0)
|
const [percentage, setPercentage] = useState(0)
|
||||||
const [amount, setAmount] = useState(BN(0))
|
const [amount, setAmount] = useState(BN_ZERO)
|
||||||
const [change, setChange] = useState<AccountChange | undefined>()
|
const [change, setChange] = useState<AccountChange | undefined>()
|
||||||
const [isConfirming, setIsConfirming] = useToggle()
|
const [isConfirming, setIsConfirming] = useToggle()
|
||||||
const [borrowToWallet, setBorrowToWallet] = useToggle()
|
const [borrowToWallet, setBorrowToWallet] = useToggle()
|
||||||
@ -53,12 +54,12 @@ function BorrowModal(props: Props) {
|
|||||||
const repay = useStore((s) => s.repay)
|
const repay = useStore((s) => s.repay)
|
||||||
const asset = modal?.asset ?? ASSETS[0]
|
const asset = modal?.asset ?? ASSETS[0]
|
||||||
const isRepay = modal?.isRepay ?? false
|
const isRepay = modal?.isRepay ?? false
|
||||||
const [max, setMax] = useState(BN(0))
|
const [max, setMax] = useState(BN_ZERO)
|
||||||
|
|
||||||
const { computeMaxBorrowAmount } = useHealthComputer(props.account)
|
const { computeMaxBorrowAmount } = useHealthComputer(props.account)
|
||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
setAmount(BN(0))
|
setAmount(BN_ZERO)
|
||||||
setPercentage(0)
|
setPercentage(0)
|
||||||
setIsConfirming(false)
|
setIsConfirming(false)
|
||||||
}
|
}
|
||||||
@ -125,13 +126,13 @@ function BorrowModal(props: Props) {
|
|||||||
setChange({
|
setChange({
|
||||||
deposits: [
|
deposits: [
|
||||||
{
|
{
|
||||||
amount: isRepay ? BN(0).minus(amount).toString() : BN(0).plus(amount).toString(),
|
amount: isRepay ? BN_ZERO.minus(amount).toString() : BN_ZERO.plus(amount).toString(),
|
||||||
denom: modal.asset.denom,
|
denom: modal.asset.denom,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
debts: [
|
debts: [
|
||||||
{
|
{
|
||||||
amount: isRepay ? BN(0).minus(amount).toString() : BN(0).plus(amount).toString(),
|
amount: isRepay ? BN_ZERO.minus(amount).toString() : BN_ZERO.plus(amount).toString(),
|
||||||
denom: modal.asset.denom,
|
denom: modal.asset.denom,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -11,7 +11,7 @@ import useToggle from 'hooks/useToggle'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { getAmount } from 'utils/accounts'
|
import { getAmount } from 'utils/accounts'
|
||||||
import { hardcodedFee } from 'utils/constants'
|
import { hardcodedFee } from 'utils/constants'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
account: Account
|
account: Account
|
||||||
@ -25,21 +25,23 @@ export default function FundWithdrawModalContent(props: Props) {
|
|||||||
const balances = useStore((s) => s.balances)
|
const balances = useStore((s) => s.balances)
|
||||||
const [isConfirming, setIsConfirming] = useToggle()
|
const [isConfirming, setIsConfirming] = useToggle()
|
||||||
const [currentAsset, setCurrentAsset] = useState(baseCurrency)
|
const [currentAsset, setCurrentAsset] = useState(baseCurrency)
|
||||||
const [amount, setAmount] = useState(BN(0))
|
const [amount, setAmount] = useState(BN_ZERO)
|
||||||
const [change, setChange] = useState<AccountChange | undefined>()
|
const [change, setChange] = useState<AccountChange | undefined>()
|
||||||
|
|
||||||
const max = props.isFunding
|
const max = props.isFunding
|
||||||
? getAmount(currentAsset.denom, balances ?? [])
|
? getAmount(currentAsset.denom, balances ?? [])
|
||||||
: props.account
|
: props.account
|
||||||
? getAmount(currentAsset.denom, props.account.deposits)
|
? getAmount(currentAsset.denom, props.account.deposits)
|
||||||
: BN(0)
|
: BN_ZERO
|
||||||
|
|
||||||
function onChangeAmount(val: BigNumber) {
|
function onChangeAmount(val: BigNumber) {
|
||||||
setAmount(val)
|
setAmount(val)
|
||||||
setChange({
|
setChange({
|
||||||
deposits: [
|
deposits: [
|
||||||
{
|
{
|
||||||
amount: props.isFunding ? BN(0).plus(amount).toString() : BN(0).minus(amount).toString(),
|
amount: props.isFunding
|
||||||
|
? BN_ZERO.plus(amount).toString()
|
||||||
|
: BN_ZERO.minus(amount).toString(),
|
||||||
denom: currentAsset.denom,
|
denom: currentAsset.denom,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -48,7 +50,7 @@ export default function FundWithdrawModalContent(props: Props) {
|
|||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
setCurrentAsset(baseCurrency)
|
setCurrentAsset(baseCurrency)
|
||||||
setAmount(BN(0))
|
setAmount(BN_ZERO)
|
||||||
setChange(undefined)
|
setChange(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import useLocalStorage from 'hooks/useLocalStorage'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { getAllAssets, getDisplayCurrencies } from 'utils/assets'
|
import { getAllAssets, getDisplayCurrencies } from 'utils/assets'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
const slippages = [0.02, 0.03]
|
const slippages = [0.02, 0.03]
|
||||||
|
|
||||||
@ -281,7 +282,7 @@ export default function SettingsModal() {
|
|||||||
onFocus={handleSlippageInputFocus}
|
onFocus={handleSlippageInputFocus}
|
||||||
amount={BN(customSlippage).multipliedBy(100)}
|
amount={BN(customSlippage).multipliedBy(100)}
|
||||||
max={BN(10)}
|
max={BN(10)}
|
||||||
min={BN(0)}
|
min={BN_ZERO}
|
||||||
maxDecimals={1}
|
maxDecimals={1}
|
||||||
maxLength={2}
|
maxLength={2}
|
||||||
style={{ fontSize: 16 }}
|
style={{ fontSize: 16 }}
|
||||||
|
@ -14,8 +14,8 @@ import useStore from 'store'
|
|||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { findCoinByDenom, getAssetByDenom } from 'utils/assets'
|
import { findCoinByDenom, getAssetByDenom } from 'utils/assets'
|
||||||
import { formatPercent } from 'utils/formatters'
|
import { formatPercent } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
export interface VaultBorrowingsProps {
|
export interface VaultBorrowingsProps {
|
||||||
updatedAccount: Account
|
updatedAccount: Account
|
||||||
@ -44,7 +44,7 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
|
|||||||
if (!price) return prev
|
if (!price) return prev
|
||||||
|
|
||||||
return prev.plus(curr.amount.multipliedBy(price))
|
return prev.plus(curr.amount.multipliedBy(price))
|
||||||
}, BN(0) as BigNumber)
|
}, BN_ZERO as BigNumber)
|
||||||
}, [props.borrowings, prices])
|
}, [props.borrowings, prices])
|
||||||
|
|
||||||
const totalValue = useMemo(() => {
|
const totalValue = useMemo(() => {
|
||||||
@ -53,7 +53,7 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
|
|||||||
if (!price) return prev
|
if (!price) return prev
|
||||||
const value = curr.amount.multipliedBy(price)
|
const value = curr.amount.multipliedBy(price)
|
||||||
return prev.plus(value)
|
return prev.plus(value)
|
||||||
}, BN(0) as BigNumber)
|
}, BN_ZERO as BigNumber)
|
||||||
|
|
||||||
return depositValue.plus(borrowingValue)
|
return depositValue.plus(borrowingValue)
|
||||||
}, [props.deposits, borrowingValue, prices])
|
}, [props.deposits, borrowingValue, prices])
|
||||||
@ -68,7 +68,7 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updatedBorrowings = selectedBorrowDenoms.map((denom) => {
|
const updatedBorrowings = selectedBorrowDenoms.map((denom) => {
|
||||||
const amount = findCoinByDenom(denom, props.borrowings)?.amount || BN(0)
|
const amount = findCoinByDenom(denom, props.borrowings)?.amount || BN_ZERO
|
||||||
return new BNCoin({
|
return new BNCoin({
|
||||||
denom,
|
denom,
|
||||||
amount: amount.toString(),
|
amount: amount.toString(),
|
||||||
@ -84,12 +84,13 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
|
|||||||
|
|
||||||
const denom = props.borrowings[0].denom
|
const denom = props.borrowings[0].denom
|
||||||
const currentAmount = props.borrowings[0].amount
|
const currentAmount = props.borrowings[0].amount
|
||||||
const maxAmount = maxBorrowAmounts.find((coin) => coin.denom === denom)?.amount ?? BN(0)
|
const maxAmount = maxBorrowAmounts.find((coin) => coin.denom === denom)?.amount ?? BN_ZERO
|
||||||
const newBorrowings: BNCoin[] = [
|
const newBorrowings: BNCoin[] = [
|
||||||
new BNCoin({
|
new BNCoin({
|
||||||
denom,
|
denom,
|
||||||
amount: (
|
amount: (
|
||||||
maxAmount.plus(currentAmount).multipliedBy(value).dividedBy(100).decimalPlaces(0) || BN(0)
|
maxAmount.plus(currentAmount).multipliedBy(value).dividedBy(100).decimalPlaces(0) ||
|
||||||
|
BN_ZERO
|
||||||
).toString(),
|
).toString(),
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
|
@ -5,7 +5,7 @@ import usePrices from 'hooks/usePrices'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { formatAmountWithSymbol } from 'utils/formatters'
|
import { formatAmountWithSymbol } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
borrowings: BNCoin[]
|
borrowings: BNCoin[]
|
||||||
@ -17,7 +17,7 @@ export default function VaultDepositSubTitle(props: Props) {
|
|||||||
|
|
||||||
const [borrowingTexts, borrowingValue] = useMemo(() => {
|
const [borrowingTexts, borrowingValue] = useMemo(() => {
|
||||||
const texts: string[] = []
|
const texts: string[] = []
|
||||||
let borrowingValue = BN(0)
|
let borrowingValue = BN_ZERO
|
||||||
props.borrowings.map((coin) => {
|
props.borrowings.map((coin) => {
|
||||||
const price = prices.find((p) => p.denom === coin.denom)?.amount
|
const price = prices.find((p) => p.denom === coin.denom)?.amount
|
||||||
if (!price || coin.amount.isZero()) return
|
if (!price || coin.amount.isZero()) return
|
||||||
|
@ -16,6 +16,7 @@ import { BNCoin } from 'types/classes/BNCoin'
|
|||||||
import { getAmount } from 'utils/accounts'
|
import { getAmount } from 'utils/accounts'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
import { findCoinByDenom } from 'utils/assets'
|
import { findCoinByDenom } from 'utils/assets'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
deposits: BNCoin[]
|
deposits: BNCoin[]
|
||||||
@ -103,8 +104,8 @@ export default function VaultDeposit(props: Props) {
|
|||||||
function handleSwitch() {
|
function handleSwitch() {
|
||||||
const isCustomRatioNew = !props.isCustomRatio
|
const isCustomRatioNew = !props.isCustomRatio
|
||||||
if (!isCustomRatioNew) {
|
if (!isCustomRatioNew) {
|
||||||
primaryCoin.amount = BN(0)
|
primaryCoin.amount = BN_ZERO
|
||||||
secondaryCoin.amount = BN(0)
|
secondaryCoin.amount = BN_ZERO
|
||||||
onChangeDeposits([primaryCoin, secondaryCoin])
|
onChangeDeposits([primaryCoin, secondaryCoin])
|
||||||
setPercentage(0)
|
setPercentage(0)
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ import VaultBorrowingsSubTitle from 'components/Modals/Vault/VaultBorrowingsSubT
|
|||||||
import VaultDeposit from 'components/Modals/Vault/VaultDeposits'
|
import VaultDeposit from 'components/Modals/Vault/VaultDeposits'
|
||||||
import VaultDepositSubTitle from 'components/Modals/Vault/VaultDepositsSubTitle'
|
import VaultDepositSubTitle from 'components/Modals/Vault/VaultDepositsSubTitle'
|
||||||
import useIsOpenArray from 'hooks/useIsOpenArray'
|
import useIsOpenArray from 'hooks/useIsOpenArray'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import useDepositVault from 'hooks/broadcast/useDepositVault'
|
import useDepositVault from 'hooks/broadcast/useDepositVault'
|
||||||
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
vault: Vault | DepositedVault
|
vault: Vault | DepositedVault
|
||||||
@ -60,10 +60,11 @@ export default function VaultModalContent(props: Props) {
|
|||||||
return (
|
return (
|
||||||
<VaultDepositSubTitle
|
<VaultDepositSubTitle
|
||||||
primaryAmount={
|
primaryAmount={
|
||||||
removedDeposits.find((coin) => coin.denom === props.primaryAsset.denom)?.amount || BN(0)
|
removedDeposits.find((coin) => coin.denom === props.primaryAsset.denom)?.amount || BN_ZERO
|
||||||
}
|
}
|
||||||
secondaryAmount={
|
secondaryAmount={
|
||||||
removedDeposits.find((coin) => coin.denom === props.secondaryAsset.denom)?.amount || BN(0)
|
removedDeposits.find((coin) => coin.denom === props.secondaryAsset.denom)?.amount ||
|
||||||
|
BN_ZERO
|
||||||
}
|
}
|
||||||
primaryAsset={props.primaryAsset}
|
primaryAsset={props.primaryAsset}
|
||||||
secondaryAsset={props.secondaryAsset}
|
secondaryAsset={props.secondaryAsset}
|
||||||
|
@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'
|
|||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { demagnify, formatValue, magnify } from 'utils/formatters'
|
import { demagnify, formatValue, magnify } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
@ -99,14 +100,14 @@ export default function NumberInput(props: Props) {
|
|||||||
const exceedsMaxDecimals = props.maxDecimals !== undefined && decimals > props.maxDecimals
|
const exceedsMaxDecimals = props.maxDecimals !== undefined && decimals > props.maxDecimals
|
||||||
|
|
||||||
if (formattedAmount === '') {
|
if (formattedAmount === '') {
|
||||||
updateValues('0', BN(0))
|
updateValues('0', BN_ZERO)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNegative && !props.allowNegative) return
|
if (isNegative && !props.allowNegative) return
|
||||||
|
|
||||||
if (isSeparator && formattedAmount.length === 1) {
|
if (isSeparator && formattedAmount.length === 1) {
|
||||||
updateValues('0.', BN(0))
|
updateValues('0.', BN_ZERO)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { useState } from 'react'
|
|||||||
import Slider from 'components/Slider'
|
import Slider from 'components/Slider'
|
||||||
import TokenInput from 'components/TokenInput'
|
import TokenInput from 'components/TokenInput'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
amount: BigNumber
|
amount: BigNumber
|
||||||
@ -39,7 +40,7 @@ export default function TokenInputWithSlider(props: Props) {
|
|||||||
function onChangeAsset(newAsset: Asset) {
|
function onChangeAsset(newAsset: Asset) {
|
||||||
if (!props.onChangeAsset) return
|
if (!props.onChangeAsset) return
|
||||||
setPercentage(0)
|
setPercentage(0)
|
||||||
setAmount(BN(0))
|
setAmount(BN_ZERO)
|
||||||
props.onChangeAsset(newAsset)
|
props.onChangeAsset(newAsset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ import DisplayCurrency from 'components/DisplayCurrency'
|
|||||||
import { StarFilled, StarOutlined } from 'components/Icons'
|
import { StarFilled, StarOutlined } from 'components/Icons'
|
||||||
import Text from 'components/Text'
|
import Text from 'components/Text'
|
||||||
import { FAVORITE_ASSETS_KEY } from 'constants/localStore'
|
import { FAVORITE_ASSETS_KEY } from 'constants/localStore'
|
||||||
|
import { BN_ONE } from 'constants/math'
|
||||||
import useLocalStorage from 'hooks/useLocalStorage'
|
import useLocalStorage from 'hooks/useLocalStorage'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
asset: Asset
|
asset: Asset
|
||||||
@ -50,7 +50,7 @@ export default function AssetItem(props: Props) {
|
|||||||
<DisplayCurrency
|
<DisplayCurrency
|
||||||
className='text-sm'
|
className='text-sm'
|
||||||
coin={
|
coin={
|
||||||
new BNCoin({ denom: asset.denom, amount: BN(1).shiftedBy(asset.decimals).toString() })
|
new BNCoin({ denom: asset.denom, amount: BN_ONE.shiftedBy(asset.decimals).toString() })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
@ -3,7 +3,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
|
|||||||
import Divider from 'components/Divider'
|
import Divider from 'components/Divider'
|
||||||
import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
|
import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
|
||||||
import { SLIPPAGE_KEY } from 'constants/localStore'
|
import { SLIPPAGE_KEY } from 'constants/localStore'
|
||||||
import { ZERO } from 'constants/math'
|
import { BN_ZERO } from 'constants/math'
|
||||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||||
import useLocalStorage from 'hooks/useLocalStorage'
|
import useLocalStorage from 'hooks/useLocalStorage'
|
||||||
import usePrices from 'hooks/usePrices'
|
import usePrices from 'hooks/usePrices'
|
||||||
@ -31,15 +31,15 @@ export default function SwapForm(props: Props) {
|
|||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
const swap = useStore((s) => s.swap)
|
const swap = useStore((s) => s.swap)
|
||||||
const [isMarginChecked, setMarginChecked] = useState(false)
|
const [isMarginChecked, setMarginChecked] = useState(false)
|
||||||
const [buyAssetAmount, setBuyAssetAmount] = useState(ZERO)
|
const [buyAssetAmount, setBuyAssetAmount] = useState(BN_ZERO)
|
||||||
const [sellAssetAmount, setSellAssetAmount] = useState(ZERO)
|
const [sellAssetAmount, setSellAssetAmount] = useState(BN_ZERO)
|
||||||
const [slippage] = useLocalStorage(SLIPPAGE_KEY, DEFAULT_SETTINGS.slippage)
|
const [slippage] = useLocalStorage(SLIPPAGE_KEY, DEFAULT_SETTINGS.slippage)
|
||||||
const [focusedInput, setFocusedInput] = useState<'buy' | 'sell' | null>(null)
|
const [focusedInput, setFocusedInput] = useState<'buy' | 'sell' | null>(null)
|
||||||
const [maxBuyableAmountEstimation, setMaxBuyableAmountEstimation] = useState(ZERO)
|
const [maxBuyableAmountEstimation, setMaxBuyableAmountEstimation] = useState(BN_ZERO)
|
||||||
const [selectedOrderType, setSelectedOrderType] = useState<AvailableOrderType>('Market')
|
const [selectedOrderType, setSelectedOrderType] = useState<AvailableOrderType>('Market')
|
||||||
|
|
||||||
const accountSellAssetDeposit = useMemo(
|
const accountSellAssetDeposit = useMemo(
|
||||||
() => account?.deposits.find(byDenom(sellAsset.denom))?.amount || ZERO,
|
() => account?.deposits.find(byDenom(sellAsset.denom))?.amount || BN_ZERO,
|
||||||
[account, sellAsset.denom],
|
[account, sellAsset.denom],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,8 +51,8 @@ export default function SwapForm(props: Props) {
|
|||||||
}, [accountSellAssetDeposit, buyAsset.denom, sellAsset.denom])
|
}, [accountSellAssetDeposit, buyAsset.denom, sellAsset.denom])
|
||||||
|
|
||||||
const [buyAssetValue, sellAssetValue] = useMemo(() => {
|
const [buyAssetValue, sellAssetValue] = useMemo(() => {
|
||||||
const buyAssetPrice = prices.find(byDenom(buyAsset.denom))?.amount ?? ZERO
|
const buyAssetPrice = prices.find(byDenom(buyAsset.denom))?.amount ?? BN_ZERO
|
||||||
const sellAssetPrice = prices.find(byDenom(sellAsset.denom))?.amount ?? ZERO
|
const sellAssetPrice = prices.find(byDenom(sellAsset.denom))?.amount ?? BN_ZERO
|
||||||
|
|
||||||
return [
|
return [
|
||||||
buyAssetPrice.multipliedBy(buyAssetAmount.shiftedBy(-buyAsset.decimals)),
|
buyAssetPrice.multipliedBy(buyAssetAmount.shiftedBy(-buyAsset.decimals)),
|
||||||
@ -91,8 +91,8 @@ export default function SwapForm(props: Props) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFocusedInput(null)
|
setFocusedInput(null)
|
||||||
setBuyAssetAmount(ZERO)
|
setBuyAssetAmount(BN_ZERO)
|
||||||
setSellAssetAmount(ZERO)
|
setSellAssetAmount(BN_ZERO)
|
||||||
}, [sellAsset.denom])
|
}, [sellAsset.denom])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -109,7 +109,7 @@ export default function SwapForm(props: Props) {
|
|||||||
slippage,
|
slippage,
|
||||||
})
|
})
|
||||||
if (isSucceeded) {
|
if (isSucceeded) {
|
||||||
setSellAssetAmount(ZERO)
|
setSellAssetAmount(BN_ZERO)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [account?.id, buyAsset.denom, sellAsset.denom, sellAssetAmount, slippage, swap])
|
}, [account?.id, buyAsset.denom, sellAsset.denom, sellAssetAmount, slippage, swap])
|
||||||
|
@ -19,7 +19,7 @@ import useStore from 'store'
|
|||||||
import { ChainInfoID } from 'types/enums/wallet'
|
import { ChainInfoID } from 'types/enums/wallet'
|
||||||
import { getBaseAsset, getEnabledMarketAssets } from 'utils/assets'
|
import { getBaseAsset, getEnabledMarketAssets } from 'utils/assets'
|
||||||
import { formatValue, truncate } from 'utils/formatters'
|
import { formatValue, truncate } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
export default function WalletConnectedButton() {
|
export default function WalletConnectedButton() {
|
||||||
// ---------------
|
// ---------------
|
||||||
@ -38,7 +38,7 @@ export default function WalletConnectedButton() {
|
|||||||
// LOCAL STATE
|
// LOCAL STATE
|
||||||
// ---------------
|
// ---------------
|
||||||
const [showDetails, setShowDetails] = useToggle()
|
const [showDetails, setShowDetails] = useToggle()
|
||||||
const [walletAmount, setWalletAmount] = useState(BN(0))
|
const [walletAmount, setWalletAmount] = useState(BN_ZERO)
|
||||||
const [isCopied, setCopied] = useClipboard(address || '', {
|
const [isCopied, setCopied] = useClipboard(address || '', {
|
||||||
successDuration: 1000 * 5,
|
successDuration: 1000 * 5,
|
||||||
})
|
})
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
export const ZERO = BN(0)
|
export const BN_ZERO = BN(0)
|
||||||
|
export const BN_ONE = BN(1)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { VaultStatus } from 'types/enums/vault'
|
import { VaultStatus } from 'types/enums/vault'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
export const VAULT_DEPOSIT_BUFFER = 0.999
|
export const VAULT_DEPOSIT_BUFFER = 0.999
|
||||||
|
|
||||||
@ -92,15 +92,15 @@ export const VAULTS_META_DATA: VaultMetaData[] = [
|
|||||||
|
|
||||||
export const MOCK_DEPOSITED_VAULT_POSITION = {
|
export const MOCK_DEPOSITED_VAULT_POSITION = {
|
||||||
values: {
|
values: {
|
||||||
primary: BN(0),
|
primary: BN_ZERO,
|
||||||
secondary: BN(0),
|
secondary: BN_ZERO,
|
||||||
},
|
},
|
||||||
amounts: {
|
amounts: {
|
||||||
primary: BN(0),
|
primary: BN_ZERO,
|
||||||
secondary: BN(0),
|
secondary: BN_ZERO,
|
||||||
locked: BN(0),
|
locked: BN_ZERO,
|
||||||
unlocked: BN(0),
|
unlocked: BN_ZERO,
|
||||||
unlocking: BN(0),
|
unlocking: BN_ZERO,
|
||||||
},
|
},
|
||||||
status: VaultStatus.ACTIVE,
|
status: VaultStatus.ACTIVE,
|
||||||
apy: null,
|
apy: null,
|
||||||
@ -110,7 +110,7 @@ export const MOCK_DEPOSITED_VAULT_POSITION = {
|
|||||||
},
|
},
|
||||||
cap: {
|
cap: {
|
||||||
denom: '',
|
denom: '',
|
||||||
max: BN(0),
|
max: BN_ZERO,
|
||||||
used: BN(0),
|
used: BN_ZERO,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import usePrices from 'hooks/usePrices'
|
|||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
import { hardcodedFee } from 'utils/constants'
|
import { hardcodedFee } from 'utils/constants'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import {
|
import {
|
||||||
getEnterVaultActions,
|
getEnterVaultActions,
|
||||||
getVaultDepositCoinsAndValue,
|
getVaultDepositCoinsAndValue,
|
||||||
getVaultSwapActions,
|
getVaultSwapActions,
|
||||||
} from 'utils/vaults'
|
} from 'utils/vaults'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
vault: Vault
|
vault: Vault
|
||||||
@ -27,7 +27,7 @@ export default function useDepositVault(props: Props): {
|
|||||||
minLpToReceive: string
|
minLpToReceive: string
|
||||||
totalValue: BigNumber
|
totalValue: BigNumber
|
||||||
} {
|
} {
|
||||||
const [minLpToReceive, setMinLpToReceive] = useState<BigNumber>(BN(0))
|
const [minLpToReceive, setMinLpToReceive] = useState<BigNumber>(BN_ZERO)
|
||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
const [slippage] = useLocalStorage<number>(SLIPPAGE_KEY, DEFAULT_SETTINGS.slippage)
|
const [slippage] = useLocalStorage<number>(SLIPPAGE_KEY, DEFAULT_SETTINGS.slippage)
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import usePrices from 'hooks/usePrices'
|
|||||||
import { byDenom } from 'utils/array'
|
import { byDenom } from 'utils/array'
|
||||||
import { getDisplayCurrencies } from 'utils/assets'
|
import { getDisplayCurrencies } from 'utils/assets'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
function useDisplayCurrencyPrice() {
|
function useDisplayCurrencyPrice() {
|
||||||
const { data: prices } = usePrices()
|
const { data: prices } = usePrices()
|
||||||
@ -32,14 +33,15 @@ function useDisplayCurrencyPrice() {
|
|||||||
return BN(assetPrice.amount).dividedBy(displayCurrencyPrice.amount)
|
return BN(assetPrice.amount).dividedBy(displayCurrencyPrice.amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return BN(0)
|
return BN_ZERO
|
||||||
},
|
},
|
||||||
[prices, displayCurrency],
|
[prices, displayCurrency],
|
||||||
)
|
)
|
||||||
|
|
||||||
const convertAmount = useCallback(
|
const convertAmount = useCallback(
|
||||||
(asset: Asset, amount: string | number | BigNumber) =>
|
(asset: Asset, amount: string | number | BigNumber) =>
|
||||||
getConversionRate(asset.denom)?.multipliedBy(BN(amount).shiftedBy(-asset.decimals)) ?? BN(0),
|
getConversionRate(asset.denom)?.multipliedBy(BN(amount).shiftedBy(-asset.decimals)) ??
|
||||||
|
BN_ZERO,
|
||||||
[getConversionRate],
|
[getConversionRate],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
|
|
||||||
export const calculateAccountBalance = (
|
export const calculateAccountBalance = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
@ -21,46 +22,46 @@ export const calculateAccountDeposits = (
|
|||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
): BigNumber => {
|
): BigNumber => {
|
||||||
if (!account.deposits) return BN(0)
|
if (!account.deposits) return BN_ZERO
|
||||||
return account.deposits.reduce((acc, deposit) => {
|
return account.deposits.reduce((acc, deposit) => {
|
||||||
const price = prices.find((price) => price.denom === deposit.denom)?.amount ?? 0
|
const price = prices.find((price) => price.denom === deposit.denom)?.amount ?? 0
|
||||||
const depositValue = BN(deposit.amount).multipliedBy(price)
|
const depositValue = BN(deposit.amount).multipliedBy(price)
|
||||||
return acc.plus(depositValue)
|
return acc.plus(depositValue)
|
||||||
}, BN(0))
|
}, BN_ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calculateAccountDebt = (
|
export const calculateAccountDebt = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
): BigNumber => {
|
): BigNumber => {
|
||||||
if (!account.debts) return BN(0)
|
if (!account.debts) return BN_ZERO
|
||||||
return account.debts.reduce((acc, debt) => {
|
return account.debts.reduce((acc, debt) => {
|
||||||
const price = prices.find((price) => price.denom === debt.denom)?.amount ?? 0
|
const price = prices.find((price) => price.denom === debt.denom)?.amount ?? 0
|
||||||
const debtAmount = BN(debt.amount)
|
const debtAmount = BN(debt.amount)
|
||||||
const debtValue = debtAmount.multipliedBy(price)
|
const debtValue = debtAmount.multipliedBy(price)
|
||||||
return acc.plus(debtValue)
|
return acc.plus(debtValue)
|
||||||
}, BN(0))
|
}, BN_ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calculateAccountPnL = (
|
export const calculateAccountPnL = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
): BigNumber => {
|
): BigNumber => {
|
||||||
return BN(0)
|
return BN_ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calculateAccountApr = (
|
export const calculateAccountApr = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
): BigNumber => {
|
): BigNumber => {
|
||||||
return BN(0)
|
return BN_ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
export const calculateAccountBorrowRate = (
|
export const calculateAccountBorrowRate = (
|
||||||
account: Account | AccountChange,
|
account: Account | AccountChange,
|
||||||
prices: BNCoin[],
|
prices: BNCoin[],
|
||||||
): BigNumber => {
|
): BigNumber => {
|
||||||
return BN(0)
|
return BN_ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAmount(denom: string, coins: Coin[]): BigNumber {
|
export function getAmount(denom: string, coins: Coin[]): BigNumber {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { getEnabledMarketAssets } from 'utils/assets'
|
import { getEnabledMarketAssets } from 'utils/assets'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
@ -179,7 +180,7 @@ export function convertToDisplayAmount(coin: BNCoin, displayCurrency: string, pr
|
|||||||
const asset = getEnabledMarketAssets().find((asset) => asset.denom === coin.denom)
|
const asset = getEnabledMarketAssets().find((asset) => asset.denom === coin.denom)
|
||||||
const displayPrice = prices.find((price) => price.denom === displayCurrency)
|
const displayPrice = prices.find((price) => price.denom === displayCurrency)
|
||||||
|
|
||||||
if (!price || !asset || !displayPrice) return BN(0)
|
if (!price || !asset || !displayPrice) return BN_ZERO
|
||||||
|
|
||||||
return coin.amount
|
return coin.amount
|
||||||
.shiftedBy(-1 * asset.decimals)
|
.shiftedBy(-1 * asset.decimals)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { IS_TESTNET } from 'constants/env'
|
import { IS_TESTNET } from 'constants/env'
|
||||||
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import { getTokenPrice, getTokenValue } from 'utils/tokens'
|
import { getTokenPrice, getTokenValue } from 'utils/tokens'
|
||||||
|
|
||||||
export function getVaultsMetaData() {
|
export function getVaultsMetaData() {
|
||||||
@ -25,7 +25,7 @@ export function getVaultDepositCoinsAndValue(
|
|||||||
if (!price) return prev
|
if (!price) return prev
|
||||||
|
|
||||||
return prev.plus(bnCoin.amount.multipliedBy(price))
|
return prev.plus(bnCoin.amount.multipliedBy(price))
|
||||||
}, BN(0))
|
}, BN_ZERO)
|
||||||
|
|
||||||
const halfValue = totalValue.dividedBy(2)
|
const halfValue = totalValue.dividedBy(2)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user