Skip to content

Commit

Permalink
broken, stashing here
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol committed Jan 30, 2025
1 parent 9a42151 commit d66a653
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 32 deletions.
90 changes: 60 additions & 30 deletions packages/protocol/migrations_sol/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
console.log(" Implementation deployed to:", address(implementation));
console.log(" Calling initialize(..)");
proxy._setAndInitializeImplementation(implementation, initializeCalldata);
console.log("Finised initialize");
}

function deployImplementationAndAddToRegistry(
string memory contractName,
IProxy proxy,
bytes memory initializeCalldata
) public {
console.log("Owner is:", proxy._getOwner());
setImplementationOnProxy(proxy, contractName, initializeCalldata);
addToRegistry(contractName, address(proxy));
}

function deployProxiedContract(
Expand All @@ -164,8 +175,10 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
IProxy proxy = IProxy(toProxy);
console.log(" Proxy deployed to:", toProxy);

setImplementationOnProxy(proxy, contractName, initializeCalldata);
addToRegistry(contractName, address(proxy));
// setImplementationOnProxy(proxy, contractName, initializeCalldata);
// addToRegistry(contractName, address(proxy));
deployImplementationAndAddToRegistry(contractName, proxy, initializeCalldata);

console.log(" Done deploying:", contractName);
console.log("------------------------------");
}
Expand All @@ -187,9 +200,7 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
IProxy proxy = IProxy(proxyAddress);
console.log(" Proxy deployed to:", address(proxy));

setImplementationOnProxy(proxy, contractName, initializeCalldata);
addToRegistry(contractName, address(proxy));

deployImplementationAndAddToRegistry(contractName, proxy, initializeCalldata);
console.log(" Done deploying:", contractName);
console.log("------------------------------");
}
Expand All @@ -216,7 +227,7 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
migrateFeeCurrencyDirectory();
migrateCeloToken(json);
migrateSortedOracles(json);
// migrateGasPriceMinimum(json);
// // migrateGasPriceMinimum(json);
migrateReserveSpenderMultiSig(json);
migrateReserve(json);
migrateStableToken(json);
Expand All @@ -243,25 +254,25 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
migrateCeloUnreleasedTreasury();
vm.stopBroadcast();

// needs to broadcast from a pre-funded account
fundCeloUnreleasedTreasury();
// // needs to broadcast from a pre-funded account
// fundCeloUnreleasedTreasury();

vm.startBroadcast(DEPLOYER_ACCOUNT);
migrateEpochManagerEnabler();
migrateEpochManager(json);
migrateScoreManager();
migrateGovernance(json);
vm.stopBroadcast();
// vm.startBroadcast(DEPLOYER_ACCOUNT);
// migrateEpochManagerEnabler();
// migrateEpochManager(json);
// migrateScoreManager();
// migrateGovernance(json);
// vm.stopBroadcast();

// Functions with broadcast with different addresses
// Validators needs to lock, which can be only used by the msg.sender
electValidators(json);
// // Functions with broadcast with different addresses
// // Validators needs to lock, which can be only used by the msg.sender
// electValidators(json);

vm.startBroadcast(DEPLOYER_ACCOUNT);
// vm.startBroadcast(DEPLOYER_ACCOUNT);

// captureEpochManagerEnablerValidators();
// // captureEpochManagerEnablerValidators();

vm.stopBroadcast();
// vm.stopBroadcast();
}

/**
Expand All @@ -273,14 +284,14 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
}

function migrateRegistry() public {
// setImplementationOnProxy(
// IProxy(REGISTRY_ADDRESS),
// "Registry",
// abi.encodeWithSelector(IRegistryInitializer.initialize.selector)
// );
deployImplementationAndAddToRegistry(
"Registry",
IProxy(REGISTRY_ADDRESS),
abi.encodeWithSelector(IRegistryInitializer.initialize.selector)
);
// set registry in registry itself
// console.log("Owner of the Registry Proxy is", IProxy(REGISTRY_ADDRESS)._getOwner());
addToRegistry("Registry", REGISTRY_ADDRESS);
console.log("Owner of the Registry Proxy is", IProxy(REGISTRY_ADDRESS)._getOwner());
// addToRegistry("Registry", REGISTRY_ADDRESS);
console.log("Done migration registry");
}

Expand All @@ -307,13 +318,21 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {

function migrateCeloToken(string memory json) public {
// TODO change pre-funded addresses to make it match circulation supply
address celoProxyAddress = deployProxiedContract(
// address celoProxyAddress = deployProxiedContract(
// "GoldToken",
// abi.encodeWithSelector(ICeloTokenInitializer.initialize.selector, REGISTRY_ADDRESS)
// );

address celoProxyAddress = 0x471EcE3750Da237f93B8E339c536989b8978a438;
console.log("Gold token Proxy not redeployed, using existing proxy ");
deployImplementationAndAddToRegistry(
"GoldToken",
IProxy(celoProxyAddress),
abi.encodeWithSelector(ICeloTokenInitializer.initialize.selector, REGISTRY_ADDRESS)
);

addToRegistry("CeloToken", celoProxyAddress);
addToRegistry("GoldToken", celoProxyAddress);
// addToRegistry("GoldToken", celoProxyAddress);
bool frozen = abi.decode(json.parseRaw(".goldToken.frozen"), (bool));
if (frozen) {
getFreezer().freeze(celoProxyAddress);
Expand Down Expand Up @@ -941,13 +960,24 @@ contract Migration is Script, UsingRegistry, MigrationsConstants {
}

function migrateCeloUnreleasedTreasury() public {
address celoUnreleasedTreasury = deployProxiedContract(
address celoUnreleasedTreasury = 0xB76D502Ad168F9D545661ea628179878DcA92FD5;
console.log("CeloUnreleasedTreasury Proxy not redeployed, using existing proxy ");
deployImplementationAndAddToRegistry(
"CeloUnreleasedTreasury",
IProxy(celoUnreleasedTreasury),
abi.encodeWithSelector(
ICeloUnreleasedTreasuryInitializer.initialize.selector,
REGISTRY_ADDRESS
)
);

// address celoUnreleasedTreasury = deployProxiedContract(
// "CeloUnreleasedTreasury",
// abi.encodeWithSelector(
// ICeloUnreleasedTreasuryInitializer.initialize.selector,
// REGISTRY_ADDRESS
// )
// );
}

function fundCeloUnreleasedTreasury() public {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/scripts/foundry/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export MIGRATION_L2_SCRIPT_PATH="migrations_sol/MigrationL2.s.sol" # Path to L2
export MIGRATION_TARGET_CONTRACT="Migration" # The name of the contract you want to run.
export MIGRATION_L2_TARGET_CONTRACT="MigrationL2" # The name of the contract you want to run.
export BROADCAST="--broadcast" # Broadcasts the transactions. Enable: "--broadcast" / Disable: ""
# export SKIP_SIMULATION="--skip-simulation" # Skips on-chain simulation. Enable: "--skip-simulation" / Disable: ""
export SKIP_SIMULATION="" # Skips on-chain simulation. Enable: "--skip-simulation" / Disable: ""
export NON_INTERACTIVE="--non-interactive" # Remove interactive prompts which appear if the contract is near the EIP-170 size limit.
export VERBOSITY_LEVEL="-vvv" # Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ mkdir -p $TMP_FOLDER
ANVIL_PORT=9545
ANVIL_RPC_URL="http://127.0.0.1:9545"
source $PWD/scripts/foundry/deploy_libraries.sh
echo "Library flags are: $LIBRARY_FLAGS"

# export LIBRARY_FLAGS="--libraries contracts/common/linkedlists/AddressSortedLinkedListWithMedian.sol:AddressSortedLinkedListWithMedian:0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690 --libraries contracts/common/Signatures.sol:Signatures:0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --libraries contracts-0.8/common/linkedlists/AddressLinkedList.sol:AddressLinkedList:0x9E545E3C0baAB3E08CdfD552C960A1050f373042 --libraries contracts/common/linkedlists/AddressSortedLinkedList.sol:AddressSortedLinkedList:0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9 --libraries contracts/common/linkedlists/IntegerSortedLinkedList.sol:IntegerSortedLinkedList:0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8 --libraries contracts/governance/Proposals.sol:Proposals:0x851356ae760d987E095750cCeb3bC6014560891C"

echo "Library flags are: $LIBRARY_FLAGS"
# Build all contracts with deployed libraries
# Including contracts that depend on libraries. This step replaces the library placeholder
# in the bytecode with the address of the actually deployed library.
Expand All @@ -48,18 +50,25 @@ time FOUNDRY_PROFILE=devchain forge build $LIBRARY_FLAGS
# $REGISTRY_ADDRESS $REGISTRY_STORAGE_LOCATION "0x000000000000000000000000$REGISTRY_OWNER_ADDRESS" \
# --rpc-url $ANVIL_RPC_URL


# Can't do the transfer here
# cast send 0xB76D502Ad168F9D545661ea628179878DcA92FD5 --value 390000000000000000000000000 --rpc-url http://localhost:9545 --private-key 59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d

# Run migrations
echo "Running migration script... "
forge script \
$MIGRATION_SCRIPT_PATH \
--target-contract $MIGRATION_TARGET_CONTRACT \
--sender $FROM_ACCOUNT \
--unlocked \
# --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--unlocked
$VERBOSITY_LEVEL \
$BROADCAST \
$SKIP_SIMULATION \
$NON_INTERACTIVE \
$LIBRARY_FLAGS \
# --slow \
# --gas-price 4331510
--rpc-url $ANVIL_RPC_URL || { echo "Migration script failed"; exit 1; }

CELO_EPOCH_REWARDS_ADDRESS=$(
Expand All @@ -70,13 +79,18 @@ CELO_EPOCH_REWARDS_ADDRESS=$(
--rpc-url $ANVIL_RPC_URL
)


cast send 0xB76D502Ad168F9D545661ea628179878DcA92FD5 --value 390000000000000000000000000 --rpc-url http://localhost:9545 --private-key 59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d


echo "Setting storage of EpochRewards start time to same value as on mainnet"
# Storage slot of start time is 2 and the value is 1587587214 which is identical to mainnet
cast rpc \
anvil_setStorageAt \
$CELO_EPOCH_REWARDS_ADDRESS 2 "0x000000000000000000000000000000000000000000000000000000005ea0a88e" \
--rpc-url $ANVIL_RPC_URL


# Keeping track of the finish time to measure how long it takes to run the script entirely
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Migration script total elapsed time: $ELAPSED_TIME seconds"
Expand Down

0 comments on commit d66a653

Please sign in to comment.