Skip to content

Commit 2398ae8

Browse files
committed
add suilend tools
1 parent 4f2d4d7 commit 2398ae8

File tree

6 files changed

+721
-53
lines changed

6 files changed

+721
-53
lines changed

packages/sui-agent/src/agents/ToolRegistry.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AfterMath from '../protocols/aftermath/tools';
33
import Navi from '../protocols/navi/tools';
44
import Cetus from '../protocols/cetus/tools';
55
import Transaction from '../transactions/tools';
6+
import Suilend from '../protocols/suilend/tools';
67
/*
78
format for tool registry is:
89
tool name, tool description, tool arguments, process(function)
@@ -17,4 +18,6 @@ export function registerAllTools(tools: Tools) {
1718
Cetus.registerTools(tools);
1819
// Transaction Tools
1920
Transaction.registerTools(tools);
21+
// Suilend tools
22+
Suilend.registerTools(tools);
2023
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Suilend Protocol Integration
2+
3+
This module provides integration with the Suilend lending protocol on Sui Network.
4+
5+
## Features
6+
7+
- Lending Market Management
8+
- Create lending markets
9+
- Create and configure reserves
10+
- Update reserve configurations
11+
- Change reserve price feeds
12+
- Lending Operations
13+
- Borrow and send funds
14+
- Repay into obligation
15+
- Deposit into obligation
16+
- Withdraw and send to user
17+
- Deposit liquidity and get CTokens
18+
- Redeem CTokens and withdraw liquidity
19+
- Reward Management
20+
- Add rewards
21+
- Cancel rewards
22+
- Close rewards
23+
- Claim rewards and send to user
24+
- Claim rewards and deposit
25+
- Liquidation
26+
- Liquidate and redeem positions
27+
- Query Operations
28+
- Get lending market owner capability ID
29+
- Get obligation details
30+
31+
## Tools
32+
33+
### Lending Market Management
34+
35+
#### `create_lending_market`
36+
37+
Create a new lending market.
38+
39+
Parameters:
40+
41+
- `registry_id` (string, required): Registry ID
42+
- `lending_market_type` (string, required): Lending market type
43+
44+
#### `create_reserve`
45+
46+
Create a new reserve in a lending market.
47+
48+
Parameters:
49+
50+
- `lending_market_owner_cap_id` (string, required): Lending market owner capability ID
51+
- `pyth_price_id` (string, required): Pyth price feed ID
52+
- `coin_type` (string, required): Coin type
53+
- `config` (object, required): Reserve configuration
54+
55+
### Lending Operations
56+
57+
#### `borrow_and_send`
58+
59+
Borrow and send funds to user.
60+
61+
Parameters:
62+
63+
- `owner_id` (string, required): Owner ID
64+
- `obligation_owner_cap_id` (string, required): Obligation owner capability ID
65+
- `obligation_id` (string, required): Obligation ID
66+
- `coin_type` (string, required): Coin type
67+
- `value` (string, required): Value to borrow
68+
69+
## Usage Example
70+
71+
```typescript
72+
// Initialize the protocol
73+
const client = await suilendClientWrapper();
74+
75+
// Create a lending market
76+
await tools.execute('create_lending_market', [
77+
'registry123', // registry_id
78+
'type123', // lending_market_type
79+
]);
80+
81+
// Borrow funds
82+
await tools.execute('borrow_and_send', [
83+
'owner123', // owner_id
84+
'cap123', // obligation_owner_cap_id
85+
'obligation123', // obligation_id
86+
'sui', // coin_type
87+
'1000000', // value
88+
]);
89+
```
90+
91+
## Error Handling
92+
93+
All tools return responses in a standardized format:
94+
95+
```typescript
96+
{
97+
reasoning: string; // Description of what happened
98+
response: string; // The actual response data
99+
status: string; // "success" or "failure"
100+
query: string; // The original query
101+
errors: string[]; // Array of error messages if any
102+
}
103+
```
104+
105+
## Dependencies
106+
107+
- @suilend/sdk: Latest version
108+
- @mysten/sui: ^1.1.0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export * from './types';
2+
export { default as SuilendTools } from './tools';
3+
4+
import { SuiClient, SuiHTTPTransport } from '@mysten/sui/client';
5+
import {
6+
SuilendClient,
7+
LENDING_MARKET_ID,
8+
LENDING_MARKET_TYPE,
9+
} from '@suilend/sdk/client';
10+
import { NETWORK_CONFIG } from '../../@types/interface';
11+
12+
/**
13+
* Initializes and returns a SuilendClient instance configured for the mainnet.
14+
*
15+
* This function creates a configured SuilendClient by:
16+
* 1. Establishing a connection to the Sui mainnet using SuiClient
17+
* 2. Initializing a SuilendClient with predefined lending market parameters
18+
*
19+
* @returns {Promise<SuilendClient>} A configured SuilendClient instance ready for lending operations
20+
* @throws {Error} If client initialization fails, with detailed error message
21+
*
22+
* @example
23+
* try {
24+
* const client = await suilendClientWrapper();
25+
* // Use client for lending operations
26+
* } catch (error) {
27+
* console.error('Failed to initialize SuilendClient:', error);
28+
* }
29+
*
30+
* @see {@link SuilendClient} For available lending operations
31+
* @see {@link LENDING_MARKET_ID} For the configured lending market identifier
32+
* @see {@link LENDING_MARKET_TYPE} For the lending market type configuration
33+
*/
34+
export async function suilendClientWrapper(): Promise<SuilendClient> {
35+
try {
36+
const suiClient = new SuiClient({
37+
transport: new SuiHTTPTransport({
38+
url: NETWORK_CONFIG.MAINNET.fullnode,
39+
}),
40+
});
41+
42+
const suilendClient = await SuilendClient.initialize(
43+
LENDING_MARKET_ID,
44+
LENDING_MARKET_TYPE,
45+
suiClient,
46+
);
47+
48+
return suilendClient;
49+
} catch (error) {
50+
throw new Error(
51+
`Failed to initialize SuilendClient: ${error instanceof Error ? error.message : String(error)}`,
52+
);
53+
}
54+
}
Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,2 @@
1-
import { SuiClient, SuiHTTPTransport } from '@mysten/sui/client';
2-
import {
3-
SuilendClient,
4-
LENDING_MARKET_ID,
5-
LENDING_MARKET_TYPE,
6-
} from '@suilend/sdk/client';
7-
import { NETWORK_CONFIG } from '../../@types/interface';
8-
9-
/**
10-
* Initializes and returns a SuilendClient instance configured for the mainnet.
11-
*
12-
* This function creates a configured SuilendClient by:
13-
* 1. Establishing a connection to the Sui mainnet using SuiClient
14-
* 2. Initializing a SuilendClient with predefined lending market parameters
15-
*
16-
* @returns {Promise<SuilendClient>} A configured SuilendClient instance ready for lending operations
17-
* @throws {Error} If client initialization fails, with detailed error message
18-
*
19-
* @example
20-
* try {
21-
* const client = await suilendClientWrapper();
22-
* // Use client for lending operations
23-
* } catch (error) {
24-
* console.error('Failed to initialize SuilendClient:', error);
25-
* }
26-
*
27-
* @see {@link SuilendClient} For available lending operations
28-
* @see {@link LENDING_MARKET_ID} For the configured lending market identifier
29-
* @see {@link LENDING_MARKET_TYPE} For the lending market type configuration
30-
*/
31-
async function suilendClientWrapper(): Promise<SuilendClient> {
32-
try {
33-
const suiClient = new SuiClient({
34-
transport: new SuiHTTPTransport({
35-
url: NETWORK_CONFIG.MAINNET.fullnode,
36-
}),
37-
});
38-
39-
const suilendClient = await SuilendClient.initialize(
40-
LENDING_MARKET_ID,
41-
LENDING_MARKET_TYPE,
42-
suiClient,
43-
);
44-
45-
return suilendClient;
46-
} catch (error) {
47-
throw new Error(
48-
`Failed to initialize SuilendClient: ${error instanceof Error ? error.message : String(error)}`,
49-
);
50-
}
51-
}
52-
53-
export { suilendClientWrapper };
1+
export * from './types';
2+
export { default as SuilendTools } from './tools';

0 commit comments

Comments
 (0)