Skip to content

Commit

Permalink
fix: 🐛 format
Browse files Browse the repository at this point in the history
  • Loading branch information
yooml committed Oct 19, 2023
1 parent e9c305c commit 3f57ddb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
19 changes: 8 additions & 11 deletions pallets/leverage-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,7 +133,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;

if let Some(flash_loan_info) = AccountFlashLoans::<T>::get(asset_id, &who) {
if let Some(_flash_loan_info) = AccountFlashLoans::<T>::get(asset_id, &who) {
Self::do_repay(&who, asset_id, None)?;
}

Expand Down Expand Up @@ -192,11 +188,11 @@ pub mod pallet {
pub fn flash_loan_repay(
origin: OriginFor<T>,
asset_id: AssetIdOf<T>,
rate: Rate,
rate: Option<Rate>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;

Self::do_repay(&who, asset_id, Some(rate))?;
Self::do_repay(&who, asset_id, rate)?;
Ok(().into())
}
}
Expand Down Expand Up @@ -249,6 +245,7 @@ impl<T: Config> Pallet<T> {
)?;
T::LendMarket::do_repay_borrow(&who, asset_id, token_value)?;
T::LendMarket::do_redeem(&who, vtoken_id, vtoken_value)?;

<T as lend_market::Config>::Assets::burn_from(
vtoken_id,
&who,
Expand Down
17 changes: 7 additions & 10 deletions pallets/leverage-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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)));
Expand All @@ -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)));
Expand All @@ -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::<Test>::get(DOT, 1),
Expand All @@ -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::<Test>::get(DOT, 1),
BorrowSnapshot { principal: 0, borrow_index: 1.into() },
);
assert_eq!(AccountFlashLoans::<Test>::get(DOT, 1), None,);
assert_eq!(AccountFlashLoans::<Test>::get(DOT, 1), None);
});
}
10 changes: 7 additions & 3 deletions pallets/stable-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ impl<T: Config> Pallet<T> {
currency_id_out: PoolTokenIndex,
amount: T::Balance,
) -> Result<T::Balance, DispatchError> {
let mut pool_info = T::StableAsset::pool(pool_id)
let pool_info = T::StableAsset::pool(pool_id)
.ok_or(nutsfinance_stable_asset::Error::<T>::PoolNotFound)?;
let dy = Self::upscale(
amount,
Expand Down Expand Up @@ -886,9 +886,13 @@ impl<T: Config> Pallet<T> {
currency_id_out: &AssetIdOf<T>,
) -> Option<(StableAssetPoolId, PoolTokenIndex, PoolTokenIndex)> {
Pools::<T>::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
Expand Down
21 changes: 10 additions & 11 deletions pallets/stable-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

//! traits for stable-pool
use crate::*;
use nutsfinance_stable_asset::StableAssetPoolInfo;

pub trait StablePoolHandler {
type Balance;
Expand Down Expand Up @@ -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<Self::Balance, DispatchError> {
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<Self::Balance, DispatchError> {
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
}
Expand Down

0 comments on commit 3f57ddb

Please sign in to comment.