Skip to content

Commit

Permalink
updates for abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeexcoin committed Dec 30, 2024
1 parent 233a592 commit 9fd64a5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 7 deletions.
9 changes: 3 additions & 6 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ contract Deploy is Script {
vm.startBroadcast();

// deploy resolver
bytes memory resolverInitCode = abi.encodePacked(type(ExclusiveDelegateResolver).creationCode);
resolver = ExclusiveDelegateResolver(
ImmutableCreate2Factory(0x0000000000FFe8B47B3e2130213B802212439497).safeCreate2(salt, resolverInitCode)
);
vm.stopBroadcast();

console2.logBytes32(keccak256(resolverInitCode));
ExclusiveDelegateResolver resolver = new ExclusiveDelegateResolver{salt: bytes32(0)}();
console.log("resolver", address(resolver));
vm.stopBroadcast();
}
}
61 changes: 60 additions & 1 deletion src/ExclusiveDelegateResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,52 @@ import {IDelegateRegistry} from "./interfaces/IDelegateRegistry.sol";
*/
contract ExclusiveDelegateResolver {
/// @dev The address of the Delegate Registry contract
address public constant DELEGATE_REGISTRY = 0x00000000000000447e69651d841bD8D104Bed493;
address public constant DELEGATE_REGISTRY = 0x6b176c958fb89Ddca0fc8214150DA4c4D0a32fbe;

/// @dev The rights value for a global delegation. These are considered only if no delegation by rights matches the request.
bytes24 public constant GLOBAL_DELEGATION = bytes24(0);

/**
* @notice Gets an exclusive wallet delegation, resolved through delegatexyz if possible
* @param vault The vault address
* @param rights The rights to check
* @return owner The vault wallet address or delegated wallet if one exists
* @notice returns the most recent delegation that matches the rights for an entire wallet delegation
* (type ALL) if multiple delegations of the same specificity match the rights, the most recent one is respected.
* If no delegation matches the rights, global delegations (bytes24(0) are considered,
* but MUST have an expiration greater than 0 to avoid conflicts with pre-existing delegations.
* If no delegation matches the rights and there are no empty delegations, the owner is returned.
* Expirations are supported by extracting a uint40 from the final 40 bits of a given delegation's rights value.
* If the expiration is past, the delegation is not considered to match the request.
*/
function exclusiveWalletByRights(address vault, bytes24 rights) external view returns (address) {
IDelegateRegistry.Delegation[] memory delegations =
IDelegateRegistry(DELEGATE_REGISTRY).getOutgoingDelegations(vault);

IDelegateRegistry.Delegation memory delegationToReturn;

for (uint256 i = delegations.length; i > 0;) {
unchecked {
--i;
}
IDelegateRegistry.Delegation memory delegation = delegations[i];

if (_delegationMatchesRequest(delegation, rights)) {
if (_delegationOutranksCurrent(delegationToReturn, delegation)) {
// re-check rights here to ensure global delegation does not get early returned
if (
delegation.type_ == IDelegateRegistry.DelegationType.ALL && bytes24(delegation.rights) == rights
) {
return delegation.to;
}
delegationToReturn = delegation;
}
}
}

return delegationToReturn.to == address(0) ? vault : delegationToReturn.to;
}

/**
* @notice Gets the owner of an ERC721 token, resolved through delegatexyz if possible
* @param contractAddress The ERC721 contract address
Expand Down Expand Up @@ -101,6 +142,24 @@ contract ExclusiveDelegateResolver {
return bytes32(rights | uint256(expiration));
}

function _delegationMatchesRequest(IDelegateRegistry.Delegation memory delegation, bytes24 rights)
internal
view
returns (bool)
{
(bytes24 rightsIdentifier, uint40 expiration) = decodeRightsExpiration(delegation.rights);

if (block.timestamp > expiration) {
return false;
} else if (rightsIdentifier != rights && rightsIdentifier != GLOBAL_DELEGATION) {
return false;
} else if (delegation.type_ == IDelegateRegistry.DelegationType.ALL) {
return true;
} else {
return false;
}
}

function _delegationMatchesRequest(
IDelegateRegistry.Delegation memory delegation,
address contractAddress,
Expand Down

0 comments on commit 9fd64a5

Please sign in to comment.