From ee718a0b8c566a647fa25c5f9921eee68c821907 Mon Sep 17 00:00:00 2001 From: mejango Date: Thu, 24 Oct 2024 18:45:21 -0300 Subject: [PATCH 1/3] added projectId check to IJBToken --- src/JBERC20.sol | 13 ++++++++++++- src/JBTokens.sol | 4 ++++ src/interfaces/IJBToken.sol | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/JBERC20.sol b/src/JBERC20.sol index b697cb39..11527279 100644 --- a/src/JBERC20.sol +++ b/src/JBERC20.sol @@ -14,6 +14,14 @@ import {IJBToken} from "./interfaces/IJBToken.sol"; /// `JBController.deployERC20For(...)` or `JBController.setTokenFor(...)`, credits can be redeemed to claim tokens. /// @dev `JBController.deployERC20For(...)` deploys a `JBERC20` contract and sets it as the project's token. contract JBERC20 is ERC20Votes, ERC20Permit, Ownable, IJBToken { + + //*********************************************************************// + // ---------------- public immutable stored properties --------------- // + //*********************************************************************// + + /// @notice The project ID. + uint256 public immutable override projectId; + //*********************************************************************// // --------------------- internal stored properties ------------------ // //*********************************************************************// @@ -92,14 +100,17 @@ contract JBERC20 is ERC20Votes, ERC20Permit, Ownable, IJBToken { /// @notice Initializes the token. /// @param name_ The token's name. /// @param symbol_ The token's symbol. + /// @param projectId_ The project ID. /// @param owner The token contract's owner. - function initialize(string memory name_, string memory symbol_, address owner) public override { + function initialize(string memory name_, string memory symbol_, uint256 projectId_, address owner) public override { // Prevent re-initialization by reverting if a name is already set or if the provided name is empty. if (bytes(_name).length != 0 || bytes(name_).length == 0) revert(); _name = name_; _symbol = symbol_; + projectId = projectId_; + // Transfer ownership to the owner. _transferOwnership(owner); } diff --git a/src/JBTokens.sol b/src/JBTokens.sol index b451c913..d3836a5d 100644 --- a/src/JBTokens.sol +++ b/src/JBTokens.sol @@ -26,6 +26,7 @@ contract JBTokens is JBControlled, IJBTokens { error JBTokens_InsufficientTokensToBurn(uint256 count, uint256 tokenBalance); error JBTokens_OverflowAlert(uint256 value, uint256 limit); error JBTokens_ProjectAlreadyHasToken(IJBToken token); + error JBTokens_TokenProjectIdMismatch(uint256 tokenProjectId, uint256 projectId); error JBTokens_RecipientZeroAddress(); error JBTokens_TokenAlreadyBeingUsed(uint256 projectId); error JBTokens_TokenNotFound(); @@ -317,6 +318,9 @@ contract JBTokens is JBControlled, IJBTokens { // Can't set to the zero address. if (token == IJBToken(address(0))) revert JBTokens_EmptyToken(); + // The token's project ID must match the project ID. + if (token.projectId() != projectId) revert JBTokens_TokenProjectIdMismatch(token.projectId(), projectId); + // Can't set a token if the project is already associated with another token. if (tokenOf[projectId] != IJBToken(address(0))) revert JBTokens_ProjectAlreadyHasToken(tokenOf[projectId]); diff --git a/src/interfaces/IJBToken.sol b/src/interfaces/IJBToken.sol index ce94f9f0..641813fb 100644 --- a/src/interfaces/IJBToken.sol +++ b/src/interfaces/IJBToken.sol @@ -5,6 +5,7 @@ interface IJBToken { function balanceOf(address account) external view returns (uint256); function decimals() external view returns (uint8); function totalSupply() external view returns (uint256); + function projectId() external view returns (uint256); function initialize(string memory name, string memory symbol, address owner) external; function burn(address account, uint256 amount) external; From ba6fa1cd6b669fbeaf735aacebf96ee17641320c Mon Sep 17 00:00:00 2001 From: mejango Date: Thu, 24 Oct 2024 18:45:31 -0300 Subject: [PATCH 2/3] fmt --- src/JBERC20.sol | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/JBERC20.sol b/src/JBERC20.sol index 11527279..9090cfa0 100644 --- a/src/JBERC20.sol +++ b/src/JBERC20.sol @@ -14,7 +14,6 @@ import {IJBToken} from "./interfaces/IJBToken.sol"; /// `JBController.deployERC20For(...)` or `JBController.setTokenFor(...)`, credits can be redeemed to claim tokens. /// @dev `JBController.deployERC20For(...)` deploys a `JBERC20` contract and sets it as the project's token. contract JBERC20 is ERC20Votes, ERC20Permit, Ownable, IJBToken { - //*********************************************************************// // ---------------- public immutable stored properties --------------- // //*********************************************************************// @@ -102,7 +101,15 @@ contract JBERC20 is ERC20Votes, ERC20Permit, Ownable, IJBToken { /// @param symbol_ The token's symbol. /// @param projectId_ The project ID. /// @param owner The token contract's owner. - function initialize(string memory name_, string memory symbol_, uint256 projectId_, address owner) public override { + function initialize( + string memory name_, + string memory symbol_, + uint256 projectId_, + address owner + ) + public + override + { // Prevent re-initialization by reverting if a name is already set or if the provided name is empty. if (bytes(_name).length != 0 || bytes(name_).length == 0) revert(); From f73ab634ca3d201266cbf350e300b5f58864b853 Mon Sep 17 00:00:00 2001 From: mejango Date: Thu, 24 Oct 2024 18:46:08 -0300 Subject: [PATCH 3/3] order --- src/interfaces/IJBToken.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/IJBToken.sol b/src/interfaces/IJBToken.sol index 641813fb..00c2acb5 100644 --- a/src/interfaces/IJBToken.sol +++ b/src/interfaces/IJBToken.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.0; interface IJBToken { function balanceOf(address account) external view returns (uint256); function decimals() external view returns (uint8); - function totalSupply() external view returns (uint256); function projectId() external view returns (uint256); + function totalSupply() external view returns (uint256); function initialize(string memory name, string memory symbol, address owner) external; function burn(address account, uint256 amount) external;