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

Optimisations, CI workflow, & deploy script #190

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PRIVATE_KEY=""

MAINNET_NODE=""
GOERLI_NODE=""

ETHERSCAN_API_KEY=""

ADMIN_ADDRESS=""
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Truffle CI

on:
push:
branches: [dev, master, main]
pull_request:
branches: [dev, master, main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup NodeJS 16
uses: actions/setup-node@v2
with:
node-version: 16.17.0

- name: Show NodeJS version
run: npm --version

- name: Checkout submodules
run: git submodule update --init --recursive

- name: Install Truffle
run: npm install -g truffle

- name: Install Project Dependencies
run: npm install

- name: Run Truffle Test
run: npm t
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ artifacts
cache
#manticore
mcore_*
#secrets
.env
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.17.0
29 changes: 29 additions & 0 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.17;

library Errors {
error InvalidTransfer(address from, address to, uint256 amount);
error SnapshotScheduledInThePast(uint256 time, uint256 timestamp);
error SnapshotTimestampBeforeLastSnapshot(
uint256 time,
uint256 lastSnapshotTimestamp
);
error SnapshotTimestampAfterNextSnapshot(
uint256 time,
uint256 nextSnapshotTimestamp
);
error SnapshotTimestampBeforePreviousSnapshot(
uint256 time,
uint256 previousSnapshotTimestamp
);
error SnapshotAlreadyExists();
error SnapshotAlreadyDone();
error SnapshotNotScheduled();
error SnapshotNotFound();
error SnapshotNeverScheduled();
error AddressZeroNotAllowed();
error DirectCallToImplementation();
error WrongAllowance(uint256 allowance, uint256 currentAllowance);
error SameValue();
}
10 changes: 8 additions & 2 deletions contracts/mocks/RuleEngine/RuleEngineMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract RuleEngineMock is IRuleEngine {
uint256 _amount
) public view override returns (uint8) {
uint256 ruleArrayLength = _rules.length;
for (uint256 i = 0; i < ruleArrayLength; ++i) {
for (uint256 i; i < ruleArrayLength; ) {
uint8 restriction = _rules[i].detectTransferRestriction(
_from,
_to,
Expand All @@ -52,6 +52,9 @@ contract RuleEngineMock is IRuleEngine {
if (restriction != uint8(REJECTED_CODE_BASE.TRANSFER_OK)) {
return restriction;
}
unchecked {
++i;
}
}
return uint8(REJECTED_CODE_BASE.TRANSFER_OK);
}
Expand All @@ -72,11 +75,14 @@ contract RuleEngineMock is IRuleEngine {
uint8 _restrictionCode
) public view override returns (string memory) {
uint256 ruleArrayLength = _rules.length;
for (uint256 i = 0; i < ruleArrayLength; ++i) {
for (uint256 i; i < ruleArrayLength; ) {
if (_rules[i].canReturnTransferRestrictionCode(_restrictionCode)) {
return
_rules[i].messageForTransferRestriction(_restrictionCode);
}
unchecked {
++i;
}
}
return "Unknown restriction code";
}
Expand Down
39 changes: 19 additions & 20 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import "./wrapper/mandatory/ERC20BaseModule.sol";
/*
SnapshotModule:
Add this import in case you add the SnapshotModule
import "./wrapper/optional/SnapshotModule.sol";
*/
import "./wrapper/optional/SnapshotModule.sol";*/
import "./wrapper/mandatory/PauseModule.sol";
import "./wrapper/optional/ValidationModule.sol";
import "./wrapper/optional/MetaTxModule.sol";
Expand All @@ -24,6 +23,8 @@ import "./wrapper/optional/DebtModule/CreditEventsModule.sol";
import "./security/AuthorizationModule.sol";
import "../interfaces/IEIP1404/IEIP1404Wrapper.sol";

import "../libraries/Errors.sol";

abstract contract CMTAT_BASE is
Initializable,
ContextUpgradeable,
Expand All @@ -40,10 +41,10 @@ abstract contract CMTAT_BASE is
CreditEventsModule
{
/**
@notice
initialize the proxy contract
The calls to this function will revert if the contract was deployed without a proxy
*/
* @notice
* initialize the proxy contract
* The calls to this function will revert if the contract was deployed without a proxy
*/
function initialize(
address admin,
string memory nameIrrevocable,
Expand All @@ -67,8 +68,8 @@ abstract contract CMTAT_BASE is
}

/**
@dev calls the different initialize functions from the different modules
*/
* @dev calls the different initialize functions from the different modules
*/
function __CMTAT_init(
address admin,
string memory nameIrrevocable,
Expand Down Expand Up @@ -130,8 +131,8 @@ abstract contract CMTAT_BASE is
}

/**
@notice Returns the number of decimals used to get its user representation.
*/
* @notice Returns the number of decimals used to get its user representation.
*/
function decimals()
public
view
Expand Down Expand Up @@ -167,10 +168,8 @@ abstract contract CMTAT_BASE is
address to,
uint256 amount
) internal view override(ERC20Upgradeable) {
require(
ValidationModule.validateTransfer(from, to, amount),
"CMTAT: transfer rejected by validation module"
);
if (!ValidationModule.validateTransfer(from, to, amount))
revert Errors.InvalidTransfer(from, to, amount);
// We call the SnapshotModule only if the transfer is valid
/*
SnapshotModule:
Expand All @@ -179,9 +178,9 @@ abstract contract CMTAT_BASE is
*/
}

/**
@dev This surcharge is not necessary if you do not use the MetaTxModule
*/
/**
* @dev This surcharge is not necessary if you do not use the MetaTxModule
*/
function _msgSender()
internal
view
Expand All @@ -191,9 +190,9 @@ abstract contract CMTAT_BASE is
return MetaTxModule._msgSender();
}

/**
@dev This surcharge is not necessary if you do not use the MetaTxModule
*/
/**
* @dev This surcharge is not necessary if you do not use the MetaTxModule
*/
function _msgData()
internal
view
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/internal/EnforcementModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract contract EnforcementModuleInternal is
*/
function _freeze(
address account,
string memory reason
string calldata reason
) internal virtual returns (bool) {
if (_frozen[account]) return false;
_frozen[account] = true;
Expand All @@ -79,7 +79,7 @@ abstract contract EnforcementModuleInternal is
*/
function _unfreeze(
address account,
string memory reason
string calldata reason
) internal virtual returns (bool) {
if (!_frozen[account]) return false;
_frozen[account] = false;
Expand Down
Loading