Skip to content

Commit

Permalink
fixed scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Sep 16, 2024
1 parent 1f7a185 commit 105160f
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 213 deletions.
32 changes: 0 additions & 32 deletions deployments/ynETH-17000.json

This file was deleted.

63 changes: 48 additions & 15 deletions script/BaseData.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract BaseData is Script {
uint256 fraxtalTestnet;
}

mapping(bool => Addresses) private __addresses; // isTestnet => Actors
mapping(uint256 => Addresses) private __chainIdToAddresses;

mapping(uint256 => uint32) private __chainIdToLzEID;

Expand All @@ -43,18 +43,54 @@ contract BaseData is Script {
// at https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts

// mainnets
__addresses[true] = Addresses({
OFT_DELEGATE: 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975, // yn security council
TOKEN_ADMIN: 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975,
PROXY_ADMIN: 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975,
__chainIdToAddresses[__chainIds.mainnet] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-mainnet"),
TOKEN_ADMIN: makeAddr("gnosis-safe-mainnet"),
PROXY_ADMIN: makeAddr("proxy-controller-mainnet"),
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c
});
__chainIdToAddresses[__chainIds.base] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-base"),
TOKEN_ADMIN: makeAddr("gnosis-safe-base"),
PROXY_ADMIN: makeAddr("proxy-controller-base"),
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c
});
__chainIdToAddresses[__chainIds.optimism] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-optimism"),
TOKEN_ADMIN: makeAddr("gnosis-safe-optimism"),
PROXY_ADMIN: makeAddr("proxy-controller-optimism"),
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c
});
__chainIdToAddresses[__chainIds.arbitrum] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-arbitrum"),
TOKEN_ADMIN: makeAddr("gnosis-safe-arbitrum"),
PROXY_ADMIN: makeAddr("proxy-controller-arbitrum"),
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c
});
__chainIdToAddresses[__chainIds.fraxtal] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-fraxtal"),
TOKEN_ADMIN: makeAddr("gnosis-safe-fraxtal"),
PROXY_ADMIN: makeAddr("proxy-controller-fraxtal"),
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c
});

// testnets
__addresses[false] = Addresses({
OFT_DELEGATE: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913, // yn security council
TOKEN_ADMIN: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913,
PROXY_ADMIN: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913,
__chainIdToAddresses[__chainIds.holesky] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-holesky"),
TOKEN_ADMIN: makeAddr("gnosis-safe-holesky"),
PROXY_ADMIN: makeAddr("proxy-controller-holesky"),
LZ_ENDPOINT: 0x6EDCE65403992e310A62460808c4b910D972f10f
});
__chainIdToAddresses[__chainIds.sepolia] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-sepolia"),
TOKEN_ADMIN: makeAddr("gnosis-safe-sepolia"),
PROXY_ADMIN: makeAddr("proxy-controller-sepolia"),
LZ_ENDPOINT: 0x6EDCE65403992e310A62460808c4b910D972f10f
});
__chainIdToAddresses[__chainIds.fraxtalTestnet] = Addresses({
OFT_DELEGATE: makeAddr("gnosis-safe-fraxtal-testnet"),
TOKEN_ADMIN: makeAddr("gnosis-safe-fraxtal-testnet"),
PROXY_ADMIN: makeAddr("proxy-controller-fraxtal-testnet"),
LZ_ENDPOINT: 0x6EDCE65403992e310A62460808c4b910D972f10f
});

Expand All @@ -73,11 +109,13 @@ contract BaseData is Script {

function getAddresses() internal view returns (Addresses storage) {
require(isSupportedChainId(block.chainid), "BaseData: unsupported chainId");
return __addresses[!isTestnet()];
require(__chainIdToAddresses[block.chainid].OFT_DELEGATE != address(0), "BaseData: addresses not set");
return __chainIdToAddresses[block.chainid];
}

function getEID(uint256 chainId) internal view returns (uint32) {
require(isSupportedChainId(chainId), "BaseData: unsupported chainId");
require(__chainIdToLzEID[chainId] != 0, "BaseData: EID not set");
return __chainIdToLzEID[chainId];
}

Expand All @@ -88,9 +126,4 @@ contract BaseData is Script {
bool isEID = __chainIdToLzEID[chainId] != 0;
return isSupported && isEID;
}

function isTestnet() internal view returns (bool) {
return block.chainid == __chainIds.holesky || block.chainid == __chainIds.fraxtalTestnet
|| block.chainid == __chainIds.sepolia;
}
}
10 changes: 5 additions & 5 deletions script/BaseScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract BaseScript is BaseData {

bytes memory proxyBytecode = bytes.concat(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(implPredictedAddress, getAddresses().PROXY_ADMIN, initializeData)
abi.encode(implPredictedAddress, msg.sender, initializeData)
);

address predictedAddress = vm.computeCreate2Address(proxySalt, keccak256(proxyBytecode));
Expand All @@ -162,10 +162,10 @@ contract BaseScript is BaseData {
predictions.l2Erc20 = predictedAddress;
}

console.log("Predicted MultiChainDeployer: %s", predictions.l2MultiChainDeployer);
console.log("Predicted L1OFTAdapter: %s", predictions.l1OftAdapter);
console.log("Predicted L2OFTAdapter: %s", predictions.l2OftAdapter);
console.log("Predicted L2ERC20: %s", predictions.l2Erc20);
// console.log("Predicted MultiChainDeployer: %s", predictions.l2MultiChainDeployer);
// console.log("Predicted L1OFTAdapter: %s", predictions.l1OftAdapter);
// console.log("Predicted L2OFTAdapter: %s", predictions.l2OftAdapter);
// console.log("Predicted L2ERC20: %s", predictions.l2Erc20);
}

function _validateInput() internal view {
Expand Down
71 changes: 53 additions & 18 deletions script/BatchScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pragma solidity >=0.6.2 <0.9.0;
// 💬 ABOUT
// Gnosis Safe transaction batching script

// @dev picked up from https://github.com/ind-igo/forge-safe
// @dev modified to work with our script setup

// 🧩 MODULES
import {
Script,
Expand Down Expand Up @@ -113,24 +116,33 @@ abstract contract BatchScript is Script {
chainId = block.chainid;

// Set the Safe API base URL and multisend address based on chain
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
// if (chainId == 1) {
// SAFE_API_BASE_URL = "https://safe-transaction-mainnet.safe.global/api/v1/safes/";
// } else if (chainId == 5) {
// SAFE_API_BASE_URL = "https://safe-transaction-goerli.safe.global/api/v1/safes/";
// SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
// } else if (chainId == 8453) {
// SAFE_API_BASE_URL = "https://safe-transaction-base.safe.global/api/v1/safes/";
// SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
// } else if (chainId == 42161) {
// SAFE_API_BASE_URL = "https://safe-transaction-arbitrum.safe.global/api/v1/safes/";
// SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
// } else if (chainId == 43114) {
// SAFE_API_BASE_URL = "https://safe-transaction-avalanche.safe.global/api/v1/safes/";
// SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
// } else {
// revert("Unsupported chain");
// }
if (chainId == 1) {
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
SAFE_API_BASE_URL = "https://safe-transaction-mainnet.safe.global/api/v1/safes/";
} else if (chainId == 8453) {
SAFE_API_BASE_URL = "https://safe-transaction-base.safe.global/api/v1/safes/";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 10) {
SAFE_API_BASE_URL = "https://safe-transaction-optimism.safe.global/api/v1/safes/";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 42161) {
SAFE_API_BASE_URL = "https://safe-transaction-arbitrum.safe.global/api/v1/safes/";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 252) {
SAFE_API_BASE_URL = "";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 17000) {
SAFE_API_BASE_URL = "https://transaction-holesky.holesky-safe.protofire.io/api/v1/safes/";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 11155111) {
SAFE_API_BASE_URL = "https://safe-transaction-sepolia.safe.global/api/v1/safes/";
SAFE_MULTISEND_ADDRESS = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
} else if (chainId == 2522) {
SAFE_API_BASE_URL = "";
SAFE_MULTISEND_ADDRESS = address(0);
} else {
revert("Unsupported chain");
}

// Store the provided safe address
safe = safe_;
Expand Down Expand Up @@ -188,6 +200,29 @@ abstract contract BatchScript is Script {
}
}

function displayBatch() internal view {
// Set initial batch fields
address to = SAFE_MULTISEND_ADDRESS;
uint256 value = 0;
Operation operation = Operation.DELEGATECALL;

// Encode the batch calldata. The list of transactions is tightly packed.
bytes memory data;
uint256 len = encodedTxns.length;
for (uint256 i; i < len; ++i) {
data = bytes.concat(data, encodedTxns[i]);
}
bytes memory txData = abi.encodeWithSignature("multiSend(bytes)", data);

console2.log("Safe Batch Transaction:");
console2.log("To: ", to);
console2.log("Operation: ", uint256(operation));
console2.log("Value: ", value);
console2.log("Data: ");
console2.logBytes(txData);
console2.log("");
}

// Simulate then send the batch to the Safe API. If `send_` is `false`, the
// batch will only be simulated.
function executeBatch(bool send_) internal {
Expand Down
21 changes: 12 additions & 9 deletions script/DeployL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {BaseScript} from "./BaseScript.s.sol";

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

// forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \
Expand Down Expand Up @@ -42,18 +44,19 @@ contract DeployL1OFTAdapter is BaseScript {
vm.broadcast();
l1OFTAdapter = L1YnOFTAdapterUpgradeable(
address(
new TransparentUpgradeableProxy{salt: proxySalt}(
l1OFTAdapterImpl, getAddresses().PROXY_ADMIN, initializeData
)
new TransparentUpgradeableProxy{salt: proxySalt}(l1OFTAdapterImpl, msg.sender, initializeData)
)
);
console.log("L1 OFT Adapter deployed at: %s", address(l1OFTAdapter));

vm.broadcast();
ITransparentUpgradeableProxy(address(l1OFTAdapter)).changeAdmin(getAddresses().PROXY_ADMIN);
console.log("Deployer L1OFTAdapter at: %s", address(l1OFTAdapter));
} else {
l1OFTAdapter = L1YnOFTAdapterUpgradeable(currentDeployment.oftAdapter);
console.log("L1 OFT Adapter already deployed at: %s", address(l1OFTAdapter));
console.log("Already deployed L1OFTAdapter at: %s", address(l1OFTAdapter));
}

require(address(l1OFTAdapter) == predictions.l1OftAdapter, "Deployment failed");
require(address(l1OFTAdapter) == predictions.l1OftAdapter, "Prediction mismatch");

if (l1OFTAdapter.owner() == CURRENT_SIGNER) {
console.log("Setting rate limits");
Expand All @@ -67,7 +70,7 @@ contract DeployL1OFTAdapter is BaseScript {
address adapter = predictions.l2OftAdapter;
bytes32 adapterBytes32 = addressToBytes32(adapter);
if (l1OFTAdapter.peers(eid) == adapterBytes32) {
console.log("Adapter already set for chain %d", chainId);
console.log("Peer already set for chain %d", chainId);
continue;
}

Expand Down
Loading

0 comments on commit 105160f

Please sign in to comment.