Commit 41d06234 authored by Tarun Khasnavis's avatar Tarun Khasnavis

Create deployment scripts for auth modules

parent 78e0b0eb
{
"faucetAdmin": "0xf2C22a95bBA6F35545269183D8d1751a27F047F6",
"faucetAdmin": "0x8F0EBDaA1cF7106bE861753B0f9F5c0250fE0819",
"faucetDrippieOwner": "0xEa193Fd9565284E7534dDDA15b07B119e7792644",
"faucetDripV1Value": 20000000000000000000,
"faucetDripV1Interval": 3600,
......@@ -14,5 +14,11 @@
"faucetGelatoRecipient": "0x789e58a4B08A23a7f60141959C6ABbdC0D0C4Aba",
"faucetGelatoBalanceV1DripInterval": 86400,
"faucetGelatoBalanceV1Value": 1000000000000000000,
"faucetGelatoThreshold": 100000000000000000
"faucetGelatoThreshold": 100000000000000000,
"faucetOnchainAuthModuleAdmin": "0x8F0EBDaA1cF7106bE861753B0f9F5c0250fE0819",
"faucetOnchainAuthModuleAdminDripInterval": 86400,
"faucetOnchainAuthModuleAdminDripValue": 1000000000000000000,
"faucetOffchainAuthModuleAdmin": "0x8F0EBDaA1cF7106bE861753B0f9F5c0250fE0819",
"faucetOffchainAuthModuleAdminDripInterval": 86400,
"faucetOffchainAuthModuleAdminDripValue": 50000000000000000
}
......@@ -15,6 +15,7 @@ import { CheckGelatoLow } from "src/periphery/drippie/dripchecks/CheckGelatoLow.
import { CheckBalanceHigh } from "src/periphery/drippie/dripchecks/CheckBalanceHigh.sol";
import { CheckBalanceLow } from "src/periphery/drippie/dripchecks/CheckBalanceLow.sol";
import { CheckTrue } from "src/periphery/drippie/dripchecks/CheckTrue.sol";
import { AdminFaucetAuthModule } from "src/periphery/faucet/authmodules/AdminFaucetAuthModule.sol";
/// @title DeployPeriphery
/// @notice Script used to deploy periphery contracts.
......@@ -45,6 +46,7 @@ contract DeployPeriphery is Deployer {
deployImplementations();
initializeFaucet();
installFaucetAuthModulesConfigs();
}
/// @notice Deploy all of the proxies
......@@ -62,6 +64,8 @@ contract DeployPeriphery is Deployer {
deployCheckBalanceLow();
deployCheckBalanceHigh();
deployCheckGelatoLow();
deployOnChainAuthModule();
deployOffChainAuthModule();
}
/// @notice Modifier that wraps a function in broadcasting.
......@@ -403,4 +407,100 @@ contract DeployPeriphery is Deployer {
require(drippie.getDripStatus(dripName) == Drippie.DripStatus.ACTIVE);
}
}
/// @notice deploys the On-Chain Authentication Module
function deployOnChainAuthModule() public broadcast returns (address addr_) {
string memory moduleName = "OnChainAuthModule";
string memory version = "1";
bytes32 salt = keccak256(bytes("OnChainAuthModule"));
bytes32 initCodeHash = keccak256(abi.encodePacked(type(AdminFaucetAuthModule).creationCode, abi.encode(cfg.faucetOnchainAuthModuleAdmin(), moduleName, version)));
address preComputedAddress = computeCreate2Address(salt, initCodeHash);
if (preComputedAddress.code.length > 0) {
console.logBytes32(initCodeHash);
console.log("OnChainAuthModule already deployed at %s", preComputedAddress);
save("OnChainAuthModule", preComputedAddress);
addr_ = preComputedAddress;
} else {
AdminFaucetAuthModule onChainAuthModule = new AdminFaucetAuthModule{ salt: salt }(cfg.faucetOnchainAuthModuleAdmin(), moduleName, version);
require(onChainAuthModule.ADMIN() == cfg.faucetOnchainAuthModuleAdmin());
save("OnChainAuthModule", address(onChainAuthModule));
console.log("OnChainAuthModule deployed at %s", address(onChainAuthModule));
addr_ = address(onChainAuthModule);
}
}
/// @notice deploys the Off-Chain Authentication Module
function deployOffChainAuthModule() public broadcast returns (address addr_) {
string memory moduleName = "OffChainAuthModule";
string memory version = "1";
bytes32 salt = keccak256(bytes("OffChainAuthModule"));
bytes32 initCodeHash = keccak256(abi.encodePacked(type(AdminFaucetAuthModule).creationCode, abi.encode(cfg.faucetOffchainAuthModuleAdmin(), moduleName, version)));
address preComputedAddress = computeCreate2Address(salt, initCodeHash);
if (preComputedAddress.code.length > 0) {
console.logBytes32(initCodeHash);
console.log("OffChainAuthModule already deployed at %s", preComputedAddress);
save("OffChainAuthModule", preComputedAddress);
addr_ = preComputedAddress;
} else {
AdminFaucetAuthModule offChainAuthModule = new AdminFaucetAuthModule{ salt: salt }(cfg.faucetOffchainAuthModuleAdmin(), moduleName, version);
require(offChainAuthModule.ADMIN() == cfg.faucetOffchainAuthModuleAdmin());
save("OffChainAuthModule", address(offChainAuthModule));
console.log("OffChainAuthModule deployed at %s", address(offChainAuthModule));
addr_ = address(offChainAuthModule);
}
}
/// @notice installs the OnChain AuthModule on the Faucet contract.
function installOnChainAuthModule() public broadcast {
string memory moduleName = "OnChainAuthModule";
Faucet faucet = Faucet(mustGetAddress("Faucet"));
AdminFaucetAuthModule onChainAuthModule = AdminFaucetAuthModule(mustGetAddress(moduleName));
if (faucet.getModuleStatus(onChainAuthModule)) {
console.log("%s already installed.", moduleName);
} else {
console.log("Installing %s", moduleName);
Faucet.ModuleConfig memory myModuleConfig = Faucet.ModuleConfig({
name: moduleName,
enabled: true,
ttl: cfg.faucetOnchainAuthModuleAdminDripInterval(),
amount: cfg.faucetOnchainAuthModuleAdminDripValue()
});
faucet.configure(onChainAuthModule, myModuleConfig);
console.log("%s installed successfully", moduleName);
}
}
/// @notice installs the OffChain AuthModule on the Faucet contract.
function installOffChainAuthModule() public broadcast {
string memory moduleName = "OffChainAuthModule";
Faucet faucet = Faucet(mustGetAddress("Faucet"));
AdminFaucetAuthModule offChainAuthModule = AdminFaucetAuthModule(mustGetAddress(moduleName));
if (faucet.getModuleStatus(offChainAuthModule)) {
console.log("%s already installed.", moduleName);
} else {
console.log("Installing %s", moduleName);
Faucet.ModuleConfig memory myModuleConfig = Faucet.ModuleConfig({
name: moduleName,
enabled: true,
ttl: cfg.faucetOffchainAuthModuleAdminDripInterval(),
amount: cfg.faucetOffchainAuthModuleAdminDripValue()
});
faucet.configure(offChainAuthModule, myModuleConfig);
console.log("%s installed successfully", moduleName);
}
}
/// @notice installs all of the auth module in the faucet contract.
function installFaucetAuthModulesConfigs() public {
Faucet faucet = Faucet(mustGetAddress("Faucet"));
console.log("Installing auth modules at %s", address(faucet));
installOnChainAuthModule();
installOffChainAuthModule();
console.log("Faucet Auth Module configs successfully installed");
}
}
......@@ -28,6 +28,12 @@ contract PeripheryDeployConfig is Script {
uint256 public faucetGelatoBalanceV1DripInterval;
uint256 public faucetGelatoBalanceV1Value;
uint256 public faucetGelatoThreshold;
address public faucetOnchainAuthModuleAdmin;
uint256 public faucetOnchainAuthModuleAdminDripInterval;
uint256 public faucetOnchainAuthModuleAdminDripValue;
address public faucetOffchainAuthModuleAdmin;
uint256 public faucetOffchainAuthModuleAdminDripInterval;
uint256 public faucetOffchainAuthModuleAdminDripValue;
constructor(string memory _path) {
console.log("PeripheryDeployConfig: reading file %s", _path);
......@@ -54,5 +60,11 @@ contract PeripheryDeployConfig is Script {
faucetGelatoBalanceV1DripInterval = stdJson.readUint(_json, "$.faucetGelatoBalanceV1DripInterval");
faucetGelatoBalanceV1Value = stdJson.readUint(_json, "$.faucetGelatoBalanceV1Value");
faucetGelatoThreshold = stdJson.readUint(_json, "$.faucetGelatoThreshold");
faucetOnchainAuthModuleAdmin = stdJson.readAddress(_json, "$.faucetOnchainAuthModuleAdmin");
faucetOnchainAuthModuleAdminDripInterval = stdJson.readUint(_json, "$.faucetOnchainAuthModuleAdminDripInterval");
faucetOnchainAuthModuleAdminDripValue = stdJson.readUint(_json, "$.faucetOnchainAuthModuleAdminDripValue");
faucetOffchainAuthModuleAdmin = stdJson.readAddress(_json, "$.faucetOffchainAuthModuleAdmin");
faucetOffchainAuthModuleAdminDripInterval = stdJson.readUint(_json, "$.faucetOffchainAuthModuleAdminDripInterval");
faucetOffchainAuthModuleAdminDripValue = stdJson.readUint(_json, "$.faucetOffchainAuthModuleAdminDripValue");
}
}
......@@ -124,4 +124,11 @@ contract Faucet {
emit Drip(config.name, _auth.id, config.amount, _params.recipient);
}
/// @notice Returns the enable status of a given auth module.
/// @param _module module to check.
/// @return bool enabled status of auth modulew.
function getModuleStatus(IFaucetAuthModule _module) public view returns (bool) {
return modules[_module].enabled;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment