serai/substrate/client/tests/common/dex.rs
akildemir 899a9604e1
Add Dex pallet (#407)
* Move pallet-asset-conversion

* update licensing

* initial integration

* Integrate Currency & Assets types

* integrate liquidity tokens

* fmt

* integrate dex pallet tests

* fmt

* compilation error fixes

* integrate dex benchmarks

* fmt

* cargo clippy

* replace all occurrences of "asset" with "coin"

* add the actual add liq/swap logic to in-instructions

* add client side & tests

* fix deny

* Lint and changes

- 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

* Fix rebase artifacts

* Correct other rebase artifact

* Correct CI specification for liquidity-tokens

* Correct primitives' test to the standardized pallet account scheme

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
2023-11-05 12:02:34 -05:00

55 lines
1.2 KiB
Rust

use serai_runtime::primitives::{Coin, Amount};
use serai_client::{Serai, SeraiDex, PairSigner};
use sp_core::{sr25519::Pair, Pair as PairTrait};
use subxt::config::extrinsic_params::BaseExtrinsicParamsBuilder;
use crate::common::tx::publish_tx;
#[allow(dead_code)]
pub async fn add_liquidity(
serai: &Serai,
coin: Coin,
coin_amount: Amount,
sri_amount: Amount,
nonce: u32,
pair: Pair,
) -> [u8; 32] {
let address = pair.public();
let tx = serai
.sign(
&PairSigner::new(pair),
&SeraiDex::add_liquidity(coin, coin_amount, sri_amount, Amount(1), Amount(1), address.into()),
nonce,
BaseExtrinsicParamsBuilder::new(),
)
.unwrap();
publish_tx(serai, &tx).await
}
#[allow(dead_code)]
pub async fn swap(
serai: &Serai,
from_coin: Coin,
to_coin: Coin,
amount_in: Amount,
amount_out_min: Amount,
nonce: u32,
pair: Pair,
) -> [u8; 32] {
let address = pair.public();
let tx = serai
.sign(
&PairSigner::new(pair),
&SeraiDex::swap(from_coin, to_coin, amount_in, amount_out_min, address.into()),
nonce,
BaseExtrinsicParamsBuilder::new(),
)
.unwrap();
publish_tx(serai, &tx).await
}