Cheque
The Cheque contract is the primary contract for project financing, serving as the main entity for consensus decision verification processes...
The Cheque contract
is the primary contract for project financing, serving as the main entity for consensus decision verification processes. It also acts as the sole credential for withdrawing funds from the fund pool during project financing.
Contract Functions
The Cheque
contract, as an extension of the Distribution
contract, provides functionalities such as creating cheques, users checking cheques (participating in verification), cancelling checks, and withdrawing distribution funds. Cheques play a crucial role in the project financing verification process. Alpha vouchers can use Position Tokens to check or cancel checks to express guarantees for projects and withdraw guarantees, facilitating the consensus matching process of community decision-making.
Structure
The Cheque
contract inherits from the Distribution
contract and utilizes the SafeMath
and SafeMath32 libraries
to ensure the security of numerical operations.
Variables
chequeIndex
: Index for cheques, starting from 1.cheques
: Mapping storing details of each cheque.cheque2Owner
: Records the owner of each cheque.cheque2Time
: Records the creation time of each cheque.cheque2Claimed
: Records the amount that has already been claimed for each cheque.userCheck2Cheque
: Records user participation in each cheque.
The Function
Events
NewChequeCreated
: Triggered upon creation of a cheque.NewChequeWithdraw
: Triggered when withdrawing distribution funds.NewCheck
: Triggered when a user checks a cheque.NewCancelCheck
: Triggered when a user cancels a check.
Cheque Management
createCheque
: Creates a new cheque, requiring a fee payment.withdraw
: Allows the cheque owner to withdraw funds, subject to conditions.
Participation and Cancellation of Consensus Decisions
check
: Allows a user to check a cheque, expressing support for the project.cancelCheck
: Allows a user to cancel a check, withdrawing their support.
Query Functions
getPending
: Retrieves the current amount available for withdrawal and check progress.getTargetIdFromCheque
: Retrieves the project ID based on the cheque code.
Logic
Users create a check using the
createCheque
function and pay the corresponding fee.Users can endorse a project by using the
check
function to check the check.Users may cancel a check using the
cancelCheck
function and return the guarantee if conditions are met.After a check is successfully endorsed, check owners can withdraw financing funds using the
withdraw
function.
Interface
pragma solidity >=0.8.12;
pragma experimental ABIEncoderV2;
interface ICheque {
/**
@dev Event for creating a new cheque
*/
event NewChequeCreated(address indexed user, uint256 chequeId);
/**
@dev Event for withdrawing cheque funds
*/
event NewChequeWithdraw(address indexed user, uint256 amount);
/**
@dev Event for user check
*/
event NewCheck(
address indexed user,
uint8 typeId,
uint256 chequeId,
uint256 targetId,
uint256 amount
);
/**
@dev Event for user cancel check
*/
event NewCancelCheck(
address indexed user,
uint8 typeId,
uint256 chequeId,
uint256 targetId,
uint256 amount
);
/**
@dev Get cheque details by ID
*/
function cheques(uint256 _chequeId) external view returns (uint256);
/**
@dev Get cheque creation time by ID
*/
function cheque2Time(uint256 _chequeId) external view returns (uint32);
/**
@dev Get claimed amount by cheque ID
*/
function cheque2Claimed(uint256 _chequeId) external view returns (uint256);
/**
@dev Create a cheque
@notice Creates a cheque and pays SYT tokens as a fee
@param _indexer Cheque indexer code
*/
function createCheque(uint256 _indexer) external;
/**
@dev Withdraw funds
@notice Confirm the conditions for withdrawal
@param _chequeId Cheque ID
@param _acceptAddress Asset receiving address, can be user or contract address
*/
function withdraw(uint256 _chequeId, address _acceptAddress) external;
/**
@dev Get the amount available for withdrawal
@param _chequeId Cheque ID
@return _pending Pending amount
@return _progress Progress of the cheque
*/
function getPending(
uint256 _chequeId
) external view returns (uint256 _pending, uint8 _progress);
/**
@dev Get the price of the token
@return _tokenPrice Price of the token
@return _token2ETH Token to ETH conversion rate
*/
function getPrice()
external
view
returns (uint256 _tokenPrice, uint256 _token2ETH);
/**
@dev User performs check on a cheque, using PT, where 1 ETH = 1000 PT
- An additional 0.3% SYT fee is charged and goes to farm2
- If the amount is greater than 300, wallet must have SYT*10 > checking amount
- Long and short positions
- Can participate between creation time + 3 days and creation time + 10 days
@param _typeId Participation type, 1 for long (increases project progress, 0.3% extra fee), 2 for short (does not increase project progress)
@param _chequeId Cheque ID
@param _amount Amount, ETH value user wants to participate with
*/
function check(uint8 _typeId, uint256 _chequeId, uint256 _amount) external;
/**
@dev User cancels check, returns guarantee, only principal is returned, not including fees
@param _typeId Exit type, 1 for long (can exit during process), 2 for short (can exit after project ends)
@param _chequeId Cheque ID
@param _amount ETH value to cancel, returns _amount * 1000 PT
*/
function cancelCheck(
uint8 _typeId,
uint256 _chequeId,
uint256 _amount
) external;
/**
@dev Get target ID from cheque data
@param _data Data
@return _targetId Target ID
*/
function getTargetIdFromCheque(
uint256 _data
) external pure returns (uint256 _targetId);
/**
@dev Get aggregate information of a cheque by ID
@notice The amounts involved are in ETH value (project fundraising target)
@param _user User address
@param _chequeId Cheque ID
@return _isExpert Whether the address is an expert
@return _createTime Creation time
@return _chequeEncodeData Cheque encoding data
@return _claimed Amount claimed
@return _checkAmount Accumulated long check amount
@return _checkEmptyAmount Accumulated short check amount
@return _owner Cheque owner
@return _userCheck2Cheque User's long check amount in PT
@return _userCheck2ChequeEmpty User's short check amount in PT
*/
function getArgInfo2ChequeId(
address _user,
uint256 _chequeId
)
external
view
returns (
bool _isExpert,
uint32 _createTime,
uint256 _chequeEncodeData,
uint256 _claimed,
uint256 _checkAmount,
uint256 _checkEmptyAmount,
address _owner,
uint256 _userCheck2Cheque,
uint256 _userCheck2ChequeEmpty
);
/**
@dev Set specified address as expert, no restrictions for now
@param _user User address
@param _isBool Status true/false
*/
function setExpertUser(address _user, bool _isBool) external;
/**
@dev Check if the specified address is an expert
@param _user User address
@return _isBool Status true/false
*/
function expertUser(address _user) external view returns (bool _isBool);
/**
@dev Get the owner of a cheque by ID
@param _chequeId Cheque ID
@return _owner Owner address
*/
function cheque2Owner(uint256 _chequeId) external view returns (address _owner);
/**
@dev Get all cheque IDs of a user
@param _user User address
@return _ids List of cheque IDs
*/
function getUserChequeIds(
address _user
) external view returns (uint256[] memory _ids);
/**
@dev Get all cheques of a user
@param _user User address
@return _ids List of cheque IDs
@return _infos List of cheque info
@return _length Number of cheques
*/
function getUserAllCheque(
address _user
)
external
view
returns (
uint256[] memory _ids,
uint256[] memory _infos,
uint256 _length
);
}
Last updated