micapass
  • welcome
    • 👋Welcome to micapass
    • 📄Regulatory Context
    • ✏️Solution
  • SC Integration
    • 📍Overview
    • 👓Proof Types (Claim Topics)
    • ⛏️Basic Integration
      • Steps for Basic Integration
      • Examples of Basic Integration
    • 🛠️Advanced Integration
      • Why Advanced Integration?
      • Steps for Advanced Integration
      • Example of Advanced Integration
    • 📬Smart contracts addresses
  • LINKS
    • Web
    • X
    • Get micapass
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3
  • Step 4
  • Step5
  • Step 6
  • Step 7
  • Step 8
  1. SC Integration
  2. Advanced Integration

Steps for Advanced Integration

Step 1

Add the Micapass smart contracts to your codebase

  • IMicapassBaseVerifier.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;

interface IMicapassBaseVerifier {
    /*
     *  @dev get inforamtion if the user is verified for claim
     *  @param userAddress user wallet address
     *  @param requiredClaimTopic claim topics user is being checked for
     *  @return true or false
     */
    function isUserVerified(
        address userAddress,
        uint256[] memory requiredClaimTopics
    ) external view returns (bool);

    /*
     *  @dev get inforamtion if the user is verified for claim
     *  @param userAddress user wallet address
     *  @param claimTopicId claim topic user is being checked for
     *  @return true or false
     */
    function isUserVerifiedForClaim(
        address userAddress,
        uint256 claimTopicId
    ) external view returns (bool);
}

Step 2

Import IMicapassBaseVerifier.sol interface to your smart contract

import {IMicapassBaseVerifier} from "../interfaces/IMicapassBaseVerifier.sol";

Step 3

Define variable within your smart contract responsible for Micapass smart contract instance

    IMicapassBaseVerifier internal _micapass;
    

Step 4

Pass actual address of Micapass smart contract to your smart contract during initialization.

Use this page to check available networks and actual addresses

function initialize(address micapassAddress) external initializer {
        _micapass = IMicapassBaseVerifier(micapassAddress);
        ...

or through the setter method. Use the Micapass address of the chain you are going to deploy your smart contracts:

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

don't forget to protect calling this method for only authorized addresses (admin, manager, etc)

Step5

Define your functions that are going to be protected by Micapass

For example it can be

function deposit()

and

function withdraw() 

Step 6

This is only one example of configuring required claim topics ids for scpecific actions within your smart contract, you can follow the flow which better fits your needs, for example - make requirements for each action configurable or hardcode them, pass trough initialization or have specific setters etc

Declare claim topics ids which you are going to use

    uint256 private constant CLAIM_TOPIC_KYC = 1000001;
    uint256 private constant CLAIM_TOPIC_WALLET_SCREENING = 1000002;

Please refer to this page to check the actual proof types (claim topics) and their ids

and the variables responsible for storing set of claim topics required for specific methods

    uint256[] public requiredDepositClaimTopics;
    uint256[] public requiredHugeDepositClaimTopics; // custom set for the cases with huge amount of deposits
    uint256[] public requiredWithdrawalClaimTopics;

here is an example of the case where deposit method should be protected with two proof types - KYC and Wallet sanctions screening, but withdraw method is protected only by Wallet sanctions screening:

    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);

        ...
    }

Step 7

Define which user should be checked for Micapass proofs (sender, receiver, etc)

For example for deposit method the msg.sender should be protected by Micapass, but for withdraw - the receiver, or both, sender + receiver

Step 8

In each of the defined functions add the check or required statement for a user(s) verification check

  • use isUserVerified to check if user wallet address has set of claims (multi claims check)

    /*
     *  @dev get inforamtion if the user is verified for claim
     *  @param userAddress user wallet address
     *  @param requiredClaimTopic claim topics user is being checked for
     *  @return true or false
     */
    function isUserVerified(
        address userAddress,
        uint256[] memory requiredClaimTopics
    ) external view returns (bool);

  • use isUserVerifiedForClaim to check if user wallet address has specific claim (one claim check)

     /*
     *  @dev get inforamtion if the user is verified for claim
     *  @param userAddress user wallet address
     *  @param requiredClaimTopic claim topics user is being checked for
     *  @return true or false
     */
    function isUserVerifiedForClaim(
        address userAddress,
        uint256 claimTopicId
    ) external view returns (bool);

Examples

example of protection deposit method

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

xample of protection deposit method with custom logic - if user deposits > 1 ether - check for extended set of proofs:

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;
    }

example of protection withdraw method

    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);
    }

or withdraw if the funds should be withdrawn to different address, so we can check receiver in this case

    function withdrawTo(
        address receiver
    ) external mAddressNotZero(receiver) {
        require(
            _micapass.isUserVerified(receiver, 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 1 year ago

🛠️