@pendle/sdk-boros 0.1.34 → 0.1.35

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 CHANGED
@@ -1 +1,568 @@
1
- # Pendle SDK for Boros
1
+ # Pendle SDK Boros
2
+
3
+ The `Exchange` class provides an interface for interacting with the Boros trading platform. It handles operations such as placing orders, modifying orders, managing positions, and interacting with the blockchain.
4
+
5
+ Below is the documentation for the SDK. For more details about the overall architecture, contracts, API, and more, please refer to the [documentation](documentation/) folder.
6
+
7
+ You can start with the [lite paper](documentation/lite-paper.md) to understand the overall architecture and mechanics of the platform.
8
+ Then you can go to the [API docs](documentation/API.docs.md) to understand the API and parameters.
9
+ After that, you can refer to [SDK docs](documentation/SDK.docs.md) and [example](documentation/example/) to see how to use the SDK.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ yarn add @pendle/sdk-boros
15
+
16
+ ```
17
+
18
+ ## Initialization
19
+
20
+ ```typescript
21
+ constructor(walletClient: WalletClient, root: Address, accountId: number)
22
+ ```
23
+
24
+ The Exchange class requires three parameters for initialization:
25
+
26
+ - `walletClient`: A viem WalletClient instance for signing transactions
27
+ - `root`: The wallet address (Address type from viem)
28
+ - `accountId`: The numerical ID of the account to interact with
29
+
30
+ Example:
31
+ ```typescript
32
+ import { createWalletClient, http } from 'viem';
33
+ import { Exchange } from 'pendle-sdk-boros';
34
+
35
+ const account = privateKeyToAccount(PRIVATE_KEY);
36
+
37
+ const walletClient = createWalletClient({
38
+ transport: http(RPC_URL),
39
+ account: account,
40
+ });
41
+
42
+ const exchange = new Exchange(
43
+ walletClient,
44
+ '0xYourWalletAddress',
45
+ 0 // accountId
46
+ );
47
+ ```
48
+
49
+ ## Example Flow: Creating an Agent and Placing an Order
50
+
51
+ Below is a complete example showing how to create an agent, approve it, and place an order:
52
+
53
+ ```typescript
54
+ import { createWalletClient, http } from 'viem';
55
+ import { privateKeyToAccount } from 'viem/accounts';
56
+ import { Exchange, Agent, Side, TimeInForce, MarketAccLib } from 'pendle-sdk-boros';
57
+
58
+ // Setup wallet client
59
+ const PRIVATE_KEY = '0xYourPrivateKey';
60
+ const RPC_URL = 'https://your-rpc-endpoint.com';
61
+ const account = privateKeyToAccount(PRIVATE_KEY);
62
+ const accountId = 0;
63
+
64
+ const walletClient = createWalletClient({
65
+ transport: http(RPC_URL),
66
+ account: account,
67
+ });
68
+
69
+ async function placeOrderExample() {
70
+ const exchange = new Exchange(
71
+ walletClient,
72
+ account.address,
73
+ accountId
74
+ );
75
+
76
+ const agent = await Agent.create(walletClient);
77
+
78
+ const approvalTx = await exchange.approveAgent(agent);
79
+ console.log('Agent approved:', approvalTx);
80
+ const tokenId = 0;
81
+ const marketId = 0;
82
+
83
+ const marketAcc = MarketAccLib.pack(account.address, accountId, tokenId, marketId)
84
+
85
+ const orderResult = await exchange.placeOrder({
86
+ marketAcc: marketAcc,
87
+ marketAddress: '0xMarketAddress',
88
+ ammAddresses: ['0xAmmAddress1'],
89
+ side: Side.LONG,
90
+ size: 100000000000000000000n, // 100 tokens with 18 decimals
91
+ limitTick: 1000,
92
+ tif: TimeInForce.GOOD_TIL_CANCELLED,
93
+ useOrderBook: true
94
+ });
95
+
96
+ console.log('Order placed:', orderResult);
97
+
98
+ return orderResult;
99
+ }
100
+
101
+ placeOrderExample()
102
+ .then(result => console.log('Example completed successfully'))
103
+ .catch(error => console.error('Error in example:', error));
104
+ ```
105
+
106
+ This example demonstrates the complete flow from initializing the Exchange class to successfully placing an order. The agent creation and approval steps are required before you can place orders on the platform.
107
+
108
+ ## Order Management
109
+
110
+ ### Place Order
111
+
112
+ ```typescript
113
+ async placeOrder(params: PlaceOrderParams): Promise<{
114
+ executeResponse: any;
115
+ result: { order: any };
116
+ }>
117
+ ```
118
+
119
+ Places a new order on the exchange.
120
+
121
+ Parameters:
122
+ - `marketAcc`: Use MarketAccLib to pack
123
+ - `marketAddress`: Address of the market
124
+ - `ammAddresses`: Array of AMM addresses
125
+ - `side`: Trade side (Enum: Side)
126
+ - `size`: Order size as bigint
127
+ - `limitTick`: The tick price limit
128
+ - `tif`: Time-in-force setting enum (GOOD_TIL_CANCELLED = 0, IMMEDIATE_OR_CANCEL = 1, FILL_OR_KILL = 2, POST_ONLY = 3)
129
+ - `useOrderBook`: Boolean indicating whether to use the order book
130
+
131
+ Example:
132
+ ```typescript
133
+ const result = await exchange.placeOrder({
134
+ marketAcc: '0xMarketAccHex',
135
+ marketAddress: '0xMarketAddress',
136
+ ammAddresses: ['0xAmmAddress1', '0xAmmAddress2'],
137
+ side: Side.LONG,
138
+ size: 100000000000000000000n, // 100 tokens with 18 decimals
139
+ limitTick: 1000,
140
+ tif: TimeInForce.GOOD_TIL_CANCELLED,
141
+ useOrderBook: true
142
+ });
143
+ ```
144
+
145
+ ### Bulk Place Orders
146
+
147
+ ```typescript
148
+ async bulkPlaceOrders(orderRequests: PlaceOrderParams[]): Promise<Array<{
149
+ executeResponse: any;
150
+ result: { order: any };
151
+ }>>
152
+ ```
153
+
154
+ Places multiple orders in a single transaction.
155
+
156
+ Parameters:
157
+ - `orderRequests`: Array of PlaceOrderParams objects
158
+
159
+ Example:
160
+ ```typescript
161
+ const results = await exchange.bulkPlaceOrders([
162
+ {
163
+ marketAcc: '0xMarketAccHex1',
164
+ marketAddress: '0xMarketAddress1',
165
+ ammAddresses: ['0xAmmAddress1'],
166
+ side: Side.LONG,
167
+ size: 100000000000000000000n,
168
+ limitTick: 1000,
169
+ tif: TimeInForce.GOOD_TIL_CANCELLED,
170
+ useOrderBook: true
171
+ },
172
+ {
173
+ marketAcc: '0xMarketAccHex2',
174
+ marketAddress: '0xMarketAddress2',
175
+ ammAddresses: ['0xAmmAddress2'],
176
+ side: Side.SHORT,
177
+ size: 50000000000000000000n,
178
+ limitTick: 950,
179
+ tif: TimeInForce.POST_ONLY,
180
+ useOrderBook: true
181
+ }
182
+ ]);
183
+ ```
184
+
185
+ ### Modify Order
186
+
187
+ ```typescript
188
+ async modifyOrder(params: ModifyOrderParams): Promise<{
189
+ executeResponse: any;
190
+ result: { order: any };
191
+ }>
192
+ ```
193
+
194
+ Modifies an existing order.
195
+
196
+ Parameters:
197
+ - `orderId`: ID of the order to modify
198
+ - `marketAcc`: Hexadecimal market account identifier
199
+ - `marketAddress`: Address of the market
200
+ - `size`: New order size as bigint
201
+ - `limitTick`: New tick price limit
202
+ - `tif`: New time-in-force setting
203
+
204
+ Example:
205
+ ```typescript
206
+ const result = await exchange.modifyOrder({
207
+ orderId: '123456789',
208
+ marketAcc: '0xMarketAccHex',
209
+ marketAddress: '0xMarketAddress',
210
+ size: 150000000000000000000n, // 150 tokens with 18 decimals
211
+ limitTick: 1050,
212
+ tif: TimeInForce.GOOD_TIL_CANCELLED
213
+ });
214
+ ```
215
+
216
+ ### Bulk Modify Orders
217
+
218
+ ```typescript
219
+ async bulkModifyOrder(orderRequests: ModifyOrderParams[]): Promise<Array<{
220
+ executeResponse: any;
221
+ result: { order: any };
222
+ }>>
223
+ ```
224
+
225
+ Modifies multiple orders.
226
+
227
+ Parameters:
228
+ - `orderRequests`: Array of ModifyOrderParams objects
229
+
230
+ ### Cancel Orders
231
+
232
+ ```typescript
233
+ async cancelOrders(params: CancelOrdersParams): Promise<{
234
+ executeResponse: any;
235
+ result: { cancelledOrders: any };
236
+ }>
237
+ ```
238
+
239
+ Cancels one or more orders.
240
+
241
+ Parameters:
242
+ - `marketAcc`: Use MarketAccLib to get
243
+ - `marketAddress`: Address of the market
244
+ - `cancelAll`: Boolean indicating whether to cancel all orders
245
+ - `orderIds`: Array of order IDs to cancel (used when cancelAll is false)
246
+
247
+ Example:
248
+ ```typescript
249
+ // Cancel specific orders
250
+ const result = await exchange.cancelOrders({
251
+ marketAcc: '0xMarketAccHex',
252
+ marketAddress: '0xMarketAddress',
253
+ cancelAll: false,
254
+ orderIds: ['123456789', '987654321']
255
+ });
256
+
257
+ // Cancel all orders
258
+ const result = await exchange.cancelOrders({
259
+ marketAcc: '0xMarketAccHex',
260
+ marketAddress: '0xMarketAddress',
261
+ cancelAll: true,
262
+ orderIds: []
263
+ });
264
+ ```
265
+
266
+ ### Bulk Cancel Orders
267
+
268
+ ```typescript
269
+ async bulkCancelOrders(cancelOrderRequests: CancelOrdersParams[]): Promise<Array<{
270
+ executeResponse: any;
271
+ result: { cancelledOrders: any };
272
+ }>>
273
+ ```
274
+
275
+ Cancels multiple orders from different markets.
276
+
277
+ Parameters:
278
+ - `cancelOrderRequests`: Array of CancelOrdersParams objects
279
+
280
+
281
+
282
+ ## Agent Management
283
+
284
+ ### Approve Agent
285
+
286
+ ```typescript
287
+ async approveAgent(agent?: Agent): Promise<any>
288
+ ```
289
+
290
+ Approves an agent for transaction signing.
291
+
292
+ Parameters:
293
+ - `agent`: Optional Agent instance. If not provided, a new agent will be created.
294
+
295
+ Example:
296
+ ```typescript
297
+ // Approve a new agent
298
+ const agentApproval = await exchange.approveAgent();
299
+
300
+ // Approve a specific agent
301
+ import { Agent } from 'pendle-sdk-boros';
302
+ const customAgent = await Agent.create(walletClient);
303
+ const agentApproval = await exchange.approveAgent(customAgent.agent);
304
+ ```
305
+
306
+ ## Funds Management
307
+
308
+ ### Deposit
309
+
310
+ ```typescript
311
+ async deposit(params: DepositParams): Promise<any>
312
+ ```
313
+
314
+ Deposits funds into the exchange.
315
+
316
+ Parameters:
317
+ - `userAddress`: Address of the user
318
+ - `collateralAddress`: Address of the collateral token
319
+ - `amount`: Amount to deposit as bigint
320
+
321
+ Example:
322
+ ```typescript
323
+ const receipt = await exchange.deposit({
324
+ userAddress: '0xYourWalletAddress',
325
+ collateralAddress: '0xTokenAddress',
326
+ amount: 1000000000000000000n // 1 token with 18 decimals
327
+ });
328
+ ```
329
+
330
+ ### Withdraw
331
+
332
+ ```typescript
333
+ async withdraw(params: WithdrawParams): Promise<any>
334
+ ```
335
+
336
+ Withdraws funds from the exchange.
337
+
338
+ Parameters:
339
+ - `userAddress`: Address of the user
340
+ - `collateralAddress`: Address of the collateral token
341
+ - `amount`: Amount to withdraw as bigint
342
+
343
+ Example:
344
+ ```typescript
345
+ const receipt = await exchange.withdraw({
346
+ userAddress: '0xYourWalletAddress',
347
+ collateralAddress: '0xTokenAddress',
348
+ amount: 1000000000000000000n // 1 token with 18 decimals
349
+ });
350
+ ```
351
+
352
+ ### Cash Transfer
353
+
354
+ ```typescript
355
+ async cashTransfer(params: CashTransferParams): Promise<any>
356
+ ```
357
+
358
+ Transfers cash between markets.
359
+
360
+ Parameters:
361
+ - `marketId`: ID of the market
362
+ - `isDeposit`: true if transferring from vault to marketId
363
+ - `amount`: Amount to transfer as bigint
364
+
365
+ Example:
366
+ ```typescript
367
+ const response = await exchange.cashTransfer({
368
+ marketId: 1,
369
+ isDeposit: true,
370
+ amount: 1000000000000000000n // 1 token with 18 decimals
371
+ });
372
+ ```
373
+
374
+ ## Position Management
375
+
376
+ ### Close Active Positions
377
+
378
+ ```typescript
379
+ async closeActivePositions(params: CloseActivePositionsParams): Promise<any>
380
+ ```
381
+
382
+ Closes active positions.
383
+
384
+ Parameters:
385
+ - `marketAcc`: Hexadecimal market account identifier
386
+ - `marketAddress`: Address of the market
387
+ - `type`: Type of closing ("market" or "limit")
388
+ - `size`: Size to close as bigint
389
+ - `rate`: Optional rate for limit closings
390
+
391
+ Example:
392
+ ```typescript
393
+ // Close with market order
394
+ const response = await exchange.closeActivePositions({
395
+ marketAcc: '0xMarketAccHex',
396
+ marketAddress: '0xMarketAddress',
397
+ type: "market",
398
+ size: 100000000000000000000n // 100 tokens with 18 decimals
399
+ });
400
+
401
+ // Close with limit order
402
+ const response = await exchange.closeActivePositions({
403
+ marketAcc: '0xMarketAccHex',
404
+ marketAddress: '0xMarketAddress',
405
+ type: "limit",
406
+ size: 100000000000000000000n,
407
+ rate: 0.05 // 5% rate
408
+ });
409
+ ```
410
+
411
+ ## Settings Management
412
+
413
+ ### Update Settings
414
+
415
+ ```typescript
416
+ async updateSettings(params: UpdateSettingsParams): Promise<any>
417
+ ```
418
+
419
+ Updates account settings.
420
+
421
+ Parameters:
422
+ - `marketAcc`: Hexadecimal market account identifier
423
+ - `marketAddress`: Address of the market
424
+ - `leverage`: Leverage value
425
+ - `signature`: Signature as hexadecimal
426
+ - `agent`: Agent address as hexadecimal
427
+ - `timestamp`: Timestamp
428
+
429
+ Example:
430
+ ```typescript
431
+ const response = await exchange.updateSettings({
432
+ marketAcc: '0xMarketAccHex',
433
+ marketAddress: '0xMarketAddress',
434
+ leverage: 5, // 5x leverage
435
+ signature: '0xSignatureHex',
436
+ agent: '0xAgentAddress',
437
+ timestamp: Math.floor(Date.now() / 1000)
438
+ });
439
+ ```
440
+
441
+ ## Data Retrieval
442
+
443
+ ### Get Markets
444
+
445
+ ```typescript
446
+ async getMarkets(params: GetMarketsParams): Promise<any>
447
+ ```
448
+
449
+ Retrieves market data.
450
+
451
+ Parameters:
452
+ - `skip`: Optional number of records to skip
453
+ - `limit`: Optional limit on the number of records
454
+ - `isWhitelisted`: Optional filter for whitelisted markets
455
+
456
+ Example:
457
+ ```typescript
458
+ const markets = await exchange.getMarkets({
459
+ skip: 0,
460
+ limit: 10,
461
+ isWhitelisted: true
462
+ });
463
+ ```
464
+
465
+ ### Get Order Book
466
+
467
+ ```typescript
468
+ async getOrderBook(params: GetOrderBookParams): Promise<any>
469
+ ```
470
+
471
+ Retrieves the order book for a market.
472
+
473
+ Parameters:
474
+ - `marketAddress`: Address of the market
475
+ - `tickSize`: Tick size (0.00001, 0.0001, 0.001, 0.01, or 0.1)
476
+
477
+ Example:
478
+ ```typescript
479
+ const orderBook = await exchange.getOrderBook({
480
+ marketAddress: '0xMarketAddress',
481
+ tickSize: 0.001
482
+ });
483
+ ```
484
+
485
+ ### Get PnL Limit Orders
486
+
487
+ ```typescript
488
+ async getPnlLimitOrders(params: GetPnlLimitOrdersParams): Promise<any>
489
+ ```
490
+
491
+ Retrieves PnL (Profit and Loss) limit orders.
492
+
493
+ Parameters:
494
+ - `skip`: Optional number of records to skip
495
+ - `limit`: Optional limit on the number of records
496
+ - `isActive`: Optional filter for active orders
497
+ - `marketAddress`: Optional filter for a specific market
498
+ - `orderBy`: Optional field to order by ('timeClosed', 'positionSize', 'avgFixedApr', 'avgUnderlyingApr', 'pnl')
499
+
500
+ Example:
501
+ ```typescript
502
+ const pnlOrders = await exchange.getPnlLimitOrders({
503
+ skip: 0,
504
+ limit: 10,
505
+ isActive: true,
506
+ marketAddress: '0xMarketAddress',
507
+ orderBy: 'pnl'
508
+ });
509
+ ```
510
+
511
+ ### Get Collaterals
512
+
513
+ ```typescript
514
+ async getCollaterals(): Promise<any>
515
+ ```
516
+
517
+ Retrieves collateral information for the current user and account.
518
+
519
+ Example:
520
+ ```typescript
521
+ const collaterals = await exchange.getCollaterals();
522
+ ```
523
+
524
+ ### Get Active Positions
525
+
526
+ ```typescript
527
+ async getActivePositions(params: GetActivePositionsParams): Promise<any>
528
+ ```
529
+
530
+ Retrieves active positions.
531
+
532
+ Parameters:
533
+ - `marketAddress`: Optional filter for a specific market
534
+
535
+ Example:
536
+ ```typescript
537
+ // Get all active positions
538
+ const allPositions = await exchange.getActivePositions({});
539
+
540
+ // Get active positions for a specific market
541
+ const marketPositions = await exchange.getActivePositions({
542
+ marketAddress: '0xMarketAddress'
543
+ });
544
+ ```
545
+
546
+ ### Get Closed Positions
547
+
548
+ ```typescript
549
+ async getClosedPositions(params: GetClosedPositionsParams): Promise<any>
550
+ ```
551
+
552
+ Retrieves closed positions.
553
+
554
+ Parameters:
555
+ - `marketAddress`: Optional filter for a specific market
556
+ - `skip`: Optional number of records to skip
557
+ - `limit`: Optional limit on the number of records
558
+ - `orderBy`: Optional field to order by ('timeClosed', 'positionSize', 'avgFixedApr', 'avgUnderlyingApr', 'pnl')
559
+
560
+ Example:
561
+ ```typitten
562
+ const closedPositions = await exchange.getClosedPositions({
563
+ marketAddress: '0xMarketAddress',
564
+ skip: 0,
565
+ limit: 10,
566
+ orderBy: 'timeClosed'
567
+ });
568
+ ```