Skip to content

Commit

Permalink
Merge pull request #98 from galacticcouncil/feature/claims
Browse files Browse the repository at this point in the history
Claims
  • Loading branch information
jak-pan authored Mar 7, 2021
2 parents ac45b0f + 99fdd12 commit d0e89c2
Show file tree
Hide file tree
Showing 14 changed files with 6,365 additions and 10 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ targets = ['x86_64-unknown-linux-gnu']
substrate-build-script-utils = '2.0.1'

[dependencies]
hex-literal = "0.3.1"
jsonrpc-core = '15.0.0'
serde_json = "1.0.61"
structopt = '0.3.8'
Expand All @@ -33,6 +32,7 @@ primitives = {path = '../primitives', version = '2.0.0'}
frame-benchmarking = '2.0.0'
frame-benchmarking-cli = {version = '2.0.0', optional = true}
futures = '0.3.4'
hex-literal = "0.3.1"
pallet-im-online = "2.0.0"
pallet-staking = '2.0.0'
pallet-transaction-payment-rpc = '2.0.0'
Expand All @@ -53,6 +53,7 @@ sc-network = '0.8.0'
sc-rpc = '2.0.0'
sc-rpc-api = '0.8.0'
sc-service = '0.8.0'
sc-telemetry = '2.0.0'
sc-transaction-pool = '2.0.0'
sp-api = '2.0.0'
sp-authority-discovery = '2.0.0'
Expand All @@ -66,7 +67,6 @@ sp-inherents = '2.0.0'
sp-keystore = '0.8.0'
sp-runtime = '2.0.0'
sp-transaction-pool = '2.0.0'
sc-telemetry = '2.0.0'
substrate-frame-rpc-system = '2.0.0'

[features]
Expand Down
51 changes: 47 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(clippy::or_fun_call)]

use hex_literal::hex;
use hydra_dx_runtime::constants::currency::{Balance, DOLLARS};
use hydra_dx_runtime::constants::currency::{Balance, DOLLARS, HDX};
use hydra_dx_runtime::opaque::SessionKeys;
use hydra_dx_runtime::pallet_claims::EthereumAddress;
use hydra_dx_runtime::{
AccountId, AssetRegistryConfig, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, CouncilConfig,
AccountId, AssetRegistryConfig, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ClaimsConfig, CouncilConfig,
ElectionsConfig, FaucetConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, Perbill, SessionConfig, Signature,
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TokensConfig, CORE_ASSET_ID, WASM_BINARY,
};
Expand All @@ -16,10 +16,10 @@ use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};

use hex_literal::hex;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;

// The URL for the telemetry server.
const TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

Expand Down Expand Up @@ -367,6 +367,9 @@ fn testnet_genesis(
}),
pallet_elections_phragmen: Some(ElectionsConfig { members: vec![] }),
pallet_collective_Instance1: Some(CouncilConfig::default()),
pallet_claims: Some(ClaimsConfig {
claims: create_testnet_claims(),
}),
}
}

Expand Down Expand Up @@ -468,5 +471,45 @@ fn lerna_genesis(
}),
pallet_elections_phragmen: Some(ElectionsConfig { members: vec![] }),
pallet_collective_Instance1: Some(CouncilConfig::default()),
pallet_claims: Some(ClaimsConfig { claims: vec![] }),
}
}

fn create_testnet_claims() -> Vec<(EthereumAddress, Balance)> {
let mut claims = Vec::<(EthereumAddress, Balance)>::new();

// Alice's claim
// Signature: 0xbcae7d4f96f71cf974c173ae936a1a79083af7f76232efbf8a568b7f990eceed73c2465bba769de959b7f6ac5690162b61eb90949901464d0fa158a83022a0741c
// Message: "I hereby claim all my HDX tokens to wallet:d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"
let claim_address_1 = (
// Test seed: "image stomach entry drink rice hen abstract moment nature broken gadget flash"
// private key (m/44'/60'/0'/0/0) : 0xdd75dd5f4a9e964d1c4cc929768947859a98ae2c08100744878a4b6b6d853cc0
EthereumAddress(hex!["8202C0aF5962B750123CE1A9B12e1C30A4973557"]),
HDX / 1_000,
);

// Bob's claim
// Signature: 0x60f3d2541b0ff09982f70844a7f645f4681cbbad2f138fee18404c932bd02cb738d577d53ce94cf067bae87a0b6fa1ec532ceea78d71f4e81a9c27193649c6291b
// Message: "I hereby claim all my HDX tokens to wallet:8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"
let claim_address_2 = (
// Test seed: "image stomach entry drink rice hen abstract moment nature broken gadget flash"
// private key (m/44'/60'/0'/0/1) : 0x9b5ef380c0a59008df32ba71ab3c7645950f986fc3f43fd4f9dffc8b2b4e7a5d
EthereumAddress(hex!["8aF7764663644989671A71Abe9738a3cF295f384"]),
HDX,
);

// Charlie's claim
// Signature: 0x52485aece74eb503fb998f0ca08bcc283fa731613db213af4e7fe153faed3de97ea0873d3889622b41d2d989a9e2a0bef160cff1ba8845875d4bc15431136a811c
// Message: "I hereby claim all my HDX tokens to wallet:90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22"
let claim_address_3 = (
// Test seed: "image stomach entry drink rice hen abstract moment nature broken gadget flash"
// private key (m/44'/60'/0'/0/2) : 0x653a29ac0c93de0e9f7d7ea2d60338e68f407b18d16d6ff84db996076424f8fa
EthereumAddress(hex!["C19A2970A13ac19898c47d59Cbd0278D428EBC7c"]),
1_000 * HDX,
);

claims.push(claim_address_1);
claims.push(claim_address_2);
claims.push(claim_address_3);
claims
}
65 changes: 65 additions & 0 deletions pallets/claims/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[package]
authors = ['GalacticCouncil']
description = 'HydraDX Claims Module'
edition = '2018'
homepage = 'https://github.com/galacticcouncil/hack.hydradx-node'
license = 'Unlicense'
name = 'pallet-claims'
repository = 'https://github.com/galacticcouncil/hack.hydradx-node'
version = '2.0.0'

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

# alias "parity-scale-code" to "codec"
[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '1.3.4'

[dependencies]
# Substrate dependencies
frame-support = { default-features = false, version = '2.0.0' }
frame-system = { default-features = false, version = '2.0.0' }
frame-benchmarking = { version = "2.0.0", default-features = false, optional = true }
rustc-hex = { version = '2.1.0', default-features = false }
serde = { optional = true, version = '1.0.101', features = ['derive'] }
sp-io = { default-features = false, version = '2.0.0' }
sp-runtime = { default-features = false, version = '2.0.0' }
sp-std = { default-features = false, version = '2.0.0' }
hex = {default-features = false, version = "0.4.2"}
hex-literal = '0.3.1'
lazy_static = {features = ['spin_no_std'], version = "1.4.0"}

# Local dependencies
primitives = {path = '../../primitives', default-features = false, version = '2.0.0'}

# ORML dependencies
orml-traits = { default-features = false, version = '0.3.3-dev' }
orml-tokens = { default-features = false, version = '0.3.3-dev' }
orml-utilities = { default-features = false, version = '0.3.3-dev' }

[dev-dependencies]
sp-core = { default-features = false, version = '2.0.0' }
hex-literal = '0.3.1'
pallet-balances = { version = "2.0.0" }

[features]
default = ['std']
std = [
'codec/std',
'frame-support/std',
'frame-system/std',
'orml-traits/std',
'orml-tokens/std',
'orml-utilities/std',
'primitives/std',
'rustc-hex/std',
'serde/std',
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
37 changes: 37 additions & 0 deletions pallets/claims/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;

use codec::Decode;
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use hex_literal::hex;

benchmarks! {
_ {}

claim {
let alice_id = hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"];
let caller = T::AccountId::decode(&mut &alice_id[..]).unwrap_or_default();
let eth_address = EthereumAddress(hex!["8202c0af5962b750123ce1a9b12e1c30a4973557"]);
let signature = hex!["ef9816023122208983c11e596446874df3d400d2f9e380a831206d0e91bfb96d54db352fbd62d3cfa8d8674cf63e6a32052ef3cab038e1e7398eac3d048ed5181c"];
Claims::<T>::insert(eth_address, 1_000_000_000_000_000_000);
}: _(RawOrigin::Signed(caller.clone()), EcdsaSignature(signature))
verify {
assert_eq!(T::Currency::free_balance(0, &caller), 2_152_921_504_606_846_976);
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::tests::{new_test_ext, Test};
use frame_support::assert_ok;

#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_claim::<Test>());
});
}
}
Loading

0 comments on commit d0e89c2

Please sign in to comment.