Skip to content

Commit

Permalink
Exercise contracts migrating all owned plots
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaman1337 committed Sep 19, 2024
1 parent 49228f6 commit 45a777a
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 189 deletions.
45 changes: 45 additions & 0 deletions protocol/scripts/beanstalk-3/plotDataReader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require("fs");
const { ethers } = require("ethers");

function readPlotData(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 plot data found for account: ${checksummedAccount}`);
return "0x";
}

const plotIds = accountData[1];
const amounts = accountData[2];

// Encode the data
const encodedData = ethers.utils.defaultAbiCoder.encode(
["uint256[]", "uint256[]"],
[plotIds, amounts]
);

return encodedData;
} catch (error) {
console.error(`Error reading plot 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 = readPlotData(jsonFilePath, account);
console.log(encodedData);
File renamed without changes.
40 changes: 40 additions & 0 deletions protocol/scripts/beanstalk-3/proofReaderPlots.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);
Loading

0 comments on commit 45a777a

Please sign in to comment.