diff --git a/evm-precompiles/erc1155/src/lib.rs b/evm-precompiles/erc1155/src/lib.rs index b6f424ec3..946989073 100644 --- a/evm-precompiles/erc1155/src/lib.rs +++ b/evm-precompiles/erc1155/src/lib.rs @@ -322,7 +322,7 @@ where let operator: Runtime::AccountId = H160::from(operator).into(); handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_approved = pallet_token_approvals::Pallet::::erc1155_approvals_for_all( + let is_approved = pallet_token_approvals::ERC1155ApprovalsForAll::::get( owner, (collection_id, operator), ) @@ -582,7 +582,7 @@ where // Check approvals if from != handle.context().caller { handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_approved = pallet_token_approvals::Pallet::::erc1155_approvals_for_all( + let is_approved = pallet_token_approvals::ERC1155ApprovalsForAll::::get( Runtime::AccountId::from(from), (collection_id, Runtime::AccountId::from(handle.context().caller)), ) @@ -629,7 +629,7 @@ where // Check approvals if operator != handle.context().caller { handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_approved = pallet_token_approvals::Pallet::::erc1155_approvals_for_all( + let is_approved = pallet_token_approvals::ERC1155ApprovalsForAll::::get( Runtime::AccountId::from(operator), (collection_id, Runtime::AccountId::from(handle.context().caller)), ) @@ -697,7 +697,7 @@ where // Check approvals if operator != handle.context().caller { handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_approved = pallet_token_approvals::Pallet::::erc1155_approvals_for_all( + let is_approved = pallet_token_approvals::ERC1155ApprovalsForAll::::get( Runtime::AccountId::from(operator), (collection_id, Runtime::AccountId::from(handle.context().caller)), ) diff --git a/evm-precompiles/erc20/src/lib.rs b/evm-precompiles/erc20/src/lib.rs index 59d95714e..444339957 100644 --- a/evm-precompiles/erc20/src/lib.rs +++ b/evm-precompiles/erc20/src/lib.rs @@ -217,12 +217,10 @@ where let spender: Runtime::AccountId = H160::from(spender).into(); // Fetch info. - let amount: U256 = pallet_token_approvals::Pallet::::erc20_approvals( - (&owner, &asset_id), - &spender, - ) - .unwrap_or_default() - .into(); + let amount: U256 = + pallet_token_approvals::ERC20Approvals::::get((&owner, &asset_id), &spender) + .unwrap_or_default() + .into(); // Build output. Ok(succeed(EvmDataWriter::new().write(amount).build())) diff --git a/evm-precompiles/erc721/src/lib.rs b/evm-precompiles/erc721/src/lib.rs index 967c87297..c59c23795 100644 --- a/evm-precompiles/erc721/src/lib.rs +++ b/evm-precompiles/erc721/src/lib.rs @@ -581,14 +581,12 @@ where // Return either the approved account or zero address if no account is approved handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let approved_account: H160 = - match pallet_token_approvals::Pallet::::erc721_approvals(( - collection_id, - serial_number, - )) { - Some(approved_account) => (approved_account).into(), - None => H160::default(), - }; + let approved_account: H160 = match pallet_token_approvals::ERC721Approvals::::get( + (collection_id, serial_number), + ) { + Some(approved_account) => (approved_account).into(), + None => H160::default(), + }; Ok(succeed(EvmDataWriter::new().write(Address::from(approved_account)).build())) } @@ -605,7 +603,7 @@ where let operator: Runtime::AccountId = H160::from(operator).into(); handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_approved = pallet_token_approvals::Pallet::::erc721_approvals_for_all( + let is_approved = pallet_token_approvals::ERC721ApprovalsForAll::::get( owner, (collection_id, operator), ) diff --git a/pallet/dex/src/lib.rs b/pallet/dex/src/lib.rs index e8f77737c..1beace30e 100644 --- a/pallet/dex/src/lib.rs +++ b/pallet/dex/src/lib.rs @@ -224,25 +224,20 @@ pub mod pallet { /// FeeTo account where network fees are deposited #[pallet::storage] - #[pallet::getter(fn fee_to)] pub type FeeTo = StorageValue<_, Option, ValueQuery, DefaultFeeTo>; #[pallet::storage] - #[pallet::getter(fn lp_token_id)] pub type TradingPairLPToken = StorageMap<_, Twox64Concat, TradingPair, Option, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn liquidity_pool)] pub type LiquidityPool = StorageMap<_, Twox64Concat, TradingPair, (Balance, Balance), ValueQuery>; #[pallet::storage] - #[pallet::getter(fn liquidity_pool_last_k)] pub type LiquidityPoolLastK = StorageMap<_, Twox64Concat, AssetId, U256, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn trading_pair_statuses)] pub type TradingPairStatuses = StorageMap<_, Twox64Concat, TradingPair, TradingPairStatus, ValueQuery>; @@ -466,11 +461,11 @@ pub mod pallet { let trading_pair = TradingPair::new(token_a, token_b); ensure!( - Self::lp_token_id(&trading_pair).is_some(), + TradingPairLPToken::::get(&trading_pair).is_some(), Error::::LiquidityProviderTokenNotCreated ); - match Self::trading_pair_statuses(&trading_pair) { + match TradingPairStatuses::::get(&trading_pair) { TradingPairStatus::Enabled => return Err(Error::::MustBeNotEnabled.into()), // will enabled Disabled trading_pair TradingPairStatus::NotEnabled => { @@ -500,11 +495,11 @@ pub mod pallet { let trading_pair = TradingPair::new(token_a, token_b); ensure!( - Self::lp_token_id(&trading_pair).is_some(), + TradingPairLPToken::::get(&trading_pair).is_some(), Error::::LiquidityProviderTokenNotCreated ); - match Self::trading_pair_statuses(&trading_pair) { + match TradingPairStatuses::::get(&trading_pair) { // will disable Enabled trading_pair TradingPairStatus::Enabled => { TradingPairStatuses::::insert(trading_pair, TradingPairStatus::NotEnabled); @@ -602,13 +597,13 @@ where let trading_pair = TradingPair::new(token_a, token_b); // create trading pair & lp token if non-existent - let lp_share_asset_id = match Self::lp_token_id(trading_pair) { + let lp_share_asset_id = match TradingPairLPToken::::get(trading_pair) { Some(lp_id) => lp_id, None => Self::create_lp_token(&trading_pair)?, }; ensure!( - matches!(Self::trading_pair_statuses(&trading_pair), TradingPairStatus::Enabled), + matches!(TradingPairStatuses::::get(&trading_pair), TradingPairStatus::Enabled), Error::::MustBeEnabled, ); @@ -769,7 +764,7 @@ where let trading_pair = TradingPair::new(token_a, token_b); let lp_share_asset_id = - Self::lp_token_id(trading_pair).ok_or(Error::::InvalidAssetId)?; + TradingPairLPToken::::get(trading_pair).ok_or(Error::::InvalidAssetId)?; ensure!(token_a != token_b, Error::::IdenticalTokenAddress); @@ -876,12 +871,12 @@ where token_b: AssetId, ) -> sp_std::result::Result { let trading_pair = TradingPair::new(token_a, token_b); - Self::lp_token_id(trading_pair).ok_or(Error::::InvalidAssetId.into()) + TradingPairLPToken::::get(trading_pair).ok_or(Error::::InvalidAssetId.into()) } pub fn get_liquidity(token_a: AssetId, token_b: AssetId) -> (Balance, Balance) { let trading_pair = TradingPair::new(token_a, token_b); - let (reserve_0, reserve_1) = Self::liquidity_pool(trading_pair); + let (reserve_0, reserve_1) = LiquidityPool::::get(trading_pair); if token_a == trading_pair.0 { (reserve_0, reserve_1) } else { @@ -891,7 +886,7 @@ where pub fn get_trading_pair_status(token_a: AssetId, token_b: AssetId) -> TradingPairStatus { let trading_pair = TradingPair::new(token_a, token_b); - Self::trading_pair_statuses(trading_pair) + TradingPairStatuses::::get(trading_pair) } /// Given an input amount of an asset and pair reserves, returns the maximum output amount of @@ -965,7 +960,7 @@ where // trading pair in path must be enabled ensure!( matches!( - Self::trading_pair_statuses(&TradingPair::new(path[i], path[i + 1])), + TradingPairStatuses::::get(&TradingPair::new(path[i], path[i + 1])), TradingPairStatus::Enabled ), Error::::MustBeEnabled @@ -1006,7 +1001,7 @@ where // trading pair in path must be enabled ensure!( matches!( - Self::trading_pair_statuses(&TradingPair::new(path[i - 1], path[i])), + TradingPairStatuses::::get(&TradingPair::new(path[i - 1], path[i])), TradingPairStatus::Enabled ), Error::::MustBeEnabled @@ -1160,7 +1155,7 @@ where if FeeTo::::get().is_some() { // get the lp shared asset id let lp_share_asset_id = - Self::lp_token_id(trading_pair).ok_or(Error::::InvalidAssetId)?; + TradingPairLPToken::::get(trading_pair).ok_or(Error::::InvalidAssetId)?; // get the updated reserve values of the trading pair let (reserve_a, reserve_b) = LiquidityPool::::get(trading_pair); diff --git a/pallet/dex/src/tests.rs b/pallet/dex/src/tests.rs index 4f87ebf44..0eec785ea 100644 --- a/pallet/dex/src/tests.rs +++ b/pallet/dex/src/tests.rs @@ -65,7 +65,7 @@ fn disable_trading_pair() { TradingPair::new(usdc, weth), ))); assert_eq!( - Dex::trading_pair_statuses(TradingPair::new(usdc, weth)), + TradingPairStatuses::::get(TradingPair::new(usdc, weth)), TradingPairStatus::NotEnabled ); @@ -101,7 +101,7 @@ fn reenable_trading_pair() { ); // check that pair LP token does not exist - assert_eq!(Dex::lp_token_id(TradingPair::new(usdc, weth)).is_some(), false); + assert_eq!(TradingPairLPToken::::get(TradingPair::new(usdc, weth)).is_some(), false); // manually create LP token and enable it TradingPairLPToken::::insert(TradingPair::new(usdc, weth), Some(3)); @@ -125,7 +125,7 @@ fn reenable_trading_pair() { // a disabled trading pair can be re-enabled assert_ok!(Dex::reenable_trading_pair(RuntimeOrigin::root(), usdc, weth)); assert_eq!( - Dex::trading_pair_statuses(TradingPair::new(usdc, weth)), + TradingPairStatuses::::get(TradingPair::new(usdc, weth)), TradingPairStatus::Enabled ); System::assert_last_event(MockEvent::Dex(crate::Event::EnableTradingPair( @@ -319,7 +319,7 @@ fn add_liquidity() { // adding LP enables trading pair assert_eq!( - Dex::trading_pair_statuses(TradingPair::new(usdc, weth)), + TradingPairStatuses::::get(TradingPair::new(usdc, weth)), TradingPairStatus::Enabled ); @@ -361,25 +361,34 @@ fn add_liquidity() { ))); // the created lp token should be the 3rd created token (first 22bit) + 100 (last 10bits) - assert_eq!(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), 3 << 10 | 100); + assert_eq!( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + 3 << 10 | 100 + ); // check that the next asset id should be 4 (2 assets + 1 lp token) // lp token is the same token independent of trading pair token ordering assert_eq!( - Dex::lp_token_id(TradingPair::new(usdc, weth)), - Dex::lp_token_id(TradingPair::new(weth, usdc)) + TradingPairLPToken::::get(TradingPair::new(usdc, weth)), + TradingPairLPToken::::get(TradingPair::new(weth, usdc)) ); // verify Alice now has LP tokens assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ), 999_999_999_999_999_000u128, ); // verify Charlie now has LP tokens assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &charlie), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &charlie + ), 1_000_000_000_000_000_000u128, ); @@ -418,14 +427,22 @@ fn add_liquidity() { // verify Bob now has LP tokens assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &bob), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &bob + ), to_eth(2), ); // bob should have more LP tokens than Alice as Bob provisioned more liquidity assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice) - < AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &bob), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ) < AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &bob + ), true ); @@ -483,7 +500,7 @@ fn add_shared_liquidity() { let trading_pair: TradingPair = TradingPair::new(usdc, weth); // adding LP enables trading pair - assert_eq!(Dex::trading_pair_statuses(trading_pair), TradingPairStatus::Enabled); + assert_eq!(TradingPairStatuses::::get(trading_pair), TradingPairStatus::Enabled); System::assert_last_event(MockEvent::Dex(crate::Event::AddLiquidity( alice, @@ -497,8 +514,8 @@ fn add_shared_liquidity() { // lp token is the same token independent of trading pair token ordering assert_eq!( - Dex::lp_token_id(TradingPair::new(usdc, weth)), - Dex::lp_token_id(TradingPair::new(weth, usdc)) + TradingPairLPToken::::get(TradingPair::new(usdc, weth)), + TradingPairLPToken::::get(TradingPair::new(weth, usdc)) ); // mint tokens to new user @@ -694,7 +711,10 @@ fn add_liquidity_issue_15() { None, )); assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ), 1_999_999_999_999_999_000_u128, ); assert_eq!(AssetsExt::balance(usdc, &alice), 8_000_000_000_000_000_000_u128); @@ -729,7 +749,7 @@ fn remove_liquidity_simple() { None, )); - let lp_token_id = Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(); + let lp_token_id = TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(); assert_eq!(AssetsExt::balance(lp_token_id, &alice), 1_999_999_999_999_999_000u128); assert_eq!(AssetsExt::balance(usdc, &alice), 0); assert_eq!(AssetsExt::balance(weth, &alice), 0); @@ -772,7 +792,10 @@ fn remove_liquidity_simple() { ))); assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ), 0, ); assert_eq!(AssetsExt::balance(usdc, &bob), 1_999_999_999_999_999_000u128); @@ -847,7 +870,7 @@ fn remove_liquidity_full() { None, None, )); - let lp_token_id = Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(); // TODO remove + let lp_token_id = TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(); // TODO remove assert_eq!(AssetsExt::balance(lp_token_id, &alice), 1_999_999_999_999_999_000u128); assert_eq!(AssetsExt::balance(usdc, &alice), 0); assert_eq!(AssetsExt::balance(weth, &alice), 0); @@ -918,7 +941,10 @@ fn remove_liquidity_full() { ))); assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ), 1, ); assert_eq!(AssetsExt::balance(usdc, &alice), 1_999_999_999_999_998_999_u128); @@ -945,7 +971,10 @@ fn remove_liquidity_full() { // removing all liquidity should imply user has recieved all input tokens assert_eq!( - AssetsExt::balance(Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(), &alice), + AssetsExt::balance( + TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(), + &alice + ), 0u128, ); // do not get 100% tokens back as some lost due to minimum liquidity minting @@ -1455,7 +1484,7 @@ fn multiple_swaps_with_multiple_lp() { None, )); - let lp_usdc_weth = Dex::lp_token_id(TradingPair::new(usdc, weth)).unwrap(); + let lp_usdc_weth = TradingPairLPToken::::get(TradingPair::new(usdc, weth)).unwrap(); // lp providers alice have lp tokens assert_eq!(AssetsExt::balance(lp_usdc_weth, &alice), 17_320_508_075_688_771_935_u128); @@ -1631,20 +1660,20 @@ fn set_fee_to() { // check the default value of FeeTo let fee_pot = DefaultFeeTo::::get().map(|v| v.into()); - assert_eq!(Dex::fee_to(), fee_pot); + assert_eq!(FeeTo::::get(), fee_pot); // normal user can not set FeeTo assert_noop!(Dex::set_fee_to(RuntimeOrigin::signed(alice), Some(bob)), BadOrigin); // change FeeTo with root user assert_ok!(Dex::set_fee_to(RuntimeOrigin::root(), Some(bob))); - assert_eq!(Dex::fee_to().unwrap(), bob); + assert_eq!(FeeTo::::get().unwrap(), bob); System::assert_last_event(MockEvent::Dex(crate::Event::FeeToSet(Some(bob)))); // disable FeeTo with root user assert_ok!(Dex::set_fee_to(RuntimeOrigin::root(), None)); - assert_eq!(Dex::fee_to().is_none(), true); + assert_eq!(FeeTo::::get().is_none(), true); System::assert_last_event(MockEvent::Dex(crate::Event::FeeToSet(None))); }); @@ -1679,8 +1708,8 @@ fn mint_fee() { // get the lp token id let trading_pair = TradingPair::new(usdc, weth); - let lp_token = Dex::lp_token_id(trading_pair).unwrap(); - let (reserve_a, reserve_b) = Dex::liquidity_pool(trading_pair); + let lp_token = TradingPairLPToken::::get(trading_pair).unwrap(); + let (reserve_a, reserve_b) = LiquidityPool::::get(trading_pair); // set FeeTo to None assert_ok!(Dex::set_fee_to(RuntimeOrigin::root(), None)); @@ -1755,11 +1784,14 @@ fn test_network_fee() { // get the lp token id let trading_pair = TradingPair::new(usdc, weth); - let lp_token = Dex::lp_token_id(trading_pair).unwrap(); + let lp_token = TradingPairLPToken::::get(trading_pair).unwrap(); // the last k value should be updated as the product of the initial reserve values let (reserve_0_init, reserve_1_init) = LiquidityPool::::get(trading_pair); - assert_eq!(Dex::liquidity_pool_last_k(lp_token), (reserve_0_init * reserve_1_init).into()); + assert_eq!( + LiquidityPoolLastK::::get(lp_token), + (reserve_0_init * reserve_1_init).into() + ); // fee_pot doesn't have lp token balance before swaps happening assert_eq!(AssetsExt::balance(lp_token, &fee_pot), 0); @@ -1803,7 +1835,10 @@ fn test_network_fee() { // the last k value should be updated after remove_liquidity is called let (reserve_0_new, reserve_1_new) = LiquidityPool::::get(trading_pair); - assert_eq!(Dex::liquidity_pool_last_k(lp_token), (reserve_0_new * reserve_1_new).into()); + assert_eq!( + LiquidityPoolLastK::::get(lp_token), + (reserve_0_new * reserve_1_new).into() + ); }); } diff --git a/pallet/echo/src/lib.rs b/pallet/echo/src/lib.rs index 3ef97a6da..c309b54fc 100644 --- a/pallet/echo/src/lib.rs +++ b/pallet/echo/src/lib.rs @@ -73,7 +73,6 @@ pub mod pallet { /// The next available offer_id #[pallet::storage] - #[pallet::getter(fn next_session_id)] pub type NextSessionId = StorageValue<_, u64, ValueQuery>; #[pallet::event] @@ -108,7 +107,7 @@ pub mod pallet { let source: H160 = ensure_signed(origin)?.into(); // Get session id and ensure within u64 bounds - let session_id = Self::next_session_id(); + let session_id = NextSessionId::::get(); ensure!(session_id.checked_add(u64::one()).is_some(), Error::::NoAvailableIds); // Encode the message, the first value as 0 states that the event was sent from this diff --git a/pallet/echo/src/tests.rs b/pallet/echo/src/tests.rs index 180194c4a..bae725567 100644 --- a/pallet/echo/src/tests.rs +++ b/pallet/echo/src/tests.rs @@ -24,12 +24,12 @@ fn ping_works_from_runtime() { TestExt::::default().build().execute_with(|| { let caller = H160::from_low_u64_be(123); let destination = ::PalletId::get().into_account_truncating(); - let next_session_id = Echo::next_session_id(); + let next_session_id = NextSessionId::::get(); assert_ok!(Echo::ping(Some(AccountId::from(caller)).into(), destination)); // Check storage updated - assert_eq!(Echo::next_session_id(), next_session_id + 1); + assert_eq!(NextSessionId::::get(), next_session_id + 1); // Check PingSent event thrown System::assert_has_event( @@ -64,7 +64,7 @@ fn ping_works_from_ethereum() { TestExt::::default().build().execute_with(|| { let caller = H160::from_low_u64_be(123); let destination = ::PalletId::get().into_account_truncating(); - let next_session_id = Echo::next_session_id(); + let next_session_id = NextSessionId::::get(); let data = ethabi::encode(&[ Token::Uint(PONG.into()), diff --git a/pallet/evm-chain-id/src/benchmarking.rs b/pallet/evm-chain-id/src/benchmarking.rs index 933fb1931..b23eadd00 100644 --- a/pallet/evm-chain-id/src/benchmarking.rs +++ b/pallet/evm-chain-id/src/benchmarking.rs @@ -17,6 +17,7 @@ use super::*; +#[allow(unused_imports)] use crate::Pallet as EVMChainId; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; @@ -28,7 +29,7 @@ benchmarks! { assert_eq!(ChainId::::get(), T::DefaultChainId::get()); }: _(RawOrigin::Root, 1234) verify { - assert_eq!(EVMChainId::::chain_id(), 1234); + assert_eq!(ChainId::::get(), 1234); } } diff --git a/pallet/evm-chain-id/src/lib.rs b/pallet/evm-chain-id/src/lib.rs index 51a8b48dd..0e6bca9ea 100644 --- a/pallet/evm-chain-id/src/lib.rs +++ b/pallet/evm-chain-id/src/lib.rs @@ -63,7 +63,7 @@ pub mod pallet { impl Get for Pallet { fn get() -> u64 { - Self::chain_id() + ChainId::::get() } } @@ -74,7 +74,6 @@ pub mod pallet { /// The EVM chain ID. #[pallet::storage] - #[pallet::getter(fn chain_id)] pub type ChainId = StorageValue<_, u64, ValueQuery, DefaultChainId>; #[pallet::event] diff --git a/pallet/evm-chain-id/src/tests.rs b/pallet/evm-chain-id/src/tests.rs index bc7c9f6c7..413564788 100644 --- a/pallet/evm-chain-id/src/tests.rs +++ b/pallet/evm-chain-id/src/tests.rs @@ -14,13 +14,14 @@ // You may obtain a copy of the License at the root of this project source code #![cfg(test)] -use crate::mock::{EVMChainId, RuntimeEvent, RuntimeOrigin, System, TestExt}; +use crate::mock::{EVMChainId, RuntimeEvent, RuntimeOrigin, System, Test, TestExt}; +use crate::ChainId; use seed_pallet_common::test_prelude::*; #[test] fn default_chain_id() { TestExt::default().build().execute_with(|| { - let chain_id = EVMChainId::chain_id(); + let chain_id = ChainId::::get(); assert_eq!(chain_id, 7672); }); } @@ -30,11 +31,11 @@ fn update_chain_id() { TestExt::default().build().execute_with(|| { // normal user cannot update chain id assert_noop!(EVMChainId::set_chain_id(RuntimeOrigin::signed(alice()), 1234), BadOrigin); - assert_eq!(EVMChainId::chain_id(), 7672); // chain id is not updated + assert_eq!(ChainId::::get(), 7672); // chain id is not updated // root user can update chain id assert_ok!(EVMChainId::set_chain_id(RuntimeOrigin::root().into(), 1234)); - assert_eq!(EVMChainId::chain_id(), 1234); // chain id is updated + assert_eq!(ChainId::::get(), 1234); // chain id is updated System::assert_last_event(RuntimeEvent::EVMChainId(crate::Event::ChainIdSet(1234))); }); diff --git a/pallet/marketplace/src/impls.rs b/pallet/marketplace/src/impls.rs index 364f85b78..a7dd02603 100644 --- a/pallet/marketplace/src/impls.rs +++ b/pallet/marketplace/src/impls.rs @@ -32,7 +32,7 @@ impl Pallet { Error::::RoyaltiesInvalid ); let marketplace_account = marketplace_account.unwrap_or(who); - let marketplace_id = Self::next_marketplace_id(); + let marketplace_id = NextMarketplaceId::::get(); let marketplace = Marketplace { account: marketplace_account.clone(), entitlement }; let next_marketplace_id = >::get(); ensure!(next_marketplace_id.checked_add(One::one()).is_some(), Error::::NoAvailableIds); @@ -61,7 +61,7 @@ impl Pallet { // Validate tokens tokens.validate()?; let royalties_schedule = Self::calculate_bundle_royalties(tokens.clone(), marketplace_id)?; - let listing_id = Self::next_listing_id(); + let listing_id = NextListingId::::get(); tokens.lock_tokens(&who, listing_id)?; @@ -126,7 +126,7 @@ impl Pallet { // /// Returns the offer detail of a specified offer_id pub fn get_offer_detail(offer_id: OfferId) -> Result, DispatchError> { - let Some(OfferType::Simple(offer)) = Self::offers(offer_id) else { + let Some(OfferType::Simple(offer)) = Offers::::get(offer_id) else { return Err(Error::::InvalidOffer.into()); }; Ok(offer) @@ -182,7 +182,7 @@ impl Pallet { // Validate tokens and get collection_id tokens.validate()?; let royalties_schedule = Self::calculate_bundle_royalties(tokens.clone(), marketplace_id)?; - let listing_id = Self::next_listing_id(); + let listing_id = NextListingId::::get(); ensure!(listing_id.checked_add(One::one()).is_some(), Error::::NoAvailableIds); tokens.lock_tokens(&who, listing_id)?; @@ -220,7 +220,7 @@ impl Pallet { _ => return Err(Error::::NotForAuction.into()), }; - if let Some(current_bid) = Self::listing_winning_bid(listing_id) { + if let Some(current_bid) = ListingWinningBid::::get(listing_id) { ensure!(amount > current_bid.1, Error::::BidTooLow); } else { // first bid @@ -283,7 +283,7 @@ impl Pallet { }, Listing::::Auction(auction) => { ensure!(auction.seller == who, Error::::NotSeller); - ensure!(Self::listing_winning_bid(listing_id).is_none(), Error::::TokenLocked); + ensure!(ListingWinningBid::::get(listing_id).is_none(), Error::::TokenLocked); auction.tokens.unlock_tokens(&who)?; Self::deposit_event(Event::::AuctionClose { @@ -311,7 +311,7 @@ impl Pallet { let token_owner = T::NFTExt::get_token_owner(&token_id); ensure!(token_owner.is_some(), Error::::NoToken); ensure!(token_owner != Some(who), Error::::IsTokenOwner); - let offer_id = Self::next_offer_id(); + let offer_id = NextOfferId::::get(); ensure!(offer_id.checked_add(One::one()).is_some(), Error::::NoAvailableIds); // ensure the token_id is not currently in an auction @@ -347,7 +347,7 @@ impl Pallet { } pub fn do_cancel_offer(who: T::AccountId, offer_id: OfferId) -> DispatchResult { - let Some(OfferType::Simple(offer)) = Self::offers(offer_id) else { + let Some(OfferType::Simple(offer)) = Offers::::get(offer_id) else { return Err(Error::::InvalidOffer.into()); }; ensure!(offer.buyer == who, Error::::NotBuyer); @@ -362,7 +362,7 @@ impl Pallet { } pub fn do_accept_offer(who: T::AccountId, offer_id: OfferId) -> DispatchResult { - let Some(OfferType::Simple(offer)) = Self::offers(offer_id) else { + let Some(OfferType::Simple(offer)) = Offers::::get(offer_id) else { return Err(Error::::InvalidOffer.into()); }; diff --git a/pallet/marketplace/src/lib.rs b/pallet/marketplace/src/lib.rs index b521117ef..438a78336 100644 --- a/pallet/marketplace/src/lib.rs +++ b/pallet/marketplace/src/lib.rs @@ -125,12 +125,10 @@ pub mod pallet { /// The next available marketplace id #[pallet::storage] - #[pallet::getter(fn next_marketplace_id)] pub type NextMarketplaceId = StorageValue<_, MarketplaceId, ValueQuery>; /// Map from marketplace account_id to royalties schedule #[pallet::storage] - #[pallet::getter(fn registered_marketplaces)] pub type RegisteredMarketplaces = StorageMap<_, Twox64Concat, MarketplaceId, Marketplace>; @@ -140,42 +138,35 @@ pub mod pallet { /// The next available listing Id #[pallet::storage] - #[pallet::getter(fn next_listing_id)] pub type NextListingId = StorageValue<_, ListingId, ValueQuery>; /// Map from collection to any open listings #[pallet::storage] - #[pallet::getter(fn open_collection_listings)] pub type OpenCollectionListings = StorageDoubleMap<_, Twox64Concat, CollectionUuid, Twox64Concat, ListingId, bool>; /// Winning bids on open listings. #[pallet::storage] - #[pallet::getter(fn listing_winning_bid)] pub type ListingWinningBid = StorageMap<_, Twox64Concat, ListingId, (T::AccountId, Balance)>; /// Block numbers where listings will close. Value is `true` if at block number `listing_id` is /// scheduled to close. #[pallet::storage] - #[pallet::getter(fn listing_end_schedule)] pub type ListingEndSchedule = StorageDoubleMap<_, Twox64Concat, BlockNumberFor, Twox64Concat, ListingId, bool>; /// Map from offer_id to the information related to the offer #[pallet::storage] - #[pallet::getter(fn offers)] pub type Offers = StorageMap<_, Twox64Concat, OfferId, OfferType>; /// Maps from token_id to a vector of offer_ids on that token #[pallet::storage] - #[pallet::getter(fn token_offers)] pub type TokenOffers = StorageMap<_, Twox64Concat, TokenId, BoundedVec>; /// The next available offer_id #[pallet::storage] - #[pallet::getter(fn next_offer_id)] pub type NextOfferId = StorageValue<_, OfferId, ValueQuery>; /// The pallet id for the tx fee pot diff --git a/pallet/marketplace/src/tests.rs b/pallet/marketplace/src/tests.rs index bcab82792..8c07ee3b1 100644 --- a/pallet/marketplace/src/tests.rs +++ b/pallet/marketplace/src/tests.rs @@ -94,7 +94,7 @@ fn make_new_simple_offer( buyer: AccountId, marketplace_id: Option, ) -> (OfferId, SimpleOffer) { - let next_offer_id = Marketplace::next_offer_id(); + let next_offer_id = NextOfferId::::get(); assert_ok!(Marketplace::make_simple_offer( Some(buyer).into(), @@ -112,8 +112,8 @@ fn make_new_simple_offer( }; // Check storage has been updated - assert_eq!(Marketplace::next_offer_id(), next_offer_id + 1); - assert_eq!(Marketplace::offers(next_offer_id), Some(OfferType::Simple(offer.clone()))); + assert_eq!(NextOfferId::::get(), next_offer_id + 1); + assert_eq!(Offers::::get(next_offer_id), Some(OfferType::Simple(offer.clone()))); System::assert_last_event(MockEvent::Marketplace(Event::::Offer { offer_id: next_offer_id, amount: offer_amount, @@ -156,7 +156,7 @@ fn sell() { let serial_numbers: BoundedVec = BoundedVec::try_from(vec![1, 3, 4]).unwrap(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::sell_nft( Some(collection_owner).into(), @@ -270,7 +270,7 @@ fn sell_multiple_fails() { fn sell_multiple() { TestExt::::default().build().execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); @@ -297,7 +297,7 @@ fn sell_multiple() { })); assert_eq!(TokenLocks::::get(token_id).unwrap(), TokenLockReason::Listed(listing_id)); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).unwrap()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).unwrap()); let fee_pot_account: AccountId = FeePotId::get().into_account_truncating(); let royalties_schedule = RoyaltiesSchedule { @@ -321,7 +321,7 @@ fn sell_multiple() { assert_eq!(listing, expected); // current block is 1 + duration - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -434,7 +434,7 @@ fn sell_zero_duration_fails() { fn cancel_sell() { TestExt::::default().build().execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); let buyer = create_account(5); @@ -459,7 +459,7 @@ fn cancel_sell() { // storage cleared up assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -483,7 +483,7 @@ fn sell_closes_on_schedule() { TestExt::::default().build().execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); let listing_duration = 100; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); let buyer = create_account(5); @@ -503,7 +503,7 @@ fn sell_closes_on_schedule() { // seller should have tokens assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + listing_duration, listing_id ) @@ -541,7 +541,7 @@ fn listing_price_splits_royalties_and_network_fee() { let (collection_id, token_id, token_owner) = setup_nft_token_with_royalties(royalties_schedule.clone(), 2); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -607,7 +607,7 @@ fn listing_price_splits_multiple_royalties_and_network_fee() { let (collection_id, token_id, token_owner) = setup_nft_token_with_royalties(royalties_schedule.clone(), 2); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -672,7 +672,7 @@ fn network_fee_royalties_split_is_respected_xrpl() { let (collection_id, token_id, token_owner) = setup_nft_token_with_royalties(royalties_schedule.clone(), 2); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -712,7 +712,7 @@ fn network_fee_royalties_split_is_respected_xrpl() { fn update_fixed_price() { TestExt::::default().build().execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); let buyer = create_account(5); @@ -766,7 +766,7 @@ fn update_fixed_price_fails() { let (collection_id, token_id, token_owner) = setup_nft_token(); let reserve_price = 1_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); // can't update, token not listed assert_noop!( @@ -797,7 +797,7 @@ fn update_fixed_price_fails() { fn update_fixed_price_fails_not_owner() { TestExt::::default().build().execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); let buyer = create_account(5); @@ -824,14 +824,14 @@ fn register_marketplace() { TestExt::::default().build().execute_with(|| { let account = create_account(1); let entitlement: Permill = Permill::from_float(0.1); - let marketplace_id = Marketplace::next_marketplace_id(); + let marketplace_id = NextMarketplaceId::::get(); assert_ok!(Marketplace::register_marketplace(Some(account).into(), None, entitlement)); System::assert_last_event(MockEvent::Marketplace(Event::::MarketplaceRegister { account, entitlement, marketplace_id, })); - assert_eq!(Marketplace::next_marketplace_id(), marketplace_id + 1); + assert_eq!(NextMarketplaceId::::get(), marketplace_id + 1); }); } @@ -840,7 +840,7 @@ fn register_marketplace_separate_account() { TestExt::::default().build().execute_with(|| { let account = create_account(1); let marketplace_account = create_account(2); - let marketplace_id = Marketplace::next_marketplace_id(); + let marketplace_id = NextMarketplaceId::::get(); let entitlement: Permill = Permill::from_float(0.1); assert_ok!(Marketplace::register_marketplace( @@ -888,7 +888,7 @@ fn buy_with_marketplace_royalties() { marketplace_entitlement )); let marketplace_id = 0; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_eq!(listing_id, 0); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); @@ -989,7 +989,7 @@ fn buy() { let (collection_id, token_id, token_owner) = setup_nft_token(); let buyer = create_account(5); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -1014,7 +1014,7 @@ fn buy() { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -1022,7 +1022,7 @@ fn buy() { // ownership changed assert!(TokenLocks::::get(&token_id).is_none()); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); assert_eq!( Nft::owned_tokens(collection_id, &buyer, 0, 1000), (0_u32, 1, vec![token_id.1]) @@ -1050,7 +1050,7 @@ fn buy_with_xrp() { let (collection_id, token_id, token_owner) = setup_nft_token(); let buyer = create_account(5); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -1075,7 +1075,7 @@ fn buy_with_xrp() { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -1083,7 +1083,7 @@ fn buy_with_xrp() { // ownership changed assert!(TokenLocks::::get(&token_id).is_none()); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); assert_eq!( Nft::owned_tokens(collection_id, &buyer, 0, 1000), (0_u32, 1, vec![token_id.1]) @@ -1121,7 +1121,7 @@ fn buy_with_royalties() { let (collection_id, token_id, token_owner) = setup_nft_token_with_royalties(royalties_schedule.clone(), 2); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_eq!(listing_id, 0); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); @@ -1172,7 +1172,7 @@ fn buy_with_royalties() { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -1198,7 +1198,7 @@ fn buy_fails_prechecks() { let buyer = create_account(5); let price = 1_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); // not for sale assert_noop!( @@ -1243,7 +1243,7 @@ fn sell_to_anybody() { let (collection_id, token_id, token_owner) = setup_nft_token(); let price = 1_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -1264,7 +1264,7 @@ fn sell_to_anybody() { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -1296,7 +1296,7 @@ fn buy_with_overcommitted_royalties() { (12_u64, Permill::from_float(0.9)), ]), }; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::sell_nft( @@ -1329,7 +1329,7 @@ fn cancel_auction() { let (collection_id, token_id, token_owner) = setup_nft_token(); let reserve_price = 100_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -1360,7 +1360,7 @@ fn cancel_auction() { // storage cleared up assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule(System::block_number() + 1, listing_id).is_none()); + assert!(ListingEndSchedule::::get(System::block_number() + 1, listing_id).is_none()); // it should be free to operate on the token let serial_numbers: BoundedVec = @@ -1400,7 +1400,7 @@ fn auction_bundle() { let serial_numbers: BoundedVec = BoundedVec::try_from(vec![1, 3, 4]).unwrap(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::auction_nft( Some(collection_owner).into(), @@ -1412,7 +1412,7 @@ fn auction_bundle() { None, )); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).unwrap()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).unwrap()); for serial_number in serial_numbers.iter() { assert_eq!( TokenLocks::::get((collection_id, serial_number)).unwrap(), @@ -1464,7 +1464,7 @@ fn auction_bundle_no_bids() { let serial_numbers: BoundedVec = BoundedVec::try_from(vec![1, 3, 4]).unwrap(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::auction_nft( Some(collection_owner).into(), @@ -1476,7 +1476,7 @@ fn auction_bundle_no_bids() { None, )); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).unwrap()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).unwrap()); for serial_number in serial_numbers.iter() { assert_eq!( TokenLocks::::get((collection_id, serial_number)).unwrap(), @@ -1533,7 +1533,7 @@ fn auction() { .execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -1549,8 +1549,8 @@ fn auction() { TokenLocks::::get(&token_id).unwrap(), TokenLockReason::Listed(listing_id) ); - assert_eq!(Marketplace::next_listing_id(), listing_id + 1); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).unwrap()); + assert_eq!(NextListingId::::get(), listing_id + 1); + assert!(OpenCollectionListings::::get(collection_id, listing_id).unwrap()); // first bidder at reserve price assert_ok!(Marketplace::bid(Some(bidder_1).into(), listing_id, reserve_price,)); @@ -1601,7 +1601,7 @@ fn auction() { // listing metadata removed assert!(Listings::::get(listing_id).is_none()); assert!( - Marketplace::listing_end_schedule(System::block_number() + 1, listing_id).is_none() + ListingEndSchedule::::get(System::block_number() + 1, listing_id).is_none() ); // ownership changed @@ -1610,7 +1610,7 @@ fn auction() { Nft::owned_tokens(collection_id, &bidder_2, 0, 1000), (0_u32, 1, vec![token_id.1]) ); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); // event logged let tokens = ListingTokens::Nft(NftListing { collection_id, serial_numbers }); @@ -1638,7 +1638,7 @@ fn auction_with_xrp_asset() { .execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -1654,8 +1654,8 @@ fn auction_with_xrp_asset() { TokenLocks::::get(&token_id).unwrap(), TokenLockReason::Listed(listing_id) ); - assert_eq!(Marketplace::next_listing_id(), listing_id + 1); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).unwrap()); + assert_eq!(NextListingId::::get(), listing_id + 1); + assert!(OpenCollectionListings::::get(collection_id, listing_id).unwrap()); // first bidder at reserve price assert_ok!(Marketplace::bid(Some(bidder_1).into(), listing_id, reserve_price,)); @@ -1690,7 +1690,7 @@ fn auction_with_xrp_asset() { // listing metadata removed assert!(Listings::::get(listing_id).is_none()); assert!( - Marketplace::listing_end_schedule(System::block_number() + 1, listing_id).is_none() + ListingEndSchedule::::get(System::block_number() + 1, listing_id).is_none() ); // ownership changed @@ -1699,7 +1699,7 @@ fn auction_with_xrp_asset() { Nft::owned_tokens(collection_id, &bidder_2, 0, 1000), (0_u32, 1, vec![token_id.1]) ); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); // event logged let tokens = ListingTokens::Nft(NftListing { collection_id, serial_numbers }); @@ -1725,7 +1725,7 @@ fn bid_auto_extends() { .execute_with(|| { let (collection_id, token_id, token_owner) = setup_nft_token(); let reserve_price = 100_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -1744,7 +1744,7 @@ fn bid_auto_extends() { if let Some(Listing::Auction(listing)) = Listings::::get(listing_id) { assert_eq!(listing.close, System::block_number() + AUCTION_EXTENSION_PERIOD as u64); } - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + AUCTION_EXTENSION_PERIOD as u64, listing_id ) @@ -1773,7 +1773,7 @@ fn auction_royalty_payments() { }; let (collection_id, token_id, token_owner) = setup_nft_token_with_royalties(royalties_schedule.clone(), 1); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -1906,9 +1906,9 @@ fn close_listings_at_removes_listing_data() { .is_zero()); for listing_id in 0..listings.len() as ListingId { assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_winning_bid(listing_id).is_none()); + assert!(ListingWinningBid::::get(listing_id).is_none()); assert!( - Marketplace::listing_end_schedule(System::block_number() + 1, listing_id).is_none() + ListingEndSchedule::::get(System::block_number() + 1, listing_id).is_none() ); } }); @@ -2032,7 +2032,7 @@ fn bid_fails_prechecks() { ); let (collection_id, token_id, token_owner) = setup_nft_token(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -2091,7 +2091,7 @@ fn bid_no_balance_should_fail() { let (collection_id, token_id, token_owner) = setup_nft_token(); let reserve_price = 100_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); assert_ok!(Marketplace::auction_nft( @@ -2124,7 +2124,7 @@ fn make_simple_offer() { let (_, token_id, _) = setup_nft_token(); let offer_amount: Balance = 100; let (offer_id, _) = make_new_simple_offer(offer_amount, token_id, buyer, None); - assert_eq!(Marketplace::token_offers(token_id).unwrap(), vec![offer_id]); + assert_eq!(TokenOffers::::get(token_id).unwrap(), vec![offer_id]); // Check funds have been locked assert_eq!( AssetsExt::hold_balance(&MarketplacePalletId::get(), &buyer, &NativeAssetId::get()), @@ -2257,7 +2257,7 @@ fn make_simple_offer_on_fixed_price_listing() { let sell_price = 100_000; let serial_numbers: BoundedVec = BoundedVec::try_from(vec![token_id.1]).unwrap(); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::sell_nft( Some(token_owner).into(), @@ -2290,8 +2290,8 @@ fn make_simple_offer_on_fixed_price_listing() { assert!(Listings::::get(listing_id).is_none()); assert!(TokenLocks::::get(token_id).is_none()); // Check offer storage has been removed - assert!(Marketplace::token_offers(token_id).is_none()); - assert!(Marketplace::offers(offer_id).is_none()); + assert!(TokenOffers::::get(token_id).is_none()); + assert!(Offers::::get(offer_id).is_none()); // Check funds have been transferred assert_eq!( @@ -2374,8 +2374,8 @@ fn cancel_offer() { })); // Check storage has been removed - assert!(Marketplace::token_offers(token_id).is_none()); - assert_eq!(Marketplace::offers(offer_id), None); + assert!(TokenOffers::::get(token_id).is_none()); + assert_eq!(Offers::::get(offer_id), None); // Check funds have been unlocked after offer cancelled assert_eq!(AssetsExt::balance(NativeAssetId::get(), &buyer), initial_balance_buyer); assert!(AssetsExt::hold_balance( @@ -2422,9 +2422,9 @@ fn cancel_offer_multiple_offers() { // Check storage has been removed let offer_vector: Vec = vec![offer_id_2]; - assert_eq!(Marketplace::token_offers(token_id).unwrap(), offer_vector); - assert_eq!(Marketplace::offers(offer_id_2), Some(OfferType::Simple(offer_2.clone()))); - assert_eq!(Marketplace::offers(offer_id_1), None); + assert_eq!(TokenOffers::::get(token_id).unwrap(), offer_vector); + assert_eq!(Offers::::get(offer_id_2), Some(OfferType::Simple(offer_2.clone()))); + assert_eq!(Offers::::get(offer_id_1), None); // Check funds have been unlocked after offer cancelled assert_eq!(AssetsExt::balance(NativeAssetId::get(), &buyer_1), initial_balance_buyer_1); @@ -2492,8 +2492,8 @@ fn accept_offer() { })); // Check storage has been removed - assert!(Marketplace::token_offers(token_id).is_none()); - assert!(Marketplace::offers(offer_id).is_none()); + assert!(TokenOffers::::get(token_id).is_none()); + assert!(Offers::::get(offer_id).is_none()); // Check funds have been transferred assert_eq!( AssetsExt::balance(NativeAssetId::get(), &buyer), @@ -2540,9 +2540,9 @@ fn accept_offer_multiple_offers() { })); // Check storage has been removed let offer_vector: Vec = vec![offer_id_1]; - assert_eq!(Marketplace::token_offers(token_id).unwrap(), offer_vector); - assert_eq!(Marketplace::offers(offer_id_1), Some(OfferType::Simple(offer_1.clone()))); - assert_eq!(Marketplace::offers(offer_id_2), None); + assert_eq!(TokenOffers::::get(token_id).unwrap(), offer_vector); + assert_eq!(Offers::::get(offer_id_1), Some(OfferType::Simple(offer_1.clone()))); + assert_eq!(Offers::::get(offer_id_2), None); // Check funds have been transferred assert_eq!( @@ -2594,7 +2594,7 @@ fn accept_offer_pays_marketplace_royalties() { let marketplace_account = create_account(4); let entitlements: Permill = Permill::from_float(0.1); - let marketplace_id = Marketplace::next_marketplace_id(); + let marketplace_id = NextMarketplaceId::::get(); assert_ok!(Marketplace::register_marketplace( Some(marketplace_account).into(), None, @@ -2606,8 +2606,8 @@ fn accept_offer_pays_marketplace_royalties() { assert_ok!(Marketplace::accept_offer(Some(token_owner).into(), offer_id)); // Check storage has been removed - assert!(Marketplace::token_offers(token_id).is_none()); - assert_eq!(Marketplace::offers(offer_id), None); + assert!(TokenOffers::::get(token_id).is_none()); + assert_eq!(Offers::::get(offer_id), None); // Check funds have been transferred with royalties assert_eq!( AssetsExt::balance(NativeAssetId::get(), &buyer), @@ -2698,7 +2698,7 @@ mod sell_sft { let price = 100_000; let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, balance)]); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let sft_token = ListingTokens::Sft(SftListing { collection_id, serial_numbers: serial_numbers.clone(), @@ -2923,7 +2923,7 @@ mod sell_sft { serial_numbers: serial_numbers.clone(), }); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::sell( Some(token_owner).into(), sft_token.clone(), @@ -3003,7 +3003,7 @@ mod buy_sft { let (collection_id, token_id, token_owner) = setup_sft_token(initial_issuance); let buyer = create_account(5); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let sell_quantity = 60; let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, sell_quantity)]); @@ -3035,12 +3035,12 @@ mod buy_sft { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) .is_none()); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); // Check SFT balances of both seller and buyer let seller_balance = sft_balance_of::(token_id, &token_owner); @@ -3096,7 +3096,7 @@ mod buy_sft { let (collection_id, token_id, token_owner) = setup_sft_token(initial_issuance); let buyer = create_account(5); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let sell_quantity = 60; let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, sell_quantity)]); @@ -3125,12 +3125,12 @@ mod buy_sft { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) .is_none()); - assert!(Marketplace::open_collection_listings(collection_id, listing_id).is_none()); + assert!(OpenCollectionListings::::get(collection_id, listing_id).is_none()); // Check SFT balances of both seller and buyer let seller_balance = sft_balance_of::(token_id, &token_owner); @@ -3196,7 +3196,7 @@ mod buy_sft { let (collection_id, token_id, token_owner) = setup_sft_token_with_royalties(initial_issuance, royalties_schedule.clone()); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let sell_quantity = 100; let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, sell_quantity)]); @@ -3208,7 +3208,7 @@ mod buy_sft { // Setup marketplace let marketplace_account = create_account(4); let marketplace_entitlements: Permill = Permill::from_float(0.1); - let marketplace_id = Marketplace::next_marketplace_id(); + let marketplace_id = NextMarketplaceId::::get(); assert_ok!(Marketplace::register_marketplace( Some(marketplace_account).into(), None, @@ -3275,7 +3275,7 @@ mod buy_sft { // listing removed assert!(Listings::::get(listing_id).is_none()); - assert!(Marketplace::listing_end_schedule( + assert!(ListingEndSchedule::::get( System::block_number() + ::DefaultListingDuration::get(), listing_id ) @@ -3304,7 +3304,7 @@ mod buy_sft { let (collection_id, token_id, token_owner) = setup_sft_token(initial_issuance); let buyer = create_account(5); let price = 1_000; - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, 100)]); let sft_token = ListingTokens::Sft(SftListing { @@ -3348,7 +3348,7 @@ mod auction_sft { let reserve_price = 100_000; let serial_numbers: BoundedVec<(SerialNumber, Balance), MaxTokensPerListing> = BoundedVec::truncate_from(vec![(token_id.1, balance)]); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); let sft_token = ListingTokens::Sft(SftListing { collection_id, serial_numbers: serial_numbers.clone(), @@ -4041,7 +4041,7 @@ mod buy_multi { }); let price1 = 1_000; let asset_id1 = NativeAssetId::get(); - let listing_id1 = Marketplace::next_listing_id(); + let listing_id1 = NextListingId::::get(); assert_ok!(Marketplace::sell( Some(token_owner1).into(), nft_token.clone(), @@ -4062,7 +4062,7 @@ mod buy_multi { }); let price2 = 2_000; let asset_id2 = XRP_ASSET_ID; - let listing_id2 = Marketplace::next_listing_id(); + let listing_id2 = NextListingId::::get(); assert_ok!(Marketplace::sell( Some(token_owner2).into(), sft_token.clone(), @@ -4148,7 +4148,7 @@ mod buy_multi { collection_id, serial_numbers: serial_numbers.clone(), }); - let listing_id = Marketplace::next_listing_id(); + let listing_id = NextListingId::::get(); assert_ok!(Marketplace::sell( Some(token_owner).into(), nft_token.clone(), diff --git a/pallet/token-approvals/src/lib.rs b/pallet/token-approvals/src/lib.rs index 8c40c66d9..cb9817365 100644 --- a/pallet/token-approvals/src/lib.rs +++ b/pallet/token-approvals/src/lib.rs @@ -58,12 +58,10 @@ pub mod pallet { // Account with transfer approval for a single NFT #[pallet::storage] - #[pallet::getter(fn erc721_approvals)] pub type ERC721Approvals = StorageMap<_, Twox64Concat, TokenId, T::AccountId>; // Accounts with transfer approval for an NFT collection of another account #[pallet::storage] - #[pallet::getter(fn erc721_approvals_for_all)] pub type ERC721ApprovalsForAll = StorageDoubleMap< _, Twox64Concat, @@ -75,7 +73,6 @@ pub mod pallet { // Mapping from account/ asset_id to an approved balance of another account #[pallet::storage] - #[pallet::getter(fn erc20_approvals)] pub type ERC20Approvals = StorageDoubleMap< _, Twox64Concat, @@ -87,7 +84,6 @@ pub mod pallet { // Accounts with transfer approval for an SFT collection of another account #[pallet::storage] - #[pallet::getter(fn erc1155_approvals_for_all)] pub type ERC1155ApprovalsForAll = StorageDoubleMap< _, Twox64Concat, @@ -140,7 +136,7 @@ pub mod pallet { }; let is_approved_for_all = - Self::erc721_approvals_for_all(&token_owner, (token_id.0, caller.clone())) + ERC721ApprovalsForAll::::get(&token_owner, (token_id.0, caller.clone())) .unwrap_or_default(); ensure!( token_owner == caller || is_approved_for_all, @@ -194,7 +190,7 @@ pub mod pallet { amount: Balance, ) -> DispatchResult { let _ = ensure_none(origin)?; - let new_approved_amount = Self::erc20_approvals((&caller, asset_id), &spender) + let new_approved_amount = ERC20Approvals::::get((&caller, asset_id), &spender) .ok_or(Error::::CallerNotApproved)? .checked_sub(amount) .ok_or(Error::::ApprovedAmountTooLow)?; @@ -277,7 +273,7 @@ impl Pallet { // Check approvalForAll if let Some(owner) = token_owner { - if Self::erc721_approvals_for_all(owner, (token_id.0, spender.clone())) + if ERC721ApprovalsForAll::::get(owner, (token_id.0, spender.clone())) .unwrap_or_default() { return true; @@ -285,7 +281,7 @@ impl Pallet { } // Lastly, Check token approval - Some(spender) == Self::erc721_approvals(token_id) + Some(spender) == ERC721Approvals::::get(token_id) } } diff --git a/pallet/token-approvals/src/tests.rs b/pallet/token-approvals/src/tests.rs index 25eb53ba3..35ce75692 100644 --- a/pallet/token-approvals/src/tests.rs +++ b/pallet/token-approvals/src/tests.rs @@ -15,6 +15,7 @@ use super::*; use crate::mock::{Nft, Test, TokenApprovals}; +use crate::{ERC1155ApprovalsForAll, ERC20Approvals, ERC721Approvals, ERC721ApprovalsForAll}; use seed_pallet_common::test_prelude::*; use seed_primitives::OriginChain; @@ -72,7 +73,7 @@ fn set_erc721_approval() { let operator = create_account(12); assert_ok!(TokenApprovals::erc721_approval(None.into(), caller, operator, token_id)); - assert_eq!(TokenApprovals::erc721_approvals(token_id).unwrap(), operator); + assert_eq!(ERC721Approvals::::get(token_id).unwrap(), operator); }); } @@ -95,7 +96,7 @@ fn set_erc721_approval_approved_for_all() { // Caller is not token owner, but they are approved for all so this passes assert_ok!(TokenApprovals::erc721_approval(None.into(), caller, operator, token_id)); - assert_eq!(TokenApprovals::erc721_approvals(token_id).unwrap(), operator); + assert_eq!(ERC721Approvals::::get(token_id).unwrap(), operator); // 000_001_500_000_000_000 }); } @@ -136,7 +137,7 @@ fn erc721_approval_removed_on_transfer() { let operator = create_account(11); assert_ok!(TokenApprovals::erc721_approval(None.into(), caller, operator, token_id)); - assert_eq!(TokenApprovals::erc721_approvals(token_id).unwrap(), operator); + assert_eq!(ERC721Approvals::::get(token_id).unwrap(), operator); TokenApprovals::on_nft_transfer(&token_id); assert!(!ERC721Approvals::::contains_key(token_id)); }); @@ -197,7 +198,7 @@ fn set_erc20_approval() { let amount: Balance = 10; assert_ok!(TokenApprovals::erc20_approval(None.into(), caller, spender, asset_id, amount)); - assert_eq!(TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), amount); + assert_eq!(ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount); }); } @@ -225,7 +226,7 @@ fn update_erc20_approval_full_amount() { let amount: Balance = 10; assert_ok!(TokenApprovals::erc20_approval(None.into(), caller, spender, asset_id, amount)); - assert_eq!(TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), amount); + assert_eq!(ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount); // Remove approval assert_ok!(TokenApprovals::erc20_update_approval( @@ -248,7 +249,7 @@ fn update_erc20_approval_some_amount() { let amount: Balance = 10; assert_ok!(TokenApprovals::erc20_approval(None.into(), caller, spender, asset_id, amount)); - assert_eq!(TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), amount); + assert_eq!(ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount); let removal_amount: Balance = 9; // Remove approval @@ -260,7 +261,7 @@ fn update_erc20_approval_some_amount() { removal_amount )); assert_eq!( - TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), + ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount - removal_amount ); }); @@ -275,7 +276,7 @@ fn update_erc20_approval_amount_too_high_should_fail() { let amount: Balance = 10; assert_ok!(TokenApprovals::erc20_approval(None.into(), caller, spender, asset_id, amount)); - assert_eq!(TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), amount); + assert_eq!(ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount); let removal_amount: Balance = 11; // Attempt to remove approval @@ -301,7 +302,7 @@ fn update_erc20_approval_not_approved_should_fail() { let amount: Balance = 10; assert_ok!(TokenApprovals::erc20_approval(None.into(), caller, spender, asset_id, amount)); - assert_eq!(TokenApprovals::erc20_approvals((caller, asset_id), spender).unwrap(), amount); + assert_eq!(ERC20Approvals::::get((caller, asset_id), spender).unwrap(), amount); let malicious_spender = create_account(13); // Attempt to remove approval @@ -333,9 +334,7 @@ fn set_erc721_approval_for_all() { collection_id, true )); - assert!( - TokenApprovals::erc721_approvals_for_all(caller, (collection_id, operator)).unwrap() - ); + assert!(ERC721ApprovalsForAll::::get(caller, (collection_id, operator)).unwrap()); // Remove approval assert_ok!(TokenApprovals::erc721_approval_for_all( @@ -345,9 +344,7 @@ fn set_erc721_approval_for_all() { collection_id, false )); - assert!( - TokenApprovals::erc721_approvals_for_all(caller, (collection_id, operator)).is_none() - ); + assert!(ERC721ApprovalsForAll::::get(caller, (collection_id, operator)).is_none()); }); } @@ -384,15 +381,9 @@ fn set_erc721_approval_for_all_multiple_approvals() { )); // Check storage - assert!( - TokenApprovals::erc721_approvals_for_all(caller, (collection_id, operator_1)).unwrap() - ); - assert!( - TokenApprovals::erc721_approvals_for_all(caller, (collection_id, operator_2)).unwrap() - ); - assert!( - TokenApprovals::erc721_approvals_for_all(caller, (collection_id, operator_3)).unwrap() - ); + assert!(ERC721ApprovalsForAll::::get(caller, (collection_id, operator_1)).unwrap()); + assert!(ERC721ApprovalsForAll::::get(caller, (collection_id, operator_2)).unwrap()); + assert!(ERC721ApprovalsForAll::::get(caller, (collection_id, operator_3)).unwrap()); }); } @@ -467,9 +458,7 @@ fn set_erc1155_approval_for_all() { collection_id, true )); - assert!( - TokenApprovals::erc1155_approvals_for_all(caller, (collection_id, operator)).unwrap() - ); + assert!(ERC1155ApprovalsForAll::::get(caller, (collection_id, operator)).unwrap()); // Remove approval assert_ok!(TokenApprovals::erc1155_approval_for_all( @@ -479,9 +468,7 @@ fn set_erc1155_approval_for_all() { collection_id, false )); - assert!( - TokenApprovals::erc1155_approvals_for_all(caller, (collection_id, operator)).is_none() - ); + assert!(ERC1155ApprovalsForAll::::get(caller, (collection_id, operator)).is_none()); }); } @@ -518,15 +505,9 @@ fn set_erc1155_approval_for_all_multiple_approvals() { )); // Check storage - assert!( - TokenApprovals::erc1155_approvals_for_all(caller, (collection_id, operator_1)).unwrap() - ); - assert!( - TokenApprovals::erc1155_approvals_for_all(caller, (collection_id, operator_2)).unwrap() - ); - assert!( - TokenApprovals::erc1155_approvals_for_all(caller, (collection_id, operator_3)).unwrap() - ); + assert!(ERC1155ApprovalsForAll::::get(caller, (collection_id, operator_1)).unwrap()); + assert!(ERC1155ApprovalsForAll::::get(caller, (collection_id, operator_2)).unwrap()); + assert!(ERC1155ApprovalsForAll::::get(caller, (collection_id, operator_3)).unwrap()); }); } diff --git a/pallet/tx-fee-pot/src/lib.rs b/pallet/tx-fee-pot/src/lib.rs index e1c7f3620..cbe4657d4 100644 --- a/pallet/tx-fee-pot/src/lib.rs +++ b/pallet/tx-fee-pot/src/lib.rs @@ -61,7 +61,6 @@ pub mod pallet { /// Accrued transaction fees in the current staking Era #[pallet::storage] - #[pallet::getter(fn era_tx_fees)] pub type EraTxFees = StorageValue<_, Balance, ValueQuery>; } @@ -76,7 +75,7 @@ impl Pallet { } /// Get the tx fee pot balance (current era) pub fn era_pot_balance() -> Balance { - Self::era_tx_fees() + EraTxFees::::get() } /// Get the tx fee pot balance (all eras - any claimed amounts) pub fn total_pot_balance() -> Balance { diff --git a/pallet/xrpl-bridge/src/lib.rs b/pallet/xrpl-bridge/src/lib.rs index 38e52dbc7..62a8ecdfb 100644 --- a/pallet/xrpl-bridge/src/lib.rs +++ b/pallet/xrpl-bridge/src/lib.rs @@ -406,7 +406,6 @@ pub mod pallet { 0_u32 } #[pallet::storage] - #[pallet::getter(fn door_ticket_sequence)] /// The current ticket sequence of the XRPL door accounts pub type DoorTicketSequence = StorageMap< _, @@ -418,19 +417,16 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn door_ticket_sequence_params)] /// The Ticket sequence params of the XRPL door accounts for the current allocation pub type DoorTicketSequenceParams = StorageMap<_, Twox64Concat, XRPLDoorAccount, XrplTicketSequenceParams, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn door_ticket_sequence_params_next)] /// The Ticket sequence params of the XRPL door accounts for the next allocation pub type DoorTicketSequenceParamsNext = StorageMap<_, Twox64Concat, XRPLDoorAccount, XrplTicketSequenceParams, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn ticket_sequence_threshold_reached_emitted)] /// Keeps track whether the TicketSequenceThresholdReached event is emitted for XRPL door accounts pub type TicketSequenceThresholdReachedEmitted = StorageMap<_, Twox64Concat, XRPLDoorAccount, bool, ValueQuery>; @@ -676,8 +672,8 @@ pub mod pallet { let active_relayer = >::get(&relayer).unwrap_or(false); ensure!(active_relayer, Error::::NotPermitted); - let current_ticket_sequence = Self::door_ticket_sequence(door_account); - let current_params = Self::door_ticket_sequence_params(door_account); + let current_ticket_sequence = DoorTicketSequence::::get(door_account); + let current_params = DoorTicketSequenceParams::::get(door_account); if start_ticket_sequence < current_ticket_sequence || start_ticket_sequence < current_params.start_sequence @@ -711,8 +707,8 @@ pub mod pallet { ticket_bucket_size: u32, ) -> DispatchResult { ensure_root(origin)?; // only the root will be able to do it - let current_ticket_sequence = Self::door_ticket_sequence(door_account); - let current_params = Self::door_ticket_sequence_params(door_account); + let current_ticket_sequence = DoorTicketSequence::::get(door_account); + let current_params = DoorTicketSequenceParams::::get(door_account); if ticket_sequence < current_ticket_sequence || start_ticket_sequence < current_params.start_sequence @@ -1697,8 +1693,8 @@ impl Pallet { pub fn get_door_ticket_sequence( door_account: XRPLDoorAccount, ) -> Result { - let mut current_sequence = Self::door_ticket_sequence(door_account); - let ticket_params = Self::door_ticket_sequence_params(door_account); + let mut current_sequence = DoorTicketSequence::::get(door_account); + let ticket_params = DoorTicketSequenceParams::::get(door_account); // check if TicketSequenceThreshold reached. notify by emitting // TicketSequenceThresholdReached @@ -1707,7 +1703,7 @@ impl Pallet { current_sequence - ticket_params.start_sequence + 1, ticket_params.bucket_size, ) >= T::TicketSequenceThreshold::get() - && !Self::ticket_sequence_threshold_reached_emitted(door_account) + && !TicketSequenceThresholdReachedEmitted::::get(door_account) { Self::deposit_event(Event::::TicketSequenceThresholdReached { door_account, @@ -1724,7 +1720,7 @@ impl Pallet { .ok_or(ArithmeticError::Overflow)?; if current_sequence >= last_sequence { // we ran out current bucket, check the next_start_sequence - let next_ticket_params = Self::door_ticket_sequence_params_next(door_account); + let next_ticket_params = DoorTicketSequenceParamsNext::::get(door_account); if next_ticket_params == XrplTicketSequenceParams::default() || next_ticket_params.start_sequence == ticket_params.start_sequence { diff --git a/pallet/xrpl-bridge/src/tests.rs b/pallet/xrpl-bridge/src/tests.rs index 28d337be6..f0704d9fb 100644 --- a/pallet/xrpl-bridge/src/tests.rs +++ b/pallet/xrpl-bridge/src/tests.rs @@ -2543,14 +2543,11 @@ fn get_door_ticket_sequence_success_at_start_if_initial_params_not_set() { )); assert_eq!(XRPLBridge::get_door_ticket_sequence(XRPLDoorAccount::Main), Ok(3)); assert_eq!( - XRPLBridge::ticket_sequence_threshold_reached_emitted(XRPLDoorAccount::Main), + TicketSequenceThresholdReachedEmitted::::get(XRPLDoorAccount::Main), false ); assert_eq!(XRPLBridge::get_door_ticket_sequence(XRPLDoorAccount::Main), Ok(4)); - assert_eq!( - XRPLBridge::ticket_sequence_threshold_reached_emitted(XRPLDoorAccount::Main), - true - ); + assert_eq!(TicketSequenceThresholdReachedEmitted::::get(XRPLDoorAccount::Main), true); System::assert_has_event( Event::::TicketSequenceThresholdReached { door_account: XRPLDoorAccount::Main, @@ -2675,15 +2672,12 @@ fn get_door_ticket_sequence_check_events_emitted() { )); assert_eq!(XRPLBridge::get_door_ticket_sequence(XRPLDoorAccount::Main), Ok(3)); assert_eq!( - XRPLBridge::ticket_sequence_threshold_reached_emitted(XRPLDoorAccount::Main), + TicketSequenceThresholdReachedEmitted::::get(XRPLDoorAccount::Main), false ); assert_eq!(XRPLBridge::get_door_ticket_sequence(XRPLDoorAccount::Main), Ok(4)); // event should be emitted here since ((4 - 3) + 1)/3 = 0.66 == TicketSequenceThreshold - assert_eq!( - XRPLBridge::ticket_sequence_threshold_reached_emitted(XRPLDoorAccount::Main), - true - ); + assert_eq!(TicketSequenceThresholdReachedEmitted::::get(XRPLDoorAccount::Main), true); System::assert_has_event( Event::::TicketSequenceThresholdReached { door_account: XRPLDoorAccount::Main, diff --git a/runtime/src/tests/evm_tests.rs b/runtime/src/tests/evm_tests.rs index 9d6d9b4cb..f354a4810 100644 --- a/runtime/src/tests/evm_tests.rs +++ b/runtime/src/tests/evm_tests.rs @@ -344,7 +344,7 @@ fn call_with_fee_preferences_futurepass_proxy_extrinsic() { fn transactions_cost_goes_to_tx_pot() { ExtBuilder::default().build().execute_with(|| { // Setup - let old_pot = TxFeePot::era_tx_fees(); + let old_pot = pallet_tx_fee_pot::EraTxFees::::get(); // Call let (origin, tx) = TxBuilder::default().build(); @@ -352,7 +352,7 @@ fn transactions_cost_goes_to_tx_pot() { // Check let expected_change = 157_500u128; - assert_eq!(TxFeePot::era_tx_fees(), old_pot + expected_change); + assert_eq!(pallet_tx_fee_pot::EraTxFees::::get(), old_pot + expected_change); }) }