mantle-agent-kit-sdk 1.0.3 → 1.0.4
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 +192 -87
- package/dist/index.cjs +978 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1051 -261
- package/dist/index.d.ts +1051 -261
- package/dist/index.js +970 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Mantle Agent Kit SDK
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for seamless integration with DeFi protocols on Mantle Network. Provides unified interfaces for swaps, lending, liquid staking, and cross-chain operations.
|
|
3
|
+
TypeScript SDK for seamless integration with DeFi protocols on Mantle Network. Provides unified interfaces for swaps, lending, liquid staking, perpetual trading, and cross-chain operations.
|
|
4
4
|
|
|
5
5
|
Part of [Mantle DevKit](https://mantle-devkit.vercel.app) - the complete developer suite for Mantle.
|
|
6
6
|
|
|
@@ -32,31 +32,23 @@ const txHash = await agent.sendTransaction(
|
|
|
32
32
|
|
|
33
33
|
## Supported Protocols
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### Liquid Staking
|
|
49
|
-
- **mETH Protocol** - Mantle's native liquid staking derivative for Ethereum
|
|
50
|
-
|
|
51
|
-
### Cross-Chain Infrastructure
|
|
52
|
-
- **Squid Router** - Seamless cross-chain swaps via Axelar network
|
|
35
|
+
| Protocol | Network | Description |
|
|
36
|
+
|----------|---------|-------------|
|
|
37
|
+
| **OKX DEX** | Mainnet | Multi-source liquidity aggregation |
|
|
38
|
+
| **1inch** | Mainnet | Pathfinder algorithm for optimal routes |
|
|
39
|
+
| **OpenOcean** | Mainnet | Cross-DEX aggregation |
|
|
40
|
+
| **Agni Finance** | Mainnet | Concentrated liquidity DEX (Uniswap V3) |
|
|
41
|
+
| **Merchant Moe** | Mainnet | Liquidity Book DEX (TraderJoe V2.1) |
|
|
42
|
+
| **Uniswap V3** | Mainnet | Canonical Uniswap V3 contracts |
|
|
43
|
+
| **Lendle** | Mainnet | Lending market (Aave V2 fork) |
|
|
44
|
+
| **mETH Protocol** | Mainnet | Liquid staking token |
|
|
45
|
+
| **PikePerps** | Testnet | Perpetual futures trading (up to 100x) |
|
|
46
|
+
| **Squid Router** | Mainnet | Cross-chain swaps via Axelar |
|
|
53
47
|
|
|
54
48
|
## API Reference
|
|
55
49
|
|
|
56
50
|
### Token Transfers
|
|
57
51
|
|
|
58
|
-
Send native MNT tokens to any address.
|
|
59
|
-
|
|
60
52
|
```typescript
|
|
61
53
|
await agent.sendTransaction(
|
|
62
54
|
recipientAddress: Address,
|
|
@@ -64,6 +56,8 @@ await agent.sendTransaction(
|
|
|
64
56
|
): Promise<Address>
|
|
65
57
|
```
|
|
66
58
|
|
|
59
|
+
---
|
|
60
|
+
|
|
67
61
|
### DEX Operations
|
|
68
62
|
|
|
69
63
|
#### OKX DEX Aggregator
|
|
@@ -160,12 +154,12 @@ const txHash = await agent.merchantMoeSwap(
|
|
|
160
154
|
);
|
|
161
155
|
```
|
|
162
156
|
|
|
157
|
+
---
|
|
158
|
+
|
|
163
159
|
### Lendle Lending Protocol
|
|
164
160
|
|
|
165
161
|
#### Supply Assets
|
|
166
162
|
|
|
167
|
-
Deposit tokens to earn yield and use as collateral.
|
|
168
|
-
|
|
169
163
|
```typescript
|
|
170
164
|
const txHash = await agent.lendleSupply(
|
|
171
165
|
tokenAddress: Address,
|
|
@@ -175,8 +169,6 @@ const txHash = await agent.lendleSupply(
|
|
|
175
169
|
|
|
176
170
|
#### Withdraw Assets
|
|
177
171
|
|
|
178
|
-
Withdraw previously supplied tokens.
|
|
179
|
-
|
|
180
172
|
```typescript
|
|
181
173
|
const txHash = await agent.lendleWithdraw(
|
|
182
174
|
tokenAddress: Address,
|
|
@@ -187,46 +179,158 @@ const txHash = await agent.lendleWithdraw(
|
|
|
187
179
|
|
|
188
180
|
#### Borrow Assets
|
|
189
181
|
|
|
190
|
-
Borrow against supplied collateral.
|
|
191
|
-
|
|
192
182
|
```typescript
|
|
193
183
|
const txHash = await agent.lendleBorrow(
|
|
194
184
|
tokenAddress: Address,
|
|
195
185
|
amount: string,
|
|
196
186
|
interestRateMode?: 1 | 2, // 1 = stable, 2 = variable (default)
|
|
197
|
-
onBehalfOf?: Address
|
|
187
|
+
onBehalfOf?: Address
|
|
198
188
|
);
|
|
199
189
|
```
|
|
200
190
|
|
|
201
191
|
#### Repay Debt
|
|
202
192
|
|
|
203
|
-
Repay borrowed assets.
|
|
204
|
-
|
|
205
193
|
```typescript
|
|
206
194
|
const txHash = await agent.lendleRepay(
|
|
207
195
|
tokenAddress: Address,
|
|
208
196
|
amount: string,
|
|
209
197
|
rateMode?: 1 | 2, // 1 = stable, 2 = variable (default)
|
|
210
|
-
onBehalfOf?: Address
|
|
198
|
+
onBehalfOf?: Address
|
|
199
|
+
);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### View Account Data
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const accountData = await agent.lendleGetUserAccountData(
|
|
206
|
+
userAddress?: Address // optional, defaults to agent account
|
|
207
|
+
);
|
|
208
|
+
// Returns: {
|
|
209
|
+
// totalCollateralETH: bigint,
|
|
210
|
+
// totalDebtETH: bigint,
|
|
211
|
+
// availableBorrowsETH: bigint,
|
|
212
|
+
// currentLiquidationThreshold: bigint,
|
|
213
|
+
// ltv: bigint,
|
|
214
|
+
// healthFactor: bigint
|
|
215
|
+
// }
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### View All Positions
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const positions = await agent.lendleGetPositions(
|
|
222
|
+
userAddress?: Address // optional, defaults to agent account
|
|
211
223
|
);
|
|
224
|
+
// Returns: {
|
|
225
|
+
// positions: LendlePosition[],
|
|
226
|
+
// totalSupplied: bigint,
|
|
227
|
+
// totalDebt: bigint
|
|
228
|
+
// }
|
|
212
229
|
```
|
|
213
230
|
|
|
214
|
-
|
|
231
|
+
---
|
|
215
232
|
|
|
216
|
-
|
|
233
|
+
### mETH Protocol (Liquid Staking)
|
|
217
234
|
|
|
218
235
|
```typescript
|
|
236
|
+
// Get mETH token address
|
|
219
237
|
const methAddress = agent.getMethTokenAddress();
|
|
220
238
|
// Returns: 0xcDA86A272531e8640cD7F1a92c01839911B90bb0 (mainnet)
|
|
239
|
+
|
|
240
|
+
// View mETH position (balances)
|
|
241
|
+
const position = await agent.methGetPosition(
|
|
242
|
+
userAddress?: Address // optional, defaults to agent account
|
|
243
|
+
);
|
|
244
|
+
// Returns: {
|
|
245
|
+
// methBalance: bigint,
|
|
246
|
+
// wethBalance: bigint,
|
|
247
|
+
// wmntBalance: bigint,
|
|
248
|
+
// methTokenAddress: Address,
|
|
249
|
+
// wethTokenAddress: Address,
|
|
250
|
+
// wmntTokenAddress: Address
|
|
251
|
+
// }
|
|
252
|
+
|
|
253
|
+
// Swap WETH to mETH via DEX
|
|
254
|
+
const txHash = await agent.swapToMeth(
|
|
255
|
+
amount: string, // WETH amount in wei
|
|
256
|
+
slippage?: number // default: 0.5
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// Swap mETH to WETH via DEX
|
|
260
|
+
const txHash = await agent.swapFromMeth(
|
|
261
|
+
amount: string, // mETH amount in wei
|
|
262
|
+
slippage?: number // default: 0.5
|
|
263
|
+
);
|
|
221
264
|
```
|
|
222
265
|
|
|
223
|
-
Note
|
|
266
|
+
> **Note**: Actual ETH staking happens on Ethereum L1. On Mantle L2, you can swap to/from mETH via DEX or use it in DeFi protocols. To stake ETH for mETH on L1, use the [official mETH interface](https://www.mantle-meth.xyz/).
|
|
267
|
+
|
|
268
|
+
---
|
|
224
269
|
|
|
225
|
-
###
|
|
270
|
+
### PikePerps - Perpetual Trading
|
|
226
271
|
|
|
227
|
-
|
|
272
|
+
Trade perpetual futures with up to 100x leverage on meme tokens.
|
|
228
273
|
|
|
229
|
-
|
|
274
|
+
> **Network**: Mantle Sepolia Testnet only
|
|
275
|
+
|
|
276
|
+
#### Open Long Position
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const result = await agent.pikeperpsOpenLong(
|
|
280
|
+
tokenAddress: Address, // Meme token to trade
|
|
281
|
+
margin: string, // Margin in wei
|
|
282
|
+
leverage?: number // 1-100, default: 10
|
|
283
|
+
);
|
|
284
|
+
// Returns: { positionId: bigint, txHash: Hex }
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
#### Open Short Position
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
const result = await agent.pikeperpsOpenShort(
|
|
291
|
+
tokenAddress: Address,
|
|
292
|
+
margin: string,
|
|
293
|
+
leverage?: number // 1-100, default: 10
|
|
294
|
+
);
|
|
295
|
+
// Returns: { positionId: bigint, txHash: Hex }
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### Close Position
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
const txHash = await agent.pikeperpsClosePosition(
|
|
302
|
+
positionId: bigint
|
|
303
|
+
);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### View Positions
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
const positions = await agent.pikeperpsGetPositions(
|
|
310
|
+
userAddress?: Address // optional, defaults to agent account
|
|
311
|
+
);
|
|
312
|
+
// Returns: PikePerpsPosition[] with:
|
|
313
|
+
// positionId, token, isLong, size, margin, leverage,
|
|
314
|
+
// entryPrice, currentPrice, pnl, isProfit,
|
|
315
|
+
// liquidationPrice, isOpen
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
#### Get Market Data
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const marketData = await agent.pikeperpsGetMarketData(
|
|
322
|
+
tokenAddress: Address,
|
|
323
|
+
limit?: number // default: 20
|
|
324
|
+
);
|
|
325
|
+
// Returns: {
|
|
326
|
+
// token, currentPrice, hasPrice, isListed, curveProgress,
|
|
327
|
+
// recentTrades: PikePerpsTrade[]
|
|
328
|
+
// }
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
### Cross-Chain Operations (Squid Router)
|
|
230
334
|
|
|
231
335
|
```typescript
|
|
232
336
|
// Get cross-chain route
|
|
@@ -250,14 +354,14 @@ const txHash = await agent.crossChainSwapViaSquid(
|
|
|
250
354
|
);
|
|
251
355
|
```
|
|
252
356
|
|
|
357
|
+
---
|
|
358
|
+
|
|
253
359
|
## Configuration
|
|
254
360
|
|
|
255
361
|
### Environment Variables
|
|
256
362
|
|
|
257
363
|
#### Platform Configuration (Required)
|
|
258
364
|
|
|
259
|
-
The Mantle Agent Kit requires an APP_ID for platform validation and authentication.
|
|
260
|
-
|
|
261
365
|
```env
|
|
262
366
|
APP_ID=your_app_id_here
|
|
263
367
|
|
|
@@ -265,10 +369,6 @@ APP_ID=your_app_id_here
|
|
|
265
369
|
PLATFORM_URL=https://mantle-devkit.vercel.app
|
|
266
370
|
```
|
|
267
371
|
|
|
268
|
-
**What is APP_ID?**
|
|
269
|
-
|
|
270
|
-
APP_ID is a unique identifier that authenticates your application and validates access to the Mantle Agent Kit. When you call `agent.initialize()`, it validates your APP_ID with the platform API and returns your project configuration (name, payout address, network, status).
|
|
271
|
-
|
|
272
372
|
#### OKX DEX (Required for OKX methods)
|
|
273
373
|
|
|
274
374
|
```env
|
|
@@ -286,10 +386,10 @@ ONEINCH_API_KEY=your_api_key
|
|
|
286
386
|
|
|
287
387
|
### Network Configuration
|
|
288
388
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
389
|
+
| Network | Chain ID | Usage |
|
|
390
|
+
|---------|----------|-------|
|
|
391
|
+
| Mainnet | 5000 | Production (DEX, Lendle, mETH) |
|
|
392
|
+
| Testnet (Sepolia) | 5003 | Development, PikePerps |
|
|
293
393
|
|
|
294
394
|
```typescript
|
|
295
395
|
const mainnetAgent = new MNTAgentKit(privateKey, "mainnet");
|
|
@@ -298,58 +398,48 @@ const testnetAgent = new MNTAgentKit(privateKey, "testnet");
|
|
|
298
398
|
|
|
299
399
|
### Demo/Simulation Mode
|
|
300
400
|
|
|
301
|
-
The SDK includes a demo mode for testing and development without executing real blockchain transactions. In demo mode, all operations return simulated responses instead of making actual on-chain calls.
|
|
302
|
-
|
|
303
401
|
```typescript
|
|
304
402
|
// Initialize agent in demo mode
|
|
305
403
|
const demoAgent = new MNTAgentKit(privateKey, "testnet-demo");
|
|
306
404
|
|
|
307
405
|
// All operations return mock responses
|
|
308
406
|
const result = await demoAgent.swapOnUniswap(tokenA, tokenB, amount);
|
|
309
|
-
// Returns: { txHash: "0xdemo...",
|
|
407
|
+
// Returns: { txHash: "0xdemo...", demo: true, message: "..." }
|
|
310
408
|
```
|
|
311
409
|
|
|
312
|
-
|
|
313
|
-
- Testing application logic without spending real tokens
|
|
314
|
-
- Development and debugging workflows
|
|
315
|
-
- Integration testing in CI/CD pipelines
|
|
316
|
-
- Demonstrating functionality without wallet funds
|
|
317
|
-
|
|
318
|
-
All protocol methods (swaps, lending operations, cross-chain transfers) support demo mode and return consistent mock response structures with `demo: true` flag.
|
|
410
|
+
---
|
|
319
411
|
|
|
320
412
|
## Contract Addresses
|
|
321
413
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
**Lendle Protocol**
|
|
325
|
-
- LendingPool: `0xCFa5aE7c2CE8Fadc6426C1ff872cA45378Fb7cF3`
|
|
326
|
-
- DataProvider: `0xD0E0b5e99c8a36f4c5234cd1E90CFc5C2Bb58A69`
|
|
414
|
+
### Mainnet (Chain ID: 5000)
|
|
327
415
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
416
|
+
| Protocol | Contract | Address |
|
|
417
|
+
|----------|----------|---------|
|
|
418
|
+
| **mETH** | Token | `0xcDA86A272531e8640cD7F1a92c01839911B90bb0` |
|
|
419
|
+
| **WETH** | Token | `0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111` |
|
|
420
|
+
| **WMNT** | Token | `0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8` |
|
|
421
|
+
| **Lendle** | LendingPool | `0xCFa5aE7c2CE8Fadc6426C1ff872cA45378Fb7cF3` |
|
|
422
|
+
| **Lendle** | DataProvider | `0x552b9e4bae485C4B7F540777d7D25614CdB84773` |
|
|
423
|
+
| **Agni** | Factory | `0x25780dc8Fc3cfBD75F33bFDAB65e969b603b2035` |
|
|
424
|
+
| **Agni** | SwapRouter | `0x319B69888b0d11cEC22caA5034e25FfFBDc88421` |
|
|
425
|
+
| **Merchant Moe** | LBRouter | `0x013e138EF6008ae5FDFDE29700e3f2Bc61d21E3a` |
|
|
426
|
+
| **Uniswap V3** | SwapRouter | `0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45` |
|
|
332
427
|
|
|
333
|
-
|
|
334
|
-
- LBRouter: `0x013e138EF6008ae5FDFDE29700e3f2Bc61d21E3a`
|
|
335
|
-
- LBFactory: `0xa6630671775c4EA2743840F9A5016dCf2A104054`
|
|
336
|
-
- LBQuoter: `0xFa1ec885c522Ee2c06aFCfBC66E88a88ca09EEED`
|
|
428
|
+
### Testnet (Chain ID: 5003)
|
|
337
429
|
|
|
338
|
-
|
|
339
|
-
|
|
430
|
+
| Protocol | Contract | Address |
|
|
431
|
+
|----------|----------|---------|
|
|
432
|
+
| **PikePerps** | PerpetualTrading | `0x8081b646f349c049f2d5e8a400057d411dd657bd` |
|
|
433
|
+
| **PikePerps** | BondingCurveMarket | `0x93b268325A9862645c82b32229f3B52264750Ca2` |
|
|
340
434
|
|
|
341
|
-
|
|
342
|
-
- SwapRouter: `0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45`
|
|
343
|
-
- QuoterV2: `0x61fFE014bA17989E743c5F6cB21bF9697530B21e`
|
|
435
|
+
Verify addresses on [Mantlescan](https://mantlescan.xyz).
|
|
344
436
|
|
|
345
|
-
|
|
437
|
+
---
|
|
346
438
|
|
|
347
439
|
## Advanced Usage
|
|
348
440
|
|
|
349
441
|
### Accessing Protocol Constants
|
|
350
442
|
|
|
351
|
-
Import protocol-specific constants for advanced integrations:
|
|
352
|
-
|
|
353
443
|
```typescript
|
|
354
444
|
import {
|
|
355
445
|
AgniConstants,
|
|
@@ -357,26 +447,37 @@ import {
|
|
|
357
447
|
MerchantMoeConstants,
|
|
358
448
|
MethConstants,
|
|
359
449
|
UniswapConstants,
|
|
450
|
+
PikePerpsConstants,
|
|
360
451
|
} from "mantle-agent-kit-sdk";
|
|
361
452
|
|
|
362
453
|
// Example: Get Lendle pool address
|
|
363
454
|
const poolAddress = LendleConstants.LENDING_POOL.mainnet;
|
|
455
|
+
|
|
456
|
+
// Example: Get PikePerps contract
|
|
457
|
+
const perpsAddress = PikePerpsConstants.PERPETUAL_TRADING.testnet;
|
|
458
|
+
|
|
459
|
+
// Example: Get mETH/WETH/WMNT addresses
|
|
460
|
+
const methToken = MethConstants.METH_TOKEN.mainnet;
|
|
461
|
+
const wethToken = MethConstants.WETH_TOKEN.mainnet;
|
|
462
|
+
const wmntToken = MethConstants.WMNT_TOKEN.mainnet;
|
|
364
463
|
```
|
|
365
464
|
|
|
366
465
|
### Type Definitions
|
|
367
466
|
|
|
368
|
-
Import utility types for type-safe development:
|
|
369
|
-
|
|
370
467
|
```typescript
|
|
371
|
-
import type {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
468
|
+
import type {
|
|
469
|
+
UserAccountData,
|
|
470
|
+
ProjectConfig,
|
|
471
|
+
LendlePosition,
|
|
472
|
+
LendlePositionsResult,
|
|
473
|
+
MethPosition,
|
|
474
|
+
PikePerpsPosition,
|
|
475
|
+
PikePerpsMarketData,
|
|
476
|
+
PikePerpsTrade,
|
|
477
|
+
} from "mantle-agent-kit-sdk";
|
|
375
478
|
```
|
|
376
479
|
|
|
377
|
-
###
|
|
378
|
-
|
|
379
|
-
After initializing the agent, you can access the validated project configuration:
|
|
480
|
+
### Project Configuration
|
|
380
481
|
|
|
381
482
|
```typescript
|
|
382
483
|
const agent = new MNTAgentKit(privateKey, "mainnet");
|
|
@@ -389,6 +490,8 @@ console.log("Network:", agent.projectConfig?.network);
|
|
|
389
490
|
console.log("Status:", agent.projectConfig?.status);
|
|
390
491
|
```
|
|
391
492
|
|
|
493
|
+
---
|
|
494
|
+
|
|
392
495
|
## Development
|
|
393
496
|
|
|
394
497
|
### Build from Source
|
|
@@ -414,6 +517,8 @@ dist/
|
|
|
414
517
|
└── *.map # Source maps
|
|
415
518
|
```
|
|
416
519
|
|
|
520
|
+
---
|
|
521
|
+
|
|
417
522
|
## License
|
|
418
523
|
|
|
419
524
|
MIT
|