From ddff78627699d997fbcc86b1409726b0269ffb44 Mon Sep 17 00:00:00 2001 From: jaypan Date: Mon, 30 Dec 2024 13:25:29 +0100 Subject: [PATCH] Add the apr_v2_calculation.py tools --- tools/apr_v2_calculation.py | 46 +++++++++++++++++++++++++ tools/stress/stress_token_economy_v2.py | 1 - 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tools/apr_v2_calculation.py diff --git a/tools/apr_v2_calculation.py b/tools/apr_v2_calculation.py new file mode 100644 index 0000000..036d4f3 --- /dev/null +++ b/tools/apr_v2_calculation.py @@ -0,0 +1,46 @@ +import sys +sys.path.append('./') + + +from substrateinterface import SubstrateInterface + + +URL = 'wss://docker-test.peaq.network' +URL = 'wss://mpfn1.peaq.network' +INFLAITON_PERCENTAGE = 0.035 +COLLATR_DELEGATOR_PERCENTAGE = 0.40 +TOTAL_ISSUANCE_NUMBER = 4.2 * 10 ** 9 * 10 ** 18 + + +if __name__ == '__main__': + substrate = SubstrateInterface(URL) + now_collators = substrate.query( + module='Session', + storage_function='Validators', + ) + now_collators = now_collators.value + candidate_pool = substrate.query_map( + module='ParachainStaking', + storage_function='CandidatePool', + start_key=None, + page_size=1000, + ) + candidate_pool = {k.value: v.value for k, v in candidate_pool.records} + in_candidate_pool = {collator: candidate_pool[collator] for collator in now_collators} + print(in_candidate_pool) + + total_staking_number = sum([value['total'] for value in in_candidate_pool.values()]) + print(total_staking_number) + + for k, v in in_candidate_pool.items(): + print(f'collator: {k}') + print(f' collator total: {v["total"]}') + # commission_rate = v['commission'] / 10000000 + commission_rate = 0.1 + print(f' commission rate: {commission_rate}') + for delegator in v['delegators']: + print(f' delegator: {delegator["owner"]}') + print(f' delegator stake: {delegator["amount"]}') + print(f' delegator apr: {(INFLAITON_PERCENTAGE * COLLATR_DELEGATOR_PERCENTAGE * TOTAL_ISSUANCE_NUMBER * (1 - commission_rate) * delegator["amount"] / total_staking_number / delegator["amount"] * 100)}') + print(f' sum: {total_staking_number}') + print(f' collator apr: {(INFLAITON_PERCENTAGE * COLLATR_DELEGATOR_PERCENTAGE * TOTAL_ISSUANCE_NUMBER * (v["stake"] + commission_rate * sum([delegator["amount"] for delegator in v["delegators"]])) / total_staking_number / v["stake"] * 100)}') diff --git a/tools/stress/stress_token_economy_v2.py b/tools/stress/stress_token_economy_v2.py index cef7e72..a7b464c 100644 --- a/tools/stress/stress_token_economy_v2.py +++ b/tools/stress/stress_token_economy_v2.py @@ -78,7 +78,6 @@ def check_single_session_collators(substrate, session_height, round_length, sess start_key=None, page_size=1000, ) - all_colators_info.records[0][0].value collators_block_set = set([addr.value for addr, _ in all_colators_info.records]) if not collators_block_set.issubset(now_collator_set): raise IOError(f' error: collators in session block: {now_collator_set} v.s. collators in collator block: {collators_block_set}')