From cc802273cc81164a07658eb579548288335d39bd Mon Sep 17 00:00:00 2001 From: Alberto Nicolas Penayo <74352651+bee344@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:51:25 -0300 Subject: [PATCH] docs(calc): Updated README for calc package (#1386) * moved fn docs from README to inline * changed add and sub operations to saturating_* * updated copyright --- calc/README.md | 75 +------------- calc/src/calc_partial_fee.rs | 62 ++++++++++- calc/src/calc_payout.rs | 65 ++++++------ calc/src/debug.rs | 2 +- calc/src/lib.rs | 2 +- calc/src/test.rs | 193 +++++++++++++++++------------------ 6 files changed, 187 insertions(+), 212 deletions(-) diff --git a/calc/README.md b/calc/README.md index c650e43b6..b32f120ce 100644 --- a/calc/README.md +++ b/calc/README.md @@ -36,80 +36,7 @@ and Sidecar's [block service](https://github.com/paritytech/substrate-api-sideca In order to build the rust source code with `wasm-pack`, please run `sh build.sh`. This will require `wasm-pack` being installed globally. The script will install it for you, but before it does it will ask you whether you want it installed or not. -### calc_partial_fee -Tool to calculate an extrinsics' `partial_fee` (i.e. the total fee minus any tip). -It uses the following formula: - -``` -partial_fee = base_fee + len_fee + ((adjusted_weight_fee/estimated_weight)*actual_weight) -``` - -Where: -- `base_fee` is a fixed base fee to include some transaction in a block. It accounts - for the work needed to verify the signature and the computing work common to any tx. - It is constant for any tx. -- `len_fee` is a fee paid based on the size (length in bytes) of the transaction. - Longer transactions require more storage, and therefore are more expensive. -- `adjusted_weight_fee` is a fee that is itself `estimated_weight * targeted_fee_adjustment`: - - `targeted_fee_adjustment` is some adjustment made based on the network load and - other circumstantial factors, and is an opaque internal value we have no access to. - - `estimated_weight` is the "pre-dispatch" weight of the transaction. It's set - based on the cost of processing the transaction on reference hardware. -- `actual_weight` is the weight that is found in the `ExtrinsicSuccess` event for - the extrinsic in a block (it's just called `weight` in the event), and it's - value is often close to `estimated_weight`, but the node has the opportunity - to change it depending on the actual computing work necessary to process the tx. - -The RPC endpoint `payment_queryFeeDetails` returns `base_fee`, `len_fee` and -`adjusted_weight_fee`. The RPC endpoint `payment_queryInfo` returns `estimated_weight` -(called `weight` in the response), and a `partialFee` value, which is our best -guess at the inclusion fee for the tx without actually submitting it and seeing -whether the node changes the weight or decides not to take a fee at all. - -To get the correct values for some extrinsic from both endpoints, provide the -extrinsic bytes, and the number of the block **before the block it is included in** -(e.g. if the extrinsic was in block 100, you'd use block 99 as an argument). This -is very important. - -Once you've called these endpoints, access the `ExtrinsicSuccess` event to find -the `actual_weight`, but also a `paysFee` value which signals whether the extrinsic -actually incurred a fee at all or not (a node has the opportunity to refund the -fee entirely). - -With all of those values at hand, the equation above calculates the correct Fee. -Why? Well, the basic way to calculate a pre-dispatch fee is: - -``` -partial_fee = base_fee + len_fee + adjusted_weight_fee -``` - -We can do this from just the RPC methods. But then once it's in a block, we need -to swap out the weight used to calculate that `adjusted_weight_fee` with the -actual weight that was used from the `ExtrinsicSuccess` event. In the end, the -calculation itself is simple, but gathering the details needed is the main difficulty. -We do this all in Rust simply to limit any precision loss. - -### calc_payout - -This is a tool to calculate the payout of a staking era, either for a validator -or a nominator. This is not a predictive estimation, instead it intakes data -from a concluded [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes) -to arrive to the final amount. For this it takes the following parameters: -- `total_reward_points` are the total [era points](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#era-points) - for a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). -- `era_payout` is the [payout](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#payout-scheme) - for a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). -- `validator_reward_points` are the [era points](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#era-points) - earned by the validator in a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). -- `validator_commission` is the commission that the validator takes of its assigned - payout before distribituing the remainder between itself and it's nominators. -- `nominator_exposure` is the amount staked by the nominator or validator, - depending on who we are inquiring about. -- `total_exposure` the total amount staked. -- `is_validator` is a `bool` that states whether the inquired account is a validator. - - ## Contributing We welcome [contributions for documentation and code](https://github.com/paritytech/substrate-api-sidecar/pulls). -If you have any questions you can reach the maintainers by [filing an issue on github.](https://github.com/paritytech/substrate-api-sidecar/issues) \ No newline at end of file +If you have any questions you can reach the maintainers by [filing an issue on github.](https://github.com/paritytech/substrate-api-sidecar/issues) diff --git a/calc/src/calc_partial_fee.rs b/calc/src/calc_partial_fee.rs index f6dcbc500..117101d35 100644 --- a/calc/src/calc_partial_fee.rs +++ b/calc/src/calc_partial_fee.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. (admin@parity.io) +// Copyright (C) 2022-2024 Parity Technologies (UK) Ltd. (admin@parity.io) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,59 @@ use sp_arithmetic::Perbill; use wasm_bindgen::prelude::*; +/// ### calc_partial_fee +/// +/// Tool to calculate an extrinsics' `partial_fee` (i.e. the total fee minus any tip). +/// It uses the following formula: +/// +/// ``` +/// partial_fee = base_fee + len_fee + ((adjusted_weight_fee/estimated_weight)*actual_weight) +/// ``` +/// +/// Where: +/// - `base_fee` is a fixed base fee to include some transaction in a block. It accounts +/// for the work needed to verify the signature and the computing work common to any tx. +/// It is constant for any tx. +/// - `len_fee` is a fee paid based on the size (length in bytes) of the transaction. +/// Longer transactions require more storage, and therefore are more expensive. +/// - `adjusted_weight_fee` is a fee that is itself `estimated_weight * targeted_fee_adjustment`: +/// - `targeted_fee_adjustment` is some adjustment made based on the network load and +/// other circumstantial factors, and is an opaque internal value we have no access to. +/// - `estimated_weight` is the "pre-dispatch" weight of the transaction. It's set +/// based on the cost of processing the transaction on reference hardware. +/// - `actual_weight` is the weight that is found in the `ExtrinsicSuccess` event for +/// the extrinsic in a block (it's just called `weight` in the event), and it's +/// value is often close to `estimated_weight`, but the node has the opportunity +/// to change it depending on the actual computing work necessary to process the tx. +/// +/// The RPC endpoint `payment_queryFeeDetails` returns `base_fee`, `len_fee` and +/// `adjusted_weight_fee`. The RPC endpoint `payment_queryInfo` returns `estimated_weight` +/// (called `weight` in the response), and a `partialFee` value, which is our best +/// guess at the inclusion fee for the tx without actually submitting it and seeing +/// whether the node changes the weight or decides not to take a fee at all. +/// +/// To get the correct values for some extrinsic from both endpoints, provide the +/// extrinsic bytes, and the number of the block **before the block it is included in** +/// (e.g. if the extrinsic was in block 100, you'd use block 99 as an argument). This +/// is very important. +/// +/// Once you've called these endpoints, access the `ExtrinsicSuccess` event to find +/// the `actual_weight`, but also a `paysFee` value which signals whether the extrinsic +/// actually incurred a fee at all or not (a node has the opportunity to refund the +/// fee entirely). +/// +/// With all of those values at hand, the equation above calculates the correct Fee. +/// Why? Well, the basic way to calculate a pre-dispatch fee is: +/// +/// ``` +/// partial_fee = base_fee + len_fee + adjusted_weight_fee +/// ``` +/// +/// We can do this from just the RPC methods. But then once it's in a block, we need +/// to swap out the weight used to calculate that `adjusted_weight_fee` with the +/// actual weight that was used from the `ExtrinsicSuccess` event. In the end, the +/// calculation itself is simple, but gathering the details needed is the main difficulty. +/// We do this all in Rust simply to limit any precision loss. #[wasm_bindgen] pub fn calc_partial_fee( base_fee: &str, @@ -47,9 +100,10 @@ fn calc_raw( estimated_weight: u128, actual_weight: u128 ) -> u128 { - // calculate new adjusted_weight_fee, trying to maintain precision: - let adjusted_weight_fee = Perbill::from_rational(estimated_weight, actual_weight) * adjusted_weight_fee; - // add the fee components together to get the partial/inclusion fee: + // Calculate new adjusted_weight_fee, trying to maintain precision. + let adjusted_weight_fee = Perbill::from_rational(estimated_weight, actual_weight) * adjusted_weight_fee; + // Add the fee components together to get the partial/inclusion fee and return + // the result. base_fee.saturating_add(len_fee).saturating_add(adjusted_weight_fee) } diff --git a/calc/src/calc_payout.rs b/calc/src/calc_payout.rs index 14da0d70f..b80710350 100644 --- a/calc/src/calc_payout.rs +++ b/calc/src/calc_payout.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. (admin@parity.io) +// Copyright (C) 2022-2024 Parity Technologies (UK) Ltd. (admin@parity.io) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,6 +28,24 @@ pub struct CalcPayout { era_payout: Balance, } +/// ### calc_payout +/// +/// This is a tool to calculate the payout of a staking era, either for a validator +/// or a nominator. This is not a predictive estimation, instead it intakes data +/// from a concluded [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes) +/// to arrive to the final amount. For this it takes the following parameters: +/// - `total_reward_points` are the total [era points](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#era-points) +/// for a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). +/// - `era_payout` is the [payout](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#payout-scheme) +/// for a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). +/// - `validator_reward_points` are the [era points](https://wiki.polkadot.network/docs/maintain-guides-validator-payout#era-points) +/// earned by the validator in a determined [era](https://wiki.polkadot.network/docs/kusama-parameters#periods-of-common-actions-and-attributes). +/// - `validator_commission` is the commission that the validator takes of its assigned +/// payout before distribituing the remainder between itself and it's nominators. +/// - `nominator_exposure` is the amount staked by the nominator or validator, +/// depending on who we are inquiring about. +/// - `total_exposure` the total amount staked. +/// - `is_validator` is a `bool` that states whether the inquired account is a validator. #[wasm_bindgen] impl CalcPayout { pub fn from_params(total_reward_points: u32, era_payout: &str) -> Self { @@ -64,47 +82,34 @@ impl CalcPayout { is_validator, ); - /* - This is the fraction of the total reward that will be split between the - validator and its nominators - */ + // This is the fraction of the total reward that will be split between the + // validator and its nominators let validator_total_reward_part: Perbill = Perbill::from_rational(validator_reward_points, self.total_reward_points); - /* - Using the previous info, here we calculate the portion of the era's reward - that the nominator and its validators are entitled to - */ - let validator_total_payout: u128 = validator_total_reward_part * self.era_payout; - - /* - This is the validator's commission, independent of their share of the - reward for their stake - */ + // Using the previous info, here we calculate the portion of the era's reward + // that the nominator and its validators are entitled to + let validator_total_payout: u128 = validator_total_reward_part * self.era_payout; + // This is the validator's commission, independent of their share of the + // reward for their stake let validator_commission: Perbill = Perbill::from_percent(validator_commission); let validator_commission_payout: u128 = validator_commission * validator_total_payout; - /* - Subtracting the validator's commission, how much is left to split between - the validator and its nominators - */ - let validator_leftover_payout: u128 = validator_total_payout - validator_commission_payout; + // Subtracting the validator's commission, how much is left to split between + // the validator and its nominators + let validator_leftover_payout: u128 = validator_total_payout.saturating_sub(validator_commission_payout); let own_exposure: u128 = Balance::from_str(nominator_exposure).unwrap(); let total_exposure: u128 = Balance::from_str(total_exposure).unwrap(); - /* - This is the portion of the validator/nominator's leftover payout that - the staker is entitled to - */ + // This is the portion of the validator/nominator's leftover payout that + // the staker is entitled to let own_exposure_part: Perbill = Perbill::from_rational(own_exposure, total_exposure); - - /* - This is the payout for the address we are interested in, depending on - whether it's a validator or a nominator - */ + + // This is the payout for the address we are interested in, depending on + // whether it's a validator or a nominator let own_staking_payout: u128 = if is_validator { - own_exposure_part * validator_leftover_payout + validator_commission_payout + (own_exposure_part * validator_leftover_payout).saturating_add(validator_commission_payout) } else { own_exposure_part * validator_leftover_payout }; diff --git a/calc/src/debug.rs b/calc/src/debug.rs index 66f6c772d..6d58d6d1f 100644 --- a/calc/src/debug.rs +++ b/calc/src/debug.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. (admin@parity.io) +// Copyright (C) 2022-2024 Parity Technologies (UK) Ltd. (admin@parity.io) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/calc/src/lib.rs b/calc/src/lib.rs index 049a753c0..3fc9f8081 100644 --- a/calc/src/lib.rs +++ b/calc/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. (admin@parity.io) +// Copyright (C) 2022-2024 Parity Technologies (UK) Ltd. (admin@parity.io) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/calc/src/test.rs b/calc/src/test.rs index 5fe88b75f..81ef11fca 100644 --- a/calc/src/test.rs +++ b/calc/src/test.rs @@ -1,43 +1,40 @@ - #[cfg(test)] mod tests { - use crate::{calc_payout::CalcPayout, calc_partial_fee::calc_partial_fee}; + use crate::{calc_partial_fee::calc_partial_fee, calc_payout::CalcPayout}; use wasm_bindgen::prelude::*; fn unwrap(val: Result) -> T { match val { Ok(v) => v, - Err(_e) => panic!("Cannot unwrap result") + Err(_e) => panic!("Cannot unwrap result"), } } - // Fee calculation example 1: - // - // Extrinsic Hex: - // 0x5502840032663236e3cb206fcd0751b43da451089990581becf91cc7bcc48bf5f5a47aaf005baf8efe06ccb5bdd78a1fee70025f4526e6b06419d6acc4555c10d7c164a85bcf61696bdde25a019b2db6e8014ae8d4a12df7d8464f5f512a87d0da01ec10054934a116001f030066470863fba68183688aeeb4f6ed27cbf1085daee54c16cf9caaa7ff0939b27a1700a89123deaa2a8118 - // - // Network WS URL: wss://rpc.shiden.astar.network - // Block number: 1820490 - // Block hash: 0x7b8d40f067cd67191904d43e40225522e491061c170547cf227d791a49e0db62 - // Actual fee: 1611916814889018 + /// Fee calculation example 1: + /// Extrinsic Hex: + /// 0x5502840032663236e3cb206fcd0751b43da451089990581becf91cc7bcc48bf5f5a47aaf005baf8efe06ccb5bdd78a1fee70025f4526e6b06419d6acc4555c10d7c164a85bcf61696bdde25a019b2db6e8014ae8d4a12df7d8464f5f512a87d0da01ec10054934a116001f030066470863fba68183688aeeb4f6ed27cbf1085daee54c16cf9caaa7ff0939b27a1700a89123deaa2a8118 + /// Network WS URL: wss://rpc.shiden.astar.network + /// Block number: 1820490 + /// Block hash: 0x7b8d40f067cd67191904d43e40225522e491061c170547cf227d791a49e0db62 + /// Actual fee: 1611916814889018 #[test] fn shiden_block_1820490_tx() { - // NOTE: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. + // **NOTE**: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. // It turns out that this is where the values we need should come from. - + // From payment.queryFeeDetails (18 decimal places to 1 SDN): - // baseFee: 100.0000 µSDN - // lenFee: 1.5100 mSDN - // adjustedWeightFee: 1.9168 µSDN + // baseFee: 100.0000 µSDN + // lenFee: 1.5100 mSDN + // adjustedWeightFee: 1.9168 µSDN let base_fee: u128 = 100000000000000; let len_fee: u128 = 1510000000000000; let adjusted_weight_fee: u128 = 1916814889018; - + // From payment.queryInfo: - // weight: 152822000 - // partialFee: 1611916814889018 + // weight: 152822000 + // partialFee: 1611916814889018 let estimated_weight: u128 = 152822000; - + // From ExtrinsicSuccess event: let actual_weight: u128 = 152822000; @@ -53,24 +50,25 @@ mod tests { &len_fee.to_string(), &adjusted_weight_fee.to_string(), &estimated_weight.to_string(), - &actual_weight.to_string() + &actual_weight.to_string(), ); assert_eq!(expected_partial_fee, unwrap(actual_partial_fee)); } - - // Fee calculation example 2: - // - // Extrinsic Hex: - // 0x5502840032663236e3cb206fcd0751b43da451089990581becf91cc7bcc48bf5f5a47aaf00c9e0ce04135a6c150301c53de2f98f9f45cf62025be3e5f28de0769798f855c8bb5cb92aa9cdf4811675122df4e32b21938a3e72be790e1a4fda1c99933c740e192b9d16001f030042d3bfbf83ea4576b85b63b83a58a60ebc5c89e8820ebb92f21926c59be46c1a170040ed0989910d320f - // - // Network WS URL: wss://rpc.shiden.astar.network - // Block number: 1820341 - // Block hash: 0x9f81ab761c40a03ef14e46197a4c00e44c5ee1d225eb1eee37d4ba6a730dc628 - // Actual fee: 1611917528885264 + + /// Fee calculation example 2: + /// + /// Extrinsic Hex: + /// 0x5502840032663236e3cb206fcd0751b43da451089990581becf91cc7bcc48bf5f5a47aaf00c9e0ce04135a6c150301c53de2f98f9f45cf62025be3e5f28de0769798f855c8bb5cb92aa9cdf4811675122df4e32b21938a3e72be790e1a4fda1c99933c740e192b9d16001f030042d3bfbf83ea4576b85b63b83a58a60ebc5c89e8820ebb92f21926c59be46c1a170040ed0989910d320f + /// + /// Network WS URL: wss://rpc.shiden.astar.network + /// Block number: 1820341 + /// Block hash: 0x9f81ab761c40a03ef14e46197a4c00e44c5ee1d225eb1eee37d4ba6a730dc628 + /// Actual fee: 1611917528885264 + #[test] fn shiden_block_1820341_tx() { - // NOTE: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. + // **NOTE**: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. // It turns out that this is where the values we need should come from. // From payment.queryFeeDetails: @@ -79,8 +77,8 @@ mod tests { let adjusted_weight_fee: u128 = 1917528885264; // From payment.queryInfo: - // weight: 152822000 - // partialFee: 1611917528885264 + // weight: 152822000 + // partialFee: 1611917528885264 let estimated_weight: u128 = 152822000; // From ExtrinsicSuccess event: @@ -96,34 +94,35 @@ mod tests { &len_fee.to_string(), &adjusted_weight_fee.to_string(), &estimated_weight.to_string(), - &actual_weight.to_string() + &actual_weight.to_string(), ); assert_eq!(expected_partial_fee, unwrap(actual_partial_fee)); } - // Fee Calculation Example 3: - // - // Extrinsic Hex: - // 0x4d028400a9a38c06cfb948f7176027985ec9632a690a1f9e8a64f244f749c117f45aaec50053c5dc9b60c3b73ee49b08d35b79755556280520b2121ad795a0130ff1899d2ccdcc8bffc5ea606cb0e8c05138d336945b1c2d7be22c033b239d4c1dee802700c92ded56000a0300daa641169afddb7e3480071c91348155e9d5543f6dcfd8583667183103cbde0f0f003cc373933e01 - // - // Network WS URL: wss://acala-rpc-0.aca-api.network - // Block Number: 1285857 - // Block Hash: 0x0a7ce4030de0d3d9629ca67381f96ca2936f57fa7a73440bc4a55fe2603e9dc1 - // Actual Fee: 2490128143 + /// Fee Calculation Example 3: + /// + /// Extrinsic Hex: + /// 0x4d028400a9a38c06cfb948f7176027985ec9632a690a1f9e8a64f244f749c117f45aaec50053c5dc9b60c3b73ee49b08d35b79755556280520b2121ad795a0130ff1899d2ccdcc8bffc5ea606cb0e8c05138d336945b1c2d7be22c033b239d4c1dee802700c92ded56000a0300daa641169afddb7e3480071c91348155e9d5543f6dcfd8583667183103cbde0f0f003cc373933e01 + /// + /// Network WS URL: wss://acala-rpc-0.aca-api.network + /// Block Number: 1285857 + /// Block Hash: 0x0a7ce4030de0d3d9629ca67381f96ca2936f57fa7a73440bc4a55fe2603e9dc1 + /// Actual Fee: 2490128143 #[test] fn acala_block_1285857_tx() { - // NOTE: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. + + // **NOTE**: Whatever block number the tx comes from, we use $blockNumber-1 to get the values. // It turns out that this is where the values we need should come from. - + // // From payment.queryFeeDetails: let adjusted_weight_fee: u128 = 128143; let base_fee: u128 = 1000000000; let len_fee: u128 = 1490000000; // From payment.queryInfo: - // weight: 152822000 - // partialFee: 2490128142 + // weight: 152822000 + // partialFee: 2490128142 let estimated_weight: u128 = 152822000; // From ExtrinsicSuccess event: @@ -135,35 +134,31 @@ mod tests { let expected_partial_fee = "2490128143"; let actual_partial_fee = calc_partial_fee( - &base_fee.to_string(), - &len_fee.to_string(), - &adjusted_weight_fee.to_string(), - &estimated_weight.to_string(), - &actual_weight.to_string() + &base_fee.to_string(), + &len_fee.to_string(), + &adjusted_weight_fee.to_string(), + &estimated_weight.to_string(), + &actual_weight.to_string(), ); assert_eq!(expected_partial_fee, unwrap(actual_partial_fee)); } - /* - These tests are designed to test the accuracy of the preceding functions. - All the data can be retrieved and checked with polkadot-js and subscan.io - with the era and block_number. - */ + + /// These tests are designed to test the accuracy of the preceding functions. + /// All the data can be retrieved and checked with polkadot-js and subscan.io + /// with the era and block_number. #[test] fn kusama_era_5529_validator() { - /* - Parameters: - block_number: 19259255 - era: 5529 - total_reward_points: 6_341_260 - era_payout: 792_713_971_465_885 - validator: CaxeCQ3JWSrZiRNyCTnE4vT8aMrX1sJDJWCXSwrEpxWkiL5 - validator_reward_points: 3_920 - validator_commission: 10 % - nominator_exposure: 5_545_118_499_777 - total_exposure: 9_676_879_871_438_978 - */ - + // Parameters: + // block_number: 19259255 + // era: 5529 + // total_reward_points: 6_341_260 + // era_payout: 792_713_971_465_885 + // validator: CaxeCQ3JWSrZiRNyCTnE4vT8aMrX1sJDJWCXSwrEpxWkiL5 + // validator_reward_points: 3_920 + // validator_commission: 10 % + // nominator_exposure: 5_545_118_499_777 + // total_exposure: 9_676_879_871_438_978 let total_reward_points = 6_341_260u32; let era_payout = String::from("792713971465885"); @@ -184,26 +179,23 @@ mod tests { is_validator, ); - //https://kusama.subscan.io/extrinsic/19259255-4?event=19259255-60 + // https://kusama.subscan.io/extrinsic/19259255-4?event=19259255-60 let total_actual_payout = "49256160022"; assert_eq!(estimated_payout, total_actual_payout) } #[test] fn polkadot_era_1150_validator() { - /* - Parameters: - block_number: 16584606 - era: 1150 - total_reward_points: 22_265_020 - era_payout: 3_213_084_537_093_535 - validator: 14xKzzU1ZYDnzFj7FgdtDAYSMJNARjDc2gNw4XAFDgr4uXgp - validator_reward_points: 56_220 - validator_commission: 3 % - nominator_exposure: 4_423_101_721_494 - total_exposure: 20_509_805_345_780_557 - */ - + // Parameters: + // block_number: 16584606 + // era: 1150 + // total_reward_points: 22_265_020 + // era_payout: 3_213_084_537_093_535 + // validator: 14xKzzU1ZYDnzFj7FgdtDAYSMJNARjDc2gNw4XAFDgr4uXgp + // validator_reward_points: 56_220 + // validator_commission: 3 % + // nominator_exposure: 4_423_101_721_494 + // total_exposure: 20_509_805_345_780_557 let total_reward_points = 22_265_020u32; let era_payout = String::from("3213084537093535"); @@ -224,27 +216,24 @@ mod tests { is_validator, ); - //https://polkadot.subscan.io/extrinsic/16584606-2?event=16584606-230 + // https://polkadot.subscan.io/extrinsic/16584606-2?event=16584606-230 let total_actual_payout: &str = "245091889606"; assert_eq!(estimated_payout, total_actual_payout) } #[test] fn polkadot_era_1150_nominator() { - /* - Parameters: - block_number: 16584521 - era: 1150 - total_reward_points: 22_265_020 - era_payout: 3_213_084_537_093_535 - validator: 12MgK2Sc8Rrh6DXS2gDrt7fWJ24eGeVb23NALbZLMw1grnkL - nominator: 14xA7KotR6pxt3LpgdZz8BDv3fyokWnP67bBnN6tsCWn5wsF - validator_reward_points: 74_280 - validator_commission: 3 % - nominator_exposure: 4_669_514_624_960 - total_exposure: 20_509_805_345_780_557 - */ - + // Parameters: + // block_number: 16584521 + // era: 1150 + // total_reward_points: 22_265_020 + // era_payout: 3_213_084_537_093_535 + // validator: 12MgK2Sc8Rrh6DXS2gDrt7fWJ24eGeVb23NALbZLMw1grnkL + // nominator: 14xA7KotR6pxt3LpgdZz8BDv3fyokWnP67bBnN6tsCWn5wsF + // validator_reward_points: 74_280 + // validator_commission: 3 % + // nominator_exposure: 4_669_514_624_960 + // total_exposure: 20_509_805_345_780_557 let total_reward_points = 22_265_020u32; let era_payout = String::from("3213084537093535"); @@ -265,7 +254,7 @@ mod tests { is_validator, ); - //https://polkadot.subscan.io/extrinsic/16584521-2?event=16584521-1840 + // https://polkadot.subscan.io/extrinsic/16584521-2?event=16584521-1840 let total_actual_payout: &str = "2391688616"; assert_eq!(estimated_payout, total_actual_payout) }