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

Take revenue #1228

Merged
merged 7 commits into from
Jul 22, 2021
Merged

Take revenue #1228

merged 7 commits into from
Jul 22, 2021

Conversation

zjb0807
Copy link
Member

@zjb0807 zjb0807 commented Jul 19, 2021

Closes: #1115

@zjb0807 zjb0807 requested a review from shaunxw July 19, 2021 04:28
@@ -1060,6 +1062,15 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}
}
impl TakeRevenue for DealWithFees {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset::ConcreteFungible { amount, .. } = revenue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all concrete fungible revenue is in KSM, need to check the the location.

@@ -1106,6 +1108,15 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}
}
impl TakeRevenue for DealWithFees {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset::ConcreteFungible { amount, .. } = revenue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

if let MultiAsset::ConcreteFungible { amount, .. } = revenue {
// ensure KaruraTreasuryAccount have ed for DOT.
// Ignore the result.
let _ = Tokens::deposit(AUSD, &TreasuryAccount::get(), amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _ = Tokens::deposit(AUSD, &TreasuryAccount::get(), amount);
let _ = Tokens::deposit(DOT, &TreasuryAccount::get(), amount);

@@ -1060,6 +1062,15 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}
}
impl TakeRevenue for DealWithFees {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to reuse the DealWithFees. We should make each struct type concern their own business. Declare a new struct before XcmConfig and name it ToTreasury.

@codecov
Copy link

codecov bot commented Jul 19, 2021

Codecov Report

Merging #1228 (28bd6ca) into master (eb3af16) will decrease coverage by 0.23%.
The diff coverage is 0.00%.

❗ Current head 28bd6ca differs from pull request most recent head 2039536. Consider uploading reports for the commit 2039536 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1228      +/-   ##
==========================================
- Coverage   66.04%   65.80%   -0.24%     
==========================================
  Files         224      222       -2     
  Lines       19753    19213     -540     
==========================================
- Hits        13045    12643     -402     
+ Misses       6708     6570     -138     
Impacted Files Coverage Δ
runtime/karura/src/lib.rs 8.57% <0.00%> (-0.10%) ⬇️
runtime/mandala/src/lib.rs 24.26% <0.00%> (-0.25%) ⬇️
modules/evm/src/runner/handler.rs 69.86% <0.00%> (-0.27%) ⬇️
modules/currencies/src/mock.rs
modules/currencies/src/tests.rs
modules/currencies/src/lib.rs
modules/currencies/src/weights.rs
primitives/src/currency.rs
modules/staking-pool/rpc/runtime-api/src/lib.rs
node/src/main.rs 0.00% <0.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb3af16...2039536. Read the comment docs.

@zjb0807 zjb0807 requested a review from shaunxw July 19, 2021 06:37
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset::ConcreteFungible { id, amount } = revenue {
if CurrencyIdConvert::convert(id).is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_some check only ensures id could be converted to a CurrencyId but it doesn't have to be KSM.

To handle it correctly, get the wrapped currency_id in result and deposit with it.

Copy link
Contributor

@shaunxw shaunxw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now. We need to do end to end test before merging it.

@zjb0807
Copy link
Member Author

zjb0807 commented Jul 20, 2021

image

[
  {
    "phase": {
      "applyExtrinsic": 0
    },
    "event": {
      "index": "0x0000",
      "data": [
        {
          "weight": 185277000,
          "class": "Mandatory",
          "paysFee": "Yes"
        }
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x1e03",
      "data": [
        1
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x0003",
      "data": [
        "owxc9EpKLTtSjkRmzSytjmJtBgjVcMdNf5ZwCvR1hDjTGSE"
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x0b00",
      "data": [
        {
          "token": "KSM"
        },
        "owxc9EpKLTtSjkRmzSytjmJtBgjVcMdNf5ZwCvR1hDjTGSE",
        999952000000
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x0c02",
      "data": [
        {
          "token": "KSM"
        },
        "owxc9EpKLTtSjkRmzSytjmJtBgjVcMdNf5ZwCvR1hDjTGSE",
        999952000000
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x0c02",
      "data": [
        {
          "token": "KSM"
        },
        "qmmNufxeWaAVLMER2va1v4w2HbuU683c5gGtuxQG4fKTZSb",
        48000000
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x3502",
      "data": [
        "0xd0fc0b77005cdc143478c9d30527010bc62d51b8cb1b2c2d37643a3c0d5e14af",
        {
          "complete": 600000000
        }
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x1e04",
      "data": [
        600000000,
        "0x8ffc8978d9512ac029f7a829ebb1a360066c362c1a7e17bef6212178503b505e"
      ]
    },
    "topics": []
  },
  {
    "phase": {
      "applyExtrinsic": 1
    },
    "event": {
      "index": "0x0000",
      "data": [
        {
          "weight": 0,
          "class": "Mandatory",
          "paysFee": "Yes"
        }
      ]
    },
    "topics": []
  }
]

The treasury(qmmNufxeWaAVLMER2va1v4w2HbuU683c5gGtuxQG4fKTZSb) take revenue of XCM execution fee 48000000.

@xlc
Copy link
Member

xlc commented Jul 20, 2021

How hard to write some tests for this?

@zjb0807
Copy link
Member Author

zjb0807 commented Jul 20, 2021

How hard to write some tests for this?

BTW, learn about the xcm transaction process.

@shaunxw
Copy link
Contributor

shaunxw commented Jul 20, 2021

We only need to mock the execution of received XCM from Kusama in integration tests. You may refer to the commented out ones in integration tests.

// fn receive_cross_chain_assets() {

@zjb0807 zjb0807 merged commit 9ca456e into master Jul 22, 2021
@zjb0807 zjb0807 deleted the take_revenue branch July 22, 2021 03:45
syan095 pushed a commit that referenced this pull request Jul 22, 2021
…am-version

* origin/master:
  Take revenue (#1228)
  Update orml (#1245)
  Updated the Substrate and Cumulus version to the latest commit on polkadot-v0.9.8 branch (#1242)

# Conflicts:
#	orml
syan095 pushed a commit that referenced this pull request Jul 22, 2021
…mprovement

* origin/master:
  Take revenue (#1228)
  Update orml (#1245)
  Updated the Substrate and Cumulus version to the latest commit on polkadot-v0.9.8 branch (#1242)

# Conflicts:
#	orml
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.

Make treasury take revenue of XCM execution fee
3 participants