Skip to content

[#760] Added rounding down of available ether to valid number for dep… #764

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

julian-st
Copy link
Contributor

Added rounding down of available ether to valid number for deposit contract

see #760

Copy link

netlify bot commented May 13, 2025

👷 Deploy request for dapper-rolypoly-9814ad pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c7efba5

Copy link

netlify bot commented May 13, 2025

👷 Deploy request for phenomenal-frangipane-7c4bd1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c7efba5

Comment on lines 213 to 215
.multipliedBy(1e8)
.integerValue(BigNumber.ROUND_DOWN)
.div(1e8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @julian-st! Thanks for the PR... Few things

For gwei precision we'd want 9 here, and should be able to just use .decimalPlaces(9, BigNumber.ROUND_DOWN)

But, this issue seems to be primarily addressed in the createAddFundsTransaction function:

https://github.com/julian-st/staking-launchpad/blob/0bade1b9f8796fb668e412abc091689fcebb4a6f/src/pages/Actions/components/AddFunds.tsx#L164-L208

  const createAddFundsTransaction = async () => {
    if (!etherAmount || !account) return;

    setTxStatus('waiting_user_confirmation');
    setShowTx(true);

    const walletProvider: provider = await (connector as AbstractConnector).getProvider();
    const web3: Web3Instance = new Web3(walletProvider);
    const contract = new web3.eth.Contract(
      contractAbi,
      DEPOSIT_CONTRACT_ADDRESS
    );
    const bnInput = new BigNumber(etherAmount);
    const transactionAmount = bnInput
      .multipliedBy(1e18) // <-- Change to 1e9?
      .integerValue(BigNumber.ROUND_DOWN); // Convert to Wei and ensure it's an integer
    const reconstructedRootAmount = bnInput
      .multipliedBy(1e9)
      .integerValue(BigNumber.ROUND_DOWN); // Convert to Gwei and ensure it's an integer

    const transactionParameters: SendOptions = {
      gasPrice: web3.utils.toHex(await web3.eth.getGasPrice()),
      from: account as string,
      value: transactionAmount.toFixed(),
    };

    const reconstructedKeyFile = {
      pubkey: bufferHex(validator.pubkey.substring(2)),
      withdrawalCredentials: Buffer.alloc(32),
      amount: reconstructedRootAmount,
      signature: Buffer.alloc(96),
    };

    const byteRoot = depositDataContainer.hashTreeRoot(reconstructedKeyFile);
    const reconstructedDepositDataRoot = `0x${buf2hex(byteRoot)}`;

    contract.methods
      .deposit(
        reconstructedKeyFile.pubkey,
        reconstructedKeyFile.withdrawalCredentials,
        reconstructedKeyFile.signature,
        reconstructedDepositDataRoot
      )
      .send(transactionParameters)

Marked one line with // <-- Change to 1e9? above, which maybe @valefar-on-discord or @remyroy could weigh in on, but I believe that would fix any issues where values with deeper precision than "gwei" are let through to the transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wackerow thanks for the input, I changed it and used the function decimalPlaces

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure, but what about the rest of my comment? I think that would be the cleaner approach

Copy link
Contributor Author

@julian-st julian-st May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed also the decimal value for the transactionAmount. If I changed it to 1e9 wouldn't that convert it to Gwei and change the value down the line and in further handling of the value especially in SendOptions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants