mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Dex improvements (#422)
* remove dex traits&balance types * remove liq tokens pallet in favor of coins-pallet instance * fix tests & benchmarks * remove liquidity tokens trait * fix CI * fix pr comments * Slight renamings * Add burn_with_instruction as a negative to LiquidityTokens CallFilter * Remove use of One, Zero, Saturating taits in dex pallet --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
@@ -24,8 +24,8 @@ impl<'a> SeraiCoins<'a> {
|
||||
self.0.events::<Coins, _>(|event| matches!(event, CoinsEvent::Mint { .. })).await
|
||||
}
|
||||
|
||||
pub async fn burn_events(&self) -> Result<Vec<CoinsEvent>, SeraiError> {
|
||||
self.0.events::<Coins, _>(|event| matches!(event, CoinsEvent::Burn { .. })).await
|
||||
pub async fn burn_with_instruction_events(&self) -> Result<Vec<CoinsEvent>, SeraiError> {
|
||||
self.0.events::<Coins, _>(|event| matches!(event, CoinsEvent::BurnWithInstruction { .. })).await
|
||||
}
|
||||
|
||||
pub async fn coin_supply(&self, coin: Coin) -> Result<Amount, SeraiError> {
|
||||
@@ -64,7 +64,15 @@ impl<'a> SeraiCoins<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn burn(instruction: OutInstructionWithBalance) -> Payload<Composite<()>> {
|
||||
Payload::new(PALLET, "burn", scale_composite(coins::Call::<Runtime>::burn { instruction }))
|
||||
pub fn burn(balance: Balance) -> Payload<Composite<()>> {
|
||||
Payload::new(PALLET, "burn", scale_composite(coins::Call::<Runtime>::burn { balance }))
|
||||
}
|
||||
|
||||
pub fn burn_with_instruction(instruction: OutInstructionWithBalance) -> Payload<Composite<()>> {
|
||||
Payload::new(
|
||||
PALLET,
|
||||
"burn_with_instruction",
|
||||
scale_composite(coins::Call::<Runtime>::burn_with_instruction { instruction }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,11 @@ impl<'a> SeraiDex<'a> {
|
||||
PALLET,
|
||||
"add_liquidity",
|
||||
scale_composite(dex::Call::<Runtime>::add_liquidity {
|
||||
coin1: coin,
|
||||
coin2: Coin::Serai,
|
||||
amount1_desired: coin_amount.0,
|
||||
amount2_desired: sri_amount.0,
|
||||
amount1_min: min_coin_amount.0,
|
||||
amount2_min: min_sri_amount.0,
|
||||
coin,
|
||||
coin_desired: coin_amount.0,
|
||||
sri_desired: sri_amount.0,
|
||||
coin_min: min_coin_amount.0,
|
||||
sri_min: min_sri_amount.0,
|
||||
mint_to: address.into(),
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -93,7 +93,7 @@ serai_test!(
|
||||
&serai
|
||||
.sign(
|
||||
&PairSigner::new(pair),
|
||||
&SeraiCoins::burn(instruction.clone()),
|
||||
&SeraiCoins::burn_with_instruction(instruction.clone()),
|
||||
0,
|
||||
BaseExtrinsicParamsBuilder::new(),
|
||||
)
|
||||
@@ -102,8 +102,8 @@ serai_test!(
|
||||
.await;
|
||||
|
||||
let serai = serai.as_of(block).coins();
|
||||
let events = serai.burn_events().await.unwrap();
|
||||
assert_eq!(events, vec![CoinsEvent::Burn { from: address.into(), instruction }]);
|
||||
let events = serai.burn_with_instruction_events().await.unwrap();
|
||||
assert_eq!(events, vec![CoinsEvent::BurnWithInstruction { from: address.into(), instruction }]);
|
||||
assert_eq!(serai.coin_supply(coin).await.unwrap(), Amount(0));
|
||||
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
|
||||
})
|
||||
|
||||
@@ -36,24 +36,24 @@ serai_test!(
|
||||
events,
|
||||
vec![
|
||||
DexEvent::PoolCreated {
|
||||
pool_id: (Coin::Serai, Coin::Bitcoin),
|
||||
pool_account: PublicKey::from_raw(blake2_256(&(Coin::Serai, Coin::Bitcoin).encode())),
|
||||
lp_token: 0,
|
||||
pool_id: Coin::Bitcoin,
|
||||
pool_account: PublicKey::from_raw(blake2_256(&Coin::Bitcoin.encode())),
|
||||
lp_token: Coin::Bitcoin,
|
||||
},
|
||||
DexEvent::PoolCreated {
|
||||
pool_id: (Coin::Serai, Coin::Ether),
|
||||
pool_account: PublicKey::from_raw(blake2_256(&(Coin::Serai, Coin::Ether).encode())),
|
||||
lp_token: 1,
|
||||
pool_id: Coin::Ether,
|
||||
pool_account: PublicKey::from_raw(blake2_256(&Coin::Ether.encode())),
|
||||
lp_token: Coin::Ether,
|
||||
},
|
||||
DexEvent::PoolCreated {
|
||||
pool_id: (Coin::Serai, Coin::Dai),
|
||||
pool_account: PublicKey::from_raw(blake2_256(&(Coin::Serai, Coin::Dai).encode())),
|
||||
lp_token: 2,
|
||||
pool_id: Coin::Dai,
|
||||
pool_account: PublicKey::from_raw(blake2_256(&Coin::Dai.encode())),
|
||||
lp_token: Coin::Dai,
|
||||
},
|
||||
DexEvent::PoolCreated {
|
||||
pool_id: (Coin::Serai, Coin::Monero),
|
||||
pool_account: PublicKey::from_raw(blake2_256(&(Coin::Serai, Coin::Monero).encode())),
|
||||
lp_token: 3,
|
||||
pool_id: Coin::Monero,
|
||||
pool_account: PublicKey::from_raw(blake2_256(&Coin::Monero.encode())),
|
||||
lp_token: Coin::Monero,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -93,10 +93,10 @@ serai_test!(
|
||||
vec![DexEvent::LiquidityAdded {
|
||||
who: pair.public(),
|
||||
mint_to: pair.public(),
|
||||
pool_id: (Coin::Serai, Coin::Monero),
|
||||
amount1_provided: coin_amount.0,
|
||||
amount2_provided: sri_amount.0,
|
||||
lp_token: 3,
|
||||
pool_id: Coin::Monero,
|
||||
coin_amount: coin_amount.0,
|
||||
sri_amount: sri_amount.0,
|
||||
lp_token: Coin::Monero,
|
||||
lp_token_minted: 49_999999990000
|
||||
}]
|
||||
);
|
||||
@@ -277,10 +277,10 @@ serai_test!(
|
||||
vec![DexEvent::LiquidityAdded {
|
||||
who: IN_INSTRUCTION_EXECUTOR.into(),
|
||||
mint_to: pair.public(),
|
||||
pool_id: (Coin::Serai, Coin::Bitcoin),
|
||||
amount1_provided: 6_947_918_403_646,
|
||||
amount2_provided: 10_000_000_000_000, // half of sent amount
|
||||
lp_token: 0,
|
||||
pool_id: Coin::Bitcoin,
|
||||
coin_amount: 10_000_000_000_000, // half of sent amount
|
||||
sri_amount: 6_947_918_403_646,
|
||||
lp_token: Coin::Bitcoin,
|
||||
lp_token_minted: 8333333333332
|
||||
}]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user