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.
- package/LICENSE +7 -0
- package/README.md +199 -97
- package/dist/__tests__/deleverageEstimate.unit.test.d.ts +10 -0
- package/dist/__tests__/deleverageEstimate.unit.test.d.ts.map +1 -0
- package/dist/__tests__/deleverageEstimate.unit.test.js +116 -0
- package/dist/__tests__/deleverageEstimate.unit.test.js.map +1 -0
- package/dist/__tests__/findBestLeverageRoute.test.d.ts +12 -0
- package/dist/__tests__/findBestLeverageRoute.test.d.ts.map +1 -0
- package/dist/__tests__/findBestLeverageRoute.test.js +177 -0
- package/dist/__tests__/findBestLeverageRoute.test.js.map +1 -0
- package/dist/__tests__/getAssetApy.test.d.ts +2 -0
- package/dist/__tests__/getAssetApy.test.d.ts.map +1 -0
- package/dist/__tests__/getAssetApy.test.js +133 -0
- package/dist/__tests__/getAssetApy.test.js.map +1 -0
- package/dist/__tests__/getAssetRiskParams.test.d.ts +11 -0
- package/dist/__tests__/getAssetRiskParams.test.d.ts.map +1 -0
- package/dist/__tests__/getAssetRiskParams.test.js +183 -0
- package/dist/__tests__/getAssetRiskParams.test.js.map +1 -0
- package/dist/__tests__/internal.getAssetApy.test.d.ts +2 -0
- package/dist/__tests__/internal.getAssetApy.test.d.ts.map +1 -0
- package/dist/__tests__/internal.getAssetApy.test.js +140 -0
- package/dist/__tests__/internal.getAssetApy.test.js.map +1 -0
- package/dist/__tests__/internal.getAssetRiskParams.test.d.ts +22 -0
- package/dist/__tests__/internal.getAssetRiskParams.test.d.ts.map +1 -0
- package/dist/__tests__/internal.getAssetRiskParams.test.js +194 -0
- package/dist/__tests__/internal.getAssetRiskParams.test.js.map +1 -0
- package/dist/__tests__/internal.getPosition.test.d.ts +22 -0
- package/dist/__tests__/internal.getPosition.test.d.ts.map +1 -0
- package/dist/__tests__/internal.getPosition.test.js +153 -0
- package/dist/__tests__/internal.getPosition.test.js.map +1 -0
- package/dist/__tests__/leveragePreview.unit.test.d.ts +10 -0
- package/dist/__tests__/leveragePreview.unit.test.d.ts.map +1 -0
- package/dist/__tests__/leveragePreview.unit.test.js +168 -0
- package/dist/__tests__/leveragePreview.unit.test.js.map +1 -0
- package/dist/__tests__/leverageRoute.unit.test.d.ts +10 -0
- package/dist/__tests__/leverageRoute.unit.test.d.ts.map +1 -0
- package/dist/__tests__/leverageRoute.unit.test.js +159 -0
- package/dist/__tests__/leverageRoute.unit.test.js.map +1 -0
- package/dist/__tests__/previewLeverage.test.d.ts +13 -0
- package/dist/__tests__/previewLeverage.test.d.ts.map +1 -0
- package/dist/__tests__/previewLeverage.test.js +217 -0
- package/dist/__tests__/previewLeverage.test.js.map +1 -0
- package/dist/__tests__/sdk.bestRoute.test.d.ts +22 -0
- package/dist/__tests__/sdk.bestRoute.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.bestRoute.test.js +186 -0
- package/dist/__tests__/sdk.bestRoute.test.js.map +1 -0
- package/dist/__tests__/sdk.bestRoute.unit.test.d.ts +16 -0
- package/dist/__tests__/sdk.bestRoute.unit.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.bestRoute.unit.test.js +165 -0
- package/dist/__tests__/sdk.bestRoute.unit.test.js.map +1 -0
- package/dist/__tests__/sdk.deleverage.test.d.ts +21 -0
- package/dist/__tests__/sdk.deleverage.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.deleverage.test.js +130 -0
- package/dist/__tests__/sdk.deleverage.test.js.map +1 -0
- package/dist/__tests__/sdk.deleverage.unit.test.d.ts +21 -0
- package/dist/__tests__/sdk.deleverage.unit.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.deleverage.unit.test.js +141 -0
- package/dist/__tests__/sdk.deleverage.unit.test.js.map +1 -0
- package/dist/__tests__/sdk.leverage.test.d.ts +19 -0
- package/dist/__tests__/sdk.leverage.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.leverage.test.js +188 -0
- package/dist/__tests__/sdk.leverage.test.js.map +1 -0
- package/dist/__tests__/sdk.portfolio.test.d.ts +17 -0
- package/dist/__tests__/sdk.portfolio.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.portfolio.test.js +162 -0
- package/dist/__tests__/sdk.portfolio.test.js.map +1 -0
- package/dist/__tests__/sdk.position.test.d.ts +16 -0
- package/dist/__tests__/sdk.position.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.position.test.js +193 -0
- package/dist/__tests__/sdk.position.test.js.map +1 -0
- package/dist/__tests__/sdk.preview.test.d.ts +23 -0
- package/dist/__tests__/sdk.preview.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.preview.test.js +226 -0
- package/dist/__tests__/sdk.preview.test.js.map +1 -0
- package/dist/__tests__/sdk.preview.unit.test.d.ts +18 -0
- package/dist/__tests__/sdk.preview.unit.test.d.ts.map +1 -0
- package/dist/__tests__/sdk.preview.unit.test.js +175 -0
- package/dist/__tests__/sdk.preview.unit.test.js.map +1 -0
- package/dist/__tests__/utils.normalizeCoinType.test.d.ts +7 -0
- package/dist/__tests__/utils.normalizeCoinType.test.d.ts.map +1 -0
- package/dist/__tests__/utils.normalizeCoinType.test.js +42 -0
- package/dist/__tests__/utils.normalizeCoinType.test.js.map +1 -0
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -40
- package/dist/index.js.map +1 -1
- package/dist/protocols/base-adapter.d.ts +42 -75
- package/dist/protocols/base-adapter.d.ts.map +1 -1
- package/dist/protocols/base-adapter.js +34 -77
- package/dist/protocols/base-adapter.js.map +1 -1
- package/dist/protocols/navi/adapter.d.ts +22 -2
- package/dist/protocols/navi/adapter.d.ts.map +1 -1
- package/dist/protocols/navi/adapter.js +145 -11
- package/dist/protocols/navi/adapter.js.map +1 -1
- package/dist/protocols/scallop/adapter.d.ts +26 -6
- package/dist/protocols/scallop/adapter.d.ts.map +1 -1
- package/dist/protocols/scallop/adapter.js +206 -43
- package/dist/protocols/scallop/adapter.js.map +1 -1
- package/dist/protocols/scallop/flash-loan.d.ts +18 -3
- package/dist/protocols/scallop/flash-loan.d.ts.map +1 -1
- package/dist/protocols/scallop/flash-loan.js +79 -20
- package/dist/protocols/scallop/flash-loan.js.map +1 -1
- package/dist/protocols/scallop/types.d.ts.map +1 -1
- package/dist/protocols/scallop/types.js +4 -1
- package/dist/protocols/scallop/types.js.map +1 -1
- package/dist/protocols/suilend/adapter.d.ts +19 -1
- package/dist/protocols/suilend/adapter.d.ts.map +1 -1
- package/dist/protocols/suilend/adapter.js +196 -51
- package/dist/protocols/suilend/adapter.js.map +1 -1
- package/dist/sdk.d.ts +107 -148
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +171 -523
- package/dist/sdk.js.map +1 -1
- package/dist/strategies/common.d.ts +42 -0
- package/dist/strategies/common.d.ts.map +1 -0
- package/dist/strategies/common.js +81 -0
- package/dist/strategies/common.js.map +1 -0
- package/dist/strategies/deleverage.d.ts.map +1 -1
- package/dist/strategies/deleverage.js +44 -62
- package/dist/strategies/deleverage.js.map +1 -1
- package/dist/strategies/index.d.ts +9 -1
- package/dist/strategies/index.d.ts.map +1 -1
- package/dist/strategies/index.js +11 -2
- package/dist/strategies/index.js.map +1 -1
- package/dist/strategies/leverage-preview.d.ts +27 -0
- package/dist/strategies/leverage-preview.d.ts.map +1 -0
- package/dist/strategies/leverage-preview.js +120 -0
- package/dist/strategies/leverage-preview.js.map +1 -0
- package/dist/strategies/leverage-route.d.ts +29 -0
- package/dist/strategies/leverage-route.d.ts.map +1 -0
- package/dist/strategies/leverage-route.js +112 -0
- package/dist/strategies/leverage-route.js.map +1 -0
- package/dist/strategies/leverage.d.ts +4 -44
- package/dist/strategies/leverage.d.ts.map +1 -1
- package/dist/strategies/leverage.js +43 -112
- package/dist/strategies/leverage.js.map +1 -1
- package/dist/strategies/scallop-leverage.d.ts +34 -0
- package/dist/strategies/scallop-leverage.d.ts.map +1 -0
- package/dist/strategies/scallop-leverage.js +143 -0
- package/dist/strategies/scallop-leverage.js.map +1 -0
- package/dist/types/config.d.ts +0 -7
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/constants.js +9 -1
- package/dist/types/constants.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/position.d.ts +7 -3
- package/dist/types/position.d.ts.map +1 -1
- package/dist/types/protocol.d.ts +101 -0
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +82 -38
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/utils/calculations.d.ts +10 -137
- package/dist/utils/calculations.d.ts.map +1 -1
- package/dist/utils/calculations.js +11 -162
- package/dist/utils/calculations.js.map +1 -1
- package/dist/utils/coin.d.ts +16 -7
- package/dist/utils/coin.d.ts.map +1 -1
- package/dist/utils/coin.js +32 -25
- package/dist/utils/coin.js.map +1 -1
- package/dist/utils/errors.d.ts +0 -18
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +2 -40
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/execution.d.ts +38 -0
- package/dist/utils/execution.d.ts.map +1 -0
- package/dist/utils/execution.js +110 -0
- package/dist/utils/execution.js.map +1 -0
- package/dist/utils/gas.d.ts +0 -37
- package/dist/utils/gas.d.ts.map +1 -1
- package/dist/utils/gas.js +2 -60
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- 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
|
|
8
|
-
import { Ed25519Keypair } from
|
|
9
|
-
import { Transaction } from
|
|
10
|
-
import { LendingProtocol,
|
|
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 =
|
|
17
|
-
*
|
|
18
|
-
* const
|
|
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 =
|
|
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(
|
|
43
|
+
private constructor();
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
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
|
|
53
|
+
* const sdk = await DefiDashSDK.create(suiClient, keypair);
|
|
53
54
|
* ```
|
|
54
55
|
*
|
|
55
56
|
* @example Browser
|
|
56
57
|
* ```typescript
|
|
57
|
-
* await
|
|
58
|
+
* const sdk = await DefiDashSDK.create(suiClient, account.address);
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
|
-
|
|
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
|
-
*
|
|
121
|
+
* Get position for a single protocol
|
|
119
122
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
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
|
-
|
|
135
|
+
getPosition(protocol: LendingProtocol): Promise<PositionInfo | null>;
|
|
220
136
|
/**
|
|
221
|
-
* Get
|
|
222
|
-
*
|
|
223
|
-
* @param protocol - The lending protocol to query
|
|
137
|
+
* Get all open positions across all supported protocols
|
|
224
138
|
*
|
|
225
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
146
|
+
* const positions = await sdk.getOpenPositions();
|
|
233
147
|
*
|
|
234
|
-
*
|
|
235
|
-
* console.log(
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* }
|
|
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
|
-
|
|
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
|
-
* -
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
365
|
-
*
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
*
|
|
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
|
-
|
|
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;A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