PopCoinRoot.sol

Overview

PopCoinRoot.sol defines the PopCoinRoot smart contract, which serves as the core contract managing the lifecycle, metadata, and reward distribution of a token system named PopCoin. It handles creation and activation of tokens ("popits"), manages media associated with popits, and coordinates interactions with other contracts, including wallets (PopCoinWallet), games (PopitGame), and verifier contracts (MobileVerifiersContractRoot). The contract ensures secure minting, reward calculations, and state transitions, while controlling access through owner public key checks and sender validations.


Contract: PopCoinRoot

State Variables


Constructor

constructor (
    TvmCell PopCoinWalletCode,
    uint256 popitgamehash,
    uint16 maxPopitIndex,
    mapping(uint16 => PopitMedia) popits_media,
    string description,
    uint256 root_pubkey,
    bool isPublic,
    uint128 index,
    address popitGameOwner
)

Public Methods

setIsPublic

function setIsPublic(bool isPublic) public onlyOwnerPubkey(_root_pubkey) accept

setPopitMedia

function setPopitMedia(uint16 index, PopitMedia data) public onlyOwnerPubkey(_root_pubkey) accept

addNewPopit

function addNewPopit(string media, optional(uint32) protopopit) public onlyOwnerPubkey(_root_pubkey) accept

addNewPopitPublic

function addNewPopitPublic(string media, optional(uint32) protopopit) public accept

Private Methods

newPopit

function newPopit(string media, optional(uint32) protopopit) private

ensureBalance

function ensureBalance() private pure

Activation and State Management

activate

function activate(bool isOld) public onlyOwnerPubkey(_root_pubkey) accept

activatePopit

function activatePopit(uint256 id, optional(string) media) public view onlyOwnerPubkey(_root_pubkey) accept

deleteCandidate

function deleteCandidate(uint256 id) public onlyOwnerPubkey(_root_pubkey) accept

destroy

function destroy() public view onlyOwnerPubkey(_root_pubkey) accept

Minting Functions

These functions update the total supply, metrics, and signal readiness to the wallet contracts.

mintValue

function mintValue(address owner, uint64 value, uint64 mbiCur) public senderIs(expectedWalletAddress) accept

mintValuePopit

function mintValuePopit(address owner, uint256 dataId, uint64 dataValue, uint64 mbiCur) public senderIs(expectedWalletAddress) accept

mintValueOld

function mintValueOld(address owner, uint64 value) public senderIs(expectedWalletAddress) accept

Readiness and Rewards

isReady

function isReady(address owner, uint64 value, address popitGameAddress, uint128 mbi) public senderIs(expectedWalletAddress) accept

isReadyPopit

function isReadyPopit(address owner, uint16 indexRoot, uint256 candidateId, uint128 candidateValue, address popitGameAddress, uint128 mbi) public senderIs(expectedWalletAddress) accept

Self-Destruction

destroyNode

function destroyNode() public senderIs(address(this)) accept

Fallback / Receive

receive() external

Getters

getDetails

function getDetails() external view returns (
    address root,
    string name,
    uint128 totalSupply,
    uint16 maxPopitIndex,
    mapping(uint16 => Popit) popits_value,
    mapping(uint16 => PopitMedia) popits_media,
    uint128 rewards,
    mapping(uint256 => PopitCandidateWithMedia) popits_candidate,
    bool isReadyStatus,
    address popitGameOwner,
    string description,
    uint64 deployed
)

getVersion

function getVersion() external pure returns (string, string)

Important Implementation Details


Interactions with Other Contracts


Data Structures Referenced


Visual Diagram: Contract Structure and Method Overview

classDiagram
class PopCoinRoot {
-string version
-mapping _code
-bool _isReady
-uint256 _popitgamehash
-address _root
-string static _name
-bool _isPublic
-uint128 _totalSupply
-uint16 _maxPopitIndex
-mapping _popits_value
-mapping _popits_media
-mapping _popits_candidate
-uint256 _root_pubkey
-string _description
-uint128 _rewards
-uint128 _basicRewards
-address _popitGameOwner
-uint64[] _MBNLst
-uint64[] _TAPLst
-uint64[] _BCLst
-uint64 _deployed
+constructor()
+setIsPublic()
+setPopitMedia()
+addNewPopit()
+addNewPopitPublic()
-newPopit()
-ensureBalance()
+activate()
+activatePopit()
+deleteCandidate()
+getTapReward()
+destroy()
+mintValue()
+mintValuePopit()
+mintValueOld()
+isReady()
+isReadyPopit()
+destroyNode()
+getDetails()
+getVersion()
+receive()
}
PopCoinRoot ..> PopCoinWallet : uses
PopCoinRoot ..> PopitGame : notifies
PopCoinRoot ..> MobileVerifiersContractRoot : coordinates
PopCoinRoot ..> VerifiersLib : address verification

Usage Examples

Adding a New Popit by Owner

popCoinRoot.addNewPopit("https://example.com/media1.png", optional.empty());

Public Adding a New Popit (if allowed)

popCoinRoot.addNewPopitPublic("https://example.com/media2.png", 123);

Activating the Contract

popCoinRoot.activate(false);

Minting Value from Wallet

popCoinRoot.mintValue(ownerAddress, 100, 5);

Querying Contract Details

(
    address root,
    string memory name,
    uint128 totalSupply,
    uint16 maxPopitIndex,
    mapping(uint16 => Popit) memory popits_value,
    mapping(uint16 => PopitMedia) memory popits_media,
    uint128 rewards,
    mapping(uint256 => PopitCandidateWithMedia) memory popits_candidate,
    bool isReadyStatus,
    address popitGameOwner,
    string memory description,
    uint64 deployed
) = popCoinRoot.getDetails();

References to Related Topics

These topics provide foundational knowledge on contract security, verification, and token management mechanisms. For detailed explanations on Modifiers and VerifiersLib, refer to Modifiers and VerifiersLib. The token wallet and game logic contracts are documented in PopCoinWallet and PopitGame.