Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control. - Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities. - Created .gitmodules to include OpenZeppelin contracts as a submodule. - Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment. - Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks. - Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring. - Created scripts for resource import and usage validation across non-US regions. - Added tests for CCIP error handling and integration to ensure robust functionality. - Included various new files and directories for the orchestration portal and deployment scripts.
This commit is contained in:
128
contracts/utils/AddressMapper.sol
Normal file
128
contracts/utils/AddressMapper.sol
Normal file
@@ -0,0 +1,128 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
/**
|
||||
* @title AddressMapper
|
||||
* @notice Maps reserved genesis.json addresses to actual deployed addresses
|
||||
* @dev This contract provides a centralized mapping for addresses that were
|
||||
* reserved in genesis.json but deployed to different addresses
|
||||
*/
|
||||
contract AddressMapper {
|
||||
// Mapping from genesis address to deployed address
|
||||
mapping(address => address) private _addressMap;
|
||||
|
||||
// Reverse mapping for verification
|
||||
mapping(address => address) private _reverseMap;
|
||||
|
||||
// Owner for updates
|
||||
address public owner;
|
||||
|
||||
event AddressMapped(address indexed genesisAddress, address indexed deployedAddress);
|
||||
event MappingRemoved(address indexed genesisAddress);
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner, "AddressMapper: caller is not owner");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
owner = msg.sender;
|
||||
|
||||
// Initialize with known mappings
|
||||
// WETH9: Genesis -> Deployed
|
||||
address weth9Genesis = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
|
||||
address weth9Deployed = 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6;
|
||||
_addressMap[weth9Genesis] = weth9Deployed;
|
||||
_reverseMap[weth9Deployed] = weth9Genesis;
|
||||
emit AddressMapped(weth9Genesis, weth9Deployed);
|
||||
|
||||
// WETH10: Genesis -> Deployed
|
||||
address weth10Genesis = 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9F;
|
||||
address weth10Deployed = 0x105F8A15b819948a89153505762444Ee9f324684;
|
||||
_addressMap[weth10Genesis] = weth10Deployed;
|
||||
_reverseMap[weth10Deployed] = weth10Genesis;
|
||||
emit AddressMapped(weth10Genesis, weth10Deployed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get the deployed address for a genesis address
|
||||
* @param genesisAddress The address from genesis.json
|
||||
* @return deployedAddress The actual deployed address, or address(0) if not mapped
|
||||
*/
|
||||
function getDeployedAddress(address genesisAddress) external view returns (address) {
|
||||
address deployed = _addressMap[genesisAddress];
|
||||
// If not mapped, return the genesis address itself (no mapping needed)
|
||||
return deployed == address(0) ? genesisAddress : deployed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get the genesis address for a deployed address
|
||||
* @param deployedAddress The deployed address
|
||||
* @return genesisAddress The genesis address, or address(0) if not mapped
|
||||
*/
|
||||
function getGenesisAddress(address deployedAddress) external view returns (address) {
|
||||
return _reverseMap[deployedAddress];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Check if an address is a genesis address that has been mapped
|
||||
* @param addr Address to check
|
||||
* @return isMapped True if the address has a mapping
|
||||
*/
|
||||
function isMapped(address addr) external view returns (bool) {
|
||||
return _addressMap[addr] != address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Add or update a mapping (owner only)
|
||||
* @param genesisAddress The genesis address
|
||||
* @param deployedAddress The deployed address
|
||||
*/
|
||||
function setMapping(address genesisAddress, address deployedAddress) external onlyOwner {
|
||||
require(genesisAddress != address(0), "AddressMapper: genesis address cannot be zero");
|
||||
require(deployedAddress != address(0), "AddressMapper: deployed address cannot be zero");
|
||||
require(genesisAddress != deployedAddress, "AddressMapper: addresses must be different");
|
||||
|
||||
// Remove old reverse mapping if exists
|
||||
address oldDeployed = _addressMap[genesisAddress];
|
||||
if (oldDeployed != address(0)) {
|
||||
delete _reverseMap[oldDeployed];
|
||||
}
|
||||
|
||||
// Remove old forward mapping if deployed address was mapped to something else
|
||||
address oldGenesis = _reverseMap[deployedAddress];
|
||||
if (oldGenesis != address(0)) {
|
||||
delete _addressMap[oldGenesis];
|
||||
}
|
||||
|
||||
// Set new mappings
|
||||
_addressMap[genesisAddress] = deployedAddress;
|
||||
_reverseMap[deployedAddress] = genesisAddress;
|
||||
|
||||
emit AddressMapped(genesisAddress, deployedAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Remove a mapping (owner only)
|
||||
* @param genesisAddress The genesis address to remove
|
||||
*/
|
||||
function removeMapping(address genesisAddress) external onlyOwner {
|
||||
address deployed = _addressMap[genesisAddress];
|
||||
require(deployed != address(0), "AddressMapper: mapping does not exist");
|
||||
|
||||
delete _addressMap[genesisAddress];
|
||||
delete _reverseMap[deployed];
|
||||
|
||||
emit MappingRemoved(genesisAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Transfer ownership (owner only)
|
||||
* @param newOwner The new owner address
|
||||
*/
|
||||
function transferOwnership(address newOwner) external onlyOwner {
|
||||
require(newOwner != address(0), "AddressMapper: new owner cannot be zero");
|
||||
owner = newOwner;
|
||||
}
|
||||
}
|
||||
|
||||
59
contracts/utils/CREATE2Factory.sol
Normal file
59
contracts/utils/CREATE2Factory.sol
Normal file
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
/**
|
||||
* @title CREATE2 Factory
|
||||
* @notice Factory for deploying contracts at deterministic addresses using CREATE2
|
||||
* @dev Based on the canonical CREATE2 factory pattern
|
||||
*/
|
||||
contract CREATE2Factory {
|
||||
event Deployed(address addr, uint256 salt);
|
||||
|
||||
/**
|
||||
* @notice Deploy a contract using CREATE2
|
||||
* @param bytecode Contract bytecode
|
||||
* @param salt Salt for deterministic address generation
|
||||
* @return addr Deployed contract address
|
||||
*/
|
||||
function deploy(bytes memory bytecode, uint256 salt) public returns (address addr) {
|
||||
assembly {
|
||||
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
|
||||
if iszero(extcodesize(addr)) {
|
||||
revert(0, 0)
|
||||
}
|
||||
}
|
||||
emit Deployed(addr, salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Compute the address that will be created with CREATE2
|
||||
* @param bytecode Contract bytecode
|
||||
* @param salt Salt for deterministic address generation
|
||||
* @return addr Predicted contract address
|
||||
*/
|
||||
function computeAddress(bytes memory bytecode, uint256 salt) public view returns (address addr) {
|
||||
bytes32 hash = keccak256(
|
||||
abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(bytecode))
|
||||
);
|
||||
addr = address(uint160(uint256(hash)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Compute the address that will be created with CREATE2 (with deployer)
|
||||
* @param deployer Deployer address
|
||||
* @param bytecode Contract bytecode
|
||||
* @param salt Salt for deterministic address generation
|
||||
* @return addr Predicted contract address
|
||||
*/
|
||||
function computeAddressWithDeployer(
|
||||
address deployer,
|
||||
bytes memory bytecode,
|
||||
uint256 salt
|
||||
) public pure returns (address addr) {
|
||||
bytes32 hash = keccak256(
|
||||
abi.encodePacked(bytes1(0xff), deployer, salt, keccak256(bytecode))
|
||||
);
|
||||
addr = address(uint160(uint256(hash)));
|
||||
}
|
||||
}
|
||||
|
||||
131
contracts/utils/Multicall.sol
Normal file
131
contracts/utils/Multicall.sol
Normal file
@@ -0,0 +1,131 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
/**
|
||||
* @title Multicall
|
||||
* @notice Aggregate multiple calls in a single transaction
|
||||
* @dev Based on Uniswap V3 Multicall
|
||||
*/
|
||||
contract Multicall {
|
||||
struct Call {
|
||||
address target;
|
||||
bytes callData;
|
||||
}
|
||||
|
||||
struct Result {
|
||||
bool success;
|
||||
bytes returnData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Aggregate multiple calls
|
||||
* @param calls Array of calls to execute
|
||||
* @return returnData Array of return data for each call
|
||||
*/
|
||||
function aggregate(Call[] memory calls) public returns (bytes[] memory returnData) {
|
||||
returnData = new bytes[](calls.length);
|
||||
for (uint256 i = 0; i < calls.length; i++) {
|
||||
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
|
||||
require(success, "Multicall: call failed");
|
||||
returnData[i] = ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Aggregate multiple calls, allowing failures
|
||||
* @param requireSuccess If true, require all calls to succeed
|
||||
* @param calls Array of calls to execute
|
||||
* @return returnData Array of results with success flags and return data for each call
|
||||
*/
|
||||
function tryAggregate(bool requireSuccess, Call[] memory calls)
|
||||
public
|
||||
returns (Result[] memory returnData)
|
||||
{
|
||||
returnData = new Result[](calls.length);
|
||||
for (uint256 i = 0; i < calls.length; i++) {
|
||||
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
|
||||
|
||||
if (requireSuccess) {
|
||||
require(success, "Multicall: call failed");
|
||||
}
|
||||
|
||||
returnData[i] = Result(success, ret);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Aggregate multiple calls with gas limit
|
||||
* @param calls Array of calls to execute
|
||||
* @param gasLimit Gas limit for each call
|
||||
* @return returnData Array of return data for each call
|
||||
*/
|
||||
function aggregateWithGasLimit(Call[] memory calls, uint256 gasLimit)
|
||||
public
|
||||
returns (bytes[] memory returnData)
|
||||
{
|
||||
returnData = new bytes[](calls.length);
|
||||
for (uint256 i = 0; i < calls.length; i++) {
|
||||
(bool success, bytes memory ret) = calls[i].target.call{gas: gasLimit}(calls[i].callData);
|
||||
require(success, "Multicall: call failed");
|
||||
returnData[i] = ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get block hash for a specific block
|
||||
* @param blockNumber Block number
|
||||
* @return blockHash Block hash
|
||||
*/
|
||||
function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
|
||||
blockHash = blockhash(blockNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current block timestamp
|
||||
* @return timestamp Current block timestamp
|
||||
*/
|
||||
function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
|
||||
timestamp = block.timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current block difficulty
|
||||
* @return difficulty Current block difficulty
|
||||
*/
|
||||
function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
|
||||
difficulty = block.difficulty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current block gas limit
|
||||
* @return gaslimit Current block gas limit
|
||||
*/
|
||||
function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
|
||||
gaslimit = block.gaslimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current block coinbase
|
||||
* @return coinbase Current block coinbase
|
||||
*/
|
||||
function getCurrentBlockCoinbase() public view returns (address coinbase) {
|
||||
coinbase = block.coinbase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current block number
|
||||
* @return blockNumber Current block number
|
||||
*/
|
||||
function getCurrentBlockNumber() public view returns (uint256 blockNumber) {
|
||||
blockNumber = block.number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Get current chain ID
|
||||
* @return chainid Current chain ID
|
||||
*/
|
||||
function getChainId() public view returns (uint256 chainid) {
|
||||
chainid = block.chainid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user