# Contract architecture

The contracts behind a Maxy swap, what each enforces, and who can change them. It is for security reviewers and teams that read the chain themselves. Addresses: [Contracts](https://maxy.co/docs/contracts).

| Contract | Where | Enforces |
| --- | --- | --- |
| Settler (`BitcoinIntentSettler`) | One per EVM chain: Base, Arbitrum, BNB Chain, Avalanche, Robinhood Chain | Holds every escrow. Pays it out only against a verified Bitcoin payment, or back after a deadline |
| Verifier | One per EVM chain, read by that chain's settler | Tracks Bitcoin's header chain and checks payment proofs against it |
| Permit2 | The same address on every chain | Moves USDC on the gasless route, only as the user's signed witness allows |
| Solana settlement program | Solana | Holds SOL escrows, with its own Bitcoin node |

## The settler

The user signs an intent, an EIP-712 message on the domain `BitcoinIntentSettler`, version `6`, for that chain and that settler. Its hash is the order id, on chain and in the API. The settler enforces:

- **The intent.** Only the paying wallet (`maker`) can authorise an escrow, by signing the intent. The wallet, a solver on the gasless route or a contract caller can then open it, and each nonce is used once.
- **The price band.** When a solver commits, anything escrowed above the settlement amount goes straight back to the user.
- **The commit deadline.** A solver can commit only within 2 hours of the quote, and posts a bond when it does, 1% by default.
- **Four exits.** An escrow leaves only by these:

| Exit | To | When | Function |
| --- | --- | --- | --- |
| Settle | the solver | it proves it paid the BTC to the signed script, with the required confirmations | `fillIntentWithFeeToken` |
| Cancel | the user | no solver committed: the user any time, anyone after the escrow deadline | `cancelBuyEscrow`, `cancelNativeBuyEscrow` |
| Slash | the user, plus the bond | a solver committed and did not prove payment within the order's `settlementTimeoutBlocks`: 36 Bitcoin blocks, about 6 hours, on API orders | `slashExpired` |
| Refund | the user | the Bitcoin deadline passed and there was no bond | `refundExpired` |

Once their deadline has passed, cancel, slash and refund are open calls with no caller check: anyone may send them, and the coins go only to the user. A third party that sends a slash earns half the solver's bond, and a user who sends it keeps the whole bond. Pausing the settler never blocks them, so no escrow can be trapped. Who sends them in practice: [Refunds](https://maxy.co/docs/when-it-fails#refunds). 

## Each route on chain

| Route | The escrow is opened by | It is released by |
| --- | --- | --- |
| `evm-btc-escrow` | The user's wallet, with `openNativeBuyIntent` carrying the ETH, BNB or AVAX | The solver's proof of its BTC payment |
| `evm-btc-gasless` | The solver: Permit2 moves the user's USDC under the signed witness, and the solver pays the gas | The solver's proof of its BTC payment |
| `btc-evm` | The solver, locking the user's payout before any Bitcoin address is given | A proof of the user's BTC payment, which anyone may send, paying the user. Unpaid, it returns to the solver after the deadline |
| `sol-btc`, `btc-sol` | The Solana program, holding the user's or the solver's SOL | A payment proof checked by the program's Bitcoin node |

A contract can open an escrow for a user: see [Opening an escrow from a contract](https://maxy.co/docs/opening-an-escrow-from-a-contract).

## The verifier

The verifier is an on-chain Bitcoin node: a contract that validates and stores Bitcoin's block headers and checks payment proofs against them, for an output paying `scriptHash`, the script the user signed for: [Bitcoin verification](https://maxy.co/docs/bitcoin-verification).

## Who can change what

| Contract | Upgradeable | How |
| --- | --- | --- |
| Settler | Yes: an EIP-1967 transparent proxy | Upgrades go through a 48-hour timelock on all five chains |
| Settler settings | — | A governance role can allow or remove bond tokens and settlement assets; changes to the bond split are timelocked 72 hours |
| Settler pause | — | A pauser role can stop new escrows and commits. Pausing never blocks cancel, settle, slash or refund |
| Verifier | No: not a proxy | An admin can set the minimum confirmations (1 on every chain) and its settings |
| Solana settlement program | No: immutable | The upgrade authority is revoked. Governance roles are held by three multisigs |

No one can replace the settler's code in a hurry. Every upgrade passes through a 48-hour timelock on all five chains, so partners and users always have two days to review a change before it can take effect. Pausing the settler never blocks a cancel, a slash or a refund, so no escrow can be trapped. Every timelock and role, with addresses and a check: [Upgrades and roles](https://maxy.co/docs/upgrades-and-roles).

Maxy cannot move an escrow except by the four exits, sign for the user, or change what the user signed.

---
Source: https://maxy.co/docs/contract-architecture (Maxy Docs › Maxy architecture › Smart contracts)
