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

Nightfall/account recovery #10

Merged
merged 10 commits into from
Jan 11, 2024
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
url = "https://github.com/PaulRBerg/prb-test"
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
Expand All @@ -21,12 +21,12 @@
[submodule "lib/soul-wallet-contract"]
path = lib/soul-wallet-contract
url = https://github.com/proofofsoulprotocol/soul-wallet-contract
[submodule "lib/chainlink"]
path = lib/chainlink
url = https://github.com/smartcontractkit/chainlink
[submodule "lib/erc6551"]
path = lib/erc6551
url = https://github.com/erc6551/reference
[submodule "lib/tokenbound"]
path = lib/tokenbound
url = https://github.com/tokenbound/contracts
[submodule "lib/chainlink"]
path = lib/chainlink
url = https://github.com/smartcontractkit/chainlink
2 changes: 1 addition & 1 deletion lib/chainlink
Submodule chainlink updated 1615 files
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contr
openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/
openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/
prb-test/=lib/prb-test/src/
@chainlink/=lib/chainlink
@chainlink/=lib/chainlink/contracts/src/
@tokenbound/=lib/tokenbound/src/
@erc6551/=lib/erc6551/src/
19 changes: 11 additions & 8 deletions script/CreateVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import { Script } from "forge-std/Script.sol";
import { HelpersConfig } from "script/helpers/HelpersConfig.s.sol";
import { FileHelpers } from "script/helpers/FileHelpers.s.sol";
import { ERC6551Registry } from "@erc6551/ERC6551Registry.sol";

Check warning on line 7 in script/CreateVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ERC6551Registry is not used
import { IABGuardian as Guardian } from "src/IABGuardian.sol";
import { TokenShieldGuardian as Guardian } from "src/TokenShieldGuardian.sol";

Check warning on line 8 in script/CreateVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name Guardian is not used
import { TokenShieldSubscription as TokenShieldNft } from "src/TokenShieldSubscription.sol";
import { Vault } from "src/Vault.sol";

Check warning on line 10 in script/CreateVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name Vault is not used
import { MockAggregatorV3 } from "src/mock/MockPriceFeeds.sol";

Check warning on line 11 in script/CreateVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name MockAggregatorV3 is not used
import { ERC1967Proxy } from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol";

Check warning on line 12 in script/CreateVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ERC1967Proxy is not used
import { Vm } from "forge-std/Vm.sol";

contract CreateVault is Script, HelpersConfig, FileHelpers {
Expand All @@ -18,30 +18,33 @@
address tokenShieldNftAddress = 0x7C2562c8eC021c82E51E7C6737d3F613026e263d;
address erc6551RegistryAddress = 0xf8666e5042139b90670b5548BFBeCd61b9a45897;
address vaultImplAddress = 0xd2B513C2fC13C200c2f9E080C5b99fb5897F7E3e;
address recoveryManager = address(0);
if (chainId == 11_155_111) {
privateKey = vm.envUint("SEPOLIA_PRIVATE_KEY");
} else {
privateKey = vm.envUint("PRIVATE_KEY");
}
vm.startBroadcast(privateKey);
createdVault = createVault(tokenShieldNftAddress, erc6551RegistryAddress, vaultImplAddress);
createdVault = createVault(tokenShieldNftAddress, erc6551RegistryAddress, vaultImplAddress, recoveryManager);
vm.stopBroadcast();
}

function createVault(
address tokenShieldNftAddress,
address erc6551RegistryAddress,
address vaultImplAddress
address _tokenShieldNftAddress,
address _erc6551RegistryAddress,
address _vaultImplAddress,
address _recoveryManager
)
public
returns (address createdVault)
{
TokenShieldNft tokenShieldNft = TokenShieldNft(tokenShieldNftAddress);
TokenShieldNft tokenShieldNft = TokenShieldNft(_tokenShieldNftAddress);
bool isMintInitiated = tokenShieldNft.initiatedMint();

if (!isMintInitiated) {
tokenShieldNft.setRegistryAddress(erc6551RegistryAddress);
tokenShieldNft.setImplementationAddress(vaultImplAddress);
tokenShieldNft.setRegistryAddress(_erc6551RegistryAddress);
tokenShieldNft.setRecoveryManager(_recoveryManager);
tokenShieldNft.setImplementationAddress(_vaultImplAddress);
tokenShieldNft.toggleMint();
}
createdVault = _createVault(tokenShieldNft);
Expand Down
44 changes: 29 additions & 15 deletions script/DeployVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,67 @@
import { HelpersConfig } from "script/helpers/HelpersConfig.s.sol";
import { FileHelpers } from "script/helpers/FileHelpers.s.sol";
import { ERC6551Registry } from "@erc6551/ERC6551Registry.sol";
import { IABGuardian as Guardian } from "src/IABGuardian.sol";
import { TokenShieldGuardian as Guardian } from "src/TokenShieldGuardian.sol";
import { TokenShieldSubscription as TokenShieldNft } from "src/TokenShieldSubscription.sol";
import { Vault } from "src/Vault.sol";
import { RecoveryManager } from "src/RecoveryManager.sol";
import { MockAggregatorV3 } from "src/mock/MockPriceFeeds.sol";
import { ERC1967Proxy } from "openzeppelin-contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { MockAutomation } from "src/mock/MockAutomation.sol";

contract DeployVault is Script, HelpersConfig, FileHelpers {
address entryPoint = address(6);

Check warning on line 17 in script/DeployVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state
address constant SEPOLIA_AUTOMATION_REGISTRY = 0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad;

Check warning on line 18 in script/DeployVault.s.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

function run() external returns (address, address, address, address) {
function run() external returns (address, address, address, address, address) {
uint256 privateKey;
if (chainId == 11_155_111) {
privateKey = vm.envUint("SEPOLIA_PRIVATE_KEY");
} else {
privateKey = vm.envUint("PRIVATE_KEY");
}
vm.startBroadcast(privateKey);
(address registry, address guardian, address tokenShieldNft, address vaultImpl) = deploy();
(address registry, address guardian, address tokenShieldNft, address vaultImpl, address recoveryManager) =
deploy();
vm.stopBroadcast();
writeLatestFile(registry, guardian, tokenShieldNft, vaultImpl);
return (registry, guardian, tokenShieldNft, vaultImpl);
writeLatestFile(registry, guardian, tokenShieldNft, vaultImpl, recoveryManager);
return (registry, guardian, tokenShieldNft, vaultImpl, recoveryManager);
}

function deploy() public returns (address, address, address, address) {
function deploy() public returns (address, address, address, address, address) {
// Getting the appropriate config for the chain
ChainConfig memory config = getConfig();
address admin = config.contractAdmin;
address guardianSigner = config.guardianSigner;
address guardianSetter = config.guardianSetter;
address accountRecoveryManager = config.accountRecoveryManager;

ERC6551Registry registry;
if (chainId == 11_155_111) {
registry = ERC6551Registry(0x000000006551c19487814612e58FE06813775758);
config.automationRegistry = SEPOLIA_AUTOMATION_REGISTRY;
} else {
registry = new ERC6551Registry{salt:"655165516551"}();
registry = new ERC6551Registry{ salt: "655165516551" }();
MockAggregatorV3 mockPriceFeed = new MockAggregatorV3();
MockAutomation automationRegistry = new MockAutomation();
config.ethPriceFeed = address(mockPriceFeed);
config.automationRegistry = address(automationRegistry);
}
Guardian guardian = new Guardian{salt:"655165516551"}(admin,guardianSigner,guardianSetter);
Guardian guardian = new Guardian{ salt: "655165516551" }(admin, guardianSigner, guardianSetter);

TokenShieldNft tokenShieldNftImpl = new TokenShieldNft{salt:"655165516551"}();
ERC1967Proxy tokenShieldNftProxy = new ERC1967Proxy{salt:"655165516551"}(address(tokenShieldNftImpl),
abi.encodeWithSelector(tokenShieldNftImpl.initialize.selector,
"TokenShield","TSD", admin, accountRecoveryManager, config.ethPriceFeed));
Vault vaultImpl = new Vault{salt:"655165516551"}(address(guardian),address(entryPoint));
TokenShieldNft tokenShieldNftImpl = new TokenShieldNft{ salt: "655165516551" }();
ERC1967Proxy tokenShieldNftProxy = new ERC1967Proxy{ salt: "655165516551" }(
address(tokenShieldNftImpl),
abi.encodeWithSelector(
tokenShieldNftImpl.initialize.selector, "TokenShield", "TSD", admin, config.ethPriceFeed
)
);
Vault vaultImpl = new Vault{ salt: "655165516551" }(address(guardian), address(entryPoint));
TokenShieldNft tokenShieldNft = TokenShieldNft(address(tokenShieldNftProxy));
return (address(registry), address(guardian), address(tokenShieldNft), address(vaultImpl));
RecoveryManager recoveryManager = new RecoveryManager{ salt: "655165516551" }(
address(tokenShieldNftProxy), config.automationRegistry, address(guardian)
);
return (
address(registry), address(guardian), address(tokenShieldNft), address(vaultImpl), address(recoveryManager)
);
}
}
13 changes: 12 additions & 1 deletion script/helpers/FileHelpers.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import { Strings } from "openzeppelin-contracts/utils/Strings.sol";
contract FileHelpers is Script {
using Strings for string;

function writeLatestFile(address registry, address guardian, address tokenShieldNft, address vault) public {
function writeLatestFile(
address registry,
address guardian,
address tokenShieldNft,
address vault,
address recoveryManager
)
public
{
string memory root = vm.projectRoot();
string memory anvilFilePath = string.concat(root, "/deployments/anvilLatest");
string memory sepoliaFilePath = string.concat(root, "/deployments/sepoliaLatest");
Expand All @@ -16,19 +24,22 @@ contract FileHelpers is Script {
string memory guardianTxt = string.concat("guardian-", Strings.toHexString(guardian));
string memory tokenShieldNftTxt = string.concat("tokenShieldNft-", Strings.toHexString(tokenShieldNft));
string memory vaultTxt = string.concat("vault-", Strings.toHexString(vault));
string memory recoveryManagerTxt = string.concat("recoveryManager-", Strings.toHexString(recoveryManager));
if (block.chainid == 11_155_111) {
removeFileIfExists(sepoliaFilePath);
vm.writeLine(sepoliaFilePath, registryTxt);
vm.writeLine(sepoliaFilePath, guardianTxt);
vm.writeLine(sepoliaFilePath, tokenShieldNftTxt);
vm.writeLine(sepoliaFilePath, vaultTxt);
vm.writeLine(sepoliaFilePath, recoveryManagerTxt);
vm.closeFile(sepoliaFilePath);
} else {
removeFileIfExists(anvilFilePath);
vm.writeLine(anvilFilePath, registryTxt);
vm.writeLine(anvilFilePath, guardianTxt);
vm.writeLine(anvilFilePath, tokenShieldNftTxt);
vm.writeLine(anvilFilePath, vaultTxt);
vm.writeLine(anvilFilePath, recoveryManagerTxt);
vm.closeFile(anvilFilePath);
}

Expand Down
3 changes: 3 additions & 0 deletions script/helpers/HelpersConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract HelpersConfig is Script {
address guardianSetter;
address accountRecoveryManager;
address ethPriceFeed;
address automationRegistry;
string domainName;
string domainVersion;
}
Expand Down Expand Up @@ -54,6 +55,7 @@ contract HelpersConfig is Script {
guardianSetter: vm.addr(3),
accountRecoveryManager: vm.addr(4),
ethPriceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306,
automationRegistry: 0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad,
domainName: "TokenShield",
domainVersion: "1"
});
Expand All @@ -69,6 +71,7 @@ contract HelpersConfig is Script {
guardianSetter: guardSetter,
accountRecoveryManager: vm.addr(4),
ethPriceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306,
automationRegistry: 0x86EFBD0b6736Bed994962f9797049422A3A8E8Ad,
domainName: "TokenShield",
domainVersion: "1"
});
Expand Down
Loading
Loading