Find something... ⌘K

Maxy architecture / Smart contracts

Opening an escrow from a contract

How a router, or any other contract, opens a Maxy escrow for its user, who is refunded, and which wallets can sign. It is for teams that send bridge calls through their own contracts.

Maxy supports routers that call the settler from their own contracts. The settler has an entry point for third-party callers and records a refund recipient for each order, so a refund returns to the user and not to the router. Contract accounts can act as the paying party through EIP-1271.

Which function a contract calls

openBuyEscrowFor, in two forms. Both are on the settler implementation of all five EVM chains:

solidity Copy
// selector 0x8aa5b6b5 function openBuyEscrowFor(Intent intent, bytes scriptPubKey, OracleConfig oracleConfig, bytes signature) external payable returns (bytes32 intentHash); // selector 0xf9e218ec function openBuyEscrowFor(Intent intent, bytes scriptPubKey, OracleConfig oracleConfig, bytes signature, address refundRecipient) external payable returns (bytes32 intentHash); // Intent = (uint8 side, address maker, address asset, bytes32 scriptHash, uint64 satAmount, address designatedFiller, // uint8 pricingMode, uint256 limitPrice, uint256 startPrice, uint256 endPrice, uint64 decayStartTime, uint64 decayEndTime, // uint16 slippageBps, uint16 oracleDiscountBps, uint16 bondBps, uint16 requiredConfirmations, uint32 settlementTimeoutBlocks, // uint64 deadline, uint256 nonce, bytes32 oracleConfigHash) // OracleConfig = (address[3] feeds, uint8 feedCount, uint64 maxAge)
  • The caller pays. ETH, BNB or AVAX goes in as msg.value, exactly the deposit. A token is pulled from the caller with transferFrom, so the caller approves the settler first. The settler checks the exact amount either way.
  • The order id comes back. The call returns the intent hash, and the settler emits BuyEscrowOpened(intentHash, maker, asset, amount) and BuyEscrowRefundRecipientSet(intentHash, refundRecipient).
  • Pause. While the settler is paused, new escrows stop. Cancel, slash and refund never do.

Who is refunded

MoneyGoes to
The price-band excess, when a solver commitsThe refund recipient, in the commit transaction
The escrow, on cancel, slash or refundThe refund recipient
The solver's bond, on a slashA third party that sends a slash earns half the solver's bond, and a user who sends it keeps the whole bond.

The four-argument form always records the maker as refund recipient. The five-argument form accepts another address only when the maker is a contract calling for itself; zero or the maker's own address means the maker, and anything else reverts with InvalidRefundRecipient(). A router that opens an escrow for its user therefore cannot redirect that user's refund.

From the API. Name the user on the quote: GET /quote?…&fromAddress=<contract>&refundRecipient=<user>. Without refundRecipient the settler refunds the contract itself. POST /orders then answers the contract's openBuyEscrowFor call with that recipient.

Does an escrow with no POST /orders get filled?

Only when the opening transaction is the settler call itself. The solver watches every settler for NativeBuyEscrowOpened and BuyEscrowOpened (Base every few seconds, the other chains about every 15 seconds). The event has no signature or Bitcoin script, so the solver reads them from the transaction's input, which must be one of the open functions below sent straight to the settler.

An escrow opened inside another contract's call (a router, a Safe's execTransaction, an ERC-4337 bundle) shows only that outer call, so the solver does not fill it. A contract integrator calls POST /orders/submit once the transaction is mined, with the quote's order, the contract's signature and the transaction hash; the solver commits at once. Otherwise the escrow goes back to its refund recipient with a cancel after its deadline.

Every open function needs the maker's signature

All four open functions run BitcoinIntentIntakeLib.openBuyEscrow, which reverts BadSignature() unless signature is the maker's over the intent's EIP-712 hash: ECDSA for a maker with no code, otherwise isValidSignature(hash, signature) returning 0x1626ba7e (EIP-1271). There is no unsigned open.

FunctionCaller
openBuyEscrowFor(intent, scriptPubKey, oracleConfig, signature)Anyone; refunds go to the maker
openBuyEscrowFor(…, signature, refundRecipient)Anyone; another recipient only when the maker calls
openNativeBuyIntent(intent, scriptPubKey, oracleConfig, signature)The maker only, native coin
openNativeBuyEscrow(intent, scriptPubKey, oracleConfig, signature)The maker only, native coin

A contract maker is the one-call eip1271 escrow: a quote with the contract as fromAddress answers signing.kind: eip1271. Any contract can be a maker, with no allowlist, and an empty signature works when its own check accepts it; Maxy's loan contract opens its orders that way. A minimal maker approves only the intent it is opening. hash is the quote's intent step hash, and settlerCall is transaction.data from POST /orders, sent with signature 0x:

solidity Copy
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract MaxyMaker { address public immutable owner = msg.sender; address public immutable settler; bytes32 private approved; constructor(address settler_) { settler = settler_; } function open(bytes32 hash, bytes calldata settlerCall) external payable { require(msg.sender == owner, "owner only"); approved = hash; (bool ok, ) = settler.call{value: msg.value}(settlerCall); delete approved; require(ok, "settler refused the open"); } // EIP-1271: the settler asks this during the open. function isValidSignature(bytes32 hash, bytes calldata) external view returns (bytes4) { return hash != bytes32(0) && hash == approved ? bytes4(0x1626ba7e) : bytes4(0xffffffff); } }

Delegated wallets and smart accounts

  • Smart accounts, such as a Safe or an ERC-4337 wallet, sign through EIP-1271: the intent, and on the gasless route the Permit2 witness, since Permit2 applies the same rule.
  • EIP-7702 wallets have code, so the settler and Permit2 call the delegate's isValidSignature rather than recovering the key. A signature from the wallet's own key works when the delegate accepts that key in isValidSignature.

A worked example

A router contract takes ETH from the user and opens the escrow with the user as maker, who signed the intent from GET /quote, so every refund goes back to the user.

solidity Copy
event MaxyOrder(bytes32 indexed orderId, address indexed user); function buyBtcFor(Intent calldata intent, bytes calldata scriptPubKey, OracleConfig calldata oracleConfig, bytes calldata userSig) external payable returns (bytes32 orderId) { require(intent.maker == msg.sender, "the user is the maker"); orderId = SETTLER.openBuyEscrowFor{value: msg.value}(intent, scriptPubKey, oracleConfig, userSig); emit MaxyOrder(orderId, msg.sender); // refunds go to intent.maker: the user }

Agree the setup for a contract route with your Maxy contact before you send live orders through it.

The calls in a router's order: Router flow. Every exit an escrow has: Contract architecture.