Example of Advanced Integration

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IMicapassBaseVerifier} from "../interfaces/IMicapassBaseVerifier.sol";
import {Managerable} from "../extensions/Managerable.sol";

contract ClientCustom is Initializable, Managerable {
    IMicapassBaseVerifier public _micapass;

    mapping(address => uint256) internal _userBalance;
    // Declare claim topics for function access control
    uint256 private constant CLAIM_TOPIC_KYC = 1000001;
    uint256 private constant CLAIM_TOPIC_WALLET_SCREENING = 1000002;

    // Required for input formatting
    uint256[] public requiredDepositClaimTopics;
    uint256[] public requiredHugeDepositClaimTopics;
    uint256[] public requiredWithdrawalClaimTopics;

    function initialize(address micapassAddress) external initializer {
        _micapass = IMicapassBaseVerifier(micapassAddress);
        requiredDepositClaimTopics.push(CLAIM_TOPIC_WALLET_SCREENING);
        requiredHugeDepositClaimTopics.push(CLAIM_TOPIC_KYC);
        requiredHugeDepositClaimTopics.push(CLAIM_TOPIC_WALLET_SCREENING);

        requiredWithdrawalClaimTopics.push(CLAIM_TOPIC_WALLET_SCREENING);

        __Managerable_init();
    }

    function setMicapass(
        address micapassAddress
    ) external onlyRole(MANAGER_ROLE) {
        _micapass = IMicapassBaseVerifier(micapassAddress);
    }

    function deposit() external payable {
        if (msg.value > 1 ether) {
            require(
                _micapass.isUserVerified(
                    msg.sender,
                    requiredHugeDepositClaimTopics
                ),
                "Lacking required claims"
            );
        } else {
            require(
                _micapass.isUserVerified(
                    msg.sender,
                    requiredDepositClaimTopics
                ),
                "Lacking required claims"
            );
        }
        _userBalance[msg.sender] += msg.value;
    }

    function withdraw() external {
        require(
            _micapass.isUserVerified(msg.sender, requiredWithdrawalClaimTopics),
            "Lacking required claims"
        );
        require(_userBalance[msg.sender] > 0, "No funds deposited");
        uint256 userBalance = _userBalance[msg.sender];
        _userBalance[msg.sender] = 0;
        payable(msg.sender).transfer(userBalance);
    }

    function withdrawTo(address receiver) external mAddressNotZero(receiver) {
        require(
            _micapass.isUserVerified(msg.sender, requiredWithdrawalClaimTopics),
            "Lacking required claims"
        );
        require(_userBalance[msg.sender] > 0, "No funds deposited");
        uint256 userBalance = _userBalance[msg.sender];
        _userBalance[msg.sender] = 0;
        payable(receiver).transfer(userBalance);
    }
}

Last updated