Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network fee distribution and Incentive Pools #2153

Draft
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

zqhxuyuan
Copy link
Contributor

@zqhxuyuan zqhxuyuan commented May 23, 2022

relates to: #2139

  • Introduce OnFeeDeposit trait

modules:

  • transaciton payment
    • DealWithTxFees used to deal with OnUnbalanced, and distribution fee to treasury pool account.
  • xcm execution fee
  • homa staking reward fee
  • honzon stability fee
  • honzon liquidation fee (Honzon Liquidation penalty goes to OnFeeDeposit #2250)
  • dex swap fee

integrations:

  • migration existing Treasury Accounts to Treasury Pool Accounts?
    • we can provide a dispatch call to manual transfer token to new treasury pool accounts if need.
  • genesis initialize configuration
  • dex swap if none native token when allocation from treasury pool to incentive pools.

@zqhxuyuan zqhxuyuan changed the title fee distributionn framework Network fee distribution and Incentive Pools May 23, 2022
@xlc
Copy link
Member

xlc commented Jun 10, 2022

swap fee is not yet implemented so leave it for now
xcm execution fee are charged by relaychain so we don't actually have those fees and we can also ignore it

@zqhxuyuan
Copy link
Contributor Author

zqhxuyuan commented Jun 10, 2022

swap fee is not yet implemented so leave it for now
xcm execution fee are charged by relaychain so we don't actually have those fees and we can also ignore it

xcm fee here means buy_weight revenue, and it go to our treasury account, so it can also refactored with fee distribution strategy:

pub struct ToTreasury;
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset {
id: Concrete(location),
fun: Fungible(amount),
} = revenue
{
if let Some(currency_id) = CurrencyIdConvert::convert(location) {
// Ensure KaruraTreasuryAccount have ed requirement for native asset, but don't need
// ed requirement for cross-chain asset because it's one of whitelist accounts.
// Ignore the result.
let _ = Currencies::deposit(currency_id, &KaruraTreasuryAccount::get(), amount);
}
}
}
}

@zqhxuyuan zqhxuyuan requested review from xlc and shaunxw June 14, 2022 07:46
@zqhxuyuan
Copy link
Contributor Author

zqhxuyuan commented Jun 17, 2022

@syan095 can you confirm that honzon stability fee is still working on bad debit case. I think current is not working, i.e.:

  • cdp_engine on_initialize deposit fee to a new treasury account instead of CDPTreasuryAccount
  • cdp_treasury on_finalize: when bad debit happened, surplus_pool is zero, because CDPTreasuryAccount got no balance on_initialize now, so the DebitPool would't decreased anymore(offset_amount is zero in this case).
    let offset_amount = sp_std::cmp::min(Self::debit_pool(), Self::surplus_pool());
    // Burn the amount that is equal to offset amount of stable currency.
    if !offset_amount.is_zero() {
    let res = T::Currency::withdraw(T::GetStableCurrencyId::get(), &Self::account_id(), offset_amount);
    match res {
    Ok(_) => {
    DebitPool::<T>::mutate(|debit| {
    *debit = debit
    .checked_sub(offset_amount)

and also should consider a case that when stability fee go to treasury account, it'll be allocation to incentive pool, so it'll will make balance of treasury account zero. My first thougth is maybe we could add a whitlelist to stop allocation to incentive pools?

@zqhxuyuan
Copy link
Contributor Author

/bench runtime mandala module_fees

@ghost
Copy link

ghost commented Jun 20, 2022

Finished benchmark for branch: fee_distribution

Benchmark: Benchmark Runtime Mandala Module

cargo run --profile production --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/

Results

Pallet: "module_fees", Extrinsic: "set_income_fee", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees IncomeToTreasuries (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 16.07
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 16.07
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "set_treasury_pool", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryToIncentives (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 16.82
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 16.82
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "force_transfer_to_incentive", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryTokens (r:1 w:0)
Storage: Fees TreasuryToIncentives (r:1 w:0)
Storage: System Account (r:2 w:2)
Storage: EvmAccounts EvmAddresses (r:1 w:0)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 47.11
µs

Reads = 6
Writes = 3

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 47.11
µs

Reads = 6
Writes = 3

Acala Benchmarking Bot and others added 3 commits June 20, 2022 08:56
…untime-benchmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/
@zqhxuyuan
Copy link
Contributor Author

/bench runtime karura module_fees

@ghost
Copy link

ghost commented Jun 20, 2022

Finished benchmark for branch: fee_distribution

Benchmark: Benchmark Runtime Karura Module

cargo run --profile production --color=never --bin=acala --features=runtime-benchmarks --features=with-karura-runtime -- benchmark pallet --chain=karura-dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/

Results

Pallet: "module_fees", Extrinsic: "set_income_fee", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees IncomeToTreasuries (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 14.98
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 14.98
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "set_treasury_pool", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryToIncentives (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 15.91
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 15.91
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "force_transfer_to_incentive", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryTokens (r:1 w:0)
Storage: Fees TreasuryToIncentives (r:1 w:0)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 8.493
µs

Reads = 3
Writes = 1

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 8.493
µs

Reads = 3
Writes = 1

…untime-benchmarks --features=with-karura-runtime -- benchmark pallet --chain=karura-dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/
@zqhxuyuan
Copy link
Contributor Author

/bench runtime acala module_fees

@ghost
Copy link

ghost commented Jun 20, 2022

Finished benchmark for branch: fee_distribution

Benchmark: Benchmark Runtime Acala Module

cargo run --profile production --color=never --bin=acala --features=runtime-benchmarks --features=with-acala-runtime -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/

Results

Pallet: "module_fees", Extrinsic: "set_income_fee", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees IncomeToTreasuries (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 15.45
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 15.45
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "set_treasury_pool", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryToIncentives (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 17.62
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 17.62
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "force_transfer_to_incentive", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryTokens (r:1 w:0)
Storage: Fees TreasuryToIncentives (r:1 w:0)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 15.32
µs

Reads = 3
Writes = 1

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 15.32
µs

Reads = 3
Writes = 1

…untime-benchmarks --features=with-acala-runtime -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/
@zqhxuyuan
Copy link
Contributor Author

/bench runtime module module_fees

@ghost
Copy link

ghost commented Jun 20, 2022

Finished benchmark for branch: fee_distribution

Benchmark: Benchmark Runtime Module

cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./modules/fees/src/weights.rs --template=./templates/module-weight-template.hbs

Results

Wrote dot graph to /app/git/Acala/target/release/build/orchestra-proc-macro-7191253e5cd10c8b/out/overseer-subsystem-messaging.dot
Pallet: "module_fees", Extrinsic: "set_income_fee", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees IncomeToTreasuries (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 24.04
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 24.04
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "set_treasury_pool", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryToIncentives (r:1 w:1)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 24.27
µs

Reads = 2
Writes = 2

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 24.27
µs

Reads = 2
Writes = 2

Pallet: "module_fees", Extrinsic: "force_transfer_to_incentive", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info

Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
Storage: Fees TreasuryTokens (r:1 w:0)
Storage: Fees TreasuryToIncentives (r:1 w:0)
Storage: System Account (r:2 w:2)
Storage: EvmAccounts EvmAddresses (r:1 w:0)

Median Slopes Analysis

-- Extrinsic Time --

Model:
Time ~= 69.85
µs

Reads = 6
Writes = 3

Min Squares Analysis

-- Extrinsic Time --

Model:
Time ~= 69.85
µs

Reads = 6
Writes = 3

Acala Benchmarking Bot and others added 7 commits June 20, 2022 12:44
…hmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=module_fees --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./modules/fees/src/weights.rs --template=./templates/module-weight-template.hbs
…debit is added to the Treasury. When liquidation is complete, the debit should be fully paid off.

Updated tests accordingly.
…ount of debit is added to the Treasury. When liquidation is complete, the debit should be fully paid off."

This reverts commit d0e6454.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants