Skip to content

Commit

Permalink
feat: make 'stETH to wstETH' operation on L2
Browse files Browse the repository at this point in the history
  • Loading branch information
solidovic committed Sep 26, 2024
1 parent fbda9a8 commit 34b463c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
39 changes: 19 additions & 20 deletions features/wsteth/wrap/hooks/use-wrap-form-processing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback } from 'react';
import invariant from 'tiny-invariant';
import { useAccount } from 'wagmi';
import { parseEther } from 'viem';

import { useSDK, useWSTETHContractRPC } from '@lido-sdk/react';

import { CHAINS, isSDKSupportedL2Chain } from 'consts/chains';
import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider';
import { runWithTransactionLogger } from 'utils';
import { isContract } from 'utils/isContract';
Expand All @@ -14,7 +14,7 @@ import type {
WrapFormApprovalData,
WrapFormInputType,
} from '../wrap-form-context';
// import { useWrapTxProcessing } from './use-wrap-tx-processing';
import { useWrapTxProcessing } from './use-wrap-tx-processing';
import { useTxModalWrap } from './use-tx-modal-stages-wrap';
import { useLidoSDK } from '../../../../providers/lido-sdk';

Expand All @@ -29,13 +29,13 @@ export const useWrapFormProcessor = ({
onConfirm,
onRetry,
}: UseWrapFormProcessorArgs) => {
const { address } = useAccount();
const { address, chainId } = useAccount();
const { providerWeb3 } = useSDK();
const { staticRpcProvider } = useCurrentStaticRpcProvider();
const wstETHContractRPC = useWSTETHContractRPC();

const { txModalStages } = useTxModalWrap();
// const processWrapTx = useWrapTxProcessing();
const processWrapTx = useWrapTxProcessing();

const { l2 } = useLidoSDK();

Expand Down Expand Up @@ -72,22 +72,19 @@ export const useWrapFormProcessor = ({

txModalStages.sign(amount, token, willReceive);

// console.log('address:', address);
// console.log('amount:', amount);
// console.log('amount.toString():', amount.toString());

const tx = await l2.unwrap({
// account: address,
// value: amount,
value: parseEther('0.0001'),
});
// console.log('tx:', tx);
const txHash = tx.hash;
// console.log('txHash:', txHash);

// const txHash = await runWithTransactionLogger('Wrap signing', () =>
// processWrapTx({ amount, token, isMultisig }),
// );
let txHash;
if (isSDKSupportedL2Chain(chainId as CHAINS)) {
// The operation 'stETH to wstETH' on L2 is unwrap
const tx = await l2.unwrap({
// value: amount.toString(), <- Not working
value: amount.toBigInt(),
});
txHash = tx.hash;
} else {
txHash = await runWithTransactionLogger('Wrap signing', () =>
processWrapTx({ amount, token, isMultisig }),
);
}

if (isMultisig) {
txModalStages.successMultisig();
Expand All @@ -114,6 +111,7 @@ export const useWrapFormProcessor = ({
}
},
[
chainId,
address,
providerWeb3,
staticRpcProvider,
Expand All @@ -123,6 +121,7 @@ export const useWrapFormProcessor = ({
l2,
onConfirm,
processApproveTx,
processWrapTx,
waitForTx,
onRetry,
],
Expand Down
6 changes: 3 additions & 3 deletions providers/lido-sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export const LidoSDKProvider = ({ children }: React.PropsWithChildren) => {

const l2 = new LidoSDKL2({
chainId,
logMode: 'debug',
rpcProvider: publicClient2 as any,
web3Provider: walletClient2 as any,
logMode: 'info',
rpcProvider: publicClient2,
web3Provider: walletClient2,
// viem client can be unavailable on ipfs+dev first renders
// rpcUrls: !publicClient && fallbackRpcUrl ? [fallbackRpcUrl] : undefined,
});
Expand Down

0 comments on commit 34b463c

Please sign in to comment.