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

Connectors POC #861

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,485 changes: 1,032 additions & 453 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"libs/types",
"pallets/anchors",
"pallets/bridge",
"pallets/connectors",
"pallets/claims",
"pallets/collator-allowlist",
"pallets/crowdloan-claim",
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
};

# This is a hash of all the Cargo dependencies, for reproducibility.
cargoSha256 = "sha256-0PYFTi+gH8T1NocZAC+rdnpuGg9s10ObyFC5ebp8iRs=";
cargoSha256 = "sha256-OzVeIy/zwXJv4BCwOxauc18G8jVaB4+75yDyvRE3XfA=";

nativeBuildInputs = with pkgs; [ clang git-mock pkg-config ];
buildInputs = with pkgs; [ openssl ] ++ (
Expand Down
2 changes: 1 addition & 1 deletion libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub trait PoolNAV<PoolId, Amount> {

/// A trait that support pool inspection operations such as pool existence checks and pool admin of permission set.
pub trait PoolInspect<AccountId, CurrencyId> {
type PoolId: Parameter + Member + Debug + Copy + Default + TypeInfo;
type PoolId: Parameter + Member + Debug + Copy + Default + TypeInfo + Encode + Decode;
type TrancheId: Parameter + Member + Debug + Copy + Default + TypeInfo;
type Rate;
type Moment;
Expand Down
102 changes: 102 additions & 0 deletions pallets/connectors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[package]
authors = ["Centrifuge <[email protected]>"]
description = 'Centrifuge Connectors Pallet'
edition = '2018'
license = "LGPL-3.0"
name = 'pallet-connectors'
repository = "https://github.com/centrifuge/centrifuge-chain/pallets/connectors"
version = '0.0.1'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']

[dependencies]
codec = { package = 'parity-scale-codec', version = '3.0.0', features = ['derive'], default-features = false }
ethabi = { version = "16.0", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
hex = { version = "0.4.3", default_features = false }
scale-info = { version = "2.0", default-features = false, features = ["derive"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }

# Substrate crates
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }

# Optional dependencies for benchmarking
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.29" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.29" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.29" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.29" }
pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.29" }

# Our custom pallets
cfg-primitives = { path = "../../libs/primitives", default-features = false }
cfg-traits = { path = "../../libs/traits", default-features = false }
cfg-types = { path = "../../libs/types", default-features = false }
runtime-common = { path = "../../runtime/common", default-features = false }

# Polkadot
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.29" }

pallet-ethereum = { git = "https://github.com/NunoAlexandre/frontier", branch = "unfork-v0.9.29", default-features = false }
pallet-ethereum-xcm = { git = "https://github.com/NunoAlexandre/moonbeam", default-features = false, branch = "unfork-v0.9.29" }
pallet-xcm-transactor = { git = "https://github.com/NunoAlexandre/moonbeam", default-features = false, branch = "unfork-v0.9.29" }
xcm-primitives = { git = "https://github.com/NunoAlexandre/moonbeam", default-features = false, branch = "unfork-v0.9.29" }

[dev-dependencies]
hex = "0.4.3"
serde = { version = "1.0.102" }

# Our pallets
pallet-interest-accrual = { path = "../interest-accrual", default-features = true }
pallet-loans = { path = "../loans", default-features = true }
pallet-permissions = { path = "../permissions", default-features = true }
pallet-pools = { path = "../pools", default-features = true }

# Substrate crates & pallets
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.29" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.29" }
pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.29" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.29" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.29" }

# Orml crates
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.29" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.29" }

# Local crates
runtime-common = { path = "../../runtime/common", default-features = true }

[features]
default = ['std']
runtime-benchmarks = [
"frame-benchmarking",
"pallet-balances",
"orml-tokens",
"orml-traits",
]
std = [
'codec/std',
'cfg-types/std',
'cfg-traits/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-runtime/std',
'orml-tokens/std',
'orml-traits/std',
'pallet-balances/std',
'runtime-common/std',
'xcm/std',
'pallet-xcm-transactor/std',
'pallet-ethereum-xcm/std',
'pallet-ethereum/std',
'xcm-primitives/std',
'ethabi/std',
'pallet-interest-accrual/std',
'pallet-permissions/std',
'pallet-loans/std',
'pallet-pools/std',
'pallet-uniques/std',
]
63 changes: 63 additions & 0 deletions pallets/connectors/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2022 Centrifuge Foundation (centrifuge.io).
// This file is part of Centrifuge chain project.

// Centrifuge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version (see http://www.gnu.org/licenses).

// Centrifuge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
#![cfg_attr(not(feature = "std"), no_std)]
use ethabi::{Bytes, Contract};
use sp_std::{vec, vec::Vec};

/// The ConnectorsXcmContract handle function name
static HANDLE_FUNCTION: &str = "handle";

/// Return the encoded contract call, i.e, ConnectorsXcmRouter::handle(encoded_msg).
pub fn encoded_contract_call(encoded_msg: Vec<u8>) -> Bytes {
let contract = xcm_router_contract();
let encoded_contract_call = contract
.function(HANDLE_FUNCTION)
.expect("Known at compilation time")
.encode_input(&[ethabi::Token::Bytes(encoded_msg)])
.expect("Known at compilation time");

encoded_contract_call
}

/// The ConnectorsXcmRouter Abi as in ethabi::Contract
/// Note: We only concern ourselves with the `handle` function of the contract
/// since that's all we need to build the calls for remote EVM execution.
pub fn xcm_router_contract() -> Contract {
use sp_std::collections::btree_map::BTreeMap;

let mut functions = BTreeMap::new();
#[allow(deprecated)]
functions.insert(
"handle".into(),
vec![ethabi::Function {
name: HANDLE_FUNCTION.into(),
inputs: vec![ethabi::Param {
name: "message".into(),
kind: ethabi::ParamType::Bytes,
internal_type: None,
}],
outputs: vec![],
constant: false,
state_mutability: Default::default(),
}],
);

ethabi::Contract {
constructor: None,
functions,
events: Default::default(),
errors: Default::default(),
receive: false,
fallback: false,
}
}
Loading