You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
32 lines
1.1 KiB
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
pragma solidity ^0.8.20;
|
||
|
|
||
|
import {IAuthority} from "./IAuthority.sol";
|
||
|
|
||
|
library AuthorityUtils {
|
||
|
/**
|
||
|
* @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
|
||
|
* for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
|
||
|
* This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
|
||
|
*/
|
||
|
function canCallWithDelay(
|
||
|
address authority,
|
||
|
address caller,
|
||
|
address target,
|
||
|
bytes4 selector
|
||
|
) internal view returns (bool allowed, uint32 delay) {
|
||
|
(bool success, bytes memory data) = authority.staticcall(
|
||
|
abi.encodeCall(IAuthority.canCall, (caller, target, selector))
|
||
|
);
|
||
|
if (success) {
|
||
|
if (data.length >= 0x40) {
|
||
|
(allowed, delay) = abi.decode(data, (bool, uint32));
|
||
|
} else if (data.length >= 0x20) {
|
||
|
allowed = abi.decode(data, (bool));
|
||
|
}
|
||
|
}
|
||
|
return (allowed, delay);
|
||
|
}
|
||
|
}
|