Skip to content

Commit

Permalink
Lint and changes
Browse files Browse the repository at this point in the history
- Renames InInstruction::AddLiquidity to InInstruction::SwapAndAddLiquidity
- Makes create_pool an internal function
- Makes dex-pallet exclusively create pools against a native coin
- Removes various fees
- Adds new crates to GH workflow
  • Loading branch information
kayabaNerve committed Nov 5, 2023
1 parent 15a28d9 commit a844084
Show file tree
Hide file tree
Showing 23 changed files with 529 additions and 818 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
-p serai-primitives \
-p serai-coins-primitives \
-p serai-coins-pallet \
-p serai-liquidity-tokens-primitives \
-p serai-dex-primitives \
-p serai-dex-pallet \
-p serai-validator-sets-primitives \
-p serai-validator-sets-pallet \
-p serai-in-instructions-primitives \
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ exceptions = [
{ allow = ["AGPL-3.0"], name = "serai-coordinator" },

{ allow = ["AGPL-3.0"], name = "serai-coins-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-dex-pallet" },
{ allow = ["AGPL-3.0"], name = "serai-dex-primitives" },
{ allow = ["AGPL-3.0"], name = "serai-liquidity-tokens-pallet" },
{ allow = ["AGPL-3.0"], name = "serai-dex-primitives" },
{ allow = ["AGPL-3.0"], name = "serai-dex-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-in-instructions-pallet" },

Expand Down
31 changes: 6 additions & 25 deletions substrate/client/src/serai/dex.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use sp_core::bounded_vec::BoundedVec;
use serai_runtime::{
primitives::{SeraiAddress, Amount, Coin},
dex, Dex, Runtime,
};

use subxt::tx::Payload;
use sp_core::bounded_vec::BoundedVec;

use crate::{TemporalSerai, SeraiError, Composite, scale_composite};
use crate::{SeraiError, Composite, TemporalSerai, scale_composite};

const PALLET: &str = "Dex";

Expand All @@ -16,28 +16,9 @@ pub type DexEvent = dex::Event<Runtime>;
pub struct SeraiDex<'a>(pub(crate) TemporalSerai<'a>);
impl<'a> SeraiDex<'a> {
pub async fn all_events(&self) -> Result<Vec<DexEvent>, SeraiError> {
self
.0
.events::<Dex, _>(|event| {
matches!(
event,
DexEvent::PoolCreated { .. } |
DexEvent::LiquidityAdded { .. } |
DexEvent::SwapExecuted { .. } |
DexEvent::LiquidityRemoved { .. } |
DexEvent::Transfer { .. }
)
})
.await
self.0.events::<Dex, _>(|_| true).await
}

pub fn create_pool(coin: Coin) -> Payload<Composite<()>> {
Payload::new(
PALLET,
"create_pool",
scale_composite(dex::Call::<Runtime>::create_pool { coin1: coin, coin2: Coin::Serai }),
)
}
pub fn add_liquidity(
coin: Coin,
coin_amount: Amount,
Expand Down Expand Up @@ -69,11 +50,11 @@ impl<'a> SeraiDex<'a> {
address: SeraiAddress,
) -> Payload<Composite<()>> {
let path = if to_coin.is_native() {
BoundedVec::truncate_from(vec![from_coin, Coin::Serai])
BoundedVec::try_from(vec![from_coin, Coin::Serai]).unwrap()
} else if from_coin.is_native() {
BoundedVec::truncate_from(vec![Coin::Serai, to_coin])
BoundedVec::try_from(vec![Coin::Serai, to_coin]).unwrap()
} else {
BoundedVec::truncate_from(vec![from_coin, Coin::Serai, to_coin])
BoundedVec::try_from(vec![from_coin, Coin::Serai, to_coin]).unwrap()
};

Payload::new(
Expand Down
12 changes: 6 additions & 6 deletions substrate/client/src/serai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ use serai_runtime::{

pub mod coins;
pub use coins::SeraiCoins;
pub mod in_instructions;
pub use in_instructions::SeraiInInstructions;
pub mod dex;
pub use dex::SeraiDex;
pub mod in_instructions;
pub use in_instructions::SeraiInInstructions;
pub mod validator_sets;
pub use validator_sets::SeraiValidatorSets;

Expand Down Expand Up @@ -349,14 +349,14 @@ impl<'a> TemporalSerai<'a> {
SeraiCoins(self)
}

pub fn in_instructions(self) -> SeraiInInstructions<'a> {
SeraiInInstructions(self)
}

pub fn dex(self) -> SeraiDex<'a> {
SeraiDex(self)
}

pub fn in_instructions(self) -> SeraiInInstructions<'a> {
SeraiInInstructions(self)
}

pub fn validator_sets(self) -> SeraiValidatorSets<'a> {
SeraiValidatorSets(self)
}
Expand Down
16 changes: 0 additions & 16 deletions substrate/client/tests/common/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ use subxt::config::extrinsic_params::BaseExtrinsicParamsBuilder;

use crate::common::{serai, tx::publish_tx};

#[allow(dead_code)]
pub async fn create_pool(coin: Coin, nonce: u32, pair: Pair) -> [u8; 32] {
let serai = serai().await;

let tx = serai
.sign(
&PairSigner::new(pair),
&SeraiDex::create_pool(coin),
nonce,
BaseExtrinsicParamsBuilder::new(),
)
.unwrap();

publish_tx(&tx).await
}

#[allow(dead_code)]
pub async fn add_liquidity(
coin: Coin,
Expand Down
Loading

0 comments on commit a844084

Please sign in to comment.