Skip to content

Commit

Permalink
Merge branch 'eth-rollup-develop' into fix/reject-old-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa authored Nov 29, 2024
2 parents 6d561d0 + 0a07b8c commit 05f4b0a
Show file tree
Hide file tree
Showing 34 changed files with 1,726 additions and 905 deletions.
281 changes: 142 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pallets/bootstrap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl orml_tokens::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type CurrencyHooks = ();
type NontransferableTokens = Nothing;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/crowdloan-rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl orml_tokens::Config for Test {
type CurrencyHooks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type NontransferableTokens = Nothing;
}

parameter_types! {
Expand Down
3 changes: 2 additions & 1 deletion pallets/fee-lock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate as pallet_fee_lock;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{Contains, Everything},
traits::{Contains, Nothing},
weights::constants::RocksDbWeight,
PalletId,
};
Expand Down Expand Up @@ -68,6 +68,7 @@ impl orml_tokens::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type CurrencyHooks = ();
type NontransferableTokens = Nothing;
}

parameter_types! {
Expand Down
3 changes: 2 additions & 1 deletion pallets/issuance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::*;
use crate as pallet_issuance;
use frame_support::{
assert_ok, construct_runtime, derive_impl, parameter_types,
traits::{Contains, Everything, WithdrawReasons},
traits::{Contains, Nothing, WithdrawReasons},
PalletId,
};
use orml_traits::parameter_type_with_key;
Expand Down Expand Up @@ -79,6 +79,7 @@ impl orml_tokens::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type CurrencyHooks = ();
type NontransferableTokens = Nothing;
}

parameter_types! {
Expand Down
60 changes: 60 additions & 0 deletions pallets/market/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ pub trait MarketApi<BlockHash, Balance, TokenId> {
at: Option<BlockHash>,
) -> RpcResult<NumberOrHex>;

#[method(name = "market_calculate_sell_price_with_impact")]
fn calculate_sell_price_with_impact(
&self,
pool_id: TokenId,
sell_asset_id: TokenId,
sell_amount: NumberOrHex,
at: Option<BlockHash>,
) -> RpcResult<(NumberOrHex, NumberOrHex)>;

#[method(name = "market_calculate_buy_price")]
fn calculate_buy_price(
&self,
Expand All @@ -34,6 +43,15 @@ pub trait MarketApi<BlockHash, Balance, TokenId> {
at: Option<BlockHash>,
) -> RpcResult<NumberOrHex>;

#[method(name = "market_calculate_buy_price_with_impact")]
fn calculate_buy_price_with_impact(
&self,
pool_id: TokenId,
buy_asset_id: TokenId,
buy_amount: NumberOrHex,
at: Option<BlockHash>,
) -> RpcResult<(NumberOrHex, NumberOrHex)>;

#[method(name = "market_calculate_expected_amount_for_minting")]
fn calculate_expected_amount_for_minting(
&self,
Expand Down Expand Up @@ -130,6 +148,27 @@ where
})
}

fn calculate_sell_price_with_impact(
&self,
pool_id: TokenId,
sell_asset_id: TokenId,
sell_amount: NumberOrHex,
_at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<(NumberOrHex, NumberOrHex)> {
let api = self.client.runtime_api();
let at = self.client.info().best_hash;

api.calculate_sell_price_with_impact(
at,
pool_id,
sell_asset_id,
sell_amount.try_into_balance()?,
)
.map(|val| val.unwrap_or_default())
.map(|val| (val.0.into(), val.1.into()))
.map_err(|e| ErrorObject::owned(1, "Unable to serve the request", Some(format!("{:?}", e))))
}

fn calculate_buy_price(
&self,
pool_id: TokenId,
Expand All @@ -147,6 +186,27 @@ where
})
}

fn calculate_buy_price_with_impact(
&self,
pool_id: TokenId,
buy_asset_id: TokenId,
buy_amount: NumberOrHex,
_at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<(NumberOrHex, NumberOrHex)> {
let api = self.client.runtime_api();
let at = self.client.info().best_hash;

api.calculate_buy_price_with_impact(
at,
pool_id,
buy_asset_id,
buy_amount.try_into_balance()?,
)
.map(|val| val.unwrap_or_default())
.map(|val| (val.0.into(), val.1.into()))
.map_err(|e| ErrorObject::owned(1, "Unable to serve the request", Some(format!("{:?}", e))))
}

fn get_burn_amount(
&self,
pool_id: TokenId,
Expand Down
Loading

0 comments on commit 05f4b0a

Please sign in to comment.