Skip to content

Commit

Permalink
fix: negative rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Feb 11, 2025
1 parent 9e4e49e commit 667791a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"test:integration": "hardhat test test/integration/**/*.ts",
"test:integration:trace": "hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:fulltrace": "hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:scratch": "INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts",
"test:integration:scratch:trace": "INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:scratch:fulltrace": "INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:scratch": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts",
"test:integration:scratch:trace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:scratch:fulltrace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:fork:local": "hardhat test test/integration/**/*.ts --network local",
"test:integration:fork:mainnet": "hardhat test test/integration/**/*.ts --network mainnet-fork",
"test:integration:fork:mainnet:custom": "hardhat test --network mainnet-fork",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ import { ethers } from "hardhat";
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import { setBalance } from "@nomicfoundation/hardhat-network-helpers";

import { ether, impersonate } from "lib";
import { ether } from "lib";
import { getProtocolContext, ProtocolContext } from "lib/protocol";
import { report } from "lib/protocol/helpers/accounting";
import { norEnsureOperators } from "lib/protocol/helpers/nor";
import { finalizeWithdrawalQueue } from "lib/protocol/helpers/withdrawal";
import { report } from "lib/protocol/helpers";

import { Snapshot } from "test/suite";

describe("Negative rebase", () => {
let ctx: ProtocolContext;
let beforeSnapshot: string;
let beforeEachSnapshot: string;
let ethHolder, stEthHolder: HardhatEthersSigner;
let ethHolder: HardhatEthersSigner;

before(async () => {
beforeSnapshot = await Snapshot.take();
ctx = await getProtocolContext();

[ethHolder, stEthHolder] = await ethers.getSigners();
[ethHolder] = await ethers.getSigners();
await setBalance(ethHolder.address, ether("1000000"));
const network = await ethers.provider.getNetwork();
console.log("network", network.name);

// In case of sepolia network, transfer some BEPOLIA tokens to the adapter contract
if (network.name == "sepolia" || network.name == "sepolia-fork") {
const sepoliaDepositContractAddress = "0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D";
const bepoliaWhaleHolder = "0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134";
Expand All @@ -37,35 +36,11 @@ describe("Negative rebase", () => {
const adapterAddr = await ctx.contracts.stakingRouter.DEPOSIT_CONTRACT();
await bepoliaToken.connect(bepiloaSigner).transfer(adapterAddr, BEPOLIA_TO_TRANSFER);
}
const beaconStat = await ctx.contracts.lido.getBeaconStat();
if (beaconStat.beaconValidators == 0n) {
const MAX_DEPOSIT = 150n;
const CURATED_MODULE_ID = 1n;
const ZERO_HASH = new Uint8Array(32).fill(0);
const { lido, depositSecurityModule } = ctx.contracts;

await finalizeWithdrawalQueue(ctx, stEthHolder, ethHolder);

await norEnsureOperators(ctx, 3n, 5n);

const dsmSigner = await impersonate(depositSecurityModule.address, ether("100"));
await lido.connect(dsmSigner).deposit(MAX_DEPOSIT, CURATED_MODULE_ID, ZERO_HASH);

await report(ctx, {
clDiff: ether("32") * 3n,
clAppearedValidators: 3n,
excludeVaultsBalances: true,
});
}
});

after(async () => {
await Snapshot.restore(beforeSnapshot);
});
after(async () => await Snapshot.restore(beforeSnapshot));

beforeEach(async () => {
beforeEachSnapshot = await Snapshot.take();
});
beforeEach(async () => (beforeEachSnapshot = await Snapshot.take()));

afterEach(async () => await Snapshot.restore(beforeEachSnapshot));

Expand Down Expand Up @@ -104,7 +79,6 @@ describe("Negative rebase", () => {

expect(lastReportData.totalExitedValidators).to.be.equal(lastExitedTotal + 2n);
expect(beforeLastReportData.totalExitedValidators).to.be.equal(lastExitedTotal);

});

it("Should store correctly many negative rebases", async () => {
Expand Down

0 comments on commit 667791a

Please sign in to comment.