MPP.Methods.Tempo.MachineToken (mpp v0.14.0)

Copy Markdown View Source

Canonical first-party machine-token (MPP Credits / machineUSD) charge routes.

A machine-token payment does not send the challenge currency from the payer. The payer approves the canonical swapper and calls swapTo; the swapper pulls and burns the credit token, then transferWithMemos the challenge currency to the merchant. Merchant-facing verification is therefore a TIP-20 TransferWithMemo whose from is the swapper, not the payer.

On-chain authority: Tempo's verified Moderato MppcSwapper source (swapTo pulls/burns input, then target.transferWithMemo) plus live Moderato receipts. Reference SDKs are compatibility evidence only:

  • mppx refs/mppx/src/tempo/internal/machine-token.ts / defaults.ts
  • mpp-rs refs/mpp-rs/src/protocol/methods/tempo/machine_token.rs

Calldata/event parsers for this route belong in onchain_tempo. Until that library ships them, this module holds the MPP-side constants and exact [approve, swapTo] match the verifier needs.

Summary

Functions

Match the exact canonical [approve, swapTo] route for a charge.

Build the canonical [approve, swapTo] calls for a charge.

Return the canonical swapper address that emits the merchant transfer, or nil.

Return whether a first-party machine-token deployment exists on chain_id.

ABI-encode swapTo(address,uint256,address,address,bytes32) calldata.

Return the canonical machine-token (credit) address on chain_id, or nil.

Types

call()

@type call() :: %{to: binary(), value: non_neg_integer(), input: binary()}

route()

@type route() :: %{settlement_sender: String.t(), memo: String.t()}

Functions

match_route(calls, chain_id, currency, amount, recipient, memo)

@spec match_route(
  [call()],
  non_neg_integer(),
  String.t(),
  String.t(),
  String.t() | nil,
  String.t() | nil
) :: {:ok, route()} | :error

Match the exact canonical [approve, swapTo] route for a charge.

When memo is nil, the memo is taken from the swapTo calldata (mppx matchRoute / mpp-rs match_route). Any other call shape returns :error.

settlement_calls(chain_id, currency, amount, recipient, memo)

@spec settlement_calls(
  non_neg_integer(),
  String.t(),
  non_neg_integer() | String.t(),
  String.t(),
  binary()
) :: {:ok, [call()]} | :error

Build the canonical [approve, swapTo] calls for a charge.

Returns :error when the chain has no first-party deployment or any address, amount, or memo is invalid.

settlement_sender(chain_id)

@spec settlement_sender(non_neg_integer()) :: String.t() | nil

Return the canonical swapper address that emits the merchant transfer, or nil.

supported?(chain_id)

@spec supported?(non_neg_integer()) :: boolean()

Return whether a first-party machine-token deployment exists on chain_id.

swap_to_calldata(input_token, amount, target_token, recipient, memo)

@spec swap_to_calldata(binary(), non_neg_integer(), binary(), binary(), binary()) ::
  binary()

ABI-encode swapTo(address,uint256,address,address,bytes32) calldata.

token(chain_id)

@spec token(non_neg_integer()) :: String.t() | nil

Return the canonical machine-token (credit) address on chain_id, or nil.