solidity
function getId(
ERC20 stakingToken,
ERC20 transferToken,
address caller
) public pure override returns (bytes32) {
return keccak256(abi.encodePacked(stakingToken, transferToken, caller));
}
Hi, im trying to reduce this hashing function here to a simpler function that returns a unique string according to these 3 arguments.
I was thinking of something along the lines of casting each one of the incoming arguments to a string and concatenate them so an example will be - "SushiEthWilliam" (obviously their corresponding addresses).
The problem with my idea is that i cannot seem to cast these instances to strings easily. Any idea how i can do that or for another way to achieve the same effect (unique string generated by a triplet order is important!). bare in mind that i want a byte32 as the return value
Dec 8, 2021, 5:21 PM
if this is for a specific list of token addresses, then you could have an address->string mapping to look up from based on the ERC20 addresses, and use that
otherwise, you wont be able to fit all three concatenated addresses into a single bytes32...hence the hash function
Dec 8, 2021, 5:50 PM
I investigated a little and read that address is consist of 20 bytes, so concatenate all 3 is impossible to 32 bytes
My problem is that this isnt a closed list. I want to allow any erc20 token
Dec 8, 2021, 10:20 PM
yeah so the hash of them is perfect for that
Dec 8, 2021, 11:01 PM