Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AA Support #554

Merged
merged 30 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f08e945
refactor: migrate to new SDK, to bigint, to viem, to react-query
solidovic Dec 2, 2024
96b49ab
Merge branch 'develop' into feature/si-1693-migrate-wrapunwrap-page-t…
solidovic Dec 2, 2024
639b933
fix: fix after resolved conflicts
solidovic Dec 2, 2024
8be3639
feat: aa
Jeday Nov 29, 2024
cbac748
refactor: naming
solidovic Dec 3, 2024
7462373
feat: withdrawal and claim aa
Jeday Dec 3, 2024
b24a0a7
fix: clean up
Jeday Dec 3, 2024
2eeb447
feat: aux funds support
Jeday Dec 3, 2024
7ab7e5e
Merge branch 'develop' into feature/si-1693-migrate-wrapunwrap-page-t…
solidovic Dec 4, 2024
6e44c12
refactor: small updates
solidovic Dec 4, 2024
3edc6a9
fix: remove lock ui for aa
Jeday Dec 4, 2024
de919da
Merge branch 'feature/si-1693-migrate-wrapunwrap-page-to-new-sdk' of …
Jeday Dec 4, 2024
3551467
fix: promise all
Jeday Dec 4, 2024
c19654b
refactor: aa flow
Jeday Dec 4, 2024
2369f42
fix: eth balance validation
Jeday Dec 5, 2024
3cf4b36
fix: isl2
Jeday Dec 5, 2024
3f09043
feat: request permit deadline
Jeday Dec 6, 2024
9b0c5cf
Merge branch 'develop' of github.com:lidofinance/ethereum-staking-wid…
Jeday Dec 9, 2024
cf3310f
fix: remove redun check
Jeday Dec 9, 2024
7550e8e
chore: import order
Jeday Dec 9, 2024
297296e
fix: build
Jeday Dec 10, 2024
c857e89
Merge branch 'develop' of github.com:lidofinance/ethereum-staking-wid…
Jeday Dec 10, 2024
c14f14b
Merge branch 'develop' into feature/si-1714-aa-on-the-widget
Jeday Dec 11, 2024
d0c1667
chore: refactor & up sdk
Jeday Dec 12, 2024
0463176
fix: build
Jeday Dec 12, 2024
75f1a0f
fix: aa flow only for atomicBatch
Jeday Dec 12, 2024
4ad4035
fix: parse AA errors
Jeday Dec 12, 2024
1d265a4
fix: error message
Jeday Dec 13, 2024
cff67de
Merge branch 'develop' of github.com:lidofinance/ethereum-staking-wid…
Jeday Dec 13, 2024
d7392f5
chore: bump rk
Jeday Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/groups/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const STAKE_GASLIMIT_FALLBACK = BigInt(
),
);

export const LIDO_ADDRESS = '0x11D00000000000000000000000000000000011D0';
export const LIDO_ADDRESS = '0x11d00000000000000000000000000000000011d0';

export const STAKE_FALLBACK_REFERRAL_ADDRESS = preConfig.ipfsMode
? IPFS_REFERRAL_ADDRESS
Expand Down
2 changes: 2 additions & 0 deletions config/groups/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const PROVIDER_POLLING_INTERVAL = 12_000;
export const PROVIDER_BATCH_TIME = 150;
// max batch
export const PROVIDER_MAX_BATCH = 20;
// AA transaction polling timeout(ms)
export const AA_TX_POLLING_TIMEOUT = 60_000;

// account for gas estimation
// will always have:
Expand Down
2 changes: 1 addition & 1 deletion consts/token-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const TOKENS_BY_NETWORK: {
},
};

export const getRateTokenAddress = (
export const getTokenAddress = (
chainId: CHAINS,
token: TOKENS,
): Address | undefined => {
Expand Down
6 changes: 2 additions & 4 deletions features/settings/settings-form/settings-form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { useForm } from 'react-hook-form';

import type { LIDO_CONTRACT_NAMES } from '@lidofinance/lido-ethereum-sdk/common';
import { LIDO_CONTRACT_NAMES } from '@lidofinance/lido-ethereum-sdk/common';
import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui';

import { useUserConfig } from 'config/user-config';
Expand Down Expand Up @@ -34,9 +34,7 @@ export const SettingsForm = () => {
},
});

const { data: stethAddress } = useContractAddress(
'lido' as LIDO_CONTRACT_NAMES,
);
const { data: stethAddress } = useContractAddress(LIDO_CONTRACT_NAMES.lido);

const {
formState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ const getTxModalStagesStake = (transitStage: TransactionModalTransitStage) => ({
/>,
),

pending: (amount: bigint, txHash?: Hash) =>
pending: (amount: bigint, txHash?: Hash, isAA?: boolean) =>
transitStage(
<TxStageSignOperationAmount
{...STAGE_OPERATION_ARGS}
amount={amount}
isAA={isAA}
willReceive={amount}
isPending
txHash={txHash}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'shared/hook-form/form-controller';
import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount';
import { useStakingLimitInfo } from 'shared/hooks/useStakingLimitInfo';
import { useIsMultisig, useMaxGasPrice } from 'modules/web3';
import { useIsSmartAccount, useMaxGasPrice } from 'modules/web3';
import { useFormControllerRetry } from 'shared/hook-form/form-controller/use-form-controller-retry-delegate';

import {
Expand Down Expand Up @@ -63,7 +63,8 @@ const useStakeFormNetworkData = (): StakeFormNetworkData => {
refetch: updateStethBalance,
isLoading: isStethBalanceLoading,
} = useStethBalance();
const { isMultisig, isLoading: isMultisigLoading } = useIsMultisig();
const { isSmartAccount, isLoading: isSmartAccountLoading } =
useIsSmartAccount();
const gasLimit = useStethSubmitGasLimit();
const { maxGasPrice, isLoading: isMaxGasPriceLoading } = useMaxGasPrice();

Expand Down Expand Up @@ -97,10 +98,10 @@ const useStakeFormNetworkData = (): StakeFormNetworkData => {
const maxAmount = useTokenMaxAmount({
balance: etherBalance,
limit: stakingLimitInfo?.currentStakeLimit,
isPadded: !isMultisig,
isPadded: !isSmartAccount,
gasLimit: gasLimit,
padding: BALANCE_PADDING,
isLoading: isMultisigLoading,
isLoading: isSmartAccountLoading,
});

const revalidate = useCallback(async () => {
Expand All @@ -114,14 +115,14 @@ const useStakeFormNetworkData = (): StakeFormNetworkData => {
const loading = useMemo(
() => ({
isStethBalanceLoading,
isMultisigLoading,
isSmartAccountLoading,
isMaxGasPriceLoading,
isEtherBalanceLoading,
isStakeableEtherLoading: isStakingLimitIsLoading || isEtherBalanceLoading,
}),
[
isStethBalanceLoading,
isMultisigLoading,
isSmartAccountLoading,
isMaxGasPriceLoading,
isEtherBalanceLoading,
isStakingLimitIsLoading,
Expand All @@ -131,7 +132,7 @@ const useStakeFormNetworkData = (): StakeFormNetworkData => {
return {
stethBalance,
etherBalance,
isMultisig: isMultisigLoading ? undefined : isMultisig,
isSmartAccount,
stakeableEther,
stakingLimitInfo,
gasCost,
Expand Down
7 changes: 4 additions & 3 deletions features/stake/stake-form/stake-form-context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export type StakeFormInput = {

export type StakeFormLoading = {
isStethBalanceLoading: boolean;
isMultisigLoading: boolean;
isSmartAccountLoading: boolean;
isMaxGasPriceLoading: boolean;
isEtherBalanceLoading: boolean;
isStakeableEtherLoading: boolean;
};

export type StakeFormNetworkData = {
etherBalance?: bigint;
isMultisig?: boolean;
isSmartAccount?: boolean;
stethBalance?: bigint;
stakeableEther?: bigint;
stakingLimitInfo?: StakeLimitFullInfo;
Expand All @@ -35,5 +35,6 @@ export type StakeFormValidationContext = {
currentStakeLimit: bigint;
gasCost: bigint;
etherBalance: bigint;
isMultisig: boolean;
isSmartAccount: boolean;
shouldValidateEtherBalance: boolean;
};
26 changes: 19 additions & 7 deletions features/stake/stake-form/stake-form-context/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import type { Resolver } from 'react-hook-form';
import invariant from 'tiny-invariant';

import { useDappStatus } from 'modules/web3';
import { useAA, useDappStatus } from 'modules/web3';
import { VALIDATION_CONTEXT_TIMEOUT } from 'features/withdrawals/withdrawals-constants';
import { TOKENS_TO_WRAP } from 'features/wsteth/shared/types';
import { useAwaiter } from 'shared/hooks/use-awaiter';
Expand Down Expand Up @@ -36,7 +36,8 @@ export const stakeFormValidationResolver: Resolver<
currentStakeLimit,
etherBalance,
gasCost,
isMultisig,
isSmartAccount,
shouldValidateEtherBalance,
} = await awaitWithTimeout(
validationContextPromise,
VALIDATION_CONTEXT_TIMEOUT,
Expand All @@ -49,8 +50,9 @@ export const stakeFormValidationResolver: Resolver<
stakingLimitLevel,
currentStakeLimit,
etherBalance,
shouldValidateEtherBalance,
gasCost,
isMultisig,
isSmartAccount,
});

if (!isWalletActive) {
Expand All @@ -73,7 +75,9 @@ export const useStakeFormValidationContext = (
networkData: StakeFormNetworkData,
): Promise<StakeFormValidationContext> => {
const { isDappActive } = useDappStatus();
const { stakingLimitInfo, etherBalance, isMultisig, gasCost } = networkData;
const { areAuxiliaryFundsSupported } = useAA();
const { stakingLimitInfo, etherBalance, isSmartAccount, gasCost } =
networkData;

const validationContextAwaited = useMemo(() => {
if (
Expand All @@ -82,20 +86,28 @@ export const useStakeFormValidationContext = (
(!isDappActive ||
(etherBalance !== undefined &&
gasCost !== undefined &&
isMultisig !== undefined))
isSmartAccount !== undefined))
) {
return {
isWalletActive: isDappActive,
stakingLimitLevel: stakingLimitInfo.stakeLimitLevel,
currentStakeLimit: stakingLimitInfo.currentStakeLimit,
shouldValidateEtherBalance: areAuxiliaryFundsSupported,
// condition above guaranties stubs will only be passed when isDappActive = false
etherBalance: etherBalance ?? 0n,
gasCost: gasCost ?? 0n,
isMultisig: isMultisig ?? false,
isSmartAccount: isSmartAccount ?? false,
};
}
return undefined;
}, [isDappActive, etherBalance, gasCost, isMultisig, stakingLimitInfo]);
}, [
stakingLimitInfo,
isDappActive,
etherBalance,
gasCost,
isSmartAccount,
areAuxiliaryFundsSupported,
]);

return useAwaiter(validationContextAwaited).awaiter;
};
56 changes: 53 additions & 3 deletions features/stake/stake-form/use-stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {
} from '@lidofinance/lido-ethereum-sdk';

import { config } from 'config';
import { applyRoundUpGasLimit, useDappStatus, useLidoSDK } from 'modules/web3';
import {
applyRoundUpGasLimit,
useAA,
useDappStatus,
useLidoSDK,
useSendAACalls,
} from 'modules/web3';

import { MockLimitReachedError, getRefferalAddress } from './utils';
import { useTxModalStagesStake } from './hooks/use-tx-modal-stages-stake';
Expand All @@ -26,6 +32,8 @@ type StakeOptions = {

export const useStake = ({ onConfirm, onRetry }: StakeOptions) => {
const { address } = useDappStatus();
const { isAA } = useAA();
const sendAACalls = useSendAACalls();
const { stake, stETH } = useLidoSDK();
const { txModalStages } = useTxModalStagesStake();

Expand All @@ -42,11 +50,44 @@ export const useStake = ({ onConfirm, onRetry }: StakeOptions) => {
throw new MockLimitReachedError('Stake limit reached');
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const referralAddress = referral
? await getRefferalAddress(referral, stake.core.rpcProvider)
: config.STAKE_FALLBACK_REFERRAL_ADDRESS;

//
// ERC5792 flow
//
if (isAA) {
const calls: unknown[] = [];
const steth = await stake.getContractStETH();
calls.push({
to: steth.address,
abi: steth.abi,
functionName: 'submit',
args: [referralAddress],
value: amount,
});

txModalStages.sign(amount);
const { txHash } = await sendAACalls(calls, (props) => {
if (props.stage === 'sent')
txModalStages.pending(amount, props.callId as Hash, isAA);
});

const [, balance] = await Promise.all([
onConfirm?.(),
stETH.balance(address),
]);

txModalStages.success(balance, txHash);

return true;
}

//
// Legacy flow
//

let txHash: Hash | undefined = undefined;
const txCallback: TransactionCallback = async ({ stage, payload }) => {
switch (stage) {
Expand Down Expand Up @@ -92,6 +133,15 @@ export const useStake = ({ onConfirm, onRetry }: StakeOptions) => {
return false;
}
},
[address, stake, txModalStages, onConfirm, stETH, onRetry],
[
address,
stake,
isAA,
txModalStages,
sendAACalls,
onConfirm,
stETH,
onRetry,
],
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
External,
Tooltip,
} from '@lidofinance/lido-ui';
import type { LIDO_CONTRACT_NAMES } from '@lidofinance/lido-ethereum-sdk/common';
import { LIDO_CONTRACT_NAMES } from '@lidofinance/lido-ethereum-sdk/common';

import { FormatToken } from 'shared/formatters';
import { useDappStatus, useContractAddress } from 'modules/web3';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const RequestItem = forwardRef<HTMLInputElement, RequestItemProps>(
});

const { data: withdrawalQueueAddress } = useContractAddress(
'withdrawalQueue' as LIDO_CONTRACT_NAMES,
LIDO_CONTRACT_NAMES.withdrawalQueue,
);

const isDisabled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const getTxModalStagesClaim = (transitStage: TransactionModalTransitStage) => ({
<TxStageSignOperationAmount {...STAGE_OPERATION_ARGS} amount={amount} />,
),

pending: (amount: bigint, txHash?: Hash) =>
pending: (amount: bigint, txHash?: Hash, isAA?: boolean) =>
transitStage(
<TxStageSignOperationAmount
{...STAGE_OPERATION_ARGS}
amount={amount}
isAA={isAA}
txHash={txHash}
isPending
/>,
Expand Down
Loading
Loading