Skip to content

Commit

Permalink
Merge pull request #803 from galacticcouncil/otc_offchain_worker
Browse files Browse the repository at this point in the history
feat: OTC offchain worker
  • Loading branch information
mrq1911 authored Jun 21, 2024
2 parents 975196b + 6b381a4 commit f8df96e
Show file tree
Hide file tree
Showing 48 changed files with 3,178 additions and 539 deletions.
56 changes: 45 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
'pallets/dynamic-fees',
'pallets/duster',
'pallets/otc',
'pallets/otc-settlements',
'pallets/bonds',
'pallets/lbp',
'pallets/nft',
Expand Down Expand Up @@ -87,6 +88,7 @@ pallet-nft = { path = "pallets/nft", default-features = false }
pallet-omnipool = { path = "pallets/omnipool", default-features = false }
pallet-omnipool-liquidity-mining = { path = "pallets/omnipool-liquidity-mining", default-features = false }
pallet-otc = { path = "pallets/otc", default-features = false}
pallet-otc-settlements = { path = "pallets/otc-settlements", default-features = false}
pallet-relaychain-info = { path = "pallets/relaychain-info", default-features = false }
pallet-route-executor = { path = "pallets/route-executor", default-features = false }
pallet-stableswap = { path = "pallets/stableswap", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.22.4"
version = "1.22.5"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -30,6 +30,7 @@ pallet-duster = { workspace = true }
pallet-ema-oracle = { workspace = true }
warehouse-liquidity-mining = { workspace = true }
pallet-otc = { workspace = true }
pallet-otc-settlements = { workspace = true }
pallet-relaychain-info = { workspace = true }
pallet-route-executor = { workspace = true}
pallet-dca = { workspace = true}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/evm_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ fn dispatch_permit_should_increase_account_nonce_correctly() {

let hdx_balance = user_acc.balance(HDX);
let tx_fee = initial_user_hdx_balance - hdx_balance;
assert_eq!(tx_fee, 1_797_526_858_553);
assert_eq!(tx_fee, 1_797_084_195_590);
})
}

Expand Down
2 changes: 1 addition & 1 deletion math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = 'Apache-2.0'
name = "hydra-dx-math"
description = "A collection of utilities to make performing liquidity pool calculations more convenient."
repository = 'https://github.com/galacticcouncil/hydradx-math'
version = "8.1.1"
version = "8.1.2"

[dependencies]
primitive-types = {default-features = false, version = '0.12.0'}
Expand Down
2 changes: 1 addition & 1 deletion math/src/stableswap/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ pub fn calculate_spot_price(
let mut updated_reserves = asset_reserves.clone();
for reserve in updated_reserves.iter_mut() {
if reserve.0 == added_asset.0 {
reserve.1.amount += added_asset.1;
reserve.1.amount = reserve.1.amount.checked_add(added_asset.1)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-dca'
version = "1.4.8"
version = "1.4.9"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
8 changes: 4 additions & 4 deletions pallets/dca/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub type BlockNumber = u64;
pub type AssetId = u32;
type NamedReserveIdentifier = [u8; 8];

pub const BUY_DCA_FEE_IN_NATIVE: Balance = 1334471000;
pub const BUY_DCA_FEE_IN_DAI: Balance = 1174334480;
pub const SELL_DCA_FEE_IN_NATIVE: Balance = 1335115000;
pub const SELL_DCA_FEE_IN_DAI: Balance = 1174901200;
pub const BUY_DCA_FEE_IN_NATIVE: Balance = 1336361000;
pub const BUY_DCA_FEE_IN_DAI: Balance = 1175997680;
pub const SELL_DCA_FEE_IN_NATIVE: Balance = 1338448000;
pub const SELL_DCA_FEE_IN_DAI: Balance = 1177834240;

pub const HDX: AssetId = 0;
pub const LRNA: AssetId = 1;
Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/src/tests/on_initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ fn full_buy_dca_should_be_completed_when_some_execution_is_successful_but_not_en
assert_number_of_executed_buy_trades!(4);
assert_eq!(0, Currencies::reserved_balance(HDX, &ALICE));

let left_over_which_is_not_enough_for_last_trade = 9994662116000;
let left_over_which_is_not_enough_for_last_trade = 9994654556000;

assert_balance!(
ALICE,
Expand Down
32 changes: 16 additions & 16 deletions pallets/dca/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Autogenerated weights for `pallet_dca`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-05-24, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-06-20, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
Expand Down Expand Up @@ -72,10 +72,10 @@ impl WeightInfo for () {
/// Proof: `DCA::RetriesOnError` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`)
fn on_initialize_with_buy_trade() -> Weight {
// Proof Size summary in bytes:
// Measured: `54485`
// Measured: `54523`
// Estimated: `31902`
// Minimum execution time: 207_153_000 picoseconds.
Weight::from_parts(209_471_000, 31902)
// Minimum execution time: 207_400_000 picoseconds.
Weight::from_parts(211_361_000, 31902)
.saturating_add(RocksDbWeight::get().reads(17_u64))
.saturating_add(RocksDbWeight::get().writes(7_u64))
}
Expand All @@ -93,21 +93,21 @@ impl WeightInfo for () {
/// Proof: `DCA::RetriesOnError` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`)
fn on_initialize_with_sell_trade() -> Weight {
// Proof Size summary in bytes:
// Measured: `54593`
// Measured: `54631`
// Estimated: `31902`
// Minimum execution time: 206_729_000 picoseconds.
Weight::from_parts(210_115_000, 31902)
// Minimum execution time: 209_659_000 picoseconds.
Weight::from_parts(213_448_000, 31902)
.saturating_add(RocksDbWeight::get().reads(17_u64))
.saturating_add(RocksDbWeight::get().writes(7_u64))
}
/// Storage: `DCA::ScheduleIdsPerBlock` (r:1 w:0)
/// Proof: `DCA::ScheduleIdsPerBlock` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`)
fn on_initialize_with_empty_block() -> Weight {
// Proof Size summary in bytes:
// Measured: `1075`
// Measured: `1113`
// Estimated: `3566`
// Minimum execution time: 14_273_000 picoseconds.
Weight::from_parts(14_864_000, 3566).saturating_add(RocksDbWeight::get().reads(1_u64))
// Minimum execution time: 14_992_000 picoseconds.
Weight::from_parts(15_296_000, 3566).saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0)
/// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`)
Expand All @@ -133,10 +133,10 @@ impl WeightInfo for () {
/// Proof: `DCA::RemainingAmounts` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`)
fn schedule() -> Weight {
// Proof Size summary in bytes:
// Measured: `52618`
// Measured: `52656`
// Estimated: `29326`
// Minimum execution time: 153_135_000 picoseconds.
Weight::from_parts(155_526_000, 29326)
// Minimum execution time: 152_493_000 picoseconds.
Weight::from_parts(155_888_000, 29326)
.saturating_add(RocksDbWeight::get().reads(17_u64))
.saturating_add(RocksDbWeight::get().writes(8_u64))
}
Expand All @@ -156,10 +156,10 @@ impl WeightInfo for () {
/// Proof: `DCA::ScheduleOwnership` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
fn terminate() -> Weight {
// Proof Size summary in bytes:
// Measured: `2492`
// Measured: `2530`
// Estimated: `4714`
// Minimum execution time: 70_794_000 picoseconds.
Weight::from_parts(71_685_000, 4714)
// Minimum execution time: 71_135_000 picoseconds.
Weight::from_parts(71_902_000, 4714)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(7_u64))
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/lbp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-lbp"
version = "4.8.3"
version = "4.8.4"
description = "HydraDX Liquidity Bootstrapping Pool Pallet"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
24 changes: 24 additions & 0 deletions pallets/lbp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,30 @@ benchmarks! {
assert!(<LBP::<T> as TradeExecution<T::RuntimeOrigin, T::AccountId, AssetId, Balance>>::calculate_buy(PoolType::LBP, asset_in, asset_out, amount).is_ok());
}
verify{}

calculate_spot_price_with_fee {
let caller = funded_account::<T>("caller", 0);
let fee_collector = funded_account::<T>("fee_collector", 0);
let asset_in: AssetId = ASSET_A_ID;
let asset_out: AssetId = ASSET_B_ID;
let amount : Balance = 100_000_000;
let max_limit: Balance = 1_000_000_000;

let pool_id = LBP::<T>::pair_account_from_assets(ASSET_A_ID, ASSET_B_ID);

LBP::<T>::create_pool(RawOrigin::Root.into(), caller.clone(), ASSET_A_ID, ASSET_A_AMOUNT, ASSET_B_ID, ASSET_B_AMOUNT, INITIAL_WEIGHT, FINAL_WEIGHT, WeightCurveType::Linear, DEFAULT_FEE, fee_collector, 0)?;
ensure!(PoolData::<T>::contains_key(&pool_id), "Pool does not exist.");

let start = BlockNumberFor::<T>::from(1u32);
let end = BlockNumberFor::<T>::from(11u32);

LBP::<T>::update_pool_data(RawOrigin::Signed(caller).into(), pool_id, None, Some(start), Some(end), None, None, None, None, None)?;

frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::from(2u32));

}: {
assert!(<LBP::<T> as TradeExecution<T::RuntimeOrigin, T::AccountId, AssetId, Balance>>::calculate_spot_price_with_fee(PoolType::LBP, asset_in, asset_out).is_ok());
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit f8df96e

Please sign in to comment.