Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kinto App Registry #28

Merged
merged 48 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
920e9f7
KintoApp
rrecuero Jan 4, 2024
ae08457
Complete functionality
rrecuero Jan 5, 2024
d68e8db
Modifies paymaster to read from sponsored contracts
rrecuero Jan 5, 2024
670ed46
Makes paymaster a bit more resilient
rrecuero Jan 5, 2024
4ef149e
Get gas limits from app registry
rrecuero Jan 5, 2024
d2f8616
Changes in the wallet
rrecuero Jan 5, 2024
78764b6
forge fmt
rrecuero Jan 5, 2024
359c6e6
Merge with latest
rrecuero Jan 5, 2024
7c5fea6
cleanup
rrecuero Jan 6, 2024
1481634
Merge branch 'main' into kintoapps
rrecuero Jan 6, 2024
ac7f7ba
Merge branch 'main' into kintoapps
rrecuero Jan 6, 2024
501e31b
First tests of KintoApp
rrecuero Jan 6, 2024
a735230
mechanism to set the new param in wallet impl
rrecuero Jan 6, 2024
7983d4d
More tests passing
rrecuero Jan 6, 2024
3df9a65
More test fixes
rrecuero Jan 7, 2024
8e638e2
forge format
rrecuero Jan 7, 2024
ea66e1d
All tests passing
rrecuero Jan 7, 2024
7ff1442
Tests for KintoApp
rrecuero Jan 7, 2024
fbcc9cc
Renames app registry
rrecuero Jan 7, 2024
2c0df80
Renames isContractSponsored
rrecuero Jan 7, 2024
077dc3f
Adds events
rrecuero Jan 7, 2024
17cc6a6
Struct packing
rrecuero Jan 7, 2024
5b64e26
Changes AccessControl to ownable in KintoAppRegistry
rrecuero Jan 7, 2024
d972bee
Fixes KYC viewer issue
rrecuero Jan 7, 2024
c686a75
Adds needed migrations
rrecuero Jan 7, 2024
09cba14
Update src/paymasters/SponsorPaymaster.sol
rrecuero Jan 8, 2024
d703a1f
Update src/paymasters/SponsorPaymaster.sol
rrecuero Jan 8, 2024
b8dabf4
Merge with latest
rrecuero Jan 8, 2024
ec08496
Changes compiler version
rrecuero Jan 8, 2024
f5fc112
Update src/apps/KintoAppRegistry.sol
rrecuero Jan 8, 2024
f7072a2
Update test/KintoAppRegistry.t.sol
rrecuero Jan 8, 2024
a2e1334
Addresses comments
rrecuero Jan 8, 2024
e3c2b8e
more comments
rrecuero Jan 8, 2024
ab6a8f2
Adds missing events
rrecuero Jan 8, 2024
59b92f7
broadcast
rrecuero Jan 8, 2024
5be6ae1
comments
rrecuero Jan 8, 2024
cc537c5
Fixes app whitelist and child parent req
rrecuero Jan 8, 2024
5b7d846
refactor: rmv unneeded files
fedealconada Jan 8, 2024
bb63af7
refactor: unify Counter contracts
fedealconada Jan 8, 2024
de4b17f
refactor: rename _kintoApp as _kintoAppRegistry
fedealconada Jan 8, 2024
6e06940
chore: rebase
fedealconada Jan 8, 2024
6a2f601
refactor: some refactors on the tests files and also renamed setAppWh…
fedealconada Jan 8, 2024
352f592
test: add whitelist tests
fedealconada Jan 8, 2024
2b391a7
test: add more tests
fedealconada Jan 9, 2024
6f1ac47
Merge pull request #32 from KintoXYZ/registry-tests
fedealconada Jan 9, 2024
52e7be4
Register app gated by deployer
rrecuero Jan 9, 2024
db286ec
Modifies migration
rrecuero Jan 9, 2024
1f8cd4b
Makes app registry immutable
rrecuero Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ KINTO_RPC_URL="https://kinto-mainnet.calderachain.xyz/http"
MAINNET_NETWORK_ID="7887"
TESTNET_NETWORK_ID="7887000"
KINTO_EXPLORER_URL="https://kinto-mainnet.calderaexplorer.xyz/"
LEDGER_ADMIN=""
2 changes: 1 addition & 1 deletion script/deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {
console.log("Wallet Implementation already deployed at", address(walletImplementationAddr));
} else {
// Deploy Wallet Implementation
_walletImpl = new KintoWallet{salt: 0}(_entryPoint, _kintoIDv1);
_walletImpl = new KintoWallet{salt: 0}(_entryPoint, _kintoIDv1, IKintoAppRegistry(address(0)));
console.log("Wallet Implementation deployed at", address(_walletImpl));
}

Expand Down
9 changes: 8 additions & 1 deletion script/migrations/02-upgrade_wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/wallet/KintoWalletFactory.sol";
import {KintoWalletV2} from "../../src/wallet/KintoWallet.sol";
import {KintoWallet} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
Expand All @@ -12,6 +12,13 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

// Upgradeable version of KintoWallet
contract KintoWalletV2 is KintoWallet {
constructor(IEntryPoint _entryPoint, IKintoID _kintoID)
KintoWallet(_entryPoint, _kintoID, IKintoAppRegistry(address(0)))
rrecuero marked this conversation as resolved.
Show resolved Hide resolved
{}
}

contract KintoMigration2DeployScript is Create2Helper, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

Expand Down
1 change: 0 additions & 1 deletion script/migrations/04-deploy_admin_wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import "../../src/wallet/KintoWalletFactory.sol";
import "../../src/KintoID.sol";
import {KintoWalletV2} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
Expand Down
1 change: 0 additions & 1 deletion script/migrations/05-deploy_faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/Faucet.sol";
import {KintoWalletV2} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
Expand Down
1 change: 0 additions & 1 deletion script/migrations/06-counter_advance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/sample/Counter.sol";
import {KintoWalletV2} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
Expand Down
60 changes: 60 additions & 0 deletions script/migrations/07-deploy_kinto_app.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/apps/KintoAppRegistry.sol";
import "../../src/paymasters/SponsorPaymaster.sol";
import "../../src/interfaces/IKintoWalletFactory.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract KintoMigration7DeployScript is Create2Helper, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

KintoAppRegistry _kintoApp;

function setUp() public {}

// solhint-disable code-complexity
function run() public {
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid));
// Execute this script with the hot wallet, not with ledger
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address admin = vm.envAddress("LEDGER_ADMIN");
if (admin == address(0)) {
console.log("Admin key not set", admin);
return;
}
vm.startBroadcast(deployerPrivateKey);
rrecuero marked this conversation as resolved.
Show resolved Hide resolved
console.log("Executing with address", msg.sender);
address appAddr = _getChainDeployment("KintoAppRegistry");
if (appAddr != address(0)) {
console.log("KintoAppRegistry already deployed", appAddr);
return;
}
address walletFactoryAddr = _getChainDeployment("KintoWalletFactory");
IKintoWalletFactory _walletFactory = IKintoWalletFactory(walletFactoryAddr);
_kintoApp = KintoAppRegistry(
_walletFactory.deployContract(
msg.sender, 0, abi.encodePacked(type(KintoAppRegistry).creationCode), bytes32(0)
)
);
// Give ownership to admin
_kintoApp.transferOwnership(admin);
address credits = _getChainDeployment("EngenCredits");
// Create Engen App
_kintoApp.registerApp("Engen", credits, new address[](0), [uint256(0), uint256(0), uint256(0), uint256(0)]);
// Fund in the paymaster
SponsorPaymaster _paymaster = SponsorPaymaster(payable(_getChainDeployment("SponsorPaymaster")));
_paymaster.addDepositFor{value: 1e17}(credits);
vm.stopBroadcast();
// Writes the addresses to a file
console.log("Add these new addresses to the artifacts file");
console.log(string.concat('"KintoAppRegistry": "', vm.toString(address(_kintoApp)), '"'));
}
}
60 changes: 60 additions & 0 deletions script/migrations/08-upgrade_wallet_v3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/wallet/KintoWalletFactory.sol";
import {KintoWallet} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract KintoMigration8DeployScript is Create2Helper, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

KintoWalletFactory _walletFactory;
KintoWalletV3 _kintoWalletImpl;
UUPSProxy _proxy;

function setUp() public {}

// solhint-disable code-complexity
function run() public {
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid));
// Execute this script with the ledger admin
console.log("Executing with address", msg.sender);
vm.startBroadcast();
address walletFactoryAddr = _getChainDeployment("KintoWalletFactory");
if (walletFactoryAddr == address(0)) {
console.log("Need to execute main deploy script first", walletFactoryAddr);
return;
}
address kintoAppAddr = _getChainDeployment("KintoAppRegistry");
if (kintoAppAddr == address(0)) {
console.log("Need to deploy kinto app registry first", kintoAppAddr);
return;
}
_walletFactory = KintoWalletFactory(payable(walletFactoryAddr));

bytes memory bytecode = abi.encodePacked(
abi.encodePacked(type(KintoWalletV3).creationCode),
abi.encode(
_getChainDeployment("EntryPoint"),
IKintoID(_getChainDeployment("KintoID")),
IKintoAppRegistry(_getChainDeployment("KintoAppRegistry"))
) // Encoded constructor arguments
);

// Deploy new wallet implementation
_kintoWalletImpl = KintoWalletV3(payable(_walletFactory.deployContract(msg.sender, 0, bytecode, bytes32(0))));
// Upgrade all implementations
_walletFactory.upgradeAllWalletImplementations(_kintoWalletImpl);
vm.stopBroadcast();
// Writes the addresses to a file
console.log("Add these new addresses to the artifacts file");
console.log(string.concat('"KintoWalletV3-impl": "', vm.toString(address(_kintoWalletImpl)), '"'));
}
}
54 changes: 54 additions & 0 deletions script/migrations/09-upgrade_paymasterv2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/wallet/KintoWalletFactory.sol";
import "../../src/paymasters/SponsorPaymaster.sol";
import {KintoWallet} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract KintoMigration9DeployScript is Create2Helper, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

SponsorPaymaster _paymaster;
KintoWalletFactory _walletFactory;
SponsorPaymasterV2 _paymasterImpl;
UUPSProxy _proxy;

function setUp() public {}

// solhint-disable code-complexity
function run() public {
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid));
// Execute this script with the ledger admin
console.log("Executing with address", msg.sender);
vm.startBroadcast();
address sponsorAddr = _getChainDeployment("SponsorPaymaster");
if (sponsorAddr == address(0)) {
console.log("Need to execute main deploy script first", sponsorAddr);
return;
}
_paymaster = SponsorPaymaster(payable(sponsorAddr));

_walletFactory = KintoWalletFactory(payable(_getChainDeployment("KintoWalletFactory")));
bytes memory bytecode = abi.encodePacked(
abi.encodePacked(type(SponsorPaymasterV2).creationCode),
abi.encode(_getChainDeployment("EntryPoint")) // Encoded constructor arguments
);

// Deploy new paymaster implementation
_paymasterImpl = SponsorPaymasterV2(payable(_walletFactory.deployContract(msg.sender, 0, bytecode, bytes32(0))));
// Upgrade
_paymaster.upgradeTo(address(_paymasterImpl));
vm.stopBroadcast();
// Writes the addresses to a file
console.log("Add these new addresses to the artifacts file");
console.log(string.concat('"SponsorPaymasterV2-impl": "', vm.toString(address(_paymasterImpl)), '"'));
}
}
56 changes: 56 additions & 0 deletions script/migrations/10-upgrade_wallet_factoryv2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../../src/wallet/KintoWalletFactory.sol";
import {KintoWallet} from "../../src/wallet/KintoWallet.sol";
import {Create2Helper} from "../../test/helpers/Create2Helper.sol";
import {ArtifactsReader} from "../../test/helpers/ArtifactsReader.sol";
import {UUPSProxy} from "../../test/helpers/UUPSProxy.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract KintoMigration9DeployScript is Create2Helper, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

KintoWalletFactory _walletFactory;
KintoWalletFactoryV2 _factoryImpl;
UUPSProxy _proxy;

function setUp() public {}

// solhint-disable code-complexity
function run() public {
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid));
// Execute this script with the ledger admin
console.log("Executing with address", msg.sender);
vm.startBroadcast();
address factoryAddr = _getChainDeployment("KintoWalletFactory");
if (factoryAddr == address(0)) {
console.log("Need to execute main deploy script first", factoryAddr);
return;
}
_walletFactory = KintoWalletFactory(payable(_getChainDeployment("KintoWalletFactory")));

address newImpl = _getChainDeployment("KintoWalletV3-impl");
if (newImpl == address(0)) {
console.log("Need to deploy the new wallet first", newImpl);
return;
}
bytes memory bytecode = abi.encodePacked(
abi.encodePacked(type(KintoWalletFactoryV2).creationCode),
abi.encode(_getChainDeployment("KintoWalletV3-impl")) // Encoded constructor arguments
);

// Deploy new paymaster implementation
_factoryImpl = KintoWalletFactoryV2(payable(_walletFactory.deployContract(msg.sender, 0, bytecode, bytes32(0))));
// Upgrade
_walletFactory.upgradeTo(address(_factoryImpl));
vm.stopBroadcast();
// Writes the addresses to a file
console.log("Add these new addresses to the artifacts file");
console.log(string.concat('"KintoWalletFactoryV2-impl": "', vm.toString(address(_factoryImpl)), '"'));
}
}
23 changes: 14 additions & 9 deletions script/upgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract KintoWalletFactoryV2 is KintoWalletFactory {
contract KintoWalletFactoryV999 is KintoWalletFactory {
constructor(KintoWallet _impl) KintoWalletFactory(_impl) {}
}

Expand All @@ -39,16 +39,18 @@ contract KintoWalletFactoryUpgradeScript is ArtifactsReader {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
_oldKintoWalletFactory = KintoWalletFactory(payable(_getChainDeployment("KintoWalletFactory")));
KintoWalletFactoryV2 _implementationV2 =
new KintoWalletFactoryV2(KintoWallet(payable(_getChainDeployment("KintoWallet-impl"))));
_oldKintoWalletFactory.upgradeTo(address(_implementationV2));
console.log("KintoWalletFactory Upgraded to implementation", address(_implementationV2));
KintoWalletFactoryV999 _implementationV999 =
new KintoWalletFactoryV999(KintoWallet(payable(_getChainDeployment("KintoWallet-impl"))));
_oldKintoWalletFactory.upgradeTo(address(_implementationV999));
console.log("KintoWalletFactory Upgraded to implementation", address(_implementationV999));
vm.stopBroadcast();
}
}

contract KintoWalletV3 is KintoWallet {
constructor(IEntryPoint _entryPoint, IKintoID _kintoIDv1) KintoWallet(_entryPoint, _kintoIDv1) {}
contract KintoWalletVTest is KintoWallet {
constructor(IEntryPoint _entryPoint, IKintoID _kintoIDv1, IKintoAppRegistry _kintoApp)
KintoWallet(_entryPoint, _kintoIDv1, _kintoApp)
{}
}

contract KintoWalletsUpgradeScript is ArtifactsReader {
Expand All @@ -66,8 +68,11 @@ contract KintoWalletsUpgradeScript is ArtifactsReader {

_walletFactory = KintoWalletFactory(payable(_getChainDeployment("KintoWalletFactory")));
// Deploy new wallet implementation
_kintoWalletImpl =
new KintoWalletV3(IEntryPoint(_getChainDeployment("EntryPoint")), IKintoID(_getChainDeployment("KintoID")));
_kintoWalletImpl = new KintoWalletVTest(
IEntryPoint(_getChainDeployment("EntryPoint")),
IKintoID(_getChainDeployment("KintoID")),
IKintoAppRegistry(_getChainDeployment("IKintoAppRegistry"))
);
// // Upgrade all implementations
_walletFactory.upgradeAllWalletImplementations(_kintoWalletImpl);
vm.stopBroadcast();
Expand Down
Loading
Loading