Skip to content

Commit

Permalink
Migrate Truffle test to hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Jul 25, 2024
1 parent 21e6d64 commit fa23b90
Show file tree
Hide file tree
Showing 69 changed files with 1,675 additions and 2,147 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ CMTA providers further documentation describing the CMTAT framework in a platfor
- [CMTA - A comparison of different security token standards](https://cmta.ch/news-articles/a-comparison-of-different-security-token-standards)
- [Taurus - Security Token Standards: A Closer Look at CMTAT](https://www.taurushq.com/blog/security-token-standards-a-closer-look-at-cmtat/)
- [Taurus - Equity Tokenization: How to Pay Dividend On-Chain Using CMTAT](https://www.taurushq.com/blog/equity-tokenization-how-to-pay-dividend-on-chain-using-cmtat/)
- [Taurus - Token Transfer Management: How to Apply Restrictions with CMTAT and ERC-1404](https://www.taurushq.com/blog/token-transfer-management-how-to-apply-restrictions-with-cmtat-and-erc-1404/)

## Others implementations
Two versions are available for the blockchain [Tezos](https://tezos.com)
Expand Down
11 changes: 11 additions & 0 deletions contracts/interfaces/draft-IERC1643.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.20;

/// @title IERC1643 Document Management
/// (part of the ERC1400 Security Token Standards)
interface IERC1643 {
// Document Management
function getDocument(bytes32 _name) external view returns (string memory , bytes32, uint256);
function getAllDocuments() external view returns (bytes32[] memory);
}
5 changes: 0 additions & 5 deletions contracts/modules/internal/ERC20SnapshotModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ abstract contract ERC20SnapshotModuleInternal is ICMTATSnapshot, SnapshotModuleB
ownerBalances = new uint256[][](times.length);
totalSupply = new uint256[](times.length);
for(uint256 iT = 0; iT < times.length; ++iT){
/*ownerBalances[iT] = new uint256[](addresses.length);
for(uint256 jA = 0; jA < addresses.length; ++jA){
ownerBalances[iT][jA] = snapshotBalanceOf(times[iT], addresses[jA]);
}
totalSupply[iT] = snapshotTotalSupply(times[iT]);*/
(ownerBalances[iT], totalSupply[iT]) = snapshotInfoBatch(times[iT],addresses);
}
}
Expand Down
47 changes: 20 additions & 27 deletions contracts/modules/internal/base/SnapshotModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ abstract contract SnapshotModuleBase is Initializable {
*/
function _scheduleSnapshot(uint256 time) internal {
// Check the time firstly to avoid an useless read of storage
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast(
time,
block.timestamp
);
}
_checkTimeInThePast(time);

if (_scheduledSnapshots.length > 0) {
// We check the last snapshot on the list
Expand All @@ -143,16 +138,25 @@ abstract contract SnapshotModuleBase is Initializable {
emit SnapshotSchedule(0, time);
}

function _checkTimeInThePast(uint256 time) internal view{
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast(
time,
block.timestamp
);
}
}
function _checkTimeSnapshotAlreadyDone(uint256 time) internal view{
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone();
}
}

/**
* @dev schedule a snapshot at the specified time
*/
function _scheduleSnapshotNotOptimized(uint256 time) internal {
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast(
time,
block.timestamp
);
}
_checkTimeInThePast(time);
(bool isFound, uint256 index) = _findScheduledSnapshotIndex(time);
// Perfect match
if (isFound) {
Expand Down Expand Up @@ -181,15 +185,8 @@ abstract contract SnapshotModuleBase is Initializable {
*/
function _rescheduleSnapshot(uint256 oldTime, uint256 newTime) internal {
// Check the time firstly to avoid an useless read of storage
if (oldTime <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone();
}
if (newTime <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotScheduledInThePast(
newTime,
block.timestamp
);
}
_checkTimeSnapshotAlreadyDone(oldTime);
_checkTimeInThePast(newTime);
if (_scheduledSnapshots.length == 0) {
revert Errors.CMTAT_SnapshotModule_NoSnapshotScheduled();
}
Expand Down Expand Up @@ -227,9 +224,7 @@ abstract contract SnapshotModuleBase is Initializable {
*/
function _unscheduleLastSnapshot(uint256 time) internal {
// Check the time firstly to avoid an useless read of storage
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone();
}
_checkTimeSnapshotAlreadyDone(time);
if (_scheduledSnapshots.length == 0) {
revert Errors.CMTAT_SnapshotModule_NoSnapshotScheduled();
}
Expand All @@ -248,9 +243,7 @@ abstract contract SnapshotModuleBase is Initializable {
* - Reduce the array size by deleting the last snapshot
*/
function _unscheduleSnapshotNotOptimized(uint256 time) internal {
if (time <= block.timestamp) {
revert Errors.CMTAT_SnapshotModule_SnapshotAlreadyDone();
}
_checkTimeSnapshotAlreadyDone(time);
(bool isFound, uint256 index) = _findScheduledSnapshotIndex(time);
if (!isFound) {
revert Errors.CMTAT_SnapshotModule_SnapshotNotFound();
Expand Down
24 changes: 14 additions & 10 deletions contracts/modules/wrapper/core/BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pragma solidity ^0.8.20;
// required OZ imports here
import "../../security/AuthorizationModule.sol";
import "../../../libraries/Errors.sol";

abstract contract BaseModule is AuthorizationModule {
import "../../../interfaces/draft-IERC1643.sol";
abstract contract BaseModule is IERC1643, AuthorizationModule {
/**
* @notice
* Get the current version of the smart contract
Expand All @@ -27,6 +27,7 @@ abstract contract BaseModule is AuthorizationModule {
string public information;
// additional attribute to store information as an uint256
uint256 public flag;
IERC1643 DocumentEngine;



Expand Down Expand Up @@ -80,15 +81,18 @@ abstract contract BaseModule is AuthorizationModule {
emit Information(information_, information_);
}

/**
* @notice The call will be reverted if the new value of flag is the same as the current one
*/
function setFlag(uint256 flag_) public onlyRole(DEFAULT_ADMIN_ROLE) {
if (flag == flag_) {
revert Errors.CMTAT_BaseModule_SameValue();
function getDocument(bytes32 _name) public view returns (string memory, bytes32, uint256){
if(address(DocumentEngine) != address(0)){
return DocumentEngine.getDocument( _name);
} else{
return ("",0x0, 0);
}
}

function getAllDocuments() public view returns (bytes32[] memory documents){
if(address(DocumentEngine) != address(0)){
documents = DocumentEngine.getAllDocuments();
}
flag = flag_;
emit Flag(flag_);
}

uint256[50] private __gap;
Expand Down
3 changes: 2 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/** @type import('hardhat/config').HardhatUserConfig */
require('@nomiclabs/hardhat-truffle5')
//require('@nomiclabs/hardhat-truffle5')
require('@openzeppelin/hardhat-upgrades')
require("hardhat-gas-reporter");
require("solidity-coverage")
require('solidity-docgen')
require("hardhat-contract-sizer");
require("@nomicfoundation/hardhat-chai-matchers")
module.exports = {
solidity: {
version: '0.8.24',
Expand Down
Loading

0 comments on commit fa23b90

Please sign in to comment.