---
# System prepended metadata

title: Untitled

---

Rage quit and full withdrawal for Solo staker

```
const rageQuitTest = async () => {

    const provider = new ethers.providers.InfuraProvider("goerli", {
        projectId: INFURA_PROJECT_ID,
        projectSecret: INFURA_PROJECT_SECRET
    });
    // const provider = new ethers.providers.JsonRpcProvider(`https://rpc.tenderly.co/fork/50699573-60b4-4241-8f3d-8929a6f28261`);
    const signer = new ethers.Wallet(PRIV_KEY_1, provider);

    const sdk = new StakehouseSDK(signer);

    const blsPublicKey = "0xa33a8dba7796fcea62dad3a4fda273668dc8c4c245c1201768a0c82876b82481e9a714d6b83169717dfdfaa991f669a1";
    const stakehouseAddress = "0x02efe99002854e3ec762cf99ab7146a694232c56";

    // const contract  = new ethers.Contract(
    //     '0x4aCB708eb8Def5D66Ff8Da7EE4796C4B3EDb44A4',//full withdr
    //     require("./full_withdrawal.json"),
    //     signer
    // )

    // console.log('sweepReportingContract', await contract.sweepReportingContract())

    // return;

    const finalisedReport = await sdk.balanceReport.getFinalisedEpochReport(BEACON_NODE, blsPublicKey);
    console.log("finalisedReport: ", finalisedReport);

    // let authenticatedReport = await sdk.balanceReport.authenticateReport(BEACON_NODE, finalisedReport);
    // console.log("authenticatedReport: ", authenticatedReport);

    // const exitFee = await sdk.utils.calculateExitFee(blsPublicKey);
    // console.log("exitFee: ", exitFee.toString());

    // const rageQuitTx = await sdk.rageQuitKnot(stakehouseAddress, authenticatedReport, ADDRESS_1, "0");
    // console.log("rageQuitTx: ", rageQuitTx);
    // return;

    // The BLS public key has already exited Beacon chain, hence no need of broadcasting and voluntary withdrawal
    // Next step is to execute full withdrawal

    // NOTE: Do rage quit before final withdrawal

    const validatorIndex = finalisedReport.validatorIndex;
    console.log("validatorIndex: ", validatorIndex);

    const totalETHSentToBLSPublicKey = await sdk.balanceReport.getTotalETHSentToBlsKey(blsPublicKey);
    // const totalETHSentToBLSPublicKey = "32000000000";
    console.log("totalETHSentToBLSPublicKey: ", totalETHSentToBLSPublicKey.toString());

    let sweeps = await sdk.balanceReport.getDETHSweeps(validatorIndex, "5196198", "5625937");
    console.log("dETHSweeps: ", sweeps);

    let sweep = sweeps.sweeps;
    for(let i=0; i<4; ++i) sweep.shift(); 
    sweep.pop();
    sweeps.sweeps = sweep;
    console.log("sweeps: ", sweeps);

    const sumOfSweeps = sdk.balanceReport.calculateSumOfSweeps(sweeps.sweeps);

    // const sumOfSweeps = "32107424935";
    console.log("sumOfSweeps: ", sumOfSweeps.toString());

    /*
    Sweep struct {
        // Sweeps can be reported out of order apart from validators part of the set pre-shanghai
        uint256 withdrawalIndex;
        uint256 validatorIndex;
        address recipient; // account manager
        uint256 amount;
    }
    */

    const finalSweep = {
        "sweep": {
            "index": "5414948",
            "validatorIndex": "387117",
            "recipient": "0x952295078A226bF40c8cb076C16E0e7229F77B28",
            "amount": "32000000000"
        },
        "slot": "5625937",
        "block": "8995315"
    }

    let finalReport = await sdk.balanceReport.generateFinalReport(
        BEACON_NODE,
        blsPublicKey,
        totalETHSentToBLSPublicKey,
        sumOfSweeps,
        sweeps,
        finalSweep
    );

    console.log("sweep length: ", sweeps.sweeps.length);

    console.log("totalETHSentToBLSPublicKey: ", totalETHSentToBLSPublicKey);
    console.log("blsPublicKey: ", blsPublicKey);
    console.log("finalisedReport: ", finalisedReport);
    console.log("sumOfSweeps: ", sumOfSweeps);
    console.log("sweeps.sweeps: ", sweeps.sweeps);

    finalReport.blsPublicKey = sdk.utils.remove0x(finalReport.blsPublicKey);
    finalReport.totalETHSentToBLSKey = totalETHSentToBLSPublicKey.toString();
    finalReport.sumOfUnreportedSweeps = sumOfSweeps.toString();
    finalReport.unreportedSweeps = await sdk.balanceReport.formatSweepReport(sweeps.sweeps, validatorIndex);

    console.log("finalReport: ", finalReport);

    // totalETHSentToBLSPublicKey,
    //     blsPublicKey,
    //     finalisedReport,
    //     sumOfSweeps,
    //     sweeps.sweeps
    // const verifyFinalReport = await sdk.balanceReport.verifyFinalReport(
    //     finalReport,
    //     finalisedReport
    // );
    // console.log("verifyFinalReport: ", verifyFinalReport);

    const depositRouterfinalReport = {
        "validatorInfo": {
            "blsPublicKey": "a33a8dba7796fcea62dad3a4fda273668dc8c4c245c1201768a0c82876b82481e9a714d6b83169717dfdfaa991f669a1",
            "validatorIndex": "387117",
            "withdrawalCredentials": "010000000000000000000000952295078a226bf40c8cb076c16e0e7229f77b28",
            "slashed": false,
            "activeBalance": "0",
            "effectiveBalance": "0",
            "exitEpoch": "175497",
            "activationEpoch": "123432",
            "withdrawalEpoch": "175753",
            "currentCheckpointEpoch": 179537
        },
        "finalSweep": {
            "sweep": {
                "withdrawalIndex": "5414948",
                "validatorIndex": "387117",
                "recipient": "0x952295078A226bF40c8cb076C16E0e7229F77B28",
                "amount": "32000000000"
            },
            "slot": "5625937",
            "block": "8995315"
        },
        "designatedVerifierSignature": {
            "deadline": 9091415,
            "v": 27,
            "r": "0x504ef75b7b840910b3fc1e601c93fe611150d16c753319fb3f449919f4da2ba4",
            "s": "0x35683d918c95b673ee67d0ace7ca1295f16980fde6c16b039619c206bd690688"
        }
    }

    // const authenticatedReport = await sdk.balanceReport.authenticateReport(BEACON_NODE, finalisedReport);

    // authenticatedReport.report.blsPublicKey = _add0x(authenticatedReport.report.blsPublicKey);
    // authenticatedReport.report.withdrawalCredentials = _add0x(authenticatedReport.report.withdrawalCredentials);

    // const signature = {
    //     deadline: authenticatedReport.deadline,
    //     v: authenticatedReport.v,
    //     r: Buffer.from(authenticatedReport.r, 'hex'),
    //     s: Buffer.from(authenticatedReport.s, 'hex'),
    // };

    // const contract  = new ethers.Contract(
    //     '0x4aCB708eb8Def5D66Ff8Da7EE4796C4B3EDb44A4',//full withdr
    //     require("./full_withdrawal.json"),
    //     signer
    // )
    // console.log("contract: ", contract.address);
    // console.log("signer: ", signer);

    // console.log("totalETHSentToBLSPublicKey: ", totalETHSentToBLSPublicKey);
    // console.log("blsPublicKey: ", authenticatedReport.report.blsPublicKey);
    // console.log("unreportedSweeps: ", sweeps.sweeps);
    // console.log("finalSweep: ", finalSweep);
    // console.log("report: ", authenticatedReport.report);
    // console.log("signature: ", signature);

    // const inputParams = [
    //     totalETHSentToBLSPublicKey,
    //     authenticatedReport.report.blsPublicKey,
    //     sweeps.sweeps,
    //     finalSweep,
    //     authenticatedReport.report,
    //     signature
    // ];

    // const fullWithdrawalTx = await contract.reportFinalSweepAndWithdraw(
    //     totalETHSentToBLSPublicKey,
    //     authenticatedReport.report.blsPublicKey,
    //     sweeps.sweeps,
    //     finalSweep,
    //     authenticatedReport.report,
    //     signature
    // );

    const sweepReport = await sdk.balanceReport.formatSweepReport(sweeps.sweeps, finalisedReport.validatorIndex);
    console.log("sweepReport: ", sweepReport);

    const fullWithdrawalTx = await sdk.withdrawal.reportFinalSweepAndWithdraw(
        totalETHSentToBLSPublicKey,
        sweepReport,
        depositRouterfinalReport.finalSweep,
        depositRouterfinalReport
    );
    console.log("fullWithdrawalTx: ", fullWithdrawalTx);

    return;

    /*
        NOTE:
        1) User broadcasts voluntary exit
        2) Voluntary withdrawal to be reported on tx router (LSD requires to report before voluntary withdrawal)
        3) rage quit (LSD  - rage quit assistant) has recipient param that receives ETH and **can only call full withdrawal**
        4) sweep and full withdrawal
        5) Unstaking/ claiming

    */
};

rageQuitTest();
```