Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added means for finding the project from a token #61

Open
wants to merge 2 commits into
base: feature/jbtokenstore-claimFor-param
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions contracts/JBToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
15 changes: 14 additions & 1 deletion contracts/JBTokenStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IJBTokenStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down