diff --git a/package.json b/package.json index 22213e3..1f07e14 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@openzeppelin/contracts": "^4.3.2", "@truffle/hdwallet-provider": "^1.4.2", - "dotenv": "^10.0.0", + "dotenv": "^16.3.1", "truffle": "^5.4.3", "web3": "^1.6.0" }, diff --git a/scripts/deposit.js b/scripts/deposit.js index c8555ec..11df19c 100644 --- a/scripts/deposit.js +++ b/scripts/deposit.js @@ -1,8 +1,10 @@ const Web3 = require('web3') - +const path = require('path') const { abi } = require('../build/contracts/IERC677.json') const { abi: depositABI } = require('../build/contracts/IDepositContract.json') +require('dotenv').config({ path: path.resolve(__dirname, '.env') }) + const { RPC_URL, GAS_PRICE, @@ -19,7 +21,11 @@ const { const web3 = new Web3(RPC_URL) const { address } = web3.eth.accounts.wallet.add(STAKING_ACCOUNT_PRIVATE_KEY) -const depositData = require(process.argv[2]) +const depositDataFilepath = process.argv[2] +if (!depositDataFilepath) { + throw Error('must provide positional argument $deposit_data_filepath') +} +const depositData = readJson(depositDataFilepath) const batchSize = parseInt(BATCH_SIZE, 10) const offset = parseInt(OFFSET, 10) @@ -154,4 +160,14 @@ async function getPastLogs(contract, event, { fromBlock, toBlock }) { } } +function readJson(filepath) { + const s = fs.readFileSync(filepath) + try { + return JSON.parse(s) + } catch (e) { + e.message = `error parsing JSON string: ${e.message}\n${s}` + throw e + } +} + main() diff --git a/yarn.lock b/yarn.lock index d592f14..2091ae9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2543,10 +2543,10 @@ dot-prop@^6.0.1: dependencies: is-obj "^2.0.0" -dotenv@^10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" - integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== double-ended-queue@2.1.0-0: version "2.1.0-0"