Skip to content

Commit

Permalink
merged feat/deployment into scripts. data loading from json.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Sep 6, 2024
1 parent 40ae302 commit 0a2c882
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 27 deletions.
6 changes: 3 additions & 3 deletions script/BaseData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ contract BaseData is Script {
Actors({OFT_DELEGATE: address(0), TOKEN_ADMIN: address(0), PROXY_ADMIN: address(0)});
}

function getActors(uint256 chainId) external view returns (Actors memory) {
function getActors(uint256 chainId) public view returns (Actors memory) {
return actors[chainId];
}

function getChainAddresses(uint256 chainId) external view returns (ChainAddresses memory) {
function getChainAddresses(uint256 chainId) public view returns (ChainAddresses memory) {
return addresses[chainId];
}

function isSupportedChainId(uint256 chainId) external view returns (bool) {
function isSupportedChainId(uint256 chainId) public view returns (bool) {
return chainId == chainIds.mainnet || chainId == chainIds.base || chainId == chainIds.fraxtal
|| chainId == chainIds.optimism || chainId == chainIds.arbitrum || chainId == chainIds.holeksy
|| chainId == chainIds.fraxtalTestnet;
Expand Down
52 changes: 44 additions & 8 deletions script/BaseScript.s.sol
Original file line number Diff line number Diff line change
@@ -1,51 +1,87 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {BaseData} from "./BaseData.sol";
import {ImmutableMultiChainDeployer} from "@factory/ImmutableMultiChainDeployer.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {EndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/EndpointV2.sol";

struct YnOFTAdapterInput {
address erc20Address;
address lzEndpoint;
address adapterImplementation;
RateLimiterConfig[] rateLimitConfigs;
uint256 chainId;
address erc20Address;
RateLimitConfig[] rateLimitConfigs;
}

struct RateLimitConfig {
uint32 dstEid;
uint256 limit;
uint256 window;
}

struct YnERC20Input {
uint256 chainId;
address erc20Address;
string name;
string symbol;
}
//forge script script/DeployMainnetImplementations.s.sol:DeployMainnetImplementations --rpc-url ${rpc} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify

contract BaseScript is Script {
contract BaseScript is BaseData {
// TODO: parse token address from json or as input from user
// TODO: setup forks based on if testnet or mainnet deployment as per json
// TODO: setup saving of deployment data in deployments json file
uint256 _chainId;
bytes public data;
YnOFTAdapterInput public _ynOFTAdapterInputs;
YnERC20Input public _ynERC20Inputs;
RateLimiter.RateLimitConfig[] public _rateLimitConfigs;

function _loadERC20(string memory _inputPath) internal {
_loadJson(_inputPath);
_loadYnERC20Inputs();
isSupportedChainId(_chainId);
}

function _loadOFTAdapter(string memory _inputPath) internal {
_loadJson(_inputPath);
_loadYnOFTAdapterInputs();
_getRateLimiterConfigs();
isSupportedChainId(_chainId);
}

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

function _loadYnOFTAdapterInputs() internal {
YnOFTAdapterInput memory _inputs = abi.decode(data, (YnOFTAdapterInput));
YnOFTAdapterInput memory ynOFTAdapterInputs = abi.decode(data, (YnOFTAdapterInput));
_chainId = _ynOFTAdapterInputs.chainId;
this.loadAdapterInputs(ynOFTAdapterInputs);
}

function loadAdapterInputs(YnOFTAdapterInput calldata _ynInput) external {
_ynOFTAdapterInputs = _ynInput;
}

function _loadYnERC20Inputs() internal {
_ynERC20Inputs = abi.decode(data, (YnERC20Input));
_chainId = _ynERC20Inputs.chainId;
}

function _getRateLimiterConfigs() internal {
RateLimiter.RateLimitConfig memory _tempConfig;
uint32 tempDstEid = EndpointV2(_ynOFTAdapterInputs.lzEndpoint).eid();
uint32 tempDstEid = EndpointV2(addresses[_chainId].lzEndpoint).eid();
for (uint256 i; i < _ynOFTAdapterInputs.rateLimitConfigs.length; i++) {
_tempConfig.dstEid = tempDstEid;
_tempConfig.limit = _ynOFTAdapterInputs.rateLimitConfigs[i].limit;
_tempConfig.window = _ynOFTAdapterInputs.rateLimitConfigs[i].window;
_rateLimitConfigs.push(_tempConfig);
}
}

function _serializeOutputs(string memory objectKey) internal virtual {
// left blank on purpose
}
}
9 changes: 4 additions & 5 deletions script/DeployImmutableMultiChainDeployer.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {BaseScript} from "./BaseScript.s.sol";
import {ImmutableMultiChainDeployer} from "@factory/ImmutableMultiChainDeployer.sol";
import "forge-std/console.sol";
//forge script script/DeployImmutableMultiChainDeployer.s.sol:DeployImmutableMultiChainDeployer --rpc-url ${rpc} --sig "run(string memory)" ${path} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify

contract DeployImmutableMultiChainDeployer is Script {
contract DeployImmutableMultiChainDeployer is BaseScript {
address public multiChainDeployerAddress;

function setUp() public {}

function run(string memory _salt) public {
function run(bytes32 _salt) public {
vm.broadcast();
multiChainDeployerAddress = address(new ImmutableMultiChainDeployer{salt: _salt}());

Expand Down
19 changes: 11 additions & 8 deletions script/DeployMainnetImplementations.s.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {BaseScript} from "./BaseScript.s.sol";
import {ImmutableMultiChainDeployer} from "@factory/ImmutableMultiChainDeployer.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {L1YnOFTAdapterUpgradeable} from "@/L1YnOFTAdapterUpgradeable.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

//forge script script/DeployMainnetImplementations.s.sol:DeployMainnetImplementations --rpc-url ${rpc} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify
contract DeployMainnetImplementations is Script {
RateLimiter.RateLimitConfig[] public _rateLimitConfigs;

function setUp() public {}
contract DeployMainnetImplementations is BaseScript {
address public mainnetOFTAdapterImpl;
L1YnOFTAdapterUpgradeable public mainnetOFTAdapter;

function run(string memory __path) public {
loadOFTAdapter(__path);

vm.broadcast();

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

mainnetOFTAdapter.initialize(msg.sender, _rateLimitConfigs);
}
}
4 changes: 3 additions & 1 deletion script/inputs/L2ERC20DeploymentInput.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"chainId": 1,
"erc20Address": "0x0000000000000000000000000000000000000000",
"lzEndpoint": "0x0000000000000000000000000000000000000000"
"lzEndpoint": "0x0000000000000000000000000000000000000000",
"name": "name",
"symbol": "symbol"
}
6 changes: 4 additions & 2 deletions script/inputs/L2OFTAdapterInput.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"chainId": 1,
"erc20Address": "0x0000000000000000000000000000000000000000",
"lzEndpoint": "0x0000000000000000000000000000000000000000",
"adapterImplementation": "0x0000000000000000000000000000000000000000",
"rateLimiterConfigs": [
{
"limit": "100000000000000000000",
"window": "86400"
}
]
],
"TOKEN_ADMIN": "0x0000000000000000000000000000000000000000",
"PROXY_ADMIN": "0x0000000000000000000000000000000000000000",
"OFT_DELEGATE": "0x0000000000000000000000000000000000000000"
}

0 comments on commit 0a2c882

Please sign in to comment.