# 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.

TBA

# 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.

TBA