@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.
@@ -0,0 +1,22 @@
1
+ import type { Address, ContractFunctionArgs, Hex, PublicClient } from "viem";
2
+ import { automationAbi, rebalanceAbi } from "./abis.ts";
3
+ import type { Action } from "./actions.ts";
4
+ /**
5
+ * Module states, built and checked by each module's own encoder so the SDK never re-implements the layout.
6
+ * Enable a module with gate.setModule(module, true, state), and give the module (as actor) adapter access,
7
+ * markets and caps like an agent.
8
+ */
9
+ export declare const moduleState: {
10
+ /** The same action every `interval` seconds, `runs` times from `firstAt`; only `keeper` may trigger it. */
11
+ dca: (client: PublicClient, a: {
12
+ action: Action;
13
+ keeper: Address;
14
+ interval: bigint;
15
+ firstAt: bigint;
16
+ runs: number;
17
+ }) => Promise<Hex>;
18
+ /** Up to eight tasks: scheduled, recurring or price-triggered actions, each run by its own keeper. */
19
+ automation: (client: PublicClient, tasks: ContractFunctionArgs<typeof automationAbi, "pure", "encodeTasks">[0]) => Promise<Hex>;
20
+ /** Token pairs kept near a target share of their Chainlink value. */
21
+ rebalance: (client: PublicClient, pairs: ContractFunctionArgs<typeof rebalanceAbi, "pure", "encodePairs">[0]) => Promise<Hex>;
22
+ };
package/dist/root.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type Address, type Hex } from "viem";
2
+ /** One key of a vault's root: an ECDSA signer or a WebAuthn passkey (P-256 public key). */
3
+ export type RootMember = {
4
+ type: "ecdsa";
5
+ signer: Address;
6
+ } | {
7
+ type: "passkey";
8
+ x: Hex;
9
+ y: Hex;
10
+ };
11
+ /** A vault's root: one to ten keys and how many of them must sign. */
12
+ export interface Root {
13
+ members: RootMember[];
14
+ threshold: number;
15
+ }
16
+ /** The bytes MortiseRootValidator takes as a root: abi.encode(Member[] members, uint256 threshold). */
17
+ export declare function encodeRoot(root: Root): Hex;
18
+ /** The hash guardians approve and RecoveryReady reports for a new root. */
19
+ export declare function rootHash(root: Root): Hex;
20
+ /**
21
+ * A passkey member's signature: abi.encode(WebAuthnAuth) as Solady's WebAuthn decodes it. The assertion must
22
+ * be over the hash being signed (the userOp hash) as its challenge, with user verification.
23
+ */
24
+ export declare function encodePasskeySignature(a: {
25
+ authenticatorData: Hex;
26
+ clientDataJSON: string;
27
+ r: bigint;
28
+ s: bigint;
29
+ }): Hex;
30
+ /** A one-key ECDSA root. */
31
+ export declare function singleKeyRoot(signer: Address): Root;
32
+ /**
33
+ * The signature MortiseRootValidator expects from a root. A one-key root takes that key's signature as is.
34
+ * A larger root takes abi.encode(MemberSignature[]) with strictly increasing member indices.
35
+ */
36
+ export declare function encodeRootSignature(root: Root, signatures: {
37
+ index: number;
38
+ signature: Hex;
39
+ }[]): Hex;
@@ -0,0 +1,151 @@
1
+ import { type Account, type Address, type Chain, type Hex, type PublicClient, type Transport, type WalletClient } from "viem";
2
+ import { type Root } from "./root.ts";
3
+ /** One call the vault makes. */
4
+ export interface Call {
5
+ to: Address;
6
+ value?: bigint;
7
+ data?: Hex;
8
+ }
9
+ /** What a root userOp asks the vault to do. The root validator accepts only these three account functions. */
10
+ export type RootCall = {
11
+ kind: "execute";
12
+ calls: Call[];
13
+ } | {
14
+ kind: "installModule";
15
+ moduleType: bigint;
16
+ module: Address;
17
+ initData: Hex;
18
+ } | {
19
+ kind: "uninstallModule";
20
+ moduleType: bigint;
21
+ module: Address;
22
+ deInitData: Hex;
23
+ };
24
+ export declare const MODULE_TYPE: {
25
+ readonly validator: 1n;
26
+ readonly executor: 2n;
27
+ readonly fallback: 3n;
28
+ readonly hook: 4n;
29
+ };
30
+ export declare function encodeRootCall(c: RootCall): Hex;
31
+ /** EntryPoint v0.7 PackedUserOperation. */
32
+ export interface PackedUserOperation {
33
+ sender: Address;
34
+ nonce: bigint;
35
+ initCode: Hex;
36
+ callData: Hex;
37
+ accountGasLimits: Hex;
38
+ preVerificationGas: bigint;
39
+ gasFees: Hex;
40
+ paymasterAndData: Hex;
41
+ signature: Hex;
42
+ }
43
+ /** The unpacked fields a userOp is built from. */
44
+ export interface UserOperation {
45
+ sender: Address;
46
+ nonce: bigint;
47
+ factory?: Address;
48
+ factoryData?: Hex;
49
+ callData: Hex;
50
+ callGasLimit: bigint;
51
+ verificationGasLimit: bigint;
52
+ preVerificationGas: bigint;
53
+ maxFeePerGas: bigint;
54
+ maxPriorityFeePerGas: bigint;
55
+ paymaster?: Address;
56
+ paymasterVerificationGasLimit?: bigint;
57
+ paymasterPostOpGasLimit?: bigint;
58
+ paymasterData?: Hex;
59
+ signature: Hex;
60
+ }
61
+ export declare function packUserOp(op: UserOperation): PackedUserOperation;
62
+ /** The nonce of the vault's next root userOp: Safe7579 picks the validator from the nonce key. */
63
+ export declare function rootNonce(client: PublicClient, vault: Address): Promise<bigint>;
64
+ export declare function userOpHash(client: PublicClient, op: UserOperation): Promise<Hex>;
65
+ /**
66
+ * Runs the root call as the EntryPoint would, without a signature, and returns the gas it used. A revert here
67
+ * (for instance the timelock's NotScheduled) would also revert inside the userOp.
68
+ */
69
+ export declare function simulateRootCall(client: PublicClient, vault: Address, callData: Hex): Promise<bigint>;
70
+ /** A root call that failed, with the reason Safe7579 hid behind ExecutionFailed when it can be recovered. */
71
+ export declare class RootCallError extends Error {
72
+ /** Where the failure came from: the vault's hook (such as the timelock), one call of the batch, or a module's install. */
73
+ readonly source: "hook" | "call" | "install" | "account";
74
+ /** Index of the failing call in the batch, when source is "call". */
75
+ readonly callIndex: number | undefined;
76
+ /** The revert data that carries the reason; decode it with decodeMortiseError. */
77
+ readonly data: Hex | undefined;
78
+ constructor(message: string, source: "hook" | "call" | "install" | "account", data: Hex | undefined, cause: unknown, callIndex?: number);
79
+ }
80
+ /** A key that signs root userOps: its index in the root and how it signs a userOp hash. */
81
+ export interface RootKeySigner {
82
+ index: number;
83
+ sign(userOpHash: Hex): Promise<Hex>;
84
+ }
85
+ /** An ECDSA member signs the EIP-191 hash of the userOp hash. */
86
+ export declare function ecdsaRootSigner(index: number, account: {
87
+ signMessage(a: {
88
+ message: {
89
+ raw: Hex;
90
+ };
91
+ }): Promise<Hex>;
92
+ }): RootKeySigner;
93
+ /** Fields a gas sponsor adds; see ERC-4337 v0.7. */
94
+ export interface PaymasterFields {
95
+ paymaster: Address;
96
+ paymasterVerificationGasLimit: bigint;
97
+ paymasterPostOpGasLimit: bigint;
98
+ paymasterData: Hex;
99
+ }
100
+ export interface RootOpOptions {
101
+ /** The vault's root, to encode the signatures in the format it expects. */
102
+ root: Root;
103
+ signers: RootKeySigner[];
104
+ /** Creates the vault in the same userOp when it does not exist yet. */
105
+ create?: {
106
+ salt: bigint;
107
+ };
108
+ /**
109
+ * Asked for paymaster fields; required when the vault is in paymaster-only mode. With a bundler it is asked
110
+ * twice, as ERC-7677's pm_getPaymasterStubData and pm_getPaymasterData: `stub: true` before the gas estimate,
111
+ * for fields that need not validate, then `stub: false` over the final gas values.
112
+ */
113
+ paymaster?: (op: UserOperation, phase: {
114
+ stub: boolean;
115
+ }) => Promise<PaymasterFields>;
116
+ /** When set, gas and the priority fee come from this bundler's estimates (never lower than the SDK's own). */
117
+ bundlerUrl?: string;
118
+ /** Overrides for the gas fields. */
119
+ gas?: Partial<Pick<UserOperation, "callGasLimit" | "verificationGasLimit" | "preVerificationGas" | "maxFeePerGas" | "maxPriorityFeePerGas">>;
120
+ }
121
+ /**
122
+ * Builds and signs a root userOp. The call is simulated first; the signatures cover every field, including gas
123
+ * and paymaster, so nothing is changed after signing.
124
+ */
125
+ export declare function buildRootOp(client: PublicClient, vault: Address, call: RootCall, o: RootOpOptions): Promise<UserOperation>;
126
+ /** A signature of the right shape that fails validation without reverting, for gas estimation only. */
127
+ /**
128
+ * A signature of the right shape for gas estimation, for the members that will sign (by index; the first
129
+ * `threshold` members when not given), so the estimate runs the same validation path as the real one.
130
+ */
131
+ export declare function dummyRootSignature(root: Root, signerIndices?: number[]): Hex;
132
+ /** The outcome of a userOp, read from the EntryPoint's events. */
133
+ export interface UserOpResult {
134
+ userOpHash: Hex;
135
+ transactionHash: Hex;
136
+ success: boolean;
137
+ actualGasCost: bigint;
138
+ revertReason?: Hex;
139
+ }
140
+ /**
141
+ * Sends a signed userOp straight to the EntryPoint from an ordinary account, which acts as its own bundler and
142
+ * is paid the gas back by the vault (or the paymaster). No third-party bundler is needed.
143
+ */
144
+ export declare function sendUserOpDirect(client: PublicClient, wallet: WalletClient<Transport, Chain, Account>, op: UserOperation): Promise<UserOpResult>;
145
+ /** An error the bundler answered with, as opposed to one on the way to it. */
146
+ export declare class BundlerError extends Error {
147
+ readonly code: number;
148
+ constructor(method: string, code: number, message: string);
149
+ }
150
+ /** Sends a signed userOp through an ERC-4337 bundler (for Robinhood Chain, Alchemy's) and waits for it. */
151
+ export declare function sendUserOpToBundler(client: PublicClient, bundlerUrl: string, op: UserOperation, timeoutMs?: number): Promise<UserOpResult>;
@@ -0,0 +1,78 @@
1
+ import { type Account, type Address, type Chain, type Hex, type PublicClient, type Transport, type WalletClient } from "viem";
2
+ import { type Root, type RootMember } from "./root.ts";
3
+ type Wallet = WalletClient<Transport, Chain, Account>;
4
+ /** The address the vault for this root and salt has, whether or not it exists yet. */
5
+ export declare function predictVault(client: PublicClient, root: Root, salt: bigint): Promise<Address>;
6
+ /** Creates the vault in an ordinary transaction; anyone can pay for it. Returns its address. */
7
+ export declare function createVault(client: PublicClient, wallet: Wallet, root: Root, salt: bigint): Promise<Address>;
8
+ /**
9
+ * Deposits through the deposit router, which takes the fee and counts the vault's limit. A plain transfer to
10
+ * the vault also works but is not counted and pays no fee. For a token, approves the router for the amount first.
11
+ */
12
+ export declare function deposit(client: PublicClient, wallet: Wallet, vault: Address, token: Address, amount: bigint): Promise<Hex>;
13
+ /** What the router would take as fee and count toward the vault's limit for a deposit. */
14
+ export declare function depositQuote(client: PublicClient, vault: Address, token: Address, amount: bigint): Promise<{
15
+ fee: bigint;
16
+ net: bigint;
17
+ usdValue: bigint;
18
+ capUsd: bigint;
19
+ receivedUsd: bigint;
20
+ fitsCap: boolean;
21
+ }>;
22
+ /**
23
+ * Guardian side of recovery: a guardian approves replacing the vault's root with `next`. Once the threshold of
24
+ * guardians approve the same root, the delay starts (RecoveryReady); the root can cancel it until then.
25
+ */
26
+ export declare function approveRecovery(client: PublicClient, guardian: Wallet, vault: Address, next: Root): Promise<Hex>;
27
+ /** Applies an approved recovery once its delay has passed; anyone may send it. */
28
+ export declare function executeRecovery(client: PublicClient, wallet: Wallet, vault: Address, next: Root): Promise<Hex>;
29
+ /** One look at a vault: its root, recovery, modules and pause state. */
30
+ export declare function vaultStatus(client: PublicClient, vault: Address): Promise<{
31
+ exists: false;
32
+ vault: `0x${string}`;
33
+ root?: undefined;
34
+ recovery?: undefined;
35
+ paymasterOnly?: undefined;
36
+ gate?: undefined;
37
+ hook?: undefined;
38
+ timelock?: undefined;
39
+ family?: undefined;
40
+ modules?: undefined;
41
+ ethBalance?: undefined;
42
+ entryPointDeposit?: undefined;
43
+ } | {
44
+ exists: true;
45
+ vault: `0x${string}`;
46
+ root: {
47
+ members: RootMember[];
48
+ threshold: number;
49
+ };
50
+ recovery: {
51
+ guardians: readonly `0x${string}`[];
52
+ threshold: bigint;
53
+ delay: bigint;
54
+ };
55
+ paymasterOnly: boolean;
56
+ gate: {
57
+ installed: boolean;
58
+ paused: boolean;
59
+ pauser: `0x${string}`;
60
+ };
61
+ hook: `0x${string}`;
62
+ timelock: {
63
+ installed: boolean;
64
+ delay: number;
65
+ };
66
+ family: {
67
+ parent: `0x${string}` | undefined;
68
+ controller: `0x${string}` | undefined;
69
+ children: bigint;
70
+ };
71
+ modules: {
72
+ subVaults: boolean;
73
+ signer: boolean;
74
+ };
75
+ ethBalance: bigint;
76
+ entryPointDeposit: bigint;
77
+ }>;
78
+ export {};
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@mortiseagentvault/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "TypeScript SDK for Mortise, the non-custodial vault for AI agents on Robinhood Chain.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "mortise",
8
+ "robinhood-chain",
9
+ "vault",
10
+ "ai-agents",
11
+ "erc-4337",
12
+ "erc-7579",
13
+ "safe",
14
+ "viem"
15
+ ],
16
+ "homepage": "https://github.com/mortiseagentvault/mortise#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/mortiseagentvault/mortise/issues"
19
+ },
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "sideEffects": false,
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "scripts": {
38
+ "abis": "node scripts/abis.mjs",
39
+ "build": "node scripts/build.mjs",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit",
41
+ "test": "node --experimental-strip-types --no-warnings --test --test-concurrency=1 test/*.test.ts",
42
+ "prepublishOnly": "npm run build"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/mortiseagentvault/mortise.git",
47
+ "directory": "sdk"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "22.20.7",
51
+ "esbuild": "0.28.2",
52
+ "typescript": "5.9.3",
53
+ "viem": "2.58.8"
54
+ }
55
+ }