Docs

Developers

Writing a module

A piece is either an adapter, which connects the vault to a protocol, or a strategy module, which proposes actions on its own. Both are plain contracts with no access to the vault: they return plans, and the Gate decides what runs.

Adapters

An adapter has two view functions. rules returns every call shape it can ever emit, as a target and a selector. plan turns one action's input into the market, the calls and the tokens they can move. Adapters are called with STATICCALL and never hold funds.

IMortise.sol
struct Action { address adapter; bytes data; }

struct CallRule {
    address target;   // a contract, ANY_TOKEN (address(0)) or ANY_FAMILY_VAULT (address(1))
    bytes4 selector;  // bytes4(0) matches empty calldata only
}

struct Plan {
    bytes32 market;       // must be listed for this adapter, unless open markets are on
    Execution[] calls;    // run in order, as one batch, by the vault
    address[] tokens;     // every token the calls can move; address(0) is ETH
    bool isSwap;          // true: the Gate checks the floor for swapIn -> swapOut
    address swapIn;
    address swapOut;
}

interface IMortiseAdapter {
    function rules() external view returns (CallRule[] memory);
    function plan(address vault, bytes calldata data) external view returns (Plan memory);
}

Strategy modules

A strategy module keeps no state of its own. The Gate stores it per vault and passes it in. When someone calls the Gate's trigger, the module returns the actions to run now and its next state. It learns who triggered it, so it can accept only the keeper the owner named.

IMortise.sol
interface IMortiseModule {
    /// Called with STATICCALL. caller is whoever called the Gate's trigger.
    function propose(address vault, address caller, bytes calldata state)
        external
        view
        returns (Action[] memory actions, bytes memory nextState);
}

What the Gate holds them to

  • Every call must match one of the adapter's rules, and no call may target the vault, the Gate, Safe7579, the EntryPoint or an installed module.
  • Every token that moves must be declared, and every decrease counts against the cap of the agent or module.
  • Swaps must return at least the owner's floor, and every approval must end at zero.
  • A module's actions pass exactly the same checks as an agent's.
Rules decide what a piece can do

The Gate enforces the rules an adapter declares, but the adapter chooses them. An adapter that declares a plain token transfer can send tokens anywhere within the caps. The guarantee that outputs only reach the vault, its family or listed recipients covers the adapters Mortise ships. Only allow an adapter whose source you have read.

Listing a piece

The app's catalog shows the pieces Mortise ships. A community piece can be listed when its source is verified on the explorer, it has no upgrade proxy, and its code hash is recorded at listing, so a later change to the code at that address would show. To submit one, open an issue on the GitHub repository with the address and the source.