@mortiseagentvault/sdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mortise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # Mortise SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript client for [Mortise](../README.md) vaults on Robinhood Chain (chain id 4663). It builds on
4
+ [viem](https://viem.sh) and covers both sides of a vault:
5
+
6
+ - **Owner side.** Root userOps for ERC-4337 EntryPoint v0.7: vault creation, Gate settings, the timelock,
7
+ sub-vaults, recovery and gas-sponsor mode, signed by one key, several keys or a passkey.
8
+ - **Agent side.** Actions for every adapter, simulation, execution through the Gate, module triggers and a
9
+ read of what an agent may still do.
10
+
11
+ The addresses of the deployed contracts are built in; see [`deployments/4663.json`](../deployments/4663.json).
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @mortiseagentvault/sdk viem
17
+ ```
18
+
19
+ Requires Node.js 20 or later.
20
+
21
+ ## Owner: create a vault and add an agent
22
+
23
+ The first root userOp deploys the vault and configures it in one step.
24
+
25
+ ```ts
26
+ import { createPublicClient, createWalletClient, http, parseEther } from "viem";
27
+ import { privateKeyToAccount } from "viem/accounts";
28
+ import {
29
+ ETH, robinhood, mortise, markets, gate, singleKeyRoot, ecdsaRootSigner,
30
+ predictVault, buildRootOp, sendUserOpToBundler,
31
+ } from "@mortiseagentvault/sdk";
32
+
33
+ const client = createPublicClient({ chain: robinhood, transport: http(RPC_URL) });
34
+ const owner = privateKeyToAccount(OWNER_KEY);
35
+ const root = singleKeyRoot(owner.address);
36
+ const vault = await predictVault(client, root, 0n);
37
+ // Fund `vault` with ETH for gas (or use a paymaster), then:
38
+
39
+ const day = 86_400n;
40
+ const until = (await client.getBlock()).timestamp + 30n * day;
41
+ const op = await buildRootOp(
42
+ client,
43
+ vault,
44
+ {
45
+ kind: "execute",
46
+ calls: [
47
+ gate.setAgent(AGENT, until),
48
+ gate.setAdapterAccess(AGENT, mortise.weth, true),
49
+ gate.setMarket(mortise.weth, markets.weth(), true),
50
+ gate.setCap(AGENT, ETH, parseEther("0.1"), day),
51
+ ],
52
+ },
53
+ { root, signers: [ecdsaRootSigner(0, owner)], create: { salt: 0n }, bundlerUrl: BUNDLER_URL },
54
+ );
55
+ const result = await sendUserOpToBundler(client, BUNDLER_URL, op);
56
+ ```
57
+
58
+ A root of several keys is `{ members: [...], threshold }`. Each signer passes its index in the root, and
59
+ `encodeRootSignature` orders the signatures as the root validator expects. Passkey members sign WebAuthn
60
+ assertions; `encodePasskeySignature` packs one and normalises `s` to the low half of the curve order.
61
+
62
+ Guardians set with `root.setGuardians` can replace a lost root: each one calls `approveRecovery` from its own
63
+ key, and once the threshold approves and the delay has passed, anyone calls `executeRecovery`. The root can
64
+ cancel a pending recovery with `root.cancelRecovery` until then.
65
+
66
+ ## Agent: act inside the limits
67
+
68
+ The agent uses its own key, sends transactions to the Gate and pays its own gas. It never holds the
69
+ vault's funds or its root keys.
70
+
71
+ ```ts
72
+ import { actions, simulateActions, executeActions, permissions, mortiseErrorName } from "@mortiseagentvault/sdk";
73
+
74
+ const wrap = [actions.weth({ wrap: true, amount: parseEther("0.01") })];
75
+ try {
76
+ await simulateActions(client, agent.address, vault, wrap);
77
+ } catch (err) {
78
+ console.log(mortiseErrorName(err)); // e.g. "CapExceeded", "MarketNotAllowed", "NotAgent"
79
+ }
80
+ const receipt = await executeActions(client, agentWallet, vault, wrap);
81
+ const p = await permissions(client, vault, agent.address, { adapters: [mortise.weth], tokens: [ETH] });
82
+ ```
83
+
84
+ `actions.*` encodes the input of each adapter: Uniswap v3 and v4 swaps and positions, Morpho Blue,
85
+ ERC-4626, Pons, Flap, Across, WETH, listed transfers and family transfers. `markets.*` gives the
86
+ market id the owner allows for each of them.
87
+
88
+ ## Errors
89
+
90
+ Contract errors decode by name with `mortiseErrorName` and `decodeMortiseError`. Safe7579 reports a
91
+ failing hook, or a failing call inside a batch, as a bare `ExecutionFailed`. `simulateRootCall` then
92
+ recovers the reason itself and throws a `RootCallError` that names the source: the vault's hook (for
93
+ example the timelock's `NotScheduled`), the index of the failing call in the batch, or the module that
94
+ refused to install.
95
+
96
+ ## Tests
97
+
98
+ The tests run against the live Mortise contracts on a local fork of Robinhood Chain mainnet. Nothing is
99
+ mocked. They need Node.js 22.6 or later and [Foundry](https://book.getfoundry.sh)'s `anvil` on the `PATH`.
100
+
101
+ ```sh
102
+ npm install
103
+ npm test # forks the public RPC
104
+ FORK_RPC=<url> npm test # or a private RPC
105
+ ```
106
+
107
+ ## License
108
+
109
+ MIT