@mangrove-ai/sdk 0.2.0 → 1.0.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/dist/index.d.cts DELETED
@@ -1,371 +0,0 @@
1
- /**
2
- * Fee billing mode. 'standard' bakes fee into swap; 'x402' pays separately for better output.
3
- */
4
- type BillingMode = 'standard' | 'x402';
5
- /**
6
- * Server-issued swap quote with pricing, fees, and expiry.
7
- */
8
- interface Quote {
9
- /** Unique quote identifier, valid until expiresAt. */
10
- quoteId: string;
11
- /** DEX venue that will execute the swap (e.g. '1inch'). */
12
- venueId: string;
13
- /** Contract address of the token being sold. */
14
- inputToken: string;
15
- /** Contract address of the token being bought. */
16
- outputToken: string;
17
- /** Amount of input token in smallest unit (wei). */
18
- inputAmount: string;
19
- /** Expected amount of output token in smallest unit (wei). */
20
- outputAmount: string;
21
- /** Mangrove fee amount in smallest unit of input token. */
22
- mangroveFee: string;
23
- /** EVM chain ID where the swap will execute. */
24
- chainId: number;
25
- /** Billing mode used for this quote. */
26
- billingMode: BillingMode;
27
- /** Ordered list of DEX routes the aggregator will use. */
28
- routes: string[];
29
- /** ISO 8601 timestamp after which this quote is no longer valid. */
30
- expiresAt: string;
31
- }
32
- /**
33
- * Chain-agnostic unsigned transaction calldata. Agent signs locally.
34
- */
35
- interface UnsignedTransaction {
36
- /** EVM chain ID for the transaction. */
37
- chainId: number;
38
- /** Target contract address. */
39
- to: string;
40
- /** ABI-encoded calldata. */
41
- data: string;
42
- /** Native token value to send (wei). */
43
- value: string;
44
- /** Gas limit for the transaction. */
45
- gas: string;
46
- /** Transaction nonce (sequence number). */
47
- nonce?: number;
48
- /** Legacy gas price (wei). Mutually exclusive with EIP-1559 fields. */
49
- gasPrice?: string;
50
- /** EIP-1559 max fee per gas (wei). */
51
- maxFeePerGas?: string;
52
- /** EIP-1559 max priority fee per gas (wei). */
53
- maxPriorityFeePerGas?: string;
54
- }
55
- /**
56
- * Result returned after broadcasting a signed transaction.
57
- */
58
- interface BroadcastResult {
59
- /** Transaction hash of the broadcasted transaction. */
60
- txHash: string;
61
- /** Chain ID the transaction was broadcast on. */
62
- chainId: number;
63
- /** Method used to broadcast (e.g. 'public', 'flashbots'). */
64
- broadcastMethod: string;
65
- }
66
- /**
67
- * Current status of an on-chain transaction.
68
- */
69
- interface TransactionStatus {
70
- /** Transaction hash being tracked. */
71
- txHash: string;
72
- /** Chain ID the transaction is on. */
73
- chainId: number;
74
- /** Current transaction status. */
75
- status: 'pending' | 'confirmed' | 'failed';
76
- /** Block number the transaction was included in, if confirmed. */
77
- blockNumber?: number;
78
- /** Gas consumed by the transaction, if confirmed. */
79
- gasUsed?: string;
80
- }
81
- /**
82
- * Final result of a completed swap operation.
83
- */
84
- interface SwapResult {
85
- /** Transaction hash of the swap. */
86
- txHash: string;
87
- /** Chain ID the swap executed on. */
88
- chainId: number;
89
- /** Final transaction status. */
90
- status: 'confirmed' | 'failed';
91
- /** Gas consumed by the swap transaction. */
92
- gasUsed: string;
93
- /** Contract address of the token sold. */
94
- inputToken: string;
95
- /** Contract address of the token bought. */
96
- outputToken: string;
97
- /** Amount of input token swapped (smallest unit). */
98
- inputAmount: string;
99
- /** Amount of output token received (smallest unit). */
100
- outputAmount: string;
101
- }
102
- /**
103
- * Parameters for requesting a swap quote.
104
- */
105
- interface QuoteParams {
106
- /** Source token contract address. */
107
- src: string;
108
- /** Destination token contract address. */
109
- dst: string;
110
- /** Amount of source token in smallest unit (wei). */
111
- amount: string;
112
- /** EVM chain ID to get the quote on. */
113
- chainId: number;
114
- /** Fee billing mode. Defaults to 'standard'. */
115
- mode?: BillingMode;
116
- }
117
- /**
118
- * Parameters for executing a full swap (quote through confirmation).
119
- */
120
- interface SwapParams {
121
- /** Source token contract address. */
122
- src: string;
123
- /** Destination token contract address. */
124
- dst: string;
125
- /** Amount of source token in smallest unit (wei). */
126
- amount: string;
127
- /** EVM chain ID to execute the swap on. */
128
- chainId: number;
129
- /** Maximum acceptable slippage percentage (e.g. 0.5 = 0.5%). Defaults to 0.5. */
130
- slippage?: number;
131
- /** Whether to use Flashbots or similar MEV protection. Defaults to false. */
132
- mevProtection?: boolean;
133
- /** Fee billing mode. Defaults to 'standard'. */
134
- mode?: BillingMode;
135
- }
136
- /**
137
- * Parameters for generating an ERC-20 token approval transaction.
138
- */
139
- interface ApproveParams {
140
- /** ERC-20 token contract address to approve. */
141
- tokenAddress: string;
142
- /** EVM chain ID. */
143
- chainId: number;
144
- /** The agent's public wallet address. */
145
- walletAddress: string;
146
- /** Specific approval amount (wei). Omit for unlimited approval. */
147
- amount?: string;
148
- }
149
- /**
150
- * Parameters for broadcasting a signed transaction.
151
- */
152
- interface BroadcastParams {
153
- /** EVM chain ID to broadcast on. */
154
- chainId: number;
155
- /** Raw signed transaction hex string. */
156
- signedTx: string;
157
- /** Whether to use MEV protection for broadcast. Defaults to false. */
158
- mevProtection?: boolean;
159
- }
160
- /**
161
- * Parameters for checking the status of a swap transaction.
162
- */
163
- interface SwapStatusParams {
164
- /** Transaction hash to check. */
165
- txHash: string;
166
- /** EVM chain ID the transaction is on. */
167
- chainId: number;
168
- }
169
-
170
- /**
171
- * Interface for transaction signing. The SDK never sees private keys -- it passes
172
- * unsigned calldata to the Signer and gets signed bytes back.
173
- */
174
- interface Signer {
175
- /** Return the signer's public address (checksummed hex for EVM). */
176
- getAddress(): Promise<string>;
177
- /**
178
- * Sign an unsigned transaction and return the raw signed hex string.
179
- * @param tx - Chain-agnostic unsigned transaction to sign.
180
- * @returns Raw signed transaction as a hex string.
181
- */
182
- signTransaction(tx: UnsignedTransaction): Promise<string>;
183
- /** Return the list of chain IDs this signer can sign for. */
184
- getSupportedChainIds(): Promise<number[]>;
185
- }
186
-
187
- /**
188
- * Configuration for creating a MangroveClient instance.
189
- */
190
- interface MangroveConfig {
191
- /** MCP server URL (e.g. 'https://mangrovemarkets.com/mcp' or 'https://mangrovemarkets.com'). */
192
- url: string;
193
- /** Optional Signer for transaction signing. Required for swap() operations. */
194
- signer?: Signer;
195
- /** Transport type. 'mcp' (default) uses MCP protocol; 'rest' uses FastAPI REST endpoints. */
196
- transport?: 'mcp' | 'rest';
197
- /** Optional Bearer token for authenticated endpoints. */
198
- apiKey?: string;
199
- }
200
-
201
- /**
202
- * Raw parsed JSON response from a tool call.
203
- */
204
- interface ToolCallResult {
205
- [key: string]: unknown;
206
- }
207
- /**
208
- * Interface for communicating with the MangroveMarkets MCP server.
209
- * Implementations: McpTransport (primary), RestTransport (fallback).
210
- */
211
- interface Transport {
212
- /**
213
- * Invoke an MCP tool by name with parameters. Returns parsed JSON response.
214
- * @param name - Tool name (e.g. 'dex_get_quote', 'oneinch_balances').
215
- * @param params - Tool parameters as key-value pairs.
216
- * @returns Parsed JSON response from the server.
217
- */
218
- callTool(name: string, params: Record<string, unknown>): Promise<ToolCallResult>;
219
- /** Open the transport connection to the server. */
220
- connect(): Promise<void>;
221
- /** Close the transport connection and release resources. */
222
- disconnect(): Promise<void>;
223
- }
224
-
225
- /**
226
- * Low-level DEX service wrapping individual dex_* MCP tools.
227
- * For high-level swap orchestration, use SwapOrchestrator or MangroveClient.dex.swap().
228
- */
229
- declare class DexService {
230
- private transport;
231
- constructor(transport: Transport);
232
- /**
233
- * Request a swap quote from the DEX aggregator.
234
- * @param params - Quote parameters (src, dst, amount, chainId, mode).
235
- * @returns A server-issued Quote with pricing and expiry.
236
- */
237
- getQuote(params: QuoteParams): Promise<Quote>;
238
- /**
239
- * Convert a quote into unsigned swap calldata ready for signing.
240
- * @param quoteId - ID from a previously obtained Quote.
241
- * @param slippage - Maximum slippage percentage (default 0.5%).
242
- * @returns Unsigned transaction calldata for the swap.
243
- */
244
- prepareSwap(params: {
245
- quoteId: string;
246
- walletAddress: string;
247
- slippage?: number;
248
- }): Promise<UnsignedTransaction>;
249
- /**
250
- * Generate an unsigned ERC-20 approval transaction for the DEX router.
251
- * @param params - Token address, chain ID, and optional specific amount.
252
- * @returns Unsigned approval transaction calldata.
253
- */
254
- approveToken(params: ApproveParams): Promise<UnsignedTransaction>;
255
- /**
256
- * Broadcast a signed transaction to the network.
257
- * @param params - Chain ID, signed transaction hex, and MEV protection flag.
258
- * @returns Broadcast result with transaction hash.
259
- */
260
- broadcast(params: BroadcastParams): Promise<BroadcastResult>;
261
- /**
262
- * Check the on-chain status of a transaction.
263
- * @param params - Transaction hash and chain ID.
264
- * @returns Current transaction status (pending, confirmed, or failed).
265
- */
266
- txStatus(params: SwapStatusParams): Promise<TransactionStatus>;
267
- /**
268
- * List all venues supported by the DEX aggregator.
269
- * @returns Supported venue metadata.
270
- */
271
- supportedVenues(): Promise<ToolCallResult>;
272
- /**
273
- * List supported trading pairs, optionally filtered by chain or venue.
274
- * @param chainId - Optional chain ID filter.
275
- * @param venue - Optional venue name filter (e.g. '1inch').
276
- * @returns Supported trading pair metadata.
277
- */
278
- supportedPairs(venueId: string): Promise<ToolCallResult>;
279
- }
280
-
281
- /** Combined DEX API surface exposing both low-level tools and high-level swap(). */
282
- interface DexClientApi extends DexService {
283
- swap(params: SwapParams): Promise<SwapResult>;
284
- }
285
- /**
286
- * Main entry point for the MangroveMarkets SDK. Provides access to DEX, marketplace,
287
- * and wallet services through a pluggable transport layer.
288
- */
289
- declare class MangroveClient {
290
- private transport;
291
- private _dex;
292
- private _swapOrchestrator?;
293
- private config;
294
- /**
295
- * Create a MangroveClient. Uses MCP transport by default; pass transport: 'rest' for REST fallback.
296
- * @param config - Client configuration (url, signer, transport, apiKey).
297
- */
298
- constructor(config: MangroveConfig);
299
- /**
300
- * Access DEX operations. Includes low-level methods (getQuote, prepareSwap, approveToken,
301
- * broadcast, txStatus) and high-level swap() orchestration.
302
- * Calling swap() requires a Signer in the config.
303
- */
304
- get dex(): DexClientApi;
305
- /** Open the transport connection. Must be called before making any tool calls. */
306
- connect(): Promise<void>;
307
- /** Close the transport connection and release resources. */
308
- disconnect(): Promise<void>;
309
- }
310
-
311
- interface EthersWallet {
312
- address: string;
313
- signTransaction(tx: Record<string, unknown>): Promise<string>;
314
- }
315
- /**
316
- * Signer adapter for ethers.js Wallet. Maps UnsignedTransaction fields to
317
- * ethers.js format (gas -> gasLimit, spreads EIP-1559 fields).
318
- */
319
- declare class EthersSigner implements Signer {
320
- private wallet;
321
- private chainIds;
322
- /**
323
- * Create an EthersSigner from an ethers.js Wallet and list of supported chain IDs.
324
- * @param wallet - An ethers.js Wallet instance (or any object matching EthersWallet).
325
- * @param supportedChainIds - Chain IDs this wallet can sign transactions for.
326
- */
327
- constructor(wallet: EthersWallet, supportedChainIds: number[]);
328
- /** {@inheritDoc Signer.getAddress} */
329
- getAddress(): Promise<string>;
330
- /** {@inheritDoc Signer.signTransaction} */
331
- signTransaction(tx: UnsignedTransaction): Promise<string>;
332
- /** {@inheritDoc Signer.getSupportedChainIds} */
333
- getSupportedChainIds(): Promise<number[]>;
334
- }
335
-
336
- /**
337
- * MCP protocol transport using Streamable HTTP. Primary transport for agent communication.
338
- */
339
- declare class McpTransport implements Transport {
340
- private url;
341
- private apiKey?;
342
- private client;
343
- /**
344
- * Create an MCP transport targeting the given server URL.
345
- * @param url - MCP server endpoint URL.
346
- * @param apiKey - Optional Bearer token for authenticated requests.
347
- */
348
- constructor(url: string, apiKey?: string);
349
- connect(): Promise<void>;
350
- callTool(name: string, params: Record<string, unknown>): Promise<ToolCallResult>;
351
- disconnect(): Promise<void>;
352
- }
353
-
354
- /**
355
- * REST API transport using native fetch. Calls POST /api/v1/tools/{name} on the FastAPI server.
356
- */
357
- declare class RestTransport implements Transport {
358
- private baseUrl;
359
- private apiKey?;
360
- /**
361
- * Create a REST transport targeting the given base URL with optional API key.
362
- * @param baseUrl - Base URL of the FastAPI server (trailing slash is stripped). Must use HTTPS unless localhost.
363
- * @param apiKey - Optional Bearer token for authenticated requests.
364
- */
365
- constructor(baseUrl: string, apiKey?: string);
366
- callTool(name: string, params: Record<string, unknown>): Promise<ToolCallResult>;
367
- connect(): Promise<void>;
368
- disconnect(): Promise<void>;
369
- }
370
-
371
- export { type ApproveParams, type BillingMode, type BroadcastParams, type BroadcastResult, DexService, EthersSigner, MangroveClient, type MangroveConfig, McpTransport, type Quote, type QuoteParams, RestTransport, type Signer, type SwapParams, type SwapResult, type SwapStatusParams, type ToolCallResult, type TransactionStatus, type Transport, type UnsignedTransaction };