defi-dash-sdk 0.1.3 → 0.1.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.
Files changed (181) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +199 -97
  3. package/dist/__tests__/deleverageEstimate.unit.test.d.ts +10 -0
  4. package/dist/__tests__/deleverageEstimate.unit.test.d.ts.map +1 -0
  5. package/dist/__tests__/deleverageEstimate.unit.test.js +116 -0
  6. package/dist/__tests__/deleverageEstimate.unit.test.js.map +1 -0
  7. package/dist/__tests__/findBestLeverageRoute.test.d.ts +12 -0
  8. package/dist/__tests__/findBestLeverageRoute.test.d.ts.map +1 -0
  9. package/dist/__tests__/findBestLeverageRoute.test.js +177 -0
  10. package/dist/__tests__/findBestLeverageRoute.test.js.map +1 -0
  11. package/dist/__tests__/getAssetApy.test.d.ts +2 -0
  12. package/dist/__tests__/getAssetApy.test.d.ts.map +1 -0
  13. package/dist/__tests__/getAssetApy.test.js +133 -0
  14. package/dist/__tests__/getAssetApy.test.js.map +1 -0
  15. package/dist/__tests__/getAssetRiskParams.test.d.ts +11 -0
  16. package/dist/__tests__/getAssetRiskParams.test.d.ts.map +1 -0
  17. package/dist/__tests__/getAssetRiskParams.test.js +183 -0
  18. package/dist/__tests__/getAssetRiskParams.test.js.map +1 -0
  19. package/dist/__tests__/internal.getAssetApy.test.d.ts +2 -0
  20. package/dist/__tests__/internal.getAssetApy.test.d.ts.map +1 -0
  21. package/dist/__tests__/internal.getAssetApy.test.js +140 -0
  22. package/dist/__tests__/internal.getAssetApy.test.js.map +1 -0
  23. package/dist/__tests__/internal.getAssetRiskParams.test.d.ts +22 -0
  24. package/dist/__tests__/internal.getAssetRiskParams.test.d.ts.map +1 -0
  25. package/dist/__tests__/internal.getAssetRiskParams.test.js +194 -0
  26. package/dist/__tests__/internal.getAssetRiskParams.test.js.map +1 -0
  27. package/dist/__tests__/internal.getPosition.test.d.ts +22 -0
  28. package/dist/__tests__/internal.getPosition.test.d.ts.map +1 -0
  29. package/dist/__tests__/internal.getPosition.test.js +153 -0
  30. package/dist/__tests__/internal.getPosition.test.js.map +1 -0
  31. package/dist/__tests__/leveragePreview.unit.test.d.ts +10 -0
  32. package/dist/__tests__/leveragePreview.unit.test.d.ts.map +1 -0
  33. package/dist/__tests__/leveragePreview.unit.test.js +168 -0
  34. package/dist/__tests__/leveragePreview.unit.test.js.map +1 -0
  35. package/dist/__tests__/leverageRoute.unit.test.d.ts +10 -0
  36. package/dist/__tests__/leverageRoute.unit.test.d.ts.map +1 -0
  37. package/dist/__tests__/leverageRoute.unit.test.js +159 -0
  38. package/dist/__tests__/leverageRoute.unit.test.js.map +1 -0
  39. package/dist/__tests__/previewLeverage.test.d.ts +13 -0
  40. package/dist/__tests__/previewLeverage.test.d.ts.map +1 -0
  41. package/dist/__tests__/previewLeverage.test.js +217 -0
  42. package/dist/__tests__/previewLeverage.test.js.map +1 -0
  43. package/dist/__tests__/sdk.bestRoute.test.d.ts +22 -0
  44. package/dist/__tests__/sdk.bestRoute.test.d.ts.map +1 -0
  45. package/dist/__tests__/sdk.bestRoute.test.js +186 -0
  46. package/dist/__tests__/sdk.bestRoute.test.js.map +1 -0
  47. package/dist/__tests__/sdk.bestRoute.unit.test.d.ts +16 -0
  48. package/dist/__tests__/sdk.bestRoute.unit.test.d.ts.map +1 -0
  49. package/dist/__tests__/sdk.bestRoute.unit.test.js +165 -0
  50. package/dist/__tests__/sdk.bestRoute.unit.test.js.map +1 -0
  51. package/dist/__tests__/sdk.deleverage.test.d.ts +21 -0
  52. package/dist/__tests__/sdk.deleverage.test.d.ts.map +1 -0
  53. package/dist/__tests__/sdk.deleverage.test.js +130 -0
  54. package/dist/__tests__/sdk.deleverage.test.js.map +1 -0
  55. package/dist/__tests__/sdk.deleverage.unit.test.d.ts +21 -0
  56. package/dist/__tests__/sdk.deleverage.unit.test.d.ts.map +1 -0
  57. package/dist/__tests__/sdk.deleverage.unit.test.js +141 -0
  58. package/dist/__tests__/sdk.deleverage.unit.test.js.map +1 -0
  59. package/dist/__tests__/sdk.leverage.test.d.ts +19 -0
  60. package/dist/__tests__/sdk.leverage.test.d.ts.map +1 -0
  61. package/dist/__tests__/sdk.leverage.test.js +188 -0
  62. package/dist/__tests__/sdk.leverage.test.js.map +1 -0
  63. package/dist/__tests__/sdk.portfolio.test.d.ts +17 -0
  64. package/dist/__tests__/sdk.portfolio.test.d.ts.map +1 -0
  65. package/dist/__tests__/sdk.portfolio.test.js +162 -0
  66. package/dist/__tests__/sdk.portfolio.test.js.map +1 -0
  67. package/dist/__tests__/sdk.position.test.d.ts +16 -0
  68. package/dist/__tests__/sdk.position.test.d.ts.map +1 -0
  69. package/dist/__tests__/sdk.position.test.js +193 -0
  70. package/dist/__tests__/sdk.position.test.js.map +1 -0
  71. package/dist/__tests__/sdk.preview.test.d.ts +23 -0
  72. package/dist/__tests__/sdk.preview.test.d.ts.map +1 -0
  73. package/dist/__tests__/sdk.preview.test.js +226 -0
  74. package/dist/__tests__/sdk.preview.test.js.map +1 -0
  75. package/dist/__tests__/sdk.preview.unit.test.d.ts +18 -0
  76. package/dist/__tests__/sdk.preview.unit.test.d.ts.map +1 -0
  77. package/dist/__tests__/sdk.preview.unit.test.js +175 -0
  78. package/dist/__tests__/sdk.preview.unit.test.js.map +1 -0
  79. package/dist/__tests__/utils.normalizeCoinType.test.d.ts +7 -0
  80. package/dist/__tests__/utils.normalizeCoinType.test.d.ts.map +1 -0
  81. package/dist/__tests__/utils.normalizeCoinType.test.js +42 -0
  82. package/dist/__tests__/utils.normalizeCoinType.test.js.map +1 -0
  83. package/dist/index.d.ts +19 -11
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +24 -40
  86. package/dist/index.js.map +1 -1
  87. package/dist/protocols/base-adapter.d.ts +42 -75
  88. package/dist/protocols/base-adapter.d.ts.map +1 -1
  89. package/dist/protocols/base-adapter.js +34 -77
  90. package/dist/protocols/base-adapter.js.map +1 -1
  91. package/dist/protocols/navi/adapter.d.ts +22 -2
  92. package/dist/protocols/navi/adapter.d.ts.map +1 -1
  93. package/dist/protocols/navi/adapter.js +145 -11
  94. package/dist/protocols/navi/adapter.js.map +1 -1
  95. package/dist/protocols/scallop/adapter.d.ts +26 -6
  96. package/dist/protocols/scallop/adapter.d.ts.map +1 -1
  97. package/dist/protocols/scallop/adapter.js +206 -43
  98. package/dist/protocols/scallop/adapter.js.map +1 -1
  99. package/dist/protocols/scallop/flash-loan.d.ts +18 -3
  100. package/dist/protocols/scallop/flash-loan.d.ts.map +1 -1
  101. package/dist/protocols/scallop/flash-loan.js +79 -20
  102. package/dist/protocols/scallop/flash-loan.js.map +1 -1
  103. package/dist/protocols/scallop/types.d.ts.map +1 -1
  104. package/dist/protocols/scallop/types.js +4 -1
  105. package/dist/protocols/scallop/types.js.map +1 -1
  106. package/dist/protocols/suilend/adapter.d.ts +19 -1
  107. package/dist/protocols/suilend/adapter.d.ts.map +1 -1
  108. package/dist/protocols/suilend/adapter.js +196 -51
  109. package/dist/protocols/suilend/adapter.js.map +1 -1
  110. package/dist/sdk.d.ts +107 -148
  111. package/dist/sdk.d.ts.map +1 -1
  112. package/dist/sdk.js +171 -523
  113. package/dist/sdk.js.map +1 -1
  114. package/dist/strategies/common.d.ts +42 -0
  115. package/dist/strategies/common.d.ts.map +1 -0
  116. package/dist/strategies/common.js +81 -0
  117. package/dist/strategies/common.js.map +1 -0
  118. package/dist/strategies/deleverage.d.ts.map +1 -1
  119. package/dist/strategies/deleverage.js +44 -62
  120. package/dist/strategies/deleverage.js.map +1 -1
  121. package/dist/strategies/index.d.ts +9 -1
  122. package/dist/strategies/index.d.ts.map +1 -1
  123. package/dist/strategies/index.js +11 -2
  124. package/dist/strategies/index.js.map +1 -1
  125. package/dist/strategies/leverage-preview.d.ts +27 -0
  126. package/dist/strategies/leverage-preview.d.ts.map +1 -0
  127. package/dist/strategies/leverage-preview.js +120 -0
  128. package/dist/strategies/leverage-preview.js.map +1 -0
  129. package/dist/strategies/leverage-route.d.ts +29 -0
  130. package/dist/strategies/leverage-route.d.ts.map +1 -0
  131. package/dist/strategies/leverage-route.js +112 -0
  132. package/dist/strategies/leverage-route.js.map +1 -0
  133. package/dist/strategies/leverage.d.ts +4 -44
  134. package/dist/strategies/leverage.d.ts.map +1 -1
  135. package/dist/strategies/leverage.js +43 -112
  136. package/dist/strategies/leverage.js.map +1 -1
  137. package/dist/strategies/scallop-leverage.d.ts +34 -0
  138. package/dist/strategies/scallop-leverage.d.ts.map +1 -0
  139. package/dist/strategies/scallop-leverage.js +143 -0
  140. package/dist/strategies/scallop-leverage.js.map +1 -0
  141. package/dist/types/config.d.ts +0 -7
  142. package/dist/types/config.d.ts.map +1 -1
  143. package/dist/types/constants.d.ts +8 -0
  144. package/dist/types/constants.d.ts.map +1 -1
  145. package/dist/types/constants.js +9 -1
  146. package/dist/types/constants.js.map +1 -1
  147. package/dist/types/index.d.ts +3 -3
  148. package/dist/types/index.d.ts.map +1 -1
  149. package/dist/types/index.js +2 -1
  150. package/dist/types/index.js.map +1 -1
  151. package/dist/types/position.d.ts +7 -3
  152. package/dist/types/position.d.ts.map +1 -1
  153. package/dist/types/protocol.d.ts +101 -0
  154. package/dist/types/protocol.d.ts.map +1 -1
  155. package/dist/types/strategy.d.ts +82 -38
  156. package/dist/types/strategy.d.ts.map +1 -1
  157. package/dist/utils/calculations.d.ts +10 -137
  158. package/dist/utils/calculations.d.ts.map +1 -1
  159. package/dist/utils/calculations.js +11 -162
  160. package/dist/utils/calculations.js.map +1 -1
  161. package/dist/utils/coin.d.ts +16 -7
  162. package/dist/utils/coin.d.ts.map +1 -1
  163. package/dist/utils/coin.js +32 -25
  164. package/dist/utils/coin.js.map +1 -1
  165. package/dist/utils/errors.d.ts +0 -18
  166. package/dist/utils/errors.d.ts.map +1 -1
  167. package/dist/utils/errors.js +2 -40
  168. package/dist/utils/errors.js.map +1 -1
  169. package/dist/utils/execution.d.ts +38 -0
  170. package/dist/utils/execution.d.ts.map +1 -0
  171. package/dist/utils/execution.js +110 -0
  172. package/dist/utils/execution.js.map +1 -0
  173. package/dist/utils/gas.d.ts +0 -37
  174. package/dist/utils/gas.d.ts.map +1 -1
  175. package/dist/utils/gas.js +2 -60
  176. package/dist/utils/gas.js.map +1 -1
  177. package/dist/utils/index.d.ts +1 -1
  178. package/dist/utils/index.d.ts.map +1 -1
  179. package/dist/utils/index.js +1 -1
  180. package/dist/utils/index.js.map +1 -1
  181. package/package.json +15 -45
package/dist/sdk.d.ts CHANGED
@@ -4,31 +4,31 @@
4
4
  * Multi-protocol DeFi SDK for Sui blockchain
5
5
  * Supports both Node.js (with keypair) and Browser (with wallet adapter)
6
6
  */
7
- import { SuiClient } from "@mysten/sui/client";
8
- import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
9
- import { Transaction } from "@mysten/sui/transactions";
10
- import { LendingProtocol, LeverageParams, DeleverageParams, PositionInfo, StrategyResult, LeveragePreview, SDKOptions, AccountPortfolio, BrowserLeverageParams, BrowserDeleverageParams } from "./types";
7
+ import { SuiClient } from '@mysten/sui/client';
8
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
9
+ import { Transaction } from '@mysten/sui/transactions';
10
+ import { LendingProtocol, PositionInfo, StrategyResult, LeveragePreview, SDKOptions, AccountPortfolio, BrowserLeverageParams, BrowserDeleverageParams, FindBestRouteParams, LeverageRouteResult } from './types';
11
11
  /**
12
12
  * DeFi Dash SDK - Main entry point
13
13
  *
14
- * @example Node.js usage:
14
+ * @example Node.js usage (build + execute):
15
15
  * ```typescript
16
- * const sdk = new DefiDashSDK();
17
- * await sdk.initialize(suiClient, keypair);
18
- * const result = await sdk.leverage({ protocol: LendingProtocol.Suilend, ... });
16
+ * const sdk = await DefiDashSDK.create(suiClient, keypair);
17
+ *
18
+ * const tx = new Transaction();
19
+ * tx.setSender(address);
20
+ * await sdk.buildLeverageTransaction(tx, { protocol, depositAsset, ... });
21
+ * const result = await sdk.execute(tx); // or sdk.dryRun(tx)
19
22
  * ```
20
23
  *
21
24
  * @example Browser usage:
22
25
  * ```typescript
23
- * const sdk = new DefiDashSDK();
24
- * await sdk.initialize(suiClient, userAddress); // No keypair needed
26
+ * const sdk = await DefiDashSDK.create(suiClient, userAddress);
25
27
  *
26
28
  * const tx = new Transaction();
27
29
  * tx.setSender(userAddress);
28
30
  * await sdk.buildLeverageTransaction(tx, { protocol, depositAsset, ... });
29
- *
30
- * // Sign with wallet adapter
31
- * await signAndExecute({ transaction: tx });
31
+ * await signAndExecute({ transaction: tx }); // wallet adapter
32
32
  * ```
33
33
  */
34
34
  export declare class DefiDashSDK {
@@ -40,30 +40,33 @@ export declare class DefiDashSDK {
40
40
  private protocols;
41
41
  private initialized;
42
42
  private options;
43
- constructor(options?: SDKOptions);
43
+ private constructor();
44
44
  /**
45
- * Initialize the SDK
45
+ * Create and initialize the SDK in one step (recommended).
46
46
  *
47
47
  * @param suiClient - Sui client instance
48
48
  * @param keypairOrAddress - Ed25519Keypair (Node.js) or user address string (Browser)
49
+ * @param options - SDK options
49
50
  *
50
51
  * @example Node.js
51
52
  * ```typescript
52
- * await sdk.initialize(suiClient, keypair);
53
+ * const sdk = await DefiDashSDK.create(suiClient, keypair);
53
54
  * ```
54
55
  *
55
56
  * @example Browser
56
57
  * ```typescript
57
- * await sdk.initialize(suiClient, account.address);
58
+ * const sdk = await DefiDashSDK.create(suiClient, account.address);
58
59
  * ```
59
60
  */
60
- initialize(suiClient: SuiClient, keypairOrAddress: Ed25519Keypair | string): Promise<void>;
61
+ static create(suiClient: SuiClient, keypairOrAddress: Ed25519Keypair | string, options?: SDKOptions): Promise<DefiDashSDK>;
62
+ /**
63
+ * Initialize the SDK (internal — use `DefiDashSDK.create()`)
64
+ */
65
+ private initialize;
61
66
  private ensureInitialized;
62
67
  private getProtocol;
63
68
  private get userAddress();
64
- /**
65
- * Resolve asset symbol to coin type
66
- */
69
+ /** Resolve asset symbol to coin type */
67
70
  private resolveCoinType;
68
71
  /**
69
72
  * Build leverage transaction (Browser-compatible)
@@ -115,133 +118,46 @@ export declare class DefiDashSDK {
115
118
  */
116
119
  buildDeleverageTransaction(tx: Transaction, params: BrowserDeleverageParams): Promise<void>;
117
120
  /**
118
- * Execute leverage strategy (Node.js only)
121
+ * Get position for a single protocol
119
122
  *
120
- * Opens a leveraged position by:
121
- * 1. Taking a flash loan
122
- * 2. Swapping borrowed USDC for deposit asset
123
- * 3. Depositing total collateral (user deposit + swapped amount)
124
- * 4. Borrowing USDC to repay flash loan
125
- *
126
- * @param params - Leverage parameters
127
- * @param params.protocol - Lending protocol to use (Suilend, Scallop, or Navi)
128
- * @param params.depositAsset - Asset symbol (e.g., "SUI", "LBTC") or full coin type
129
- * @param params.depositAmount - Amount to deposit (required if depositValueUsd not provided)
130
- * @param params.depositValueUsd - USD value to deposit (required if depositAmount not provided)
131
- * @param params.multiplier - Leverage multiplier (e.g., 2.0 for 2x leverage)
132
- * @param params.dryRun - If true, simulates transaction and returns gas estimate without executing
133
- *
134
- * @returns Strategy result with success status, transaction digest (if executed), and gas used
135
- *
136
- * @throws {SDKNotInitializedError} If SDK not initialized
137
- * @throws {KeypairRequiredError} If keypair not provided (Node.js mode required)
138
- * @throws {InvalidParameterError} If both or neither depositAmount and depositValueUsd provided
139
- * @throws {UnknownAssetError} If asset symbol not recognized
123
+ * @param protocol - Lending protocol to query
124
+ * @returns Position info or null if no active position
140
125
  *
141
126
  * @example
142
127
  * ```typescript
143
- * // Leverage with fixed amount
144
- * const result = await sdk.leverage({
145
- * protocol: LendingProtocol.Suilend,
146
- * depositAsset: 'LBTC',
147
- * depositAmount: '0.001',
148
- * multiplier: 2.0,
149
- * dryRun: true
150
- * });
151
- *
152
- * // Leverage with USD value
153
- * const result = await sdk.leverage({
154
- * protocol: LendingProtocol.Scallop,
155
- * depositAsset: 'SUI',
156
- * depositValueUsd: 100, // $100 worth of SUI
157
- * multiplier: 3.0,
158
- * dryRun: false
159
- * });
160
- * ```
161
- *
162
- * @remarks
163
- * - Requires SDK to be initialized with keypair (Node.js mode)
164
- * - For browser usage, use {@link buildLeverageTransaction} instead
165
- * - Scallop protocol uses optimized native SDK for oracle updates
166
- * - Gas is automatically optimized via dry run (20% buffer added)
167
- */
168
- leverage(params: LeverageParams): Promise<StrategyResult>;
169
- /**
170
- * Execute deleverage strategy (Node.js only)
171
- *
172
- * Closes or reduces a leveraged position by:
173
- * 1. Taking a flash loan to repay debt
174
- * 2. Withdrawing collateral
175
- * 3. Swapping portion of collateral to USDC
176
- * 4. Repaying flash loan
177
- * 5. Keeping remaining collateral
178
- *
179
- * @param params - Deleverage parameters
180
- * @param params.protocol - Lending protocol where position exists
181
- * @param params.dryRun - If true, simulates transaction without executing
182
- *
183
- * @returns Strategy result with success status, transaction digest, and gas used
184
- *
185
- * @throws {SDKNotInitializedError} If SDK not initialized
186
- * @throws {KeypairRequiredError} If keypair not provided (Node.js mode required)
187
- * @throws {PositionNotFoundError} If no position exists on the protocol
188
- * @throws {NoDebtError} If position has no debt (use withdraw instead)
189
- *
190
- * @example
191
- * ```typescript
192
- * // Dry run first to preview
193
- * const preview = await sdk.deleverage({
194
- * protocol: LendingProtocol.Suilend,
195
- * dryRun: true
196
- * });
197
- *
198
- * if (preview.success) {
199
- * console.log(`Estimated gas: ${preview.gasUsed}`);
200
- *
201
- * // Execute for real
202
- * const result = await sdk.deleverage({
203
- * protocol: LendingProtocol.Suilend,
204
- * dryRun: false
205
- * });
206
- *
207
- * if (result.success) {
208
- * console.log(`Position closed: ${result.txDigest}`);
209
- * }
128
+ * const position = await sdk.getPosition(LendingProtocol.Navi);
129
+ * if (position) {
130
+ * console.log(`Collateral: ${position.collateral.symbol} $${position.collateral.valueUsd}`);
131
+ * console.log(`Debt: ${position.debt.symbol} $${position.debt.valueUsd}`);
210
132
  * }
211
133
  * ```
212
- *
213
- * @remarks
214
- * - Requires SDK to be initialized with keypair (Node.js mode)
215
- * - For browser usage, use {@link buildDeleverageTransaction} instead
216
- * - Automatically fetches current position and calculates optimal swap amounts
217
- * - Gas is automatically optimized via dry run (20% buffer added)
218
134
  */
219
- deleverage(params: DeleverageParams): Promise<StrategyResult>;
135
+ getPosition(protocol: LendingProtocol): Promise<PositionInfo | null>;
220
136
  /**
221
- * Get current lending position on a specific protocol
222
- *
223
- * @param protocol - The lending protocol to query
137
+ * Get all open positions across all supported protocols
224
138
  *
225
- * @returns Position information including collateral, debt, and metrics, or null if no position exists
139
+ * Queries Suilend, Navi, and Scallop in parallel and returns
140
+ * only the protocols that have an active position (collateral > 0 or debt > 0).
226
141
  *
227
- * @throws {SDKNotInitializedError} If SDK not initialized
228
- * @throws {UnsupportedProtocolError} If protocol not supported
142
+ * @returns Array of open positions with protocol identifier
229
143
  *
230
144
  * @example
231
145
  * ```typescript
232
- * const position = await sdk.getPosition(LendingProtocol.Suilend);
146
+ * const positions = await sdk.getOpenPositions();
233
147
  *
234
- * if (position) {
235
- * console.log(`Collateral: ${position.collateral.amount} ${position.collateral.symbol}`);
236
- * console.log(`Debt: ${position.debt.amount} ${position.debt.symbol}`);
237
- * console.log(`Health Factor: ${position.healthFactor}`);
238
- * console.log(`Net Value: $${position.netValueUsd}`);
239
- * } else {
240
- * console.log('No position found');
148
+ * for (const { protocol, position } of positions) {
149
+ * console.log(`${protocol}: ${position.collateral.symbol} $${position.collateral.valueUsd.toFixed(2)}`);
150
+ * if (position.debt.amount > 0n) {
151
+ * console.log(` Debt: ${position.debt.symbol} $${position.debt.valueUsd.toFixed(2)}`);
152
+ * }
153
+ * console.log(` Net: $${position.netValueUsd.toFixed(2)}`);
241
154
  * }
242
155
  * ```
243
156
  */
244
- getPosition(protocol: LendingProtocol): Promise<PositionInfo | null>;
157
+ getOpenPositions(): Promise<Array<{
158
+ protocol: LendingProtocol;
159
+ position: PositionInfo;
160
+ }>>;
245
161
  /**
246
162
  * Get aggregated portfolio data from all supported protocols
247
163
  *
@@ -282,6 +198,7 @@ export declare class DefiDashSDK {
282
198
  * Useful for showing users what their leveraged position will look like.
283
199
  *
284
200
  * @param params - Preview parameters
201
+ * @param params.protocol - Lending protocol to use (suilend, navi, scallop)
285
202
  * @param params.depositAsset - Asset symbol (e.g., "SUI", "LBTC") or full coin type
286
203
  * @param params.depositAmount - Amount to deposit (required if depositValueUsd not provided)
287
204
  * @param params.depositValueUsd - USD value to deposit (required if depositAmount not provided)
@@ -290,12 +207,14 @@ export declare class DefiDashSDK {
290
207
  * @returns Preview containing position metrics, flash loan details, and risk parameters
291
208
  *
292
209
  * @throws {InvalidParameterError} If both or neither depositAmount and depositValueUsd provided
210
+ * @throws {InvalidParameterError} If multiplier exceeds protocol's max multiplier
293
211
  * @throws {UnknownAssetError} If asset symbol not recognized
294
212
  *
295
213
  * @example
296
214
  * ```typescript
297
215
  * // Preview with fixed amount
298
216
  * const preview = await sdk.previewLeverage({
217
+ * protocol: 'suilend',
299
218
  * depositAsset: 'LBTC',
300
219
  * depositAmount: '0.001',
301
220
  * multiplier: 2.0
@@ -305,11 +224,13 @@ export declare class DefiDashSDK {
305
224
  * console.log(`Flash Loan: ${preview.flashLoanUsdc / 1e6} USDC`);
306
225
  * console.log(`Total Position: $${preview.totalPositionUsd}`);
307
226
  * console.log(`Position LTV: ${preview.ltvPercent.toFixed(1)}%`);
227
+ * console.log(`Max Multiplier: ${preview.maxMultiplier.toFixed(2)}x`);
308
228
  * console.log(`Liquidation Price: $${preview.liquidationPrice}`);
309
229
  * console.log(`Price Drop Buffer: ${preview.priceDropBuffer.toFixed(1)}%`);
310
230
  *
311
231
  * // Preview with USD value
312
232
  * const preview2 = await sdk.previewLeverage({
233
+ * protocol: 'scallop',
313
234
  * depositAsset: 'SUI',
314
235
  * depositValueUsd: 100, // $100 worth
315
236
  * multiplier: 3.0
@@ -317,17 +238,41 @@ export declare class DefiDashSDK {
317
238
  * ```
318
239
  *
319
240
  * @remarks
320
- * - Does not require SDK initialization (standalone utility)
241
+ * - Queries protocol-specific LTV to calculate accurate max multiplier
242
+ * - Max multiplier = 1 / (1 - LTV), e.g., 65% LTV → 2.857x max
321
243
  * - Fetches current market prices from 7k Protocol
322
244
  * - Calculations are estimates; actual execution may differ slightly
323
245
  * - Higher multipliers increase both returns and liquidation risk
324
246
  */
325
247
  previewLeverage(params: {
248
+ protocol: LendingProtocol;
326
249
  depositAsset: string;
327
250
  depositAmount?: string;
328
251
  depositValueUsd?: number;
329
252
  multiplier: number;
330
253
  }): Promise<LeveragePreview>;
254
+ /**
255
+ * Find the best leverage route across all initialized protocols for a given asset.
256
+ *
257
+ * Returns two recommendations:
258
+ * 1. **bestMaxMultiplier** — the protocol offering the highest possible leverage
259
+ * 2. **bestApy** — the protocol with the highest net APY at a safe multiplier
260
+ *
261
+ * The safe multiplier = min(maxMultiplier across protocols) - LEVERAGE_MULTIPLIER_BUFFER
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const route = await sdk.findBestLeverageRoute({
266
+ * depositAsset: 'SUI',
267
+ * depositValueUsd: 100,
268
+ * });
269
+ *
270
+ * console.log(route.bestMaxMultiplier.protocol); // e.g. 'scallop'
271
+ * console.log(route.bestApy.protocol); // e.g. 'suilend'
272
+ * console.log(route.safeMultiplier); // e.g. 2.83
273
+ * ```
274
+ */
275
+ findBestLeverageRoute(params: FindBestRouteParams): Promise<LeverageRouteResult>;
331
276
  /**
332
277
  * Get token price in USD
333
278
  */
@@ -341,13 +286,26 @@ export declare class DefiDashSDK {
341
286
  */
342
287
  getUserAddress(): string;
343
288
  /**
344
- * Dry run with gas optimization
289
+ * Dry run a transaction with gas optimization
345
290
  *
346
- * Uses small fixed budget for dryrun, returns actual gas estimation.
291
+ * Simulates the transaction and returns estimated gas usage.
292
+ * Does NOT execute the transaction on-chain.
293
+ *
294
+ * @param tx - Built transaction to simulate
295
+ * @returns Strategy result with gas estimate
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const tx = new Transaction();
300
+ * tx.setSender(address);
301
+ * await sdk.buildLeverageTransaction(tx, params);
302
+ * const result = await sdk.dryRun(tx);
303
+ * console.log(`Estimated gas: ${result.gasUsed}`);
304
+ * ```
347
305
  */
348
- private dryRunWithGasOptimization;
306
+ dryRun(tx: Transaction): Promise<StrategyResult>;
349
307
  /**
350
- * Execute transaction with gas optimization
308
+ * Execute a transaction with gas optimization (Node.js only)
351
309
  *
352
310
  * Flow:
353
311
  * 1. Dryrun with small fixed budget to get actual gas usage
@@ -355,19 +313,20 @@ export declare class DefiDashSDK {
355
313
  * 3. Check user has enough balance
356
314
  * 4. Execute with optimized budget
357
315
  *
358
- * This ensures we never overpay for gas.
359
- */
360
- private execute;
361
- /**
362
- * Execute Scallop leverage using native Scallop SDK builder
316
+ * @param tx - Built transaction to execute
317
+ * @returns Strategy result with transaction digest and gas used
363
318
  *
364
- * Scallop requires oracle price updates via their SDK's updateAssetPricesQuick.
365
- * This method uses the Scallop SDK builder internally.
366
- */
367
- private executeScallopLeverage;
368
- /**
369
- * Get Scallop coin name from coin type
319
+ * @throws {KeypairRequiredError} If keypair not provided
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * const tx = new Transaction();
324
+ * tx.setSender(address);
325
+ * await sdk.buildLeverageTransaction(tx, params);
326
+ * const result = await sdk.execute(tx);
327
+ * console.log(`TX: ${result.txDigest}`);
328
+ * ```
370
329
  */
371
- private getScallopCoinName;
330
+ execute(tx: Transaction): Promise<StrategyResult>;
372
331
  }
373
332
  //# sourceMappingURL=sdk.d.ts.map
package/dist/sdk.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,UAAU,EAEV,gBAAgB,EAEhB,q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