Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/rpc-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Sep 21, 2023
2 parents 8a1993e + 6530140 commit e66bda1
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 371 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
/usr/local/cargo/registry
key: cargo-coverage-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }}
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin
run: cargo install cargo-tarpaulin@0.26.1
- name: Generate coverage report with cargo-tarpaulin
run: cargo tarpaulin --timeout 120 --workspace -e runtime-integration-test mangata-node common-runtime mangata-kusama-runtime mangata-rococo-runtime --exclude-files **/mock.rs **/weights.rs **/weights/* --out Xml
- name: Upload to codecov.io
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ jobs:
fast: false
- command: "yarn test-experimentalStaking"
fast: true
- command: "yarn test-crowdloan"
fast: false

runs-on: [self-hosted, compile]
timeout-minutes: 180
Expand Down
408 changes: 187 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,6 @@ frame-support = { git = "https://github.com/mangata-finance//substrate", branch
frame-support-procedural-tools-derive = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural-tools = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-curve = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-fn = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down Expand Up @@ -672,8 +670,6 @@ frame-support = { git = "https://github.com/mangata-finance//substrate", branch
frame-support-procedural-tools-derive = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural-tools = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-curve = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-fn = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down Expand Up @@ -858,8 +854,6 @@ frame-support = { git = "https://github.com/mangata-finance//substrate", branch
frame-support-procedural-tools-derive = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural-tools = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-support-procedural = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting-mangata = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-curve = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-staking-reward-fn = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down Expand Up @@ -925,7 +919,7 @@ sp-npos-elections = { git = "https://github.com/mangata-finance//substrate", bra
sp-authorship = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-storage = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }


# # patch generated by ./scripts/dev_manifest.sh
Expand Down Expand Up @@ -1045,8 +1039,6 @@ sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch =
# frame-support-procedural-tools-derive = { path = "../substrate/frame/support/procedural/tools/derive" }
# frame-support-procedural-tools = { path = "../substrate/frame/support/procedural/tools" }
# frame-support-procedural = { path = "../substrate/frame/support/procedural" }
# pallet-vesting-mangata-rpc-runtime-api = { path = "../substrate/frame/vesting-mangata/rpc/runtime-api" }
# pallet-vesting-mangata-rpc = { path = "../substrate/frame/vesting-mangata/rpc" }
# pallet-vesting-mangata = { path = "../substrate/frame/vesting-mangata" }
# pallet-staking-reward-curve = { path = "../substrate/frame/staking/reward-curve" }
# pallet-staking-reward-fn = { path = "../substrate/frame/staking/reward-fn" }
Expand Down Expand Up @@ -1228,8 +1220,6 @@ sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch =
# frame-support-procedural-tools-derive = { path = "../substrate/frame/support/procedural/tools/derive" }
# frame-support-procedural-tools = { path = "../substrate/frame/support/procedural/tools" }
# frame-support-procedural = { path = "../substrate/frame/support/procedural" }
# pallet-vesting-mangata-rpc-runtime-api = { path = "../substrate/frame/vesting-mangata/rpc/runtime-api" }
# pallet-vesting-mangata-rpc = { path = "../substrate/frame/vesting-mangata/rpc" }
# pallet-vesting-mangata = { path = "../substrate/frame/vesting-mangata" }
# pallet-staking-reward-curve = { path = "../substrate/frame/staking/reward-curve" }
# pallet-staking-reward-fn = { path = "../substrate/frame/staking/reward-fn" }
Expand Down Expand Up @@ -1411,8 +1401,6 @@ sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch =
# frame-support-procedural-tools-derive = { path = "../substrate/frame/support/procedural/tools/derive" }
# frame-support-procedural-tools = { path = "../substrate/frame/support/procedural/tools" }
# frame-support-procedural = { path = "../substrate/frame/support/procedural" }
# pallet-vesting-mangata-rpc-runtime-api = { path = "../substrate/frame/vesting-mangata/rpc/runtime-api" }
# pallet-vesting-mangata-rpc = { path = "../substrate/frame/vesting-mangata/rpc" }
# pallet-vesting-mangata = { path = "../substrate/frame/vesting-mangata" }
# pallet-staking-reward-curve = { path = "../substrate/frame/staking/reward-curve" }
# pallet-staking-reward-fn = { path = "../substrate/frame/staking/reward-fn" }
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

## Description

Reliable decentralized exchange (DEX) blockchain - interoperable with other blockchains using Polkadot. The exchange is using a consensus algorithm that solves MEV/frontrunning problems and makes all participants' access to trading opportunities equal.

The design of the blockchain guarantees fixed-fees that provides greater control of trading costs and higher arbitrage opportunity.
Assets on the exchange will serve multiple purposes- at the first iteration, they are the block producer’s stake and exchange liquidity at the same time, and more comes later.
Mangata operates as a cross-chain liquidity protocol, facilitating seamless transactions between Ethereum and various other blockchains through a Multirollup Interchain Infrastructure. We leverage the power of ZK-rollup, a second-layer (L2) solution, to ensure universal connectivity with first-layer (L1) blockchains. Additionally, our decentralized exchange platform is designed to provide robust protection against Miner Extractable Value (MEV) and frontrunning attempts, thereby safeguarding the interests of our users.

## API

Expand Down
5 changes: 0 additions & 5 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ default = ['mangata-kusama', 'mangata-rococo']
mangata-kusama = [
"mangata-kusama-runtime/std",
"xyk-rpc/std",
"pallet-vesting-mangata-rpc/std",
"polkadot-cli/kusama-native",
]
mangata-rococo = [
"mangata-rococo-runtime/std",
"xyk-rpc/std",
"pallet-vesting-mangata-rpc/std",
"polkadot-cli/rococo-native",
]
#disable-execution = ['mangata-kusama-runtime/disable-execution']
Expand Down Expand Up @@ -146,9 +144,6 @@ polkadot-test-service = { git = "https://github.com/mangata-finance/polkadot", b
xyk-rpc = { default-features = false, version = '2.0.0', path = '../pallets/xyk/rpc' }
xyk-runtime-api = { default-features = false, version = '2.0.0', path = '../pallets/xyk/runtime-api' }

pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance/substrate", default-features = false, branch = "mangata-dev" }
pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance/substrate", default-features = false, branch = "mangata-dev" }


[dev-dependencies]
sub-tokens = { git = "https://github.com/paritytech/substrate-debug-kit", branch = "master" }
Expand Down
16 changes: 2 additions & 14 deletions node/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ pub trait RuntimeApiCollection:
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ pallet_vesting_mangata_rpc::VestingMangataRuntimeApi<
Block,
AccountId,
TokenId,
Balance,
BlockNumber,
> + sp_consensus_aura::AuraApi<Block, AuraId>
+ sp_consensus_aura::AuraApi<Block, AuraId>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand All @@ -71,13 +65,7 @@ where
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ pallet_vesting_mangata_rpc::VestingMangataRuntimeApi<
Block,
AccountId,
TokenId,
Balance,
BlockNumber,
> + sp_consensus_aura::AuraApi<Block, AuraId>,
+ sp_consensus_aura::AuraApi<Block, AuraId>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
}
Expand Down
9 changes: 0 additions & 9 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,11 @@ where
C::Api: pallet_transaction_payment_mangata_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>,
C::Api: pallet_vesting_mangata_rpc::VestingMangataRuntimeApi<
Block,
AccountId,
TokenId,
Balance,
BlockNumber,
>,
C::Api: BlockBuilder<Block>,
C::Api: VerNonceApi<Block, AccountId>,
P: TransactionPool + Sync + Send + 'static,
{
use pallet_transaction_payment_mangata_rpc::{TransactionPayment, TransactionPaymentApiServer};
use pallet_vesting_mangata_rpc::{VestingMangata, VestingMangataApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use xyk_rpc::{Xyk, XykApiServer};

Expand All @@ -68,7 +60,6 @@ where
module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(Xyk::new(client.clone()).into_rpc())?;
module.merge(VestingMangata::new(client.clone()).into_rpc())?;

Ok(module)
}
16 changes: 2 additions & 14 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,7 @@ where
+ ver_api::VerApi<Block>
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ pallet_vesting_mangata_rpc::VestingMangataRuntimeApi<
Block,
AccountId,
TokenId,
Balance,
BlockNumber,
> + sp_consensus_aura::AuraApi<Block, AuraId>,
+ sp_consensus_aura::AuraApi<Block, AuraId>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
RB: Fn(
Expand Down Expand Up @@ -538,13 +532,7 @@ where
+ ver_api::VerApi<Block>
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ pallet_vesting_mangata_rpc::VestingMangataRuntimeApi<
Block,
AccountId,
TokenId,
Balance,
BlockNumber,
> + sp_consensus_aura::AuraApi<Block, AuraId>,
+ sp_consensus_aura::AuraApi<Block, AuraId>,
{
start_node_impl::<RuntimeApi, Executor, _, _>(
parachain_config,
Expand Down
26 changes: 25 additions & 1 deletion pallets/xyk/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_core::U256;
use sp_rpc::number::NumberOrHex;
use sp_runtime::traits::{Block as BlockT, MaybeDisplay, MaybeFromStr};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, MaybeDisplay, MaybeFromStr},
};
use sp_std::convert::{TryFrom, TryInto};
use std::sync::Arc;
use xyk_runtime_api::RpcAssetMetadata;
Expand Down Expand Up @@ -95,6 +98,9 @@ pub trait XykApi<BlockHash, Balance, TokenId, AccountId> {
at: Option<BlockHash>,
) -> RpcResult<NumberOrHex>;

#[method(name = "xyk_get_liq_tokens_for_trading")]
fn get_liq_tokens_for_trading(&self, at: Option<BlockHash>) -> RpcResult<Vec<TokenId>>;

#[method(name = "xyk_is_buy_asset_lock_free")]
fn is_buy_asset_lock_free(
&self,
Expand Down Expand Up @@ -372,6 +378,22 @@ where
})
}

fn get_liq_tokens_for_trading(
&self,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<TokenId>> {
let api = self.client.runtime_api();
let at = self.client.info().best_hash;

api.get_liq_tokens_for_trading(at).map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
1,
"Unable to serve the request",
Some(format!("{:?}", e)),
)))
})
}

fn is_buy_asset_lock_free(
&self,
path: sp_std::vec::Vec<TokenId>,
Expand All @@ -390,6 +412,7 @@ where
)))
})
}

fn is_sell_asset_lock_free(
&self,
path: sp_std::vec::Vec<TokenId>,
Expand All @@ -408,6 +431,7 @@ where
)))
})
}

fn get_tradeable_tokens(
&self,
at: Option<<Block as BlockT>::Hash>,
Expand Down
5 changes: 2 additions & 3 deletions pallets/xyk/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ sp_api::decl_runtime_apis! {
total_amount: Balance,
reserve_amount: Balance,
) -> Balance;

fn get_liq_tokens_for_trading(
) -> Vec<TokenId>;
fn is_buy_asset_lock_free(
path: sp_std::vec::Vec<TokenId>,
input_amount: Balance,
) -> Option<bool>;

fn is_sell_asset_lock_free(
path: sp_std::vec::Vec<TokenId>,
input_amount: Balance,
) -> Option<bool>;

fn get_tradeable_tokens() -> Vec<RpcAssetMetadata<TokenId>>;
}
}
3 changes: 2 additions & 1 deletion pallets/xyk/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ benchmarks! {

}: burn_liquidity(RawOrigin::Signed(caller.clone().into()), non_native_asset_id1.into(), non_native_asset_id2.into(), total_liquidity_after_minting)
verify {
assert!(Xyk::<T>::liquidity_pool(liquidity_asset_id).is_none());
assert_eq!(Xyk::<T>::liquidity_pool(liquidity_asset_id), Some((non_native_asset_id1.into(), non_native_asset_id2.into())));
assert_eq!(<T as Config>::Currency::total_issuance(liquidity_asset_id.into()).into(), 0);
}

provide_liquidity_with_conversion {
Expand Down
Loading

0 comments on commit e66bda1

Please sign in to comment.