diff --git a/libs/network-parameters/src/use-network-params.ts b/libs/network-parameters/src/use-network-params.ts index bd598c85e..0f028ea31 100644 --- a/libs/network-parameters/src/use-network-params.ts +++ b/libs/network-parameters/src/use-network-params.ts @@ -99,6 +99,8 @@ export const NetworkParams = { governance_proposal_freeform_minProposerBalance: 'governance_proposal_freeform_minProposerBalance', validators_delegation_minAmount: 'validators_delegation_minAmount', + spam_protection_minimumWithdrawalQuantumMultiple: + 'spam_protection_minimumWithdrawalQuantumMultiple', spam_protection_voting_min_tokens: 'spam_protection_voting_min_tokens', spam_protection_proposal_min_tokens: 'spam_protection_proposal_min_tokens', market_liquidity_stakeToCcyVolume: 'market_liquidity_stakeToCcyVolume', diff --git a/libs/withdraws/src/lib/use-withdraw-asset.tsx b/libs/withdraws/src/lib/use-withdraw-asset.tsx index d65584d32..6d58a2621 100644 --- a/libs/withdraws/src/lib/use-withdraw-asset.tsx +++ b/libs/withdraws/src/lib/use-withdraw-asset.tsx @@ -3,13 +3,14 @@ import { addDecimal } from '@vegaprotocol/utils'; import { localLoggerFactory } from '@vegaprotocol/logger'; import * as Schema from '@vegaprotocol/types'; import BigNumber from 'bignumber.js'; -import { useCallback, useEffect } from 'react'; +import { useCallback, useEffect, useMemo } from 'react'; import type { AccountFieldsFragment } from '@vegaprotocol/accounts'; import { useGetWithdrawDelay, useGetWithdrawThreshold, } from '@vegaprotocol/web3'; import { useWithdrawStore } from './withdraw-store'; +import { useNetworkParam } from '@vegaprotocol/network-parameters'; export const useWithdrawAsset = ( assets: Asset[], @@ -19,6 +20,17 @@ export const useWithdrawAsset = ( const { asset, balance, min, threshold, delay, update } = useWithdrawStore(); const getThreshold = useGetWithdrawThreshold(); const getDelay = useGetWithdrawDelay(); + const { param } = useNetworkParam( + 'spam_protection_minimumWithdrawalQuantumMultiple' + ); + + const minimumWithdrawalQuantumMultiple = useMemo(() => { + const factor = new BigNumber(param || ''); + if (factor.isNaN()) { + return new BigNumber(1); + } + return factor; + }, [param]); // Every time an asset is selected we need to find the corresponding // account, balance, min viable amount and delay threshold @@ -37,7 +49,9 @@ export const useWithdrawAsset = ( const min = asset ? BigNumber.max( new BigNumber(addDecimal('1', asset.decimals)), - new BigNumber(addDecimal(asset.quantum, asset.decimals)) + new BigNumber(addDecimal(asset.quantum, asset.decimals)).times( + minimumWithdrawalQuantumMultiple + ) ) : new BigNumber(0); // Query collateral bridge for threshold for selected asset @@ -56,7 +70,14 @@ export const useWithdrawAsset = ( update({ asset, balance, min, threshold, delay }); }, - [accounts, assets, update, getThreshold, getDelay] + [ + assets, + accounts, + minimumWithdrawalQuantumMultiple, + update, + getThreshold, + getDelay, + ] ); useEffect(() => { diff --git a/libs/withdraws/src/lib/withdraw-form-container.spec.tsx b/libs/withdraws/src/lib/withdraw-form-container.spec.tsx index 47f910080..69545b756 100644 --- a/libs/withdraws/src/lib/withdraw-form-container.spec.tsx +++ b/libs/withdraws/src/lib/withdraw-form-container.spec.tsx @@ -15,6 +15,18 @@ jest.mock('@vegaprotocol/data-provider', () => ({ })); jest.mock('@web3-react/core'); jest.mock('@vegaprotocol/accounts'); +jest.mock('@vegaprotocol/network-parameters', () => { + const impl = jest.requireActual('@vegaprotocol/network-parameters'); + return { + ...impl, + useNetworkParam: jest.fn((param) => { + if (param === 'spam_protection_minimumWithdrawalQuantumMultiple') { + return { param: '10.00', loading: false, error: undefined }; + } + return impl.useNetworkParam(param); + }), + }; +}); describe('WithdrawFormContainer', () => { const props = { @@ -99,7 +111,7 @@ describe('WithdrawFormContainer', () => { accountDecimals: null, }); }); - afterEach(() => { + afterAll(() => { jest.resetAllMocks(); }); it('should be properly rendered', async () => {