-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1c7e9e
commit 2812065
Showing
6 changed files
with
306 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.env | ||
.git/ | ||
.idea/ | ||
build/ | ||
coverage/ | ||
node_modules/ | ||
coverage.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000 | ||
|
||
RPC_URL=https://xdai.poa.network | ||
|
||
BATCH_SIZE=128 | ||
N=256 | ||
OFFSET=0 | ||
|
||
TOKEN_ADDRESS=0x0000000000000000000000000000000000000000 | ||
DEPOSIT_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM node:14-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json yarn.lock ./ | ||
|
||
RUN yarn install | ||
|
||
COPY . . | ||
|
||
RUN yarn compile | ||
|
||
ENTRYPOINT ["node", "./scripts/deposit.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Web3 = require('web3') | ||
|
||
const { abi } = require('../build/contracts/IERC677.json') | ||
|
||
const { RPC_URL, DEPLOYMENT_ACCOUNT_PRIVATE_KEY, BATCH_SIZE, N, OFFSET, TOKEN_ADDRESS, DEPOSIT_CONTRACT_ADDRESS } = process.env | ||
|
||
const web3 = new Web3(RPC_URL) | ||
const { address } = web3.eth.accounts.wallet.add(DEPLOYMENT_ACCOUNT_PRIVATE_KEY) | ||
|
||
const depositData = require(process.argv[2]) | ||
|
||
const batchSize = parseInt(BATCH_SIZE, 10) | ||
const offset = parseInt(OFFSET, 10) | ||
const n = parseInt(N, 10) | ||
async function main() { | ||
const token = new web3.eth.Contract(abi, TOKEN_ADDRESS) | ||
const deposits = depositData.slice(offset, offset + n) | ||
|
||
const wc = deposits[0].withdrawal_credentials | ||
if (!deposits.every(d => d.withdrawal_credentials === wc)) { | ||
console.log('Withdrawal credentials do not match') | ||
return | ||
} | ||
|
||
if (!deposits.every(d => d.amount === 32000000000)) { | ||
console.log('Amount should be exactly 32 tokens for batch deposits') | ||
return | ||
} | ||
|
||
console.log(`Sending ${Math.ceil(deposits.length / batchSize)} deposit transactions for ${deposits.length} deposits in batches of ${batchSize} events`) | ||
let nonce = await web3.eth.getTransactionCount(address) | ||
let count = 0 | ||
let data = '0x' + wc | ||
for (let i = 0; i < deposits.length; i++) { | ||
const deposit = deposits[i] | ||
data += deposit.pubkey | ||
data += deposit.signature | ||
data += deposit.deposit_data_root | ||
count++ | ||
|
||
if (count === batchSize || i === deposits.length - 1) { | ||
const amount = web3.utils.toBN(32 * count).mul(web3.utils.toBN('1000000000000000000')) | ||
const call = token.methods.transferAndCall(DEPOSIT_CONTRACT_ADDRESS, amount, data) | ||
const gas = await call.estimateGas({ from: address }) | ||
const receipt = await call.send({ | ||
from: address, | ||
nonce: nonce++, | ||
gas: Math.ceil(gas * 1.5), | ||
}) | ||
console.log(`\t${count} next deposits: ${receipt.transactionHash}`) | ||
data = '0x' + wc | ||
count = 0 | ||
} | ||
} | ||
} | ||
|
||
main() |
Oops, something went wrong.