Skip to content

Commit 5fcd17f

Browse files
authored
Rename RarimoKYCModule to SimpleKYCModule (#8)
* Rename RarimoKYCModule to SimpleKYCModule & small fixes * Rename getContextKey to getContextKeyBySelector & bump dependencies versions
1 parent 0c1c2ac commit 5fcd17f

23 files changed

+1007
-325
lines changed

contracts/NFTF.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import {AccessControlUpgradeable} from "./core/AgentAccessControl.sol";
1414
import {NFTFStorage} from "./storages/NFTFStorage.sol";
1515

1616
abstract contract NFTF is INFTF, AbstractAssetF, NFTFStorage, ERC721EnumerableUpgradeable {
17+
/// @dev Precomputed selectors for safe transfers from the IERC721.
18+
/// @dev Selector for `safeTransferFrom(address,address,uint256)`
19+
bytes4 public constant SAFE_TRANSFER_FROM_SELECTOR = 0x42842e0e;
20+
/// @dev Selector for `safeTransferFrom(address,address,uint256,bytes)`
21+
bytes4 public constant SAFE_TRANSFER_FROM_WITH_DATA_SELECTOR = 0xb88d4fde;
22+
1723
bytes4 public constant TRANSFER_SELECTOR = this.transfer.selector;
1824
bytes4 public constant TRANSFER_FROM_SELECTOR = this.transferFrom.selector;
1925
bytes4 public constant MINT_SELECTOR = this.mint.selector;

contracts/mock/modules/ModuleMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ contract ModuleMock is AbstractRegulatoryModule, AbstractKYCModule {
3232
__AbstractKYCModule_init();
3333
}
3434

35-
function getContextKey(bytes4 selector_) external view returns (bytes32) {
35+
function getContextKeyBySelector(bytes4 selector_) external view returns (bytes32) {
3636
IAssetF.Context memory ctx_;
3737
ctx_.selector = selector_;
3838

contracts/mock/modules/kyc/RarimoModuleMock.sol

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.21;
3+
4+
import {IAssetF} from "../../../interfaces/IAssetF.sol";
5+
import {SimpleKYCModule} from "../../../modules/kyc/SimpleKYCModule.sol";
6+
7+
contract SimpleKYCModuleMock is SimpleKYCModule {
8+
function __SimpleKYCModuleMock_init(address assetF_, address sbt_) external initializer {
9+
__AbstractModule_init(assetF_);
10+
__AbstractKYCModule_init();
11+
__SimpleKYCModule_init(sbt_);
12+
}
13+
14+
function __SimpleKYCModuleDirect_init() external {
15+
__SimpleKYCModule_init(address(0));
16+
}
17+
18+
function getContextKeyBySelector(bytes4 selector_) external view returns (bytes32) {
19+
IAssetF.Context memory ctx_;
20+
ctx_.selector = selector_;
21+
22+
return getContextKey(ctx_);
23+
}
24+
}

contracts/mock/modules/regulatory/ERC20TransferLimitsModuleMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ contract ERC20TransferLimitsModuleMock is ERC20TransferLimitsModule {
2727
__AbstractRegulatoryModule_init();
2828
}
2929

30-
function getContextKey(bytes4 selector_) external view returns (bytes32) {
30+
function getContextKeyBySelector(bytes4 selector_) external view returns (bytes32) {
3131
IAssetF.Context memory ctx_;
3232
ctx_.selector = selector_;
3333

34-
return _getContextKey(ctx_);
34+
return getContextKey(ctx_);
3535
}
3636
}

contracts/mock/modules/regulatory/ERC721TransferLimitsModuleMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ contract ERC721TransferLimitsModuleMock is ERC721TransferLimitsModule {
2727
__AbstractRegulatoryModule_init();
2828
}
2929

30-
function getContextKey(bytes4 selector_) external view returns (bytes32) {
30+
function getContextKeyBySelector(bytes4 selector_) external view returns (bytes32) {
3131
IAssetF.Context memory ctx_;
3232
ctx_.selector = selector_;
3333

34-
return _getContextKey(ctx_);
34+
return getContextKey(ctx_);
3535
}
3636
}

contracts/modules/AbstractModule.sol

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ abstract contract AbstractModule is Initializable {
8888
_removeHandlerTopics(contextKey_, handlerTopics_);
8989
}
9090

91+
/**
92+
* @notice Function to retrieve the context key from the provided transaction context.
93+
*
94+
* This function calls the internal `_getContextKey` function, which can be overridden
95+
* in derived contracts to customize how the context key is generated based on the
96+
* specific module's requirements.
97+
*
98+
* @param ctx_ The transaction context
99+
* @return context key
100+
*/
101+
function getContextKey(IAssetF.Context memory ctx_) public view virtual returns (bytes32) {
102+
return _getContextKey(ctx_);
103+
}
104+
91105
/**
92106
* @notice Function to retrieve all stored handler topics by the passed context key.
93107
*
@@ -184,7 +198,7 @@ abstract contract AbstractModule is Initializable {
184198
function _handlerer() internal virtual;
185199

186200
/**
187-
* @notice Function to retrieve the context key from the transaction context.
201+
* @notice Internal function to calculate and retrieve the context key from the transaction context.
188202
*
189203
* The `bytes32` type has been chosen for the context key so that it could be customised.
190204
* Depending on the future purpose of the module, it will be possible to define the process of creating a context key,
@@ -209,7 +223,7 @@ abstract contract AbstractModule is Initializable {
209223
* @param ctx_ The transaction context
210224
*/
211225
function _handle(IAssetF.Context memory ctx_) internal view virtual returns (bool) {
212-
bytes32 contextKey_ = _getContextKey(ctx_);
226+
bytes32 contextKey_ = getContextKey(ctx_);
213227
bytes32[] memory handlerTopics_ = getHandlerTopics(contextKey_);
214228

215229
for (uint256 j = 0; j < handlerTopics_.length; ++j) {

contracts/modules/kyc/RarimoModule.sol renamed to contracts/modules/kyc/SimpleKYCModule.sol

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ import {IAssetF} from "../../interfaces/IAssetF.sol";
77
import {AbstractKYCModule} from "../AbstractKYCModule.sol";
88

99
/**
10-
* @notice `RarimoModule` is an example of a possible KYC module implementation,
10+
* @notice `SimpleKYCModule` is an example of a possible KYC module implementation,
1111
* within which the user's SBT token is checked.
1212
*/
13-
abstract contract RarimoModule is AbstractKYCModule {
13+
abstract contract SimpleKYCModule is AbstractKYCModule {
1414
bytes32 public constant HAS_SOUL_SENDER_TOPIC = keccak256("HAS_SOUL_SENDER");
1515
bytes32 public constant HAS_SOUL_RECIPIENT_TOPIC = keccak256("HAS_SOUL_RECIPIENT");
1616
bytes32 public constant HAS_SOUL_OPERATOR_TOPIC = keccak256("HAS_SOUL_OPERATOR");
1717

18-
// keccak256("tokenf.standard.rarimo.module.storage")
19-
bytes32 private constant RARIMO_MODULE_STORAGE =
20-
0x4daee3f1bcf471e40cb8bb42f6957ecf0fb0ccfdf6e24496c76bda599dbc8902;
18+
// keccak256("tokenf.standard.simple.kyc.module.storage")
19+
bytes32 private constant SIMPLE_KYC_MODULE_STORAGE =
20+
0x38deaaaa98559b0911f428b8b3b9bbf960af9ad1ba4f2251fc09aa6872c543ae;
2121

22-
struct RarimoModuleStorage {
22+
struct SimpleKYCModuleStorage {
2323
address sbt;
2424
}
2525

26-
function __RarimoModule_init(address sbt_) internal onlyInitializing {
27-
RarimoModuleStorage storage $ = _getRarimoModuleStorage();
26+
function __SimpleKYCModule_init(address sbt_) internal onlyInitializing {
27+
SimpleKYCModuleStorage storage $ = _getSimpleKYCModuleStorage();
2828

2929
$.sbt = sbt_;
3030
}
3131

3232
function getSBT() public view virtual returns (address) {
33-
RarimoModuleStorage storage $ = _getRarimoModuleStorage();
33+
SimpleKYCModuleStorage storage $ = _getSimpleKYCModuleStorage();
3434

3535
return $.sbt;
3636
}
@@ -44,33 +44,31 @@ abstract contract RarimoModule is AbstractKYCModule {
4444
function _handleHasSoulSenderTopic(
4545
IAssetF.Context memory ctx_
4646
) internal view virtual returns (bool) {
47-
RarimoModuleStorage storage $ = _getRarimoModuleStorage();
48-
49-
return ISBT($.sbt).balanceOf(ctx_.from) > 0;
47+
return _hasSBT(ctx_.from);
5048
}
5149

5250
function _handleHasSoulRecipientTopic(
5351
IAssetF.Context memory ctx_
5452
) internal view virtual returns (bool) {
55-
RarimoModuleStorage storage $ = _getRarimoModuleStorage();
56-
57-
return ISBT($.sbt).balanceOf(ctx_.to) > 0;
53+
return _hasSBT(ctx_.to);
5854
}
5955

6056
function _handleHasSoulOperatorTopic(
6157
IAssetF.Context memory ctx_
6258
) internal view virtual returns (bool) {
63-
RarimoModuleStorage storage $ = _getRarimoModuleStorage();
59+
return _hasSBT(ctx_.operator);
60+
}
6461

65-
return ISBT($.sbt).balanceOf(ctx_.operator) > 0;
62+
function _hasSBT(address userAddr_) internal view returns (bool) {
63+
return ISBT(_getSimpleKYCModuleStorage().sbt).balanceOf(userAddr_) > 0;
6664
}
6765

6866
/**
6967
* @dev Returns a pointer to the storage namespace
7068
*/
71-
function _getRarimoModuleStorage() private pure returns (RarimoModuleStorage storage $) {
69+
function _getSimpleKYCModuleStorage() private pure returns (SimpleKYCModuleStorage storage $) {
7270
assembly {
73-
$.slot := RARIMO_MODULE_STORAGE
71+
$.slot := SIMPLE_KYC_MODULE_STORAGE
7472
}
7573
}
7674
}

examples/equity-token/contracts/RarimoSBT.sol renamed to examples/equity-token/contracts/EquitySBT.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Own
55

66
import {ASBT} from "@solarity/solidity-lib/tokens/ASBT.sol";
77

8-
contract RarimoSBT is ASBT, OwnableUpgradeable {
9-
function __RarimoSBT_init() external initializer {
10-
__ASBT_init("RarimoSBT", "RarimoSBT");
8+
contract EquitySBT is ASBT, OwnableUpgradeable {
9+
function __EquitySBT_init() external initializer {
10+
__ASBT_init("EquitySBT", "EquitySBT");
1111
__Ownable_init(msg.sender);
1212
}
1313

examples/equity-token/contracts/modules/EquityERC20TransferLimitsModule.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ contract EquityERC20TransferLimitsModule is ERC20TransferLimitsModule {
1010
__ERC20TransferLimitsModule_init(1 ether, MAX_TRANSFER_LIMIT);
1111
}
1212

13-
function getContextKey(bytes4 selector_) external view returns (bytes32) {
13+
function getContextKeyBySelector(bytes4 selector_) external view returns (bytes32) {
1414
IAssetF.Context memory ctx_;
1515
ctx_.selector = selector_;
1616

17-
return _getContextKey(ctx_);
17+
return getContextKey(ctx_);
1818
}
1919
}

0 commit comments

Comments
 (0)