# Asset Conversions

Asset conversions are required for various Hive financial transactions. The @hiveio/wax library provides methods like VESTS to HP and HBD to Hive to facilitate these conversions.

# VESTS to HP conversion

This method converts VESTS into Hive Power (HP). This conversion requires three NaiAsset instances or values convertible to NaiAsset (number, string or bigint for JavaScript): one for the VESTS and two others for the total vesting fund Hive and total vesting shares.

This method takes 3 parameters:

import { createWaxFoundation } from '@hiveio/wax';

// Create a Wax Foundation instance
const waxApi = await createWaxFoundation();

// Assume these amounts represent the vests, totalVestingFundHive, and totalVestingShares
const vestsAmount = 1_000000;
const totalVestingFundHiveAmount = 20_000;
const totalVestingSharesAmount = 5_000000;

// Convert amounts to `NaiAsset`
const vestsAsset = waxApi.vestsSatoshis(vestsAmount);
const totalVestingFundHiveAsset = waxApi.hiveSatoshis(totalVestingFundHiveAmount);
const totalVestingSharesAsset = waxApi.vestsSatoshis(totalVestingSharesAmount);

// Use `vestsToHp` to perform the conversion
const hpAsset = waxApi.vestsToHp(
  vestsAsset,
  totalVestingFundHiveAsset,
  totalVestingSharesAsset
);

console.log(`HP Asset: ${JSON.stringify(hpAsset)}`);

You can also perform the reverse conversion from HP to VESTS using the hpToVests method.

from wax import create_wax_foundation


# Create a Wax Foundation instance
wax = create_wax_foundation()


# Assume these amounts represent the vests, total_vesting_fund_hive_amount, and total_vesting_shares_amount
vests_asset = 1_000000
total_vesting_fund_hive_amount = 20_000
total_vesting_shares_amount = 5_000000

# Convert amounts to `NaiAsset`
vests_asset = wax.vests.satoshis(vests_asset)
total_vesting_fund_hive_amount = wax.hive.satoshis(total_vesting_fund_hive_amount)
total_vesting_shares_amount = wax.vests.satoshis(total_vesting_shares_amount)

# Use `vests_to_hp` to perform the conversion
hp_asset = wax.vests_to_hp(vests_asset, total_vesting_fund_hive_amount, total_vesting_shares_amount)
print(f"HP Asset: \n\n{hp_asset}")

# HBD to HIVE conversion

This method converts HBD into Hive. This conversion requires three NaiAsset instances or values convertible to NaiAsset (number, string or bigint for JavaScript): one for the HBD, one for the base (another HBD asset), and one for the quote (a HIVE asset).

This method takes 3 parameters:

import { createWaxFoundation } from '@hiveio/wax';

// Create a Wax Foundation instance
const waxApi = await createWaxFoundation();

// Assume these amounts represent the HBD, base, and quote
const hbdAmount = 1_000;
const baseAmount = 1_500;
const quoteAmount = 2_000;

// Convert amounts to `NaiAsset`
const hbdAsset = waxApi.hbdSatoshis(hbdAmount);
const baseAsset = waxApi.hbdSatoshis(baseAmount);
const quoteAsset = waxApi.hiveSatoshis(quoteAmount);

// Use `hbdToHive` to perform the conversion
const hiveAsset = waxApi.hbdToHive(hbdAsset, baseAsset, quoteAsset);
console.log(`Converted Hive Asset: ${JSON.stringify(hiveAsset)}`);

You can also perform the reverse conversion from HIVE to HBD using the hiveToHbd method.

from wax import create_wax_foundation


# Create a Wax Foundation instance
wax = create_wax_foundation()

# Assume these amounts represent the HBD, base, and quote
hbd_amount = 1_000
base_amount = 1_500
quote_amount = 2_000

# Convert amounts to `NaiAsset`
hbd_asset = wax.hbd.satoshis(hbd_amount)
base_asset = wax.hbd.satoshis(base_amount)
quote_asset = wax.hive.satoshis(quote_amount)

# Use `hbd_to_hive` to perform the conversion
hive_asset = wax.hbd_to_hive(hbd_asset, base_asset, quote_asset)
print(f"Converted Hive Asset: {hive_asset}")