I'm exploring Gnosis conditional tokens (which are adapted ERC1155
). The _mint
method in ERC1155
requires an id
that is uint
. Gnosis has a method called getPositionId
which converts a
keccak256 hash into a uint
:
/**
* @dev Constructs a position ID from a collateral token and an outcome collection
* @param _collateralToken: ERC20 token collateralizing the position
* @param _collectionId: ID of the outcome collection associated with this position
*/
function getPositionId(IERC20 _collateralToken, bytes32 _collectionId) internal pure returns (uint) {
return uint(keccak256(abi.encodePacked(_collateralToken, _collectionId)));
}
The return value is used as the id
in the _mint
function. However, the value is massive (BigNumber
) and causes overflow issues while working with hardhat tests.
For example, let:
_collateralToken
=0x2Dd78Fd9B8F40659Af32eF98555B8b31bC97A351
_collectionId
=0x6f6f41ff811f45c6dfe727fcb2a278f07323fb85ec753bece2f9a690cca7a01d
Then packing these into a keccak256 and then converting to a uint
generates the return value of getPositionId
:
74229324384859666491956367114251131107901747002219700387957564294760735619703
Now if I wanted to check the balanceOf
an address
, I need to pass in two parameters:
balanceOf(address account, uint256 id)
This requires me to convert the positionId
into a uint
using positionId.toNumber()
but then
the overflow error occurs!
Is there a trivial solution I'm overlooking or should I refactor the getPositionId
into something more simplistic?