Skip to content
Snippets Groups Projects
Commit 85325421 authored by Fabian Waszkiewicz's avatar Fabian Waszkiewicz
Browse files

Extend TypeScript interface for support for vests_to_hp calculation and hp_apr estimation

parent 5571b7b4
No related branches found
No related tags found
2 merge requests!163Release Candidate changes done in develop branch targeted to master,!158Extend TypeScript interface for support for vests_to_hp calculation and hp_apr estimation
Pipeline #97034 passed
......@@ -408,6 +408,70 @@ test.describe('Wax object interface foundation tests', () => {
expect(retVal.encrypted).toBe("#5P5bvgpUUGTskb98shuYBTpSMqfoTBev6Ay2xo9UgMF3Rj5uhFSqwVLb4LZkmCcodBdQUgEspA1t2dByaMVAjyJFZN767GRGxGDtx2r3sQtui9kFEWPGcxXYvWZLxAxDJmgtqc4wUsgNKYe5kZPPQSHg");
expect(retVal.decrypted).toBe("This should be encrypted");
})
test('Should be able to calculate account HP', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateAccountHp(10, 10, 10);
});
expect(retVal).toEqual({
amount: "10",
nai: "@@000000021",
precision: 3
});
});
test('Should be able to calculate account HP with mixed params', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateAccountHp(10, base.hive(10), 10);
});
expect(retVal).toEqual({
amount: "10",
nai: "@@000000021",
precision: 3
});
});
test('Should be able to calculate witness votes HP', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateWitnessVotesHp(10, 10, 10);
});
expect(retVal).toEqual({
amount: "42949672970",
nai: "@@000000021",
precision: 3
});
});
test('Should be able to calculate witness votes HP with mixed params', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateWitnessVotesHp(10, base.hive(10), 10);
});
expect(retVal).toEqual({
amount: "42949672970",
nai: "@@000000021",
precision: 3
});
});
test('Should be able to calculate HP APR', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateHpApr(1_000_000, 1_500, 10, 10);
});
expect(retVal).toEqual(1.46);
});
test('Should be able to calculate HP APR with mixed params', async ({ waxTest }) => {
const retVal = await waxTest(async({ base }) => {
return base.calculateHpApr(1_000_000, 1_500, base.hive(10), 10);
});
expect(retVal).toEqual(1.46);
});
test('Should be able to generate random private key using password', async ({ waxTest }) => {
......
......@@ -244,7 +244,45 @@ export class WaxBaseApi implements IWaxBaseInterface {
};
}
public calculateAccountHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset {
const vestsAsset = isNaiAsset(vests) ? vests as NaiAsset : this.vests(vests as number | string | BigInt | Long);
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hive(totalVestingFundHive as number | string | BigInt | Long);
const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? totalVestingShares as NaiAsset : this.vests(totalVestingShares as number | string | BigInt | Long);
if (vestsAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for vests');
if (totalVestingFundHiveAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for totalVestingFundHive');
if (totalVestingSharesAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for totalVestingShares');
return this.proto.cpp_calculate_account_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset;
}
public calculateWitnessVotesHp(votes: number, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset {
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hive(totalVestingFundHive as number | string | BigInt | Long);
const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? totalVestingShares as NaiAsset : this.vests(totalVestingShares as number | string | BigInt | Long);
if (totalVestingFundHiveAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for totalVestingFundHive');
if (totalVestingSharesAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for totalVestingShares');
return this.proto.cpp_calculate_witness_votes_hp(votes, votes, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset;
}
public calculateHpApr(headBlockNum: number, vestingRewardPercent: number, virtualSupply: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset): number {
const virtualSupplyAsset = isNaiAsset(virtualSupply) ? virtualSupply as NaiAsset : this.hive(virtualSupply as number | string | BigInt | Long);
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hive(totalVestingFundHive as number | string | BigInt | Long);
return Number.parseFloat(this.extract(this.proto.cpp_calculate_hp_apr(headBlockNum, vestingRewardPercent, virtualSupplyAsset, totalVestingFundHiveAsset)));
}
public delete(): void {
this.proto.delete();
}
}
......@@ -622,6 +622,37 @@ export interface IWaxBaseInterface {
*/
calculateManabarFullRegenerationTime(now: number, maxManaLH: number | string | Long, currentManaLH: number | string | Long, lastUpdateTime: number): number;
/**
* Calculates account HP based on given vests, total vesting fund HIVE and total vesting shares
*
* @param {number | string | BigInt | Long | NaiAsset} vests VESTS asset
* @param {number | string | BigInt | Long | NaiAsset} totalVestingFundHive HIVE asset total vesting fund
* @param {number | string | BigInt | Long | NaiAsset} totalVestingShares VESTS asset total shares
* @returns {NaiAsset} HP in nai form
*/
calculateAccountHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset;
/**
* Calculates witness votes HP based on given votes, total vesting fund HIVE and total vesting shares
*
* @param {number} votes witness votes
* @param {number | string | BigInt | Long | NaiAsset} totalVestingFundHive HIVE asset total vesting fund
* @param {number | string | BigInt | Long | NaiAsset} totalVestingShares VESTS asset total shares
* @returns {NaiAsset} HP in nai form
*/
calculateWitnessVotesHp(votes: number, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset;
/**
* Calculate current HP APR
*
* @param {number} headBlockNum head block number
* @param {number} vestingRewardPercent vesting reward percent
* @param {number | string | BigInt | Long | NaiAsset} virtualSupply virtual supply
* @param {number | string | BigInt | Long | NaiAsset} totalVestingFundHive HIVE asset total vesting fund HIVE
* @returns {number} HP APR percent with 2 decimals
*/
calculateHpApr(headBlockNum: number, vestingRewardPercent: number, virtualSupply: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset): number;
/**
* Deletes the created wax proto_protocol instance
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment