Skip to content

Commit

Permalink
Merge pull request #4 from kargakis/upgrade-to-latest
Browse files Browse the repository at this point in the history
Bump to latest version
  • Loading branch information
0xmichalis authored Jun 22, 2022
2 parents da10e1f + a0cf2b5 commit cf3d9e5
Show file tree
Hide file tree
Showing 57 changed files with 2,879 additions and 258 deletions.
37 changes: 25 additions & 12 deletions contracts/CarbonOffsetBatches.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth
pragma solidity ^0.8.0;
pragma solidity >=0.8.4 <=0.8.9;

import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol';
Expand All @@ -21,6 +21,7 @@ import './libraries/Modifiers.sol';

/// @notice Also referred to as Batch-Contract (formerly BatchCollection)
/// Contract that tokenizes retired/cancelled CO2 credits into NFTs via a claims process
//slither-disable-next-line unprotected-upgrade
contract CarbonOffsetBatches is
ICarbonOffsetBatches,
ERC721EnumerableUpgradeable,
Expand Down Expand Up @@ -58,16 +59,25 @@ contract CarbonOffsetBatches is
);
event BatchStatusUpdate(uint256 tokenId, RetirementStatus status);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

// ----------------------------------------
// Upgradable related functions
// ----------------------------------------

/// @dev Returns the current version of the smart contract
function version() public pure returns (string memory) {
function version() external pure returns (string memory) {
return '1.2.0';
}

function initialize(address _contractRegistry) public virtual initializer {
function initialize(address _contractRegistry)
external
virtual
initializer
{
__Context_init_unchained();
__ERC721_init_unchained(
'Toucan Protocol: Carbon Offset Batches',
Expand All @@ -92,17 +102,17 @@ contract CarbonOffsetBatches is

/// @notice Emergency function to disable contract's core functionality
/// @dev wraps _pause(), only Admin
function pause() public virtual onlyBy(contractRegistry, owner()) {
function pause() external virtual onlyBy(contractRegistry, owner()) {
_pause();
}

/// @dev unpause the system, wraps _unpause(), only Admin
function unpause() public virtual onlyBy(contractRegistry, owner()) {
function unpause() external virtual onlyBy(contractRegistry, owner()) {
_unpause();
}

function setToucanContractRegistry(address _address)
public
external
virtual
onlyOwner
{
Expand Down Expand Up @@ -175,7 +185,7 @@ contract CarbonOffsetBatches is

/// @notice Function to reject Batch-NFTs, including a reason to be displayed to the user.
function rejectWithComment(uint256 tokenId, string memory comment)
public
external
virtual
onlyVerifier
whenNotPaused
Expand All @@ -187,7 +197,7 @@ contract CarbonOffsetBatches is
/// @dev admin function to reject a previously approved batch
/// Requires that the Batch-NFT has not been fractionalized yet
function rejectApprovedWithComment(uint256 tokenId, string memory comment)
public
external
virtual
onlyOwner
whenNotPaused
Expand Down Expand Up @@ -238,7 +248,7 @@ contract CarbonOffsetBatches is
function confirmRetirementWithVintage(
uint256 tokenId,
uint256 projectVintageTokenId
) public virtual onlyVerifier whenNotPaused {
) external virtual onlyVerifier whenNotPaused {
require(
nftList[tokenId].status != RetirementStatus.Confirmed,
'Batch retirement is already confirmed'
Expand All @@ -261,7 +271,10 @@ contract CarbonOffsetBatches is
/// owner (deployer), in practice that is a multi-sig even before upgrade,
/// and unsetting a bunch of serials via multi-sig is not practical.
/// So instead we allow the verifiers to do it.
function unsetSerialNumber(string memory serialNumber) public onlyVerifier {
function unsetSerialNumber(string memory serialNumber)
external
onlyVerifier
{
serialNumberApproved[serialNumber] = false;
}

Expand Down Expand Up @@ -297,7 +310,7 @@ contract CarbonOffsetBatches is
string memory serialNumber,
uint256 quantity,
string memory uri
) public virtual whenNotPaused {
) external virtual whenNotPaused {
require(
ownerOf(tokenId) == _msgSender() ||
hasRole(VERIFIER_ROLE, _msgSender()),
Expand Down Expand Up @@ -391,7 +404,7 @@ contract CarbonOffsetBatches is
/// gas reasons:
/// https://docs.soliditylang.org/en/latest/contracts.html#visibility-and-getters
function getComments(uint256 tokenId)
public
external
view
virtual
returns (string[] memory, address[] memory)
Expand Down
5 changes: 4 additions & 1 deletion contracts/CarbonOffsetBatchesStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
//
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;
pragma solidity >=0.8.4 <=0.8.14;

import './CarbonOffsetBatchesTypes.sol';

/// @dev Separate storage contract to improve upgrade safety
contract CarbonOffsetBatchesStorage {
//slither-disable-next-line constable-states
uint256 public batchTokenCounter;
/// @custom:oz-upgrades-renamed-from serialNumberExist
mapping(string => bool) public serialNumberApproved;
mapping(string => bool) public URIs;
mapping(address => bool) public verifiers; // has been removed, but must stay here because of storage layout

//slither-disable-next-line constable-states
string public baseURI;
//slither-disable-next-line constable-states
address public contractRegistry;

struct NFTData {
Expand Down
2 changes: 1 addition & 1 deletion contracts/CarbonOffsetBatchesTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth

pragma solidity >=0.8.4 <0.9.0;
pragma solidity >=0.8.4 <=0.8.14;

enum RetirementStatus {
Pending, // 0
Expand Down
2 changes: 1 addition & 1 deletion contracts/CarbonProjectTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth

pragma solidity >=0.8.4 <0.9.0;
pragma solidity >=0.8.4 <=0.8.14;

/// @dev CarbonProject related data and attributes
struct ProjectData {
Expand Down
2 changes: 1 addition & 1 deletion contracts/CarbonProjectVintageTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth

pragma solidity >=0.8.4 <0.9.0;
pragma solidity >=0.8.4 <=0.8.14;

struct VintageData {
/// @dev A human-readable string which differentiates this from other vintages in
Expand Down
91 changes: 33 additions & 58 deletions contracts/CarbonProjectVintages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth
pragma solidity ^0.8.0;
pragma solidity >=0.8.4 <=0.8.14;
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
Expand Down Expand Up @@ -35,6 +35,8 @@ contract CarbonProjectVintages is
// Constants
// ----------------------------------------

string public constant VERSION = '1.1.0';

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

Expand All @@ -55,7 +57,7 @@ contract CarbonProjectVintages is
// Upgradable related functions
// ----------------------------------------

function initialize() public virtual initializer {
function initialize() external virtual initializer {
__Context_init_unchained();
__ERC721_init_unchained(
'Toucan Protocol: Carbon Project Vintages',
Expand Down Expand Up @@ -89,17 +91,17 @@ contract CarbonProjectVintages is

/// @notice Emergency function to disable contract's core functionality
/// @dev wraps _pause(), only Admin
function pause() public virtual onlyBy(contractRegistry, owner()) {
function pause() external virtual onlyBy(contractRegistry, owner()) {
_pause();
}

/// @dev unpause the system, wraps _unpause(), only Admin
function unpause() public virtual onlyBy(contractRegistry, owner()) {
function unpause() external virtual onlyBy(contractRegistry, owner()) {
_unpause();
}

function setToucanContractRegistry(address _address)
public
external
virtual
onlyOwner
{
Expand All @@ -108,29 +110,24 @@ contract CarbonProjectVintages is

/// @notice Adds a new carbon project-vintage along with attributes/data
/// @dev vintages can be added by data-managers
function addNewVintage(
address to,
uint256 projectTokenId,
string memory name,
uint64 startTime,
uint64 endTime,
uint64 totalVintageQuantity,
bool isCorsiaCompliant,
bool isCCPcompliant,
string memory coBenefits,
string memory correspAdjustment,
string memory additionalCertification,
string memory uri
) external virtual override onlyManagers whenNotPaused returns (uint256) {
checkProjectTokenExists(contractRegistry, projectTokenId);
function addNewVintage(address to, VintageData memory _vintageData)
external
virtual
override
onlyManagers
whenNotPaused
returns (uint256)
{
checkProjectTokenExists(contractRegistry, _vintageData.projectTokenId);

require(
pvToTokenId[projectTokenId][startTime] == 0,
pvToTokenId[_vintageData.projectTokenId][_vintageData.startTime] ==
0,
'Error: vintage already added'
);

require(
startTime < endTime,
_vintageData.startTime < _vintageData.endTime,
'Error: vintage startTime must be less than endTime'
);

Expand All @@ -146,21 +143,16 @@ contract CarbonProjectVintages is

_mint(to, newItemId);

vintageData[newItemId].name = name;
vintageData[newItemId].startTime = startTime;
vintageData[newItemId].endTime = endTime;
vintageData[newItemId].projectTokenId = projectTokenId;
vintageData[newItemId].totalVintageQuantity = totalVintageQuantity;
vintageData[newItemId].isCorsiaCompliant = isCorsiaCompliant;
vintageData[newItemId].isCCPcompliant = isCCPcompliant;
vintageData[newItemId].coBenefits = coBenefits;
vintageData[newItemId].correspAdjustment = correspAdjustment;
vintageData[newItemId]
.additionalCertification = additionalCertification;
vintageData[newItemId].uri = uri;

emit ProjectVintageMinted(to, newItemId, projectTokenId, startTime);
pvToTokenId[projectTokenId][startTime] = newItemId;
vintageData[newItemId] = _vintageData;
emit ProjectVintageMinted(
to,
newItemId,
_vintageData.projectTokenId,
_vintageData.startTime
);
pvToTokenId[_vintageData.projectTokenId][
_vintageData.startTime
] = newItemId;

return newItemId;
}
Expand All @@ -182,29 +174,12 @@ contract CarbonProjectVintages is
/// except the sensitive `projectId`
function updateProjectVintage(
uint256 tokenId,
// uint256 projectTokenId, // @dev commented out because very sensitive data, better via separate function
string memory name,
uint64 startTime,
uint64 endTime,
uint64 totalVintageQuantity,
bool isCorsiaCompliant,
bool isCCPcompliant,
string memory coBenefits,
string memory correspAdjustment,
string memory additionalCertification,
string memory uri
VintageData memory _vintageData
) external virtual onlyManagers whenNotPaused {
require(_exists(tokenId), 'Project not yet minted');
vintageData[tokenId].name = name;
vintageData[tokenId].startTime = startTime;
vintageData[tokenId].endTime = endTime;
vintageData[tokenId].totalVintageQuantity = totalVintageQuantity;
vintageData[tokenId].isCorsiaCompliant = isCorsiaCompliant;
vintageData[tokenId].isCCPcompliant = isCCPcompliant;
vintageData[tokenId].coBenefits = coBenefits;
vintageData[tokenId].correspAdjustment = correspAdjustment;
vintageData[tokenId].additionalCertification = additionalCertification;
vintageData[tokenId].uri = uri;
// @dev very sensitive data, better update via separate function
_vintageData.projectTokenId = vintageData[tokenId].projectTokenId;
vintageData[tokenId] = _vintageData;

emit ProjectVintageUpdated(tokenId);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/CarbonProjectVintagesStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth

// Storage contract for CarbonProjects
pragma solidity >=0.8.4 <0.9.0;
pragma solidity >=0.8.4 <=0.8.14;

import './CarbonProjectVintageTypes.sol';

Expand Down
Loading

0 comments on commit cf3d9e5

Please sign in to comment.