Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tasks/requisition/

# deployment outputs
scripts/deployment/outputs/
scripts/beanstalkShipments/data/deployedAddresses*.json

# hardhat cache
hardhat-cache/
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ task("runLatestUpgrade", "Compiles the contracts").setAction(async function () {
await hre.run("compile");

// run beanstalk shipments
await hre.run("runBeanstalkShipments", { skipPause: true, runStep0: false });
await hre.run("runBeanstalkShipments", { skipPause: false, runStep0: false, step: "deploy" });
});

task("callSunriseAndTestMigration", "Calls the sunrise function and tests the migration").setAction(
Expand Down
48 changes: 24 additions & 24 deletions scripts/beanstalkShipments/data/updatedShipmentRoutes.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
[
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x7c655075",
"recipient": "0x1",
"data": "0x0000000000000000000000000000000000000000000000000000000000000000"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x7c655075",
"recipient": "0x1",
"data": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x12e8d3ed",
"recipient": "0x2",
"data": "0x0000000000000000000000000000000000000000000000000000000000000000"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x12e8d3ed",
"recipient": "0x2",
"data": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x05655264",
"recipient": "0x3",
"data": "0x000000000000000000000000b0cdb715D8122bd976a30996866Ebe5e51bb18b0"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x05655264",
"recipient": "0x3",
"data": "0x000000000000000000000000b0cdb715D8122bd976a30996866Ebe5e51bb18b0"
},
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x6fc9267a",
"recipient": "0x2",
"data": "0x0000000000000000000000009e449a18155d4b03c2e08a4e28b2bcae580efc4e00000000000000000000000071ad4dcd54b1ee0fa450d7f389beaff1c8602f9b0000000000000000000000000000000000000000000000000000000000000001"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x6fc9267a",
"recipient": "0x2",
"data": "0x00000000000000000000000041a63c5ec74c8d1b0cb7cea171e84f926c97c129000000000000000000000000d8a725b613be344a63d7b8ab69ef28010d35be5d0000000000000000000000000000000000000000000000000000000000000001"
},
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0xb34da3d2",
"recipient": "0x5",
"data": "0x0000000000000000000000009e449a18155d4b03c2e08a4e28b2bcae580efc4e00000000000000000000000071ad4dcd54b1ee0fa450d7f389beaff1c8602f9b"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0xb34da3d2",
"recipient": "0x5",
"data": "0x00000000000000000000000041a63c5ec74c8d1b0cb7cea171e84f926c97c129000000000000000000000000d8a725b613be344a63d7b8ab69ef28010d35be5d"
},
{
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x5f6cc37d",
"recipient": "0x6",
"data": "0x00000000000000000000000071ad4dcd54b1ee0fa450d7f389beaff1c8602f9b0000000000000000000000009e449a18155d4b03c2e08a4e28b2bcae580efc4e"
"planContract": "0x0000000000000000000000000000000000000000",
"planSelector": "0x5f6cc37d",
"recipient": "0x6",
"data": "0x00000000000000000000000041a63c5ec74c8d1b0cb7cea171e84f926c97c129000000000000000000000000d8a725b613be344a63d7b8ab69ef28010d35be5d"
}
]
63 changes: 55 additions & 8 deletions scripts/beanstalkShipments/utils/addressCache.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
const fs = require("fs");
const path = require("path");

const CACHE_FILE_PATH = path.join(__dirname, "../data/deployedAddresses.json");
const DATA_DIR = path.join(__dirname, "../data");
const FILE_PREFIX = "deployedAddresses_";
const FILE_EXTENSION = ".json";

/**
* Saves deployed contract addresses to cache file
* Gets all existing deployed address files and returns them sorted by counter
* @returns {Array<{path: string, counter: number}>} Sorted array of file info
*/
function getExistingFiles() {
if (!fs.existsSync(DATA_DIR)) {
return [];
}

const files = fs.readdirSync(DATA_DIR);
const addressFiles = files
.filter((f) => f.startsWith(FILE_PREFIX) && f.endsWith(FILE_EXTENSION))
.map((f) => {
const counterStr = f.slice(FILE_PREFIX.length, -FILE_EXTENSION.length);
const counter = parseInt(counterStr, 10);
return { path: path.join(DATA_DIR, f), counter };
})
.filter((f) => !isNaN(f.counter))
.sort((a, b) => a.counter - b.counter);

return addressFiles;
}

/**
* Gets the path for the next available counter
* @returns {string} Path for the next file
*/
function getNextFilePath() {
const existing = getExistingFiles();
const nextCounter = existing.length > 0 ? existing[existing.length - 1].counter + 1 : 1;
return path.join(DATA_DIR, `${FILE_PREFIX}${nextCounter}${FILE_EXTENSION}`);
}

/**
* Gets the path of the latest (highest counter) file
* @returns {string|null} Path to latest file or null if none exist
*/
function getLatestFilePath() {
const existing = getExistingFiles();
return existing.length > 0 ? existing[existing.length - 1].path : null;
}

/**
* Saves deployed contract addresses to cache file with auto-incrementing counter
* @param {Object} addresses - Object containing contract addresses
* @param {string} addresses.siloPayback - SiloPayback contract address
* @param {string} addresses.barnPayback - BarnPayback contract address
Expand All @@ -20,21 +64,23 @@ function saveDeployedAddresses(addresses, network = "unknown") {
network: network
};

fs.writeFileSync(CACHE_FILE_PATH, JSON.stringify(data, null, 2));
console.log(`📝 Deployed addresses saved to ${CACHE_FILE_PATH}`);
const filePath = getNextFilePath();
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
console.log(`📝 Deployed addresses saved to ${filePath}`);
}

/**
* Gets deployed contract addresses from cache file
* Gets deployed contract addresses from the latest cache file
* @returns {Object|null} Object containing contract addresses or null if not found
*/
function getDeployedAddresses() {
if (!fs.existsSync(CACHE_FILE_PATH)) {
const latestFile = getLatestFilePath();
if (!latestFile) {
return null;
}

try {
const data = JSON.parse(fs.readFileSync(CACHE_FILE_PATH));
const data = JSON.parse(fs.readFileSync(latestFile));
return data;
} catch (error) {
console.error("Error reading deployed addresses cache:", error);
Expand Down Expand Up @@ -82,5 +128,6 @@ module.exports = {
getDeployedAddresses,
verifyDeployedAddresses,
getContractAddress,
CACHE_FILE_PATH
getLatestFilePath,
getExistingFiles
};
2 changes: 2 additions & 0 deletions tasks/beanstalk-shipments.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module.exports = function () {

const siloPaybackAddress = contracts.siloPaybackContract.address;
const barnPaybackAddress = contracts.barnPaybackContract.address;
const contractPaybackDistributorAddress = contracts.contractPaybackDistributorContract.address;

// Helper to encode addresses into padded hex data
const encodeAddress = (addr) => addr.toLowerCase().replace("0x", "").padStart(64, "0");
Expand All @@ -171,6 +172,7 @@ module.exports = function () {
console.log("Updated updatedShipmentRoutes.json with deployed contract addresses:");
console.log(` - SiloPayback: ${siloPaybackAddress}`);
console.log(` - BarnPayback: ${barnPaybackAddress}`);
console.log(` - ContractPaybackDistributor: ${contractPaybackDistributorAddress}`);
console.log(` - Routes 4, 5, 6 data fields updated\n`);
});

Expand Down
4 changes: 2 additions & 2 deletions test/hardhat/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ module.exports = {
PINTO_PRICE_CONTRACT: "0x13D25ABCB6a19948d35654715c729c6501230b49",

//////////////////////// BEANSTALK SHIPMENTS ////////////////////////
// EOA That will deploy the beanstlak shipment related contracts on base
BEANSTALK_SHIPMENTS_DEPLOYER: "0x47c365cc9ef51052651c2be22f274470ad6afc53",
// EOA That will deploy the beanstalk shipment related contracts on base
BEANSTALK_SHIPMENTS_DEPLOYER: "0x00000015EE13a3C1fD0e8Dc2e8C2c8590D5B440B",
// Expected proxy address of the silo payback contract from deployer at nonce 1
BEANSTALK_SILO_PAYBACK: "0x9E449a18155D4B03C2E08A4E28b2BcAE580efC4E",
BEANSTALK_SILO_PAYBACK_IMPLEMENTATION: "0x3E0635B980714303351DAeE305dB1A380C56ed38",
Expand Down