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

RING DAO part.1 #1543

Merged
merged 24 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
23 changes: 9 additions & 14 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ version = "6.6.3"
# crates.io
array-bytes = { version = "6.2" }
codec = { package = "parity-scale-codec", version = "3.6", default-features = false }
ethabi = { version = "18.0", default-features = false }
ethereum = { version = "0.15", default-features = false, features = ["with-codec"] }
libsecp256k1 = { version = "0.7", default-features = false }
log = { version = "0.4" }
Expand Down
2 changes: 1 addition & 1 deletion node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ where
network_provider: network.clone(),
is_validator: config.role.is_authority(),
enable_http_requests: false,
custom_extensions: move |_| vec![],
custom_extensions: move |_| Vec::new(),
})
.run(client.clone(), task_manager.spawn_handle())
.boxed(),
Expand Down
12 changes: 0 additions & 12 deletions pallet/account-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ codec = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true }

# darwinia
darwinia-deposit = { workspace = true }
darwinia-staking = { workspace = true }
dc-primitives = { workspace = true }

# polkadot-sdk
Expand Down Expand Up @@ -42,8 +40,6 @@ std = [
"scale-info/std",

# darwinia
"darwinia-deposit/std",
"darwinia-staking/std",
"dc-primitives/std",

# polkadot-sdk
Expand All @@ -60,10 +56,6 @@ std = [
]

runtime-benchmarks = [
# darwinia
"darwinia-deposit/runtime-benchmarks",
"darwinia-staking/runtime-benchmarks",

# polkadot-sdk
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
Expand All @@ -74,10 +66,6 @@ runtime-benchmarks = [
]

try-runtime = [
# darwinia
"darwinia-deposit/try-runtime",
"darwinia-staking/try-runtime",

# polkadot-sdk
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand Down
32 changes: 0 additions & 32 deletions pallet/account-migration/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,6 @@ mod benchmarks {
extra: Default::default(),
},
);
<Deposits<T>>::insert(
from,
vec![
Deposit {
id: Default::default(),
value: 1,
start_time: Default::default(),
expired_time: Default::default(),
in_use: Default::default(),
};
<T as darwinia_deposit::Config>::MaxDeposits::get() as usize
],
);
<Ledgers<T>>::insert(
from,
OldLedger {
staked_ring: 1,
staked_deposits: BoundedVec::truncate_from(vec![
Default::default();
<T as darwinia_deposit::Config>::MaxDeposits::get()
as usize
]),
unstaking_ring: BoundedVec::truncate_from(vec![
(
Default::default(),
Default::default()
);
16
]),
..Default::default()
},
);
}

#[benchmark]
Expand Down
58 changes: 5 additions & 53 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@ mod weights;
pub use weights::WeightInfo;

// darwinia
use darwinia_deposit::Deposit;
use darwinia_staking::{migration::v2::OldLedger, Ledger};
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, Nonce};
// polkadot-sdk
use frame_support::{
migration,
pallet_prelude::*,
traits::{Currency, ExistenceRequirement::AllowDeath},
StorageHasher,
};
use frame_support::{migration, pallet_prelude::*, StorageHasher};
use frame_system::{pallet_prelude::*, AccountInfo};
use pallet_balances::AccountData;
use sp_core::{
Expand Down Expand Up @@ -107,8 +100,6 @@ pub mod pallet {
Lookup = IdentityLookup<AccountId20>,
> + pallet_assets::Config<Balance = Balance, AssetId = AssetId>
+ pallet_balances::Config<Balance = Balance>
+ darwinia_deposit::Config
+ darwinia_staking::Config
{
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -152,17 +143,6 @@ pub mod pallet {
#[pallet::getter(fn kton_account_of)]
pub type KtonAccounts<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, AssetAccount>;

/// [`darwinia_deposit::Deposits`] data.
#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn deposit_of)]
pub type Deposits<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, Vec<Deposit>>;

/// [`darwinia_staking::migration::v2::OldLedger`] data.
#[pallet::storage]
#[pallet::getter(fn ledger_of)]
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, OldLedger<T>>;

/// Multisig migration caches.
#[pallet::storage]
#[pallet::unbounded]
Expand Down Expand Up @@ -418,34 +398,6 @@ pub mod pallet {
);
}
}
if let Some(l) = <Ledgers<T>>::take(from) {
if l.staked_ring > 0 {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_staking::account_id(),
l.staked_ring,
AllowDeath,
)?;
}

if let Some(ds) = <Deposits<T>>::take(from) {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_deposit::account_id(),
ds.iter().map(|d| d.value).sum(),
AllowDeath,
)?;
<darwinia_deposit::Deposits<T>>::insert(
to,
BoundedVec::try_from(ds).map_err(|_| <Error<T>>::ExceedMaxDeposits)?,
);
}

<darwinia_staking::Ledgers<T>>::insert(
to,
Ledger { ring: l.staked_ring, deposits: l.staked_deposits },
);
}

Ok(())
}
Expand All @@ -459,15 +411,15 @@ pub(crate) type Signature = [u8; 64];
// Copy from <https://github.dev/paritytech/substrate/blob/polkadot-v0.9.30/frame/assets/src/types.rs#L115>.
// Due to its visibility.
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub struct AssetAccount {
balance: Balance,
is_frozen: bool,
reason: ExistenceReason,
extra: (),
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) enum ExistenceReason {
#[codec(index = 0)]
Consumer,
Expand All @@ -479,7 +431,7 @@ pub(crate) enum ExistenceReason {
DepositRefunded,
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) struct AssetDetails {
owner: AccountId20,
issuer: AccountId20,
Expand All @@ -495,7 +447,7 @@ pub(crate) struct AssetDetails {
status: AssetStatus,
}
#[allow(missing_docs)]
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub(crate) enum AssetStatus {
Live,
Frozen,
Expand Down
58 changes: 0 additions & 58 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ use frame_support::derive_impl;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub struct Dummy;
impl darwinia_deposit::SimpleAsset for Dummy {
type AccountId = AccountId;

fn mint(_: &Self::AccountId, _: Balance) -> sp_runtime::DispatchResult {
Ok(())
}

fn burn(_: &Self::AccountId, _: Balance) -> sp_runtime::DispatchResult {
Ok(())
}
}
impl darwinia_staking::Stake for Dummy {
type AccountId = AccountId;
type Item = Balance;

fn stake(_: &Self::AccountId, _: Self::Item) -> sp_runtime::DispatchResult {
Ok(())
}

fn unstake(_: &Self::AccountId, _: Self::Item) -> sp_runtime::DispatchResult {
Ok(())
}
}

#[sp_version::runtime_version]
pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion {
spec_name: sp_runtime::create_runtime_str!("Darwinia2"),
Expand Down Expand Up @@ -117,37 +92,6 @@ impl pallet_assets::Config for Runtime {
type WeightInfo = ();
}

frame_support::parameter_types! {
pub UnvestedFundsAllowedWithdrawReasons: frame_support::traits::WithdrawReasons =
frame_support::traits::WithdrawReasons::except(
frame_support::traits::WithdrawReasons::TRANSFER | frame_support::traits::WithdrawReasons::RESERVE
);
}

impl darwinia_deposit::Config for Runtime {
type Kton = Dummy;
type MaxDeposits = ();
type MinLockingAmount = ();
type Ring = Balances;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

impl darwinia_staking::Config for Runtime {
type Currency = Balances;
type Deposit = Deposit;
type IssuingManager = ();
type Kton = Dummy;
type KtonStakerNotifier = ();
type MaxDeposits = ();
type Ring = Dummy;
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = ();
type WeightInfo = ();
}
#[cfg(not(feature = "runtime-benchmarks"))]
impl darwinia_staking::DepositConfig for Runtime {}

impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand All @@ -159,8 +103,6 @@ frame_support::construct_runtime! {
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Assets: pallet_assets,
Deposit: darwinia_deposit,
Staking: darwinia_staking,
AccountMigration: darwinia_account_migration,
}
}
Expand Down
Loading
Loading