When developing TokenF, a lot of attention was paid to making it easy to create projects based on it. The architecture may seem complicated at first glance, but once you understand it, it is easy enough to implement a project of any size.
In order to start developing a TokenF-based project, you need to add an npm package with the core contracts
npm install @tokenf/contracts
Regulatory token setup
Since you have chosen TokenF, the centrepiece of your protocol is likely to be the regulatory token itself. All you need to do is inherit the token contract from the TokenF or NFTF contract and add an init function. This completes the configuration of the base token.
This contracts are easily customisable by overriding the virutal functions, so you can implement arbitrary logic.
Compliances setup
The next step is to create KYCCompliance and RegulatoryCompliance contracts. As with the token, in the basic version you only need to inherit from the required TokenF compliance contracts and add init functions.
Like all other contracts, compliance contracts can be easily customised to suit your needs. If the contracts cannot provide you with the functionality you need, you can implement the compliance contracts yourself, as long as the IKYCCompliance and IRegulatoryCompliance interfaces are implemented.
Example of basic compliance contracts for EquityToken or EquityNFT:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import {KYCCompliance} from "@tokenf/contracts/core/KYCCompliance.sol";
contract KYCComplianceFacet is KYCCompliance {
function __KYCComplianceFacet_init() external onlyInitializing {
__KYCCompliance_init();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import {RegulatoryCompliance} from "@tokenf/contracts/core/RegulatoryCompliance.sol";
contract RegulatoryComplianceFacet is RegulatoryCompliance {
function __RegulatoryComplianceFacet_init() external onlyInitializing {
__RegulatoryCompliance_init();
}
}
Modules setup
The last but not least part is module configuration. TokenF provides abstract contracts for KYC and Regulatory modules, which in most situations will be suitable for inheritance. In case they can't provide the necessary business logic, there is an AbstractModule contract that will definitely fit all situations.
To release your own modules, you need to inherit from the required abstract module or from already implemented modules, which TokenF also provides.
Example of a TokenF regulatory module for setting minimum and maximum transfer limits:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import {IAssetF} from "../../../interfaces/IAssetF.sol";
import {ERC20TransferLimitsModule} from "../../../modules/regulatory/ERC20TransferLimitsModule.sol";
contract ERC20TransferLimitsModuleMock is ERC20TransferLimitsModule {
function __ERC20TransferLimitsModuleMock_init(
address assetF_,
uint256 minTransferValue_,
uint256 maxTransferValue_
) external initializer {
__AbstractModule_init(assetF_);
__AbstractRegulatoryModule_init();
__ERC20TransferLimitsModule_init(minTransferValue_, maxTransferValue_);
}
function __TransferLimitsDirect_init() external {
__ERC20TransferLimitsModule_init(0, 0);
}
function __AbstractModuleDirect_init() external {
__AbstractModule_init(address(0));
}
function __AbstractRegulatoryModuleDirect_init() external {
__AbstractRegulatoryModule_init();
}
function getContextKey(bytes4 selector_) external view returns (bytes32) {
IAssetF.Context memory ctx_;
ctx_.selector = selector_;
return _getContextKey(ctx_);
}
}
Example of a ready-to-use user module:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import {IAssetF} from "@tokenf/contracts/interfaces/IAssetF.sol";
import {ERC20TransferLimitsModule} from "@tokenf/contracts/modules/regulatory/ERC20TransferLimitsModule.sol";
contract EquityERC20TransferLimitsModule is ERC20TransferLimitsModule {
function __EquityERC20TransferLimitsModule_init(address tokenF_) external initializer {
__AbstractModule_init(tokenF_);
__ERC20TransferLimitsModule_init(1 ether, MAX_TRANSFER_LIMIT);
}
function getContextKey(bytes4 selector_) external view returns (bytes32) {
IAssetF.Context memory ctx_;
ctx_.selector = selector_;
return _getContextKey(ctx_);
}
}
Deployment process
Deployment process depends quite a lot on the specific implementation of the project, but still there will be common parts. Let's look at the steps for deploying basic contracts from the examples above:
Deployment of core contracts, including EquityToken, KYCComplianceFacet and RegulatoryComplianceFacet