diff --git a/protocol/scripts/beanstalk-3/internalBalancesDataReader.js b/protocol/scripts/beanstalk-3/internalBalancesDataReader.js new file mode 100644 index 000000000..b28f4e9dc --- /dev/null +++ b/protocol/scripts/beanstalk-3/internalBalancesDataReader.js @@ -0,0 +1,45 @@ +const fs = require("fs"); +const { ethers } = require("ethers"); + +function readDepositData(jsonFilePath, account) { + try { + // Read the JSON file + const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, "utf8")); + + // Convert the input address to checksummed format + const checksummedAccount = ethers.utils.getAddress(account); + + // Find the data for the specified account + const accountData = jsonData.find( + (data) => ethers.utils.getAddress(data[0]) === checksummedAccount + ); + + if (!accountData) { + // console.error(`No data found for account: ${checksummedAccount}`); + return "0x"; + } + + const addresses = accountData[1]; + const amounts = accountData[2]; + + // Encode the data + const encodedData = ethers.utils.defaultAbiCoder.encode( + ["address[]", "uint256[]"], + [addresses, amounts] + ); + + return encodedData; + } catch (error) { + console.error(`Error reading deposit data: ${error.message}`); + return "0x"; + } +} + +// Get command line arguments +const args = process.argv.slice(2); +const jsonFilePath = args[0]; +const account = args[1]; + +// Run the function and output the result +const encodedData = readDepositData(jsonFilePath, account); +console.log(encodedData); diff --git a/protocol/scripts/beanstalk-3/proofReaderInternalBalances.js b/protocol/scripts/beanstalk-3/proofReaderInternalBalances.js new file mode 100644 index 000000000..c50cfaeb5 --- /dev/null +++ b/protocol/scripts/beanstalk-3/proofReaderInternalBalances.js @@ -0,0 +1,40 @@ +const fs = require("fs"); +const path = require("path"); + +function getProofForAccount(jsonFilePath, account) { + try { + // Read the JSON file + const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, "utf8")); + + // Create a new object with lowercased keys + const lowercaseProofs = Object.keys(jsonData.proofs).reduce((acc, key) => { + acc[key.toLowerCase()] = jsonData.proofs[key]; + return acc; + }, {}); + + // Convert the input account to lowercase + const lowercaseAccount = account.toLowerCase(); + + // Check if the lowercased account exists in the proofs object + if (lowercaseProofs.hasOwnProperty(lowercaseAccount)) { + const proof = lowercaseProofs[lowercaseAccount]; + + // Convert the proof array to a single packed string without '0x' prefixes + return proof.map((element) => element.slice(2)).join(""); + } else { + return "NO_PROOF_FOUND"; + } + } catch (error) { + console.error(`Error reading proof data: ${error.message}`); + return "ERROR_READING_PROOF"; + } +} + +// Get the command line arguments +const args = process.argv.slice(2); +const jsonFilePath = args[0]; +const account = args[1]; + +// Run the function and output the result +const proof = getProofForAccount(jsonFilePath, account); +console.log(proof);