Different from the regular PVP Space, which uses UFO tokens, the On-Chain PVP Space requires a game contract from $UFO.
All participating players must deposit a specified amount of $UFO. The contract will lock these tokens until the end of the competition.
Game Result Determination: At the end, an external trusted source (such as the game server backend/Oracle) must submit the players' final scores to the contract. The contract determines the winner based on the scores and distributes the rewards accordingly.
Permissions and Security:
The contract checks NFT ownership to ensure that NFT holders can create specific PVP spaces.
After the competition ends, the administrator (which can later be replaced by a DAO or Oracle) submits the results to ensure that the contract's internal logic remains closed and uncontrollable.
Utilize the OpenZeppelin security library to enhance security.
Players lock their tokens in the contract, and the winner of the prize pool is determined based on the competition results, implementing a centralized game logic on-chain.
Contract Design Process
Contract Roles:
Owner/Manager: Contract manager (can be a multi-signature address from the project team or a DAO).
NFT Contract Address: Can verify ownership permissions through the IERC721 interface.
Host (NFT Holder): Player who opens the PVP room.
Participating Players: Players who inject $UFO to join the competition.
Contract Data Structures:
Data Structures
Definition
MatchInfo
Stores information for each match
host
Address of the initiator
entryFee
Betting amount required to participate
startTime
Start times of the match
endTime
End times of the match
participants
List of participants
scores
Final scores of participants
finished
Whether the match has been settled
totalPool
Total prize pool amount
feeRate
Platform fee rate (e.g., 2%)
Contract Workflow:
Host Creates Room: NFT holders call createMatch to generate a new match ID, setting the betting amount, start/end times, fee rate mode, etc.
Players Participate: Players call joinMatch(matchId) and pay the entryFee (via ERC20 approve + transferFrom). The contract records the player's address and accumulates the amount into the totalPool.
Upload Scores (After Match Ends): After the match ends (endTime), a trusted backend service/administrator calls submitScores(matchId, players[], scores[]) to submit the final results on-chain.
Contract Verification:
Has the endTime been exceeded?
Only the designated administrator (backend oracle) can submit the results.
Settlement and Prize Distribution: finalizeMatch(matchId) distributes the prize pool to the highest scorer.
Deduct platform fees
Transfer the remaining amount to the highest scorer
The code here only shows the architecture design, the actual code will be refined and optimized.