Skip to content

Commit

Permalink
Support for internal balances checking for all contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaman1337 committed Sep 19, 2024
1 parent 45a777a commit 8ff1786
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
45 changes: 45 additions & 0 deletions protocol/scripts/beanstalk-3/internalBalancesDataReader.js
Original file line number Diff line number Diff line change
@@ -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);
40 changes: 40 additions & 0 deletions protocol/scripts/beanstalk-3/proofReaderInternalBalances.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 8ff1786

Please sign in to comment.