Skip to content

Commit

Permalink
Merge a0dfd3a into 75b1a6f
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR authored Nov 28, 2024
2 parents 75b1a6f + a0dfd3a commit 9350c6b
Show file tree
Hide file tree
Showing 20 changed files with 372 additions and 50 deletions.
10 changes: 10 additions & 0 deletions contracts/.changeset/metal-ducks-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainlink/contracts': patch
---

#feature adds OZ AccessControl support to the registry module


PR issue: CCIP-4105

Solidity Review issue: CCIP-3966
7 changes: 7 additions & 0 deletions contracts/.changeset/wet-eyes-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chainlink/contracts': patch
---

Refactor MockCCIPRouter to support EVMExtraArgsV2

PR issue : CCIP-4288
2 changes: 1 addition & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test = 'src/v0.8/transmission/test'
optimizer_runs = 1_000_000
src = 'src/v0.8/shared'
test = 'src/v0.8/shared/test'
solc_version = '0.8.19'
solc_version = '0.8.24'


# See more config options https://github.com/foundry-rs/foundry/tree/master/config
23 changes: 14 additions & 9 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ MerkleMultiProofTest:test_EmptyLeaf_Revert() (gas: 3585)
MerkleMultiProofTest:test_MerkleRoot256() (gas: 394891)
MerkleMultiProofTest:test_MerkleRootSingleLeaf_Success() (gas: 3661)
MerkleMultiProofTest:test_SpecSync_gas() (gas: 34129)
MockRouterTest:test_ccipSendWithEVMExtraArgsV1_Success() (gas: 110073)
MockRouterTest:test_ccipSendWithEVMExtraArgsV2_Success() (gas: 132614)
MockRouterTest:test_ccipSendWithInsufficientNativeTokens_Revert() (gas: 34037)
MockRouterTest:test_ccipSendWithInvalidMsgValue_Revert() (gas: 60842)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126576)
MockRouterTest:test_ccipSendWithLinkFeeTokenbutInsufficientAllowance_Revert() (gas: 63455)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 44012)
MockRouterTest:test_ccipSendWithInvalidEVMExtraArgs_Revert() (gas: 106684)
MockRouterTest:test_ccipSendWithInvalidMsgValue_Revert() (gas: 60886)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126640)
MockRouterTest:test_ccipSendWithLinkFeeTokenButInsufficientAllowance_Revert() (gas: 63478)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 44048)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigsBothLanes_Success() (gas: 133528)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigs_Success() (gas: 315630)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_OnlyCallableByOwner_Revert() (gas: 17864)
Expand Down Expand Up @@ -917,11 +920,13 @@ RateLimiter_consume:test_TokenRateLimitReached_Revert() (gas: 24886)
RateLimiter_currentTokenBucketState:test_CurrentTokenBucketState_Success() (gas: 38944)
RateLimiter_currentTokenBucketState:test_Refill_Success() (gas: 46849)
RateLimiter_setTokenBucketConfig:test_SetRateLimiterConfig_Success() (gas: 38506)
RegistryModuleOwnerCustom_constructor:test_constructor_Revert() (gas: 36033)
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Revert() (gas: 19739)
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Success() (gas: 130086)
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Revert() (gas: 19559)
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Success() (gas: 129905)
RegistryModuleOwnerCustom_constructor:test_constructor_Revert() (gas: 36107)
RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin:test_registerAccessControlDefaultAdmin_Revert() (gas: 20206)
RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin:test_registerAccessControlDefaultAdmin_Success() (gas: 130628)
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Revert() (gas: 19773)
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Success() (gas: 130108)
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Revert() (gas: 19593)
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Success() (gas: 129927)
Router_applyRampUpdates:test_OffRampMismatch_Revert() (gas: 89366)
Router_applyRampUpdates:test_OffRampUpdatesWithRouting() (gas: 10662612)
Router_applyRampUpdates:test_OnRampDisable() (gas: 56007)
Expand Down
58 changes: 33 additions & 25 deletions contracts/gas-snapshots/shared.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
AuthorizedCallers_applyAuthorizedCallerUpdates:test_AddAndRemove_Success() (gas: 125205)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyAdd_Success() (gas: 133100)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyCallableByOwner_Revert() (gas: 12350)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyRemove_Success() (gas: 45064)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_RemoveThenAdd_Success() (gas: 57241)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_SkipRemove_Success() (gas: 32121)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_ZeroAddressNotAllowed_Revert() (gas: 64473)
AuthorizedCallers_constructor:test_ZeroAddressNotAllowed_Revert() (gas: 64473)
AuthorizedCallers_constructor:test_constructor_Success() (gas: 720513)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_AddAndRemove_Success() (gas: 125022)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyAdd_Success() (gas: 132980)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyCallableByOwner_Revert() (gas: 12356)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_OnlyRemove_Success() (gas: 45007)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_RemoveThenAdd_Success() (gas: 57121)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_SkipRemove_Success() (gas: 32064)
AuthorizedCallers_applyAuthorizedCallerUpdates:test_ZeroAddressNotAllowed_Revert() (gas: 64440)
AuthorizedCallers_constructor:test_ZeroAddressNotAllowed_Revert() (gas: 64440)
AuthorizedCallers_constructor:test_constructor_Success() (gas: 704809)
BurnMintERC677_approve:testApproveSuccess() (gas: 55512)
BurnMintERC677_approve:testInvalidAddressReverts() (gas: 10663)
BurnMintERC677_burn:testBasicBurnSuccess() (gas: 173939)
BurnMintERC677_burn:testBasicBurnSuccess() (gas: 172100)
BurnMintERC677_burn:testBurnFromZeroAddressReverts() (gas: 47201)
BurnMintERC677_burn:testExceedsBalanceReverts() (gas: 21841)
BurnMintERC677_burn:testSenderNotBurnerReverts() (gas: 13359)
Expand All @@ -21,7 +21,7 @@ BurnMintERC677_burnFromAlias:testBurnFromSuccess() (gas: 57949)
BurnMintERC677_burnFromAlias:testExceedsBalanceReverts() (gas: 35880)
BurnMintERC677_burnFromAlias:testInsufficientAllowanceReverts() (gas: 21869)
BurnMintERC677_burnFromAlias:testSenderNotBurnerReverts() (gas: 13379)
BurnMintERC677_constructor:testConstructorSuccess() (gas: 1672809)
BurnMintERC677_constructor:testConstructorSuccess() (gas: 1672812)
BurnMintERC677_decreaseApproval:testDecreaseApprovalSuccess() (gas: 31069)
BurnMintERC677_grantMintAndBurnRoles:testGrantMintAndBurnRolesSuccess() (gas: 121324)
BurnMintERC677_grantRole:testGrantBurnAccessSuccess() (gas: 53460)
Expand All @@ -34,14 +34,14 @@ BurnMintERC677_mint:testSenderNotMinterReverts() (gas: 11195)
BurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12476)
BurnMintERC677_transfer:testInvalidAddressReverts() (gas: 10639)
BurnMintERC677_transfer:testTransferSuccess() (gas: 42299)
CallWithExactGas__callWithExactGas:test_CallWithExactGasReceiverErrorSuccess() (gas: 67209)
CallWithExactGas__callWithExactGas:test_CallWithExactGasReceiverErrorSuccess() (gas: 65949)
CallWithExactGas__callWithExactGas:test_CallWithExactGasSafeReturnDataExactGas() (gas: 18324)
CallWithExactGas__callWithExactGas:test_NoContractReverts() (gas: 11559)
CallWithExactGas__callWithExactGas:test_NoGasForCallExactCheckReverts() (gas: 15788)
CallWithExactGas__callWithExactGas:test_NotEnoughGasForCallReverts() (gas: 16241)
CallWithExactGas__callWithExactGas:test_callWithExactGasSuccess(bytes,bytes4) (runs: 256, μ: 15766, ~: 15719)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractExactGasSuccess() (gas: 20116)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractReceiverErrorSuccess() (gas: 67721)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractReceiverErrorSuccess() (gas: 66461)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractSuccess(bytes,bytes4) (runs: 256, μ: 16276, ~: 16229)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_NoContractSuccess() (gas: 12962)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_NoGasForCallExactCheckReturnFalseSuccess() (gas: 13005)
Expand Down Expand Up @@ -75,20 +75,28 @@ EnumerableMapAddresses_tryGet:testBytes32TryGetSuccess() (gas: 94622)
EnumerableMapAddresses_tryGet:testBytesTryGetSuccess() (gas: 96279)
EnumerableMapAddresses_tryGet:testTryGetSuccess() (gas: 94893)
OpStackBurnMintERC677_constructor:testConstructorSuccess() (gas: 1743649)
OpStackBurnMintERC677_interfaceCompatibility:testBurnCompatibility() (gas: 298649)
OpStackBurnMintERC677_interfaceCompatibility:testBurnCompatibility() (gas: 291393)
OpStackBurnMintERC677_interfaceCompatibility:testMintCompatibility() (gas: 137957)
OpStackBurnMintERC677_interfaceCompatibility:testStaticFunctionsCompatibility() (gas: 13781)
OpStackBurnMintERC677_supportsInterface:testConstructorSuccess() (gas: 12752)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySubset_Reverts() (gas: 5460)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySuperset_Reverts() (gas: 4661)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_HasDuplicates_Reverts() (gas: 8265)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_NotASubset_Reverts() (gas: 12487)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SingleElementSubset() (gas: 4489)
Ownable2Step_acceptOwnership:test_acceptOwnership_MustBeProposedOwner_reverts() (gas: 10360)
Ownable2Step_acceptOwnership:test_acceptOwnership_success() (gas: 31088)
Ownable2Step_constructor:test_constructor_OwnerCannotBeZero_reverts() (gas: 35858)
Ownable2Step_constructor:test_constructor_success() (gas: 10428)
Ownable2Step_onlyOwner:test_onlyOwner_OnlyCallableByOwner_reverts() (gas: 10754)
Ownable2Step_onlyOwner:test_onlyOwner_success() (gas: 7506)
Ownable2Step_transferOwnership:test_transferOwnership_CannotTransferToSelf_reverts() (gas: 10501)
Ownable2Step_transferOwnership:test_transferOwnership_success() (gas: 30140)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySubset_Reverts() (gas: 5208)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_EmptySuperset_Reverts() (gas: 4535)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_HasDuplicates_Reverts() (gas: 7761)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_NotASubset_Reverts() (gas: 11668)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SingleElementSubset() (gas: 3922)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SingleElementSubsetAndSuperset_Equal() (gas: 1464)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SingleElementSubsetAndSuperset_NotEqual_Reverts() (gas: 6172)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SubsetEqualsSuperset_NoRevert() (gas: 8867)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SubsetLargerThanSuperset_Reverts() (gas: 16544)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SupersetHasDuplicates_Reverts() (gas: 9420)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_UnsortedSubset_Reverts() (gas: 7380)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_UnsortedSuperset_Reverts() (gas: 9600)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_ValidSubset_Success() (gas: 6490)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SubsetEqualsSuperset_NoRevert() (gas: 7859)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SubsetLargerThanSuperset_Reverts() (gas: 15410)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_SupersetHasDuplicates_Reverts() (gas: 8790)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_UnsortedSubset_Reverts() (gas: 7128)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_UnsortedSuperset_Reverts() (gas: 8970)
SortedSetValidationUtil_CheckIsValidUniqueSubsetTest:test__checkIsValidUniqueSubset_ValidSubset_Success() (gas: 5671)
17 changes: 13 additions & 4 deletions contracts/src/v0.8/ccip/test/mocks/MockRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ contract MockCCIPRouter is IRouter, IRouterClient {
return mockMsgId;
}

function _fromBytes(bytes calldata extraArgs) internal pure returns (Client.EVMExtraArgsV1 memory) {
function _fromBytes(
bytes calldata extraArgs
) internal pure returns (Client.EVMExtraArgsV2 memory) {
if (extraArgs.length == 0) {
return Client.EVMExtraArgsV1({gasLimit: DEFAULT_GAS_LIMIT});
return Client.EVMExtraArgsV2({gasLimit: DEFAULT_GAS_LIMIT, allowOutOfOrderExecution: false});
}
if (bytes4(extraArgs) != Client.EVM_EXTRA_ARGS_V1_TAG) revert InvalidExtraArgsTag();
return abi.decode(extraArgs[4:], (Client.EVMExtraArgsV1));

bytes4 extraArgsTag = bytes4(extraArgs);
if (extraArgsTag == Client.EVM_EXTRA_ARGS_V2_TAG) {
return abi.decode(extraArgs[4:], (Client.EVMExtraArgsV2));
} else if (extraArgsTag == Client.EVM_EXTRA_ARGS_V1_TAG) {
return Client.EVMExtraArgsV2({gasLimit: abi.decode(extraArgs[4:], (uint256)), allowOutOfOrderExecution: false});
}

revert InvalidExtraArgsTag();
}

/// @notice Always returns true to make sure this check can be performed on any chain.
Expand Down
22 changes: 21 additions & 1 deletion contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract MockRouterTest is TokenSetup {
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithLinkFeeTokenbutInsufficientAllowance_Revert() public {
function test_ccipSendWithLinkFeeTokenButInsufficientAllowance_Revert() public {
message.feeToken = s_sourceFeeToken;

vm.expectRevert(bytes("ERC20: insufficient allowance"));
Expand All @@ -65,4 +65,24 @@ contract MockRouterTest is TokenSetup {

mockRouter.ccipSend(mockChainSelector, message);
}

function test_ccipSendWithEVMExtraArgsV1_Success() public {
Client.EVMExtraArgsV1 memory extraArgs = Client.EVMExtraArgsV1({gasLimit: 500_000});
message.extraArgs = Client._argsToBytes(extraArgs);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithEVMExtraArgsV2_Success() public {
Client.EVMExtraArgsV2 memory extraArgs = Client.EVMExtraArgsV2({gasLimit: 500_000, allowOutOfOrderExecution: true});
message.extraArgs = Client._argsToBytes(extraArgs);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithInvalidEVMExtraArgs_Revert() public {
uint256 gasLimit = 500_000;
bytes4 invalidExtraArgsTag = bytes4(keccak256("CCIP EVMExtraArgsInvalid"));
message.extraArgs = abi.encodeWithSelector(invalidExtraArgsTag, gasLimit);
vm.expectRevert(MockCCIPRouter.InvalidExtraArgsTag.selector);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {RegistryModuleOwnerCustom} from "../../tokenAdminRegistry/RegistryModule
import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol";
import {BurnMintERC677Helper} from "../helpers/BurnMintERC677Helper.sol";

import {AccessControl} from "../../../vendor/openzeppelin-solidity/v5.0.2/contracts/access/AccessControl.sol";
import {Test} from "forge-std/Test.sol";

contract RegistryModuleOwnerCustomSetup is Test {
Expand Down Expand Up @@ -102,3 +103,54 @@ contract RegistryModuleOwnerCustom_registerAdminViaOwner is RegistryModuleOwnerC
s_registryModuleOwnerCustom.registerAdminViaOwner(s_token);
}
}

contract AccessController is AccessControl {
constructor(
address admin
) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
}

contract RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin is RegistryModuleOwnerCustomSetup {
function setUp() public override {
super.setUp();

s_token = address(new AccessController(OWNER));
}

function test_registerAccessControlDefaultAdmin_Success() public {
assertEq(s_tokenAdminRegistry.getTokenConfig(s_token).administrator, address(0));

bytes32 defaultAdminRole = AccessController(s_token).DEFAULT_ADMIN_ROLE();

vm.expectCall(address(s_token), abi.encodeWithSelector(AccessControl.hasRole.selector, defaultAdminRole, OWNER), 1);
vm.expectCall(
address(s_tokenAdminRegistry),
abi.encodeWithSelector(TokenAdminRegistry.proposeAdministrator.selector, s_token, OWNER),
1
);

vm.expectEmit();
emit RegistryModuleOwnerCustom.AdministratorRegistered(s_token, OWNER);

s_registryModuleOwnerCustom.registerAccessControlDefaultAdmin(s_token);

assertEq(s_tokenAdminRegistry.getTokenConfig(s_token).pendingAdministrator, OWNER);
}

function test_registerAccessControlDefaultAdmin_Revert() public {
bytes32 defaultAdminRole = AccessController(s_token).DEFAULT_ADMIN_ROLE();

address wrongSender = makeAddr("Not_expected_owner");
vm.startPrank(wrongSender);

vm.expectRevert(
abi.encodeWithSelector(
RegistryModuleOwnerCustom.RequiredRoleNotFound.selector, wrongSender, defaultAdminRole, s_token
)
);

s_registryModuleOwnerCustom.registerAccessControlDefaultAdmin(s_token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {IGetCCIPAdmin} from "../interfaces/IGetCCIPAdmin.sol";
import {IOwner} from "../interfaces/IOwner.sol";
import {ITokenAdminRegistry} from "../interfaces/ITokenAdminRegistry.sol";

import {AccessControl} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/access/AccessControl.sol";

contract RegistryModuleOwnerCustom is ITypeAndVersion {
error CanOnlySelfRegister(address admin, address token);
error RequiredRoleNotFound(address msgSender, bytes32 role, address token);
error AddressZero();

event AdministratorRegistered(address indexed token, address indexed administrator);

string public constant override typeAndVersion = "RegistryModuleOwnerCustom 1.5.0";
string public constant override typeAndVersion = "RegistryModuleOwnerCustom 1.6.0";

// The TokenAdminRegistry contract
ITokenAdminRegistry internal immutable i_tokenAdminRegistry;
Expand All @@ -38,6 +41,20 @@ contract RegistryModuleOwnerCustom is ITypeAndVersion {
_registerAdmin(token, IOwner(token).owner());
}

/// @notice Registers the admin of the token using OZ's AccessControl DEFAULT_ADMIN_ROLE.
/// @param token The token to register the admin for.
/// @dev The caller must have the DEFAULT_ADMIN_ROLE as defined by the contract itself.
function registerAccessControlDefaultAdmin(
address token
) external {
bytes32 defaultAdminRole = AccessControl(token).DEFAULT_ADMIN_ROLE();
if (!AccessControl(token).hasRole(defaultAdminRole, msg.sender)) {
revert RequiredRoleNotFound(msg.sender, defaultAdminRole, token);
}

_registerAdmin(token, msg.sender);
}

/// @notice Registers the admin of the token to msg.sender given that the
/// admin is equal to msg.sender.
/// @param token The token to register the admin for.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/shared/access/AuthorizedCallers.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {OwnerIsCreator} from "./OwnerIsCreator.sol";
import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableSet.sol";
Expand Down
Loading

0 comments on commit 9350c6b

Please sign in to comment.