Skip to content

Commit b0f1a1e

Browse files
authored
Merge pull request #149 from lidofinance/feat/rate-limit
Feat/rate limit
2 parents cfc909f + 57ae029 commit b0f1a1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1844
-686
lines changed

contracts/steth.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
import { getContract, createPublicClient, http } from 'viem';
1+
import {
2+
getContract,
3+
createPublicClient,
4+
http,
5+
GetContractReturnType,
6+
WalletClient,
7+
} from 'viem';
28
import { StEthAbi } from 'abi/index.js';
39
import { getChain, getElUrl } from 'configs';
410
import { getLocatorContract } from 'contracts';
511

6-
export const getStethContract = async () => {
12+
export const getStethContract = async (): Promise<
13+
GetContractReturnType<typeof StEthAbi, WalletClient>
14+
> => {
715
const locator = await getLocatorContract();
816
const elUrl = getElUrl();
917
const chain = await getChain();
1018
const address = await locator.read.lido();
1119

1220
return getContract({
13-
address: address,
21+
address,
1422
abi: StEthAbi,
1523
client: createPublicClient({
1624
chain,
1725
transport: http(elUrl),
1826
}),
1927
});
2028
};
29+
30+
export type StethContract = Awaited<ReturnType<typeof getStethContract>>;

features/consolidation.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
Hex,
32
Address,
43
hexToBigInt,
54
decodeFunctionData,
5+
Hex,
66
isHex,
77
formatEther,
88
} from 'viem';
@@ -148,11 +148,13 @@ export const consolidationRequestsAndIncreaseFeeExemption = async ({
148148
if (targetAndSourceValidators.size > 0) {
149149
// 1. Fetch consolidation request encoded calls and increase fee exemption amount encoded call.
150150
const [feeExemptionEncodedCallResult, consolidationRequestEncodedCalls] =
151-
await callReadMethodSilent(
152-
consolidationContract,
153-
'getConsolidationRequestsAndFeeExemptionEncodedCalls',
154-
[sourcePubkeysFlattened, targetPubkeys, dashboard, feeExemption],
155-
);
151+
await callReadMethodSilent({
152+
contract: consolidationContract,
153+
methodName: 'getConsolidationRequestsAndFeeExemptionEncodedCalls',
154+
payload: [
155+
[sourcePubkeysFlattened, targetPubkeys, dashboard, feeExemption],
156+
],
157+
});
156158
feeExemptionEncodedCall = feeExemptionEncodedCallResult;
157159

158160
// 2. Create populated transactions for consolidation requests
@@ -198,11 +200,13 @@ const getConsolidationRequestsAndFeeExemptionEncodedCalls = async (
198200
await getValidatorConsolidationRequestsContract();
199201

200202
const [feeExemptionEncodedCall, consolidationRequestEncodedCalls] =
201-
await callReadMethodSilent(
202-
consolidationContract,
203-
'getConsolidationRequestsAndFeeExemptionEncodedCalls',
204-
[sourcePubkeysFlattened, targetPubkeys, dashboard, feeExemption],
205-
);
203+
await callReadMethodSilent({
204+
contract: consolidationContract,
205+
methodName: 'getConsolidationRequestsAndFeeExemptionEncodedCalls',
206+
payload: [
207+
[sourcePubkeysFlattened, targetPubkeys, dashboard, feeExemption],
208+
],
209+
});
206210
return [feeExemptionEncodedCall, consolidationRequestEncodedCalls];
207211
};
208212

@@ -298,10 +302,11 @@ export const confirmNewFeeExemption = async (
298302
dashboardContract: DashboardContract,
299303
newFeeExemption: bigint,
300304
) => {
301-
const settledGrowth = await callReadMethodSilent(
302-
dashboardContract,
303-
'settledGrowth',
304-
);
305+
const settledGrowth = await callReadMethodSilent({
306+
contract: dashboardContract,
307+
methodName: 'settledGrowth',
308+
payload: [],
309+
});
305310

306311
if (settledGrowth < newFeeExemption) {
307312
return {

features/defi-wrapper/create-vault.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ export const getReserveRatioGapBP = async (
190190

191191
const validateReserveRatioGapBP = async (reserveRatioGapBP: number) => {
192192
const operatorGrid = await getOperatorGridContract();
193-
const defaultTier = await callReadMethodSilent(operatorGrid, 'tier', [0n]);
193+
const defaultTier = await callReadMethodSilent({
194+
contract: operatorGrid,
195+
methodName: 'tier',
196+
payload: [[0n]],
197+
});
194198

195199
if (!defaultTier)
196200
throw new Error(

features/defi-wrapper/pool-info.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ const getStvPoolInfo = async (address: Address) => {
5151
contract.read.getAllowListSize(),
5252
]);
5353

54-
const isDepositsPaused = await callReadMethodSilent(
54+
const isDepositsPaused = await callReadMethodSilent({
5555
contract,
56-
'isFeaturePaused',
57-
[DEPOSITS_FEATURE],
58-
);
56+
methodName: 'isFeaturePaused',
57+
payload: [[DEPOSITS_FEATURE]],
58+
});
59+
5960
const isReportFresh = await reportFreshWarning(vault);
6061

6162
return {
@@ -106,11 +107,11 @@ const getStvStethPoolInfo = async (address: Address) => {
106107
contract.read.MINTING_FEATURE(),
107108
]);
108109

109-
const isMintingPaused = await callReadMethodSilent(
110+
const isMintingPaused = await callReadMethodSilent({
110111
contract,
111-
'isFeaturePaused',
112-
[MINTING_FEATURE],
113-
);
112+
methodName: 'isFeaturePaused',
113+
payload: [[MINTING_FEATURE]],
114+
});
114115

115116
return {
116117
WSTETH,

features/deposits/check-bls-deposits.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export const checkBLSDeposits = async (
66
vaultContract: StakingVaultContract,
77
deposits: Deposit[],
88
) => {
9-
const withdrawalCredentials = await callReadMethod(
10-
vaultContract,
11-
'withdrawalCredentials',
12-
);
9+
const withdrawalCredentials = await callReadMethod({
10+
contract: vaultContract,
11+
methodName: 'withdrawalCredentials',
12+
payload: [],
13+
});
1314

1415
for (const deposit of deposits) {
1516
const isBLSValid = await isValidBLSDeposit(deposit, withdrawalCredentials);
@@ -27,14 +28,16 @@ export const checkBLSWithAmountDeposits = async (
2728
vaultContract: StakingVaultContract,
2829
deposits: Deposit[],
2930
) => {
30-
const PREDEPOSIT_AMOUNT = await callReadMethod(
31-
pdgContract,
32-
'PREDEPOSIT_AMOUNT',
33-
);
34-
const withdrawalCredentials = await callReadMethod(
35-
vaultContract,
36-
'withdrawalCredentials',
37-
);
31+
const PREDEPOSIT_AMOUNT = await callReadMethod({
32+
contract: pdgContract,
33+
methodName: 'PREDEPOSIT_AMOUNT',
34+
payload: [],
35+
});
36+
const withdrawalCredentials = await callReadMethod({
37+
contract: vaultContract,
38+
methodName: 'withdrawalCredentials',
39+
payload: [],
40+
});
3841

3942
for (const deposit of deposits) {
4043
const isBLSValid = await isValidBLSDeposit(deposit, withdrawalCredentials);

features/deposits/make-pdg-proof.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ export const checkValidatorStageAndStagedBalanceForActivation = async (
2121
pdgContract: PredepositGuaranteeContract,
2222
pubkey: Hex,
2323
) => {
24-
const { stage, stakingVault } = await callReadMethodSilent(
25-
pdgContract,
26-
'validatorStatus',
27-
[pubkey],
28-
);
29-
const vaultStagedBalance = await callReadMethodSilent(
30-
await getStakingVaultContract(stakingVault),
31-
'stagedBalance',
32-
);
33-
const ACTIVATION_DEPOSIT_AMOUNT = await callReadMethodSilent(
34-
pdgContract,
35-
'ACTIVATION_DEPOSIT_AMOUNT',
36-
);
24+
const { stage, stakingVault } = await callReadMethodSilent({
25+
contract: pdgContract,
26+
methodName: 'validatorStatus',
27+
payload: [[pubkey]],
28+
});
29+
const vaultStagedBalance = await callReadMethodSilent({
30+
contract: await getStakingVaultContract(stakingVault),
31+
methodName: 'stagedBalance',
32+
payload: [],
33+
});
34+
const ACTIVATION_DEPOSIT_AMOUNT = await callReadMethodSilent({
35+
contract: pdgContract,
36+
methodName: 'ACTIVATION_DEPOSIT_AMOUNT',
37+
payload: [],
38+
});
3739

3840
if (vaultStagedBalance < ACTIVATION_DEPOSIT_AMOUNT) {
3941
throw new Error(

features/deposits/no-pdg.ts

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ export const checkNOBalancePDGforDeposit = async (
1616
) => {
1717
const currentAccount = await getAccount();
1818

19-
const balance = await callReadMethodSilent(
20-
pdgContract,
21-
'nodeOperatorBalance',
22-
[nodeOperator],
23-
);
24-
const unlockedBalance = await callReadMethodSilent(
25-
pdgContract,
26-
'unlockedBalance',
27-
[nodeOperator],
28-
);
29-
const nodeOperatorGuarantor = await callReadMethodSilent(
30-
pdgContract,
31-
'nodeOperatorGuarantor',
32-
[nodeOperator],
33-
);
19+
const balance = await callReadMethodSilent({
20+
contract: pdgContract,
21+
methodName: 'nodeOperatorBalance',
22+
payload: [[nodeOperator]],
23+
});
24+
const unlockedBalance = await callReadMethodSilent({
25+
contract: pdgContract,
26+
methodName: 'unlockedBalance',
27+
payload: [[nodeOperator]],
28+
});
29+
const nodeOperatorGuarantor = await callReadMethodSilent({
30+
contract: pdgContract,
31+
methodName: 'nodeOperatorGuarantor',
32+
payload: [[nodeOperator]],
33+
});
3434
let amountToTopUp = 0n;
3535
let isNeedTopUp = false;
3636

@@ -74,15 +74,16 @@ export const checkNOBalancePDGforDeposits = async (
7474
nodeOperator: Address,
7575
countOfDeposits: number,
7676
) => {
77-
const PREDEPOSIT_AMOUNT = await callReadMethodSilent(
78-
pdgContract,
79-
'PREDEPOSIT_AMOUNT',
80-
);
81-
const unlockedBalance = await callReadMethodSilent(
82-
pdgContract,
83-
'unlockedBalance',
84-
[nodeOperator],
85-
);
77+
const PREDEPOSIT_AMOUNT = await callReadMethodSilent({
78+
contract: pdgContract,
79+
methodName: 'PREDEPOSIT_AMOUNT',
80+
payload: [],
81+
});
82+
const unlockedBalance = await callReadMethodSilent({
83+
contract: pdgContract,
84+
methodName: 'unlockedBalance',
85+
payload: [[nodeOperator]],
86+
});
8687

8788
const amountToTopUp = PREDEPOSIT_AMOUNT * BigInt(countOfDeposits);
8889

@@ -103,10 +104,16 @@ export const checkNodeOperatorOrDepositorForDeposit = async (
103104
pdg: PredepositGuaranteeContract,
104105
) => {
105106
const currentAccount = await getAccount();
106-
const vaultNodeOperator = await callReadMethodSilent(vault, 'nodeOperator');
107-
const noDepositor = await callReadMethodSilent(pdg, 'nodeOperatorDepositor', [
108-
vaultNodeOperator,
109-
]);
107+
const vaultNodeOperator = await callReadMethodSilent({
108+
contract: vault,
109+
methodName: 'nodeOperator',
110+
payload: [],
111+
});
112+
const noDepositor = await callReadMethodSilent({
113+
contract: pdg,
114+
methodName: 'nodeOperatorDepositor',
115+
payload: [[vaultNodeOperator]],
116+
});
110117

111118
if (
112119
noDepositor.toLocaleLowerCase() !==
@@ -126,10 +133,16 @@ export const checkAndSpecifyNodeOperatorForTopUpOrWithdraw = async (
126133
isTopUp: boolean,
127134
) => {
128135
const currentAccount = await getAccount();
129-
const vaultNodeOperator = await callReadMethodSilent(vault, 'nodeOperator');
130-
const noGuarantor = await callReadMethodSilent(pdg, 'nodeOperatorGuarantor', [
131-
vaultNodeOperator,
132-
]);
136+
const vaultNodeOperator = await callReadMethodSilent({
137+
contract: vault,
138+
methodName: 'nodeOperator',
139+
payload: [],
140+
});
141+
const noGuarantor = await callReadMethodSilent({
142+
contract: pdg,
143+
methodName: 'nodeOperatorGuarantor',
144+
payload: [[vaultNodeOperator]],
145+
});
133146

134147
const isNoGuarantor =
135148
noGuarantor.toLocaleLowerCase() ===
@@ -164,11 +177,11 @@ export const getGuarantor = async (
164177
pdgContract: PredepositGuaranteeContract,
165178
) => {
166179
const currentAccount = await getAccount();
167-
const balance = await callReadMethodSilent(
168-
pdgContract,
169-
'nodeOperatorBalance',
170-
[currentAccount.address],
171-
);
180+
const balance = await callReadMethodSilent({
181+
contract: pdgContract,
182+
methodName: 'nodeOperatorBalance',
183+
payload: [[currentAccount.address]],
184+
});
172185

173186
if (balance.locked > 0n) {
174187
throw new Error(

features/deposits/pdg.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export const checkPdgIsPaused = async (
99
const chain = await getChain();
1010
const isMainnet = chain.id === mainnet.id;
1111

12-
const isPaused = await callReadMethodSilent(pdgContract, 'isPaused');
12+
const isPaused = await callReadMethodSilent({
13+
contract: pdgContract,
14+
methodName: 'isPaused',
15+
payload: [],
16+
});
1317

1418
if (isPaused) {
1519
const message = isMainnet

features/dev-tools/impersonate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export const grantRoleFromImpersonatedAccount = async ({
5454
args: [role, currentAccount],
5555
});
5656

57-
const roleMembersAfter = await callReadMethodSilent(
58-
contract,
59-
'getRoleMembers',
60-
[role],
61-
);
57+
const roleMembersAfter = await callReadMethodSilent({
58+
contract: contract,
59+
methodName: 'getRoleMembers',
60+
payload: [[role]],
61+
});
6262
logInfo('Role members after granting: ', roleMembersAfter);
6363
if (!roleMembersAfter.includes(currentAccount)) {
6464
logInfo(`Address ${currentAccount} does not have the ${roleName} role`);

0 commit comments

Comments
 (0)