2023-12-07 07:30:09 +00:00
|
|
|
use serai_abi::primitives::{Coin, Amount};
|
2023-11-05 17:02:34 +00:00
|
|
|
|
2023-11-23 04:44:24 +00:00
|
|
|
use serai_client::{Serai, SeraiDex};
|
2023-11-05 17:02:34 +00:00
|
|
|
use sp_core::{sr25519::Pair, Pair as PairTrait};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-11-22 16:23:00 +00:00
|
|
|
let tx = serai.sign(
|
2023-11-23 04:44:24 +00:00
|
|
|
&pair,
|
2023-12-07 07:30:09 +00:00
|
|
|
SeraiDex::add_liquidity(coin, coin_amount, sri_amount, Amount(1), Amount(1), address.into()),
|
2023-11-22 16:23:00 +00:00
|
|
|
nonce,
|
2023-11-28 07:29:50 +00:00
|
|
|
0,
|
2023-11-22 16:23:00 +00:00
|
|
|
);
|
2023-11-05 17:02:34 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-11-22 16:23:00 +00:00
|
|
|
let tx = serai.sign(
|
2023-11-23 04:44:24 +00:00
|
|
|
&pair,
|
2023-12-07 07:30:09 +00:00
|
|
|
SeraiDex::swap(from_coin, to_coin, amount_in, amount_out_min, address.into()),
|
2023-11-22 16:23:00 +00:00
|
|
|
nonce,
|
|
|
|
Default::default(),
|
|
|
|
);
|
2023-11-05 17:02:34 +00:00
|
|
|
|
|
|
|
publish_tx(serai, &tx).await
|
|
|
|
}
|