Target

The Target contract is designed for on-chain creation and management of projects. It facilitates functions such as enabling financiers to create projects, registering administrators, and managing proj

Contract Function

The Target contract is designed to create and manage projects (Targets), allowing users to become administrators (Contractors) of these projects. Project creators can mint NFTs to represent their projects and manage project status and funding flows through the contract's logic.

Contract Structure:

  • BaseConfig: Contains basic configurations of the contract, such as token addresses, fee addresses, treasury contract addresses, etc.

  • TargetData: Includes data structures related to the Target project.

  • ChequeData: Contains data structures related to cheques (Cheques).

  • DistributionData: Includes data structures related to distributions (Distributions).

  • PublicFun: Contains public functions that are inherited and used by the Target contract.

important variables:

  • TargetNFT: Address of the NFT contract used for minting NFTs representing projects.

  • TOKEN: Address of the token contract used for handling token transactions.

  • feeTo: Address used for receiving transaction fees.

  • Vault: Address of the vault contract used for managing fund flows.

  • Router: Address of the router contract used for obtaining token prices.

  • Farm: Address of the mining contract used for fee distribution.

  • Expert: Address of the expert contract used for associated query subscriptions.

The Functions :

  • Create Project

    • createTarget: Users can create a project, requiring them to meet the minimum hashrate requirement and mint an NFT to represent the project.

  • Register Administrator

    • registerContractor: Users can apply to become administrators of a project, needing to pay a fee and meet the minimum hashrate requirement.

  • Status Management

    • getTargetStatus: Retrieves the status of a project, where the status value defines the current phase of the project (not started, project created, cheque created, etc.).

  • Events

    • NewTargetCreated: Triggered when a new project is created.

    • NewTargetStatus: Triggered when the status of a project changes.

    • NewContractor: Triggered when a new administrator is registered.

Contract Logic

Users create projects using the createTarget function, which requires meeting specific hashrate requirements and minting an NFT.

Users can become administrators of projects by using the registerContractor function, which involves paying a fee.

The status of a project is obtained using the getTargetStatus function, where the status value reflects the current phase of the project.

Interface


pragma solidity >=0.8.12;

interface ITarget {
    /**
    @dev Create a project
    @param user         User address
    @param targetId     ID
     */
    event NewTargetCreated(address indexed user, uint256 targetId);

    /**
    @dev Event for target status change
    @param targetId     ID
    @param statusFrom   Status before change
    @param statusTo     Status after change
     */
    event NewTargetStatus(
        uint256 indexed targetId,
        uint16 statusFrom,
        uint16 statusTo
    );

    /**
    @dev Event for registering a contractor
    @param user        User address
    @param targetId    Target ID
     */
    event NewContractor(address indexed user, uint256 targetId);

    /**
    @dev Get the status of a target
    @param _targetId   ID
    @return _status    Status code
     */
    function target2Status(
        uint256 _targetId
    ) external view returns (uint16 _status);
    
    /**
    @dev Check if a user address is a contractor of a target
    @param _targetId    ID
    @param _user        User address
    @return _isBool     Status
     */
    function contractorMap(
        uint256 _targetId,
        address _user
    ) external view returns (bool _isBool);

    /**
    @dev Get the active cheque bound to the target
    @param _targetId     ID
     */
    function target2ActiveCheque(
        uint256 _targetId
    ) external view returns (uint256 _id);
    
    /**
    @dev Get the active distribution bound to the target
    @param _targetId      ID
     */
    function target2ActiveDistribution(
        uint256 _targetId
    ) external view returns (uint256 _id);

    /**
    @dev Get the current number of projects
     */
    function targetLength() external view returns (uint256);

    /**
    @dev Get all contractors of a target
    @param _targetId     ID
    @return _arr         List of addresses
    @return _length      Number of contractors
     */
    function getTargetContractorList(
        uint256 _targetId
    ) external view returns (address[] memory _arr, uint256 _length);
    
    /**
    @dev Get all projects created by a user
    @param _user      User address
    @return _ids      List of project IDs
    @return _length   Number of projects
     */
    function getAddrAllTarget(
        address _user
    ) external view returns (uint256[] memory _ids, uint256 _length);

    // ---------------------------------- SEND ----------------------------------
    /**
    @dev Create a project - Basic data NFT generation
    @notice Upload chainID, DataId, name, info, ipfsHash, etc. to IPFS, and mint an NFT using the IPFS metadata
    */
    function createTarget(string memory uri) external;

    /**
    @dev Apply to become a contractor
    @notice Need to pay SYT fee (contractorFee amount to feeTo)
    @param _targetId       Distribution ID
     */
    function registerContractor(uint256 _targetId) external;

    // ---------------------------------- Managers ----------------------------------

    /**
    @dev Admin changes the status of a target, supporting distribution and cheque contracts
     */
    function updateTargetStatus(uint256 _targetId, uint16 _statusId) external;

    /**
    @dev Admin changes the active distribution bound to a target, supporting distribution contract changes
     */
    function updateActiveDistribution(
        uint256 _targetId,
        uint256 _distributionId
    ) external;

    /**
    @dev Admin changes the active cheque bound to a target, supporting cheque contract changes
     */
    function updateActiveCheque(uint256 _targetId, uint256 _chequeId) external;

    //--------------------- CONFIG -----------------------------

    function TargetNFT() external view returns (address);
    function TOKEN() external view returns (address);
    function feeTo() external view returns (address);
    function Vault() external view returns (address);

    function USDT() external view returns (address);
    function WETH() external view returns (address);
    function Router() external view returns (address);
    function PToken() external view returns (address);
    function YToken() external view returns (address);

    function contractorFee() external view returns (uint256);
    function creationFee() external view returns (uint256);
    function BASE() external view returns (uint256);
    function BaseEth2PT() external view returns (uint256);
    function startCheckInterval() external view returns (uint32);
    function endCheckInterval() external view returns (uint32);

    // --------------------- UPDATE -----------------------------
    function updateToken(address _token) external;
    function updateFeeTo(address _feeTo) external;
    function updateFeeRate(uint256 _feeRate) external;
    function updateRouter(address _router) external;
    function updateUSDT(address _usdt) external;
    function updateBase(uint256 _base) external;
    function updatePToken(address _ptoken) external;
    function updateYToken(address _ytoken) external;
    function updateBaseEth2PT(uint256 _base) external;
    function updateStartCheckInterval(uint32 _interval) external;
    function updateEndCheckInterval(uint32 _interval) external;
}

Last updated