@mortiseagentvault/sdk 0.1.1 → 0.2.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/README.md +43 -3
- package/dist/abis.d.ts +3438 -0
- package/dist/actions.d.ts +255 -0
- package/dist/addresses.d.ts +21 -0
- package/dist/calls.d.ts +18 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +395 -5
- package/dist/modules.d.ts +14 -1
- package/dist/x402.d.ts +68 -0
- package/package.json +3 -1
package/dist/modules.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address, ContractFunctionArgs, Hex, PublicClient } from "viem";
|
|
2
|
-
import { automationAbi, rebalanceAbi } from "./abis.ts";
|
|
2
|
+
import { automationAbi, compoundAbi, rebalanceAbi } from "./abis.ts";
|
|
3
3
|
import type { Action } from "./actions.ts";
|
|
4
4
|
/**
|
|
5
5
|
* Module states, built and checked by each module's own encoder so the SDK never re-implements the layout.
|
|
@@ -19,4 +19,17 @@ export declare const moduleState: {
|
|
|
19
19
|
automation: (client: PublicClient, tasks: ContractFunctionArgs<typeof automationAbi, "pure", "encodeTasks">[0]) => Promise<Hex>;
|
|
20
20
|
/** Token pairs kept near a target share of their Chainlink value. */
|
|
21
21
|
rebalance: (client: PublicClient, pairs: ContractFunctionArgs<typeof rebalanceAbi, "pure", "encodePairs">[0]) => Promise<Hex>;
|
|
22
|
+
/**
|
|
23
|
+
* Up to eight liquidity positions whose fees go back in, in two triggers per round: collect, then deposit what the
|
|
24
|
+
* balances rose by. The deposit action is a template whose 32-byte words `word0` and `word1` hold zero; see
|
|
25
|
+
* compoundWords. collectedAt, base0 and base1 must be zero.
|
|
26
|
+
*/
|
|
27
|
+
compound: (client: PublicClient, positions: ContractFunctionArgs<typeof compoundAbi, "pure", "encodePositions">[0]) => Promise<Hex>;
|
|
28
|
+
};
|
|
29
|
+
/** The words of an `increase` action (uniswapV3Liquidity, aeroLiquidity) where CompoundModule writes amount0 and amount1. */
|
|
30
|
+
export declare const compoundWords: {
|
|
31
|
+
readonly increase: {
|
|
32
|
+
readonly word0: 5;
|
|
33
|
+
readonly word1: 6;
|
|
34
|
+
};
|
|
22
35
|
};
|
package/dist/x402.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Account, type Address, type Chain, type Hex, type PublicClient, type Transport, type WalletClient } from "viem";
|
|
2
|
+
import { type ActionReceipt, type SendOptions } from "./agent.ts";
|
|
3
|
+
type Wallet = WalletClient<Transport, Chain, Account>;
|
|
4
|
+
/** One entry of a server's x402 `accepts`, as v2 (amount) or v1 (maxAmountRequired) sends it. */
|
|
5
|
+
export interface X402Requirement {
|
|
6
|
+
scheme: string;
|
|
7
|
+
network: string;
|
|
8
|
+
amount?: string;
|
|
9
|
+
maxAmountRequired?: string;
|
|
10
|
+
asset: string;
|
|
11
|
+
payTo: string;
|
|
12
|
+
maxTimeoutSeconds?: number;
|
|
13
|
+
extra?: Record<string, unknown>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** What a server asked for in its 402 answer: the version, every option, and the resource (v2). */
|
|
17
|
+
export interface X402Required {
|
|
18
|
+
x402Version: number;
|
|
19
|
+
accepts: X402Requirement[];
|
|
20
|
+
resource?: unknown;
|
|
21
|
+
extensions?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Reads a 402 answer: the PAYMENT-REQUIRED header (v2), or the JSON body (v1). */
|
|
24
|
+
export declare function x402Required(headers: Headers, body: unknown): X402Required;
|
|
25
|
+
/** The option a Mortise vault can pay: exact scheme, Robinhood Chain, USDG. */
|
|
26
|
+
export declare function robinhoodUsdg(required: X402Required): X402Requirement;
|
|
27
|
+
/**
|
|
28
|
+
* The fields of one payment for a requirement, valid from 10 minutes ago until the server's timeout (at most an hour).
|
|
29
|
+
* The window holds by the chain's clock, which the escrow reads, and by this machine's, which a facilitator reads.
|
|
30
|
+
*/
|
|
31
|
+
export declare function x402Terms(r: X402Requirement, chainNow: bigint): {
|
|
32
|
+
to: `0x${string}`;
|
|
33
|
+
value: bigint;
|
|
34
|
+
validAfter: bigint;
|
|
35
|
+
validBefore: bigint;
|
|
36
|
+
nonce: `0x${string}`;
|
|
37
|
+
};
|
|
38
|
+
/** The request header that carries a payment funded in the escrow: PAYMENT-SIGNATURE (v2) or X-PAYMENT (v1). */
|
|
39
|
+
export declare function x402Header(required: X402Required, r: X402Requirement, terms: ReturnType<typeof x402Terms>): Record<string, string>;
|
|
40
|
+
/** The server's settlement answer, from PAYMENT-RESPONSE (v2) or X-PAYMENT-RESPONSE (v1), if it sent one. */
|
|
41
|
+
export declare function x402Settlement(headers: Headers): Record<string, unknown> | undefined;
|
|
42
|
+
/** Whether USDG has marked the escrow's authorization used, which is what a collected payment leaves behind. */
|
|
43
|
+
export declare function x402Collected(client: PublicClient, nonce: Hex): Promise<boolean>;
|
|
44
|
+
/** A failure after the payment's terms were fixed: `terms.nonce` is what x402Escrow.reclaim needs if it was funded. */
|
|
45
|
+
export declare class X402PaymentError extends Error {
|
|
46
|
+
readonly terms: ReturnType<typeof x402Terms>;
|
|
47
|
+
constructor(message: string, terms: ReturnType<typeof x402Terms>, cause: unknown);
|
|
48
|
+
}
|
|
49
|
+
export interface X402Result {
|
|
50
|
+
status: number;
|
|
51
|
+
body: string;
|
|
52
|
+
/** Whether the server collected the payment; if not, x402Escrow.reclaim(nonce) returns it after validBefore. */
|
|
53
|
+
collected: boolean;
|
|
54
|
+
settlement?: Record<string, unknown>;
|
|
55
|
+
funding: ActionReceipt;
|
|
56
|
+
terms: ReturnType<typeof x402Terms>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Pays an x402 resource from the vault through MortiseX402Escrow, as the agent: reads the 402 answer, funds one payment
|
|
60
|
+
* to the payee the owner listed, and asks again with the payment. The server's facilitator must accept a contract
|
|
61
|
+
* payer (ERC-1271), as the official @x402/evm facilitator does. Refuses a price above `maxValue` (USDG raw units).
|
|
62
|
+
*/
|
|
63
|
+
export declare function payX402(client: PublicClient, wallet: Wallet, vault: Address, url: string, o: {
|
|
64
|
+
init?: RequestInit;
|
|
65
|
+
maxValue: bigint;
|
|
66
|
+
send?: SendOptions;
|
|
67
|
+
}): Promise<X402Result>;
|
|
68
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mortiseagentvault/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for Mortise, the non-custodial vault for AI agents on Robinhood Chain.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "22.20.7",
|
|
51
|
+
"@x402/core": "2.33.0",
|
|
52
|
+
"@x402/evm": "2.33.0",
|
|
51
53
|
"esbuild": "0.28.2",
|
|
52
54
|
"typescript": "5.9.3",
|
|
53
55
|
"viem": "2.58.8"
|