编译器
0.8.21+commit.d9974bed
文件 1 的 5:BaseProxy.sol
pragma solidity ^0.8.0;
import { IProxy } from '../interfaces/IProxy.sol';
abstract contract BaseProxy is IProxy {
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 internal constant _OWNER_SLOT = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
function implementation() public view virtual returns (address implementation_) {
assembly {
implementation_ := sload(_IMPLEMENTATION_SLOT)
}
}
function setup(bytes calldata params) external {}
function contractId() internal pure virtual returns (bytes32);
fallback() external payable virtual {
address implementation_ = implementation();
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation_, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable virtual {}
}
文件 2 的 5:IContractIdentifier.sol
pragma solidity ^0.8.0;
interface IContractIdentifier {
function contractId() external pure returns (bytes32);
}
文件 3 的 5:IProxy.sol
pragma solidity ^0.8.0;
interface IProxy {
error InvalidOwner();
error InvalidImplementation();
error SetupFailed();
error NotOwner();
error AlreadyInitialized();
function implementation() external view returns (address);
function setup(bytes calldata setupParams) external;
}
文件 4 的 5:InterchainProxy.sol
pragma solidity ^0.8.0;
import { Proxy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Proxy.sol';
contract InterchainProxy is Proxy {
constructor(address implementationAddress, address owner, bytes memory setupParams) Proxy(implementationAddress, owner, setupParams) {}
}
文件 5 的 5:Proxy.sol
pragma solidity ^0.8.0;
import { IProxy } from '../interfaces/IProxy.sol';
import { IContractIdentifier } from '../interfaces/IContractIdentifier.sol';
import { BaseProxy } from './BaseProxy.sol';
contract Proxy is BaseProxy {
constructor(
address implementationAddress,
address owner,
bytes memory setupParams
) {
if (owner == address(0)) revert InvalidOwner();
bytes32 id = contractId();
if (id != bytes32(0) && IContractIdentifier(implementationAddress).contractId() != id)
revert InvalidImplementation();
assembly {
sstore(_IMPLEMENTATION_SLOT, implementationAddress)
sstore(_OWNER_SLOT, owner)
}
if (setupParams.length != 0) {
(bool success, ) = implementationAddress.delegatecall(
abi.encodeWithSelector(BaseProxy.setup.selector, setupParams)
);
if (!success) revert SetupFailed();
}
}
function contractId() internal pure virtual override returns (bytes32) {
return bytes32(0);
}
}
{
"compilationTarget": {
"contracts/proxies/InterchainProxy.sol": "InterchainProxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"implementationAddress","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes","name":"setupParams","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"InvalidImplementation","type":"error"},{"inputs":[],"name":"InvalidOwner","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"SetupFailed","type":"error"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"implementation_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"params","type":"bytes"}],"name":"setup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]