diff --git a/contracts/JBToken.sol b/contracts/JBToken.sol index 59320f933..0e44bcb12 100644 --- a/contracts/JBToken.sol +++ b/contracts/JBToken.sol @@ -82,7 +82,7 @@ contract JBToken is ERC20Votes, Ownable, IJBToken { /// @param _amount The amount of tokens to mint, as a fixed point number with 18 decimals. function mint(uint256 _projectId, address _account, uint256 _amount) external override onlyOwner { // Can't mint for a wrong project. - if (projectId != 0 && _projectId != projectId) revert BAD_PROJECT(); + if (_projectId != projectId) revert BAD_PROJECT(); return _mint(_account, _amount); } @@ -94,7 +94,7 @@ contract JBToken is ERC20Votes, Ownable, IJBToken { /// @param _amount The amount of tokens to burn, as a fixed point number with 18 decimals. function burn(uint256 _projectId, address _account, uint256 _amount) external override onlyOwner { // Can't burn for a wrong project. - if (projectId != 0 && _projectId != projectId) revert BAD_PROJECT(); + if (_projectId != projectId) revert BAD_PROJECT(); return _burn(_account, _amount); } @@ -105,7 +105,7 @@ contract JBToken is ERC20Votes, Ownable, IJBToken { /// @param _amount The amount the `_spender` is allowed to spend. function approve(uint256 _projectId, address _spender, uint256 _amount) external override { // Can't approve for a wrong project. - if (projectId != 0 && _projectId != projectId) revert BAD_PROJECT(); + if (_projectId != projectId) revert BAD_PROJECT(); approve(_spender, _amount); } @@ -116,7 +116,7 @@ contract JBToken is ERC20Votes, Ownable, IJBToken { /// @param _amount The amount of the transfer, as a fixed point number with 18 decimals. function transfer(uint256 _projectId, address _to, uint256 _amount) external override { // Can't transfer for a wrong project. - if (projectId != 0 && _projectId != projectId) revert BAD_PROJECT(); + if (_projectId != projectId) revert BAD_PROJECT(); transfer(_to, _amount); } @@ -133,7 +133,7 @@ contract JBToken is ERC20Votes, Ownable, IJBToken { uint256 _amount ) external override { // Can't transfer for a wrong project. - if (projectId != 0 && _projectId != projectId) revert BAD_PROJECT(); + if (_projectId != projectId) revert BAD_PROJECT(); transferFrom(_from, _to, _amount); } diff --git a/contracts/JBTokenStore.sol b/contracts/JBTokenStore.sol index 7b0f40d9f..a16e447dc 100644 --- a/contracts/JBTokenStore.sol +++ b/contracts/JBTokenStore.sol @@ -56,6 +56,10 @@ contract JBTokenStore is JBControllerUtility, JBOperatable, IJBTokenStore { /// @custom:param _projectId The ID of the project to which the token belongs. mapping(uint256 => IJBToken) public override tokenOf; + /// @notice Each token's project. + /// @custom:param _token The address of the token to which the project belongs. + mapping(IJBToken => uint256) public override projectIdOf; + /// @notice The total supply of unclaimed tokens for each project. /// @custom:param _projectId The ID of the project to which the token belongs. mapping(uint256 => uint256) public override unclaimedTotalSupplyOf; @@ -161,6 +165,9 @@ contract JBTokenStore is JBControllerUtility, JBOperatable, IJBTokenStore { // Store the token contract. tokenOf[_projectId] = token; + // Store the project for the token. + projectIdOf[token] = _projectId; + emit Issue(_projectId, token, _name, _symbol, msg.sender); } @@ -176,15 +183,21 @@ contract JBTokenStore is JBControllerUtility, JBOperatable, IJBTokenStore { // Can't set to the zero address. if (_token == IJBToken(address(0))) revert EMPTY_TOKEN(); - // Can't set token if already set. + // Can't set token if the project is already associated with another token. if (tokenOf[_projectId] != IJBToken(address(0))) revert ALREADY_SET(); + // Can't set token if its already associated with another project. + if (projectIdOf[_token] != 0) revert ALREADY_SET(); + // Can't change to a token that doesn't use 18 decimals. if (_token.decimals() != 18) revert TOKENS_MUST_HAVE_18_DECIMALS(); // Store the new token. tokenOf[_projectId] = _token; + // Store the project for the token. + projectIdOf[_token] = _projectId; + emit Set(_projectId, _token, msg.sender); } diff --git a/contracts/interfaces/IJBTokenStore.sol b/contracts/interfaces/IJBTokenStore.sol index 11ffbe247..7e4071ffb 100644 --- a/contracts/interfaces/IJBTokenStore.sol +++ b/contracts/interfaces/IJBTokenStore.sol @@ -54,6 +54,8 @@ interface IJBTokenStore { function tokenOf(uint256 projectId) external view returns (IJBToken); + function projectIdOf(IJBToken token) external view returns (uint256); + function projects() external view returns (IJBProjects); function fundingCycleStore() external view returns (IJBFundingCycleStore);