From 67443ac1197c2ef89649fa60182e4f919622f8ab Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 14 Aug 2024 13:00:40 +0300 Subject: [PATCH] feat(stake): round up gas limit and change fallback ref address --- config/groups/stake.ts | 5 ++--- features/stake/stake-form/use-stake.ts | 13 ++----------- features/stake/stake-form/utils.ts | 13 ------------- utils/apply-round-up-gas-limit.ts | 8 ++++++++ utils/send-tx.ts | 7 +++++++ 5 files changed, 19 insertions(+), 27 deletions(-) create mode 100644 utils/apply-round-up-gas-limit.ts diff --git a/config/groups/stake.ts b/config/groups/stake.ts index f687764cb..ebebb908a 100644 --- a/config/groups/stake.ts +++ b/config/groups/stake.ts @@ -1,6 +1,5 @@ import { BigNumber } from 'ethers'; import { parseEther } from '@ethersproject/units'; -import { AddressZero } from '@ethersproject/constants'; import { StakeSwapDiscountIntegrationKey } from 'features/stake/swap-discount-banner'; @@ -26,11 +25,11 @@ export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( ), ); -export const STAKE_WIDGET_METRIC_SUFFIX = '01'; +export const LIDO_ADDRESS = '0x11D00000000000000000000000000000000011D0'; export const STAKE_FALLBACK_REFERRAL_ADDRESS = preConfig.ipfsMode ? IPFS_REFERRAL_ADDRESS - : AddressZero; + : LIDO_ADDRESS; export const STAKE_SWAP_INTEGRATION: StakeSwapDiscountIntegrationKey = 'one-inch'; diff --git a/features/stake/stake-form/use-stake.ts b/features/stake/stake-form/use-stake.ts index 092272289..a772a63f5 100644 --- a/features/stake/stake-form/use-stake.ts +++ b/features/stake/stake-form/use-stake.ts @@ -14,11 +14,7 @@ import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc import { isContract } from 'utils/isContract'; import { runWithTransactionLogger } from 'utils'; -import { - MockLimitReachedError, - getAddress, - applyCalldataSuffix, -} from './utils'; +import { MockLimitReachedError, getAddress } from './utils'; import { useTxModalStagesStake } from './hooks/use-tx-modal-stages-stake'; import { sendTx } from 'utils/send-tx'; @@ -41,9 +37,6 @@ export const useStake = ({ onConfirm, onRetry }: StakeOptions) => { const { providerWeb3 } = useSDK(); const { txModalStages } = useTxModalStagesStake(); - // temporary disable until Ledger is fixed - const shouldApplyCalldataSuffix = false; - return useCallback( async ({ amount, referral }: StakeArguments): Promise => { try { @@ -77,14 +70,13 @@ export const useStake = ({ onConfirm, onRetry }: StakeOptions) => { }, ); - if (shouldApplyCalldataSuffix) applyCalldataSuffix(tx); - return sendTx({ tx, isMultisig, staticProvider: staticRpcProvider, walletProvider: providerWeb3, shouldApplyGasLimitRatio: true, + shouldRoundUpGasLimit: true, }); }; @@ -128,7 +120,6 @@ export const useStake = ({ onConfirm, onRetry }: StakeOptions) => { staticRpcProvider, stethContract, onConfirm, - shouldApplyCalldataSuffix, onRetry, ], ); diff --git a/features/stake/stake-form/utils.ts b/features/stake/stake-form/utils.ts index 7ebb9daf8..5f256852a 100644 --- a/features/stake/stake-form/utils.ts +++ b/features/stake/stake-form/utils.ts @@ -1,10 +1,6 @@ -import type { PopulatedTransaction } from 'ethers'; import { isAddress } from 'ethers/lib/utils'; import type { BaseProvider } from '@ethersproject/providers'; -import { config } from 'config'; -import invariant from 'tiny-invariant'; - export const getAddress = async ( input: string, providerRpc: BaseProvider, @@ -20,15 +16,6 @@ export const getAddress = async ( throw new ReferralAddressError(); }; -// adds metrics indicator for widget tx -export const applyCalldataSuffix = (tx: PopulatedTransaction) => { - if (!config.ipfsMode) { - invariant(tx.data, 'transaction must have calldata'); - tx.data = tx.data + config.STAKE_WIDGET_METRIC_SUFFIX; - } - return tx; -}; - export class ReferralAddressError extends Error { reason: string; constructor() { diff --git a/utils/apply-round-up-gas-limit.ts b/utils/apply-round-up-gas-limit.ts new file mode 100644 index 000000000..73ab28773 --- /dev/null +++ b/utils/apply-round-up-gas-limit.ts @@ -0,0 +1,8 @@ +import { BigNumber } from 'ethers'; + +export const applyRoundUpGasLimit = (number: BigNumber): BigNumber => { + const bn1000 = BigNumber.from(1000); + + // 94567 -> 94 -> 94000 -> 94999 + return number.div(bn1000).mul(bn1000).add(BigNumber.from(999)); +}; diff --git a/utils/send-tx.ts b/utils/send-tx.ts index a7c003a70..3b56366c6 100644 --- a/utils/send-tx.ts +++ b/utils/send-tx.ts @@ -7,6 +7,7 @@ import type { PopulatedTransaction } from 'ethers'; import { getFeeData } from './getFeeData'; import { estimateGas } from './estimate-gas'; import { applyGasLimitRatio } from 'utils/apply-gas-limit-ratio'; +import { applyRoundUpGasLimit } from 'utils/apply-round-up-gas-limit'; export type SendTxOptions = { tx: PopulatedTransaction; @@ -14,6 +15,7 @@ export type SendTxOptions = { walletProvider: Web3Provider; staticProvider: JsonRpcBatchProvider; shouldApplyGasLimitRatio?: boolean; + shouldRoundUpGasLimit?: boolean; }; export const sendTx = async ({ @@ -22,6 +24,7 @@ export const sendTx = async ({ staticProvider, walletProvider, shouldApplyGasLimitRatio = false, + shouldRoundUpGasLimit = false, }: SendTxOptions) => { if (!isMultisig) { const { maxFeePerGas, maxPriorityFeePerGas } = @@ -35,6 +38,10 @@ export const sendTx = async ({ tx.gasLimit = shouldApplyGasLimitRatio ? applyGasLimitRatio(gasLimit) : gasLimit; + + tx.gasLimit = shouldRoundUpGasLimit + ? applyRoundUpGasLimit(tx.gasLimit) + : gasLimit; } return walletProvider.getSigner().sendUncheckedTransaction(tx); };