Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Nov 13, 2024
1 parent b6810e6 commit 49139d4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 60 deletions.
5 changes: 1 addition & 4 deletions pallets/liquidation/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ where
AssetId: From<<T as pallet_asset_registry::Config>::AssetId>,
<T as pallet_asset_registry::Config>::AssetId: From<AssetId>,
{
use frame_support::{
storage::with_transaction,
sp_runtime::TransactionOutcome,
};
use frame_support::{sp_runtime::TransactionOutcome, storage::with_transaction};

// Register new asset in asset registry
let name = b"DOT".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?;
Expand Down
17 changes: 7 additions & 10 deletions pallets/liquidation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@

#![cfg_attr(not(feature = "std"), no_std)]

use ethabi::ethereum_types::BigEndianHash;
use evm::{ExitReason, ExitSucceed};
use frame_support::{
pallet_prelude::*,
sp_runtime::traits::{AccountIdConversion, CheckedConversion},
traits::fungibles::{Inspect, Mutate},
traits::tokens::{Fortitude, Precision, Preservation},
PalletId,
sp_runtime::traits::{AccountIdConversion, CheckedConversion},
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor, RawOrigin};
use hydradx_traits::{
evm::{CallContext, Erc20Mapping, EvmAddress, InspectEvmAccounts, EVM},
router::{AmmTradeWeights, AmountInAndOut, AssetPair, RouteProvider, RouterT, Trade},
};
use sp_arithmetic::ArithmeticError;
use sp_core::{
H256, U256,
crypto::AccountId32,
};
use sp_std::{vec, vec::Vec};
use ethabi::ethereum_types::BigEndianHash;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use evm::{ExitReason, ExitSucceed};
use pallet_evm::GasWeightMapping;
use sp_arithmetic::ArithmeticError;
use sp_core::{crypto::AccountId32, H256, U256};
use sp_std::{vec, vec::Vec};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -145,7 +142,7 @@ pub mod pallet {
/// Provided route doesn't match the existing route
InvalidRoute,
/// Liquidation was not profitable enough to repay flash loan
NotProfitable
NotProfitable,
}

#[pallet::call]
Expand Down
4 changes: 1 addition & 3 deletions pallets/liquidation/src/tests/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

pub use crate::tests::mock::*;
use crate::{Error, Event};
use frame_support::{
assert_noop, assert_ok,
};
use frame_support::{assert_noop, assert_ok};
use hydradx_traits::{
evm::InspectEvmAccounts,
router::{AssetPair, RouteProvider},
Expand Down
12 changes: 9 additions & 3 deletions runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod tests;

mod benchmarking;
pub mod weights;
mod migration;
pub mod weights;

mod assets;
pub mod evm;
Expand Down Expand Up @@ -265,8 +265,14 @@ pub type UncheckedExtrinsic = fp_self_contained::UncheckedExtrinsic<Address, Run
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;
/// Executive: handles dispatch to the various modules.
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem, migration::OnRuntimeUpgradeMigration>;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
migration::OnRuntimeUpgradeMigration,
>;

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Expand Down
76 changes: 36 additions & 40 deletions runtime/hydradx/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,46 @@

use super::*;
use frame_support::{
traits::OnRuntimeUpgrade,
weights::Weight,
dispatch::{GetDispatchInfo, RawOrigin},
dispatch::{GetDispatchInfo, RawOrigin},
traits::OnRuntimeUpgrade,
weights::Weight,
};
pub struct OnRuntimeUpgradeMigration;
use super::Runtime;

pub fn bind_pallet_account() -> Weight
{
match EVMAccounts::bind_evm_address(RawOrigin::Signed(Liquidation::account_id()).into()) {
Ok(_) => {
log::info!(
target: "runtime::pallet_liquidation",
"Migration to v1 for Liquidation pallet"
);
},
Err(error) => {
log::info!(
target: "runtime::pallet_liquidation",
"Migration to v1 for Liquidation pallet failed: {:?}", error
);
}
}

let call = pallet_evm_accounts::Call::<Runtime>::bind_evm_address {
};

call.get_dispatch_info().weight
pub fn bind_pallet_account() -> Weight {
match EVMAccounts::bind_evm_address(RawOrigin::Signed(Liquidation::account_id()).into()) {
Ok(_) => {
log::info!(
target: "runtime::pallet_liquidation",
"Migration to v1 for Liquidation pallet"
);
}
Err(error) => {
log::info!(
target: "runtime::pallet_liquidation",
"Migration to v1 for Liquidation pallet failed: {:?}", error
);
}
}

let call = pallet_evm_accounts::Call::<Runtime>::bind_evm_address {};

call.get_dispatch_info().weight
}


impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(vec![])
}

fn on_runtime_upgrade() -> Weight
{
bind_pallet_account()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
Ok(())
}
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(vec![])
}

fn on_runtime_upgrade() -> Weight {
bind_pallet_account()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
Ok(())
}
}

0 comments on commit 49139d4

Please sign in to comment.