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