Smart Contract — PactumBilling

Reference documentation for the PactumBilling Solidity contract.


Overview

PactumBilling is the on-chain component of the Pactum billing system. It manages USDC deposits from end-users, holds funds in escrow, and enables the platform operator to settle usage charges by moving funds from user balances to merchant balances in batches.

Contract: PactumBilling.sol Solidity Version: ^0.8.20 Chain: Arc Testnet (Chain ID: 5042002) Token: USDC at 0x3600000000000000000000000000000000000000

[!IMPORTANT] USDC on Arc has dual views: native 18-decimal and ERC-20 6-decimal. This contract uses the 6-decimal ERC-20 view for all operations.


Contract Architecture


State Variables

VariableTypeVisibilityDescription
usdcIERC20publicUSDC token contract reference
platformOperatoraddresspublicAddress authorized to call settlement functions
userBalancesmapping(address => uint256)publicDeposited USDC per user
merchantBalancesmapping(address => uint256)publicEarned USDC per merchant

Functions

deposit(uint256 amount)

Allows a user to deposit USDC into the contract. The user must first call approve() on the USDC token contract, granting the PactumBilling contract an allowance.

ParameterTypeDescription
amountuint256Amount of USDC to deposit (6-decimal precision)

Requirements:

  • amount > 0
  • USDC transferFrom must succeed (requires prior approve)

Emits: Deposited(user, amount)


batchSettleUsage(address[] users, address[] merchants, uint256[] amounts)

Settles off-chain usage charges in a single transaction. Moves funds from user balances to merchant balances. Only callable by the platform operator.

ParameterTypeDescription
usersaddress[]Array of user addresses being charged
merchantsaddress[]Array of merchant addresses receiving payment
amountsuint256[]Array of USDC amounts to transfer

Requirements:

  • Caller must be platformOperator
  • All arrays must have equal length
  • Each userBalances[user] >= amount

Emits: UsageSettled(user, merchant, amount) for each settlement


withdrawUser(uint256 amount)

Allows a user to withdraw their remaining unused USDC balance from the contract.

ParameterTypeDescription
amountuint256Amount to withdraw

Requirements:

  • userBalances[msg.sender] >= amount

Emits: UserWithdrawn(user, amount)


withdrawMerchant(uint256 amount)

Allows a merchant to withdraw their earned USDC from the contract.

ParameterTypeDescription
amountuint256Amount to withdraw

Requirements:

  • merchantBalances[msg.sender] >= amount

Emits: MerchantWithdrawn(merchant, amount)


setOperator(address newOperator)

Transfers the platform operator role to a new address. Only callable by the current operator.

ParameterTypeDescription
newOperatoraddressNew operator address

Requirements:

  • Caller must be current platformOperator
  • newOperator != address(0)

Events

EventParametersDescription
Depositeduser (indexed), amountUser deposited USDC
UsageSettleduser (indexed), merchant (indexed), amountUsage charge settled from user to merchant
UserWithdrawnuser (indexed), amountUser withdrew unused balance
MerchantWithdrawnmerchant (indexed), amountMerchant withdrew earned fees

Interaction Flow

A typical lifecycle:


Arc Testnet Configuration

PropertyValue
Chain ID5042002
RPChttps://rpc.testnet.arc.network
Explorerhttps://testnet.arcscan.app
USDC Address0x3600000000000000000000000000000000000000
USDC Decimals6 (ERC-20 view)
FaucetCircle Faucet