Skip to content

Commit

Permalink
refactor: bigint literal
Browse files Browse the repository at this point in the history
  • Loading branch information
solidovic committed Nov 25, 2024
1 parent 18fb703 commit 78580c8
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 85 deletions.
11 changes: 5 additions & 6 deletions config/groups/withdrawal-queue-estimate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// fallback gas limits per 1 withdraw request
export const WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT =
BigInt(255350);
export const WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT = 255_350n;
export const WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT =
BigInt(312626);
312_626n;

export const WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT =
BigInt(228163);
228_163n;
export const WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT =
BigInt(280096);
280_096n;

export const WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT = BigInt(89818);
export const WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT = 89_818n;
16 changes: 8 additions & 8 deletions consts/tx.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const WSTETH_APPROVE_GAS_LIMIT = BigInt(78000);
export const STETH_L2_APPROVE_GAS_LIMIT = BigInt(52500);
export const WSTETH_APPROVE_GAS_LIMIT = 78_000n;
export const STETH_L2_APPROVE_GAS_LIMIT = 52_500n;

export const WRAP_FROM_ETH_GAS_LIMIT = BigInt(100000);
export const WRAP_GAS_LIMIT = BigInt(140000);
export const WRAP_L2_GAS_LIMIT = BigInt(95500);
export const WRAP_FROM_ETH_GAS_LIMIT = 100_000n;
export const WRAP_GAS_LIMIT = 140_000n;
export const WRAP_L2_GAS_LIMIT = 95_500n;

export const UNWRAP_GAS_LIMIT = BigInt(115000);
export const UNWRAP_L2_GAS_LIMIT = BigInt(77500);
export const UNWRAP_GAS_LIMIT = 115_000n;
export const UNWRAP_L2_GAS_LIMIT = 77_500n;

export const WEI_PER_ETHER = BigInt(10 ** 18);
export const WEI_PER_ETHER = 10_000_000_000_000_000_000n; // 10n ** 18n;
3 changes: 2 additions & 1 deletion features/rewards/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const ETHER = BigInt(1e18);
// 1e18
export const ETHER = 1_000_000_000_000_000_000n;

export const HUMAN_DECIMALS = 8;
export const PRECISE_DECIMALS = 18;
Expand Down
5 changes: 1 addition & 4 deletions features/withdrawals/hooks/contract/useClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export const useClaim = ({ onRetry }: Args) => {
invariant(sortedRequests, 'must have requests');
invariant(address, 'must have address');

const amount = sortedRequests.reduce(
(s, r) => s + r.claimableEth,
BigInt(0),
);
const amount = sortedRequests.reduce((s, r) => s + r.claimableEth, 0n);

const requestsIds = sortedRequests.map((r) => r.id);
const hints = sortedRequests.map((r) => r.hint);
Expand Down
8 changes: 2 additions & 6 deletions features/withdrawals/hooks/contract/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ export const useWithdrawalRequest = ({
needsApprove,
isFetching: isUseApproveFetching,
refetch: refetchAllowance,
} = useWithdrawalApprove(
amount ? amount : BigInt(0),
token,
address as Address,
);
} = useWithdrawalApprove(amount ? amount : 0n, token, address as Address);
const { closeModal } = useTransactionModal();

const isWalletConnect = overrideWithQAMockBoolean(
Expand Down Expand Up @@ -180,7 +176,7 @@ export const useWithdrawalRequest = ({
return {
isTokenLocked,
isApprovalFlow,
allowance: BigInt(0),
allowance: 0n,
isApprovalFlowLoading,
request,
};
Expand Down
8 changes: 4 additions & 4 deletions features/withdrawals/hooks/contract/useWithdrawalsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export const useWithdrawalRequests = () => {
console.warn('Failed to fetch request time for requests ids', e);
}

let pendingAmountOfStETH = BigInt(0);
let claimableAmountOfStETH = BigInt(0);
let pendingAmountOfStETH = 0n;
let claimableAmountOfStETH = 0n;

requestStatuses.forEach((request, index) => {
const id = requestIds[index];
Expand Down Expand Up @@ -166,7 +166,7 @@ export const useWithdrawalRequests = () => {

const hints = await withdraw.views.findCheckpointHints({
sortedIds: claimableRequests.map(({ id }) => id),
firstIndex: BigInt(1),
firstIndex: 1n,
lastIndex: lastCheckpointIndex,
});

Expand All @@ -175,7 +175,7 @@ export const useWithdrawalRequests = () => {
hints,
});

let claimableAmountOfETH = BigInt(0);
let claimableAmountOfETH = 0n;

const sortedClaimableRequests: RequestStatusClaimable[] =
claimableRequests.map((request, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useWithdrawRequestTxPrice = ({
const contract = await withdraw.contract.getContractWithdrawalQueue();
const requestsStub = Array.from<bigint>({
length: debouncedRequestCount,
}).fill(BigInt(100));
}).fill(100n);

return await contract.estimateGas.requestWithdrawals(
[requestsStub, config.ESTIMATE_ACCOUNT],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const {
} = __test__export;

const field = 'test_field';
const balance = BigInt(5);
const balance = 5n;

describe('tvlJokeValidate', () => {
it('should work', () => {
tvlJokeValidate(field, BigInt(10), BigInt(12), balance);
tvlJokeValidate(field, 10n, 12n, balance);
});

it('should throw right error', () => {
const value = BigInt(20);
const tvl = BigInt(10);
const value = 20n;
const tvl = 10n;
const fn = () => tvlJokeValidate(field, value, tvl, balance);
expect(fn).toThrow();
try {
Expand All @@ -42,25 +42,25 @@ describe('tvlJokeValidate', () => {
});
});

const maxAmountPerRequest = BigInt(100);
const minAmountPerRequest = BigInt(10);
const maxAmountPerRequest = 100n;
const minAmountPerRequest = 10n;
const maxRequestCount = 100;

describe('validateSplitRequests', () => {
it('should split into 1 request', () => {
const requests = validateSplitRequests(
field,
BigInt(10),
10n,
maxAmountPerRequest,
minAmountPerRequest,
maxRequestCount,
);
expect(requests).toHaveLength(1);
expect(requests[0] === BigInt(10)).toBe(true);
expect(requests[0] === 10n).toBe(true);
});

it('should split into 2 requests', () => {
const amount = maxAmountPerRequest + minAmountPerRequest * BigInt(5);
const amount = maxAmountPerRequest + minAmountPerRequest * 5n;
const requests = validateSplitRequests(
field,
amount,
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('validateSplitRequests', () => {
const fn = () =>
validateSplitRequests(
field,
maxAmountPerRequest * BigInt(maxRequestCount) + BigInt(1),
maxAmountPerRequest * BigInt(maxRequestCount) + 1n,
maxAmountPerRequest,
minAmountPerRequest,
maxRequestCount,
Expand All @@ -126,7 +126,7 @@ describe('validateSplitRequests', () => {
const fn = () =>
validateSplitRequests(
field,
maxAmountPerRequest + minAmountPerRequest - BigInt(1),
maxAmountPerRequest + minAmountPerRequest - 1n,
maxAmountPerRequest,
minAmountPerRequest,
maxRequestCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const validateSplitRequests = (
const maxAmount = maxAmountPerRequest * BigInt(maxRequestCount);

const lastRequestAmountEther = amount % maxAmountPerRequest;
const restCount = lastRequestAmountEther > BigInt(0) ? 1 : 0;
const restCount = lastRequestAmountEther > 0n ? 1 : 0;
const requestCount = Number(amount / maxAmountPerRequest) + restCount;

const isMoreThanMax = amount > maxAmount;
Expand Down Expand Up @@ -109,7 +109,7 @@ const tvlJokeValidate = (
balanceSteth: bigint,
) => {
const tvlDiff = valueSteth - tvl;
if (tvlDiff > BigInt(0))
if (tvlDiff > 0n)
throw new ValidationTvlJoke(field, 'amount bigger than tvl', {
balanceDiffSteth: valueSteth - balanceSteth,
tvlDiff,
Expand Down
4 changes: 2 additions & 2 deletions features/wsteth/shared/hooks/use-debounced-wsteth-steth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const useDebouncedWstethBySteth = (
amount?: bigint | null,
delay = 500,
) => {
const fallbackedAmount = amount ?? BigInt(0);
const fallbackedAmount = amount ?? 0n;
const amountDebounced = useDebouncedValue(fallbackedAmount, delay);
const isActualValue = fallbackedAmount === amountDebounced;

Expand Down Expand Up @@ -36,7 +36,7 @@ export const useDebouncedStethByWsteth = (
amount?: bigint | null,
delay = 500,
) => {
const fallbackedAmount = amount ?? BigInt(0);
const fallbackedAmount = amount ?? 0n;
const amountDebounced = useDebouncedValue(fallbackedAmount, delay);
const isActualValue = fallbackedAmount === amountDebounced;

Expand Down
2 changes: 1 addition & 1 deletion features/wsteth/unwrap/unwrap-form/unwrap-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const UnwrapStats = () => {
{isShowAllowance && (
<AllowanceDataTableRow
data-testid="allowance"
allowance={allowance || BigInt(0)}
allowance={allowance || 0n}
isBlank={!isDappActiveOnL2}
loading={isAllowanceLoading}
token={TOKENS_TO_WRAP.wstETH}
Expand Down
1 change: 0 additions & 1 deletion modules/web3/consts/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export const ONE_wstETH = parseEther('1');

export const ONE_stETH = parseEther('1');

// BigInt('0') or 0n is equivalent
export const ZERO = parseEther('0');
4 changes: 2 additions & 2 deletions modules/web3/hooks/use-max-gas-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const feeHistoryToMaxFee = ({
const maxPriorityFeePerGas = reward
? reward?.map((fees) => fees[0]).reduce((sum, fee) => sum + fee) /
BigInt(reward.length)
: BigInt(0);
: 0n;

const lastBaseFeePerGas = baseFeePerGas[0];

// we have to multiply by 2 until we find a reliable way to predict baseFee change
return lastBaseFeePerGas * BigInt(2) + maxPriorityFeePerGas;
return lastBaseFeePerGas * 2n + maxPriorityFeePerGas;
};

export const useMaxGasPrice = (chainId?: number) => {
Expand Down
2 changes: 1 addition & 1 deletion modules/web3/utils/apply-round-up-gas-limit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const applyRoundUpGasLimit = (number: bigint): bigint =>
// 94567 -> 94 -> 94000 -> 94999
(number / BigInt(1000)) * BigInt(1000) + BigInt(999);
(number / 1_000n) * 1_000n + 999n;
2 changes: 1 addition & 1 deletion shared/components/input-amount/input-amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const InputAmount = forwardRef<HTMLInputElement, InputAmountProps>(
}, [value]);

const handleClickMax =
onChange && maxValue !== undefined && maxValue > BigInt(0)
onChange && maxValue !== undefined && maxValue > 0n
? (event: MouseEvent<HTMLButtonElement>) => {
onChange(maxValue);
onMaxClick?.(event, maxValue);
Expand Down
2 changes: 1 addition & 1 deletion shared/formatters/format-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const FormatToken: FormatTokenComponent = ({

// we show prefix for non zero amount and if we need to show Tooltip Amount
// overridden by explicitly set approx
const prefix = amount && amount !== BigInt(0) && approx ? '≈ ' : '';
const prefix = amount && amount !== 0n && approx ? '≈ ' : '';

const body = (
<span {...rest}>
Expand Down
24 changes: 12 additions & 12 deletions shared/hook-form/validation/__tests__/validation.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const field = 'test_field';

describe('validateBigintMax', () => {
it('should work', () => {
validateBigintMax(field, BigInt(10), BigInt(12), message);
validateBigintMax(field, BigInt(12), BigInt(12), message);
validateBigintMax(field, 10n, 12n, message);
validateBigintMax(field, 12n, 12n, message);
});

it('should throw right error', () => {
const fn = () => validateBigintMax(field, BigInt(12), BigInt(10), message);
const fn = () => validateBigintMax(field, 12n, 10n, message);
expect(fn).toThrowError();
try {
fn();
Expand All @@ -34,12 +34,12 @@ describe('validateBigintMax', () => {

describe('validateBigintMin', () => {
it('should work', () => {
validateBigintMin(field, BigInt(12), BigInt(10), message);
validateBigintMin(field, BigInt(12), BigInt(12), message);
validateBigintMin(field, 12n, 10n, message);
validateBigintMin(field, 12n, 12n, message);
});

it('should throw right error', () => {
const fn = () => validateBigintMin(field, BigInt(10), BigInt(12), message);
const fn = () => validateBigintMin(field, 10n, 12n, message);
expect(fn).toThrowError();
try {
fn();
Expand All @@ -55,8 +55,8 @@ describe('validateBigintMin', () => {

describe('validateEtherAmount', () => {
it('should work', () => {
// validateEtherAmount(field, BigInt(12), LIDO_TOKENS.steth);
validateEtherAmount(field, BigInt(12), 'stETH');
// validateEtherAmount(field, 12n, LIDO_TOKENS.steth);
validateEtherAmount(field, 12n, 'stETH');
});

it('should throw right error on null amount', () => {
Expand All @@ -74,8 +74,8 @@ describe('validateEtherAmount', () => {
});

it('should throw right error on zero', () => {
// const fn = () => validateEtherAmount(field, BigInt(0), LIDO_TOKENS.steth);
const fn = () => validateEtherAmount(field, BigInt(0), 'stETH');
// const fn = () => validateEtherAmount(field, 0n, LIDO_TOKENS.steth);
const fn = () => validateEtherAmount(field, 0n, 'stETH');
expect(fn).toThrowError();
try {
fn();
Expand All @@ -89,8 +89,8 @@ describe('validateEtherAmount', () => {

it('should throw right error on more than ethereum max uint', () => {
const fn = () =>
// validateEtherAmount(field, maxUint256 + BigInt(1), LIDO_TOKENS.steth);
validateEtherAmount(field, maxUint256 + BigInt(1), 'stETH');
// validateEtherAmount(field, maxUint256 + 1n, LIDO_TOKENS.steth);
validateEtherAmount(field, maxUint256 + 1n, 'stETH');
expect(fn).toThrowError();
try {
fn();
Expand Down
2 changes: 1 addition & 1 deletion shared/hooks/use-eth-usd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useEthUsd = (amount?: bigint) => {
functionName: 'latestAnswer',
});

return latestAnswer / BigInt(10 ** 8);
return latestAnswer / 10n ** 8n;
},
});

Expand Down
8 changes: 4 additions & 4 deletions shared/hooks/useStakingLimitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ const stakeLimitFullInfoMockTemplate: StakeLimitFullInfo = {
isStakingLimitSet: true,
currentStakeLimit: parseEther('150000'),
maxStakeLimit: parseEther('150000'),
maxStakeLimitGrowthBlocks: BigInt(6400),
maxStakeLimitGrowthBlocks: 6_400n,
prevStakeLimit: parseEther('149000'),
prevStakeBlockNumber: BigInt(15145339),
prevStakeBlockNumber: 15_145_339n,
stakeLimitLevel: LIMIT_LEVEL.REACHED,
};

const WARN_THRESHOLD_RATIO = BigInt(4);
const WARN_THRESHOLD_RATIO = 4n;

const getLimitLevel = (maxLimit: bigint, currentLimit: bigint) => {
if (currentLimit === BigInt(0)) return LIMIT_LEVEL.REACHED;
if (currentLimit === 0n) return LIMIT_LEVEL.REACHED;

if (maxLimit / currentLimit >= WARN_THRESHOLD_RATIO) return LIMIT_LEVEL.WARN;

Expand Down
Loading

0 comments on commit 78580c8

Please sign in to comment.