From 58b379abeeaa562ce8c19e8d3ff257dd9c6a8202 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 28 Nov 2023 13:04:01 +0800 Subject: [PATCH] DIP-0 (#5) --- DIPs/dip-0.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 DIPs/dip-0.md diff --git a/DIPs/dip-0.md b/DIPs/dip-0.md new file mode 100644 index 0000000..6614b81 --- /dev/null +++ b/DIPs/dip-0.md @@ -0,0 +1,63 @@ +--- +dip: 0 +title: Staking Power Specification +description: This specification details the functioning of staking power. +authors: Darwinia Network (@AurevoirXavier, @hackfisher) +discussions-to: None +status: Final +type: Economic +created: 2023-11-28 +--- + + +## Abstract +This DIP explicates the staking power specification applicable to Darwinia and Crab. + + +## Rationale +Darwinia's initial design recognizes the existence of two tokens. +To incorporate these two tokens in staking, a unified measuring unit is indispensable. + + +## Specification +Power is a composite unit of RINGs and KTONs. + +There is a constant total of `1` billion power, with `50%` allocated to RINGs and `50%` to KTONs. + +A RING pool exists, where all staked RINGs are held to share the `50%` power. The same applies to the KTON pool. + +```rs +const TOTAL_POWER: u32 = 1_000_000_000; +const HALF_POWER: u32 = TOTAL_POWER / 2; + +// Initially, there are no stakers. +static mut ring_pool = 0; +static mut kton_pool = 0; + +// The power of a staker is the sum of their RINGs' power and their KTONs' power. +fn power_of(staker) { + (staker.ring / ring_pool + staker.kton / kton_pool) * HALF_POWER +} + +// Staker `S1` stakes `25` RINGs. +ring_pool += 25; // , which becomes `25`. +assert_eq!(power_of(S1), HALF_POWER); + +// Staker `S1` stakes `25` KTONs. +kton_pool += 25; // , which becomes `25`; +assert_eq!(power_of(S1), TOTAL_POWER); + +// Staker `S2` stakes `75` RINGs. +ring_pool += 75; // , which becomes `100`. +assert_eq!(power_of(S1), 25 / 100 * HALF_POWER + HALF_POWER); +assert_eq!(power_of(S2), 75 / 100 * HALF_POWER); + +// Staker `S2` stakes `25` KTONs. +kton_pool += 25; // , which becomes `50`. +assert_eq!(power_of(S1), 25 / 100 * HALF_POWER + 25 / 50 * HALF_POWER); +assert_eq!(power_of(S2), 75 / 100 * HALF_POWER + 25 / 50 * HALF_POWER); +``` + + +## Copyright +Copyright and related rights waived via [CC0](../LICENSE).