Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OTC offchain worker #803

Merged
merged 76 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7df0e79
Merge branch 'feat/route-spot-price-provider' into otc_offchain_worker
Roznovjak Apr 11, 2024
935223d
Merge branch 'feat/route-spot-price-provider' into otc_offchain_worker
Roznovjak Apr 12, 2024
2864fff
implement offchain worker for OTC trades
Roznovjak Apr 15, 2024
1c21549
rebenchmark AMMs
Roznovjak Apr 15, 2024
69eec15
remove params from benchmarks
Roznovjak Apr 15, 2024
8946299
rebenchmark AMMs
Roznovjak Apr 15, 2024
391b3d3
rebenchmark router
Roznovjak Apr 15, 2024
2ecb60d
rebenchmark dca
Roznovjak Apr 15, 2024
c587394
fix benchmark test
Roznovjak Apr 15, 2024
2525c15
fix benchmarks
Roznovjak Apr 16, 2024
28041e4
rebenchmark otc settlements pallet
Roznovjak Apr 16, 2024
a47a864
update comments
Roznovjak Apr 16, 2024
8b66606
bump crate version
Roznovjak Apr 16, 2024
5b949d0
formatting
Roznovjak Apr 16, 2024
80f6ae3
Merge branch 'feat/route-spot-price-provider' into otc_offchain_worker
Roznovjak Apr 16, 2024
a10ef80
satisfy clippy
Roznovjak Apr 17, 2024
a1408dc
Merge branch 'master' into otc_offchain_worker
Roznovjak Apr 17, 2024
125b14c
update crate versions and remove unused param
Roznovjak Apr 17, 2024
0cb3695
satisfy clippy
Roznovjak Apr 17, 2024
03ccd18
remove unused code from benchmarks
Roznovjak Apr 17, 2024
1722038
include pov size in weight calculation
Roznovjak Apr 17, 2024
1b6af34
update comments
Roznovjak Apr 17, 2024
f34c26e
update comments
Roznovjak Apr 17, 2024
58088dc
satisfy clippy
Roznovjak Apr 17, 2024
d1559d7
Merge branch 'master' into otc_offchain_worker
Roznovjak Apr 19, 2024
979f816
resolve comments
Roznovjak Apr 25, 2024
883756a
Merge branch 'feat/route-spot-price-provider' into otc_offchain_worker
Roznovjak Apr 25, 2024
4619264
bump crate versions
Roznovjak Apr 25, 2024
29e7b95
Merge branch 'master' into otc_offchain_worker
Roznovjak May 9, 2024
b913f29
fix build
Roznovjak May 9, 2024
4d0ae34
remove origin check
Roznovjak May 13, 2024
5db265d
Merge branch 'master' into otc_offchain_worker
Roznovjak May 13, 2024
6e333fb
add MinTradingLimit
Roznovjak May 14, 2024
495c306
fixed unsafe math
dmoka May 14, 2024
a3a85dd
bump math version
dmoka May 14, 2024
adff992
fix bug as checked math returns a new instance
dmoka May 14, 2024
8f6d4eb
add readme file
Roznovjak May 14, 2024
b6431fe
move MaxIterations to the config
Roznovjak May 14, 2024
d8381d8
bump crate versions
Roznovjak May 14, 2024
fa0366d
Update pallets/otc-settlements/README.md
Roznovjak May 15, 2024
11a36c2
use otc order percentage to calculate min profit
Roznovjak May 15, 2024
e5f5659
satisfy clippy
Roznovjak May 15, 2024
3622848
bump crate version
Roznovjak May 15, 2024
ff3295c
Merge branch 'master' into otc_offchain_worker
Roznovjak May 24, 2024
fc26bdc
bump crate versions
Roznovjak May 24, 2024
b31d6bc
Merge branch 'master' into otc_offchain_worker
Roznovjak May 27, 2024
26c96c3
bump crate versions
Roznovjak May 27, 2024
9c8664c
Merge branch 'master' into otc_offchain_worker
Roznovjak May 27, 2024
46730d4
bump crate versions
Roznovjak May 27, 2024
bebcbde
update comments
Roznovjak May 28, 2024
ddaaa14
Merge branch 'master' into otc_offchain_worker
Roznovjak May 28, 2024
52516f7
resolve comments from the review
Roznovjak May 29, 2024
e64930c
bump crate version
Roznovjak May 29, 2024
b5254e8
formatting
Roznovjak May 29, 2024
73d67cc
fix benchmark build
Roznovjak May 29, 2024
8b166cc
rebenchmarking
Roznovjak May 29, 2024
4eb145a
Merge branch 'master' into otc_offchain_worker
Roznovjak May 29, 2024
2b614ba
bump runtime version
Roznovjak May 29, 2024
732430f
Merge branch 'master' into otc_offchain_worker
Roznovjak Jun 9, 2024
f89f4c4
subtract the initial balance from the profit
Roznovjak Jun 14, 2024
968ffae
update test
Roznovjak Jun 14, 2024
8026554
Merge branch 'master' into otc_offchain_worker
Roznovjak Jun 19, 2024
dedcd16
Update pallets/otc-settlements/src/lib.rs
Roznovjak Jun 19, 2024
ce1e3b4
resolve comments from the review
Roznovjak Jun 19, 2024
69e567b
rebenchmark lbp, omnipool, stableswap and xyk
Roznovjak Jun 20, 2024
04e23f4
fix lbp weights
Roznovjak Jun 20, 2024
d69120c
fix lbp weights
Roznovjak Jun 20, 2024
6dcc06d
rebenchmark router
Roznovjak Jun 20, 2024
800a68d
fix router weights
Roznovjak Jun 20, 2024
1bce5dc
fix incorrect weight function name
Roznovjak Jun 20, 2024
19ae17b
rebenchmark dca and otc-settlements
Roznovjak Jun 20, 2024
080cdf4
formatting
Roznovjak Jun 20, 2024
99c709d
bump crate versions
Roznovjak Jun 20, 2024
e879ff5
fix integration tests
Roznovjak Jun 20, 2024
4008c98
fix: use correct otc value
Roznovjak Jun 20, 2024
6b381a4
add comment
Roznovjak Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 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_816_997_321_901);
})
}

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
3 changes: 2 additions & 1 deletion pallets/dca/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// --pallet=pallet-dca
// --output=weights/dca.rs
// --extrinsic=*
// --extra

#![allow(unused_parens)]
#![allow(unused_imports)]
Expand Down Expand Up @@ -104,7 +105,7 @@ impl WeightInfo for () {
/// 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))
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
Loading