Skip to content

Smart Contract

The smart contract lives in move/forum/sources/forum.move and is the core of the system. All state changes happen on-chain.

Objects

ObjectTypeDescription
ForumSharedCentral registry: users with roles, subscriptions, badges, reputation, treasury
AdminCapOwnedCapability object held by the deployer, required for admin operations
EscrowSharedIndividual escrow instances for 2-of-3 multi-sig trades

Roles

Roles are stored on-chain per user in the Forum object:

ValueRolePermissions
0BANNEDCannot interact
1USERPost, vote, tip, subscribe, purchase, escrow
2MODERATORAll USER permissions + create categories, moderate content
3ADMINAll permissions + set roles, configure forum

Entry Functions

FunctionMin. RoleDescription
registerNoneRegister a new user in the Forum
post_eventUSERPost a thread, reply, or vote
mod_post_eventMODERATORCreate category, moderate content
admin_post_eventADMINSet config, manage roles
set_user_roleADMINChange a user’s role
tipUSERSend a tip to a post author
subscribeUSERSubscribe to a creator’s tier
renew_subscriptionUSERRenew an existing subscription
purchase_contentUSERPurchase gated content
purchase_badgeUSERPurchase a badge
configure_tierUSERConfigure subscription tiers for your profile
configure_badgeUSERConfigure badges available for purchase
create_escrowUSERCreate a 2-of-3 multi-sig escrow
mark_deliveredUSERSeller marks escrow as delivered
open_disputeUSEROpen a dispute on an escrow
vote_releaseUSERVote to release escrow funds to seller
vote_refundUSERVote to refund escrow funds to buyer
rate_tradeUSERRate a completed trade
withdraw_fundsADMINWithdraw treasury funds

Events

The contract emits typed events that the backend indexes:

EventTrigger
ForumEventAny forum operation (data is gzipped)
TipEventTip sent to a post author
SubscriptionEventSubscription created or renewed
PurchaseEventContent purchased
BadgeEventBadge purchased
EscrowCreatedNew escrow created
EscrowUpdatedEscrow state changed (delivered, disputed, released, refunded)
RatingEventTrade rated after completion

Data Encoding

All data stored on-chain is encoded as:

JSON -> gzip -> vector<u8>

This minimizes on-chain storage costs while keeping data structured and recoverable.

Treasury and Fees

The Forum object holds a treasury that collects fees:

Fee TypeRate
Marketplace purchases5%
Escrow trades2%

Overpayments are automatically refunded to the sender by the contract.