From c5a6c1ba20a4b6f02b91fc66178ff041ae30999e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Molina?= Date: Fri, 18 Aug 2023 15:19:34 +0200 Subject: [PATCH] feat: upgrade to polkadot-v1.0.0 --- Cargo.toml | 22 ++++++++--------- rpc/Cargo.toml | 12 +++++----- rpc/runtime-api/Cargo.toml | 8 +++---- rpc/runtime-api/src/lib.rs | 2 +- rpc/src/lib.rs | 2 +- src/benchmarking.rs | 8 ++++--- src/lib.rs | 48 +++++++++++++++++++------------------- src/mock.rs | 42 ++++++++++++++------------------- src/rpc.rs | 2 +- 9 files changed, 71 insertions(+), 75 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0cd4a79..85464fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,26 +11,26 @@ repository = "https://github.com/paritytech/substrate-dex" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +parity-scale-codec = { version = "3.6.4", default-features = false, features = ["derive"] } -frame-benchmarking = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42", optional = true } -frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -frame-system = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +frame-benchmarking = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", optional = true } +frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +frame-system = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } -pallet-assets = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +pallet-assets = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-std = { default-features = false, version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +sp-runtime = { default-features = false, version = "24.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-std = { default-features = false, version = "8.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-io = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-core = { default-features = false, version = "21.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-io = { default-features = false, version = "23.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } [features] default = ["std"] std = [ - "codec/std", + "parity-scale-codec/std", "scale-info/std", "sp-std/std", "frame-benchmarking/std", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 32d0829..9f0df50 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -11,17 +11,17 @@ repository = "https://github.com/paritytech/substrate-dex" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server", "macros"] } +parity-scale-codec = { version = "3.6.4", default-features = false, features = ["derive"] } pallet-dex-rpc-runtime-api = { version = "0.0.1", path = "./runtime-api" } -sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-blockchain = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-blockchain = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-runtime = { default-features = false, version = "24.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } [dev-dependencies] pallet-dex = { version = "0.0.1", path = ".." } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" } -substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } tokio = { version = "1.21.2", features = ["macros", "time", "parking_lot"] } diff --git a/rpc/runtime-api/Cargo.toml b/rpc/runtime-api/Cargo.toml index 58fd733..94ab1de 100644 --- a/rpc/runtime-api/Cargo.toml +++ b/rpc/runtime-api/Cargo.toml @@ -11,16 +11,16 @@ repository = "https://github.com/paritytech/substrate-dex" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +parity-scale-codec = { version = "3.6.4", default-features = false, features = ["derive"] } pallet-dex = { version = "0.0.1", default-features = false, path = "../.." } -sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } +sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-runtime = { default-features = false, version = "24.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } [features] default = ["std"] std = [ - "codec/std", + "parity-scale-codec/std", "pallet-dex/std", "sp-api/std", "sp-runtime/std", diff --git a/rpc/runtime-api/src/lib.rs b/rpc/runtime-api/src/lib.rs index e4b98e1..d348382 100644 --- a/rpc/runtime-api/src/lib.rs +++ b/rpc/runtime-api/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::Codec; pub use pallet_dex::rpc::{RpcError, RpcResult}; +use parity_scale_codec::Codec; use sp_runtime::traits::MaybeDisplay; sp_api::decl_runtime_apis! { diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index da6056d..d21cc4c 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -1,9 +1,9 @@ -use codec::Codec; use jsonrpsee::{ core::{async_trait, Error as RpcError, RpcResult}, proc_macros::rpc, types::error::{CallError, ErrorObject}, }; +use parity_scale_codec::Codec; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::MaybeDisplay; diff --git a/src/benchmarking.rs b/src/benchmarking.rs index 0d04e19..a663864 100644 --- a/src/benchmarking.rs +++ b/src/benchmarking.rs @@ -1,12 +1,14 @@ -use crate::{AccountIdOf, Call, Config, Pallet, TradeAmount}; use frame_benchmarking::{benchmarks, whitelisted_caller}; use frame_support::pallet_prelude::DispatchResult; use frame_support::traits::{ fungibles::{Create, Mutate}, Currency, }; +use frame_system::mocking::MockBlock; use frame_system::RawOrigin; +use crate::{AccountIdOf, Call, Config, Pallet, TradeAmount}; + const INIT_BALANCE: u128 = 1_000_000_000_000_000; const INIT_LIQUIDITY: u128 = 1_000_000_000_000; const ASSET_A: u32 = 1; @@ -16,7 +18,7 @@ const LIQ_TOKEN_B: u32 = 12; fn prepare_exchange(asset_id: u32, liquidity_token_id: u32) -> DispatchResult where - T: frame_system::Config, + T: frame_system::Config>, T: Config, T::Currency: Currency, Balance = u128>, T::Assets: Create> + Mutate>, @@ -38,7 +40,7 @@ where benchmarks! { where_clause { where - T: frame_system::Config, + T: frame_system::Config>, T: Config, T::Currency: Currency, Balance = u128>, T::Assets: Create> + Mutate>, diff --git a/src/lib.rs b/src/lib.rs index 804a378..bde9dfe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,13 @@ use sp_std::prelude::*; pub use pallet::*; pub use weights::WeightInfo; +use sp_runtime::{ + traits::{ + AccountIdConversion, CheckedAdd, CheckedMul, CheckedSub, Convert, One, Saturating, Zero, + }, + FixedPointNumber, FixedPointOperand, FixedU128, +}; + type AccountIdOf = ::AccountId; type BalanceOf = <::Currency as Currency>>::Balance; type AssetIdOf = ::AssetId; @@ -35,16 +42,10 @@ type AssetBalanceOf = ::AssetBalance; #[frame_support::pallet] pub mod pallet { use super::*; - use codec::EncodeLike; + use parity_scale_codec::EncodeLike; + use frame_support::{ pallet_prelude::*, - sp_runtime::{ - traits::{ - AccountIdConversion, CheckedAdd, CheckedMul, CheckedSub, Convert, One, Saturating, - Zero, - }, - FixedPointNumber, FixedPointOperand, FixedU128, - }, traits::{ fungibles::{Create, Destroy, Inspect, Mutate}, tokens::{Balance, Fortitude, Precision, Preservation, WithdrawConsequence}, @@ -156,7 +157,6 @@ pub mod pallet { pub exchanges: Vec>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> GenesisConfig { GenesisConfig { exchanges: vec![] } @@ -164,7 +164,7 @@ pub mod pallet { } #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { let pallet_account = T::pallet_account(); for (provider, asset_id, liquidity_token_id, currency_amount, token_amount) in @@ -221,7 +221,7 @@ pub mod pallet { T::AssetRegistry::mint_into( liquidity_token_id.clone(), provider, - liquidity_minted + liquidity_minted, ) .is_ok(), "Unexpected error while minting liquidity tokens for Provider" @@ -238,7 +238,7 @@ pub mod pallet { } #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[pallet::generate_deposit(pub (super) fn deposit_event)] pub enum Event { /// A new exchange was created [asset_id, liquidity_token_id] ExchangeCreated(AssetIdOf, AssetIdOf), @@ -390,7 +390,7 @@ pub mod pallet { /// * `CurrencyAmountTooLow` – Specified `currency_amount` is lower than `MinDeposit`. /// * `TokenAmountIsZero` – Specified `token_amount` equals 0. #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::create_exchange())] + #[pallet::weight(< T as Config >::WeightInfo::create_exchange())] #[transactional] pub fn create_exchange( origin: OriginFor, @@ -465,14 +465,14 @@ pub mod pallet { /// * `MinLiquidityTooHigh` – The amount of liquidity tokes which would be minted by depositing the specified /// `currency_amount` is lower than the specified `min_liquidity`. #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::add_liquidity())] + #[pallet::weight(< T as Config >::WeightInfo::add_liquidity())] pub fn add_liquidity( origin: OriginFor, asset_id: AssetIdOf, currency_amount: BalanceOf, min_liquidity: AssetBalanceOf, max_tokens: AssetBalanceOf, - deadline: T::BlockNumber, + deadline: BlockNumberFor, ) -> DispatchResult { // -------------------------- Validation part -------------------------- let caller = ensure_signed(origin)?; @@ -534,14 +534,14 @@ pub mod pallet { /// * `MinTokensTooHigh` – The amount of tokens which could be received in exchange for the specified /// `liquidity_amount` is lower than the specified `min_tokens`. #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::remove_liquidity())] + #[pallet::weight(< T as Config >::WeightInfo::remove_liquidity())] pub fn remove_liquidity( origin: OriginFor, asset_id: AssetIdOf, liquidity_amount: AssetBalanceOf, min_currency: BalanceOf, min_tokens: AssetBalanceOf, - deadline: T::BlockNumber, + deadline: BlockNumberFor, ) -> DispatchResult { // -------------------------- Validation part -------------------------- let caller = ensure_signed(origin)?; @@ -601,12 +601,12 @@ pub mod pallet { /// * `BalanceTooLow` – The available currency balance of the caller account is not enough to perform the trade. /// * `Overflow` – An overflow occurred during price computation. #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::currency_to_asset())] + #[pallet::weight(< T as Config >::WeightInfo::currency_to_asset())] pub fn currency_to_asset( origin: OriginFor, asset_id: AssetIdOf, amount: TradeAmount, AssetBalanceOf>, - deadline: T::BlockNumber, + deadline: BlockNumberFor, recipient: Option>, ) -> DispatchResult { // -------------------------- Validation part -------------------------- @@ -657,12 +657,12 @@ pub mod pallet { /// * `NotEnoughTokens` – The available asset balance of the caller account is not enough to perform the trade. /// * `Overflow` – An overflow occurred during price computation. #[pallet::call_index(4)] - #[pallet::weight(::WeightInfo::asset_to_currency())] + #[pallet::weight(< T as Config >::WeightInfo::asset_to_currency())] pub fn asset_to_currency( origin: OriginFor, asset_id: AssetIdOf, amount: TradeAmount, BalanceOf>, - deadline: T::BlockNumber, + deadline: BlockNumberFor, recipient: Option>, ) -> DispatchResult { // -------------------------- Validation part -------------------------- @@ -712,13 +712,13 @@ pub mod pallet { /// * `NotEnoughTokens` – The available sold asset balance of the caller account is not enough to perform the trade. /// * `Overflow` – An overflow occurred during price computation. #[pallet::call_index(5)] - #[pallet::weight(::WeightInfo::asset_to_asset())] + #[pallet::weight(< T as Config >::WeightInfo::asset_to_asset())] pub fn asset_to_asset( origin: OriginFor, sold_asset_id: AssetIdOf, bought_asset_id: AssetIdOf, amount: TradeAmount, AssetBalanceOf>, - deadline: T::BlockNumber, + deadline: BlockNumberFor, recipient: Option>, ) -> DispatchResult { // -------------------------- Validation part -------------------------- @@ -756,7 +756,7 @@ pub mod pallet { >::get(asset_id.clone()).ok_or(Error::::ExchangeNotFound) } - fn check_deadline(deadline: &T::BlockNumber) -> Result<(), Error> { + fn check_deadline(deadline: &BlockNumberFor) -> Result<(), Error> { ensure!(deadline >= &>::block_number(), Error::DeadlinePassed); Ok(()) } diff --git a/src/mock.rs b/src/mock.rs index 482fdfd..153b4d3 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -1,23 +1,18 @@ use crate as dex; use frame_support::traits::{ - AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Everything, GenesisBuild, + AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Everything, }; use frame_support::{parameter_types, PalletId}; use frame_system::{EnsureRoot, EnsureSigned}; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Identity, IdentityLookup}; +use sp_runtime::BuildStorage; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; -type Header = sp_runtime::generic::Header; frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + pub struct Test { + System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Assets: pallet_assets::{Pallet, Call, Storage, Config, Event}, Dex: dex::{Pallet, Call, Storage, Event}, @@ -25,20 +20,19 @@ frame_support::construct_runtime!( ); impl frame_system::Config for Test { + type RuntimeEvent = RuntimeEvent; type BaseCallFilter = Everything; type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type Index = u32; - type BlockNumber = u32; + type Nonce = u32; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU32<250>; + type Block = Block; + type BlockHashCount = ConstU64<250>; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; @@ -52,24 +46,25 @@ impl frame_system::Config for Test { } impl pallet_balances::Config for Test { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type Balance = u128; type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); type FreezeIdentifier = (); - type MaxFreezes = (); - type HoldIdentifier = (); + type MaxLocks = (); + type MaxReserves = (); type MaxHolds = (); + type MaxFreezes = (); } impl pallet_assets::Config for Test { type RuntimeEvent = RuntimeEvent; type Balance = u128; + type RemoveItemsLimit = ConstU32<5>; type AssetId = u32; type AssetIdParameter = u32; type Currency = Balances; @@ -83,9 +78,8 @@ impl pallet_assets::Config for Test { type StringLimit = ConstU32<50>; type Freezer = (); type Extra = (); - type WeightInfo = (); - type RemoveItemsLimit = ConstU32<5>; type CallbackHandle = (); + type WeightInfo = (); } parameter_types! { @@ -121,8 +115,8 @@ pub(crate) const LIQ_TOKEN_A: u32 = 200; pub(crate) const LIQ_TOKEN_B: u32 = 201; pub(crate) fn new_test_ext() -> sp_io::TestExternalities { - let mut storage = frame_system::GenesisConfig::default() - .build_storage::() + let mut storage = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); pallet_balances::GenesisConfig:: { diff --git a/src/rpc.rs b/src/rpc.rs index bd31380..cc5f925 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -1,5 +1,5 @@ use crate::{AssetBalanceOf, AssetIdOf, BalanceOf, Config, ConfigHelper, Error, Pallet}; -use codec::{Decode, Encode}; +use parity_scale_codec::{Decode, Encode}; use scale_info::prelude::format; use sp_std::fmt::Debug; use sp_std::vec::Vec;