-
Notifications
You must be signed in to change notification settings - Fork 220
[#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
base: dev
Are you sure you want to change the base?
Conversation
… for deposit contract
👷 Deploy request for dapper-rolypoly-9814ad pending review.Visit the deploys page to approve it
|
👷 Deploy request for phenomenal-frangipane-7c4bd1 pending review.Visit the deploys page to approve it
|
.multipliedBy(1e8) | ||
.integerValue(BigNumber.ROUND_DOWN) | ||
.div(1e8) |
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Added rounding down of available ether to valid number for deposit contract
see #760