Skip to content

Commit

Permalink
added script for l2 adapter deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Sep 7, 2024
1 parent de64bce commit 43bf272
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
37 changes: 34 additions & 3 deletions script/BaseScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ struct L2YnOFTAdapterInput {
address adapterImplementation;
uint256 chainId;
address erc20Address;
bytes32 implementationSalt;
address proxyController;
bytes32 proxySalt;
RateLimitConfig[] rateLimitConfigs;
}

Expand Down Expand Up @@ -39,6 +42,9 @@ contract BaseScript is BaseData {
// TODO: setup saving of deployment data in deployments json file
uint256 _chainId;
bytes public data;
string public json;
address public immutableDeployer;
address public adapterImplementation;
L2YnOFTAdapterInput public _ynOFTAdapterInputs;
L1YnOFTAdapterInput public _ynOFTImplementationInputs;
YnERC20Input public _ynERC20Inputs;
Expand All @@ -54,6 +60,7 @@ contract BaseScript is BaseData {
_loadJson(_inputPath);
_loadYnOFTAdapterInputs();
_verifyChain();
_loadDeployerForChain(block.chainid);
_getRateLimiterConfigs();
}

Expand All @@ -70,9 +77,29 @@ contract BaseScript is BaseData {
_chainId = _ynOFTImplementationInputs.chainId;
}

function _loadDeployerForChain(uint256 chainId) internal {
string memory path = string(
abi.encodePacked(
vm.projectRoot(), "/deployments/ImmutableMultiChainDeployer-", vm.toString(chainId), ".json"
)
);
string memory _json = vm.readFile(path);
immutableDeployer = vm.parseJsonAddress(_json, ".ImmutableMultiChainDeployerAddress");
require(immutableDeployer != address(0), "invalid deployer");
}

function _loadAdapterImplementationForChain(uint32 chainId) internal {
string memory path = string(
abi.encodePacked(vm.projectRoot(), "/deployments/MainnetImplementations-", vm.toString(chainId), ".json")
);
string memory _json = vm.readFile(path);
adapterImplementation = vm.parseJsonAddress(_json, ".OFTAdapterImplementation");
require(adapterImplementation != address(0), "invalid adapter Implementation");
}

function _loadJson(string memory _path) internal {
string memory path = string(abi.encodePacked(vm.projectRoot(), "/", _path));
string memory json = vm.readFile(path);
json = vm.readFile(path);
data = vm.parseJson(json);
}

Expand Down Expand Up @@ -120,8 +147,12 @@ contract BaseScript is BaseData {
return string.concat(root, "/deployments/", _deploymentType, "-", vm.toString(block.chainid), ".json");
}

function _writeOutput(string memory deploymentType, string memory json) internal {
function _writeOutput(string memory deploymentType, string memory _json) internal {
string memory path = _getOutputPath(deploymentType);
vm.writeFile(path, json);
vm.writeFile(path, _json);
}

function createSalt(address deployerAddress, string memory label) public pure returns (bytes32 _salt) {
_salt = bytes32(abi.encodePacked(bytes20(deployerAddress), bytes12(bytes32(keccak256(abi.encode(label))))));
}
}
9 changes: 6 additions & 3 deletions script/DeployMainnetImplementations.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ contract DeployMainnetImplementations is BaseScript {
function run(string memory __path) public {
_loadOFTImplementationData(__path);

_loadDeployerForChain(block.chainid);

vm.broadcast();

mainnetOFTAdapterImpl =
address(new L1YnOFTAdapterUpgradeable(_ynOFTAdapterInputs.erc20Address, addresses[_chainId].lzEndpoint));
mainnetOFTAdapterImpl = address(
new L1YnOFTAdapterUpgradeable(_ynOFTImplementationInputs.erc20Address, addresses[_chainId].lzEndpoint)
);
mainnetOFTAdapter =
L1YnOFTAdapterUpgradeable(address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, msg.sender, "")));

Expand All @@ -28,7 +31,7 @@ contract DeployMainnetImplementations is BaseScript {
}

function _serializeOutputs(string memory objectKey) internal override {
vm.serializeAddress(objectKey, "erc20", _ynOFTAdapterInputs.erc20Address);
vm.serializeAddress(objectKey, "erc20", _ynOFTImplementationInputs.erc20Address);
vm.serializeString(objectKey, "chainid", vm.toString(block.chainid));
vm.serializeAddress(objectKey, "OFTAdapterImplementation", address(mainnetOFTAdapterImpl));
string memory finalJson = vm.serializeAddress(objectKey, "OFTAdapter", address(mainnetOFTAdapter));
Expand Down
12 changes: 6 additions & 6 deletions script/inputs/L2OFTAdapterInput.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"chainId": 17000,
"erc20Address": "0x0000000000000000000000000000000000000000",
"adapterImplementation": "0x0000000000000000000000000000000000000000",
"erc20Address": "0xd9029669BC74878BCB5BE58c259ed0A277C5c16E",
"adapterImplementation": "0x1D5B39612a354C2Ff1f50cfd8D9FDEdB4d4F9e62",
"implementationSalt": "0x000000000000000000000000000000000000000093329e122e1b1b30629b7a7b",
"proxyController": "0x941E92c9Eff78a2b7217057752cf938040a59aE9",
"proxySalt": "0x000000000000000000000000000000000000000093329e122e1b1b30629f7a7b",
"rateLimiterConfigs": [
{
"limit": "100000000000000000000",
"window": "86400"
}
],
"TOKEN_ADMIN": "0x0000000000000000000000000000000000000000",
"PROXY_ADMIN": "0x0000000000000000000000000000000000000000",
"OFT_DELEGATE": "0x0000000000000000000000000000000000000000"
]
}
2 changes: 2 additions & 0 deletions src/factory/ImmutableMultiChainDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/Ra
import {IImmutableMultiChainDeployer} from "@interfaces/IImmutableMultiChainDeployer.sol";
import {L2YnOFTAdapterUpgradeable} from "@/L2YnOFTAdapterUpgradeable.sol";
import {L2YnERC20Upgradeable} from "@/L2YnERC20Upgradeable.sol";
import "forge-std/console.sol";

contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
/// @notice Emitted when a new contract is deployed
Expand Down Expand Up @@ -67,6 +68,7 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
address _proxyController,
bytes memory _l2YnOFTAdapterBytecode
) public override returns (address deployedContract) {
console.log(msg.sender);
bytes memory _constructorParams = abi.encode(_token, _lzEndpoint);
bytes memory _contractCode = abi.encodePacked(_l2YnOFTAdapterBytecode, _constructorParams);
bytes memory _initializeArgs =
Expand Down

0 comments on commit 43bf272

Please sign in to comment.