-
Notifications
You must be signed in to change notification settings - Fork 12
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
refactor: migrate to new SDK, to bigint, to viem, to react-query (DRAFT) #543
base: develop
Are you sure you want to change the base?
refactor: migrate to new SDK, to bigint, to viem, to react-query (DRAFT) #543
Conversation
utilsApi/nextApiWrappers.ts
Outdated
@@ -30,6 +30,27 @@ export enum HttpMethod { | |||
PATCH = 'PATCH', | |||
} | |||
|
|||
export const getFunctionSelector = (func: any): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also recheck other parts of this code, might have more viem helpers that we can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked. seems it all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Here, we can use it without initializeMetricContractAddresses(), | ||
// as initializeMetricContractAddresses() was already called in pages/api/rpc.ts. | ||
// However, be careful when reusing this code. | ||
const contractName = METRIC_CONTRACT_ADDRESSES?.[chainId]?.[address]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment actual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
abi: Abi, | ||
methodEncoded: string, | ||
): string | null => { | ||
for (const item of abi) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code reparses the abi on every run, we need some sort of caching for selector->method Name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be out of scope since older code is like this, pls create task for this
utilsApi/metrics/startup-metrics.ts
Outdated
@@ -20,6 +20,7 @@ const collectStartupChecksRPCMetrics = async ( | |||
const rpcChecksResults = await getRPCChecks(); | |||
|
|||
if (!rpcChecksResults) { | |||
// You will see this on 'yarn dev' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then disable this for dev env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils/formatBalance.ts
Outdated
@@ -64,7 +70,7 @@ export const formatBalance = ( | |||
}; | |||
|
|||
export const useFormattedBalance: typeof formatBalance = ( | |||
balance = Zero, | |||
balance = ZERO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
enabled: wsteth != null && !!(isL2 ? l2.steth : shares), | ||
staleTime: Infinity, | ||
queryFn: () => { | ||
if (wsteth == null) return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this creates unnecessary footgun, invariants solve this by being easily detectable.
import { STRATEGY_CONSTANT } from 'consts/react-query-strategies'; | ||
import { useLidoSDK } from 'modules/web3'; | ||
|
||
export const useContractAddress = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make this hook sync, it will be easier for other code. IMO static addresses are okay for non-critical func.
Also consider checking where this hook is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that for the moment we can leave it as is. Let's make it synchronous as soon as we need it
modules/web3/consts/units.ts
Outdated
|
||
export const ONE_stETH = parseEther('1'); | ||
|
||
export const ZERO = parseEther('0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that just 0n, let's remove this const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
import { applyGasLimitRatio } from 'utils/apply-gas-limit-ratio'; | ||
import { useDappStatus, useLidoSDK, ZERO, ESTIMATE_AMOUNT } from 'modules/web3'; | ||
|
||
const fetchGasLimitETH = async (isL2: boolean, wrap: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why any? can use LidoSDKWrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misprint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
features/rewards/constants.ts
Outdated
@@ -1,4 +1,5 @@ | |||
export const ETHER = '1e18'; | |||
// 1e18 | |||
export const ETHER = 1_000_000_000_000_000_000n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseEther('1')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1,11 +1,14 @@ | |||
import { useCallback } from 'react'; | |||
import { useForm } from 'react-hook-form'; | |||
import { Address } from 'viem'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
features/stake/stake-form/hooks.ts
Outdated
queryKey: ['submit-gas-limit', stake.core.chainId], | ||
enabled: !!stake.core && !!stake.core.chainId, | ||
...STRATEGY_CONSTANT, | ||
queryFn: async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have estimateGas in sdk.stake as method
break; | ||
} | ||
case TransactionCallbackStage.MULTISIG_DONE: | ||
txModalStages.successMultisig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we DRY this between different TXs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an idea, but it seems we could lose a lot in code readability. I think this boilerplate code is useful. what do you think about this?
…rtedChainsWithMainnet crutch
Description
Migrate from BigNumber to bigint.
Migrate from old SDK to the new SDK.
Operations:
work through the new SDK.
Requests for:
are taken through the functionality of the new SDK.
Migrate from SWR to 'react-query'.
Removed the typechain package.
Now
*abi.ts
files are used (in some cases with too much interface description).Migrate from
ethers
toviem
and removed packages:ethers
,@ethersproject/*
.APR fallback: if ETH-API is not available, then SDK is used.
Unused code has been removed.
There was a reduction in the number of lines of code.
Code review notes
...
Testing notes
The whole widget
Checklist: