From bab7b199a17a6b74b6bdf185a20a4abaddd028de Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Sat, 5 Aug 2023 17:28:47 -0600 Subject: [PATCH] Update batch deposit script for post-shapella deposits --- scripts/.env.example | 12 +++--------- scripts/Dockerfile | 2 +- scripts/deposit.js | 31 ++++++++++++++++--------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/scripts/.env.example b/scripts/.env.example index e8b9279..8579ffe 100644 --- a/scripts/.env.example +++ b/scripts/.env.example @@ -1,7 +1,7 @@ STAKING_ACCOUNT_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000 -RPC_URL=https://dai.poa.network -GAS_PRICE=1000000000 +RPC_URL=https://rpc.gnosischain.com +GAS_PRICE=2000000000 # number of deposits in one transaction, should be in range [1, 128] # NOTE: put 1 here if withdrawal credentials were generated with the BLS12-381 keys @@ -11,14 +11,8 @@ N=256 # index of the first deposit to read from file OFFSET=0 -# address of the wrapped mGNO token, leave this option only if you want to deposit wrapped mGNO tokens -META_TOKEN_ADDRESS=0x722fc4DAABFEaff81b97894fC623f91814a1BF68 -# specify these options only if you want to deposit unwrapped GNO tokens # address of the GNO token -# TOKEN_ADDRESS=0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb -# address of the GBC wrapper contract -# WRAPPER_ADDRESS=0x647507A70Ff598F386CB96ae5046486389368C66 - +TOKEN_ADDRESS=0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb # address of the GBC deposit contract DEPOSIT_CONTRACT_ADDRESS=0x0B98057eA310F4d31F2a452B414647007d1645d9 # block where the deposit contract was deployed at diff --git a/scripts/Dockerfile b/scripts/Dockerfile index c58d67e..4bf7827 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,4 +1,4 @@ -FROM node:14 +FROM node:20 LABEL org.opencontainers.image.source "https://github.com/gnosischain/deposit-contract" diff --git a/scripts/deposit.js b/scripts/deposit.js index 3742510..c8555ec 100644 --- a/scripts/deposit.js +++ b/scripts/deposit.js @@ -12,9 +12,7 @@ const { OFFSET, START_BLOCK_NUMBER, SKIP_PREVIOUS_DEPOSITS_CHECK, - WRAPPER_ADDRESS, TOKEN_ADDRESS, - META_TOKEN_ADDRESS, DEPOSIT_CONTRACT_ADDRESS, } = process.env @@ -27,18 +25,8 @@ const batchSize = parseInt(BATCH_SIZE, 10) const offset = parseInt(OFFSET, 10) const n = parseInt(N, 10) async function main() { - const useMetaTokenDeposit = !!META_TOKEN_ADDRESS && !WRAPPER_ADDRESS && !TOKEN_ADDRESS - const useWrapAndDeposit = !META_TOKEN_ADDRESS && !!WRAPPER_ADDRESS && !!TOKEN_ADDRESS - if (useMetaTokenDeposit === useWrapAndDeposit) { - console.log('Specify either a single META_TOKEN_ADDRESS variable for depositing mGNO directly, ' + - 'or specify both WRAPPER_ADDRESS and TOKEN_ADDRESS variables for depositing GNO without manual mGNO conversion.') - return - } - const depositContract = new web3.eth.Contract(depositABI, DEPOSIT_CONTRACT_ADDRESS) - const receiver = useWrapAndDeposit ? WRAPPER_ADDRESS : DEPOSIT_CONTRACT_ADDRESS - const tokenAddress = useWrapAndDeposit ? TOKEN_ADDRESS : META_TOKEN_ADDRESS - const token = new web3.eth.Contract(abi, tokenAddress) + const token = new web3.eth.Contract(abi, TOKEN_ADDRESS) const deposits = depositData.slice(offset, offset + n) if (batchSize > 1) { @@ -57,7 +45,7 @@ async function main() { return } - const depositAmountBN = web3.utils.toBN(useWrapAndDeposit ? 1 : 32).mul(web3.utils.toBN('1000000000000000000')) + const depositAmountBN = web3.utils.toWei(web3.utils.toBN(1)) const totalDepositAmountBN = depositAmountBN.muln(deposits.length) const tokenBalance = await token.methods.balanceOf(address).call() @@ -100,7 +88,7 @@ async function main() { if (count === batchSize || i === deposits.length - 1) { const amount = depositAmountBN.muln(count) - const call = token.methods.transferAndCall(receiver, amount, data) + const call = token.methods.transferAndCall(DEPOSIT_CONTRACT_ADDRESS, amount, data) let gas try { gas = await call.estimateGas({ from: address }) @@ -129,6 +117,19 @@ async function main() { } async function getPastLogs(contract, event, { fromBlock, toBlock }) { + const maxRange = 1_000_000 + if (toBlock - fromBlock > maxRange) { + const res = [] + for (let curBlock = fromBlock; curBlock < toBlock; curBlock += maxRange) { + const part = await getPastLogs(contract, event, { + fromBlock: curBlock, + toBlock: Math.min(curBlock + maxRange - 1, toBlock), + }) + res.push(part) + } + return res.flat() + } + console.log(`Fetching deposit logs from block ${fromBlock} to block ${toBlock}`) try { return contract.getPastEvents(event, { fromBlock,