This contract is a multi-asset treasury contract. It allocates and settles funds to users, partners, and protocol addresses through an internal ledger using a pull-based model.
Key Concepts
Name
Type
Description
factory
address
Factory contract address (immutable), used for permission validation, Session registration, and emergency operations.
balances
mapping(address => uint256)
Available balance (ETH) for users / partners.
sessionConfig
mapping(address => SessionConfig)
Session configuration: partner address and session validity flag.
sessionBalances
mapping(address => SessionBalance)
Session-level fund pools (ticket funds / partner deposits).
SessionConfig:
Field
Type
Description
partner
address
Partner bound to the Session
isSession
bool
Whether this is a registered Session contract
SessionBalance:
Field
Type
Description
playerTicketAmount
uint256
Accumulated player ticket funds in the Session
partnerDepositAmount
uint256
Locked partner deposit in the Session
Permission Model
Permission
Description
onlyFactory
Only callable by the Factory contract
onlySession
Only callable by registered Session contracts
Partner identity
Determined via Factory's isPartner(address)
Register Session (registerSession)
Called by Factory after creating a Session to register it in the Treasury and bind it to a partner.
Logic:
Validates the Session is not already registered
Validates the partner address is valid
Records the partner bound to the Session
Marks the Session as a legitimate contract
After registration, the Session can call onlySession-restricted functions
Player Pays with Balance (playerPayTicketUseBalance)
Called by Session, uses the player's Treasury balance to pay for tickets.
Logic:
Validates the player has sufficient balance
Deducts amount from balances[player]
Adds amount to the current Session's playerTicketAmount
Player Pays Directly (playerPayTicket)
Called by Session; the player pays directly via msg.value.
Logic:
msg.value > 0
Not added to the player's personal balance
Accumulates ETH into the current Session's playerTicketAmount
Partner Deposit (partnerDeposit)
Partner deposits ETH into the Treasury, credited to their available balance.
Restrictions:
msg.value > 0
Caller must be a partner registered in the Factory
Effects:
Increases balances[msg.sender]
Can be withdrawn anytime via the withdraw function
With sufficient funds, can stake to create a Session
Lock Partner Deposit (lockPartnerDeposit)
Called by Factory to lock partner deposit when a Session is initialized or started.
Logic:
Validates the Session is registered
Validates the Session's bound partner matches the parameter
Validates the partner has sufficient balance
Deducts amount from balances[partner]
Adds to the Session's partnerDepositAmount
Unlock Partner Deposit (unlockPartnerDeposit)
Called by Session to unlock deposits when the session ends normally or partially settles.
Logic:
Validates there is sufficient locked deposit in the Session
Deducts amount from partnerDepositAmount
Returns amount to the partner's balances
Slash Partner Deposit (slashPartnerDeposit)
Called by Session to penalize a violating partner and transfer funds to a specified recipient.
Logic:
Validates there is sufficient locked deposit in the Session
Deducts amount from partnerDepositAmount
Adds amount to balances[recipient]
Slashed funds are not returned to the partner
Emergency Unlock (emergencyUnlockPartnerDeposit)
Called by Factory to force unlock deposits in exceptional or fallback scenarios.
Logic:
Unlocks all locked deposits in the Session
Validates the partner-Session binding relationship
Returns all amounts to the partner's balance
Distribute Funds (distributeFunds)
Called by Session to distribute player ticket funds to a specified user.
Logic:
Validates the user address is valid
Validates amount > 0
Validates the Session's playerTicketAmount is sufficient
Deducts amount from the Session ticket pool
Adds to balances[user]
Batch Distribute Funds (distributeFundsBatch)
Called by Session to batch distribute player ticket funds.
Restrictions:
users.length == amounts.length
Array length greater than 0
Each user address is valid and amount is greater than 0
Logic:
Calculates total amount required for batch distribution
Validates sufficient Session ticket pool balance
Deducts total and increments each user's balance individually
Withdraw (withdraw)
Users or partners withdraw their available balance from the Treasury.