From 7d17dffe06d0f12db6c1db5749a9dfeb45291060 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Thu, 20 Mar 2025 14:48:42 +0100
Subject: [PATCH] Add hpToVests method to TS interface

---
 ts/wasm/lib/detailed/base_api.ts   | 8 ++++++++
 ts/wasm/lib/detailed/interfaces.ts | 8 ++++++++
 ts/wasm/src/wasm_interface.cpp     | 6 ++++++
 3 files changed, 22 insertions(+)

diff --git a/ts/wasm/lib/detailed/base_api.ts b/ts/wasm/lib/detailed/base_api.ts
index a51f6f300..0e3b5be8a 100644
--- a/ts/wasm/lib/detailed/base_api.ts
+++ b/ts/wasm/lib/detailed/base_api.ts
@@ -252,6 +252,14 @@ export class WaxBaseApi implements IWaxBaseInterface {
     return safeWasmCall(() => this.proto.cpp_vests_to_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset);
   }
 
+  public hpToVests(hive: TNaiAssetSource, totalVestingFundHive: TNaiAssetSource, totalVestingShares: TNaiAssetSource): NaiAsset {
+    const hiveAsset = this.createAssetWithRequiredSymbol(EAssetName.HIVE, hive);
+    const totalVestingFundHiveAsset = this.createAssetWithRequiredSymbol(EAssetName.HIVE, totalVestingFundHive);
+    const totalVestingSharesAsset = this.createAssetWithRequiredSymbol(EAssetName.VESTS, totalVestingShares);
+
+    return safeWasmCall(() => this.proto.cpp_hp_to_vests(hiveAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset);
+  }
+
   public hbdToHive(hbd: TNaiAssetSource, base: TNaiAssetSource, quote: TNaiAssetSource): NaiAsset {
     const hbdAsset = this.createAssetWithRequiredSymbol(EAssetName.HBD, hbd as NaiAsset);
     const baseAsset = this.createAssetWithRequiredSymbol(EAssetName.HBD, base as NaiAsset);
diff --git a/ts/wasm/lib/detailed/interfaces.ts b/ts/wasm/lib/detailed/interfaces.ts
index c9681aeb0..4953c9f8b 100644
--- a/ts/wasm/lib/detailed/interfaces.ts
+++ b/ts/wasm/lib/detailed/interfaces.ts
@@ -770,6 +770,14 @@ export interface IWaxBaseInterface {
    */
   vestsToHp(vests: TNaiAssetSource, totalVestingFundHive: TNaiAssetSource, totalVestingShares: TNaiAssetSource): NaiAsset
 
+  /**
+   * Converts HP to VESTS in nai form
+   * @param {NaiAsset} hive HIVE asset
+   * @param {NaiAsset} totalVestingFundHive HIVE assest total vesting fund
+   * @param {NaiAsset} totalVestingShares VESTS asset total shares
+   */
+  hpToVests(hive: TNaiAssetSource, totalVestingFundHive: TNaiAssetSource, totalVestingShares: TNaiAssetSource): NaiAsset;
+
   /**
    * Converts HBD to HIVE in nai form
    * @param {NaiAsset} hbd HBD asset
diff --git a/ts/wasm/src/wasm_interface.cpp b/ts/wasm/src/wasm_interface.cpp
index f2d4ea632..44aa1a026 100644
--- a/ts/wasm/src/wasm_interface.cpp
+++ b/ts/wasm/src/wasm_interface.cpp
@@ -145,6 +145,11 @@ json_asset cpp_vests_to_hp(const json_asset& vests, const json_asset& total_vest
   return foundation::cpp_vests_to_hp(vests, total_vesting_fund_hive, total_vesting_shares);
 }
 
+json_asset cpp_hp_to_vests(const json_asset& vests, const json_asset& total_vesting_fund_hive, const json_asset& total_vesting_shares) const
+{
+  return foundation::cpp_hp_to_vests(vests, total_vesting_fund_hive, total_vesting_shares);
+}
+
 result cpp_calculate_inflation_rate_for_block(const uint32_t block_num) const 
 {
     return foundation::cpp_calculate_inflation_rate_for_block( block_num );
@@ -347,6 +352,7 @@ EMSCRIPTEN_BINDINGS(wax_api_instance) {
     .function("cpp_calculate_hp_apr", &foundation_wasm::cpp_calculate_hp_apr)
     .function("cpp_calculate_inflation_rate_for_block", &foundation_wasm::cpp_calculate_inflation_rate_for_block)
     .function("cpp_vests_to_hp", &foundation_wasm::cpp_vests_to_hp)
+    .function("cpp_hp_to_vests", &foundation_wasm::cpp_hp_to_vests)
     .function("cpp_hbd_to_hive", &foundation_wasm::cpp_hbd_to_hive)
     .function("cpp_hive_to_hbd", &foundation_wasm::cpp_hive_to_hbd)
     .function("cpp_estimate_hive_collateral", &foundation_wasm::cpp_estimate_hive_collateral)
-- 
GitLab