Skip to content

Commit

Permalink
chore: sync latest changes
Browse files Browse the repository at this point in the history
The repository is updated with the latest changes from the main
repository. Note that not all contract state here is necessary live.
  • Loading branch information
marceljay committed Apr 24, 2022
1 parent 2da866f commit da10e1f
Show file tree
Hide file tree
Showing 29 changed files with 872 additions and 544 deletions.
137 changes: 0 additions & 137 deletions contracts/CarbonOffsetBadges.sol

This file was deleted.

28 changes: 0 additions & 28 deletions contracts/CarbonOffsetBadgesStorage.sol

This file was deleted.

29 changes: 21 additions & 8 deletions contracts/CarbonOffsetBatches.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

import './IToucanContractRegistry.sol';
import './ICarbonOffsetBatches.sol';
import './interfaces/IToucanContractRegistry.sol';
import './interfaces/ICarbonOffsetBatches.sol';
import './ToucanCarbonOffsetsFactory.sol';
import './CarbonOffsetBatchesStorage.sol';
import './libraries/ProjectVintageUtils.sol';
Expand All @@ -34,6 +34,16 @@ contract CarbonOffsetBatches is
{
using AddressUpgradeable for address;

// ----------------------------------------
// Constants
// ----------------------------------------

bytes32 public constant VERIFIER_ROLE = keccak256('VERIFIER_ROLE');

// ----------------------------------------
// Events
// ----------------------------------------

event BatchMinted(address sender, uint256 tokenId);
event BatchUpdated(uint256 tokenId, string serialNumber, uint256 quantity);
event BatchLinkedWithVintage(
Expand All @@ -48,8 +58,6 @@ contract CarbonOffsetBatches is
);
event BatchStatusUpdate(uint256 tokenId, RetirementStatus status);

bytes32 public constant VERIFIER_ROLE = keccak256('VERIFIER_ROLE');

// ----------------------------------------
// Upgradable related functions
// ----------------------------------------
Expand All @@ -68,7 +76,7 @@ contract CarbonOffsetBatches is
__Ownable_init_unchained();
__Pausable_init_unchained();
contractRegistry = _contractRegistry;
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function _authorizeUpgrade(address newImplementation)
Expand Down Expand Up @@ -266,8 +274,12 @@ contract CarbonOffsetBatches is
/// @dev To be updated by NFT owner after serial number has been provided
/// @param to The address the NFT should be minted to. This should be the user.
function mintEmptyBatch(address to) external virtual whenNotPaused {
batchTokenCounter++;
uint256 newItemId = batchTokenCounter;
unchecked {
++newItemId;
}
batchTokenCounter = newItemId;

_safeMint(to, newItemId);
nftList[newItemId].status = RetirementStatus.Pending;

Expand All @@ -291,8 +303,9 @@ contract CarbonOffsetBatches is
hasRole(VERIFIER_ROLE, _msgSender()),
'Error: update only by owner or verifier'
);
RetirementStatus status = nftList[tokenId].status;
require(
nftList[tokenId].status != RetirementStatus.Confirmed,
status != RetirementStatus.Confirmed,
'Error: cannot change data after confirmation'
);
require(
Expand All @@ -309,7 +322,7 @@ contract CarbonOffsetBatches is
URIs[uri] = true;
}

if (nftList[tokenId].status == RetirementStatus.Rejected) {
if (status == RetirementStatus.Rejected) {
updateStatus(tokenId, RetirementStatus.Pending);
}

Expand Down
27 changes: 21 additions & 6 deletions contracts/CarbonProjectVintages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

import './IToucanContractRegistry.sol';
import './ICarbonProjectVintages.sol';
import './interfaces/IToucanContractRegistry.sol';
import './interfaces/ICarbonProjectVintages.sol';
import './CarbonProjectVintagesStorage.sol';
import './CarbonProjects.sol';
import './libraries/ProjectUtils.sol';
import './libraries/Modifiers.sol';

Expand All @@ -32,6 +31,17 @@ contract CarbonProjectVintages is
Modifiers,
ProjectUtils
{
// ----------------------------------------
// Constants
// ----------------------------------------

/// @dev All roles related to Access Control
bytes32 public constant MANAGER_ROLE = keccak256('MANAGER_ROLE');

// ----------------------------------------
// Events
// ----------------------------------------

event ProjectVintageMinted(
address receiver,
uint256 tokenId,
Expand All @@ -54,7 +64,7 @@ contract CarbonProjectVintages is
__Ownable_init_unchained();
__Pausable_init_unchained();
/// @dev granting the deployer==owner the rights to grant other roles
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function _authorizeUpgrade(address newImplementation)
Expand Down Expand Up @@ -125,9 +135,13 @@ contract CarbonProjectVintages is
);

/// @dev Increase `projectVintageTokenCounter` and mark current Id as valid
projectVintageTokenCounter++;
totalSupply++;
uint256 newItemId = projectVintageTokenCounter;
unchecked {
++newItemId;
++totalSupply;
}
projectVintageTokenCounter = uint128(newItemId);

validProjectVintageIds[newItemId] = true;

_mint(to, newItemId);
Expand Down Expand Up @@ -211,6 +225,7 @@ contract CarbonProjectVintages is
external
view
virtual
override
returns (VintageData memory)
{
return (vintageData[tokenId]);
Expand Down
3 changes: 0 additions & 3 deletions contracts/CarbonProjectVintagesStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,4 @@ contract CarbonProjectVintagesStorage {
/// project/vintage; only a long serial number containing info which allows
/// that association.
mapping(uint256 => mapping(uint64 => uint256)) public pvToTokenId;

/// @dev All roles related to Access Control
bytes32 public constant MANAGER_ROLE = keccak256('MANAGER_ROLE');
}
38 changes: 20 additions & 18 deletions contracts/CarbonProjects.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

import './CarbonProjectsStorage.sol';
import './ICarbonProjects.sol';
import './interfaces/ICarbonProjects.sol';
import './libraries/Modifiers.sol';

/// @notice The CarbonProjects contract stores carbon project-specific data
Expand All @@ -31,6 +31,17 @@ contract CarbonProjects is
AccessControlUpgradeable,
UUPSUpgradeable
{
// ----------------------------------------
// Constants
// ----------------------------------------

/// @dev All roles related to Access Control
bytes32 public constant MANAGER_ROLE = keccak256('MANAGER_ROLE');

// ----------------------------------------
// Events
// ----------------------------------------

event ProjectMinted(address receiver, uint256 tokenId);
event ProjectUpdated(uint256 tokenId);
event ProjectIdUpdated(uint256 tokenId);
Expand All @@ -48,7 +59,7 @@ contract CarbonProjects is
__Ownable_init_unchained();
__Pausable_init_unchained();
/// @dev granting the deployer==owner the rights to grant other roles
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function _authorizeUpgrade(address newImplementation)
Expand Down Expand Up @@ -89,20 +100,6 @@ contract CarbonProjects is
contractRegistry = _address;
}

/// @notice Updates the controller, the entity in charge of the ProjectData
/// Questionable if needed if this stays ERC721, as this could be the NFT owner
function updateController(uint256 tokenId, address _controller)
external
virtual
whenNotPaused
{
require(
msg.sender == ownerOf(tokenId),
'Error: Caller is not the owner'
);
projectData[tokenId].controller = _controller;
}

/// @notice Adds a new carbon project along with attributes/data
/// @dev Projects can be added by data-managers
function addNewProject(
Expand All @@ -123,9 +120,13 @@ contract CarbonProjects is
require(projectIds[projectId] == false, 'Project already exists');
projectIds[projectId] = true;

projectTokenCounter++;
totalSupply++;
uint256 newItemId = projectTokenCounter;
unchecked {
++newItemId;
++totalSupply;
}
projectTokenCounter = uint128(newItemId);

validProjectTokenIds[newItemId] = true;

_mint(to, newItemId);
Expand Down Expand Up @@ -233,6 +234,7 @@ contract CarbonProjects is
external
view
virtual
override
returns (ProjectData memory)
{
return (projectData[tokenId]);
Expand Down
Loading

0 comments on commit da10e1f

Please sign in to comment.