Skip to content

Commit

Permalink
Reseed Deployment Redesign (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios authored Sep 26, 2024
2 parents d958c52 + 0a1177f commit 7019a63
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 185 deletions.
2 changes: 1 addition & 1 deletion protocol/.env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ BLOCK_NUMBER=
MAINNET_RPC=
ARBITRUM_RPC=
ETHERSCAN_KEY=
DIAMOND_DEPLOYER_PRIVATE_KEY=
ETHERSCAN_KEY_ARBITRUM=
57 changes: 0 additions & 57 deletions protocol/contracts/beanstalk/init/reseed/L2/ReseedSun.sol

This file was deleted.

35 changes: 6 additions & 29 deletions protocol/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
INTERNAL_EXTERNAL,
INTERNAL_TOLERANT
} = require("./test/hardhat/utils/balances.js");
const { BEANSTALK, PUBLIUS, BEAN_ETH_WELL, BCM } = require("./test/hardhat/utils/constants.js");
const { BEANSTALK, PUBLIUS, BEAN_ETH_WELL, BCM, L2_BCM } = require("./test/hardhat/utils/constants.js");
const { to6 } = require("./test/hardhat/utils/helpers.js");
//const { replant } = require("./replant/replant.js")
const { reseedL2 } = require("./reseed/reseedL2.js");
Expand Down Expand Up @@ -120,32 +120,6 @@ task("sunriseArb", async function () {
);
});

task("addReseedFacets", async function () {
let l2bcm = await impersonateSigner("0xDd5b31E73dB1c566Ca09e1F1f74Df34913DaaF69");
const l2BeanstalkAddress = "0xD1A0060ba708BC4BCD3DA6C37EFa8deDF015FB70";
let beanstalkDeployer = await impersonateSigner("0xe26367ca850da09a478076481535d7c1c67d62f9");
await mintEth(l2bcm.address);
await mintEth(beanstalkDeployer.address);
// transfer ownership to the l2bcm.
await upgradeWithNewFacets({
diamondAddress: l2BeanstalkAddress,
facetNames: ["OwnershipFacet"],
initFacetName: "ReseedTransferOwnership",
initArgs: [l2bcm.address],
bip: false,
verbose: false,
account: beanstalkDeployer,
checkGas: true,
initFacetNameInfo: "ReseedTransferOwnership"
});
// claim ownership of the l2 beanstalk.
await (await getBeanstalk(l2BeanstalkAddress)).connect(l2bcm).claimOwnership();
// perform the diamond cut.
await reseed10(l2bcm, l2BeanstalkAddress, false, true);
console.log("-----------------------------------");
console.log("\nDiamond cut complete: Facets added to L2 Beanstalk.");
});

task("getTime", async function () {
beanstalk = await ethers.getContractAt("SeasonFacet", BEANSTALK);
console.log("Current time: ", await this.seasonGetter.time());
Expand All @@ -167,7 +141,7 @@ task("reseedL2", async () => {
// the account that deploys the new diamond address at nonce 0.
let beanstalkDeployer = await impersonateSigner("0xe26367ca850da09a478076481535d7c1c67d62f9");
// the l2 bcm safe account address.
let l2bcm = await impersonateSigner("0xDd5b31E73dB1c566Ca09e1F1f74Df34913DaaF69");
let l2bcm = await impersonateSigner(L2_BCM);
await mintEth(beanstalkDeployer.address);
await mintEth(l2bcm.address);
await reseedL2({
Expand Down Expand Up @@ -533,7 +507,10 @@ module.exports = {
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_KEY
apiKey: {
arbitrumOne: process.env.ETHERSCAN_KEY_ARBITRUM,
mainnet: process.env.ETHERSCAN_KEY
}
},
solidity: {
compilers: [
Expand Down
105 changes: 46 additions & 59 deletions protocol/reseed/reseed10.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const { upgradeWithNewFacets } = require("../scripts/diamond.js");
const { upgradeWithDeployedFacets } = require("../scripts/diamond.js");
const fs = require("fs");
const { retryOperation } = require("../utils/read.js");

/**
* @notice reseed9 (final step) adds all facets to beanstalk, and unpauses beanstalk.
* note: All facets will be deployed prior to running the reseed.
*/
async function reseed10(account, L2Beanstalk, mock, verbose = true) {
// get list of facets to deploy:
let facets = [
console.log("-----------------------------------");
console.log("reseed10: add all facets to L2 Beanstalk.\n");

// get list of facet names to link
let facetNames = [
"SeasonFacet", // SUN
"SeasonGettersFacet",
"GaugeGettersFacet",
Expand Down Expand Up @@ -38,67 +42,50 @@ async function reseed10(account, L2Beanstalk, mock, verbose = true) {
"L1RecieverFacet" // MIGRATION
];

// A list of public libraries that need to be deployed separately.
libraryNames = [
"LibGauge",
"LibIncentive",
"LibConvert",
"LibLockedUnderlying",
"LibWellMinting",
"LibGerminate",
"LibPipelineConvert",
"LibSilo",
"LibShipping",
"LibFlood",
"LibTokenSilo",
"LibEvaluate",
"LibSiloPermit"
// get list of facet addresses to link
const facetAddresses = [
"0x552322CD960FFB809d91012CE05d6FBB86BaE290",
"0xdf522AC66735CB506D15236CF35938588f29e34B",
"0x16b6B2Deb4b19DDb664167CF8cBE601DFA9a87e5",
"0x043a11704A9e508a2b03c4Dc38Ae60dEE369EAEC",
"0x837B2DB3ea3092E9452fCB118027aeBA1d9FfbD3",
"0xA89Fbf550A453f0eD9D75DAac706fa41eE7F9A1d",
"0xD14b7AB5fd36C770e3339A94F3763cAeC046DDCc",
"0x51757F6c0A662B4fB57E96a903b199d9D0fCd312",
"0x7eF1D0449dD48189AF968586b2F91c8294ADDC07",
"0x0D6dF5E737EF25913F6f2fA1649D0F9530c83D59",
"0xa7D49dC04ab8530509A03f9B8669ac6Bc026711f",
"0x320AaEBB1a644BEd2B86038eDE49B81072D02be0",
"0xd7a7Ec3B2EC70EdFFfB969f94436908fB53B3B85",
"0x3D5Cd5A7C7312bF005de78B09e125b34165a69Ec",
"0x35f6977D9236C0734520878799598eA0FE692965",
"0x958679Ab3CC0961F4339FaeCcbf36a1d5906cbF5",
"0x6464446d74C27961396A126b2d449aBdDea354cd",
"0xE6f9cE8737fa856e2aEeD2925DB39Fcac25c6513",
"0x47422eEEcd1cE855dcf59eE7EaEb23c6A4666699",
"0xd4A0797D7700bbA801d2DeD34e5d44480D0061Fe",
"0x4D26Caf0778D651922e89c546f09Ae852cc4933a",
"0xcC0f8117B6c0c45C15D4d306Cdb14454263f33Ba",
"0xD61E6F775dE1B0C3aC8A4b2516FEb7A935DC85Bb",
"0x6f252Ecf79aF1bd57c48047a8B109001FFB4c1DB",
"0x0b980ab39F9fDf3226b98Bc32d96EC180fd61687",
"0xD9171D21C414AE676946a60cd226b3EDa5aC3a2A",
"0x7ee24734b97902E6081D702514776416F11F971b",
"0x53106dc7D78dF1EeD36947cf0536d7eCcCa7e0b1"
];

// A mapping of facet to public library names that will be linked to it.
// MockFacets will be deployed with the same public libraries.
facetLibraries = {
SeasonFacet: [
"LibGauge",
"LibIncentive",
"LibWellMinting",
"LibGerminate",
"LibShipping",
"LibFlood",
"LibEvaluate"
],
ConvertFacet: ["LibConvert", "LibPipelineConvert", "LibSilo", "LibTokenSilo"],
PipelineConvertFacet: ["LibPipelineConvert", "LibSilo", "LibTokenSilo"],
UnripeFacet: ["LibLockedUnderlying"],
SeasonGettersFacet: ["LibLockedUnderlying", "LibWellMinting"],
SiloFacet: ["LibSilo", "LibTokenSilo", "LibSiloPermit"],
EnrootFacet: ["LibSilo", "LibTokenSilo"],
ClaimFacet: ["LibSilo", "LibTokenSilo"],
GaugeGettersFacet: ["LibLockedUnderlying"],
L1RecieverFacet: ["LibSilo", "LibTokenSilo"]
};

// A mapping of external libraries to external libraries that need to be linked.
// note: if a library depends on another library, the dependency will need to come
// before itself in `libraryNames`
libraryLinks = {
LibEvaluate: ["LibLockedUnderlying"]
};

// upgrade beanstalk with all facets. calls `InitReseed`
// link all facets to beanstalk diamond:
await retryOperation(async () => {
await upgradeWithNewFacets({
await upgradeWithDeployedFacets({
diamondAddress: L2Beanstalk,
facetNames: facets,
facetLibraries: facetLibraries,
libraryNames: libraryNames,
linkedLibraries: libraryLinks,
initFacetName: "InitReseed",
initArgs: [],
bip: false,
verbose: verbose,
account: account
facetNames: facetNames,
facetAddresses: facetAddresses,
verbose: true,
account: account,
checkGas: true
});
});

console.log("\nFacets added to L2 Beanstalk.");
}
exports.reseed10 = reseed10;
2 changes: 1 addition & 1 deletion protocol/reseed/reseedAddLiquidityAndTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function reseedAddLiquidityAndTransfer(account, L2Beanstalk, mock = true,
to6("0") // to6("1000000") // BEAN/USDT
];
console.log("-----------------------------------");
console.log("add liquidity to wells and transfers to l2 beanstalk.\n");
console.log("Add liquidity to wells and transfer LP tokens to L2 beanstalk.\n");
const beanAddress = "0xBEA0005B8599265D41256905A9B3073D397812E4";
await impersonateToken(beanAddress, 6);
const bean = await ethers.getContractAt("MockToken", beanAddress);
Expand Down
43 changes: 11 additions & 32 deletions protocol/reseed/reseedL2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { parsePodMarketplace } = require("./dataConverts/convertPodMarketplace.js
const { parseGlobals } = require("./dataConverts/convertGlobal.js");
const { parseExternalHolders } = require("./dataConverts/convertExternalHolders.js");
const { parseTokens } = require("./dataConverts/convertTokens.js");
const { reseedDeployL2Beanstalk } = require("./reseedDeployL2Beanstalk.js");
const { reseed2 } = require("./reseed2.js");
const { reseed3 } = require("./reseed3.js");
const { reseed4 } = require("./reseed4.js");
Expand All @@ -23,6 +22,7 @@ const { reseedAddLiquidityAndTransfer } = require("./reseedAddLiquidityAndTransf
const fs = require("fs");
const { upgradeWithNewFacets } = require("../scripts/diamond.js");
const { getBeanstalk } = require("../utils/contracts.js");
const { L2_BEANSTALK } = require("../test/hardhat/utils/constants.js");

let reseeds;
async function reseedL2({
Expand All @@ -42,7 +42,6 @@ async function reseedL2({
// delete prev gas report
if (fs.existsSync("./reseed/data/gas-report.csv")) fs.unlinkSync("./reseed/data/gas-report.csv");
reseeds = [
reseedDeployL2Beanstalk, // deploy l2 beanstalk diamond
reseed2, // reseedbean + deploy wells and fertilizer proxy on l2
reseedGlobal, // reseed global variables
reseed3, // reseed field
Expand All @@ -54,51 +53,31 @@ async function reseedL2({
reseed9, // reseed whitelist
reseed10 // add selectors to l2
];
let l2BeanstalkAddress;

console.clear();
await printBeanstalk();
for (let i = start; i < reseeds.length; i++) {
await printStage(i, end, mock, log);
console.log("L2 Beanstalk:", l2BeanstalkAddress);

if (i == 0) {
// first step on the l2 is to deploy the L2 beanstalk diamond with predetermined address.
l2BeanstalkAddress = await reseedDeployL2Beanstalk(beanstalkDeployer, log, mock);
continue;
}
console.log("L2 Beanstalk:", L2_BEANSTALK);

if (setState == true) {
await reseeds[i](beanstalkDeployer, l2BeanstalkAddress, mock, verbose);
await reseeds[i](beanstalkDeployer, L2_BEANSTALK, mock, verbose);
continue;
}

if (i == reseeds.length - 2) {
// prior to the last reseed (i.e, adding facets to L2 beanstalk),
// the Beanstalk deployer needs to transfer ownership to the beanstalk owner.
console.log("Transferring ownership to the beanstalk owner.");
await upgradeWithNewFacets({
diamondAddress: l2BeanstalkAddress,
facetNames: ["OwnershipFacet"],
initFacetName: "ReseedTransferOwnership",
initArgs: [l2owner.address],
bip: false,
verbose: false,
account: beanstalkDeployer,
checkGas: true,
initFacetNameInfo: "ReseedTransferOwnership"
});
}
// Prior to the last reseed (i.e, adding facets to L2 beanstalk),
// the beanstalk owner needs to accept ownership of beanstalk.
// The ownership facet will already be added to the diamond
// and the deployer will have already proposed the l2 owner as the new owner.
if (i == reseeds.length - 1) {
// claim ownership of beanstalk:
console.log("Claiming ownership of beanstalk.");
await (await getBeanstalk(l2BeanstalkAddress)).connect(l2owner).claimOwnership();
// initialize beanstalk state add selectors to L2 beanstalk.
await reseed10(l2owner, l2BeanstalkAddress, mock);
await (await getBeanstalk(L2_BEANSTALK)).connect(l2owner).claimOwnership();
// add selectors to l2 beanstalk from the already deployed facets
await reseed10(l2owner, L2_BEANSTALK, mock);
}
}
// adds liquidity to wells and transfer well LP tokens to l2 beanstalk:
if (addLiquidity) await reseedAddLiquidityAndTransfer(l2owner, l2BeanstalkAddress, true);
if (addLiquidity) await reseedAddLiquidityAndTransfer(l2owner, L2_BEANSTALK, true);
console.log("Reseed successful.");
}

Expand Down
Loading

0 comments on commit 7019a63

Please sign in to comment.