Skip to content

Commit

Permalink
Merge branch 'main' into feat/101/redemptionevents
Browse files Browse the repository at this point in the history
  • Loading branch information
sirnicolaz authored Oct 26, 2023
2 parents bed9644 + 9b6a96d commit 0deefd6
Show file tree
Hide file tree
Showing 48 changed files with 862 additions and 119 deletions.
596 changes: 578 additions & 18 deletions .openzeppelin/unknown-9001.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ npx hardhat test
# Deploy to production
npx hardhat deploy --network evmos
```

# Audits

- [SolidProof](https://solidproof.io/)
- Tag: https://github.com/NeokingdomDAO/contracts/releases/tag/audit1
- Report: https://github.com/solidproof/projects/blob/main/2023/NeokingdomDAO/SmartContract_Audit_Solidproof_NeoKingdomDAO.pdf
- [LeastAuthority](https://leastauthority.com)
- Tag: https://github.com/NeokingdomDAO/contracts/releases/tag/audit2
- Report: https://leastauthority.com/blog/audits/neokingdom-dao-smart-contracts/
34 changes: 21 additions & 13 deletions contracts/GovernanceToken/GovernanceToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
Expand Down Expand Up @@ -46,6 +46,10 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
string memory name,
string memory symbol
) public initializer {
require(
address(roles) != address(0),
"GovernanceToken: 0x0 not allowed"
);
_initialize(name, symbol);
_setRoles(roles);
}
Expand Down Expand Up @@ -154,6 +158,15 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
uint256 amount
) public virtual onlyRole(Roles.RESOLUTION_ROLE) {
_mint(to, amount);

if (
_shareholderRegistry.isAtLeast(
_shareholderRegistry.CONTRIBUTOR_STATUS(),
to
)
) {
_redemptionController.afterMint(to, amount);
}
}

/**
Expand Down Expand Up @@ -292,16 +305,6 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
super._afterTokenTransfer(from, to, amount);
_voting.afterTokenTransfer(from, to, amount);

if (
from == address(0) &&
_shareholderRegistry.isAtLeast(
_shareholderRegistry.CONTRIBUTOR_STATUS(),
to
)
) {
_redemptionController.afterMint(to, amount);
}

// Invariants
require(
balanceOf(from) >= _vestingBalance[from],
Expand Down Expand Up @@ -342,7 +345,12 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
* @param amount Amount of external tokens to wrap.
*/
function _wrap(address from, uint amount) internal virtual {
tokenExternal.transferFrom(from, address(this), amount);
require(
tokenExternal.transferFrom(from, address(this), amount),
"GovernanceToken: transfer failed"
);
require(amount > 0, "GovernanceToken: attempt to wrap 0 tokens");

uint256 settlementTimestamp = block.timestamp + settlementPeriod;
depositedTokens[from].push(
DepositedTokens(amount, settlementTimestamp)
Expand All @@ -360,7 +368,7 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
DepositedTokens storage tokens = depositedTokens[from][i - 1];
if (block.timestamp >= tokens.settlementTimestamp) {
if (tokens.amount > 0) {
super._mint(from, tokens.amount);
ERC20Upgradeable._mint(from, tokens.amount);
tokens.amount = 0;
} else {
break;
Expand Down
8 changes: 5 additions & 3 deletions contracts/GovernanceToken/GovernanceTokenBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "../RedemptionController/IRedemptionController.sol";
Expand Down Expand Up @@ -69,7 +68,10 @@ abstract contract GovernanceTokenBase is ERC20Upgradeable, IGovernanceToken {
//}

function _unwrap(address from, address to, uint amount) internal virtual {
tokenExternal.transfer(to, amount);
require(
tokenExternal.transfer(to, amount),
"GovernanceToken: transfer failed"
);
super._burn(from, amount);
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/GovernanceToken/GovernanceTokenSnapshot.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/utils/Arrays.sol";
import "./IGovernanceToken.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/GovernanceToken/IGovernanceToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../extensions/ISnapshot.sol";
Expand Down
14 changes: 9 additions & 5 deletions contracts/InternalMarket/InternalMarket.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -23,13 +22,18 @@ contract InternalMarket is Initializable, HasRole, InternalMarketBase {
/**
* @dev Initializes the contract with the given roles and internal token.
* @param roles DAORoles instance containing custom access control roles.
* @param tokenInternal_ Reference to governance token.
* @param governanceToken Reference to governance token.
*/
function initialize(
DAORoles roles,
IGovernanceToken tokenInternal_
IGovernanceToken governanceToken
) public initializer {
_initialize(tokenInternal_, 7 days);
require(
address(roles) != address(0) &&
address(governanceToken) != address(0),
"InternalMarket: 0x0 not allowed"
);
_initialize(governanceToken, 7 days);
_setRoles(roles);
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/InternalMarket/InternalMarketBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
Expand All @@ -18,6 +17,7 @@ contract InternalMarketBase {
);

event OfferMatched(uint128 id, address from, address to, uint256 amount);
event Withdrawn(address from, address to, uint256 amount);

struct Offer {
uint256 expiredAt;
Expand Down Expand Up @@ -204,6 +204,8 @@ contract InternalMarketBase {
} else {
tokenInternal.unwrap(from, to, amount);
}

emit Withdrawn(from, to, amount);
}

function _burn(address from, uint256 amount) internal virtual {
Expand Down
3 changes: 1 addition & 2 deletions contracts/NeokingdomToken/INeokingdomToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/NeokingdomToken/NeokingdomToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/RedemptionController/IRedemptionController.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
Expand Down
7 changes: 5 additions & 2 deletions contracts/RedemptionController/RedemptionController.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./RedemptionControllerBase.sol";
Expand Down Expand Up @@ -36,6 +35,10 @@ contract RedemptionController is
* @param roles The addresses of DAORoles for this contract.
*/
function initialize(DAORoles roles) public initializer {
require(
address(roles) != address(0),
"RedemptionController: 0x0 not allowed"
);
_setRoles(roles);
_initialize();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "./IRedemptionController.sol";

Expand Down
30 changes: 8 additions & 22 deletions contracts/ResolutionManager/ResolutionManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { Roles } from "../extensions/Roles.sol";
Expand All @@ -26,6 +26,13 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
IGovernanceToken governanceToken,
IVoting voting
) public initializer {
require(
address(roles) != address(0) &&
address(shareholderRegistry) != address(0) &&
address(governanceToken) != address(0) &&
address(voting) != address(0),
"ResolutionManager: 0x0 not allowed"
);
_setRoles(roles);
_initialize(shareholderRegistry, governanceToken, voting);
}
Expand Down Expand Up @@ -167,13 +174,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
* @param resolutionId The id of the resolution to approve.
*/
function approveResolution(uint256 resolutionId) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can approve"
);
_approveResolution(resolutionId);
}

Expand All @@ -182,13 +182,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
* @param resolutionId The id of the resolution to reject.
*/
function rejectResolution(uint256 resolutionId) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can reject"
);
_rejectResolution(resolutionId);
}

Expand All @@ -209,13 +202,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
address[] memory executionTo,
bytes[] memory executionData
) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can update"
);
_updateResolution(
resolutionId,
dataURI,
Expand Down
5 changes: 2 additions & 3 deletions contracts/ResolutionManager/ResolutionManagerBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../ShareholderRegistry/IShareholderRegistry.sol";
import "../GovernanceToken/IGovernanceToken.sol";
Expand Down Expand Up @@ -267,7 +266,7 @@ abstract contract ResolutionManagerBase {
bool isNegative,
address[] memory executionTo,
bytes[] memory executionData
) internal virtual onlyPending(resolutionId) {
) internal virtual onlyPending(resolutionId) exists(resolutionId) {
emit ResolutionUpdated(msg.sender, resolutionId);

Resolution storage resolution = resolutions[resolutionId];
Expand Down
3 changes: 1 addition & 2 deletions contracts/ShareholderRegistry/IShareholderRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../extensions/ISnapshot.sol";

Expand Down
7 changes: 5 additions & 2 deletions contracts/ShareholderRegistry/ShareholderRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./ShareholderRegistrySnapshot.sol";
Expand Down Expand Up @@ -29,6 +28,10 @@ contract ShareholderRegistry is
string memory name,
string memory symbol
) public initializer {
require(
address(roles) != address(0),
"ShareholderRegistry: 0x0 not allowed"
);
_initialize(name, symbol);
_setRoles(roles);
}
Expand Down
16 changes: 10 additions & 6 deletions contracts/ShareholderRegistry/ShareholderRegistryBase.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// SPDX-License-Identifier: MIT

// TODO: update _statuses when account has no shares
// TODO: check who can move shares

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../Voting/IVoting.sol";

contract ShareholderRegistryBase is ERC20Upgradeable {
Expand Down Expand Up @@ -40,6 +37,10 @@ contract ShareholderRegistryBase is ERC20Upgradeable {
}

function _setStatus(bytes32 status, address account) internal virtual {
require(
!Address.isContract(account),
"ShareholderRegistry: cannot set status for smart contract"
);
require(
status == 0 || isAtLeast(SHAREHOLDER_STATUS, account),
"ShareholderRegistry: address has no tokens"
Expand Down Expand Up @@ -83,7 +84,10 @@ contract ShareholderRegistryBase is ERC20Upgradeable {
) internal view virtual returns (bool) {
return
balance > 0 &&
// shareholder < investor < contributor < managing board
// investor < contributor < managing board
// TODO: shareholder is currently equivalent to investor.
// We need to verify with the lawyer whether we can remove it
// completely from the smart contracts.
(status == INVESTOR_STATUS ||
status == SHAREHOLDER_STATUS ||
status == accountStatus ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Snapshot.sol)

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "./ShareholderRegistryBase.sol";
import "../extensions/Snapshottable.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/Voting/IVoting.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../extensions/ISnapshot.sol";

Expand Down
Loading

0 comments on commit 0deefd6

Please sign in to comment.