文件 1 的 1:ERC1967Proxy.sol
pragma solidity ^0.8.0;
bytes32 constant ERC1967_PROXY_STORAGE_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
function s() pure returns (ERC1967UpgradeDS storage diamondStorage) {
assembly { diamondStorage.slot := ERC1967_PROXY_STORAGE_SLOT }
}
struct ERC1967UpgradeDS {
address implementation;
}
error InvalidUUID();
error NotAContract();
abstract contract ERC1967 {
event Upgraded(address indexed implementation);
function _upgradeToAndCall(address logic, bytes memory data) internal {
if (logic.code.length == 0) revert NotAContract();
if (ERC1822(logic).proxiableUUID() != ERC1967_PROXY_STORAGE_SLOT) revert InvalidUUID();
if (data.length != 0) {
(bool success, ) = logic.delegatecall(data);
if (!success) {
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
}
emit Upgraded(logic);
s().implementation = logic;
}
}
contract ERC1967Proxy is ERC1967 {
constructor(address logic, bytes memory data) payable {
_upgradeToAndCall(logic, data);
}
fallback() external payable {
assembly {
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), sload(ERC1967_PROXY_STORAGE_SLOT), 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if success {
return(0, returndatasize())
}
revert(0, returndatasize())
}
}
}
abstract contract ERC1822 {
function proxiableUUID() external view virtual returns (bytes32);
}
{
"compilationTarget": {
"lib/UDS/src/proxy/ERC1967Proxy.sol": "ERC1967Proxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 100000
},
"remappings": [
":CRFTD/=src/",
":ERC721A/=lib/fx-contracts/lib/ERC721M/lib/ERC721A/contracts/",
":ERC721M/=lib/fx-contracts/lib/ERC721M/src/",
":UDS/=lib/UDS/src/",
":ds-test/=lib/solmate/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":futils/=lib/futils/src/",
":fx-contracts/=lib/fx-contracts/src/",
":fx-portal/=lib/fx-contracts/lib/ERC721M/lib/fx-portal/contracts/",
":openzeppelin/=lib/fx-contracts/lib/ERC721M/lib/openzeppelin-contracts/",
":solmate/=lib/solmate/src/"
]
}