haedal-vault-sdk 1.8.2 → 1.8.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 CHANGED
@@ -250,9 +250,11 @@ const tx = await sdk.Vaults.buildDepositPayload({
250
250
  ```typescript
251
251
  const poolId="0x..."
252
252
 
253
+ // Example 1: Single coin deposit without rebalancing (re_balance = false or undefined)
253
254
  const result = await sdk.VaultsV2.preCalculateDepositAmount( {
254
255
  mode: 'OnlyCoinA',
255
256
  coin_amount_a: toDecimalsAmount(1, 6).toString(), // Deposit only asset A
257
+ re_balance: false, // Optional: false for single coin deposit only
256
258
  })
257
259
 
258
260
  // Build the deposit transaction payload
@@ -261,8 +263,42 @@ const tx = await sdk.VaultsV2.buildDepositPayload({
261
263
  amount_a: result.deposit_amount_a,
262
264
  amount_b: result.deposit_amount_b,
263
265
  })
266
+
267
+ // Example 2: Single coin deposit with automatic rebalancing (re_balance = true)
268
+ const resultWithRebalance = await sdk.VaultsV2.preCalculateDepositAmount( {
269
+ mode: 'OnlyCoinA',
270
+ coin_amount_a: toDecimalsAmount(1, 6).toString(), // Deposit amount for asset A
271
+ re_balance: true, // Enable automatic rebalancing to match coin A and coin B
272
+ })
273
+
274
+ // Build the deposit transaction payload with rebalance information
275
+ const txWithRebalance = await sdk.VaultsV2.buildDepositPayload({
276
+ pool_id: poolId,
277
+ amount_a: resultWithRebalance.deposit_amount_a,
278
+ amount_b: resultWithRebalance.deposit_amount_b,
279
+ re_balance: resultWithRebalance.re_balance, // Include rebalance swap information
280
+ })
281
+
282
+
283
+ // Example 3: OnlyCoinB mode with rebalancing
284
+ const resultOnlyCoinB = await sdk.VaultsV2.preCalculateDepositAmount( {
285
+ mode: 'OnlyCoinB',
286
+ coin_amount_b: toDecimalsAmount(1, 9).toString(), // Deposit amount for asset B
287
+ re_balance: true, // Enable automatic rebalancing
288
+ })
289
+
290
+ const txOnlyCoinB = await sdk.VaultsV2.buildDepositPayload({
291
+ pool_id: poolId,
292
+ amount_a: resultOnlyCoinB.deposit_amount_a,
293
+ amount_b: resultOnlyCoinB.deposit_amount_b,
294
+ re_balance: resultOnlyCoinB.re_balance,
295
+ })
264
296
  ```
265
297
 
298
+ **Note on `re_balance` parameter (VaultsV2 only):**
299
+ - When `re_balance` is `true`: The system will automatically calculate and swap a portion of the deposited coin to balance both coin A and coin B according to the pool's ratio. This ensures optimal liquidity provision.
300
+ - When `re_balance` is `false` or `undefined`: Only the specified single coin will be deposited, with the other coin amount set to 0. This is a pure single-coin deposit without rebalancing.
301
+
266
302
  ### 3. Withdrawal
267
303
  Withdrawals can be performed in different modes, similar to deposits.
268
304
 
package/dist/index.d.ts CHANGED
@@ -172,6 +172,8 @@ type WithdrawCalculationResult = {
172
172
  swap?: {
173
173
  swap_amount_in: string;
174
174
  swap_amount_out: string;
175
+ remove_amount_a: string;
176
+ remove_amount_b: string;
175
177
  };
176
178
  };
177
179
  type VaultsBalance = {
@@ -658,12 +660,38 @@ type CollectFeeOptionsV2 = {
658
660
  position_id: string;
659
661
  withdraw_cert?: TransactionObjectArgument;
660
662
  } & PoolCoinTypes;
663
+ type DepositCalculationOptionsV2 = {
664
+ uuid?: string;
665
+ pool_id: string;
666
+ mode: DepositMode;
667
+ } & ({
668
+ mode: 'FixedOneSide';
669
+ fixed_amount: string;
670
+ fixed_coin_a: boolean;
671
+ } | {
672
+ mode: 'FlexibleBoth';
673
+ coin_amount_a: string;
674
+ coin_amount_b: string;
675
+ } | {
676
+ mode: 'OnlyCoinA';
677
+ coin_amount_a: string;
678
+ re_balance?: boolean;
679
+ } | {
680
+ mode: 'OnlyCoinB';
681
+ coin_amount_b: string;
682
+ re_balance?: boolean;
683
+ });
661
684
  type DepositCalculationResultV2 = {
662
685
  deposit_amount_a: string;
663
686
  deposit_amount_b: string;
664
687
  lp_amount?: string;
665
688
  uuid?: string;
666
689
  mode: DepositMode;
690
+ re_balance?: {
691
+ swap_result: SwapResult;
692
+ coin_amount: string;
693
+ mode: 'OnlyCoinA' | 'OnlyCoinB';
694
+ };
667
695
  };
668
696
  type WithdrawCalculationResultV2 = {
669
697
  burn_lp_amount: string;
@@ -673,6 +701,8 @@ type WithdrawCalculationResultV2 = {
673
701
  swap?: {
674
702
  swap_amount_in: string;
675
703
  swap_amount_out: string;
704
+ remove_amount_a: string;
705
+ remove_amount_b: string;
676
706
  };
677
707
  };
678
708
  type VaultsBalanceV2 = {
@@ -699,6 +729,24 @@ type DepositCalculationValueOptionsV2 = {
699
729
  pool_id: string;
700
730
  mode: 'FlexibleBoth' | 'OnlyCoinA' | 'OnlyCoinB';
701
731
  amount_usd: string;
732
+ re_balance?: boolean;
733
+ };
734
+ type SwapResult = {
735
+ swap_in_amount: string;
736
+ swap_out_amount: string;
737
+ route_obj?: any;
738
+ };
739
+ type DepositOptionsV2 = {
740
+ pool_id: string;
741
+ amount_a: string;
742
+ amount_b: string;
743
+ return_lp_coin?: boolean;
744
+ re_balance?: {
745
+ swap_result: SwapResult;
746
+ coin_amount: string;
747
+ mode: 'OnlyCoinA' | 'OnlyCoinB';
748
+ swap_slippage: number;
749
+ };
702
750
  };
703
751
 
704
752
  type BigNumber = Decimal.Value | number | string;
@@ -799,7 +847,7 @@ declare class VaultsModuleV2 implements IModule {
799
847
  * @param tx - An optional transaction object to append to, or a new one if not provided.
800
848
  * @returns return_lp_coin is true, return lp_coin, otherwise return undefined
801
849
  */
802
- buildDepositPayload(options: DepositOptions, tx: Transaction): Promise<TransactionObjectArgument | undefined>;
850
+ buildDepositPayload(options: DepositOptionsV2, tx: Transaction): Promise<TransactionObjectArgument | undefined>;
803
851
  /**
804
852
  * Builds a transaction payload to withdraw from a pool.
805
853
  * @param options - The options required to withdraw.
@@ -842,6 +890,7 @@ declare class VaultsModuleV2 implements IModule {
842
890
  */
843
891
  private buildWithdrawBufferReward;
844
892
  preCalculateDepositValue(options: DepositCalculationValueOptionsV2, lpCallback?: LpCallback): Promise<DepositCalculationResultV2>;
893
+ private calculateBalanceSwapAmount;
845
894
  /**
846
895
  * Pre-calculates the deposit amounts for a liquidity pool based on different deposit modes.
847
896
  * The method calculates how much of each coin to deposit and how much LP (liquidity provider) tokens the user will receive.
@@ -850,14 +899,13 @@ declare class VaultsModuleV2 implements IModule {
850
899
  *
851
900
  * @returns {Promise<DepositCalculationResult>} A promise that resolves to the calculated deposit amounts and the LP tokens to be received.
852
901
  */
853
- preCalculateDepositAmount(options: DepositCalculationOptions, lpCallback?: LpCallback): Promise<DepositCalculationResultV2>;
902
+ preCalculateDepositAmount(options: DepositCalculationOptionsV2, lpCallback?: LpCallback): Promise<DepositCalculationResultV2>;
854
903
  getVaultAndPool(pool_id: string, refreshPool?: boolean): Promise<{
855
904
  dlmmPool: DlmmPool;
856
905
  pool: VaultPool;
857
906
  }>;
858
907
  private calculatePositionValueRates;
859
908
  private calculateDepositAmountsV2;
860
- private calculateDepositAmounts;
861
909
  private calculateDepositOtherSide;
862
910
  private calculateDepositFlexibleBoth;
863
911
  private calculateDepositLpAmountBoth;
@@ -875,6 +923,7 @@ declare class VaultsModuleV2 implements IModule {
875
923
  private calculateWithdrawOnlyCoin;
876
924
  private calculateWithdrawOnlyCoinByLpAmount;
877
925
  getPackageConfigs(): Promise<SdkOptions>;
926
+ findRouters(from: string, target: string, amount: string): Promise<SwapResult>;
878
927
  }
879
928
 
880
929
  /**
@@ -1218,6 +1267,33 @@ declare function getAmountBalanceByLpAmount(sdk: VolatileVaultsSDK, lp_token_amo
1218
1267
  }>;
1219
1268
  declare function buildDLMMMarketId(vaultId: string): string;
1220
1269
  declare function buildDLMMPositionId(positionTableId: string, posId: string): string;
1270
+ /**
1271
+ * Calculate the swap amount needed to achieve target ratio
1272
+ * @param coin_amount - Total coin amount available
1273
+ * @param fix_amount_a - Whether to fix token A amount (true) or token B amount (false)
1274
+ * @param current_price - Current price:
1275
+ * - When fix_amount_a = true: current_price = B/A (price of B in terms of A)
1276
+ * - When fix_amount_a = false: current_price = A/B (price of A in terms of B)
1277
+ * @param target_ratio - Target ratio to achieve:
1278
+ * - When fix_amount_a = true: target_ratio = B/A
1279
+ * - When fix_amount_a = false: target_ratio = A/B
1280
+ * @param tolerance - Tolerance for the target ratio (default: 0.01)
1281
+ * @returns Object containing:
1282
+ * - swap_amount: Amount to swap
1283
+ * - final_amount_a: Final amount of token A (remaining A when fix_amount_a=true, obtained A when fix_amount_a=false)
1284
+ * - final_amount_b: Final amount of token B (obtained B when fix_amount_a=true, remaining B when fix_amount_a=false)
1285
+ */
1286
+ declare function calcExactSwapAmount(coin_amount: string, fix_amount_a: boolean, current_price: string, target_ratio: string): {
1287
+ swap_amount: string;
1288
+ final_amount_a: string;
1289
+ final_amount_b: string;
1290
+ best?: undefined;
1291
+ } | {
1292
+ swap_amount: string;
1293
+ final_amount_a: string;
1294
+ final_amount_b: string;
1295
+ best: string;
1296
+ };
1221
1297
 
1222
1298
  declare const checkIsMinOrMaxIndex: (tick: number, type: "min" | "max", tickSpacing: number) => boolean;
1223
1299
  declare function convertU64BytesToDecimal(bytes: number[]): string;
@@ -1281,4 +1357,4 @@ interface InitSDKOptions {
1281
1357
  declare function initVaultSDK(options: InitSDKOptions): VolatileVaultsSDK;
1282
1358
  declare const defaultProvider: string[];
1283
1359
 
1284
- export { ActionAcl, Balances, BigNumber, ClmmPoolBalance, ClmmVault, CollectFeeOptions, CollectFeeOptionsV2, CollectRewardOptions, CollectRewardOptionsV2, DLMMMarket, DLMMMarketPosition, DepositCalculationOptions, DepositCalculationResult, DepositCalculationResultV2, DepositCalculationValueOptions, DepositCalculationValueOptionsV2, DepositMode, DepositOptions, FeedInfo, GlobalVestingPeriod, LiquidityRange, LpCallback, PackageConfigs, PeriodInfo, Pool, PoolCoinTypes, Price, PythConfigs, PythNodeError, PythPriceModule, RedeemOption, SdkEnv, SdkOptions, VaultPool, VaultVestNFT, VaultsBalance, VaultsBalanceV2, VaultsConfigs, VaultsModule, VaultsModuleV2, VaultsPosition, VaultsV2Configs, VaultsVestInfo, VestConfigs, VestCreateEvent, VestModule, VolatileVaultsSDK, WithdrawCalculationOptions, WithdrawCalculationResult, WithdrawCalculationResultV2, WithdrawMode, WithdrawOptions, WrapperPosition, buildDLMMMarket, buildDLMMMarketId, buildDLMMMarketPosition, buildDLMMPositionId, buildPoolData, buildPoolV2Data, buildVaultsBalance, buildVaultsBalanceV2, calculateAum, calculateAumV2, calculateDepositRatioFixTokenA, calculateTotalAumBasedOnQuote, checkIsMinOrMaxIndex, convertU64BytesToDecimal, VolatileVaultsSDK as default, defaultProvider, estCoinAmountsFromTotalAmount, feed_map_mainnet, feed_map_testnet, getAmountBalanceByLpAmount, getCoinAmountsFromRatio, getPositionPriceRange, getPriceWithFormattedDecimals, getPrimitivePricesFromBaseQuote, getQuotePerBaseAndBasePerQuote, getShareBufferAssets, getUpdatePriceType, getVaultValidBalances, get_lp_amount_by_liquidity, get_lp_amount_by_tvl, get_share_liquidity_by_amount, initMainnetSDK, initTestnetSDK, initVaultSDK, oraclePriceMultiplierDecimal, parseVaultVestNFT, parseVaultsVestInfo, printTransaction, toSuiObjectId, vaults_mainnet, vaults_testnet };
1360
+ export { ActionAcl, Balances, BigNumber, ClmmPoolBalance, ClmmVault, CollectFeeOptions, CollectFeeOptionsV2, CollectRewardOptions, CollectRewardOptionsV2, DLMMMarket, DLMMMarketPosition, DepositCalculationOptions, DepositCalculationOptionsV2, DepositCalculationResult, DepositCalculationResultV2, DepositCalculationValueOptions, DepositCalculationValueOptionsV2, DepositMode, DepositOptions, DepositOptionsV2, FeedInfo, GlobalVestingPeriod, LiquidityRange, LpCallback, PackageConfigs, PeriodInfo, Pool, PoolCoinTypes, Price, PythConfigs, PythNodeError, PythPriceModule, RedeemOption, SdkEnv, SdkOptions, SwapResult, VaultPool, VaultVestNFT, VaultsBalance, VaultsBalanceV2, VaultsConfigs, VaultsModule, VaultsModuleV2, VaultsPosition, VaultsV2Configs, VaultsVestInfo, VestConfigs, VestCreateEvent, VestModule, VolatileVaultsSDK, WithdrawCalculationOptions, WithdrawCalculationResult, WithdrawCalculationResultV2, WithdrawMode, WithdrawOptions, WrapperPosition, buildDLMMMarket, buildDLMMMarketId, buildDLMMMarketPosition, buildDLMMPositionId, buildPoolData, buildPoolV2Data, buildVaultsBalance, buildVaultsBalanceV2, calcExactSwapAmount, calculateAum, calculateAumV2, calculateDepositRatioFixTokenA, calculateTotalAumBasedOnQuote, checkIsMinOrMaxIndex, convertU64BytesToDecimal, VolatileVaultsSDK as default, defaultProvider, estCoinAmountsFromTotalAmount, feed_map_mainnet, feed_map_testnet, getAmountBalanceByLpAmount, getCoinAmountsFromRatio, getPositionPriceRange, getPriceWithFormattedDecimals, getPrimitivePricesFromBaseQuote, getQuotePerBaseAndBasePerQuote, getShareBufferAssets, getUpdatePriceType, getVaultValidBalances, get_lp_amount_by_liquidity, get_lp_amount_by_tvl, get_share_liquidity_by_amount, initMainnetSDK, initTestnetSDK, initVaultSDK, oraclePriceMultiplierDecimal, parseVaultVestNFT, parseVaultsVestInfo, printTransaction, toSuiObjectId, vaults_mainnet, vaults_testnet };