文件 1 的 3:IDefaultImplementationBeacon.sol
pragma solidity ^0.8.7;
interface IDefaultImplementationBeacon {
function defaultImplementation() external view returns (address defaultImplementation_);
}
文件 2 的 3:Proxy.sol
pragma solidity ^0.8.7;
import { IDefaultImplementationBeacon } from "./interfaces/IDefaultImplementationBeacon.sol";
import { SlotManipulatable } from "./SlotManipulatable.sol";
contract Proxy is SlotManipulatable {
bytes32 private constant FACTORY_SLOT = bytes32(0x7a45a402e4cb6e08ebc196f20f66d5d30e67285a2a8aa80503fa409e727a4af1);
bytes32 private constant IMPLEMENTATION_SLOT = bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
constructor(address factory_, address implementation_) {
_setSlotValue(FACTORY_SLOT, bytes32(uint256(uint160(factory_))));
address implementation = implementation_ == address(0)
? IDefaultImplementationBeacon(factory_).defaultImplementation()
: implementation_;
require(implementation != address(0));
_setSlotValue(IMPLEMENTATION_SLOT, bytes32(uint256(uint160(implementation))));
}
fallback() payable external virtual {
bytes32 implementation = _getSlotValue(IMPLEMENTATION_SLOT);
require(address(uint160(uint256(implementation))).code.length != uint256(0));
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())
}
}
}
}
文件 3 的 3:SlotManipulatable.sol
pragma solidity ^0.8.7;
abstract contract SlotManipulatable {
function _getReferenceTypeSlot(bytes32 slot_, bytes32 key_) internal pure returns (bytes32 value_) {
return keccak256(abi.encodePacked(key_, slot_));
}
function _getSlotValue(bytes32 slot_) internal view returns (bytes32 value_) {
assembly {
value_ := sload(slot_)
}
}
function _setSlotValue(bytes32 slot_, bytes32 value_) internal {
assembly {
sstore(slot_, value_)
}
}
}
{
"compilationTarget": {
"modules/withdrawal-manager-queue/modules/maple-proxy-factory/modules/proxy-factory/contracts/Proxy.sol": "Proxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":address-registry/=modules/address-registry/contracts/",
":contract-test-utils/=modules/erc20/modules/contract-test-utils/contracts/",
":ds-test/=modules/forge-std/lib/ds-test/src/",
":erc20-helper/=modules/erc20-helper/src/",
":erc20/=modules/erc20/",
":fixed-term-loan-manager/=modules/fixed-term-loan-manager/contracts/",
":fixed-term-loan/=modules/fixed-term-loan/contracts/",
":forge-std/=modules/forge-std/src/",
":globals/=modules/globals/contracts/",
":liquidations/=modules/liquidations/contracts/",
":maple-proxy-factory/=modules/open-term-loan/modules/maple-proxy-factory/",
":non-transparent-proxy/=modules/globals/modules/non-transparent-proxy/",
":ntp/=modules/pool-permission-manager/modules/ntp/",
":open-term-loan-manager/=modules/open-term-loan-manager/contracts/",
":open-term-loan/=modules/open-term-loan/contracts/",
":pool-permission-manager/=modules/pool-permission-manager/contracts/",
":pool/=modules/pool/contracts/",
":proxy-factory/=modules/open-term-loan/modules/maple-proxy-factory/modules/proxy-factory/",
":withdrawal-manager-cyclical/=modules/withdrawal-manager-cyclical/contracts/",
":withdrawal-manager-queue/=modules/withdrawal-manager-queue/contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"factory_","type":"address"},{"internalType":"address","name":"implementation_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"stateMutability":"payable","type":"fallback"}]