Skip to content

Commit

Permalink
DIP-3 (#12)
Browse files Browse the repository at this point in the history
* DIP-3

* Update

* Update

* Improve
  • Loading branch information
AurevoirXavier authored Jan 4, 2024
1 parent ffa6d2f commit 4e1908c
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 8 deletions.
3 changes: 1 addition & 2 deletions DIPs/dip-0.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
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
Expand Down Expand Up @@ -61,4 +60,4 @@ assert_eq!(power_of(S2), 75 / 100 * HALF_POWER + 25 / 50 * HALF_POWER);


## Copyright
Copyright and related rights waived via [CC0](https://github.com/darwinia-network/DIPs/blob/main/LICENSE).
Copyright and related rights waived via [CC0](../LICENSE).
5 changes: 2 additions & 3 deletions DIPs/dip-1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
dip: 1
title: Staking Commission Specification
description: This specification affects the validators election and reward distribution.
authors: Darwinia Network (@AurevoirXavier, @hujw77, @hackfisher, @xiaoch05)
discussions-to: https://github.com/orgs/darwinia-network/discussions/1238, https://github.com/orgs/darwinia-network/discussions/1272
status: Final
Expand All @@ -12,7 +11,7 @@ created: 2023-11-27

# DIP-1
## Abstract
This DIP outlines the staking commission specification applicable on Darwinia and Crab.
This DIP details the staking commission framework for Darwinia and Crab, impacting validator selection and reward allocation.


## Rationale
Expand Down Expand Up @@ -64,4 +63,4 @@ let abr = remain * aa_of_pa; // , which is `45 * 90 / 135 = 30`.


## Copyright
Copyright and related rights waived via [CC0](https://github.com/darwinia-network/DIPs/blob/main/LICENSE).
Copyright and related rights waived via [CC0](../LICENSE).
4 changes: 1 addition & 3 deletions DIPs/dip-2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
dip: 2
title: Seamless Account Integration Between EVM and Substrate
description: This proposal introduces the adoption of `H160` account addresses in Substrate-based chains to unify address formats with EVM, which aims to simplify user interactions and enhance compatibility with the Ethereum ecosystem.
authors: Darwinia Network (@AurevoirXavier, @boundless-forest, @hackfisher)
status: Final
type: Core
Expand All @@ -14,7 +13,6 @@ created: 2023-12-13
To facilitate Ethereum integration, Substrate-based chains are transitioning to `H160` account addresses, using `ECDSA` for signatures.
This change streamlines the user experience by consolidating address types and wallets.


## Rationale
Ethereum-like and Substrate-based chains differ significantly in their account format.

Expand Down Expand Up @@ -48,4 +46,4 @@ All pallet addresses have been truncated to 20 bytes; simply remove the trailing


## Copyright
Copyright and related rights waived via [CC0](https://github.com/darwinia-network/DIPs/blob/main/LICENSE).
Copyright and related rights waived via [CC0](../LICENSE).
132 changes: 132 additions & 0 deletions DIPs/dip-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
dip: 3
title: Introduce EIP-1559-like Mechanism to Reform the Network Fee Market
authors: Darwinia Network
discussions-to: https://github.com/orgs/darwinia-network/discussions/1163
status: Final
type: Economic
created: 2023-12-14
---


# DIP-3
## Abstract
This DIP suggests implementing `EIP-1559`-like mechanism within the Darwinia Network to transform its fee structure.

Under this proposal, all transaction fees would be burned, while tips would be awarded directly to block authors.
This aligns with our future inflation strategy, motivates collators, and paves the way for practical applications of *RING*.
The result is a more predictable, sustainable, and user-centric ecosystem.

Before Darwinia adopts the new inflation model, this DIP will make minor adjustments to the inflation mechanism to prevent the reissuance of burned assets.


## Rationale
### Reasons
1. By adopting `EIP-1559`, which replaces the gas auction system with a base fee plus a priority fee,
users will benefit from more predictable transaction costs while also reducing network congestion during peak times.
This improvement serves both individual users and the network overall.

### Future Objectives
1. To align with our upcoming inflation model,
the burning mechanism of `EIP-1559` for part of the transaction fees is consistent with Darwinia's strategy to revamp its inflation system.
This approach aims to maintain long-term token value stability and promote sustainable development of the network.
2. To better balance responsibilities and rewards within the relay chain-parachain structure, where collators play a more indirect role in security,
it's logical to adjust block production incentives to reflect their updated contribution to consensus maintenance and network protection.
3. To enhance utility for *RING*, introducing tangible use cases is essential.
Doing so encourages wider token engagement within network activities and increases their practical value.

### References
- https://eips.ethereum.org/EIPS/eip-1559
- https://darwinia.network/Genepaper_v3.pdf

## Specification
### Transaction Fee Adjustment
Integrate this within `DealWithFees` and pass the struct to `pallet-transaction` to enable the updated transaction fee model.
```rs
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction =
pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>;
..
}

/// EIP-1559 like configuration.
///
/// Burn the base fee and allocate the tips to the block producer.
pub struct DealWithFees<R>(core::marker::PhantomData<R>);
impl<R> frame_support::traits::OnUnbalanced<pallet_balances::NegativeImbalance<R>>
for DealWithFees<R>
where
R: pallet_authorship::Config + pallet_balances::Config,
{
fn on_unbalanceds<B>(
mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<R>>,
) {
// substrate
use frame_support::traits::Currency;

if fees_then_tips.next().is_some() {
if let Some(tips) = fees_then_tips.next() {
if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
// Tip the block producer here.
<pallet_balances::Pallet<R>>::resolve_creating(&author, tips);
}

// Burn the tips here. (IMPOSSIBLE CASE)
}
}

// Burn the base fee here.
}
}
```

### Inflation Adjustment (Darwinia Only)
First, create the issuance map for Darwinia as outlined in the Darwinia Gene Paper.
```rs
// Generate the issuing map.
//
// Formula:
// ```
// unissued * (1 - (99 / 100) ^ sqrt(years));
// ```
//
// Use `I95F33` here, because `2^94 > TOTAL_SUPPLY * 10^18`.
fn issuing_map() -> Vec<Balance> {
let ninety_nine = I95F33::from_num(99_u8) / 100_i128;
let max = 10_000_000_000_u128;
let mut supply = 2_000_000_000_u128;

(1_u8..=100)
.map(|years| {
let sqrt = transcendental::sqrt::<I95F33, I95F33>(years.into()).unwrap();
let pow = transcendental::pow::<I95F33, I95F33>(ninety_nine, sqrt).unwrap();
let ratio = I95F33::from_num(1_u8) - pow;
let unissued = max - supply;
let to_issue =
(I95F33::checked_from_num(unissued).unwrap() * ratio).floor().to_num::<Balance>();

supply += to_issue;

to_issue * UNIT
})
.collect()
}
```

Calculate the session issuance amount based on the previously calculated map.
```rs
/// Calculate the issuing of a period.
///
/// Use `U94F34` here, because `2^94 > TOTAL_SUPPLY * 10^18`.
pub fn issuing_in_period(period: Moment, elapsed: Moment) -> Option<Balance> {
let years = (elapsed / MILLISECS_PER_YEAR) as usize;
let to_issue = ISSUING_MAP[years];
let to_issue_per_millisecs = U94F34::checked_from_num(to_issue)? / MILLISECS_PER_YEAR;

Some(to_issue_per_millisecs.checked_mul(U94F34::checked_from_num(period)?)?.floor().to_num())
}
```


## Copyright
Copyright and related rights waived via [CC0](../LICENSE).

0 comments on commit 4e1908c

Please sign in to comment.