Acala icon indicating copy to clipboard operation
Acala copied to clipboard

Network fee distribution and Incentive Pools

Open zqhxuyuan opened this issue 3 years ago • 11 comments

relates to: https://github.com/AcalaNetwork/Acala/issues/2139

  • Introduce OnFeeDeposit trait

modules:

  • [x] transaciton payment
    • DealWithTxFees used to deal with OnUnbalanced, and distribution fee to treasury pool account.
  • [ ] xcm execution fee
  • [x] homa staking reward fee
  • [x] honzon stability fee
  • [x] honzon liquidation fee (#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 avatar May 23 '22 08:05 zqhxuyuan

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

xlc avatar Jun 10 '22 04:06 xlc

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: https://github.com/AcalaNetwork/Acala/blob/7727abeac1cb999ae07495a7836a695a5b1f8583/runtime/karura/src/xcm_config.rs#L100-L116

zqhxuyuan avatar Jun 10 '22 05:06 zqhxuyuan

@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)~~. https://github.com/AcalaNetwork/Acala/blob/d19ca54dbb9e69b03dc7cb42af3d64488cfeba2e/modules/cdp-treasury/src/lib.rs#L292-L301

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 avatar Jun 17 '22 01:06 zqhxuyuan

/bench runtime mandala module_fees

zqhxuyuan avatar Jun 20 '22 07:06 zqhxuyuan

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

ghost avatar Jun 20 '22 07:06 ghost

/bench runtime karura module_fees

zqhxuyuan avatar Jun 20 '22 09:06 zqhxuyuan

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

ghost avatar Jun 20 '22 09:06 ghost

/bench runtime acala module_fees

zqhxuyuan avatar Jun 20 '22 10:06 zqhxuyuan

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

ghost avatar Jun 20 '22 10:06 ghost

/bench runtime module module_fees

zqhxuyuan avatar Jun 20 '22 12:06 zqhxuyuan

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

ghost avatar Jun 20 '22 12:06 ghost