Skip to content

Commit

Permalink
Merge branch 'reseed-testnet-deployment' into spacebean/bs3/testnet-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean authored Sep 23, 2024
2 parents 4e54ee1 + d5714c8 commit e3d9cc1
Show file tree
Hide file tree
Showing 8 changed files with 3,699 additions and 46 deletions.
11 changes: 5 additions & 6 deletions protocol/contracts/beanstalk/init/reseed/L2/ReseedGlobal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import "contracts/beanstalk/storage/System.sol";
import {AppStorage} from "contracts/beanstalk/storage/AppStorage.sol";
import {LibTractor} from "contracts/libraries/LibTractor.sol";
import {LibCases} from "contracts/libraries/LibCases.sol";
import {C} from "contracts/C.sol";
import {Distribution} from "contracts/beanstalk/sun/SeasonFacet/Distribution.sol";

/**
* @author Brean
* @notice ReseedGlobal sets the global state of Beanstalk.
* @dev Pod Orders and Listings are ommited and are set in a seperate reseed contract.
*/
contract ReseedGlobal {
AppStorage internal s;

contract ReseedGlobal is Distribution {
/**
* @param system contains the global state of Beanstalk.
* 1) replaces mappings with arrays, so that the state can be re-initialized.
Expand Down Expand Up @@ -89,7 +87,7 @@ contract ReseedGlobal {

LibCases.setCasesV2();
setInternalBalanceTotals(system.sysBalances);
setShipmentRoutes(system.shipmentRoutes);
_setShipmentRoutes(system.shipmentRoutes);
setSilo(system.sysSilo);
setFertilizer(system.sysFert);
s.sys.fields[0] = system.f;
Expand Down Expand Up @@ -165,10 +163,11 @@ contract ReseedGlobal {
* @notice sets the routes.
* @dev Solidity does not support direct assignment of array structs to Storage.
*/
function setShipmentRoutes(ShipmentRoute[] calldata routes) internal {
function _setShipmentRoutes(ShipmentRoute[] calldata routes) internal {
for (uint i; i < routes.length; i++) {
s.sys.shipmentRoutes.push(routes[i]);
}
emit ShipmentRoutesSet(routes);
}

function setTractor() internal {
Expand Down
3 changes: 2 additions & 1 deletion protocol/contracts/libraries/LibEvaluate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ library LibEvaluate {
for (uint256 i; i < pools.length; i++) {
// get the non-bean value in an LP.
twaReserves = LibWell.getTwaReservesFromStorageOrBeanstalkPump(pools[i]);

// if the twaReserves are 0, the well has no liquidity and thus can be skipped
if (twaReserves[0] == 0 && twaReserves[1] == 0) continue;
// calculate the non-bean usd liquidity value.
uint256 usdLiquidity = LibWell.getWellTwaUsdLiquidityFromReserves(
pools[i],
Expand Down
21 changes: 12 additions & 9 deletions protocol/contracts/libraries/Minting/LibWellMinting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,18 @@ library LibWellMinting {
uint256 beanIndex
) internal view returns (int256) {
Call memory wellFunction = IWell(well).wellFunction();
return
int256(
IBeanstalkWellFunction(wellFunction.target).calcReserveAtRatioSwap(
reserves,
beanIndex,
ratios,
wellFunction.data
)
).sub(int256(reserves[beanIndex]));
try
IBeanstalkWellFunction(wellFunction.target).calcReserveAtRatioSwap(
reserves,
beanIndex,
ratios,
wellFunction.data
)
returns (uint256 reserveAtRatioSwap) {
return int256(reserveAtRatioSwap).sub(int256(reserves[beanIndex]));
} catch {
return 0;
}
}

/**
Expand Down
21 changes: 12 additions & 9 deletions protocol/contracts/libraries/Oracle/LibDeltaB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,17 @@ library LibDeltaB {
revert("Well: USD Oracle call failed");
}

return
int256(
IBeanstalkWellFunction(wellFunction.target).calcReserveAtRatioSwap(
reserves,
beanIndex,
ratios,
wellFunction.data
)
).sub(int256(reserves[beanIndex]));
try
IBeanstalkWellFunction(wellFunction.target).calcReserveAtRatioSwap(
reserves,
beanIndex,
ratios,
wellFunction.data
)
returns (uint256 reserve) {
return int256(reserve).sub(int256(reserves[beanIndex]));
} catch {
return 0;
}
}
}
26 changes: 8 additions & 18 deletions protocol/reseed/dataConverts/convertGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,14 @@ function parseGlobals(inputFilePath, outputFilePath) {
"5000000"
],
// ShipmentRoute
// data.shipmentRoutes.length
// ? data.shipmentRoutes.map((route) => [
// route.planContract || "0x0000000000000000000000000000000000000000",
// route.planSelector || "0x00000000",
// route.recipient ? convertToBigNum(route.recipient) : "0",
// route.data || "0x"
// ])
// : [["0x0000000000000000000000000000000000000000", "0x00000000", "0", "0x"]]
[
["0x0000000000000000000000000000000000000000", "0x7c655075", "1", "0x"],
[
"0x0000000000000000000000000000000000000000",
"0x12e8d3ed",
"2",
"0x0000000000000000000000000000000000000000000000000000000000000000"
],
["0x0000000000000000000000000000000000000000", "0x43055ba8", "3", "0x"]
]
data.shipmentRoutes.length
? data.shipmentRoutes.map((route) => [
route.planContract || "0x0000000000000000000000000000000000000000",
route.planSelector || "0x00000000",
route.recipient ? convertToBigNum(route.recipient) : "0",
route.data || "0x"
])
: [["0x0000000000000000000000000000000000000000", "0x00000000", "0", "0x"]]
];

fs.writeFileSync(outputFilePath, JSON.stringify(result, null, 2));
Expand Down
2 changes: 1 addition & 1 deletion protocol/reseed/reseed3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function reseed3(account, L2Beanstalk, mock, verbose = false) {
// Read and parse the JSON file
const accountPlots = JSON.parse(await fs.readFileSync(farmerPlotsPath));

targetEntriesPerChunk = 800;
targetEntriesPerChunk = 500;
plotChunks = await splitEntriesIntoChunksOptimized(accountPlots, targetEntriesPerChunk);
const InitFacet = await (await ethers.getContractFactory("ReseedField", account)).deploy();
await InitFacet.deployed();
Expand Down
4 changes: 3 additions & 1 deletion protocol/reseed/reseedL2.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async function reseedL2({
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"],
Expand All @@ -88,8 +89,9 @@ async function reseedL2({
initFacetNameInfo: "ReseedTransferOwnership"
});
}
if (i == reseeds.length - 1 && !onlyState) {
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);
Expand Down
Loading

0 comments on commit e3d9cc1

Please sign in to comment.