Skip to main content

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

Robert Mao
BlockchainAMMDEXPathPaymentArchitecture

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:

  1. Authorize an external router to debit tokens, for example through an approve transaction where the token standard requires it.
  2. Submit a swap, traversing contract or program calls to execute the conversion.
  3. Submit a transfer or 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.

Asymmetric pool-favoring rounding rounds output down for exact-input swaps and input up for exact-output swaps, preserving the integer-domain invariant Δk >= 0

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:

  1. Exact input (EXACT_IN: given Δx, calculate Δy). The user's output is rounded down with floor. Fractional remainders remain in the pool.
  2. Exact output (EXACT_OUT: given Δy, calculate the required Δx). The required input is rounded up with ceil, adding + 1n whenever 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.00 units and a 1% tolerance, setting minAmountOut = 99.00.
  • Before execution, a reverse-direction swap changes the pool state. The input now produces 101.50 units (101.50 > expected 100.00).
  • A router configured to retain that difference may send only 100.00, or even 99.00, to the user and keep the remaining units in its own treasury.

With no positive-slippage skimming, the recipient receives the full actual output calculated from the pool state at execution

ArcBlock's native AMM has no third-party router contract between the user and the pool. Its zero positive-slippage skimming rule is explicit:

  • minAmountOut in EXACT_IN mode and maxAmountIn in EXACT_OUT mode 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.

Atomic multihop PathPayment converts Token A through two pools and credits the merchant in one transaction, without intermediate approvals or residual balances

  1. Work backward from the merchant's required amount. The transaction declares: “The merchant must receive exactly 5.00 units of asset C; I will pay no more than M units of asset A, along route A → B → C.”
  2. Settle every hop atomically in the kernel. Starting with Pool(B/C) and then Pool(A/B), the state machine works backward to calculate the required input, actualInA, using asymmetric ceil arithmetic. If actualInA <= M, one transaction against a single state snapshot:
    • Debits exactly actualInA units of asset A from the payer.
    • Updates the reserves and fee allocations of each built-in AMM pool along the route.
    • Credits exactly 5.00 units of asset C to the merchant and applies the associated order-fulfillment state change.
  3. 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.”