-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration to upgrade contracts
- Loading branch information
1 parent
81c1b99
commit 47496f6
Showing
16 changed files
with
606 additions
and
18 deletions.
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
broadcast/21-multiple_upgrade.sol/7887/dry-run/run-1706036947.json
Large diffs are not rendered by default.
Oops, something went wrong.
190 changes: 190 additions & 0 deletions
190
broadcast/21-multiple_upgrade.sol/7887/dry-run/run-latest.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "../../src/wallet/KintoWalletFactory.sol"; | ||
import "../../src/wallet/KintoWallet.sol"; | ||
import "../../src/apps/KintoAppRegistry.sol"; | ||
import "../../src/paymasters/SponsorPaymaster.sol"; | ||
import "../../src/viewers/KYCViewer.sol"; | ||
import "../../src/KintoID.sol"; | ||
|
||
import "../../test/helpers/Create2Helper.sol"; | ||
import "../../test/helpers/ArtifactsReader.sol"; | ||
import "../../test/helpers/UUPSProxy.sol"; | ||
import "../../test/helpers/UserOp.sol"; | ||
|
||
import "forge-std/Script.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract KintoMigration21DeployScript is Create2Helper, ArtifactsReader, UserOp { | ||
using ECDSAUpgradeable for bytes32; | ||
|
||
KintoWalletFactory _walletFactory; | ||
uint256 deployerPrivateKey; | ||
|
||
// NOTE: this migration must be run from the ledger admin | ||
function run() public { | ||
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid)); | ||
|
||
deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
// execute this script with the with the ledger | ||
console.log("Executing from address", msg.sender); | ||
|
||
// set wallet factory | ||
_walletFactory = KintoWalletFactory(payable(_getChainDeployment("KintoWalletFactory"))); | ||
|
||
SponsorPaymasterV4 _paymasterImpl = SponsorPaymasterV4(upgradePaymaster()); | ||
console.log(string.concat("SponsorPaymasterV4-impl: ", vm.toString(address(_paymasterImpl)))); | ||
|
||
KintoAppRegistryV3 _registryImpl = KintoAppRegistryV3(upgradeRegistry()); | ||
console.log(string.concat("KintoAppRegistryV3-impl: ", vm.toString(address(_registryImpl)))); | ||
|
||
KintoWalletV4 _walletImpl = KintoWalletV4(payable(upgradeWallet())); | ||
console.log(string.concat("KintoWalletV4-impl: ", vm.toString(address(_walletImpl)))); | ||
|
||
KintoWalletFactoryV7 _factoryImpl = KintoWalletFactoryV7(upgradeFactory()); | ||
console.log(string.concat("KintoWalletFactoryV7-impl: ", vm.toString(address(_factoryImpl)))); | ||
|
||
KYCViewerV2 _kycViewerImpl = KYCViewerV2(upgradeKYCViewer()); | ||
console.log(string.concat("KYCViewerV2-impl: ", vm.toString(address(_kycViewerImpl)))); | ||
|
||
// writes the addresses to a file | ||
console.log("TODO: Manually add these new addresses to the artifacts file"); | ||
console.log(string.concat("SponsorPaymasterV4-impl: ", vm.toString(address(_paymasterImpl)))); | ||
console.log(string.concat("KintoAppRegistryV3-impl: ", vm.toString(address(_registryImpl)))); | ||
console.log(string.concat("KintoWalletV4-impl: ", vm.toString(address(_walletImpl)))); | ||
console.log(string.concat("KintoWalletFactoryV7-impl: ", vm.toString(address(_factoryImpl)))); | ||
console.log(string.concat("KYCViewerV2-impl: ", vm.toString(address(_kycViewerImpl)))); | ||
} | ||
|
||
function upgradePaymaster() public returns (address _paymasterImpl) { | ||
// (1). deploy new paymaster implementation via wallet factory | ||
address paymasterProxy = _getChainDeployment("SponsorPaymaster"); | ||
require(paymasterProxy != address(0), "Need to execute main deploy script first"); | ||
|
||
bytes memory bytecode = | ||
abi.encodePacked(type(SponsorPaymasterV4).creationCode, abi.encode(_getChainDeployment("EntryPoint"))); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
_paymasterImpl = _walletFactory.deployContract(vm.rememberKey(deployerPrivateKey), 0, bytecode, bytes32(0)); | ||
|
||
// (3). upgrade paymaster to new implementation | ||
vm.broadcast(); // requires LEDGER_ADMIN | ||
// vm.prank(vm.envAddress("LEDGER_ADMIN")); | ||
SponsorPaymaster(payable(paymasterProxy)).upgradeTo(address(_paymasterImpl)); | ||
} | ||
|
||
function upgradeRegistry() public returns (address _registryImpl) { | ||
// (1). deploy new kinto registry implementation via wallet factory | ||
address registryProxy = _getChainDeployment("KintoAppRegistry"); | ||
require(registryProxy != address(0), "Need to execute main deploy script first"); | ||
|
||
bytes memory bytecode = | ||
abi.encodePacked(type(KintoAppRegistryV3).creationCode, abi.encode(address(_walletFactory))); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
_registryImpl = | ||
_walletFactory.deployContract{value: 0}(vm.rememberKey(deployerPrivateKey), 0, bytecode, bytes32("1")); | ||
|
||
// (2). upgrade registry to new implementation | ||
_upgradeTo(payable(registryProxy), _registryImpl, deployerPrivateKey); | ||
} | ||
|
||
function upgradeWallet() public returns (address _walletImpl) { | ||
// (1). deploy new kinto wallet implementation via wallet factory | ||
bytes memory bytecode = abi.encodePacked( | ||
type(KintoWalletV4).creationCode, | ||
abi.encode( | ||
_getChainDeployment("EntryPoint"), | ||
IKintoID(_getChainDeployment("KintoID")), | ||
IKintoAppRegistry(_getChainDeployment("KintoAppRegistry")) | ||
) | ||
); | ||
vm.broadcast(deployerPrivateKey); | ||
_walletImpl = _walletFactory.deployContract(vm.rememberKey(deployerPrivateKey), 0, bytecode, bytes32(0)); | ||
|
||
// (2). upgrade all implementations | ||
vm.broadcast(); // requires LEDGER_ADMIN | ||
// vm.prank(vm.envAddress("LEDGER_ADMIN")); | ||
_walletFactory.upgradeAllWalletImplementations(IKintoWallet(_walletImpl)); | ||
} | ||
|
||
function upgradeFactory() public returns (address _factoryImpl) { | ||
// (1). deploy new kinto factory | ||
address factoryProxy = _getChainDeployment("KintoWalletFactory"); | ||
require(factoryProxy != address(0), "Need to execute main deploy script first"); | ||
|
||
address _walletImpl = _getChainDeployment("KintoWalletV3-impl"); | ||
require(_walletImpl != address(0), "Need to deploy the new wallet first"); | ||
|
||
bytes memory bytecode = abi.encodePacked( | ||
type(KintoWalletFactoryV7).creationCode, | ||
abi.encode(_walletImpl) // Encoded constructor arguments | ||
); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
_factoryImpl = _walletFactory.deployContract(vm.rememberKey(deployerPrivateKey), 0, bytecode, bytes32(0)); | ||
|
||
// (2). upgrade factory to new implementation | ||
vm.broadcast(); // requires LEDGER_ADMIN | ||
// vm.prank(vm.envAddress("LEDGER_ADMIN")); | ||
KintoWalletFactory(payable(factoryProxy)).upgradeTo(address(_factoryImpl)); | ||
} | ||
|
||
function upgradeKYCViewer() public returns (address _kycViewer) { | ||
// (1). deploy new kyc viewer | ||
address viewerProxy = _getChainDeployment("KYCViewer"); | ||
require(viewerProxy != address(0), "Need to execute main deploy script first"); | ||
|
||
bytes memory bytecode = abi.encodePacked( | ||
type(KYCViewerV2).creationCode, | ||
abi.encode(_walletFactory) // Encoded constructor arguments | ||
); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
_kycViewer = _walletFactory.deployContract(vm.rememberKey(deployerPrivateKey), 0, bytecode, bytes32(0)); | ||
|
||
// (2). upgrade viewer to new implementation | ||
vm.broadcast(); // requires LEDGER_ADMIN | ||
// vm.prank(vm.envAddress("LEDGER_ADMIN")); | ||
KYCViewer(payable(viewerProxy)).upgradeTo(address(_kycViewer)); | ||
} | ||
|
||
function _upgradeTo(address proxy, address _newFaucetImpl, uint256 _signerPk) internal { | ||
address payable adminWallet = payable(_getChainDeployment("KintoWallet-admin")); | ||
|
||
// prep upgradeTo user op | ||
uint256 nonce = IKintoWallet(adminWallet).getNonce(); | ||
uint256[] memory privateKeys = new uint256[](1); | ||
privateKeys[0] = _signerPk; | ||
UserOperation[] memory userOps = new UserOperation[](1); | ||
userOps[0] = _createUserOperation( | ||
block.chainid, | ||
adminWallet, | ||
proxy, | ||
0, | ||
nonce, | ||
privateKeys, | ||
abi.encodeWithSelector(UUPSUpgradeable.upgradeTo.selector, address(_newFaucetImpl)), | ||
_getChainDeployment("SponsorPaymaster") | ||
); | ||
|
||
vm.broadcast(deployerPrivateKey); | ||
IEntryPoint(_getChainDeployment("EntryPoint")).handleOps(userOps, payable(vm.addr(_signerPk))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters