Skip to content

Commit

Permalink
Update batch deposit script for post-shapella deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Aug 5, 2023
1 parent 24f9fcf commit bab7b19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
12 changes: 3 additions & 9 deletions scripts/.env.example
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14
FROM node:20

LABEL org.opencontainers.image.source "https://github.com/gnosischain/deposit-contract"

Expand Down
31 changes: 16 additions & 15 deletions scripts/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand All @@ -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()

Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bab7b19

Please sign in to comment.