Skip to content

Commit

Permalink
Feat/restricted transfers closure (#1621)
Browse files Browse the repository at this point in the history
* feat: compiles and is functional.

Needs:
- tests
- clean up of warnings

* chore: clean up tests

* feat: finish tests

* feat: Adapt allowance to use fungible, restirct native

* fix: allowlist for dev

* feat: add allowlist to centrifuge

* feat: add allowlist Altair

* feat: use fixed versioning for xcm

* feat: add to dev

* feat: make dispatch result

* feat: Filter for xcm transfers

* feat: add restricted xtoken to centrifuge

* feat: add restricted xtoken altair

* feat: add transfer proxy altair

* feat: add transfer proxy centrifuge

* feat: add transfer proxy dev

* feat: rename error allowlist

* fix: indendation

* fix: doc comments restricted xtokens

* chore: error

* feat: integration tests wip

* feat: filter for lp and for tokens

* feat: use filter for tokens

* feat: flter for lp logic and runtime adjustments

* Restricted transfers follow-ups (#1630)

* 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

* deps: Update pallet-restricted-xtokens deps

* deps: Fix integration-tests deps

* deps: Use workspace deps

* restricted-xtokens: Update weights

* restricted-xtokens: Update crate version

* runtime: Add LP transfer extrinsics to Transfer proxy type

---------

Co-authored-by: Cosmin Damian <[email protected]>
  • Loading branch information
mustermeiszer and cdamian authored Dec 1, 2023
1 parent 2ba3d5a commit 4c9d5f7
Show file tree
Hide file tree
Showing 42 changed files with 2,423 additions and 531 deletions.
23 changes: 22 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ members = [
"pallets/pool-registry",
"pallets/data-collector",
"pallets/restricted-tokens",
"pallets/restricted-xtokens",
"pallets/transfer-allowlist",
"pallets/rewards",
"runtime/altair",
Expand Down Expand Up @@ -248,6 +249,7 @@ pallet-permissions = { path = "pallets/permissions", default-features = false }
pallet-pool-registry = { path = "pallets/pool-registry", default-features = false }
pallet-pool-system = { path = "pallets/pool-system", default-features = false }
pallet-restricted-tokens = { path = "pallets/restricted-tokens", default-features = false }
pallet-restricted-xtokens = { path = "pallets/restricted-xtokens", default-features = false }
pallet-rewards = { path = "pallets/rewards", default-features = false }
pallet-transfer-allowlist = { path = "pallets/transfer-allowlist", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions libs/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cfg-primitives = { path = "../primitives", default-features = false }
cfg-traits = { path = "../traits", default-features = false }
cfg-utils = { path = "../utils", default-features = false }


[dev-dependencies]
frame-support = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.43" }
hex = { version = "0.4.3", default_features = false }
Expand Down
2 changes: 1 addition & 1 deletion libs/types/src/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sp_runtime::{
traits::{BlakeTwo256, Hash},
AccountId32,
};
use xcm::{latest::MultiLocation, VersionedMultiLocation};
use xcm::{v3::MultiLocation, VersionedMultiLocation};

use crate::domain_address::DomainAddress;
/// Location types for destinations that can receive restricted transfers
Expand Down
16 changes: 15 additions & 1 deletion pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub type GeneralCurrencyIndexOf<T> =
pub mod pallet {
use cfg_traits::{
investments::{ForeignInvestment, TrancheCurrency},
CurrencyInspect, Permissions, PoolInspect, Seconds, TimeAsSecs, TrancheTokenPrice,
CurrencyInspect, Permissions, PoolInspect, PreConditions, Seconds, TimeAsSecs,
TrancheTokenPrice,
};
use cfg_types::{
permissions::{PermissionScope, PoolRole, Role},
Expand Down Expand Up @@ -278,6 +279,11 @@ pub mod pallet {
/// message.
type TreasuryAccount: Get<Self::AccountId>;

type PreTransferFilter: PreConditions<
(Self::AccountId, DomainAddress, Self::CurrencyId),
Result = DispatchResult,
>;

type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

Expand Down Expand Up @@ -565,6 +571,12 @@ pub mod pallet {
// Ensure pool and tranche exist and derive invest id
let invest_id = Self::derive_invest_id(pool_id, tranche_id)?;

T::PreTransferFilter::check((
who.clone(),
domain_address.clone(),
invest_id.clone().into(),
))?;

// Transfer to the domain account for bookkeeping
T::Tokens::transfer(
invest_id.into(),
Expand Down Expand Up @@ -627,6 +639,8 @@ pub mod pallet {
}
}

T::PreTransferFilter::check((who.clone(), receiver.clone(), currency_id))?;

// Transfer to the domain account for bookkeeping
T::Tokens::transfer(
currency_id,
Expand Down
56 changes: 56 additions & 0 deletions pallets/restricted-xtokens/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "pallet-restricted-xtokens"
authors.workspace = true
description = "A wrapper pallet around orml-xtokens to allow restricting transfers"
edition.workspace = true
license.workspace = true
repository.workspace = true
version = "0.0.1"

[dependencies]
codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
serde = { workspace = true, optional = true }

# substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-std = { workspace = true }

# orml
orml-xtokens = { workspace = true }
orml-traits = { workspace = true }

# polkadot
xcm = { workspace = true }

# local
cfg-traits = { workspace = true }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-std/std",
"cfg-traits/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"orml-xtokens/std",
"orml-traits/std",
"xcm/std"
]

runtime-benchmarks = [
"cfg-traits/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"orml-xtokens/runtime-benchmarks",
]
try-runtime = [
"cfg-traits/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"orml-xtokens/try-runtime",
]
Loading

0 comments on commit 4c9d5f7

Please sign in to comment.