Skip to main content
Settlement is the process of finalizing matched trades by moving the traded assets between the T+ exchange and on-chain vault contracts. When you settle, you exchange one token held in the T+ system for another, with the net transfer recorded on-chain. Settlement requires signing a structured order message and submitting it — either through the CLI or directly in Python using the tplus.utils.domain module.
Settlement requires the [evm] extra. Install it before proceeding:
pip install "tpluspy[evm]"
Without this extra, tplus.evm is unimportable and all on-chain operations will fail with a ModuleNotFoundError.

What settlement means on T+

On T+, your exchange balance tracks your assets internally. Settlement is how those internal balances translate into on-chain token holdings: you specify a token you are giving up (tokenIn) and a token you expect to receive (tokenOut), along with the exact amounts. The T+ settlement contract verifies the signed order against your on-chain nonce and executes the transfer atomically.

Settle via the CLI

The CLI tplus settle command handles both steps: init (sign + submit to OMS) and execute (submit on-chain once approved). Settlement init goes through the OMS (--orderbook-base-url), which returns the approval synchronously.

Initialize a settlement

settle init signs your settlement request and submits it to the OMS, returning the exchange’s approval:
tplus settle init \
  --network arbitrum:mainnet:alchemy \
  --account my-ape-alias \
  --asset-in  <32-byte-hex> \
  --amount-in  1000000000000000000 \
  --amount-in-decimals 18 \
  --asset-out <32-byte-hex> \
  --amount-out 500000 \
  --amount-out-decimals 6

Initialize and execute in one step

settle execute runs init and then submits the on-chain transaction once approved:
tplus settle execute \
  --network arbitrum:mainnet:alchemy \
  --account my-ape-alias \
  --asset-in  <32-byte-hex> \
  --amount-in  1000000000000000000 \
  --amount-in-decimals 18 \
  --asset-out <32-byte-hex> \
  --amount-out 500000 \
  --amount-out-decimals 6
FlagDescription
--networkApe network specifier, e.g. arbitrum:mainnet:alchemy
--accountYour Ape account alias for signing the on-chain transaction
--asset-in32-byte hex identifier of the token you are giving
--amount-inInteger amount of asset-in in its native token units
--amount-in-decimalsDecimal precision of asset-in (e.g. 18 for ETH-like tokens)
--asset-out32-byte hex identifier of the token you are receiving
--amount-outInteger amount of asset-out in its native token units
--amount-out-decimalsDecimal precision of asset-out (e.g. 6 for USDC)
--settler-executor <addr>Use when the registered settler is a contract, not an EOA

Settle in Python

For programmatic settlement, construct an Order object from tplus.utils.domain, sign it with your Ape account, and use the signature in your settlement submission.
from ape import accounts, convert, chain
from tplus.utils.domain import Order
from tplus.evm.contracts import vault
from tplus.utils.user import UserManager

# Load your Ethereum account registered with T+.
tplus_user = accounts.load("tplus-account")

# Load your T+ user public key.
user_id = UserManager.load("my_user").public_key

# Get the current nonce from the vault contract.
nonce = vault.getDepositNonce(tplus_user)

# Build the settlement order.
order = Order(
    tokenOut="0x62622E77D1349Face943C6e7D5c01C61465FE1dc",  # token you receive
    amountOut=convert("1 ether", int),                      # amount you receive (wei)
    tokenIn="0x58372ab62269A52fA636aD7F200d93999595DCAF",   # token you give up
    amountIn=convert("1 ether", int),                       # amount you give up (wei)
    userId=user_id,                                         # your T+ public key
    nonce=nonce,                                            # on-chain nonce from vault
    validUntil=chain.pending_timestamp,                     # expiry timestamp
)

# Sign using T+'s own signing scheme.
signature = tplus_user.sign_message(order).encode_rsv()
print("Settlement signature:", signature)

Understanding the Order fields

FieldTypeDescription
tokenOutstr (hex address)The token address you will receive on-chain
amountOutintAmount of tokenOut in its native decimals
tokenInstr (hex address)The token address you are giving up
amountInintAmount of tokenIn in its native decimals
userIdbytesYour T+ public key (from UserManager.load(...).public_key)
nonceintThe settlement nonce from vault.getDepositNonce(your_account)
validUntilintUnix timestamp after which the order is rejected
Use T+‘s own Order type and sign_message — not generic Ethereum typed-data tooling. T+ defines its own contract-level signing scheme. Passing a T+ Order to eth_account.sign_typed_data or similar will produce an invalid signature that the vault contract will reject.

Running settlement in an Ape console

You can prototype settlement interactively in an Ape console connected to the target network:
ape console --network arbitrum:mainnet:alchemy
Once in the console, the vault and registry contract objects are already available (injected by ape_console_extras.py), so you can call vault methods directly:
In [1]: from tplus.utils.user import UserManager
In [2]: user_id = UserManager.load("my_user").public_key
In [3]: vault.getDepositNonce(accounts.load("tplus-account"))
Out[3]: 3

EVM Contracts Reference

API reference for vault, registry, and other on-chain contract wrappers.

CLI Deposits & Withdrawals

CLI reference for deposit, withdrawal, and settlement subcommands.