Skip to content

Commit

Permalink
working on deploying in json
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Sep 15, 2024
1 parent 4f3f81e commit 5d14e5f
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 145 deletions.
13 changes: 2 additions & 11 deletions deployments/ynETH-17000.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"chains": {
"17000": {
"chainId": 17000,
"erc20Address": "0xd9029669BC74878BCB5BE58c259ed0A277C5c16E",
"isL1": true,
"lzEID": 40217,
"lzEndpoint": "0x6EDCE65403992e310A62460808c4b910D972f10f",
"multiChainDeployer": "0x0000000000000000000000000000000000000000",
"oftAdapter": "0x396d502dE0Fc6839a2D9b27Ab69AFeC4ca1e95E8"
},
"2522": {
"chainId": 2522,
"erc20Address": "0x0000000000000000000000000000000000000000",
"erc20Address": "0xe6CA4c0c59Ff2024fe8eBFCDFd9557d4128415c1",
"isL1": false,
"lzEID": 40255,
"lzEndpoint": "0x6EDCE65403992e310A62460808c4b910D972f10f",
"multiChainDeployer": "0xCF2f2279021A4D622bAfc47Be295257b0808ED48",
"oftAdapter": "0x0000000000000000000000000000000000000000"
"oftAdapter": "0x72f396aa7FDA534da4BE59db13FD4Fed21DDa246"
}
},
"deployerAddress": "0x09D5Bd4a4f1dA1A965fE24EA54bce3d37661E056"
Expand Down
11 changes: 10 additions & 1 deletion script/BaseScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct BaseInput {
string erc20Symbol;
uint256 l1ChainId;
address l1ERC20Address;
address predictedL2AdapterAddress;
uint256[] l2ChainIds;
RateLimitConfig rateLimitConfig;
}
Expand Down Expand Up @@ -213,7 +214,7 @@ contract BaseScript is BaseData {
// Parse the L1Input struct
baseInput.l1ChainId = vm.parseJsonUint(json, ".l1ChainId");
baseInput.l1ERC20Address = vm.parseJsonAddress(json, ".l1ERC20Address");

baseInput.predictedL2AdapterAddress = vm.parseJsonAddress(json, ".predictedL2AdapterAddress");
// Parse the L2ChainIds array
baseInput.l2ChainIds = vm.parseJsonUintArray(json, ".l2ChainIds");

Expand All @@ -231,4 +232,12 @@ contract BaseScript is BaseData {
function addressToBytes32(address _addr) internal pure returns (bytes32) {
return bytes32(uint256(uint160(_addr)));
}

function isContract(address _addr) public view returns (bool _isContract) {
uint32 size;
assembly {
size := extcodesize(_addr)
}
return (size > 0);
}
}
16 changes: 16 additions & 0 deletions script/DeployL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract DeployL1OFTAdapter is BaseScript {
_loadInput(_jsonPath);

require(currentDeployment.isL1 == true, "Must be L1 deployment");
require(baseInput.predictedL2AdapterAddress != address(0), "input the l2adapter address");

RateLimiter.RateLimitConfig[] memory rateLimitConfigs = _getRateLimitConfigs();

Expand Down Expand Up @@ -73,6 +74,21 @@ contract DeployL1OFTAdapter is BaseScript {
)
);

for (uint256 i = 0; i < deployment.chains.length; i++) {
if (deployment.chains[i].chainId == block.chainid) {
continue;
}
uint32 eid = deployment.chains[i].lzEID;
address adapter = baseInput.predictedL2AdapterAddress;
bytes32 adapterBytes32 = addressToBytes32(adapter);
if (l1OFTAdapter.peers(eid) == adapterBytes32) {
console.log("Adapter already set for chain %d", deployment.chains[i].chainId);
continue;
}

l1OFTAdapter.setPeer(eid, adapterBytes32);
}

console.log("L1 OFT Adapter deployed at: %s", address(l1OFTAdapter));

vm.stopBroadcast();
Expand Down
48 changes: 24 additions & 24 deletions script/DeployL2OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ contract DeployL2OFTAdapter is BaseScript {

RateLimiter.RateLimitConfig[] memory rateLimitConfigs = _getRateLimitConfigs();

if (currentDeployment.oftAdapter != address(0)) {
console.log("L2 OFT Adapter already deployed at: %s", currentDeployment.oftAdapter);
l2OFTAdapter = L2YnOFTAdapterUpgradeable(currentDeployment.oftAdapter);
bool needsChange = false;

for (uint256 i = 0; i < rateLimitConfigs.length; i++) {
(,, uint256 limit, uint256 window) = l2OFTAdapter.rateLimits(rateLimitConfigs[i].dstEid);
RateLimiter.RateLimitConfig memory config = rateLimitConfigs[i];
if (config.limit != limit || config.window != window) {
needsChange = true;
break;
}
}
if (!needsChange) {
console.log("Rate limits are already set");
return;
}
vm.broadcast();
// sender needs LIMITER role
l2OFTAdapter.setRateLimits(rateLimitConfigs);

console.log("Rate limits updated");
return;
}
// if (currentDeployment.oftAdapter != address(0)) {
// console.log("L2 OFT Adapter already deployed at: %s", currentDeployment.oftAdapter);
// l2OFTAdapter = L2YnOFTAdapterUpgradeable(currentDeployment.oftAdapter);
// bool needsChange = false;

// for (uint256 i = 0; i < rateLimitConfigs.length; i++) {
// (,, uint256 limit, uint256 window) = l2OFTAdapter.rateLimits(rateLimitConfigs[i].dstEid);
// RateLimiter.RateLimitConfig memory config = rateLimitConfigs[i];
// if (config.limit != limit || config.window != window) {
// needsChange = true;
// break;
// }
// }
// if (!needsChange) {
// console.log("Rate limits are already set");
// return;
// }
// vm.broadcast();
// // sender needs LIMITER role
// l2OFTAdapter.setRateLimits(rateLimitConfigs);

// console.log("Rate limits updated");
// return;
// }

bytes32 proxySalt = createSalt(msg.sender, "L2YnERC20UpgradeableProxy");
bytes32 implementationSalt = createSalt(msg.sender, "L2YnERC20Upgradeable");
Expand Down
10 changes: 7 additions & 3 deletions script/DeployMultiChainDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ contract DeployMultiChainDeployer is BaseScript {
address predictedAddress =
vm.computeCreate2Address(salt, keccak256(type(ImmutableMultiChainDeployer).creationCode));
console.log("Predicted ImmutableMultiChainDeployer address: ", predictedAddress);

console.log("CURRENT DEPLOYMENT: ", currentDeployment.multiChainDeployer);
if (currentDeployment.multiChainDeployer != address(0)) {
require(currentDeployment.multiChainDeployer == predictedAddress, "Already deployed");
console.log("ImmutableMultiChainDeployer already deployed at: ", currentDeployment.multiChainDeployer);
return;
}

vm.broadcast();
multiChainDeployerAddress = address(new ImmutableMultiChainDeployer{salt: salt}());
if (!isContract(predictedAddress)) {
vm.broadcast();
multiChainDeployerAddress = address(new ImmutableMultiChainDeployer{salt: salt}());
} else {
multiChainDeployerAddress = predictedAddress;
}

console.log("ImmutableMultiChainDeployer deployed at: ", multiChainDeployerAddress);
require(multiChainDeployerAddress == predictedAddress, "Deployment failed");
Expand Down
37 changes: 37 additions & 0 deletions script/SetPeersOFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,41 @@ contract SetPeersOFTAdapter is BaseScript {

_saveDeployment();
}

function getPeerData(
string calldata _jsonPath
)
public
returns (uint256[] memory _chains, uint32[] memory _eids, bytes32[] memory _adapterBytes32)
{
_loadInput(_jsonPath);

if (currentDeployment.oftAdapter == address(0)) {
console.log("OFT Adapter not deployed yet");
} else {
oftAdapter = OFTAdapterUpgradeable(currentDeployment.oftAdapter);

_chains = new uint256[](deployment.chains.length);
_eids = new uint32[](deployment.chains.length);
_adapterBytes32 = new bytes32[](deployment.chains.length);

for (uint256 i = 0; i < deployment.chains.length; i++) {
if (deployment.chains[i].chainId == block.chainid) {
continue;
}

_chains[i] = deployment.chains[i].chainId;
_eids[i] = deployment.chains[i].lzEID;

address adapter = deployment.chains[i].oftAdapter;
_adapterBytes32[i] = addressToBytes32(adapter);

bytes32 adapterBytes32 = addressToBytes32(adapter);
if (oftAdapter.peers(_eids[i]) == adapterBytes32) {
console.log("Adapter already set for chain %d", deployment.chains[i].chainId);
continue;
}
}
}
}
}
5 changes: 4 additions & 1 deletion script/inputs/holesky-ynETH.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
"erc20Name": "ynETH",
"erc20Symbol": "ynETH",
"l1ChainId": 17000,
"l2ChainIds": [2522],
"l2ChainIds": [
2522
],
"l1ERC20Address": "0xd9029669BC74878BCB5BE58c259ed0A277C5c16E",
"predictedL2AdapterAddress": "0x72f396aa7FDA534da4BE59db13FD4Fed21DDa246",
"rateLimitConfig": {
"limit": "100000000000000000000",
"window": "86400"
Expand Down
8 changes: 6 additions & 2 deletions script/inputs/mainnet-ynETH.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"erc20Name": "ynETH",
"erc20Symbol": "ynETH",
"l1ChainId": 1,
"l2ChainIds": [10, 8453],
"l2ChainIds": [
10,
8453
],
"l1ERC20Address": "0x09db87A538BD693E9d08544577d5cCfAA6373A48",
"predictedL2AdapterAddress": "0x0000000000000000000000000000000000000000",
"rateLimitConfig": {
"limit": "100000000000000000000",
"window": "86400"
}
}
}
Loading

0 comments on commit 5d14e5f

Please sign in to comment.