PopitGame.sol

Overview

PopitGame.sol defines the PopitGame smart contract, which orchestrates the deployment and management of the PopCoin wallets and roots within a blockchain-based game ecosystem. This contract handles the initialization of core components, interactions with wallet contracts, and coordination with auxiliary contracts like Boost. Its primary responsibilities include deploying wallet contracts, managing state variables such as rewards and current mbi (an internal metric), and ensuring sufficient contract balance to operate securely. The smart contract enforces access control primarily through public key verification and sender address validation.

Contract: PopitGame

Properties

Events


Constructor

constructor (
    mapping(uint8 => TvmCell) code,
    uint256 root_pubkey,
    uint128 index
)

Description

Initializes the PopitGame contract instance. It verifies the sender, sets essential state variables, and deploys the Boost contract with necessary initialization data.

Parameters

Implementation Details

Usage Example

mapping(uint8 => TvmCell) codeCells = ...; // Provided compiled code
uint256 rootPubKey = ...; // Owner's root public key
uint128 index = 1;

PopitGame game = new PopitGame(codeCells, rootPubKey, index);

Functions

addValuePopit

function addValuePopit(string name, uint256 id, uint64 value) public view senderIs(...) accept

Adds a specified value to a PopCoin wallet associated with the given name and id.

popitGame.addValuePopit("player1", 12345, 100);

popCoinRootDeployed

function popCoinRootDeployed(string name) public view senderIs(...) accept

Handles the event when a PopCoin root contract is deployed and signals this via an event emission.

popitGame.popCoinRootDeployed("mainRoot");

popCoinWalletDeployed

function popCoinWalletDeployed(string name) public view senderIs(...) accept

Handles the event when a PopCoin wallet contract is deployed and signals this via an event emission.

popitGame.popCoinWalletDeployed("player1");

ensureBalance (Private)

function ensureBalance() private pure

Ensures the contract maintains a minimum balance defined by CONTRACT_BALANCE. If the balance falls below the threshold, it triggers a mint operation.


setMbiCur

function setMbiCur(uint64 mbiCur) public senderIs(_boost) accept

Sets the current mbi value, which impacts wallet value updates.

boostContract.setMbiCur(42);

deployPopCoinWallet

function deployPopCoinWallet(string name, uint64 value) public view onlyOwnerPubkey(_root_pubkey) accept

Deploys a new PopCoinWallet contract with an initial value, using the provided name as an identifier.

popitGame.deployPopCoinWallet("player1", 1000);

deployPopCoinWalletOldTransfer

function deployPopCoinWalletOldTransfer(string name, uint64 value) public view onlyOwnerPubkey(_root_pubkey) accept

Alternate deployment method for a PopCoinWallet, similar to deployPopCoinWallet but without mbi validation.

popitGame.deployPopCoinWalletOldTransfer("player1", 1000);

withdraw

function withdraw(uint128 value, address to) public senderIs(_owner)

Withdraws a specified amount of currency from the contract to a specified address.

popitGame.withdraw(500, recipientAddress);

Fallback / Receive Function

receive() external

Handles incoming transfers to the contract.


Getters

getPopCoinWalletAddress

function getPopCoinWalletAddress(string name) external view returns(address)

Calculates and returns the address of a PopCoinWallet contract for a given name.

address walletAddr = popitGame.getPopCoinWalletAddress("player1");

getDetails

function getDetails() external view returns(
    address owner,
    address root,
    uint32 startTime,
    uint64 mbiCur,
    address boost,
    uint128 rewards,
    uint128 minstake
)

Returns comprehensive details about the current state of the PopitGame contract.

(address owner, , , , , , uint128 minstake) = popitGame.getDetails();

getVersion

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

Returns the contract version and its name.

(string memory version, string memory name) = popitGame.getVersion();

Implementation Details and Algorithms


Interaction with Other Contracts


Class Diagram

classDiagram
class PopitGame {
-string version
-mapping(uint8 => TvmCell) _code
-address static _owner
-uint64 _mbiCur
-address _root
-uint32 _startTime
-uint256 _root_pubkey
-address _boost
-uint128 _rewards
+constructor(code, root_pubkey, index)
+addValuePopit(name, id, value)
+popCoinRootDeployed(name)
+popCoinWalletDeployed(name)
-ensureBalance()
+setMbiCur(mbiCur)
+deployPopCoinWallet(name, value)
+deployPopCoinWalletOldTransfer(name, value)
+withdraw(value, to)
+receive()
+getPopCoinWalletAddress(name)
+getDetails()
+getVersion()
}
PopitGame ..> Modifiers : inherits
PopitGame ..> VerifiersLib : uses
PopitGame ..> PopCoinWallet : deploys/calls
PopitGame ..> Boost : deploys/calls