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

feat: add mainnet factory and fix Forge deployment script #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
56 changes: 56 additions & 0 deletions contracts/MainChainInjectorFactoryV2.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;
}
}
20 changes: 13 additions & 7 deletions foundry_scripts/InjectorInfraDeployment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ 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";
import {MainChainGaugeInjectorV2Factory} from "../contracts/MainChainInjectorFactoryV2.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
Loading