Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
clive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
clive
Merge requests
!297
Implement `Power up` part of hive power management
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement `Power up` part of hive power management
jziebinski/prepare-hp-management
into
develop
Overview
96
Commits
16
Pipelines
95
Changes
25
Merged
Jakub Ziebinski
requested to merge
jziebinski/prepare-hp-management
into
develop
1 year ago
Overview
5
Commits
16
Pipelines
95
Changes
5
Expand
Requires:
!298 (merged)
(to change the inputs to the new)
Edited
1 year ago
by
Jakub Ziebinski
0
0
Merge request reports
Compare
version 4
version 93
f6dfaa9f
1 year ago
version 92
0ed10136
1 year ago
version 91
f02a7c51
1 year ago
version 90
067199f5
1 year ago
version 89
90fe1bc7
1 year ago
version 88
e7cf2559
1 year ago
version 87
af4b08c7
1 year ago
version 86
0c276a5e
1 year ago
version 85
625d0498
1 year ago
version 84
996264d4
1 year ago
version 83
014f626f
1 year ago
version 82
4ac4c293
1 year ago
version 81
1818f131
1 year ago
version 80
c33ac704
1 year ago
version 79
1c4b2f58
1 year ago
version 78
afa1f00b
1 year ago
version 77
a91ad9a3
1 year ago
version 76
45b1b699
1 year ago
version 75
c1cfe88a
1 year ago
version 74
d474977d
1 year ago
version 73
7dbbd5a3
1 year ago
version 72
f4ac6d8d
1 year ago
version 71
1d259714
1 year ago
version 70
e5bfead8
1 year ago
version 69
81485646
1 year ago
version 68
a3ef291d
1 year ago
version 67
159028e6
1 year ago
version 66
5b3fc3a5
1 year ago
version 65
060839a8
1 year ago
version 64
3f2b35bd
1 year ago
version 63
2f6d3682
1 year ago
version 62
57401ab8
1 year ago
version 61
fca31be7
1 year ago
version 60
cb64acb9
1 year ago
version 59
090efff2
1 year ago
version 58
f7eff5d4
1 year ago
version 57
d6a6ed94
1 year ago
version 56
523dd4d0
1 year ago
version 55
9be66186
1 year ago
version 54
8c74c566
1 year ago
version 53
032578c9
1 year ago
version 52
3838c1fe
1 year ago
version 51
d8848a75
1 year ago
version 50
1fadb11e
1 year ago
version 49
27e01103
1 year ago
version 48
1acfb597
1 year ago
version 47
36be29ce
1 year ago
version 46
341ebb37
1 year ago
version 45
c9169a58
1 year ago
version 44
29e708df
1 year ago
version 43
42453757
1 year ago
version 42
eda4a327
1 year ago
version 41
7d6893c2
1 year ago
version 40
049be0e3
1 year ago
version 39
700fcf98
1 year ago
version 38
6050bdf2
1 year ago
version 37
0521cd4c
1 year ago
version 36
ba0f2e7d
1 year ago
version 35
ee144c46
1 year ago
version 34
55a75add
1 year ago
version 33
cde6b7aa
1 year ago
version 32
d5def526
1 year ago
version 31
27fd0999
1 year ago
version 30
357d87c7
1 year ago
version 29
f27f32d1
1 year ago
version 28
7cc227af
1 year ago
version 27
a8d8c220
1 year ago
version 26
af05b7d0
1 year ago
version 25
7a0af039
1 year ago
version 24
8fe60b0e
1 year ago
version 23
47cfca3a
1 year ago
version 22
771db1d4
1 year ago
version 21
5c90ed38
1 year ago
version 20
0ff92576
1 year ago
version 19
042c1360
1 year ago
version 18
699251b7
1 year ago
version 17
51eb2343
1 year ago
version 16
260eae10
1 year ago
version 15
397cd7b9
1 year ago
version 14
e193789e
1 year ago
version 13
7b1fd88f
1 year ago
version 12
5125159d
1 year ago
version 11
52f638c8
1 year ago
version 10
069376f4
1 year ago
version 9
970938f9
1 year ago
version 8
89d2e4df
1 year ago
version 7
bf232ed9
1 year ago
version 6
921cd955
1 year ago
version 5
5c7d24b7
1 year ago
version 4
a5902536
1 year ago
version 3
ff9aa535
1 year ago
version 2
6f9c1d17
1 year ago
version 1
6dc07686
1 year ago
develop (base)
and
version 7
latest version
2d5cb961
16 commits,
1 year ago
version 93
f6dfaa9f
16 commits,
1 year ago
version 92
0ed10136
16 commits,
1 year ago
version 91
f02a7c51
16 commits,
1 year ago
version 90
067199f5
16 commits,
1 year ago
version 89
90fe1bc7
16 commits,
1 year ago
version 88
e7cf2559
16 commits,
1 year ago
version 87
af4b08c7
16 commits,
1 year ago
version 86
0c276a5e
16 commits,
1 year ago
version 85
625d0498
16 commits,
1 year ago
version 84
996264d4
16 commits,
1 year ago
version 83
014f626f
16 commits,
1 year ago
version 82
4ac4c293
16 commits,
1 year ago
version 81
1818f131
16 commits,
1 year ago
version 80
c33ac704
16 commits,
1 year ago
version 79
1c4b2f58
16 commits,
1 year ago
version 78
afa1f00b
16 commits,
1 year ago
version 77
a91ad9a3
16 commits,
1 year ago
version 76
45b1b699
16 commits,
1 year ago
version 75
c1cfe88a
16 commits,
1 year ago
version 74
d474977d
16 commits,
1 year ago
version 73
7dbbd5a3
16 commits,
1 year ago
version 72
f4ac6d8d
16 commits,
1 year ago
version 71
1d259714
16 commits,
1 year ago
version 70
e5bfead8
16 commits,
1 year ago
version 69
81485646
16 commits,
1 year ago
version 68
a3ef291d
16 commits,
1 year ago
version 67
159028e6
16 commits,
1 year ago
version 66
5b3fc3a5
16 commits,
1 year ago
version 65
060839a8
16 commits,
1 year ago
version 64
3f2b35bd
15 commits,
1 year ago
version 63
2f6d3682
15 commits,
1 year ago
version 62
57401ab8
15 commits,
1 year ago
version 61
fca31be7
15 commits,
1 year ago
version 60
cb64acb9
15 commits,
1 year ago
version 59
090efff2
15 commits,
1 year ago
version 58
f7eff5d4
15 commits,
1 year ago
version 57
d6a6ed94
15 commits,
1 year ago
version 56
523dd4d0
14 commits,
1 year ago
version 55
9be66186
14 commits,
1 year ago
version 54
8c74c566
14 commits,
1 year ago
version 53
032578c9
14 commits,
1 year ago
version 52
3838c1fe
14 commits,
1 year ago
version 51
d8848a75
14 commits,
1 year ago
version 50
1fadb11e
13 commits,
1 year ago
version 49
27e01103
13 commits,
1 year ago
version 48
1acfb597
13 commits,
1 year ago
version 47
36be29ce
12 commits,
1 year ago
version 46
341ebb37
11 commits,
1 year ago
version 45
c9169a58
10 commits,
1 year ago
version 44
29e708df
10 commits,
1 year ago
version 43
42453757
10 commits,
1 year ago
version 42
eda4a327
10 commits,
1 year ago
version 41
7d6893c2
10 commits,
1 year ago
version 40
049be0e3
10 commits,
1 year ago
version 39
700fcf98
10 commits,
1 year ago
version 38
6050bdf2
10 commits,
1 year ago
version 37
0521cd4c
10 commits,
1 year ago
version 36
ba0f2e7d
11 commits,
1 year ago
version 35
ee144c46
11 commits,
1 year ago
version 34
55a75add
11 commits,
1 year ago
version 33
cde6b7aa
11 commits,
1 year ago
version 32
d5def526
11 commits,
1 year ago
version 31
27fd0999
11 commits,
1 year ago
version 30
357d87c7
10 commits,
1 year ago
version 29
f27f32d1
10 commits,
1 year ago
version 28
7cc227af
10 commits,
1 year ago
version 27
a8d8c220
10 commits,
1 year ago
version 26
af05b7d0
10 commits,
1 year ago
version 25
7a0af039
11 commits,
1 year ago
version 24
8fe60b0e
11 commits,
1 year ago
version 23
47cfca3a
12 commits,
1 year ago
version 22
771db1d4
12 commits,
1 year ago
version 21
5c90ed38
11 commits,
1 year ago
version 20
0ff92576
11 commits,
1 year ago
version 19
042c1360
11 commits,
1 year ago
version 18
699251b7
10 commits,
1 year ago
version 17
51eb2343
10 commits,
1 year ago
version 16
260eae10
10 commits,
1 year ago
version 15
397cd7b9
9 commits,
1 year ago
version 14
e193789e
9 commits,
1 year ago
version 13
7b1fd88f
9 commits,
1 year ago
version 12
5125159d
9 commits,
1 year ago
version 11
52f638c8
9 commits,
1 year ago
version 10
069376f4
9 commits,
1 year ago
version 9
970938f9
9 commits,
1 year ago
version 8
89d2e4df
9 commits,
1 year ago
version 7
bf232ed9
9 commits,
1 year ago
version 6
921cd955
9 commits,
1 year ago
version 5
5c7d24b7
9 commits,
1 year ago
version 4
a5902536
9 commits,
1 year ago
version 3
ff9aa535
9 commits,
1 year ago
version 2
6f9c1d17
9 commits,
1 year ago
version 1
6dc07686
9 commits,
1 year ago
Show latest version
5 files
+
127
−
55
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
clive/__private/core/commands/data_retrieval/hive_power_data.py
0 → 100644
+
157
−
0
Options
from
__future__
import
annotations
from
dataclasses
import
dataclass
from
typing
import
TYPE_CHECKING
,
Final
from
clive.__private.core.commands.abc.command_data_retrieval
import
CommandDataRetrieval
from
clive.__private.core.vests_to_hive
import
vests_to_hive
from
clive.models
import
Asset
if
TYPE_CHECKING
:
from
datetime
import
datetime
from
clive.__private.core.node
import
Node
from
clive.models.aliased
import
DynamicGlobalProperties
,
SchemasAccount
from
schemas.apis.database_api
import
FindAccounts
,
FindVestingDelegations
,
ListWithdrawVestingRoutes
from
schemas.apis.database_api.fundaments_of_reponses
import
VestingDelegationsFundament
as
VestingDelegation
from
schemas.apis.database_api.fundaments_of_reponses
import
WithdrawVestingRoutesFundament
as
WithdrawRoute
_MAX_WITHDRAW_VESTING_ROUTES_LIMIT
:
Final
[
int
]
=
10
@dataclass
class
HarvestedDataRaw
:
gdpo
:
DynamicGlobalProperties
|
None
=
None
core_account
:
FindAccounts
|
None
=
None
withdraw_routes
:
ListWithdrawVestingRoutes
|
None
=
None
delegations
:
FindVestingDelegations
|
None
=
None
@dataclass
class
SanitizedData
:
gdpo
:
DynamicGlobalProperties
core_account
:
SchemasAccount
withdraw_routes
:
list
[
WithdrawRoute
]
delegations
:
list
[
VestingDelegation
[
Asset
.
Vests
]]
@dataclass
class
SharesBalance
:
"""
Class to store the balance of shares in HP and VESTS.
"""
hp_balance
:
Asset
.
Hive
vests_balance
:
Asset
.
Vests
@dataclass
class
HivePowerData
:
owned_balance
:
SharesBalance
total_balance
:
SharesBalance
received_balance
:
SharesBalance
delegated_balance
:
SharesBalance
next_vesting_withdrawal
:
datetime
withdraw_routes
:
list
[
WithdrawRoute
]
delegations
:
list
[
VestingDelegation
[
Asset
.
Vests
]]
to_withdraw
:
SharesBalance
next_power_down
:
SharesBalance
current_hp_apr
:
str
gdpo
:
DynamicGlobalProperties
@dataclass
(
kw_only
=
True
)
class
HivePowerDataRetrieval
(
CommandDataRetrieval
[
HarvestedDataRaw
,
SanitizedData
,
HivePowerData
]):
node
:
Node
account_name
:
str
async
def
_harvest_data_from_api
(
self
)
->
HarvestedDataRaw
:
async
with
self
.
node
.
batch
()
as
node
:
return
HarvestedDataRaw
(
await
node
.
api
.
database_api
.
get_dynamic_global_properties
(),
await
node
.
api
.
database_api
.
find_accounts
(
accounts
=
[
self
.
account_name
]),
await
node
.
api
.
database_api
.
list_withdraw_vesting_routes
(
start
=
(
self
.
account_name
,
""
),
limit
=
_MAX_WITHDRAW_VESTING_ROUTES_LIMIT
,
order
=
"
by_withdraw_route
"
),
await
node
.
api
.
database_api
.
find_vesting_delegations
(
account
=
self
.
account_name
),
)
async
def
_sanitize_data
(
self
,
data
:
HarvestedDataRaw
)
->
SanitizedData
:
return
SanitizedData
(
gdpo
=
self
.
_assert_gdpo
(
data
.
gdpo
),
core_account
=
self
.
_assert_core_account
(
data
.
core_account
),
withdraw_routes
=
self
.
_assert_withdraw_routes
(
data
.
withdraw_routes
),
delegations
=
self
.
_assert_delegations
(
data
.
delegations
),
)
async
def
_process_data
(
self
,
data
:
SanitizedData
)
->
HivePowerData
:
owned_shares
=
data
.
core_account
.
vesting_shares
received_shares
=
data
.
core_account
.
received_vesting_shares
delegated_shares
=
data
.
core_account
.
delegated_vesting_shares
total_shares
=
owned_shares
+
received_shares
-
delegated_shares
-
data
.
core_account
.
vesting_withdraw_rate
return
HivePowerData
(
owned_balance
=
self
.
_create_balance_representation
(
data
.
gdpo
,
owned_shares
),
total_balance
=
self
.
_create_balance_representation
(
data
.
gdpo
,
total_shares
),
received_balance
=
self
.
_create_balance_representation
(
data
.
gdpo
,
received_shares
),
delegated_balance
=
self
.
_create_balance_representation
(
data
.
gdpo
,
delegated_shares
),
next_vesting_withdrawal
=
data
.
core_account
.
next_vesting_withdrawal
,
withdraw_routes
=
[
route
for
route
in
data
.
withdraw_routes
if
route
.
from_account
==
self
.
account_name
],
delegations
=
data
.
delegations
,
to_withdraw
=
self
.
_create_balance_representation
(
data
.
gdpo
,
Asset
.
vests
(
data
.
core_account
.
to_withdraw
/
10
**
data
.
gdpo
.
total_vesting_shares
.
precision
)
),
next_power_down
=
self
.
_create_balance_representation
(
data
.
gdpo
,
data
.
core_account
.
vesting_withdraw_rate
),
current_hp_apr
=
self
.
_calculate_current_hp_apr
(
data
.
gdpo
),
gdpo
=
data
.
gdpo
,
)
def
_assert_gdpo
(
self
,
data
:
DynamicGlobalProperties
|
None
)
->
DynamicGlobalProperties
:
assert
data
is
not
None
,
"
DynamicGlobalProperties data is missing
"
return
data
def
_assert_core_account
(
self
,
data
:
FindAccounts
|
None
)
->
SchemasAccount
:
assert
data
is
not
None
,
"
FindAccounts data is missing
"
assert
len
(
data
.
accounts
)
==
1
,
"
Invalid amount of accounts
"
account
=
data
.
accounts
[
0
]
assert
account
.
name
==
self
.
account_name
,
"
Invalid account name
"
return
account
def
_assert_withdraw_routes
(
self
,
data
:
ListWithdrawVestingRoutes
|
None
)
->
list
[
WithdrawRoute
]:
assert
data
is
not
None
,
"
ListWithdrawVestingRoutes data is missing
"
return
data
.
routes
def
_assert_delegations
(
self
,
data
:
FindVestingDelegations
|
None
)
->
list
[
VestingDelegation
[
Asset
.
Vests
]]:
assert
data
is
not
None
,
"
FindVestingDelegations data is missing
"
return
data
.
delegations
def
_create_balance_representation
(
self
,
gdpo
:
DynamicGlobalProperties
,
vests_value
:
Asset
.
Vests
)
->
SharesBalance
:
return
SharesBalance
(
hp_balance
=
vests_to_hive
(
vests_value
,
gdpo
),
vests_balance
=
vests_value
)
def
_calculate_current_hp_apr
(
self
,
gdpo
:
DynamicGlobalProperties
)
->
str
:
# The inflation was set to 9.5% at block 7m
initial_inflation_rate
:
Final
[
float
]
=
9.5
initial_block
:
Final
[
int
]
=
7000000
# It decreases by 0.01% every 250k blocks
decrease_rate
:
Final
[
int
]
=
250000
decrease_percent_per_increment
:
Final
[
float
]
=
0.01
# How many increments have happened since block 7m?
head_block
=
gdpo
.
head_block_number
delta_blocks
=
head_block
-
initial_block
decrease_increments
=
delta_blocks
/
decrease_rate
current_inflation_rate
=
initial_inflation_rate
-
decrease_increments
*
decrease_percent_per_increment
# Cannot go lower than 0.95 %
minimum_inflation_rate
:
Final
[
float
]
=
0.95
if
current_inflation_rate
<
minimum_inflation_rate
:
current_inflation_rate
=
0.95
# Calculate the APR
vesting_reward_percent
=
gdpo
.
vesting_reward_percent
/
10000
virtual_supply
=
int
(
gdpo
.
virtual_supply
.
amount
)
/
10
**
gdpo
.
virtual_supply
.
precision
total_vesting_funds
=
int
(
gdpo
.
total_vesting_fund_hive
.
amount
)
/
10
**
gdpo
.
total_vesting_fund_hive
.
precision
return
f
"
{
virtual_supply
*
current_inflation_rate
*
vesting_reward_percent
/
total_vesting_funds
:
.
2
f
}
"
Loading