Skip to content

Commit

Permalink
feat: add mainnet factory and make deployment script use the right lo…
Browse files Browse the repository at this point in the history
…gic on the right chains.
  • Loading branch information
Tritium-VLK committed Dec 17, 2024
1 parent f1b4146 commit 0aad7fc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
56 changes: 56 additions & 0 deletions contracts/MainInjectorFactoryV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.21;

import "./MainChainGaugeInjectorV2.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";

/**
* @title ChildChainGaugeInjectorV2Factory
* @dev Factory contract to deploy instances of ChildChainGaugeInjectorV2 using a proxy pattern for low deployment cost
*/
contract MainChainGaugeInjectorV2Factory {
event InjectorCreated(
address indexed injector, address[] keeperAddresses, address injectTokenAddress, address owner
);

address public immutable implementation;

address[] private deployedInjectors;

constructor(address logic) {
implementation = logic;
}

/**
* @dev Deploys a new instance of ChildChainGaugeInjectorV2 using Clones.sol
* @param keeperAddresses The array of addresses of the keeper contracts
* @param minWaitPeriodSeconds The minimum wait period for address between funding (for security)
* @param injectTokenAddress The ERC20 token this contract should manage
* @param maxInjectionAmount The max amount of tokens that should be injected to a single gauge in a single week by this injector.
* @param owner The owner of the ChildChainGaugeInjectorV2 instance
* @return The address of the newly deployed ChildChainGaugeInjectorV2 instance
*/
function createInjector(
address[] memory keeperAddresses,
uint256 minWaitPeriodSeconds,
address injectTokenAddress,
uint256 maxInjectionAmount,
address owner
) external returns (address) {
address injector = Clones.clone(implementation);
MainChainGaugeInjectorV2(injector).initialize(
owner, keeperAddresses, minWaitPeriodSeconds, injectTokenAddress, maxInjectionAmount
);
emit InjectorCreated(injector, keeperAddresses, injectTokenAddress, owner);
deployedInjectors.push(injector);
return injector;
}

/**
* @dev Returns the array of addresses of deployed injectors, note that not all injectors on the list may be active or functional
* @return The array of addresses of deployed injectors
*/
function getDeployedInjectors() external view returns (address[] memory) {
return deployedInjectors;
}
}
21 changes: 14 additions & 7 deletions foundry_scripts/InjectorInfraDeployment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@ pragma solidity ^0.8.25;

import {Script} from "forge-std/Script.sol";

import {MainChainGaugeInjectorV2} from "../contracts/MainChainGaugeInjectorV2.sol";
import {ChildChainGaugeInjectorV2} from "../contracts/ChildChainGaugeInjectorV2.sol";
import {ChildChainGaugeInjectorV2Factory} from "../contracts/injectorFactoryV2.sol";
import {MainChainGaugeInjectorV2} from "../contracts/MainChainGaugeInjectorV2.sol";
import {MainChainGaugeInjectorV2Factory} from "../contracts/MainInjectorFactoryV2.sol";

/// @notice Deploys the v2 infrastructure for the injectors in the following order:
/// 1. {ChildChainGaugeInjectorV2} -> singleton/implementation purposes (helps verifying in etherscan etc)
/// 2. {ChildChainGaugeInjectorV2Factory}
contract InjectorInfraDeployment is Script {
// injector infrastructure
ChildChainGaugeInjectorV2 injectorImpl;
MainChainGaugeInjectorV2 mainInjectorImpl;
ChildChainGaugeInjectorV2 childInjectorImpl;
ChildChainGaugeInjectorV2Factory injectorFactory;

MainChainGaugeInjectorV2Factory mainInjectorFactory;
function run() public {
// read pk from `.env`
uint256 pk = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(pk);

// 1. {ChildChainGaugeInjectorV2}
injectorImpl = new ChildChainGaugeInjectorV2();

// 2. {ChildChainGaugeInjectorV2Factory}
injectorFactory = new ChildChainGaugeInjectorV2Factory(address(injectorImpl));
// 1. {InjectorV2}
if (block.chainid == 1){
MainChainGaugeInjectorV2 injectorImpl = new MainChainGaugeInjectorV2();
MainChainGaugeInjectorV2Factory injectorFactory = new MainChainGaugeInjectorV2Factory(address(injectorImpl));
} else {
ChildChainGaugeInjectorV2 injectorImpl = new ChildChainGaugeInjectorV2();
ChildChainGaugeInjectorV2Factory injectorFactory = new ChildChainGaugeInjectorV2Factory(address(injectorImpl));
}
}
}
6 changes: 5 additions & 1 deletion foundry_scripts/InjectorInfraMultiChainDeployment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.25;
import {Script} from "forge-std/Script.sol";

import {ChildChainGaugeInjectorV2} from "../contracts/ChildChainGaugeInjectorV2.sol";
import {MainChainGaugeInjectorV2} from "../contracts/MainChainGaugeInjectorV2.sol";
import {ChildChainGaugeInjectorV2Factory} from "../contracts/injectorFactoryV2.sol";

/// @notice Deploys the v2 infrastructure for the injectors in all chains in `foundry.toml` in the following order:
Expand Down Expand Up @@ -86,8 +87,11 @@ contract InjectorInfraMultiChainDeployment is Script {
/// @param _pk private key to broadcast transaction
function _infraDeployment(uint256 _pk) internal broadcast(_pk) {
// 1. {ChildChainGaugeInjectorV2}
if (chain.id == 1) {
injectorImpl = new MainChainGaugeInjectorV2();
} else {
injectorImpl = new ChildChainGaugeInjectorV2();

}
// 2. {ChildChainGaugeInjectorV2Factory}
injectorFactory = new ChildChainGaugeInjectorV2Factory(address(injectorImpl));
}
Expand Down

0 comments on commit 0aad7fc

Please sign in to comment.