40 lines
1.3 KiB
Solidity
40 lines
1.3 KiB
Solidity
|
|
// SPDX-License-Identifier: MIT
|
||
|
|
pragma solidity ^0.8.24;
|
||
|
|
|
||
|
|
import {IDiamondCut} from "../src/interfaces/IDiamondCut.sol";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @title FacetCutHelper
|
||
|
|
* @notice Helper contract to get function selectors from facet contracts
|
||
|
|
*/
|
||
|
|
library FacetCutHelper {
|
||
|
|
function getSelectors(address facet) internal view returns (bytes4[] memory) {
|
||
|
|
bytes memory facetCode = _getCreationCode(facet);
|
||
|
|
return _extractSelectors(facetCode);
|
||
|
|
}
|
||
|
|
|
||
|
|
function _getCreationCode(address contractAddress) internal view returns (bytes memory) {
|
||
|
|
uint256 size;
|
||
|
|
assembly {
|
||
|
|
size := extcodesize(contractAddress)
|
||
|
|
}
|
||
|
|
bytes memory code = new bytes(size);
|
||
|
|
assembly {
|
||
|
|
extcodecopy(contractAddress, add(code, 0x20), 0, size)
|
||
|
|
}
|
||
|
|
return code;
|
||
|
|
}
|
||
|
|
|
||
|
|
function _extractSelectors(bytes memory bytecode) internal pure returns (bytes4[] memory) {
|
||
|
|
// Simplified selector extraction - in production use proper parsing
|
||
|
|
// This is a placeholder - actual implementation would parse bytecode
|
||
|
|
bytes4[] memory selectors = new bytes4[](100); // Max selectors
|
||
|
|
uint256 count = 0;
|
||
|
|
|
||
|
|
// This is a simplified version - proper implementation would parse the bytecode
|
||
|
|
// For now, return empty and require manual selector lists
|
||
|
|
return new bytes4[](0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|