-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
011d1a6
commit abd17d2
Showing
28 changed files
with
1,374 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use node_runtime::{argo_bridge::types::BridgeStatus, ArgoBridgeConfig}; | ||
|
||
pub fn production_config() -> ArgoBridgeConfig { | ||
ArgoBridgeConfig { | ||
status: BridgeStatus::Paused, | ||
mint_allowance: 0, | ||
bridging_fee: 0, | ||
thawn_duration: 1, | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn testing_config() -> ArgoBridgeConfig { | ||
ArgoBridgeConfig { | ||
status: BridgeStatus::Paused, | ||
mint_allowance: 0, | ||
bridging_fee: 0, | ||
thawn_duration: 1, | ||
..Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[package] | ||
name = "pallet-argo-bridge" | ||
version = '1.0.0' | ||
authors = ['Joystream contributors'] | ||
edition = '2018' | ||
|
||
[dependencies] | ||
sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
common = { package = 'pallet-common', default-features = false, path = '../common'} | ||
storage = { package = 'pallet-storage', default-features = false, path = '../storage'} | ||
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
membership = { package = 'pallet-membership', default-features = false, path = '../membership'} | ||
codec = { package = 'parity-scale-codec', version = '3.1.2', default-features = false, features = ['derive'] } | ||
serde = {version = '1.0.101', features = ['derive'], optional = true} | ||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } | ||
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true } | ||
|
||
# Benchmarking dependencies | ||
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true} | ||
|
||
[dev-dependencies] | ||
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' } | ||
randomness-collective-flip = { package = 'pallet-insecure-randomness-collective-flip', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
staking-handler = { package = 'pallet-staking-handler', default-features = false, path = '../staking-handler'} | ||
pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-storage = { package = 'sp-storage', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
|
||
[features] | ||
default = ['std', 'runtime-benchmarks'] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
'sp-core', | ||
"common/runtime-benchmarks", | ||
] | ||
std = [ | ||
'sp-std/std', | ||
'sp-io/std', | ||
'sp-runtime/std', | ||
'frame-support/std', | ||
'frame-system/std', | ||
'sp-arithmetic/std', | ||
'common/std', | ||
'storage/std', | ||
'balances/std', | ||
'membership/std', | ||
'codec/std', | ||
'serde', | ||
'scale-info/std', | ||
'frame-benchmarking?/std', | ||
] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
for hash use | ||
keccak256(bytes memory) returns (bytes32) − computes the Keccak-256 hash of the input. | ||
ripemd160(bytes memory) returns (bytes20) − compute RIPEMD-160 hash of the input. | ||
sha256(bytes memory) returns (bytes32) − computes the SHA-256 hash of the input. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use frame_support::{assert_err, assert_ok}; | ||
|
||
use super::*; | ||
use crate::types::*; | ||
use crate::Module as ArgoBridge; | ||
use balances::Pallet as Balances; | ||
use core::convert::TryFrom; | ||
use frame_benchmarking::v1::{account, benchmarks}; | ||
use frame_system::Pallet as System; | ||
use frame_system::{EventRecord, RawOrigin}; | ||
use sp_runtime::traits::One; | ||
use sp_std::convert::TryInto; | ||
use sp_std::vec; | ||
|
||
use crate::{BridgeConstraints, BridgeStatus, RemoteAccount, RemoteTransfer}; | ||
|
||
const SEED: u32 = 0; | ||
|
||
// We create this trait because we need to be compatible with the runtime | ||
// in the mock for tests. In that case we need to be able to have `membership_id == account_id` | ||
// We can't create an account from an `u32` or from a memberhsip_dd, | ||
// so this trait allows us to get an account id from an u32, in the case of `64` which is what | ||
// the mock use we get the parameter as a return. | ||
// In the case of `AccountId32` we use the method provided by `frame_benchmarking` to get an | ||
// AccountId. | ||
pub trait CreateAccountId { | ||
fn create_account_id(id: u32) -> Self; | ||
} | ||
|
||
impl CreateAccountId for u64 { | ||
fn create_account_id(id: u32) -> Self { | ||
id.into() | ||
} | ||
} | ||
|
||
impl CreateAccountId for u32 { | ||
fn create_account_id(id: u32) -> Self { | ||
id.into() | ||
} | ||
} | ||
|
||
impl CreateAccountId for sp_core::crypto::AccountId32 { | ||
fn create_account_id(id: u32) -> Self { | ||
account::<Self>("default", id, SEED) | ||
} | ||
} | ||
|
||
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
let events = frame_system::Pallet::<T>::events(); | ||
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into(); | ||
assert!( | ||
!events.is_empty(), | ||
"If you are checking for last event there must be at least 1 event" | ||
); | ||
let EventRecord { event, .. } = &events[events.len() - 1]; | ||
assert_eq!(event, &system_event); | ||
} | ||
|
||
benchmarks! { | ||
where_clause { | ||
where | ||
T: balances::Config, | ||
T::AccountId: CreateAccountId | ||
} | ||
|
||
request_outbound_transfer{ | ||
let fee: BalanceOf<T> = 10u32.into(); | ||
let remote_chains = BoundedVec::try_from(vec![1u32]).unwrap(); | ||
let parameters = BridgeConstraints { | ||
operator_account: Some(T::AccountId::create_account_id(1u32.into())), | ||
pauser_accounts: Some(vec![T::AccountId::create_account_id(2u32.into())]), | ||
bridging_fee: Some(fee), | ||
thawn_duration: None::<T::BlockNumber>, | ||
remote_chains: Some(remote_chains) | ||
}; | ||
assert_ok!(ArgoBridge::<T>::update_bridge_constrains( | ||
RawOrigin::Root.into(), | ||
parameters | ||
)); | ||
|
||
let dest_account = RemoteAccount { | ||
account: [0; 32], | ||
chain_id: 1, | ||
}; | ||
let sender = T::AccountId::create_account_id(1u32.into()); | ||
let origin = RawOrigin::Signed(sender); | ||
let transfer_id = ArgoBridge::<T>::next_transfer_id(); | ||
let amount = 100u32.into(); | ||
}: _(origin, dest_account, amount, fee) | ||
verify { | ||
let sender = T::AccountId::create_account_id(1u32.into()); | ||
assert_last_event::<T>( | ||
RawEvent::OutboundTransferRequested(transfer_id, sender, dest_account, amount, fee).into()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::Module; | ||
use frame_support::decl_error; | ||
use sp_std::convert::TryInto; | ||
|
||
decl_error! { | ||
pub enum Error for Module<T: crate::Config> { | ||
|
||
/// Bridge not on active state | ||
BridgeNotActive, | ||
|
||
/// Insufficient JOY Balance to cover the transaction costs | ||
InsufficientJoyBalance, | ||
|
||
/// The bridging_fee changed since the request transfer | ||
FeeDifferentThanExpected, | ||
|
||
/// Not enough mint allowance for transaction | ||
InsufficienBridgMintAllowance, | ||
|
||
/// Operator account required | ||
NotOperatorAccount, | ||
|
||
/// Pauser account required | ||
NotPauserAccount, | ||
|
||
/// Number of pauser accounts over the maximum allowed | ||
InvalidNumberOfPauserAccounts, | ||
|
||
/// Current block is lower than thawn_started_at + thawn_duration | ||
ThawnNotFinished, | ||
|
||
/// ChainId is not on the list of the supported chains | ||
NotSupportedRemoteChainId | ||
} | ||
} |
Oops, something went wrong.