-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for internal balances checking for all contracts
- Loading branch information
1 parent
45a777a
commit 8ff1786
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
protocol/scripts/beanstalk-3/internalBalancesDataReader.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,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
40
protocol/scripts/beanstalk-3/proofReaderInternalBalances.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,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); |