📄How to integrate a whitelist to my protocol

0. Requirements

  • The address of a whitelist instance already deployed using Talaria App.

  • Basic understanding of smart contracts

1. Create your Beta Testing Logic

BetaProtocol.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

interface IWhitelist {
    function usersWhitelisted(address user) external view returns (bool);
}

abstract contract BetaProtocol is Ownable {
  
  /*
  * @dev The whitelist contract instance
  */
  IWhitelist public whitelist;
  
  /*
  * @dev Whether beta access is enabled
  */
  bool public betaAccessEnabled;

  error UserNotWhitelistedAndBetaAccessIsEnabled();

  /*
  * @dev Modifier to check if the user is whitelisted
  */
  modifier onlyWhitelisted() {
    if (betaAccessEnabled && !whitelist.usersWhitelisted(msg.sender)) {
      revert UserNotWhitelistedAndBetaAccessIsEnabled();
    }
    _;
  }

  /*
  * @dev Constructor to set the whitelist contract address and initialize access
  */
  constructor(address _whitelist) Ownable(msg.sender) {
    whitelist = IWhitelist(_whitelist); // Assign the whitelist contract
    betaAccessEnabled = true; // Start with beta access enabled
  }

  /*
  * @dev Set the beta access enabled flag
  */
  function setBetaAccessEnabled(bool _enabled) public onlyOwner {
    betaAccessEnabled = _enabled;
  }
}

2. Use it

YourProtocol.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {BetaProtocol} from "./BetaProtocol.sol";

/*
* @dev This is an example protocol that uses the Talaria beta access whitelist
*/
contract YourProtocol is BetaProtocol {

  /*
  * @dev Constructor
  * @param _whitelist The address of the whitelist contract instance, you can generate one at app.talariaprotocol.xyz
  */
  constructor(address _whitelist) BetaProtocol(_whitelist) {}

  /*
  * @dev Test function
  * @notice This function is only callable by whitelisted users
  */
  function test() public view onlyWhitelisted {
    // Your logic
  }
}

You can add the address of the whitelist either via argument at deployment or hard-coded.

Last updated