@mortiseagentvault/sdk 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +122 -2
- package/dist/THIRD_PARTY_NOTICES.txt +79 -0
- package/dist/abis.d.ts +7430 -0
- package/dist/actions.d.ts +173 -0
- package/dist/addresses.d.ts +41 -0
- package/dist/agent.d.ts +91 -0
- package/dist/calls.d.ts +70 -0
- package/dist/errors.d.ts +13 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +4272 -0
- package/dist/modules.d.ts +22 -0
- package/dist/root.d.ts +39 -0
- package/dist/userop.d.ts +151 -0
- package/dist/vault.d.ts +78 -0
- package/package.json +53 -4
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,123 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mortise SDK
|
|
2
2
|
|
|
3
|
-
|
|
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. The package is a single bundled module with no runtime dependencies: it
|
|
20
|
+
carries the parts of viem it uses, and its types expect the viem clients you create yourself. The
|
|
21
|
+
licenses of the bundled code are in `dist/THIRD_PARTY_NOTICES.txt`.
|
|
22
|
+
|
|
23
|
+
viem itself pins `ws` 8.21.0, which `npm audit` reports
|
|
24
|
+
([GHSA-37g9-w4hg-h9qr](https://github.com/advisories/GHSA-37g9-w4hg-h9qr)); `ws` is only loaded by viem's
|
|
25
|
+
WebSocket transport. The SDK's bundle contains no `ws` code; your project loads `ws` only if you create a
|
|
26
|
+
viem WebSocket client yourself. To move your project to the patched release, add this to its `package.json`:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
"overrides": { "ws": "^8.23.1" }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Owner: create a vault and add an agent
|
|
33
|
+
|
|
34
|
+
The first root userOp deploys the vault and configures it in one step.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
|
|
38
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
39
|
+
import {
|
|
40
|
+
ETH, robinhood, mortise, markets, gate, singleKeyRoot, ecdsaRootSigner,
|
|
41
|
+
predictVault, buildRootOp, sendUserOpToBundler,
|
|
42
|
+
} from "@mortiseagentvault/sdk";
|
|
43
|
+
|
|
44
|
+
const client = createPublicClient({ chain: robinhood, transport: http(RPC_URL) });
|
|
45
|
+
const owner = privateKeyToAccount(OWNER_KEY);
|
|
46
|
+
const root = singleKeyRoot(owner.address);
|
|
47
|
+
const vault = await predictVault(client, root, 0n);
|
|
48
|
+
// Fund `vault` with ETH for gas (or use a paymaster), then:
|
|
49
|
+
|
|
50
|
+
const day = 86_400n;
|
|
51
|
+
const until = (await client.getBlock()).timestamp + 30n * day;
|
|
52
|
+
const op = await buildRootOp(
|
|
53
|
+
client,
|
|
54
|
+
vault,
|
|
55
|
+
{
|
|
56
|
+
kind: "execute",
|
|
57
|
+
calls: [
|
|
58
|
+
gate.setAgent(AGENT, until),
|
|
59
|
+
gate.setAdapterAccess(AGENT, mortise.weth, true),
|
|
60
|
+
gate.setMarket(mortise.weth, markets.weth(), true),
|
|
61
|
+
gate.setCap(AGENT, ETH, parseEther("0.1"), day),
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{ root, signers: [ecdsaRootSigner(0, owner)], create: { salt: 0n }, bundlerUrl: BUNDLER_URL },
|
|
65
|
+
);
|
|
66
|
+
const result = await sendUserOpToBundler(client, BUNDLER_URL, op);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
A root of several keys is `{ members: [...], threshold }`. Each signer passes its index in the root, and
|
|
70
|
+
`encodeRootSignature` orders the signatures as the root validator expects. Passkey members sign WebAuthn
|
|
71
|
+
assertions; `encodePasskeySignature` packs one and normalises `s` to the low half of the curve order.
|
|
72
|
+
|
|
73
|
+
Guardians set with `root.setGuardians` can replace a lost root: each one calls `approveRecovery` from its own
|
|
74
|
+
key, and once the threshold approves and the delay has passed, anyone calls `executeRecovery`. The root can
|
|
75
|
+
cancel a pending recovery with `root.cancelRecovery` until then.
|
|
76
|
+
|
|
77
|
+
## Agent: act inside the limits
|
|
78
|
+
|
|
79
|
+
The agent uses its own key, sends transactions to the Gate and pays its own gas. It never holds the
|
|
80
|
+
vault's funds or its root keys.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { actions, simulateActions, executeActions, permissions, mortiseErrorName } from "@mortiseagentvault/sdk";
|
|
84
|
+
|
|
85
|
+
const wrap = [actions.weth({ wrap: true, amount: parseEther("0.01") })];
|
|
86
|
+
try {
|
|
87
|
+
await simulateActions(client, agent.address, vault, wrap);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.log(mortiseErrorName(err)); // e.g. "CapExceeded", "MarketNotAllowed", "NotAgent"
|
|
90
|
+
}
|
|
91
|
+
const receipt = await executeActions(client, agentWallet, vault, wrap);
|
|
92
|
+
const p = await permissions(client, vault, agent.address, { adapters: [mortise.weth], tokens: [ETH] });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`actions.*` encodes the input of each adapter: Uniswap v3 and v4 swaps and positions, Morpho Blue,
|
|
96
|
+
ERC-4626, Pons, Flap, Across, WETH, listed transfers and family transfers. `markets.*` gives the
|
|
97
|
+
market id the owner allows for each of them.
|
|
98
|
+
|
|
99
|
+
## Errors
|
|
100
|
+
|
|
101
|
+
Contract errors decode by name with `mortiseErrorName` and `decodeMortiseError`. Safe7579 reports a
|
|
102
|
+
failing hook, or a failing call inside a batch, as a bare `ExecutionFailed`. `simulateRootCall` then
|
|
103
|
+
recovers the reason itself and throws a `RootCallError` that names the source: the vault's hook (for
|
|
104
|
+
example the timelock's `NotScheduled`), the index of the failing call in the batch, or the module that
|
|
105
|
+
refused to install.
|
|
106
|
+
|
|
107
|
+
## Tests
|
|
108
|
+
|
|
109
|
+
The tests run against the live Mortise contracts on a local fork of Robinhood Chain mainnet. Nothing is
|
|
110
|
+
mocked. They need Node.js 22.6 or later and [Foundry](https://book.getfoundry.sh)'s `anvil` on the `PATH`.
|
|
111
|
+
|
|
112
|
+
The tests import the built package, so build it first:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
npm install
|
|
116
|
+
npm run build
|
|
117
|
+
npm test # forks the public RPC
|
|
118
|
+
FORK_RPC=<url> npm test # or a private RPC
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
This package bundles the following third-party code. Their licenses follow.
|
|
2
|
+
|
|
3
|
+
------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
@noble/hashes@1.8.0 (MIT)
|
|
6
|
+
|
|
7
|
+
The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in
|
|
19
|
+
all copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
27
|
+
THE SOFTWARE.
|
|
28
|
+
|
|
29
|
+
------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
abitype@1.2.3 (MIT)
|
|
32
|
+
|
|
33
|
+
MIT License
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2022-present weth, LLC
|
|
36
|
+
|
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
38
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
39
|
+
in the Software without restriction, including without limitation the rights
|
|
40
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
41
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
42
|
+
furnished to do so, subject to the following conditions:
|
|
43
|
+
|
|
44
|
+
The above copyright notice and this permission notice shall be included in all
|
|
45
|
+
copies or substantial portions of the Software.
|
|
46
|
+
|
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
50
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
51
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
52
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
53
|
+
SOFTWARE.
|
|
54
|
+
|
|
55
|
+
------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
viem@2.58.8 (MIT)
|
|
58
|
+
|
|
59
|
+
MIT License
|
|
60
|
+
|
|
61
|
+
Copyright (c) 2023-present weth, LLC
|
|
62
|
+
|
|
63
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
64
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
65
|
+
in the Software without restriction, including without limitation the rights
|
|
66
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
67
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
68
|
+
furnished to do so, subject to the following conditions:
|
|
69
|
+
|
|
70
|
+
The above copyright notice and this permission notice shall be included in all
|
|
71
|
+
copies or substantial portions of the Software.
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
75
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
76
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
77
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
78
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
79
|
+
SOFTWARE.
|