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

Feat/restricted transfers closure #1621

Merged
merged 31 commits into from
Dec 1, 2023

Conversation

mustermeiszer
Copy link
Collaborator

@mustermeiszer mustermeiszer commented Nov 23, 2023

Description

This changes closes the restricted transfers features. This will allow accounts to set allowances for their accounts and currencies to where funds are allowed to be sent to (not for CFG though, as we can not restrict pallet-balances).

This is an opt-in restriction meaning

  • No allowance set → No restrictions
  • Allowance set → Only allowed receiver can receive funds from that account (on a per currency base)

NOTE:

  • orml-xtokens has NO storage and pallet-restricted-xtokens mimics the API 1-to-1, hence we can replace the location of orml-xtokens with pallet-restricted-xtokens in the construct_runtime!-macro

Changes and Descriptions

  • Wrap orml-xtokens in pallet-restricted-xtokens
  • Adapt pallet-transfer-allowlist to reject native currency allowances
  • Add pallet-transfer-allowlist to dev
  • Add pallet-transfer-allowlist to altair
  • Add pallet-transfer-allowlist to centrifuge
  • Add pallet-restricted-xtokens to dev
  • Add pallet-restricted-xtokens to altair
  • Add pallet-restricted-xtokens to centrifuge
  • Implement common filter to be used in pallet-restricted-xtokens and pallet-restricted-tokens
  • Adds a new ProxyType::Transfer that can be used to extend otherwise non-transfer proxies with this ability.

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

The restricted-xtokens pallet looks good 🥳

I left a couple of comments, suggestions or just questions as a first scan but will give it another look either later or tomorrow morning 👍

libs/types/src/locations.rs Show resolved Hide resolved
pallets/restricted-xtokens/Cargo.toml Outdated Show resolved Hide resolved
pallets/restricted-xtokens/src/mock/mod.rs Outdated Show resolved Hide resolved
fn para_a_rreceiver_para_a() -> MultiLocation {
MultiLocation::new(
0,
X1(Junction::AccountId32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't include the parachain "a" in the multilocation. I guess it doesn't affect functionality but it would be nice to have this in sync with para_a_rreceiver_para_b and generally having it looking like what one would expect it to be (the principle of least surprise)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why would I do that? The location is generated from the point of view of para_a, right?

Comment on lines 134 to 144
let mut a: Vec<u8> = "A".into();
a.resize(32, 0);
let mut a1: Vec<u8> = "A1".into();
a1.resize(32, 0);
let mut b: Vec<u8> = "B".into();
b.resize(32, 0);
let mut b1: Vec<u8> = "B1".into();
b1.resize(32, 0);
if l == MultiLocation::parent() {
return Some(CurrencyId::R);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unnecessarily clutter-y. If we would use a GeneralIndex (u128) that we map for each currency, then it's a lot simpler and we could even define that map at the enum definition level (i.e, pub enum CurrencyId { R = 0, A = 1, etc.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I copy pasta that one from acala. While I agree I think for the given 5 enum variants this logic is fine and I do not expect to change it often in the futre. Wdyt?

pallets/restricted-xtokens/src/tests.rs Outdated Show resolved Hide resolved
pallets/transfer-allowlist/src/lib.rs Outdated Show resolved Hide resolved
pallets/restricted-xtokens/src/lib.rs Outdated Show resolved Hide resolved
pallets/transfer-allowlist/src/lib.rs Show resolved Hide resolved
pallets/transfer-allowlist/src/mock.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, but looks good to me! 🚀

pallets/transfer-allowlist/src/lib.rs Show resolved Hide resolved
pallets/restricted-xtokens/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

The current extrinsic weights are underestimated. Given that this is a common attack vector, this needs to be fixed.

Apart from that, I also believe that we cannot simply overwrite the OrmlXTokens pallet index with XTokens because we drop the storage.

There a few more nit comments which you can ignore. I have to admit that I only skimmed through the mocks and unit tests.

pallets/restricted-xtokens/Cargo.toml Outdated Show resolved Hide resolved
pallets/restricted-xtokens/Cargo.toml Outdated Show resolved Hide resolved
pallets/restricted-xtokens/Cargo.toml Outdated Show resolved Hide resolved
pallets/restricted-xtokens/Cargo.toml Outdated Show resolved Hide resolved
pallets/restricted-xtokens/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Show resolved Hide resolved
runtime/centrifuge/src/lib.rs Show resolved Hide resolved
@@ -1994,6 +2015,7 @@ mod __runtime_api_use {

#[cfg(not(feature = "disable-runtime-api"))]
use __runtime_api_use::*;
use cfg_types::locations::Location;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on this addition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clion. will see if can remove

Copy link
Contributor

Choose a reason for hiding this comment

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

Since I switched to RustRover, I am running into similar issues. Still incredible time saving with the auto imports.

runtime/common/src/lib.rs Outdated Show resolved Hide resolved
runtime/development/src/lib.rs Show resolved Hide resolved
@mustermeiszer
Copy link
Collaborator Author

Apart from that, I also believe that we cannot simply overwrite the OrmlXTokens pallet index with XTokens because we drop the storage.

There is no storage, or am I missing something?

@wischli
Copy link
Contributor

wischli commented Nov 24, 2023

Apart from that, I also believe that we cannot simply overwrite the OrmlXTokens pallet index with XTokens because we drop the storage.

There is no storage, or am I missing something?

You are right. Then I suppose we can keep your change. Will close the requests.

Copy link
Collaborator Author

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Minus nits from william I think it is good to go. We should address these and then get this in.

mustermeiszer and others added 14 commits December 1, 2023 12:34
* integration-tests: Add relay chain storage to env, update restricted token tests

* restricted-xtokens: Remove xcm-simulator tests

* deps: Update restricted-xtokens deps

* transfer-allowlist: Use different trait for increasing an account balance in benchmarking setup

* integration-tests: Add default constructor for generic envs

* integration-test: Add LP eth usdc test via LP pallet

* integration-tests: Check for allowance in LP eth usdc test

* transfer-allowlist: Use non-default currency ID in benchmarks

* clippy: Obey

* transfer-allowlist: Drop custom currency ID in mock runtime

* transfer-allowlist: Add non-default currency ID for tests
@cdamian cdamian force-pushed the feat/restricted-transfers-closure branch from 51152d7 to ab7528a Compare December 1, 2023 11:35
wischli
wischli previously approved these changes Dec 1, 2023
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

Thanks for adhering to all my nits and fixing the weight! Looks really good, great work @mustermeiszer and @cdamian!

ProxyType::Transfer => {
matches!(
c,
RuntimeCall::XTokens(..) | RuntimeCall::Balances(..) | RuntimeCall::Tokens(..)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cdamian sit, I forgot something. We should add two more here

RuntimeCall::LiquidityPools(pallet_liquidituy_pool::Call::Transfer{..} | pallet_liquidituy_pool::Call::TransferTrancheTokens{..})

ProxyType::Transfer => {
matches!(
c,
RuntimeCall::XTokens(..) | RuntimeCall::Balances(..) | RuntimeCall::Tokens(..)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as in altair and Centrifuge

@mustermeiszer
Copy link
Collaborator Author

/benchmark centrifuge

@mustermeiszer
Copy link
Collaborator Author

/benchmark altair

@mustermeiszer
Copy link
Collaborator Author

/benchmark development

@cdamian cdamian force-pushed the feat/restricted-transfers-closure branch from 5535ee6 to df59f6a Compare December 1, 2023 12:29
@mustermeiszer mustermeiszer merged commit 4c9d5f7 into main Dec 1, 2023
8 checks passed
@cdamian cdamian deleted the feat/restricted-transfers-closure branch July 30, 2024 07:55
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.

5 participants