-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add componenttoken interface and script to calculate interfaceid
- Loading branch information
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
nest/script/helpers/CalculateComponentTokenInterfaceId.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"))) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters