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

Feature/market improvs #845

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
271 changes: 136 additions & 135 deletions Cargo.lock

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,137 @@ ver-api = { git = "https://github.com/gasp-xyz/polkadot-sdk", branch = "eth-roll
[patch."https://github.com/paritytech/polkadot-sdk"]
# ... which satisfies git dependency `sp-crypto-ec-utils` of package `sp-ark-bls12-381 v0.4.2 (https://github.com/paritytech/arkworks-substrate#caa2eed7)`
sp-crypto-ec-utils = { git = "https://github.com/gasp-xyz/polkadot-sdk", branch = "eth-rollup-develop" }

# patch generated by './scripts/dev_manifest.sh ../polkadot-sdk'
[patch."https://github.com/gasp-xyz/polkadot-sdk"]
substrate-test-runtime = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-test-runtime-client = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-test-client = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-transaction-payment = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-transaction-payment-rpc = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-collective-mangata = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-proxy = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-identity = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-sudo-mangata = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
mangata-support = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-utility-mangata = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-authorship = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-grandpa = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-vesting-mangata = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-system = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-system-benchmarking = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-system-rpc-runtime-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-support = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-support-procedural = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-support-procedural-tools = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-support-procedural-tools-derive = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-balances = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-aura = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-benchmarking = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-treasury = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-try-runtime = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-timestamp = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-babe = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-membership = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-utility = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-executive = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
pallet-session = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-wasm-builder = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
fork-tree = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-build-script-utils = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
frame-benchmarking-cli = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-bip39 = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
substrate-prometheus-endpoint = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-database = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-runtime-interface = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-runtime-interface-proc-macro = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-consensus-grandpa = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-consensus = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-consensus-aura = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-consensus-babe = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-consensus-slots = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-tracing = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-crypto-hashing = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-crypto-hashing-proc-macro = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-ver = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-maybe-compressed-blob = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-core = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-state-machine = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-keystore = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-metadata-ir = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-statement-store = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-weights = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-io = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-runtime = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-inherents = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-transaction-pool = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-std = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-storage = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-panic-handler = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-debug-derive = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-blockchain = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-externalities = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-mixnet = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-trie = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
mangata-types = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-version = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-version-proc-macro = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-block-builder = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-keyring = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-staking = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-wasm-interface = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-transaction-storage-proof = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
extrinsic-shuffler = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-arithmetic = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-api-proc-macro = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-offchain = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-timestamp = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-application-crypto = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-rpc = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
ver-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-genesis-builder = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sp-session = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-consensus-grandpa = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-consensus = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-consensus-aura = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-consensus-slots = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-tracing = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-tracing-proc-macro = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-rpc-spec-v2 = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-state-db = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-proposer-metrics = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-keystore = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-basic-authorship-ver = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-rpc-server = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-bitswap = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-transactions = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-common = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-light = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-sync = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-informant = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-transaction-pool = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-transaction-pool-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-utils = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-cli = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-chain-spec = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-chain-spec-derive = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-block-builder-ver = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-mixnet = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-block-builder = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-allocator = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-network-gossip = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-client-db = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-client-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-sysinfo = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-executor = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-executor-wasmtime = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-executor-common = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-executor-polkavm = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-telemetry = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-offchain = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-service = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-rpc = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
sc-rpc-api = { git = "https://github.com//gasp-xyz/polkadot-sdk", branch = "feature/market-improvs" }
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
Loading