Skip to content

Commit

Permalink
Dex improvements (#422)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
akildemir and kayabaNerve authored Nov 12, 2023
1 parent a43815f commit d015ee9
Show file tree
Hide file tree
Showing 30 changed files with 1,070 additions and 2,169 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ jobs:
-p serai-primitives \
-p serai-coins-primitives \
-p serai-coins-pallet \
-p serai-liquidity-tokens-pallet \
-p serai-dex-primitives \
-p serai-dex-pallet \
-p serai-validator-sets-primitives \
-p serai-validator-sets-pallet \
Expand Down
32 changes: 0 additions & 32 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions coordinator/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ async fn handle_batch_and_burns<D: Db, Pro: Processors>(
}
}

for burn in serai.coins().burn_events().await? {
if let CoinsEvent::Burn { from: _, instruction } = burn {
for burn in serai.coins().burn_with_instruction_events().await? {
if let CoinsEvent::BurnWithInstruction { from: _, instruction } = burn {
let network = instruction.balance.coin.network();
network_had_event(&mut burns, &mut batches, network);

Expand Down
2 changes: 0 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ exceptions = [
{ allow = ["AGPL-3.0"], name = "serai-coordinator" },

{ allow = ["AGPL-3.0"], name = "serai-coins-pallet" },
{ 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
16 changes: 12 additions & 4 deletions substrate/client/src/serai/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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 }),
)
}
}
11 changes: 5 additions & 6 deletions substrate/client/src/serai/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
)
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ serai_test!(
&serai
.sign(
&PairSigner::new(pair),
&SeraiCoins::burn(instruction.clone()),
&SeraiCoins::burn_with_instruction(instruction.clone()),
0,
BaseExtrinsicParamsBuilder::new(),
)
Expand All @@ -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));
})
Expand Down
40 changes: 20 additions & 20 deletions substrate/client/tests/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
);
Expand Down Expand Up @@ -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
}]
);
Expand Down Expand Up @@ -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
}]
);
Expand Down
4 changes: 0 additions & 4 deletions substrate/coins/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features

pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }

dex-primitives = { package = "serai-dex-primitives", path = "../../dex/primitives", default-features = false }

serai-primitives = { path = "../../primitives", default-features = false }
coins-primitives = { package = "serai-coins-primitives", path = "../primitives", default-features = false }

Expand All @@ -40,8 +38,6 @@ std = [

"pallet-transaction-payment/std",

"dex-primitives/std",

"serai-primitives/std",
"coins-primitives/std",
]
Expand Down
Loading

0 comments on commit d015ee9

Please sign in to comment.