Professionalization

The Expert contract allows users to professionalize as experts...

The Expert contract provides the platform with a complete system for managing experts and subscribers. It allows users to professionalize as experts, set subscription fees, and manage subscription services.

Contract Features

The Expert contract provides an expert system that allows users to apply to become experts, subscribe to experts, renew expert subscriptions, and manage subscription relationships.

The Variables

  • expertTotal: Total number of experts.

  • TOKEN: Token contract address.

  • feeTo: Address for fees.

  • applyExpertFee: Mapping of fees for applying to become an expert.

  • expertList: List of all experts.

  • experts: Stores detailed information of each expert.

  • expert2Bool: Indicates whether an address is an expert.

  • expert2Subscribe: Mapping of user subscription statuses.

  • expertToFans: List of subscribers for each expert.

  • fanToSubscribedExperts: List of experts subscribed to by a user.

  • maturityTime: Stores subscription expiration times.

The Functions

  1. Events

    • ApplyExpert: Triggered when applying to become an expert.

    • CollectSubscriptionFee: Triggered when an expert collects subscription fees.

    • Subscribe: Triggered when a user subscribes to an expert.

  2. Initialization Function

    • initialize: Initializes the contract, setting the token and fee addresses.

  3. Management Functions

    • updateToken: Updates the token contract address.

    • updateFeeTo: Updates the fee address.

  4. Expert Application and Renewal

    • applyExpert: User applies to become an expert, requiring payment of the respective fee.

    • updateApplyExpertFee: Admin updates the fee for applying to become an expert.

    • updateSubscriptionFee: Expert updates their own subscription fee.

    • expertRenewal: Expert renews their subscription.

  5. User Subscription

    • subscribe: User subscribes to an expert, requiring payment of the subscription fee.

  6. Queries and Revenue Collection

    • getExpertFans: Retrieves the list of an expert's subscribers.

    • getFanSubscriptions: Retrieves the list of experts a user has subscribed to.

    • getAllExpert: Retrieves information on all experts.

    • collectSubscriptionFee: Expert collects their subscription fees.

    • getExpert2Subscribe: Retrieves a user's subscription status for an expert.

    • getExpertInfo: Retrieves detailed information about an expert.

Logic

  • Users can apply to become an expert using the applyExpert function, which requires payment of a fee and setting their subscription fee.

  • Experts can update their subscription fee using the updateSubscriptionFee function.

  • Users can subscribe to experts using the subscribe function, pay the corresponding subscription fee, and renew their subscription through expertRenewal.

  • Experts can collect their subscription fees using the collectSubscriptionFee function. The contract provides a series of query functions to facilitate users and experts in querying relevant information.

Interface


// SPDX-License-Identifier: MIT
pragma solidity >=0.8.12;
pragma experimental ABIEncoderV2;

interface ILogic {
    struct IExpert {
        uint32 createTime;  // Creation time
        uint32 maturityTime;  // Maturity time
        uint256 subscriptionFee;  // Subscription fee
        uint256 unclaimedIncome;  // Unclaimed income
        uint256 earnedIncome;  // Earned income
    }

    /**
     * @notice Get total number of experts starting from 0.
     * @return Total number of experts.
     */
    function expertTotal() external view returns (uint256);

    /**
     * @notice Get subscription fee corresponding to the renewal cycle.
     * @param _cycle Renewal cycle, where 1 represents 1 year.
     * @return Renewal fee.
     */
    function applyExpertFee(uint8 _cycle) external view returns (uint256);

    /**
     * @notice Get expert status.
     * @param _expert   Address of the expert.
     * @return Expert status, true means the address is an expert, false means it is not.
     */
    function expert2Bool(address _expert) external view returns (bool);

    /**
     * @notice Get user's subscription status to an expert.
     * @param _user    User's address.
     * @param _expert  Expert's address.
     * @return Subscription status, true means subscribed, false means not subscribed.
     */
    function expert2Subscribe(address _user, address _expert) external view returns (bool);

    /**
     * @notice Apply to become an expert, requires payment in tokens.
     * @param _cycle    Application cycle, where 1 represents 1 year.
     * @param _fee      Subscription fee for the user.
     */
    function applyExpert(uint8 _cycle, uint256 _fee) external;

    /**
     * @notice Administrator updates the renewal fee.
     * @param _cycle           Renewal cycle.
     * @param _applyExpertFee  New renewal fee.
     */
    function updateApplyExpertFee(uint8 _cycle, uint256 _applyExpertFee) external;

    /**
     * @notice Update user's subscription fee.
     * @param _subscriptionFee    New subscription fee.
     */
    function updateSubscriptionFee(uint256 _subscriptionFee) external;

    /**
     * @notice Subscribe to an expert, requires payment in tokens.
     * @param _expert    Expert's address.
     */
    function subscribe(address _expert) external;

    /**
     * @notice Expert renews subscription, requires payment in tokens.
     * @param _cycle    Renewal cycle.
     */
    function expertRenewal(uint8 _cycle) external;

    /**
     * @notice Get list of fans for an expert.
     * @param _expert    Expert's address.
     * @return Array     of fan addresses.
     */
    function getExpertFans(address _expert) external view returns (address[] memory);

    /**
     * @notice Get list of experts subscribed by a user.
     * @param _user    User's address.
     * @return Array of subscribed expert addresses.
     */
    function getFanSubscriptions(address _user) external view returns (address[] memory);

    /**
     * @notice Get list of all experts.
     * @return Array of all experts' information.
     */
    function getAllExpert() external view returns (IExpert[] memory);

    /**
     * @notice Expert collects their subscription fee.
     */
    function collectSubscriptionFee() external;

    /**
     * @notice Get detailed information of a single expert.
     * @param _expert    Expert's address.
     * @return Detailed information of the expert.
     */
    function experts(address _expert) external view returns (IExpert memory);
}


Last updated