Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
A simple token claims integration
  • Loading branch information
MOZGIII committed Aug 16, 2022
commit c68070899a2518fbd1a8068e8adb997d3bb806ef
2 changes: 2 additions & 0 deletions Cargo.lock

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

11 changes: 10 additions & 1 deletion crates/humanode-peer/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use humanode_runtime::{
opaque::SessionKeys, robonode, AccountId, BabeConfig, Balance, BalancesConfig, BioauthConfig,
BootnodesConfig, ChainPropertiesConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig,
EvmAccountsMappingConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, SessionConfig,
Signature, SudoConfig, SystemConfig, WASM_BINARY,
Signature, SudoConfig, SystemConfig, TokenClaimsConfig, WASM_BINARY,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup};
Expand Down Expand Up @@ -236,6 +236,10 @@ fn testnet_genesis(
humanode_runtime::FeesPot::account_id(),
EXISTANTIAL_DEPOSIT + DEV_ACCOUNT_BALANCE,
),
(
humanode_runtime::TokenClaimsPot::account_id(),
EXISTANTIAL_DEPOSIT,
),
];
pot_accounts
.into_iter()
Expand Down Expand Up @@ -333,6 +337,11 @@ fn testnet_genesis(
transaction_payment: Default::default(),
fees_pot: Default::default(),
treasury_pot: Default::default(),
token_claims_pot: Default::default(),
token_claims: TokenClaimsConfig {
claims: vec![],
total_claimable: Some(0),
},
}
}

Expand Down
7 changes: 6 additions & 1 deletion crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ author-ext-api = { version = "0.1", path = "../author-ext-api", default-features
bioauth-flow-api = { version = "0.1", path = "../bioauth-flow-api", default-features = false }
eip712-account-claim = { version = "0.1", path = "../eip712-account-claim", default-features = false }
eip712-common = { version = "0.1", path = "../eip712-common", default-features = false }
eip712-token-claim = { version = "0.1", path = "../eip712-token-claim", default-features = false }
frontier-api = { version = "0.1", path = "../frontier-api", default-features = false }
keystore-bioauth-account-id = { version = "0.1", path = "../keystore-bioauth-account-id", default-features = false }
pallet-bioauth = { version = "0.1", path = "../pallet-bioauth", default-features = false }
Expand All @@ -22,6 +23,7 @@ pallet-ethereum-chain-id = { version = "0.1", path = "../pallet-ethereum-chain-i
pallet-evm-accounts-mapping = { version = "0.1", path = "../pallet-evm-accounts-mapping", default-features = false }
pallet-humanode-session = { version = "0.1", path = "../pallet-humanode-session", default-features = false }
pallet-pot = { version = "0.1", path = "../pallet-pot", default-features = false }
pallet-token-claims = { version = "0.1", path = "../pallet-token-claims", default-features = false }
precompile-bioauth = { version = "0.1", path = "../precompile-bioauth", default-features = false }
precompile-evm-accounts-mapping = { version = "0.1", path = "../precompile-evm-accounts-mapping", default-features = false }
primitives-auth-ticket = { version = "0.1", path = "../primitives-auth-ticket", default-features = false }
Expand Down Expand Up @@ -94,13 +96,15 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-ethereum/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-token-claims/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"author-ext-api/std",
"bioauth-flow-api/std",
"eip712-common/std",
"eip712-account-claim/std",
"eip712-common/std",
"eip712-token-claim/std",
"keystore-bioauth-account-id/std",
"precompile-bioauth/std",
"precompile-evm-accounts-mapping/std",
Expand Down Expand Up @@ -136,6 +140,7 @@ std = [
"pallet-randomness-collective-flip/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-token-claims/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"pallet-transaction-payment-rpc-runtime-api/std",
Expand Down
30 changes: 30 additions & 0 deletions crates/humanode-runtime/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,33 @@ impl pallet_evm_accounts_mapping::SignedClaimVerifier for AccountClaimVerifier {
eip712_account_claim::verify_account_claim(signature, domain, account_id.as_ref())
}
}

/// The verifier for the EIP-712 signature of the token claim message.
pub enum TokenClaimVerifier {}

const ETHEREUM_MAINNET_CHAIN_ID: u32 = 1;

impl pallet_token_claims::traits::EthereumSignatureVerifier for TokenClaimVerifier {
type MessageParams = pallet_token_claims::types::EthereumSignatureMessageParams<AccountId>;

fn recover_signer(
signature: &EcdsaSignature,
message_params: &Self::MessageParams,
) -> Option<EthereumAddress> {
let chain_id: [u8; 32] = U256::from(ETHEREUM_MAINNET_CHAIN_ID).into();
let genesis_hash: [u8; 32] = System::block_hash(0).into();
let mut verifying_contract = [0u8; 20];
verifying_contract.copy_from_slice(&genesis_hash[0..20]);
let domain = eip712_common::Domain {
name: "Humanode Token Claim",
version: "1",
chain_id: &chain_id,
verifying_contract: &verifying_contract,
};
eip712_token_claim::verify_token_claim(
signature,
domain,
message_params.account_id.as_ref(),
)
}
}
27 changes: 27 additions & 0 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

mod frontier_precompiles;
mod vesting;
use frontier_precompiles::FrontierPrecompiles;

mod display_moment;
Expand Down Expand Up @@ -368,10 +369,12 @@ impl pallet_authorship::Config for Runtime {
parameter_types! {
pub const TreasuryPotPalletId: PalletId = PalletId(*b"hmnd/tr1");
pub const FeesPotPalletId: PalletId = PalletId(*b"hmnd/fe1");
pub const TokenClaimsPotPalletId: PalletId = PalletId(*b"hmnd/tc1");
}

type PotInstanceTreasury = pallet_pot::Instance1;
type PotInstanceFees = pallet_pot::Instance2;
type PotInstanceTokenClaims = pallet_pot::Instance3;

impl pallet_pot::Config<PotInstanceTreasury> for Runtime {
type Event = Event;
Expand All @@ -385,6 +388,12 @@ impl pallet_pot::Config<PotInstanceFees> for Runtime {
type Currency = Balances;
}

impl pallet_pot::Config<PotInstanceTokenClaims> for Runtime {
type Event = Event;
type PalletId = TokenClaimsPotPalletId;
type Currency = Balances;
}

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
type MaxReserves = ();
Expand Down Expand Up @@ -636,6 +645,20 @@ impl pallet_evm_accounts_mapping::Config for Runtime {
type Verifier = eip712::AccountClaimVerifier;
}

parameter_types! {
pub TokenClaimsPotAccountId: AccountId = TokenClaimsPot::account_id();
}

impl pallet_token_claims::Config for Runtime {
type Event = Event;
type Currency = Balances;
type PotAccountId = TokenClaimsPotAccountId;
type VestingSchedule = ();
type VestingInterface = vesting::TokenClaimsInterface;
type EthereumSignatureVerifier = eip712::TokenClaimVerifier;
type WeightInfo = ();
}

// Create the runtime by composing the FRAME pallets that were previously
// configured.
construct_runtime!(
Expand All @@ -655,6 +678,7 @@ construct_runtime!(
Balances: pallet_balances,
TreasuryPot: pallet_pot::<Instance1>,
FeesPot: pallet_pot::<Instance2>,
TokenClaimsPot: pallet_pot::<Instance3>,
TransactionPayment: pallet_transaction_payment,
Session: pallet_session,
Offences: pallet_offences,
Expand All @@ -670,6 +694,7 @@ construct_runtime!(
BaseFee: pallet_base_fee,
ImOnline: pallet_im_online,
EvmAccountsMapping: pallet_evm_accounts_mapping,
TokenClaims: pallet_token_claims,
}
);

Expand All @@ -689,6 +714,7 @@ pub type SignedExtra = (
frame_system::CheckWeight<Runtime>,
pallet_bioauth::CheckBioauthTx<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
pallet_token_claims::CheckTokenClaim<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
Expand Down Expand Up @@ -736,6 +762,7 @@ impl frame_system::offchain::CreateSignedTransaction<Call> for Runtime {
frame_system::CheckWeight::<Runtime>::new(),
pallet_bioauth::CheckBioauthTx::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
pallet_token_claims::CheckTokenClaim::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra).ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
Expand Down
9 changes: 8 additions & 1 deletion crates/humanode-runtime/src/tests/fixed_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ fn new_test_ext_with() -> sp_io::TestExternalities {
let pot_accounts = vec![TreasuryPot::account_id(), FeesPot::account_id()];
endowed_accounts
.iter()
.chain(pot_accounts.iter())
.cloned()
.chain(pot_accounts.into_iter())
.map(|k| (k, INIT_BALANCE))
.chain(
[(
TokenClaimsPot::account_id(),
<Balances as frame_support::traits::Currency<AccountId>>::minimum_balance(),
)]
.into_iter(),
)
.collect()
},
},
Expand Down
25 changes: 25 additions & 0 deletions crates/humanode-runtime/src/vesting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use frame_support::traits::{LockableCurrency, WithdrawReasons};

use super::*;

pub enum TokenClaimsInterface {}

impl pallet_token_claims::traits::VestingInterface for TokenClaimsInterface {
type AccountId = AccountId;
type Balance = Balance;
type Schedule = ();

fn lock_under_vesting(
account: &Self::AccountId,
balance_to_lock: Self::Balance,
_schedule: Self::Schedule,
) -> frame_support::pallet_prelude::DispatchResult {
<Balances as LockableCurrency<AccountId>>::set_lock(
*b"hmnd/tc1",
account,
balance_to_lock,
WithdrawReasons::RESERVE,
);
Ok(())
}
}