Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wax
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
wax
Commits
85325421
Commit
85325421
authored
10 months ago
by
Fabian Waszkiewicz
Browse files
Options
Downloads
Patches
Plain Diff
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
!163
Release Candidate changes done in develop branch targeted to master
,
!158
Extend TypeScript interface for support for vests_to_hp calculation and hp_apr estimation
Pipeline
#97034
passed
10 months ago
Stage: static_code_analysis
Stage: build
Stage: test
Stage: deploy
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wasm/__tests__/detailed/hive_base.ts
+64
-0
64 additions, 0 deletions
wasm/__tests__/detailed/hive_base.ts
wasm/lib/detailed/base_api.ts
+38
-0
38 additions, 0 deletions
wasm/lib/detailed/base_api.ts
wasm/lib/interfaces.ts
+31
-0
31 additions, 0 deletions
wasm/lib/interfaces.ts
with
133 additions
and
0 deletions
wasm/__tests__/detailed/hive_base.ts
+
64
−
0
View file @
85325421
...
...
@@ -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
})
=>
{
...
...
This diff is collapsed.
Click to expand it.
wasm/lib/detailed/base_api.ts
+
38
−
0
View file @
85325421
...
...
@@ -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
();
}
}
This diff is collapsed.
Click to expand it.
wasm/lib/interfaces.ts
+
31
−
0
View file @
85325421
...
...
@@ -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
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment