Enshrining an AMM DEX in the Ledger Kernel: Asymmetric Rounding and Atomic PathPayment

On general-purpose smart-contract networks, AMM DEX pools usually operate as application-layer contracts. With protocols such as Uniswap or Raydium and their surrounding aggregator routers, converting a token into a merchant's settlement currency can involve several separate operations:
- Authorize an external router to debit tokens, for example through an
approvetransaction where the token standard requires it. - Submit a
swap, traversing contract or program calls to execute the conversion. - Submit a
transferor business payment to send the resulting asset to the service provider.
A frontend can hide some of that complexity. It cannot, by itself, resolve three deeper problems: rounding errors that erode pool reserves, routers that retain favorable execution differences, and conversions disconnected from final payment that leave intermediate balances behind.
ArcBlock takes a different architectural approach: the constant-product AMM (CONSTANT_PRODUCT_AMM) and multihop PathPayment are native transaction primitives in the ledger kernel.

1. Asymmetric Pool-Favoring Rounding: Enforcing Δk >= 0 with Integers
The textbook constant-product formula is x * y = k. A blockchain state machine, however, operates on discrete balances represented by unsigned big integers (BigInt), not continuous real numbers.
When a swap calculation leaves a division remainder, who receives it, even if it amounts to just 1 unit, the smallest denomination?
An incorrect rounding direction can turn that small remainder into an attack surface. If a contract uses floor for both the input a user must pay and the output they receive, repeated small round trips may extract rounding dust from the pool. Flash liquidity can amplify an exploitable calculation.
ArcBlock's arithmetic kernel enforces asymmetric pool-favoring rounding:
- Exact input (
EXACT_IN: givenΔx, calculateΔy). The user's output is rounded down withfloor. Fractional remainders remain in the pool. - Exact output (
EXACT_OUT: givenΔy, calculate the requiredΔx). The required input is rounded up withceil, adding+ 1nwhenever integer division leaves a remainder.
This rule, floor on output and ceil on required input, preserves a useful property: after accounting for protocol routing fees, every transition must satisfy x_after * y_after >= x_before * y_before, the monotonically nondecreasing invariant Δk >= 0. Splitting a transaction into many small swaps cannot reverse the rounding bias: any remainder favors the pool rather than the caller.
2. Zero Positive-Slippage Skimming: Delivering the Actual Output
Some external aggregators and wallet swap services retain favorable execution differences, a practice known as positive-slippage skimming:
- A user requests a swap with an expected output of
100.00units and a1%tolerance, settingminAmountOut = 99.00. - Before execution, a reverse-direction swap changes the pool state. The input now produces
101.50units (101.50 > expected 100.00). - A router configured to retain that difference may send only
100.00, or even99.00, to the user and keep the remaining units in its own treasury.

ArcBlock's native AMM has no third-party router contract between the user and the pool. Its zero positive-slippage skimming rule is explicit:
minAmountOutinEXACT_INmode andmaxAmountIninEXACT_OUTmode serve only as Boolean safety assertions.- When the actual output satisfies
minAmountOut, the entire calculated output is credited to the user or downstream recipient. The protocol does not retain the difference merely because execution became more favorable.
3. Atomic Multihop PathPayment: Cross-Currency Settlement in One Transaction
The practical benefit of a kernel-native AMM extends beyond swaps. It simplifies payments in a multi-token commercial environment through executePathPayment and hub routing with swapTokenForTokenViaHub.
Consider an AI image-generation Blocklet charging 5.00 units of settlement asset C per call. The caller holds only community-point token A.
With separate conversion and payment transactions, the caller may have to swap A into B, then B into C. An input-based conversion can produce too little C to pay the invoice or leave a small surplus behind.
In ArcBlock, the caller can sign a single native executePathPayment, using swapTokenForTokenViaHub for the atomic two-hop route Token_A → OfficialToken → Token_B, with the official token as the sole reserve hub and EXACT_OUT for a precise recipient amount.

- Work backward from the merchant's required amount. The transaction declares: “The merchant must receive exactly
5.00units of asset C; I will pay no more thanMunits of asset A, along routeA → B → C.” - Settle every hop atomically in the kernel. Starting with
Pool(B/C)and thenPool(A/B), the state machine works backward to calculate the required input,actualInA, using asymmetricceilarithmetic. IfactualInA <= M, one transaction against a single state snapshot:- Debits exactly
actualInAunits of asset A from the payer. - Updates the reserves and fee allocations of each built-in AMM pool along the route.
- Credits exactly
5.00units of asset C to the merchant and applies the associated order-fulfillment state change.
- Debits exactly
- No intermediate balance, separate approval, or partial payment. The caller does not sign an
approve, and no unused intermediate B remains in the wallet. If a pool lacks sufficient liquidity or a slippage bound fails, the transaction rolls back; the post-execution conservation gate also rejects any state change that violates its invariants.
From Swap Execution to Settlement Infrastructure
A kernel-native AMM and PathPayment, supported by asymmetric pool-favoring rounding (Δk >= 0) and zero positive-slippage skimming, make liquidity pools part of a transparent settlement mechanism. Conversion and delivery become one atomic operation with explicit limits and a precise recipient amount.
What if retailers and SaaS providers want shared loyalty points redeemable across merchants? Or a business wants to receive approved cross-chain assets directly into its treasury without routing the payment through a public DEX? The final article in the “Token Models and Built-In AMM / DEX Fundamentals” series examines “Coalition T-Point and a Stripe-Like Cross-Chain Cashier: Tokens for Merchant Payments and Multimerchant Settlement.”