diff --git a/protocol/hardhat.config.js b/protocol/hardhat.config.js index 5aab348f3..ef419ebd1 100644 --- a/protocol/hardhat.config.js +++ b/protocol/hardhat.config.js @@ -96,20 +96,13 @@ task("sunrise2", async function () { task("sunriseArb", async function () { beanstalk = await getBeanstalk("0xD1A0060ba708BC4BCD3DA6C37EFa8deDF015FB70"); - // call sunrise before attempting to mine more blocks: - try { - await beanstalk.sunrise(); - } catch (error) { - // make a few seconds pass to avoid pump NoTimePassed() error for twa reserves right after the sunrise. - const lastTimestamp = (await ethers.provider.getBlock("latest")).timestamp; - const hourTimestamp = parseInt(lastTimestamp / 3600 + 1) * 3600; - const additionalSeconds = 12; - await network.provider.send("evm_setNextBlockTimestamp", [hourTimestamp + additionalSeconds]); - - await beanstalk.sunrise(); - - await network.provider.send("evm_mine"); - } + // Simulate the transaction to check if it would succeed + const lastTimestamp = (await ethers.provider.getBlock("latest")).timestamp; + const hourTimestamp = parseInt(lastTimestamp / 3600 + 1) * 3600; + const additionalSeconds = 12; + await network.provider.send("evm_setNextBlockTimestamp", [hourTimestamp + additionalSeconds]); + await beanstalk.sunrise(); + await network.provider.send("evm_mine"); const unixTime = await time.latest(); const currentTime = new Date(unixTime * 1000).toLocaleString(); @@ -533,16 +526,6 @@ module.exports = { url: "", timeout: 100000 }, - reseedArbitrum: { - url: "https://virtual.arbitrum.rpc.tenderly.co/65fd0946-649e-4927-b8db-9a5ff8afa284", - chainId: 42161, - timeout: 10000000000000 - }, - reseedArbitrumSync: { - url: "https://virtual.arbitrum.rpc.tenderly.co/af868e07-a45a-41e7-b05f-c272e8d42cdd", - chainId: 42161, - timeout: 10000000000000 - }, goerli: { chainId: 5, url: process.env.GOERLI_RPC || "", diff --git a/protocol/reseed/reseed10.js b/protocol/reseed/reseed10.js index b4698169a..f850f5a34 100644 --- a/protocol/reseed/reseed10.js +++ b/protocol/reseed/reseed10.js @@ -1,5 +1,6 @@ const { upgradeWithNewFacets } = 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. @@ -85,17 +86,19 @@ async function reseed10(account, L2Beanstalk, mock, verbose = true) { }; // upgrade beanstalk with all facets. calls `InitReseed` - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: facets, - facetLibraries: facetLibraries, - libraryNames: libraryNames, - linkedLibraries: libraryLinks, - initFacetName: "InitReseed", - initArgs: [], - bip: false, - verbose: verbose, - account: account + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: facets, + facetLibraries: facetLibraries, + libraryNames: libraryNames, + linkedLibraries: libraryLinks, + initFacetName: "InitReseed", + initArgs: [], + bip: false, + verbose: verbose, + account: account + }); }); } exports.reseed10 = reseed10; diff --git a/protocol/reseed/reseed2.js b/protocol/reseed/reseed2.js index 387cb1463..68499f68d 100644 --- a/protocol/reseed/reseed2.js +++ b/protocol/reseed/reseed2.js @@ -1,8 +1,6 @@ -const { impersonateSigner } = require("../utils/index.js"); const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); -const { deployMockToken, getWellContractAt } = require("../utils/well.js"); -const { deployBasinV1_2Components, deployUpgradeableWell } = require("../scripts/basinV1_2.js"); +const { retryOperation } = require("../utils/read.js"); // Files const INIT_SUPPLY = "./reseed/data/r2/L2_initial_supply.json"; @@ -15,7 +13,7 @@ const EXTERNAL_UNRIPE_BEAN_LP = "./reseed/data/r2/L2_external_unripe_lp_balances * where it will 1) transfer to a well 2) sync and add liquidity, upon deployment. * note: for testing purposes, the L2 is on base, and the stablecoin is USDC, but can be switched based on the discretion of the DAO. */ -async function reseed2(account, L2Beanstalk, deployBasin = false, fertilizerImplementation, mock) { +async function reseed2(account, L2Beanstalk, fertilizerImplementation, mock) { verbose = true; console.log("-----------------------------------"); console.log("reseed2: deploy bean tokens.\n"); @@ -26,36 +24,32 @@ async function reseed2(account, L2Beanstalk, deployBasin = false, fertilizerImpl externalUrBean = JSON.parse(await fs.readFileSync(EXTERNAL_UNRIPE_BEAN)); externalUrBeanLP = JSON.parse(await fs.readFileSync(EXTERNAL_UNRIPE_BEAN_LP)); - if (deployBasin) { - [uWell, stable2] = await deployBasinV1_2Components(); - console.log("uWell:", uWell.address); - console.log("stable2:", stable2.address); - } - // get the bean sided liquidity from the L1 wells to mint it to the bcm. const beansInBeanEthWell = balancesInBeanEthWell[0]; const beansInBeanWstEthWell = balancesInBeanWstEthWell[0]; const beansInBeanStableWell = balancesInBeanStableWell[0]; // call init: - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedBean", - initArgs: [ - beanSupply, - unripeBeanSupply, - unripeLpSupply, - beansInBeanEthWell, - beansInBeanWstEthWell, - beansInBeanStableWell, - externalUrBean, - externalUrBeanLP, - fertilizerImplementation - ], - bip: false, - verbose: false, - account: account + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedBean", + initArgs: [ + beanSupply, + unripeBeanSupply, + unripeLpSupply, + beansInBeanEthWell, + beansInBeanWstEthWell, + beansInBeanStableWell, + externalUrBean, + externalUrBeanLP, + fertilizerImplementation + ], + bip: false, + verbose: false, + account: account + }); }); console.log("-----------------------------------"); diff --git a/protocol/reseed/reseed3.js b/protocol/reseed/reseed3.js index 259de363f..1fd2ad670 100644 --- a/protocol/reseed/reseed3.js +++ b/protocol/reseed/reseed3.js @@ -23,11 +23,11 @@ async function reseed3(account, L2Beanstalk, mock, verbose = false) { initFacetName: "ReseedPodMarket", initArgs: [podListings, podOrders], bip: false, - verbose: true, + verbose: verbose, account: account, checkGas: true }); console.log("-----------------------------------"); } -exports.reseed3 = reseed3; \ No newline at end of file +exports.reseed3 = reseed3; diff --git a/protocol/reseed/reseed4.js b/protocol/reseed/reseed4.js index 600910cb9..0c354a2bc 100644 --- a/protocol/reseed/reseed4.js +++ b/protocol/reseed/reseed4.js @@ -1,6 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); const { splitEntriesIntoChunksOptimized, updateProgress } = require("../utils/read.js"); +const { retryOperation } = require("../utils/read.js"); async function reseed4(account, L2Beanstalk, mock, verbose = false) { console.log("-----------------------------------"); @@ -27,17 +28,19 @@ async function reseed4(account, L2Beanstalk, mock, verbose = false) { console.log("Data chunk:", plotChunks[i]); console.log("-----------------------------------"); } - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedField", - initFacetAddress: InitFacet.address, - initArgs: [plotChunks[i]], - bip: false, - verbose: verbose, - account: account, - checkGas: true, - initFacetNameInfo: "ReseedField" + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedField", + initFacetAddress: InitFacet.address, + initArgs: [plotChunks[i]], + bip: false, + verbose: verbose, + account: account, + checkGas: true, + initFacetNameInfo: "ReseedField" + }); }); } } diff --git a/protocol/reseed/reseed5.js b/protocol/reseed/reseed5.js index 3b79924af..3a09cdc6c 100644 --- a/protocol/reseed/reseed5.js +++ b/protocol/reseed/reseed5.js @@ -1,6 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); const { splitEntriesIntoChunksOptimized, updateProgress } = require("../utils/read.js"); +const { retryOperation } = require("../utils/read.js"); async function reseed5(account, L2Beanstalk, mock, verbose = false) { console.log("-----------------------------------"); @@ -26,17 +27,19 @@ async function reseed5(account, L2Beanstalk, mock, verbose = false) { console.log("Data chunk:", fertChunks[i]); console.log("-----------------------------------"); } - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedBarn", - initFacetAddress: InitFacet.address, - initArgs: [fertChunks[i]], - bip: false, - verbose: verbose, - account: account, - checkGas: true, - initFacetNameInfo: "ReseedBarn" + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedBarn", + initFacetAddress: InitFacet.address, + initArgs: [fertChunks[i]], + bip: false, + verbose: verbose, + account: account, + checkGas: true, + initFacetNameInfo: "ReseedBarn" + }); }); } } diff --git a/protocol/reseed/reseed6.js b/protocol/reseed/reseed6.js index ec7a7fe89..d3f35a916 100644 --- a/protocol/reseed/reseed6.js +++ b/protocol/reseed/reseed6.js @@ -1,7 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); const { splitEntriesIntoChunksOptimized, updateProgress } = require("../utils/read.js"); - +const { retryOperation } = require("../utils/read.js"); async function reseed6(account, L2Beanstalk, mock, verbose = false) { console.log("-----------------------------------"); console.log("reseed6: reissue deposits.\n"); @@ -25,17 +25,19 @@ async function reseed6(account, L2Beanstalk, mock, verbose = false) { console.log("Data chunk:", depositChunks[i]); console.log("-----------------------------------"); } - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedSilo", - initFacetAddress: InitFacet.address, - initArgs: [depositChunks[i]], - bip: false, - verbose: verbose, - account: account, - checkGas: true, - initFacetNameInfo: "ReseedSilo" + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedSilo", + initFacetAddress: InitFacet.address, + initArgs: [depositChunks[i]], + bip: false, + verbose: verbose, + account: account, + checkGas: true, + initFacetNameInfo: "ReseedSilo" + }); }); } } diff --git a/protocol/reseed/reseed7.js b/protocol/reseed/reseed7.js index 20af5f456..a2deb3a9f 100644 --- a/protocol/reseed/reseed7.js +++ b/protocol/reseed/reseed7.js @@ -1,6 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); const { splitEntriesIntoChunksOptimized, updateProgress } = require("../utils/read.js"); +const { retryOperation } = require("../utils/read.js"); async function reseed7(account, L2Beanstalk, mock, verbose = false) { console.log("-----------------------------------"); @@ -27,16 +28,18 @@ async function reseed7(account, L2Beanstalk, mock, verbose = false) { console.log("Data chunk:", statusChunks[i]); console.log("-----------------------------------"); } - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedAccountStatus", - initFacetAddress: InitFacet.address, - initArgs: [statusChunks[i]], - bip: false, - verbose: verbose, - account: account, - initFacetNameInfo: "ReseedAccountStatus" + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedAccountStatus", + initFacetAddress: InitFacet.address, + initArgs: [statusChunks[i]], + bip: false, + verbose: verbose, + account: account, + initFacetNameInfo: "ReseedAccountStatus" + }); }); } } diff --git a/protocol/reseed/reseed8.js b/protocol/reseed/reseed8.js index 559642f46..fdebc6e8f 100644 --- a/protocol/reseed/reseed8.js +++ b/protocol/reseed/reseed8.js @@ -1,6 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const fs = require("fs"); const { splitEntriesIntoChunksOptimized, updateProgress } = require("../utils/read.js"); +const { retryOperation } = require("../utils/read.js"); async function reseed8(account, L2Beanstalk, mock, verbose = false) { console.log("-----------------------------------"); @@ -28,17 +29,19 @@ async function reseed8(account, L2Beanstalk, mock, verbose = false) { console.log("Data chunk:", balanceChunks[i]); console.log("-----------------------------------"); } - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedInternalBalances", - initFacetAddress: InitFacet.address, - initArgs: [balanceChunks[i]], - bip: false, - verbose: verbose, - account: account, - checkGas: true, - initFacetNameInfo: "ReseedInternalBalances" + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedInternalBalances", + initFacetAddress: InitFacet.address, + initArgs: [balanceChunks[i]], + bip: false, + verbose: verbose, + account: account, + checkGas: true, + initFacetNameInfo: "ReseedInternalBalances" + }); }); } } diff --git a/protocol/reseed/reseed9.js b/protocol/reseed/reseed9.js index 72027affe..6c14a948d 100644 --- a/protocol/reseed/reseed9.js +++ b/protocol/reseed/reseed9.js @@ -1,6 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const { deployContract } = require("../scripts/contracts"); const fs = require("fs"); +const { retryOperation } = require("../utils/read.js"); async function reseed9(account, L2Beanstalk, mock = false) { console.log("-----------------------------------"); @@ -29,15 +30,16 @@ async function reseed9(account, L2Beanstalk, mock = false) { oracles[4][0] = LSDChainlinkOracle.address; oracles[5][0] = LSDChainlinkOracle.address; - - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedWhitelist", - initArgs: [tokens, nonBeanTokens, siloSettings, whitelistStatuses, oracles], - bip: false, - verbose: true, - account: account + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedWhitelist", + initArgs: [tokens, nonBeanTokens, siloSettings, whitelistStatuses, oracles], + bip: false, + verbose: true, + account: account + }); }); console.log("-----------------------------------"); } diff --git a/protocol/reseed/reseedDeployL2Beanstalk.js b/protocol/reseed/reseedDeployL2Beanstalk.js index e9c113e16..ccbab0495 100644 --- a/protocol/reseed/reseedDeployL2Beanstalk.js +++ b/protocol/reseed/reseedDeployL2Beanstalk.js @@ -1,5 +1,6 @@ const { deployDiamond } = require("../scripts/diamond.js"); -const { impersonateSigner, mintEth } = require("../utils"); +const { mintEth } = require("../utils"); +const { retryOperation } = require("../utils/read.js"); /** * @notice Deploys a new beanstalk diamond contract without any facets. Should be on an L2. @@ -13,12 +14,14 @@ async function reseedDeployL2Beanstalk(account, verbose = true, mock) { // owner is initially the deployer. Upon the verification of the diamond, // the deployer will transfer ownership to the beanstalk owner. - const beanstalkDiamond = await deployDiamond({ - diamondName: "L2BeanstalkDiamond", - ownerAddress: account.address, - deployer: account, - args: [], - verbose: verbose + const beanstalkDiamond = await retryOperation(async () => { + return await deployDiamond({ + diamondName: "L2BeanstalkDiamond", + ownerAddress: account.address, + deployer: account, + args: [], + verbose: verbose + }); }); return beanstalkDiamond.address; diff --git a/protocol/reseed/reseedGlobal.js b/protocol/reseed/reseedGlobal.js index 887ae9dac..d4a3b1d00 100644 --- a/protocol/reseed/reseedGlobal.js +++ b/protocol/reseed/reseedGlobal.js @@ -1,7 +1,7 @@ const { upgradeWithNewFacets } = require("../scripts/diamond.js"); const { deployContract } = require("../scripts/contracts"); const fs = require("fs"); - +const { retryOperation } = require("../utils/read.js"); async function reseedGlobal(account, L2Beanstalk, mock) { console.log("-----------------------------------"); console.log("reseedGlobal: reseedGlobal.\n"); @@ -18,14 +18,16 @@ async function reseedGlobal(account, L2Beanstalk, mock) { settings[9][1][0] = ShipmentPlanner.address; settings[9][2][0] = ShipmentPlanner.address; - await upgradeWithNewFacets({ - diamondAddress: L2Beanstalk, - facetNames: [], - initFacetName: "ReseedGlobal", - initArgs: [settings], - bip: false, - verbose: true, - account: account + await retryOperation(async () => { + await upgradeWithNewFacets({ + diamondAddress: L2Beanstalk, + facetNames: [], + initFacetName: "ReseedGlobal", + initArgs: [settings], + bip: false, + verbose: true, + account: account + }); }); console.log("-----------------------------------"); } diff --git a/protocol/reseed/reseedL2.js b/protocol/reseed/reseedL2.js index 2da042038..b1d42a3e7 100644 --- a/protocol/reseed/reseedL2.js +++ b/protocol/reseed/reseedL2.js @@ -35,9 +35,8 @@ async function reseedL2({ start = 0, end = 11, setState = true, - deployBasin = false, addLiquidity = true, - verbose = true, + verbose = false, onlyState = true }) { if (convertData) parseBeanstalkData(); @@ -85,13 +84,7 @@ async function reseedL2({ ]); console.log("BeanstalkPrice:", beanstalkPrice.address); // deploy bean addresses. - await reseed2( - beanstalkDeployer, - l2BeanstalkAddress, - deployBasin, - fertilizerImplementation.address, - mock - ); + await reseed2(beanstalkDeployer, l2BeanstalkAddress, fertilizerImplementation.address, mock); continue; } diff --git a/protocol/utils/read.js b/protocol/utils/read.js index f68aa6316..ba4075f44 100644 --- a/protocol/utils/read.js +++ b/protocol/utils/read.js @@ -76,8 +76,31 @@ async function updateProgress(current, total) { process.stdout.write(`Processing: [${progressBar}] ${percentage}% | Chunk ${current}/${total}`); } +const MAX_RETRIES = 5; +const RETRY_DELAY = 5000; // 5 seconds + +async function sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +async function retryOperation(operation, retries = MAX_RETRIES) { + try { + return await operation(); + } catch (error) { + if (retries > 0 && error.message.includes("Internal server error")) { + console.log( + `RPC error encountered. Retrying in ${RETRY_DELAY / 1000} seconds... (${retries} attempts left)` + ); + await sleep(RETRY_DELAY); + return retryOperation(operation, retries - 1); + } + throw error; + } +} + exports.readPrune = readPrune; exports.splitEntriesIntoChunks = splitEntriesIntoChunks; exports.splitEntriesIntoChunksOptimized = splitEntriesIntoChunksOptimized; exports.updateProgress = updateProgress; exports.convertToBigNum = convertToBigNum; +exports.retryOperation = retryOperation;