Contract ABIs Documentation

This document provides comprehensive documentation for all contract ABIs in the sortes system.

Table of Contents

  • Core Contracts

    • Xbit

    • Voucher

    • Sortes

    • Charity

    • Locker

  • Token Contracts

    • Xexp

    • Xlpt

    • ERC20

  • Utility Contracts

    • Maintainable

    • Cored

    • Coordinator

  • Data Structures


Core Contracts

Xbit Contract

Location: v3xbit/api/XbitAbi.ts

The main gaming contract that handles token deposits, withdrawals, and play mechanics using Chainlink VRF for randomness.

Events

TokenDeposited

Emitted when a user deposits tokens into the pool.

TokenWithdrawRequested

Emitted when a user requests to withdraw tokens from the pool.

TokenWithdrawExecuted

Emitted when a withdrawal is executed.

PlayRequested

Emitted when a play is requested.

PlayFulfilled

Emitted when VRF fulfills a play request with random words.

User Functions

deposit

Deposits tokens into the pool and receives LP tokens in return.

requestWithdraw

Requests to withdraw tokens from the pool by burning LP tokens.

executeWithdraw

Executes an immediate withdrawal request for the caller.

play

Initiates a game play with specified tokens and probability table.

listPlayIds

Lists all play IDs for a given player.

getPlayStatusById

Gets the detailed status of a specific play by ID.

getProbabilityTableById

Gets the probability table used for a specific play.

getLp

Gets the LP token address for a given token.

setDonation

Sets the donation contract address.

Admin Functions (xbitAdminAbi)

Additional admin-only functions include:

  • setChainlinkSubscription: Configure Chainlink VRF parameters

  • listValidTokens: List all valid input and output tokens

  • addValidInputToken: Add a token as valid input with lower bound

  • addValidOutputToken: Add a token as valid output with LP

  • addSwapPair: Configure swap pairs with fees

  • pause: Pause/unpause the contract

  • Plus all functions from maintainableAbi


Voucher Contract

Location: v3xbit/api/VoucherAbi.ts

Manages vouchers that can be issued, transferred, and used for gameplay.

Events

VoucherIssued

Emitted when vouchers are issued.

VoucherTransferred

Emitted when vouchers are transferred to a new owner.

PlayRequested

Emitted when a play is requested using a voucher.

Functions

issue

Issues new vouchers with specified parameters.

getDetail

Gets the details of a voucher by its ID.

getId

Calculates the voucher ID from its parameters.

get

Gets the quantity of a specific voucher owned by an address.

list

Lists all vouchers and their quantities for an owner.

transfer

Transfers vouchers to a new owner.

play

Initiates a play using a voucher.

Admin Functions (voucherAdminAbi)

  • setXbitAddress: Set the Xbit contract address

  • nominalBalance: Get the nominal balance of a token

  • withdraw: Withdraw tokens from the contract

  • Plus all functions from maintainableAbi


Sortes Contract

Location: v3xbit/api/SortesAbi.ts

The donation and voting system that allows converting XEXP to GOOD tokens and managing donations.

Events

DonationInitiated

Emitted when a new donation is initiated.

DonationVoted

Emitted when a user votes for a donation.

DonationClosed

Emitted when a donation is closed.

GoodConverted

Emitted when XEXP is converted to GOOD.

Functions

initiateDonation

Initiates a new donation with GOOD spent. Returns the donation ID.

getDonationsTotal

Gets the total number of donations.

listDonations

Lists all donations initiated by a user.

getDonations

Gets multiple donations by their IDs.

voteDonation

Votes for a donation by converting XEXP to GOOD in a locker.

closeDonation

Closes a donation. Must be called by the initiator.

amm

Calculates the amount of GOOD that would be received for a given XEXP amount.

convertGoodAndLock

Converts XEXP to GOOD at current rate without voting.

Admin Functions (sortesAdminAbi)

  • setupParams: Configure contract parameters

  • getParams: Get current parameters

  • activate: Activate/deactivate a donation

  • withdraw: Withdraw tokens

  • pause: Pause/unpause the contract

  • Plus all functions from maintainableAbi


Charity Contract

Location: v3xbit/api/CharityAbi.ts

Allows users to play games and automatically donate their XEXP earnings to charity.

Events

PlayResult

Emitted when a charity play is completed.

Functions

playWithToken

Plays with tokens and votes all XEXP earned for the specified donation.

playWithVoucher

Plays with a voucher and votes all XEXP earned for the specified donation.

Admin Functions (charityAdminAbi)

  • setupParams: Configure contract parameters (xbit, voucher, sortes addresses)

  • getParams: Get current parameters

  • Plus all functions from maintainableAbi


Locker Contract

Location: v3xbit/api/LockerAbi.ts

Manages token locking with time-based decay (half-life) for gradual unlocking.

Events

TokenLocked

Emitted when tokens are locked for a user.

TokenClaimed

Emitted when a user claims their unlocked tokens.

Functions

lockToken

Transfers tokens into the locker and locks them for a user.

queryToken

Queries the locked and claimable token amounts for a user.

claimToken

Claims all claimable tokens for a user.

getTotalHistory

Gets the total history of tokens received and claimed by the contract.

getUserHistory

Gets the history of tokens received and claimed by a specific user.

Admin Functions (lockerAdminAbi)

  • setupParams: Configure parameters (token, halfLife, globalLockDeadline)

  • getParams: Get current parameters

  • Plus all functions from maintainableAbi


Token Contracts

Xexp Token

Location: v3xbit/api/XexpAbi.ts

The experience token that combines ERC20, Cored, and mint/burn capabilities.

Functions

Includes all functions from:

  • erc20Abi (standard ERC20 interface)

  • coredAbi (core address management)

Plus additional functions:

mint

Mints new XEXP tokens to an account.

burn

Burns XEXP tokens from an account.


Xlpt Token

Location: v3xbit/api/XlptAbi.ts

Liquidity provider token with conversion utilities.

Events

Minted

Emitted when LP tokens are minted.

Burned

Emitted when LP tokens are burned.

Functions

Includes all functions from:

  • erc20Abi (standard ERC20 interface)

  • coredAbi (core address management)

Plus additional functions:

token2LpAmount

Converts token amount to LP token amount.

lp2TokenAmount

Converts LP token amount to underlying token amount.


ERC20 Interface

Location: v3xbit/api/Erc20Abi.ts

Standard ERC20 token interface with commonly used functions.

Read Functions

  • balanceOf(address account): Get token balance

  • decimals(): Get token decimals

  • name(): Get token name

  • symbol(): Get token symbol

  • totalSupply(): Get total supply

  • allowance(address owner, address spender): Get allowance

Write Functions

  • transfer(address to, uint amount): Transfer tokens

  • approve(address spender, uint256 amount): Approve spending

  • mint(address account, uint256 amount): Mint new tokens


Utility Contracts

Maintainable

Location: v3xbit/api/MaintainableAbi.ts

Simple access control pattern for contract maintenance.

Functions

maintainer

Gets the current maintainer address.

setMaintainer

Sets a new maintainer address.


Cored

Location: v3xbit/api/CoredAbi.ts

Interface for managing core contract address references.

Events

CoreAddressSet

Emitted when the core address is set.

Functions

setCoreAddress

Sets the core contract address.

core

Gets the current core contract address.


Coordinator

Location: v3xbit/api/CoordinatorAbi.ts

Interface for the Chainlink VRF Coordinator (Arbitrum: 0x3C0Ca683b403E37668AE3DC4FB62F4B29B6f7a3e).

Events

RandomWordsFulfilled

Emitted when random words are fulfilled by the VRF coordinator.


Data Structures

ProbabilityTable

Used by Xbit, Charity, and Voucher contracts to define game mechanics.

Solidity tuple representation:

Field Details:

  • relatives[i]: For level i, reward is relative to pool (0) or input (1)

  • mExpectations[i]: Absolute expectation = input_amount * expectation / 1e6

  • mRewards[i]: Absolute reward = reward * (pool_size or input_amount) / 1e6

  • tag: Number used to identify the table


PlayStatus

Used by Xbit to track play state.

Solidity tuple representation:


WithdrawRequest

Used by Xbit to track withdrawal requests.

Solidity tuple representation:


Donation

Used by Sortes to track donation campaigns.

Solidity tuple representation:


VoucherDetail

Used by Voucher to store voucher information.

Solidity tuple representation:


Contract Parameters

Sortes Parameters

Solidity tuple: tuple(address xexp, address good, address usd, address locker, uint256 xexpReserved, uint256 goodPerDonation)


Locker Parameters

Solidity tuple: tuple(address token, uint256 halfLife, uint256 globalLockDeadline)


Charity Parameters

Solidity tuple: tuple(address xbit, address voucher, address sortes)


Usage Examples

Depositing Tokens

Playing a Game

Using Vouchers

Creating and Voting on Donations

Token Locking and Claiming


Notes

  • All amounts are in the token's base units (wei for ETH-like tokens)

  • The 1e6 scale is used throughout for probabilities and percentages

  • Admin functions require the caller to be the maintainer

  • VRF randomness is used for fair game outcomes

  • The locker uses half-life decay for gradual token unlocking

Last updated