-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,506 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#![cfg(test)] | ||
|
||
use ethabi::ethereum_types::H160; | ||
use fp_evm::ExitSucceed; | ||
use crate::polkadot_test_net::*; | ||
|
||
use frame_support::{ | ||
assert_noop, assert_ok, | ||
sp_runtime::RuntimeDebug, | ||
}; | ||
use hex_literal::hex; | ||
use orml_traits::currency::MultiCurrency; | ||
use orml_traits::MultiCurrencyExtended; | ||
use sp_runtime::FixedPointNumber; | ||
use sp_runtime::{FixedU128, Permill}; | ||
use xcm_emulator::TestExt; | ||
use hydradx_traits::evm::EvmAddress; | ||
use num_enum::{IntoPrimitive, TryFromPrimitive}; | ||
use fp_evm::ExitReason::Succeed; | ||
use fp_evm::ExitSucceed::Returned; | ||
use hydradx_traits::evm::{CallContext, EVM}; | ||
|
||
const PATH_TO_SNAPSHOT: &str = "evm-snapshot/SNAPSHOT"; | ||
|
||
#[module_evm_utility_macro::generate_function_selector] | ||
#[derive(RuntimeDebug, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)] | ||
#[repr(u32)] | ||
pub enum Function { | ||
GetPool = "getPool", | ||
} | ||
|
||
#[test] | ||
fn liquidation() { | ||
TestNet::reset(); | ||
hydra_live_ext(PATH_TO_SNAPSHOT).execute_with(|| { | ||
// let mut storage = pallet_evm::AccountCodes::<hydradx_runtime::Runtime>::iter(); | ||
// for i in storage { | ||
// println!("------ {:?}", i.0); | ||
// | ||
// } | ||
|
||
let contract = EvmAddress::from_slice(hex!("82db570265c37bE24caf5bc943428a6848c3e9a6").as_slice()); | ||
|
||
let data = Into::<u32>::into(Function::GetPool).to_be_bytes().to_vec(); | ||
let context = CallContext::new_view(contract); | ||
|
||
let (res, value) = hydradx_runtime::evm::Executor::<hydradx_runtime::Runtime>::view(context, data, 500_000); | ||
|
||
// assert_eq!(res, Succeed(Returned)); | ||
println!("---- {:?}", value); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
[package] | ||
name = 'pallet-liquidation' | ||
version = '1.0.0' | ||
description = 'A pallet for money market liquidations' | ||
authors = ['GalacticCouncil'] | ||
edition = '2021' | ||
license = 'Apache 2.0' | ||
repository = "https://github.com/galacticcouncil/Hydradx-node" | ||
|
||
[dependencies] | ||
# parity | ||
codec = { workspace = true, features = ["derive", "max-encoded-len"] } | ||
scale-info = { workspace = true } | ||
log = { workspace = true } | ||
|
||
# primitives | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-arithmetic = { workspace = true } | ||
|
||
# FRAME | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
|
||
evm = { workspace = true, features = ["with-codec"] } | ||
module-evm-utility-macro = { workspace = true } | ||
num_enum = { workspace = true, default-features = false } | ||
ethabi = { workspace = true } | ||
|
||
# HydraDX dependencies | ||
hydradx-traits = { workspace = true } | ||
|
||
# Optional imports for benchmarking | ||
frame-benchmarking = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
hydra-dx-math = { workspace = true } | ||
pallet-omnipool = { workspace = true } | ||
pallet-asset-registry = { workspace = true } | ||
pallet-route-executor = { workspace = true } | ||
pallet-balances = { workspace = true } | ||
pallet-currencies = { workspace = true } | ||
pallet-evm-accounts = { workspace = true } | ||
sp-api = { workspace = true } | ||
orml-traits = { workspace = true } | ||
orml-tokens = { workspace = true, features = ["std"] } | ||
hex-literal = { workspace = true } | ||
proptest = { workspace = true } | ||
pretty_assertions = { workspace = true } | ||
test-utils = { workspace = true } | ||
parking_lot = { workspace = true } | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
'codec/std', | ||
'frame-support/std', | ||
'frame-system/std', | ||
'sp-runtime/std', | ||
'sp-core/std', | ||
'sp-io/std', | ||
'sp-std/std', | ||
'sp-arithmetic/std', | ||
'sp-api/std', | ||
'scale-info/std', | ||
'orml-tokens/std', | ||
'orml-traits/std', | ||
'hydradx-traits/std', | ||
'hydra-dx-math/std', | ||
'frame-benchmarking/std', | ||
'pallet-balances/std', | ||
'pallet-currencies/std', | ||
'pallet-route-executor/std', | ||
'pallet-omnipool/std', | ||
'pallet-asset-registry/std', | ||
'pallet-evm-accounts/std', | ||
] | ||
|
||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"frame-system/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Pallet (Money market) Liquidation | ||
## Description | ||
|
||
## Notes | ||
|
||
## Dispatachable functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2020-2023 Intergalactic, Limited (GIB). SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
use frame_benchmarking::{account, benchmarks}; | ||
use frame_support::assert_ok; | ||
use frame_support::traits::fungibles::Mutate; | ||
use frame_system::RawOrigin; | ||
|
||
pub const ONE: Balance = 1_000_000_000_000; | ||
pub const HDX: u32 = 0; | ||
pub const DAI: u32 = 2; | ||
|
||
benchmarks! { | ||
where_clause { where | ||
AssetIdOf<T>: From<u32>, | ||
<T as crate::Config>::Currency: Mutate<T::AccountId, AssetId = AssetIdOf<T>, Balance = Balance>, | ||
T: crate::Config + pallet_otc::Config, | ||
} | ||
settle_otc_order { | ||
let account: T::AccountId = account("acc", 1, 1); | ||
|
||
<T as crate::Config>::Currency::mint_into(HDX.into(), &account, 1_000_000_000 * ONE)?; | ||
<T as crate::Config>::Currency::mint_into(DAI.into(), &account, 1_000_000_000 * ONE)?; | ||
|
||
assert_ok!( | ||
pallet_otc::Pallet::<T>::place_order(RawOrigin::Signed(account).into(), HDX.into(), DAI.into(), 100_000_000 * ONE, 202_020_001 * ONE, true) | ||
); | ||
|
||
let route = <T as crate::Config>::Router::get_route(AssetPair { | ||
asset_in: DAI.into(), | ||
asset_out: HDX.into(), | ||
}); | ||
|
||
}: _(RawOrigin::None, 0u32, 2 * ONE, route) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::mock::*; | ||
use frame_benchmarking::impl_benchmark_test_suite; | ||
|
||
impl_benchmark_test_suite!(Pallet, super::ExtBuilder::default().build().0, super::Test); | ||
} |
Oops, something went wrong.