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

Refactoring & Tests #5

Merged
merged 6 commits into from
Apr 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion contracts/core/KYCCompliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract contract KYCCompliance is IKYCCompliance, KYCComplianceStorage, AgentAc
}

/// @inheritdoc IKYCCompliance
function isKYCed(TokenF.Context calldata ctx_) public view virtual returns (bool) {
function isKYCed(TokenF.Context memory ctx_) public view virtual returns (bool) {
address[] memory regulatoryModules_ = getKYCModules();

for (uint256 i = 0; i < regulatoryModules_.length; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/core/RegulatoryCompliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract contract RegulatoryCompliance is
}

/// @inheritdoc IRegulatoryCompliance
function transferred(TokenF.Context calldata ctx_) public virtual onlyThis {
function transferred(TokenF.Context memory ctx_) public virtual onlyThis {
address[] memory regulatoryModules_ = getRegulatoryModules();

for (uint256 i = 0; i < regulatoryModules_.length; ++i) {
Expand All @@ -61,7 +61,7 @@ abstract contract RegulatoryCompliance is
}

/// @inheritdoc IRegulatoryCompliance
function canTransfer(TokenF.Context calldata ctx_) public view virtual returns (bool) {
function canTransfer(TokenF.Context memory ctx_) public view virtual returns (bool) {
address[] memory regulatoryModules_ = getRegulatoryModules();

for (uint256 i = 0; i < regulatoryModules_.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IKYCCompliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ interface IKYCCompliance is IKYCComplianceView {
* @param ctx_ The context of the transaction
* @return true if the passed context satisfies the checks on all modules
*/
function isKYCed(ITokenF.Context calldata ctx_) external view returns (bool);
function isKYCed(ITokenF.Context memory ctx_) external view returns (bool);
}
4 changes: 2 additions & 2 deletions contracts/interfaces/IRegulatoryCompliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface IRegulatoryCompliance is IRegulatoryComplianceView {
*
* @param ctx_ The context of transaction
*/
function transferred(ITokenF.Context calldata ctx_) external;
function transferred(ITokenF.Context memory ctx_) external;

/**
* @notice Function that is used to verify that all necessary regulatory rules that have been added to `RegulatoryCompliance` have been met.
Expand All @@ -66,5 +66,5 @@ interface IRegulatoryCompliance is IRegulatoryComplianceView {
* @param ctx_ The context of transaction
* @return true if the passed context satisfies the rules in all installed regulatory modules.
*/
function canTransfer(ITokenF.Context calldata ctx_) external view returns (bool);
function canTransfer(ITokenF.Context memory ctx_) external view returns (bool);
}
4 changes: 2 additions & 2 deletions contracts/mock/core/ComplianceFalseHooksMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pragma solidity ^0.8.20;
import {TokenF} from "../../core/TokenF.sol";

contract ComplianceFalseHooksMock {
function isKYCed(TokenF.Context calldata) external returns (bool) {
function isKYCed(TokenF.Context memory) external pure returns (bool) {
return false;
}

function canTransfer(TokenF.Context calldata) external returns (bool) {
function canTransfer(TokenF.Context memory) external pure returns (bool) {
return false;
}
}
6 changes: 3 additions & 3 deletions contracts/mock/core/ComplianceRevertHooksMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.20;
import {TokenF} from "../../core/TokenF.sol";

contract ComplianceRevertHooksMock {
function transferred(TokenF.Context calldata) external {
function transferred(TokenF.Context memory) external pure {
revert("ComplianceRevertHooksMock: revert");
}

function isKYCed(TokenF.Context calldata) external view returns (bool) {
function isKYCed(TokenF.Context memory) external pure returns (bool) {
revert("ComplianceRevertHooksMock: revert");
}

function canTransfer(TokenF.Context calldata) external view returns (bool) {
function canTransfer(TokenF.Context memory) external pure returns (bool) {
revert("ComplianceRevertHooksMock: revert");
}
}
2 changes: 1 addition & 1 deletion contracts/mock/core/KYCComplianceMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract KYCComplianceMock is KYCCompliance {
return super._KYCComplianceRole();
}

function _KYCComplianceRole() internal view override returns (bytes32) {
function _KYCComplianceRole() internal pure override returns (bytes32) {
return KYC_COMPLIANCE_ROLE;
}
}
2 changes: 1 addition & 1 deletion contracts/mock/core/RegulatoryComplianceMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract RegulatoryComplianceMock is RegulatoryCompliance {
return super._regulatoryComplianceRole();
}

function _regulatoryComplianceRole() internal view override returns (bytes32) {
function _regulatoryComplianceRole() internal pure override returns (bytes32) {
return REGULATORY_COMPLIANCE_ROLE;
}
}
45 changes: 45 additions & 0 deletions contracts/mock/modules/ModuleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {TokenF} from "../../core/TokenF.sol";
import {AbstractRegulatoryModule} from "../../modules/AbstractRegulatoryModule.sol";
import {AbstractKYCModule} from "../../modules/AbstractKYCModule.sol";

contract ModuleMock is AbstractRegulatoryModule, AbstractKYCModule {
bytes32 public constant MOCK_TOPIC = keccak256("MOCK");

function __ModuleMock_init(address tokenF_) external initializer {
__AbstractModule_init(tokenF_);
__AbstractRegulatoryModule_init();
__AbstractKYCModule_init();
}

function _handlerer() internal override {}

function handlerer() external {
_setHandler(MOCK_TOPIC, _handleMockTopic);
}

function __AbstractModuleDirect_init() external {
__AbstractModule_init(address(0));
}

function __AbstractRegulatoryModuleDirect_init() external {
__AbstractRegulatoryModule_init();
}

function __AbstractKYCModuleDirect_init() external {
__AbstractKYCModule_init();
}

function getClaimTopicKey(bytes4 selector_) external view returns (bytes32) {
TokenF.Context memory ctx_;
ctx_.selector = selector_;

return _getClaimTopicKey(ctx_);
}

function _handleMockTopic(TokenF.Context memory ctx_) internal view virtual returns (bool) {
return true;
}
}
2 changes: 1 addition & 1 deletion contracts/mock/modules/kyc/KYCCorrectModuleMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {AbstractKYCModule} from "../../../modules/AbstractKYCModule.sol";
contract KYCCorrectModuleMock is AbstractKYCModule {
function _handlerer() internal override {}

function isKYCed(TokenF.Context calldata) public pure override returns (bool) {
function isKYCed(TokenF.Context memory) public pure override returns (bool) {
return true;
}
}
2 changes: 1 addition & 1 deletion contracts/mock/modules/kyc/KYCIncorrectModuleMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {AbstractKYCModule} from "../../../modules/AbstractKYCModule.sol";
contract KYCIncorrectModuleMock is AbstractKYCModule {
function _handlerer() internal override {}

function isKYCed(TokenF.Context calldata) public pure override returns (bool) {
function isKYCed(TokenF.Context memory) public pure override returns (bool) {
return false;
}
}
24 changes: 24 additions & 0 deletions contracts/mock/modules/kyc/RarimoModuleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {TokenF} from "../../../core/TokenF.sol";
import {RarimoModule} from "../../../modules/kyc/RarimoModule.sol";

contract RarimoModuleMock is RarimoModule {
function __RarimoModuleMock_init(address tokenF_, address sbt_) external initializer {
__AbstractModule_init(tokenF_);
__AbstractKYCModule_init();
__RarimoModule_init(sbt_);
}

function __RarimoModuleDirect_init() external {
__RarimoModule_init(address(0));
}

function getClaimTopicKey(bytes4 selector_) external view returns (bytes32) {
TokenF.Context memory ctx_;
ctx_.selector = selector_;

return _getClaimTopicKey(ctx_);
}
}
18 changes: 18 additions & 0 deletions contracts/mock/modules/kyc/SBTMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {SBT} from "@solarity/solidity-lib/tokens/SBT.sol";

contract SBTMock is SBT {
function __SBTMock_init() external initializer {
__SBT_init("MockSBT", "MockSBT");
}

function mint(address to_, uint256 tokenId_) external {
_mint(to_, tokenId_);
}

function burn(uint256 tokenId_) external {
_burn(tokenId_);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {TokenF} from "../../../core/TokenF.sol";
import {AbstractRegulatoryModule} from "../../../modules/AbstractRegulatoryModule.sol";

contract RegulatoryCorrectModuleMock is AbstractRegulatoryModule {
function _handlerer() internal override {}
function __RegulatoryCorrectModuleMock_init(address tokenF_) external initializer {
__AbstractModule_init(tokenF_);
__AbstractRegulatoryModule_init();
}

function transferred(TokenF.Context calldata) public override {}
function _handlerer() internal override {}

function canTransfer(TokenF.Context calldata) public pure override returns (bool) {
function canTransfer(TokenF.Context memory) public pure override returns (bool) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {AbstractRegulatoryModule} from "../../../modules/AbstractRegulatoryModul
import {IRegulatoryCompliance} from "../../../interfaces/IRegulatoryCompliance.sol";

contract RegulatoryIncorrectModuleMock is AbstractRegulatoryModule {
function _handlerer() internal override {}
function __RegulatoryIncorrectModuleMock_init(address tokenF_) external initializer {
__AbstractModule_init(tokenF_);
__AbstractRegulatoryModule_init();
}

function transferred(TokenF.Context calldata ctx_) public override {}
function _handlerer() internal override {}

function canTransfer(TokenF.Context calldata) public pure override returns (bool) {
function canTransfer(TokenF.Context memory) public pure override returns (bool) {
return false;
}
}
36 changes: 36 additions & 0 deletions contracts/mock/modules/regulatory/TransferLimitsModuleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {TokenF} from "../../../core/TokenF.sol";
import {TransferLimitsModule} from "../../../modules/regulatory/TransferLimitsModule.sol";

contract TransferLimitsModuleMock is TransferLimitsModule {
function __TransferLimitsModuleMock_init(
address tokenF_,
uint256 minTransferValue_,
uint256 maxTransferValue_
) external initializer {
__AbstractModule_init(tokenF_);
__AbstractRegulatoryModule_init();
__TransferLimitsModule_init(minTransferValue_, maxTransferValue_);
}

function __TransferLimitsDirect_init() external {
__TransferLimitsModule_init(0, 0);
}

function __AbstractModuleDirect_init() external {
__AbstractModule_init(address(0));
}

function __AbstractRegulatoryModuleDirect_init() external {
__AbstractRegulatoryModule_init();
}

function getClaimTopicKey(bytes4 selector_) external view returns (bytes32) {
TokenF.Context memory ctx_;
ctx_.selector = selector_;

return _getClaimTopicKey(ctx_);
}
}
42 changes: 1 addition & 41 deletions contracts/modules/AbstractKYCModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,13 @@ import {AbstractModule} from "./AbstractModule.sol";

/**
* @notice The `AbstractKYCModule` contract is the standard base implementation for KYC modules.
*
* This implementation overrides the `_getExtContexts` and `_getClaimTopicKey` functions so that,
* that `keccak256(selector, TransferParty)` is used to create the claim topic key,
* and `_getExtContexts` returns extended contexts to validate each `TransferParty`,
* where `TransferParty` is a `SENDER`, `RECIPIENT`, or `OPERATOR`.
*
* Existing overrides allow you to specify checks for a specific function and a specific `TransferParty`.
*/
abstract contract AbstractKYCModule is AbstractModule {
enum TransferParty {
Sender,
Recipient,
Operator
}

function __AbstractKYCModule_init() internal onlyInitializing {}

function isKYCed(TokenF.Context calldata ctx_) public view virtual returns (bool) {
function isKYCed(TokenF.Context memory ctx_) public view virtual returns (bool) {
return _handle(ctx_);
}

function _getExtContexts(
TokenF.Context calldata ctx_
) internal view virtual override returns (TokenF.Context[] memory) {
TokenF.Context[] memory ctxs_ = new TokenF.Context[](3);
ctxs_[0] = _getExtContext(ctx_, TransferParty.Sender);
ctxs_[1] = _getExtContext(ctx_, TransferParty.Recipient);
ctxs_[2] = _getExtContext(ctx_, TransferParty.Operator);

return ctxs_;
}

function _getClaimTopicKey(
TokenF.Context memory ctx_
) internal view virtual override returns (bytes32) {
TransferParty transferParty_ = abi.decode(ctx_.data, (TransferParty));

return keccak256(abi.encodePacked(ctx_.selector, transferParty_));
}

function _getExtContext(
TokenF.Context calldata ctx_,
TransferParty transferParty_
) private pure returns (TokenF.Context memory extCtx_) {
extCtx_ = ctx_;
extCtx_.data = abi.encode(transferParty_);
}

uint256[50] private _gap;
}
Loading
Loading