Skip to content

Commit

Permalink
add componenttoken interface and script to calculate interfaceid
Browse files Browse the repository at this point in the history
  • Loading branch information
ungaro committed Dec 9, 2024
1 parent 663410a commit 1ec88bc
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
82 changes: 82 additions & 0 deletions nest/script/helpers/CalculateComponentTokenInterfaceId.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IComponentToken } from "../../src/interfaces/IComponentToken.sol";
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";

contract CalculateComponentTokenInterfaceId is Script {

function run() public view {
bytes4 interfaceId = calculateInterfaceId();

// Log results
console2.log("\nIComponentToken Interface ID Calculation Results:");
console2.log("----------------------------------------");
console2.log("Interface ID: ", vm.toString(interfaceId));

// Log individual function selectors
logFunctionSelectors();
}

function calculateInterfaceId() public pure returns (bytes4) {
// Split calculations into groups to avoid stack too deep
bytes4 group1 = calculateGroup1();
bytes4 group2 = calculateGroup2();
bytes4 group3 = calculateGroup3();

return group1 ^ group2 ^ group3;
}

function calculateGroup1() public pure returns (bytes4) {
return bytes4(
keccak256("requestDeposit(uint256,address,address)") ^ keccak256("deposit(uint256,address,address)")
^ keccak256("requestRedeem(uint256,address,address)") ^ keccak256("redeem(uint256,address,address)")
);
}

function calculateGroup2() public pure returns (bytes4) {
return bytes4(
keccak256("asset()") ^ keccak256("totalAssets()") ^ keccak256("assetsOf(address)")
^ keccak256("convertToShares(uint256)") ^ keccak256("convertToAssets(uint256)")
);
}

function calculateGroup3() public pure returns (bytes4) {
return bytes4(
keccak256("pendingDepositRequest(uint256,address)") ^ keccak256("claimableDepositRequest(uint256,address)")
^ keccak256("pendingRedeemRequest(uint256,address)") ^ keccak256("claimableRedeemRequest(uint256,address)")
);
}

function logFunctionSelectors() public pure {
console2.log("\nFunction Selectors:");
console2.log("----------------------------------------");
console2.log(
"requestDeposit: ", vm.toString(bytes4(keccak256("requestDeposit(uint256,address,address)")))
);
console2.log("deposit: ", vm.toString(bytes4(keccak256("deposit(uint256,address,address)"))));
console2.log(
"requestRedeem: ", vm.toString(bytes4(keccak256("requestRedeem(uint256,address,address)")))
);
console2.log("redeem: ", vm.toString(bytes4(keccak256("redeem(uint256,address,address)"))));
console2.log("asset: ", vm.toString(bytes4(keccak256("asset()"))));
console2.log("totalAssets: ", vm.toString(bytes4(keccak256("totalAssets()"))));
console2.log("assetsOf: ", vm.toString(bytes4(keccak256("assetsOf(address)"))));
console2.log("convertToShares: ", vm.toString(bytes4(keccak256("convertToShares(uint256)"))));
console2.log("convertToAssets: ", vm.toString(bytes4(keccak256("convertToAssets(uint256)"))));
console2.log(
"pendingDepositRequest: ", vm.toString(bytes4(keccak256("pendingDepositRequest(uint256,address)")))
);
console2.log(
"claimableDepositRequest: ", vm.toString(bytes4(keccak256("claimableDepositRequest(uint256,address)")))
);
console2.log(
"pendingRedeemRequest: ", vm.toString(bytes4(keccak256("pendingRedeemRequest(uint256,address)")))
);
console2.log(
"claimableRedeemRequest: ", vm.toString(bytes4(keccak256("claimableRedeemRequest(uint256,address)")))
);
}

}
4 changes: 3 additions & 1 deletion nest/src/ComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract contract ComponentToken is
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
/// @notice Base that is used to divide all price inputs in order to represent e.g. 1.000001 as 1000001e12
uint256 internal constant _BASE = 1e18;

// Events

/**
Expand Down Expand Up @@ -189,6 +189,8 @@ abstract contract ComponentToken is
ComponentTokenStorage storage $ = _getComponentTokenStorage();
return super.supportsInterface(interfaceId) || interfaceId == type(IERC20).interfaceId
|| interfaceId == type(IAccessControl).interfaceId || interfaceId == type(IERC7575).interfaceId
|| interfaceId == 0x1816b2a2 // IComponentToken interface ID - Calculated in
// CalculateComponentTokenInterfaceId.s.sol
|| interfaceId == 0xe3bc4e65 || ($.asyncDeposit && interfaceId == 0xce3bbe50)
|| ($.asyncRedeem && interfaceId == 0x620ee8e4);
}
Expand Down

0 comments on commit 1ec88bc

Please sign in to comment.