Skip to content

Commit

Permalink
Merge pull request #470 from lidofinance/develop
Browse files Browse the repository at this point in the history
eth_call allow list
  • Loading branch information
Jeday authored Sep 12, 2024
2 parents 4ae8ab1 + 507d7a1 commit 9bbe780
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 16 deletions.
135 changes: 135 additions & 0 deletions abi/lidoLocator.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "implementation_",
"type": "address"
},
{ "internalType": "address", "name": "admin_", "type": "address" },
{ "internalType": "bytes", "name": "data_", "type": "bytes" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{ "inputs": [], "name": "NotAdmin", "type": "error" },
{ "inputs": [], "name": "ProxyIsOssified", "type": "error" },
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "previousAdmin",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "newAdmin",
"type": "address"
}
],
"name": "AdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "beacon",
"type": "address"
}
],
"name": "BeaconUpgraded",
"type": "event"
},
{
"anonymous": false,
"inputs": [],
"name": "ProxyOssified",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
},
{ "stateMutability": "payable", "type": "fallback" },
{
"inputs": [
{ "internalType": "address", "name": "newAdmin_", "type": "address" }
],
"name": "proxy__changeAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "proxy__getAdmin",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proxy__getImplementation",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proxy__getIsOssified",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proxy__ossify",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newImplementation_",
"type": "address"
}
],
"name": "proxy__upgradeTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newImplementation_",
"type": "address"
},
{ "internalType": "bytes", "name": "setupCalldata_", "type": "bytes" },
{ "internalType": "bool", "name": "forceCall_", "type": "bool" }
],
"name": "proxy__upgradeToAndCall",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "stateMutability": "payable", "type": "receive" }
]
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 @@ import { parseEther } from '@ethersproject/units';
export const PROVIDER_POLLING_INTERVAL = 12_000;
// how long in ms to wait for RPC batching(multicall and provider)
export const PROVIDER_BATCH_TIME = 150;
// max batch
export const PROVIDER_MAX_BATCH = 10;

// account for gas estimation
// will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH
Expand Down
2 changes: 1 addition & 1 deletion features/rewards/hooks/use-steth-eth-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PartialCurveAbiAbi__factory } from 'generated';
import { createContractGetter } from '@lido-sdk/contracts';

const getCurveContract = createContractGetter(PartialCurveAbiAbi__factory);
const MAINNET_CURVE = '0xDC24316b9AE028F1497c275EB9192a3Ea0f67022';
export const MAINNET_CURVE = '0xDC24316b9AE028F1497c275EB9192a3Ea0f67022';

export const useStethEthRate = () => {
const { chainId } = useSDK();
Expand Down
28 changes: 20 additions & 8 deletions pages/api/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { rpcFactory } from '@lidofinance/next-pages';
import { CHAINS } from '@lido-sdk/constants';
import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper';
import { trackedFetchRpcFactory } from '@lidofinance/api-rpc';
Expand All @@ -15,17 +14,34 @@ import {
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { rpcFactory } from 'utilsApi/rpcFactory';
import { METRIC_CONTRACT_ADDRESSES } from 'utilsApi/contractAddressesMetricsMap';

const allowedCallAddresses: Record<string, string[]> = Object.entries(
METRIC_CONTRACT_ADDRESSES,
).reduce(
(acc, [chainId, addresses]) => {
acc[chainId] = Object.keys(addresses);
return acc;
},
{} as Record<string, string[]>,
);

const rpc = rpcFactory({
fetchRPC: trackedFetchRpcFactory({
registry: Metrics.registry,
prefix: METRICS_PREFIX,
}),
serverLogger: console,
metrics: {
prefix: METRICS_PREFIX,
registry: Metrics.registry,
},
defaultChain: `${config.defaultChain}`,
providers: {
[CHAINS.Mainnet]: secretConfig.rpcUrls_1,
[CHAINS.Holesky]: secretConfig.rpcUrls_17000,
[CHAINS.Sepolia]: secretConfig.rpcUrls_11155111,
},
allowedRPCMethods: [
'test',
'eth_call',
Expand All @@ -44,12 +60,8 @@ const rpc = rpcFactory({
'eth_chainId',
'net_version',
],
defaultChain: `${config.defaultChain}`,
providers: {
[CHAINS.Mainnet]: secretConfig.rpcUrls_1,
[CHAINS.Holesky]: secretConfig.rpcUrls_17000,
[CHAINS.Sepolia]: secretConfig.rpcUrls_11155111,
},
allowedCallAddresses,
maxBatchCount: 10,
});

export default wrapNextRequest([
Expand Down
6 changes: 1 addition & 5 deletions providers/web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ const Web3Provider: FC<PropsWithChildren> = ({ children }) => {
chains: supportedChains,
ssr: true,
connectors: [],

batch: {
// eth_call's can be batched via multicall contract
multicall: {
wait: config.PROVIDER_BATCH_TIME,
},
multicall: false,
},
multiInjectedProviderDiscovery: false,
pollingInterval: config.PROVIDER_POLLING_INTERVAL,
Expand Down
10 changes: 8 additions & 2 deletions utils/use-web3-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ export const useWeb3Transport = (
({ transportMap, setTransportMap }, chain) => {
const [transport, setTransport] = runtimeMutableTransport([
http(backendRpcMap[chain.id], {
batch: { wait: config.PROVIDER_BATCH_TIME },
batch: {
wait: config.PROVIDER_BATCH_TIME,
batchSize: config.PROVIDER_MAX_BATCH,
},
name: backendRpcMap[chain.id],
}),
http(undefined, {
batch: { wait: config.PROVIDER_BATCH_TIME },
batch: {
wait: config.PROVIDER_BATCH_TIME,
batchSize: config.PROVIDER_MAX_BATCH,
},
name: 'default HTTP RPC',
}),
]);
Expand Down
25 changes: 25 additions & 0 deletions utilsApi/contractAddressesMetricsMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ import {

import { config } from 'config';
import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator';
import {
PartialCurveAbiAbi__factory,
PartialStakingRouterAbi__factory,
LidoLocatorAbi__factory,
} from 'generated';
import { getStakingRouterAddress } from 'consts/staking-router';
import { MAINNET_CURVE } from 'features/rewards/hooks/use-steth-eth-rate';
import { LIDO_LOCATOR_BY_CHAIN } from '@lidofinance/lido-ethereum-sdk';

export const CONTRACT_NAMES = {
stETH: 'stETH',
wstETH: 'wstETH',
WithdrawalQueue: 'WithdrawalQueue',
Aggregator: 'Aggregator',
AggregatorStEthUsdPriceFeed: 'AggregatorStEthUsdPriceFeed',
StakingRouter: 'StakingRouter',
StethCurve: 'StethCurve',
LidoLocator: 'LidoLocator',
} as const;
export type CONTRACT_NAMES = keyof typeof CONTRACT_NAMES;

Expand All @@ -33,6 +44,9 @@ export const METRIC_CONTRACT_ABIS = {
[CONTRACT_NAMES.WithdrawalQueue]: WithdrawalQueueAbiFactory.abi,
[CONTRACT_NAMES.Aggregator]: AggregatorAbiFactory.abi,
[CONTRACT_NAMES.AggregatorStEthUsdPriceFeed]: AggregatorAbiFactory.abi,
[CONTRACT_NAMES.StakingRouter]: PartialStakingRouterAbi__factory.abi,
[CONTRACT_NAMES.StethCurve]: PartialCurveAbiAbi__factory.abi,
[CONTRACT_NAMES.LidoLocator]: LidoLocatorAbi__factory.abi,
} as const;

export const getMetricContractInterface = memoize(
Expand Down Expand Up @@ -82,6 +96,17 @@ export const METRIC_CONTRACT_ADDRESSES = (
getAggregatorStEthUsdPriceFeedAddress,
chainId,
),
[CONTRACT_NAMES.StakingRouter]: getAddressOrNull(
getStakingRouterAddress,
chainId,
),
[CONTRACT_NAMES.StethCurve]: getAddressOrNull((chainId: CHAINS) => {
if (chainId === 1) return MAINNET_CURVE;
else throw new Error('no contract address');
}, chainId),
[CONTRACT_NAMES.LidoLocator]: getAddressOrNull((chainId: CHAINS) => {
return (LIDO_LOCATOR_BY_CHAIN as any)[chainId] as string;
}, chainId),
};
return {
...mapped,
Expand Down
Loading

0 comments on commit 9bbe780

Please sign in to comment.