Skip to content

User Service Payment

The "User Service Payment" module is a system smart contract responsible for processing payments related to traffic accounting and content access.

Payment Algorithm

  • if the payer has enough XAT then only XAT are used
  • if the payer is short of XAT then the difference is paid with XAB:
    • the required amount of XAB is calculated with the exchange module
    • this amount of XAB is being charged from the payer
    • all the charged XAB are burned, the corresponding amount of XAT is automatically created and credited to the payee
    • if the lockedPool is not empty then the same amount of XAB is put into circulation (moved from lockedPool to unlockedPool)


def makeUserServicePayment(sourceAccount, targetAccount, amount):
    sourceAccount - the payer account
    targetAccount - the payee account
    amount - amount of payment in XAT
    if sourceAccount.balance.xat >= amount:
        # Source account has enough XAT

        # Move `amount` XAT from the source account to the target account
        sourceAccount.balance.xat -= amount
        targetAccount.balance.xat += amount
        # Source account doesn't have enough XAT

        # Amount of XAT the payer has
        xatAmount = sourceAccount.balance.xat

        # Amount of XAT needed to complete the payment
        xatToEmit = amount - xatAcount

        # Amount of XAB needed based on system DEX exchange rate
        exchangeRate = DEX.getRate('XAT', 'XAB')
        xabAmount = xatToEmit * exchangeRate

        if sourceAccount.balance.xab >= xabAmount:
            # Move `xatAmount` XAT from the source account to the target account
            sourceAccount.balance.xat -= xatAmount
            targetAccount.balance.xat += xatAmount

            # Burn `xabAmount` XAB from the source account
            sourceAccount.balance.xab -= xabAmount
            System.BLACKHOLE.balance.xab += xabAmount

            # Emit `xatToEmit` XAT and add them to the target account
            targetAccount.balance.xat += xatToEmit

            # Unlock at most `xabAmount` XAB
            toUnlock = min(xabAmount, System.lockedPool.amount)
            if toUnlock > 0:
                System.lockedPool.amount -= toUnlock
                System.unlockedPool.amount += toUnlock
            raise Exception('not enough tokens')


Examples are available here