From 3f57ddba42d17c99ae1bd97198699a1bdbb12026 Mon Sep 17 00:00:00 2001 From: yooml Date: Thu, 19 Oct 2023 18:10:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pallets/leverage-staking/src/lib.rs | 19 ++++++++----------- pallets/leverage-staking/src/tests.rs | 17 +++++++---------- pallets/stable-pool/src/lib.rs | 10 +++++++--- pallets/stable-pool/src/traits.rs | 21 ++++++++++----------- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/pallets/leverage-staking/src/lib.rs b/pallets/leverage-staking/src/lib.rs index dffd9f04c..da544f387 100644 --- a/pallets/leverage-staking/src/lib.rs +++ b/pallets/leverage-staking/src/lib.rs @@ -30,24 +30,20 @@ pub use codec::{Decode, Encode}; use frame_support::{ pallet_prelude::*, traits::{ - fungibles::{Inspect, Mutate}, + fungibles::Mutate, tokens::{Fortitude, Precision, Preservation}, Get, }, - BoundedVec, PalletId, Parameter, + BoundedVec, PalletId, }; use frame_system::{ensure_signed, pallet_prelude::*}; -use node_primitives::{ - CurrencyId, CurrencyIdConversion, CurrencyIdExt, CurrencyIdRegister, Rate, TimeUnit, - VtokenMintingInterface, -}; -use orml_traits::MultiCurrency; +use node_primitives::{CurrencyIdConversion, CurrencyIdRegister, Rate, VtokenMintingInterface}; pub use pallet_traits::{ ConvertToBigUint, LendMarket as LendMarketTrait, LendMarketMarketDataProvider, LendMarketPositionDataProvider, MarketInfo, MarketStatus, PriceFeeder, }; use sp_runtime::{ - traits::{CheckedMul, CheckedSub, StaticLookup, Zero}, + traits::{CheckedMul, CheckedSub, Zero}, ArithmeticError, FixedU128, RuntimeDebug, }; use sp_std::marker::PhantomData; @@ -137,7 +133,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - if let Some(flash_loan_info) = AccountFlashLoans::::get(asset_id, &who) { + if let Some(_flash_loan_info) = AccountFlashLoans::::get(asset_id, &who) { Self::do_repay(&who, asset_id, None)?; } @@ -192,11 +188,11 @@ pub mod pallet { pub fn flash_loan_repay( origin: OriginFor, asset_id: AssetIdOf, - rate: Rate, + rate: Option, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - Self::do_repay(&who, asset_id, Some(rate))?; + Self::do_repay(&who, asset_id, rate)?; Ok(().into()) } } @@ -249,6 +245,7 @@ impl Pallet { )?; T::LendMarket::do_repay_borrow(&who, asset_id, token_value)?; T::LendMarket::do_redeem(&who, vtoken_id, vtoken_value)?; + ::Assets::burn_from( vtoken_id, &who, diff --git a/pallets/leverage-staking/src/tests.rs b/pallets/leverage-staking/src/tests.rs index 00e8aa916..7534b33e2 100644 --- a/pallets/leverage-staking/src/tests.rs +++ b/pallets/leverage-staking/src/tests.rs @@ -20,15 +20,13 @@ use crate::mock::*; use frame_support::{assert_noop, assert_ok, BoundedVec}; use lend_market::{AccountBorrows, BorrowSnapshot}; -fn init_lend_market() { +fn init() { assert_ok!(LendMarket::add_market(RuntimeOrigin::root(), DOT, market_mock(VKSM))); assert_ok!(LendMarket::activate_market(RuntimeOrigin::root(), DOT)); assert_ok!(LendMarket::add_market(RuntimeOrigin::root(), VDOT, market_mock(VBNC))); assert_ok!(LendMarket::activate_market(RuntimeOrigin::root(), VDOT)); TimestampPallet::set_timestamp(6000); -} -fn init_stable_pool() { assert_ok!(StablePool::create_pool( RuntimeOrigin::root(), vec![DOT, VDOT], @@ -49,11 +47,11 @@ fn init_stable_pool() { let amounts = vec![unit(1000), unit(1000)]; assert_ok!(StablePool::add_liquidity(RuntimeOrigin::signed(0), 0, amounts, 0)); } + #[test] fn flash_loan_deposit() { ExtBuilder::default().new_test_ext().build().execute_with(|| { - init_lend_market(); - init_stable_pool(); + init(); assert_ok!(VtokenMinting::set_minimum_mint(RuntimeOrigin::signed(1), DOT, 0)); assert_ok!(VtokenMinting::mint(Some(3).into(), DOT, 100_000_000, BoundedVec::default())); assert_ok!(LendMarket::mint(RuntimeOrigin::signed(1), DOT, unit(100))); @@ -80,8 +78,7 @@ fn flash_loan_deposit() { #[test] fn flash_loan_repay() { ExtBuilder::default().new_test_ext().build().execute_with(|| { - init_lend_market(); - init_stable_pool(); + init(); assert_ok!(VtokenMinting::set_minimum_mint(RuntimeOrigin::signed(1), DOT, 0)); assert_ok!(VtokenMinting::mint(Some(3).into(), DOT, 100_000_000, BoundedVec::default())); assert_ok!(LendMarket::mint(RuntimeOrigin::signed(1), DOT, unit(100))); @@ -98,7 +95,7 @@ fn flash_loan_repay() { assert_ok!(LeverageStaking::flash_loan_repay( RuntimeOrigin::signed(1), DOT, - FixedU128::from_inner(unit(1_000_000)), + Some(FixedU128::from_inner(unit(1_000_000))), )); assert_eq!( AccountBorrows::::get(DOT, 1), @@ -114,12 +111,12 @@ fn flash_loan_repay() { assert_ok!(LeverageStaking::flash_loan_repay( RuntimeOrigin::signed(1), DOT, - FixedU128::from_inner(unit(100_000)), + Some(FixedU128::from_inner(unit(100_000))), )); assert_eq!( AccountBorrows::::get(DOT, 1), BorrowSnapshot { principal: 0, borrow_index: 1.into() }, ); - assert_eq!(AccountFlashLoans::::get(DOT, 1), None,); + assert_eq!(AccountFlashLoans::::get(DOT, 1), None); }); } diff --git a/pallets/stable-pool/src/lib.rs b/pallets/stable-pool/src/lib.rs index d8350b474..dbca9ff73 100644 --- a/pallets/stable-pool/src/lib.rs +++ b/pallets/stable-pool/src/lib.rs @@ -828,7 +828,7 @@ impl Pallet { currency_id_out: PoolTokenIndex, amount: T::Balance, ) -> Result { - let mut pool_info = T::StableAsset::pool(pool_id) + let pool_info = T::StableAsset::pool(pool_id) .ok_or(nutsfinance_stable_asset::Error::::PoolNotFound)?; let dy = Self::upscale( amount, @@ -886,9 +886,13 @@ impl Pallet { currency_id_out: &AssetIdOf, ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> { Pools::::iter().find_map(|(pool_id, pool_info)| { - if pool_info.assets.get(0) == Some(currency_id_in) && pool_info.assets.get(1) == Some(currency_id_out) { + if pool_info.assets.get(0) == Some(currency_id_in) && + pool_info.assets.get(1) == Some(currency_id_out) + { Some((pool_id, 0, 1)) - } else if pool_info.assets.get(0) == Some(currency_id_out) && pool_info.assets.get(1) == Some(currency_id_in) { + } else if pool_info.assets.get(0) == Some(currency_id_out) && + pool_info.assets.get(1) == Some(currency_id_in) + { Some((pool_id, 1, 0)) } else { None diff --git a/pallets/stable-pool/src/traits.rs b/pallets/stable-pool/src/traits.rs index bf0747e6a..bec48b7fa 100644 --- a/pallets/stable-pool/src/traits.rs +++ b/pallets/stable-pool/src/traits.rs @@ -18,7 +18,6 @@ //! traits for stable-pool use crate::*; -use nutsfinance_stable_asset::StableAssetPoolInfo; pub trait StablePoolHandler { type Balance; @@ -243,26 +242,26 @@ impl StablePoolHandler for () { } fn get_swap_output( - pool_id: StableAssetPoolId, - currency_id_in: PoolTokenIndex, - currency_id_out: PoolTokenIndex, - amount: Self::Balance, + _pool_id: StableAssetPoolId, + _currency_id_in: PoolTokenIndex, + _currency_id_out: PoolTokenIndex, + _amount: Self::Balance, ) -> Result { Ok(0) } fn get_swap_input( - pool_id: StableAssetPoolId, - currency_id_in: PoolTokenIndex, - currency_id_out: PoolTokenIndex, - amount: Self::Balance, + _pool_id: StableAssetPoolId, + _currency_id_in: PoolTokenIndex, + _currency_id_out: PoolTokenIndex, + _amount: Self::Balance, ) -> Result { Ok(0) } fn get_pool_id( - currency_id_in: &Self::CurrencyId, - currency_id_out: &Self::CurrencyId, + _currency_id_in: &Self::CurrencyId, + _currency_id_out: &Self::CurrencyId, ) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> { None }