Skip to content

Commit f64b5b4

Browse files
authored
Change key from uint8 to bytes32 (#3)
1 parent be3f027 commit f64b5b4

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/QueryTypeStakerFactory.sol

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77

88
/// @title QueryTypeStakerFactory
99
/// @author [ScopeLift](https://scopelift.co)
10-
/// @notice This contract manages the creation of staking pools for different query types.
11-
/// Each query type can have one active staking pool, and only the contract owner can create new
12-
/// pools.
10+
/// @notice This contract manages the creation of staking pools for different query type bit fields.
11+
/// Each query type bit field can have one active staking pool, and only the contract owner can
12+
/// create new pools.
1313
contract QueryTypeStakerFactory is Ownable {
1414
/// @notice The token that will be used for staking.
1515
IERC20 public immutable STAKING_TOKEN;
1616

17-
/// @notice Maps query types to their corresponding staking pool addresses.
18-
mapping(uint8 queryType => address poolAddress) public queryTypePools;
17+
/// @notice Maps query type bit fields to their corresponding staking pool addresses.
18+
mapping(bytes32 queryType => address poolAddress) public queryTypePools;
1919

20-
/// @notice Emitted when a new staking pool is created for a query type.
21-
event CreateQueryTypeStakingPool(uint8 indexed queryType, address indexed poolAddress);
20+
/// @notice Emitted when a new staking pool is created for a query type bit field.
21+
event CreateQueryTypeStakingPool(bytes32 indexed queryType, address indexed poolAddress);
2222

23-
/// @notice Thrown when attempting to create a pool for a query type that already has one.
23+
/// @notice Thrown when attempting to create a pool for a query type bit field that exists.
2424
error QueryTypeStakerFactory__PoolExists();
2525

2626
/// @notice Thrown when an invalid (zero) token address is provided.
@@ -34,13 +34,13 @@ contract QueryTypeStakerFactory is Ownable {
3434
STAKING_TOKEN = IERC20(_stakingToken);
3535
}
3636

37-
/// @notice Creates a new staking pool for a specific query type.
38-
/// @param _queryType The type of query this pool will be associated with.
37+
/// @notice Creates a new staking pool for a specific query type bit field.
38+
/// @param _queryType The bit field representing the queries this pool will support.
3939
/// @param _poolOwner The address that will own the staking pool.
4040
/// @param _initialEntry The initial conversion table entry for the pool.
4141
/// @return _poolAddress The address of the newly created staking pool.
4242
/// @dev Only callable by the contract owner.
43-
function createStakingPool(uint8 _queryType, address _poolOwner, bytes32 _initialEntry)
43+
function createStakingPool(bytes32 _queryType, address _poolOwner, bytes32 _initialEntry)
4444
external
4545
returns (address _poolAddress)
4646
{

test/QueryTypeStakerFactory.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ contract QueryTypeStakerFactoryTest is Test {
1010
QueryTypeStakerFactory public factory;
1111
address public owner;
1212
address public stakingToken;
13-
uint8 public queryType;
13+
bytes32 public queryType;
1414

1515
function setUp() public virtual {
1616
owner = makeAddr("owner");
1717
stakingToken = makeAddr("stakingToken");
1818
vm.prank(owner);
1919
factory = new QueryTypeStakerFactory(owner, stakingToken);
20-
queryType = 1;
20+
queryType = bytes32(uint256(1));
2121
}
2222

2323
function _createPool() internal returns (address) {
@@ -45,7 +45,7 @@ contract Constructor is QueryTypeStakerFactoryTest {
4545

4646
contract CreateStakingPool is QueryTypeStakerFactoryTest {
4747
function testFuzz_CreatesNewStakingPoolWithArbitraryQueryType(
48-
uint8 _queryType,
48+
bytes32 _queryType,
4949
address _poolOwner,
5050
bytes32 _initialEntry
5151
) public {
@@ -59,7 +59,7 @@ contract CreateStakingPool is QueryTypeStakerFactoryTest {
5959
}
6060

6161
function testFuzz_EmitsCreateQueryTypeStakingPoolEventWithArbitraryQueryType(
62-
uint8 _queryType,
62+
bytes32 _queryType,
6363
address _poolOwner,
6464
bytes32 _initialEntry
6565
) public {
@@ -69,8 +69,8 @@ contract CreateStakingPool is QueryTypeStakerFactoryTest {
6969
address poolAddress = factory.createStakingPool(_queryType, _poolOwner, _initialEntry);
7070

7171
VmSafe.Log[] memory entries = vm.getRecordedLogs();
72-
assertEq(entries[2].topics[0], keccak256("CreateQueryTypeStakingPool(uint8,address)"));
73-
assertEq(entries[2].topics[1], bytes32(uint256(_queryType))); // queryType
72+
assertEq(entries[2].topics[0], keccak256("CreateQueryTypeStakingPool(bytes32,address)"));
73+
assertEq(entries[2].topics[1], _queryType); // queryType
7474
assertEq(entries[2].topics[2], bytes32(uint256(uint160(poolAddress)))); // poolAddress
7575
}
7676

@@ -88,7 +88,7 @@ contract CreateStakingPool is QueryTypeStakerFactoryTest {
8888
}
8989

9090
function testFuzz_RevertIf_PoolAlreadyExistsWithArbitraryQueryType(
91-
uint8 _queryType,
91+
bytes32 _queryType,
9292
address _poolOwner,
9393
bytes32 _initialEntry
9494
) public {

0 commit comments

Comments
 (0)