Skip to content

Commit

Permalink
"delta" => "change"
Browse files Browse the repository at this point in the history
  • Loading branch information
AlastairHolmes committed Oct 30, 2023
1 parent 7a42068 commit d31a954
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions api/bin/chainflip-lp-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub trait Rpc {
pair_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size_delta: IncreaseOrDecrease<RangeOrderSizeJson>,
size_change: IncreaseOrDecrease<RangeOrderSizeJson>,
) -> Result<Vec<RangeOrderReturn>, AnyhowRpcError>;

#[method(name = "set_range_order")]
Expand All @@ -129,7 +129,7 @@ pub trait Rpc {
buy_asset: Asset,
id: OrderIdJson,
tick: Option<Tick>,
amount_delta: IncreaseOrDecrease<NumberOrHex>,
amount_change: IncreaseOrDecrease<NumberOrHex>,
) -> Result<Vec<LimitOrderReturn>, AnyhowRpcError>;

#[method(name = "set_limit_order")]
Expand Down Expand Up @@ -217,7 +217,7 @@ impl RpcServer for RpcServerImpl {
pair_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size_delta: IncreaseOrDecrease<RangeOrderSizeJson>,
size_change: IncreaseOrDecrease<RangeOrderSizeJson>,
) -> Result<Vec<RangeOrderReturn>, AnyhowRpcError> {
Ok(self
.api
Expand All @@ -227,7 +227,7 @@ impl RpcServer for RpcServerImpl {
pair_asset,
id.try_into()?,
tick_range,
size_delta.try_map(|size| size.try_into())?,
size_change.try_map(|size| size.try_into())?,
)
.await?)
}
Expand All @@ -253,7 +253,7 @@ impl RpcServer for RpcServerImpl {
buy_asset: Asset,
id: OrderIdJson,
tick: Option<Tick>,
amount_delta: IncreaseOrDecrease<NumberOrHex>,
amount_change: IncreaseOrDecrease<NumberOrHex>,
) -> Result<Vec<LimitOrderReturn>, AnyhowRpcError> {
Ok(self
.api
Expand All @@ -263,7 +263,7 @@ impl RpcServer for RpcServerImpl {
buy_asset,
id.try_into()?,
tick,
amount_delta.try_map(try_parse_number_or_hex)?,
amount_change.try_map(try_parse_number_or_hex)?,
)
.await?)
}
Expand Down
14 changes: 7 additions & 7 deletions api/lib/src/lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct LimitOrderReturn {
amount_total: AssetAmount,
collected_fees: AssetAmount,
bought_amount: AssetAmount,
amount_delta: Option<IncreaseOrDecrease<AssetAmount>>,
amount_change: Option<IncreaseOrDecrease<AssetAmount>>,
}

fn collect_limit_order_returns(
Expand All @@ -79,7 +79,7 @@ fn collect_limit_order_returns(
.filter_map(|event| match event {
state_chain_runtime::RuntimeEvent::LiquidityPools(
pallet_cf_pools::Event::LimitOrderUpdated {
amount_delta,
amount_change,
amount_total,
collected_fees,
bought_amount,
Expand All @@ -97,7 +97,7 @@ fn collect_limit_order_returns(
amount_total,
collected_fees,
bought_amount,
amount_delta,
amount_change,
}),
_ => None,
})
Expand Down Expand Up @@ -173,7 +173,7 @@ pub trait LpApi: SignedExtrinsicApi {
pair_asset: Asset,
id: OrderId,
option_tick_range: Option<Range<Tick>>,
size_delta: IncreaseOrDecrease<RangeOrderSize>,
size_change: IncreaseOrDecrease<RangeOrderSize>,
) -> Result<Vec<RangeOrderReturn>> {
// Submit the mint order
let (_tx_hash, events, ..) = self
Expand All @@ -182,7 +182,7 @@ pub trait LpApi: SignedExtrinsicApi {
pair_asset,
id,
option_tick_range,
size_delta,
size_change,
})
.await
.until_in_block()
Expand Down Expand Up @@ -221,7 +221,7 @@ pub trait LpApi: SignedExtrinsicApi {
buy_asset: Asset,
id: OrderId,
option_tick: Option<Tick>,
amount_delta: IncreaseOrDecrease<AssetAmount>,
amount_change: IncreaseOrDecrease<AssetAmount>,
) -> Result<Vec<LimitOrderReturn>> {
// Submit the mint order
let (_tx_hash, events, ..) = self
Expand All @@ -230,7 +230,7 @@ pub trait LpApi: SignedExtrinsicApi {
buy_asset,
id,
option_tick,
amount_delta,
amount_change,
})
.await
.until_in_block()
Expand Down
30 changes: 15 additions & 15 deletions state-chain/pallets/cf-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ pub mod pallet {
buy_asset: Asset,
id: OrderId,
tick: Tick,
amount_delta: Option<IncreaseOrDecrease<AssetAmount>>,
amount_change: Option<IncreaseOrDecrease<AssetAmount>>,
amount_total: AssetAmount,
collected_fees: AssetAmount,
bought_amount: AssetAmount,
Expand Down Expand Up @@ -705,7 +705,7 @@ pub mod pallet {
pair_asset: Asset,
id: OrderId,
option_tick_range: Option<core::ops::Range<Tick>>,
size_delta: IncreaseOrDecrease<RangeOrderSize>,
size_change: IncreaseOrDecrease<RangeOrderSize>,
) -> DispatchResult {
ensure!(
T::SafeMode::get().range_order_update_enabled,
Expand Down Expand Up @@ -761,7 +761,7 @@ pub mod pallet {
asset_pair,
id,
tick_range,
size_delta.map(|size| match size {
size_change.map(|size| match size {
RangeOrderSize::Liquidity { liquidity } =>
range_orders::Size::Liquidity { liquidity },
RangeOrderSize::AssetAmounts { maximum, minimum } =>
Expand Down Expand Up @@ -862,7 +862,7 @@ pub mod pallet {
buy_asset: any::Asset,
id: OrderId,
option_tick: Option<Tick>,
amount_delta: IncreaseOrDecrease<AssetAmount>,
amount_change: IncreaseOrDecrease<AssetAmount>,
) -> DispatchResult {
ensure!(
T::SafeMode::get().limit_order_update_enabled,
Expand Down Expand Up @@ -912,7 +912,7 @@ pub mod pallet {
asset_pair,
id,
tick,
amount_delta.map(|amount| amount.into()),
amount_change.map(|amount| amount.into()),
/* allow_noop */ false,
)?;

Expand Down Expand Up @@ -1222,7 +1222,7 @@ impl<T: Config> Pallet<T> {
delta: IncreaseOrDecrease<cf_amm::common::Amount>,
allow_noop: bool,
) -> Result<AssetAmount, DispatchError> {
let (amount_delta, position_info, collected) = match delta {
let (amount_change, position_info, collected) = match delta {
IncreaseOrDecrease::Increase(amount) => {
let (collected, position_info) = match pool.pool_state.collect_and_mint_limit_order(
&(lp.clone(), id),
Expand Down Expand Up @@ -1293,10 +1293,10 @@ impl<T: Config> Pallet<T> {
tick,
collected,
position_info,
delta.map(|_| amount_delta),
delta.map(|_| amount_change),
)?;

Ok(amount_delta)
Ok(amount_change)
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -1309,7 +1309,7 @@ impl<T: Config> Pallet<T> {
delta: IncreaseOrDecrease<range_orders::Size>,
allow_noop: bool,
) -> Result<AssetAmounts, DispatchError> {
let (liquidity_delta, position_info, assets_delta, collected) = match delta {
let (liquidity_change, position_info, assets_delta, collected) = match delta {
IncreaseOrDecrease::Increase(size) => {
let (assets_debited, minted_liquidity, collected, position_info) =
match pool.pool_state.collect_and_mint_range_order(
Expand Down Expand Up @@ -1394,7 +1394,7 @@ impl<T: Config> Pallet<T> {
range_orders.insert(id, tick_range.clone());
}

let zero_delta = *liquidity_delta.abs() == 0;
let zero_delta = *liquidity_change.abs() == 0;

if !zero_delta || collected_fees != Default::default() {
Self::deposit_event(Event::<T>::RangeOrderUpdated {
Expand All @@ -1408,7 +1408,7 @@ impl<T: Config> Pallet<T> {
None
} else {
Some(
liquidity_delta.map(|liquidity| RangeOrderDelta {
liquidity_change.map(|liquidity| RangeOrderDelta {
liquidity,
amounts: assets_delta,
}),
Expand Down Expand Up @@ -1676,7 +1676,7 @@ impl<T: Config> Pallet<T> {
tick: Tick,
collected: Collected,
position_info: PositionInfo,
amount_delta: IncreaseOrDecrease<AssetAmount>,
amount_change: IncreaseOrDecrease<AssetAmount>,
) -> DispatchResult {
let collected_fees = asset_pair.try_credit_asset(lp, !side, collected.fees)?;
let bought_amount = asset_pair.try_credit_asset(lp, !side, collected.bought_amount)?;
Expand All @@ -1692,7 +1692,7 @@ impl<T: Config> Pallet<T> {
limit_orders.entry(lp.clone()).or_default().insert(order, tick);
}

let zero_delta = *amount_delta.abs() == 0;
let zero_delta = *amount_change.abs() == 0;

if !zero_delta ||
collected_fees != Default::default() ||
Expand All @@ -1704,11 +1704,11 @@ impl<T: Config> Pallet<T> {
buy_asset: asset_pair.canonical_asset_pair.side_to_asset(!side),
id: order,
tick,
amount_delta: {
amount_change: {
if zero_delta {
None
} else {
Some(amount_delta)
Some(amount_change)
}
},
amount_total: position_info.amount.try_into()?,
Expand Down
6 changes: 3 additions & 3 deletions state-chain/pallets/cf-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ fn pallet_limit_order_is_in_sync_with_pool() {
buy_asset: STABLE_ASSET,
id: 0,
tick: 0,
amount_delta: None,
amount_change: None,
amount_total: 0,
collected_fees: 100,
bought_amount: 100,
Expand All @@ -578,7 +578,7 @@ fn pallet_limit_order_is_in_sync_with_pool() {
buy_asset: STABLE_ASSET,
id: 0,
tick: 100,
amount_delta: None,
amount_change: None,
amount_total: 5,
collected_fees: 100998,
bought_amount: 100998,
Expand All @@ -589,7 +589,7 @@ fn pallet_limit_order_is_in_sync_with_pool() {
buy_asset: Asset::Eth,
id: 1,
tick: 100,
amount_delta: None,
amount_change: None,
amount_total: 910,
collected_fees: 8998,
bought_amount: 8998,
Expand Down

0 comments on commit d31a954

Please sign in to comment.