Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unified trade events #910

Open
wants to merge 159 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 130 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
6cfc1cd
initial implementation
Roznovjak Sep 20, 2024
2935f90
revert removed comments about emitted events
Roznovjak Sep 20, 2024
ce87882
Merge branch 'master' into unified_trade_events
Roznovjak Sep 25, 2024
d01eab3
formatting
Roznovjak Sep 25, 2024
5bb6696
additional implementation
Roznovjak Sep 25, 2024
3ad68ab
rename batch_id to event_id
Roznovjak Sep 25, 2024
4ac8adc
rename pallet_trade_event to pallet_amm_support
Roznovjak Sep 25, 2024
1c83f9d
Merge branch 'master' into unified_trade_events
Roznovjak Sep 26, 2024
87bd948
fix some tests
Roznovjak Sep 27, 2024
ac008a3
update the event structure
Roznovjak Sep 27, 2024
111b99a
Merge branch 'master' into unified_trade_events
Roznovjak Sep 29, 2024
0f5c9a3
fix lbp tests
Roznovjak Sep 30, 2024
cb02e14
fix xyk tests
Roznovjak Sep 30, 2024
914b332
fix router tests
Roznovjak Oct 1, 2024
66272e8
fix omnipool tests
Roznovjak Oct 1, 2024
cd80ac6
formatting
Roznovjak Oct 1, 2024
065d0a7
fix stableswap tests
Roznovjak Oct 1, 2024
1d0a377
fix otc tests
Roznovjak Oct 1, 2024
81c4b6a
fix integration tests
Roznovjak Oct 2, 2024
a50ffb7
formatting
Roznovjak Oct 2, 2024
1e209bb
fix integration tests
Roznovjak Oct 2, 2024
d58de6c
satisfy clippy
Roznovjak Oct 2, 2024
2fe9d65
check event in otc-settlements test
Roznovjak Oct 2, 2024
c24094e
formatting
Roznovjak Oct 2, 2024
4bca2b6
add pallet-amm-support tests
Roznovjak Oct 2, 2024
d38504e
formatting
Roznovjak Oct 2, 2024
288705d
refactor incremental id computation
Roznovjak Oct 2, 2024
5f79fbb
satisfy clippy
Roznovjak Oct 2, 2024
682c88b
fix compilation error
dmoka Nov 4, 2024
1f8f7bd
stack
Roznovjak Nov 4, 2024
e2efb8a
revert old impl that is not needed anymore
Roznovjak Nov 5, 2024
c083ebf
formatting
Roznovjak Nov 5, 2024
5825368
fixed some compilation error
dmoka Nov 5, 2024
94bc0f9
fix compilation errors
dmoka Nov 5, 2024
66023cb
emit missing swapped events in omnipool
dmoka Nov 5, 2024
fc28af6
clean up in comments
dmoka Nov 5, 2024
62c10f4
Merge remote-tracking branch 'origin/master' into unified_trade_events
dmoka Nov 5, 2024
24721f7
update lock
dmoka Nov 5, 2024
2d5394e
fix compilation error
dmoka Nov 5, 2024
d220923
Merge remote-tracking branch 'origin/master' into unified_trade_events
dmoka Nov 5, 2024
b2d1ef5
formatting
dmoka Nov 5, 2024
ca4b6ba
update lock
dmoka Nov 6, 2024
2178b22
Merge remote-tracking branch 'origin/master' into unified_trade_events
dmoka Nov 6, 2024
7ccd1c1
update lock
dmoka Nov 6, 2024
0d6c6cb
fix compilation error
dmoka Nov 6, 2024
abd9ed2
raise swapped event in stableswap
dmoka Nov 6, 2024
e262a04
add HubAmountUpdated event deposits as these are extra info relating …
dmoka Nov 6, 2024
14b24ff
add comments explaining the why
dmoka Nov 6, 2024
25808e9
pass event id id to HubAmountUpdated event
dmoka Nov 6, 2024
f5a986e
formatting
dmoka Nov 6, 2024
8169f00
add todos
dmoka Nov 6, 2024
d318637
add unified event stack handling for DCA
dmoka Nov 7, 2024
b0f62f3
Merge remote-tracking branch 'origin/master' into unified_trade_events
dmoka Nov 7, 2024
0723194
formatting
dmoka Nov 7, 2024
2b81233
update lock
dmoka Nov 7, 2024
1045fc8
add stableswap swapped events
dmoka Nov 11, 2024
fb03a18
formatting
dmoka Nov 11, 2024
9e33836
remove unused run to block method
dmoka Nov 11, 2024
8dc92ed
simplify amm support dependencies
dmoka Nov 11, 2024
f17bcdd
add missing comments
dmoka Nov 11, 2024
e620966
add comments explaining thre why
dmoka Nov 11, 2024
d232449
add fees to swappedevents from stabeswap share calculation
dmoka Nov 14, 2024
9895a68
formatting
dmoka Nov 14, 2024
efe4ceb
add missing fee info to swapped event when removing exact amount of l…
dmoka Nov 14, 2024
ed3852a
add hooks for utility batch calls so can have proper Swapped events
dmoka Nov 14, 2024
66fbe9c
revert changes in math as we can solve it simpler way without changin…
dmoka Nov 14, 2024
d4227a3
cleaning up
dmoka Nov 14, 2024
a122029
make clippy happy
dmoka Nov 14, 2024
458ae3a
formatting
dmoka Nov 14, 2024
a2f3ad3
rebenchmark utility pallet
dmoka Nov 14, 2024
04c1942
bump versions
dmoka Nov 15, 2024
2d829b6
add liquidty add and moreve to stableswap relevant swapped events
dmoka Dec 3, 2024
30cdafd
split up swapped in omnipool sell
dmoka Dec 6, 2024
8d98ceb
split up swapped in omnipool buy
dmoka Dec 6, 2024
5291f1c
cleaning up
dmoka Dec 6, 2024
64e0b9b
fix some tests
dmoka Dec 6, 2024
b31de5d
formatting
dmoka Dec 9, 2024
5202a70
fix not compiling tests
dmoka Dec 9, 2024
0ee69af
add missing assertion for swapped when ref code is used
dmoka Dec 9, 2024
2b14d21
make setting global
dmoka Dec 9, 2024
24e5423
clear execution stack on init
dmoka Dec 9, 2024
39a2d9a
remove hanging todo comment
dmoka Dec 9, 2024
a3991c3
Merge remote-tracking branch 'origin/master' into unified_trade_events
dmoka Dec 9, 2024
4a64061
add todo for stuff we discussed in a call about refactoring event dep…
dmoka Dec 10, 2024
e8d14dd
replace amm related types to amm pallet as it belongs there
dmoka Dec 12, 2024
64a1962
add test for nested batch
dmoka Dec 18, 2024
f1b11b5
use amm support pallet directlyn instead of via traits
dmoka Dec 18, 2024
5edd26e
remove unused trait
dmoka Dec 18, 2024
fd38cf0
remove unnecessary types
dmoka Dec 18, 2024
a8c33d0
use alias for executionIdStack
dmoka Dec 18, 2024
66a0a25
fix unit tests as we removed many traits from amm support pallet
dmoka Dec 18, 2024
1a00e1c
cleaning up
dmoka Dec 18, 2024
83104b3
use overflowing to prevent future issues
dmoka Dec 18, 2024
b887f62
cleaning up
dmoka Dec 18, 2024
0233d43
cleaning up
dmoka Dec 18, 2024
feb24dc
remove unnecessary generic types
dmoka Dec 18, 2024
6ea27c7
added asset type and using it in swapped event
dmoka Dec 19, 2024
c7fbb35
remove unnecessary getter
dmoka Dec 19, 2024
27f6b3f
remove unnecessary incremental id getter
dmoka Dec 19, 2024
34a0c73
add xcm echange event stack population
dmoka Dec 19, 2024
2ff4aee
add better doc
dmoka Dec 19, 2024
c7be65b
replace incremental id type from primites as primites tpyes only used…
dmoka Dec 19, 2024
c36165d
remove xcm exchange from filler type
dmoka Dec 20, 2024
b5d94bc
remove generic type
dmoka Dec 20, 2024
58c2c80
add schedule id to dca execution type so indexer can relate DCA used …
dmoka Dec 20, 2024
ce767c2
formatting
dmoka Dec 20, 2024
96f2c5c
add todo
dmoka Dec 20, 2024
8e2ba94
add custom send xcm
dmoka Dec 23, 2024
e5bd863
add unified even support for xcm with xcm hash
dmoka Dec 26, 2024
1acc07f
populate unified event stack with xcm and topic id
dmoka Dec 27, 2024
f19c091
make unified events storage operations more bullet proof as we dont w…
dmoka Dec 27, 2024
f1a8e40
merge master to unified_trade_events
dmoka Dec 27, 2024
4f56dd8
formatting
dmoka Dec 27, 2024
d59b9d5
bump versions
dmoka Dec 27, 2024
d71deca
bump versions
dmoka Dec 27, 2024
239b22f
make clippy happy
dmoka Dec 27, 2024
53e9b58
fix test
dmoka Dec 27, 2024
2ca6939
formatting
dmoka Dec 27, 2024
92151cb
renaming to express intent better
dmoka Dec 30, 2024
8ff8309
increase stack size to 16 to have more room for events
dmoka Dec 30, 2024
708a5ea
removed ICE as not used yet
dmoka Dec 30, 2024
fd60605
rename to support pallet
dmoka Dec 30, 2024
e43cba9
fix failing test
dmoka Dec 31, 2024
7f3b92d
fix failing test
dmoka Dec 31, 2024
ff7b18b
WIP - separate normal, staking and referral fee
dmoka Dec 31, 2024
20c3363
remove unnecessary test
dmoka Jan 2, 2025
9d72e42
fix otc filler/swapper of swapped event
dmoka Jan 2, 2025
5fb58c2
formatting
dmoka Jan 2, 2025
da1b526
merge master to unified_trade_events
dmoka Jan 2, 2025
9b93702
bump versions
dmoka Jan 2, 2025
c902d29
use patch4 release
dmoka Jan 2, 2025
868c360
fix xcm test by not asserting the specific topic id as it is dynamic
dmoka Jan 2, 2025
54128eb
renaming
dmoka Jan 2, 2025
c6834fa
refactoring
dmoka Jan 2, 2025
925cd27
formatting
dmoka Jan 2, 2025
4bd0aff
some formatting
dmoka Jan 3, 2025
8c8a9f5
remove done todo
dmoka Jan 3, 2025
68632a2
adjust doc comments
dmoka Jan 3, 2025
1e3e6ad
remove done todo
dmoka Jan 3, 2025
094c186
make clippy happy
dmoka Jan 3, 2025
2c7936d
formatting
dmoka Jan 3, 2025
d709534
regenerate benchmarks for pallets using unified events
dmoka Jan 6, 2025
06a3f52
fix compilation error
dmoka Jan 6, 2025
f78f216
remove unecessary calls
dmoka Jan 6, 2025
1ac6612
Update pallets/lbp/src/lib.rs
dmoka Jan 6, 2025
d1d565a
Update pallets/lbp/src/lib.rs
dmoka Jan 6, 2025
c3c0931
Update pallets/support/src/lib.rs
dmoka Jan 6, 2025
5a836ac
fix typo
dmoka Jan 6, 2025
2407cf2
remove unecessary dep
dmoka Jan 6, 2025
eac55ed
set back version as there as no change in crate
dmoka Jan 6, 2025
7279c7c
use context call directly
dmoka Jan 6, 2025
95156dd
return stack directly as no need for error propagation
dmoka Jan 6, 2025
38c24b6
Merge remote-tracking branch 'origin/unified_trade_events' into unifi…
dmoka Jan 6, 2025
78970de
add last stack type as param to remove context to prevent unexpected …
dmoka Jan 6, 2025
81053ac
make remove from context infallible
dmoka Jan 6, 2025
ff165cc
make add to context infallible
dmoka Jan 6, 2025
fa809a0
fix todo
dmoka Jan 6, 2025
82de9af
fix doc comment
dmoka Jan 6, 2025
b0a6455
fix small issues coming from PR remark
dmoka Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
642 changes: 340 additions & 302 deletions Cargo.lock

Large diffs are not rendered by default.

898 changes: 450 additions & 448 deletions Cargo.toml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.26.0"
version = "1.27.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -44,6 +44,7 @@ pallet-evm-accounts = { workspace = true }
pallet-xyk-liquidity-mining = { workspace = true }
pallet-transaction-pause = { workspace = true }
pallet-liquidation = { workspace = true }
pallet-support = { workspace = true }

pallet-treasury = { workspace = true }
pallet-democracy = { workspace = true }
Expand Down Expand Up @@ -221,6 +222,7 @@ std = [
"precompile-utils/std",
"pallet-transaction-pause/std",
"pallet-liquidation/std",
"pallet-support/std",
]

# we don't include integration tests when benchmarking feature is enabled
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn rococo_should_receive_asset_when_sent_from_hydra() {
Rococo::execute_with(|| {
assert_eq!(
hydradx_runtime::Balances::free_balance(AccountId::from(BOB)),
2_999_989_698_923 // 3 * HDX - fee
2_999_989_606_492 // 3 * HDX - fee
jak-pan marked this conversation as resolved.
Show resolved Hide resolved
);
});
}
Expand Down
195 changes: 194 additions & 1 deletion integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use pallet_dca::types::{Order, Schedule};
use pallet_omnipool::types::Tradability;
use pallet_stableswap::types::AssetAmount;
use pallet_stableswap::MAX_ASSETS_IN_POOL;
use pallet_support::types::*;
use primitives::{AssetId, Balance};
use sp_runtime::traits::ConstU32;
use sp_runtime::DispatchError;
Expand Down Expand Up @@ -201,6 +202,99 @@ mod omnipool {
});
}

#[test]
fn buy_schedule_execution_should_emit_swapped_events() {
TestNet::reset();
Hydra::execute_with(|| {
//Arrange
init_omnipool_with_oracle_for_block_10();

let dca_budget = 1000 * UNITS;
let amount_out = 100 * UNITS;
let schedule_id = 0;
let schedule1 = schedule_fake_with_buy_order(PoolType::Omnipool, HDX, DAI, amount_out, dca_budget);
create_schedule(ALICE, schedule1);

//Act
run_to_block(11, 12);

//Assert
let swapped_events = get_last_swapped_events();
let last_two_swapped_events = &get_last_swapped_events()[swapped_events.len() - 2..];
dmoka marked this conversation as resolved.
Show resolved Hide resolved
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactOut,
inputs: vec![Asset::new(HDX, 140421094367051)],
outputs: vec![Asset::new(LRNA, 70210545436437)],
fees: vec![Fee::new(LRNA, 35105272718, Omnipool::protocol_account()),],
dmoka marked this conversation as resolved.
Show resolved Hide resolved
operation_stack: vec![
ExecutionType::DCA(schedule_id, 0),
ExecutionType::Router(1),
ExecutionType::Omnipool(2)
]
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactOut,
inputs: vec![Asset::new(LRNA, 70175440163719)],
outputs: vec![Asset::new(DAI, amount_out)],
fees: vec![Fee::new(DAI, 250626566417, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 0),
ExecutionType::Router(1),
ExecutionType::Omnipool(2)
],
})
]
);

run_to_block(13, 17);

let swapped_events = get_last_swapped_events();
let last_two_swapped_events = &get_last_swapped_events()[swapped_events.len() - 2..];
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactOut,
inputs: vec![Asset::new(HDX, 140421107716515)],
outputs: vec![Asset::new(LRNA, 70210548448729)],
fees: vec![Fee::new(LRNA, 35105274224, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 3),
ExecutionType::Router(4),
ExecutionType::Omnipool(5)
],
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactOut,
inputs: vec![Asset::new(LRNA, 70175443174505)],
outputs: vec![Asset::new(DAI, amount_out)],
fees: vec![Fee::new(DAI, 250626566417, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 3),
ExecutionType::Router(4),
ExecutionType::Omnipool(5)
],
})
]
);
});
}

#[test]
fn buy_schedule_execution_should_work_without_route() {
TestNet::reset();
Expand Down Expand Up @@ -588,6 +682,106 @@ mod omnipool {
});
}

#[test]
fn sell_schedule_execution_should_emit_swapped_event() {
TestNet::reset();
Hydra::execute_with(|| {
//Arrange
init_omnipool_with_oracle_for_block_10();
let alice_init_hdx_balance = 5000 * UNITS;
assert_ok!(Balances::force_set_balance(
RuntimeOrigin::root(),
ALICE.into(),
alice_init_hdx_balance,
));

let dca_budget = 1100 * UNITS;
let amount_to_sell = 100 * UNITS;
let schedule_id = 0;
let schedule1 =
schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget, HDX, DAI, amount_to_sell);
create_schedule(ALICE, schedule1);

//Act
run_to_block(11, 12);

//Assert
let swapped_events = get_last_swapped_events();
let last_two_swapped_events = &get_last_swapped_events()[swapped_events.len() - 2..];
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![Asset::new(HDX, amount_to_sell)],
outputs: vec![Asset::new(LRNA, 49999999159957)],
fees: vec![Fee::new(LRNA, 24999999579, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 0),
ExecutionType::Router(1),
ExecutionType::Omnipool(2)
],
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![Asset::new(LRNA, 49974999160378)],
outputs: vec![Asset::new(DAI, 71214372624126)],
fees: vec![Fee::new(DAI, 178482136903, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 0),
ExecutionType::Router(1),
ExecutionType::Omnipool(2)
],
})
]
);

run_to_block(13, 17);

let swapped_events = get_last_swapped_events();
let last_two_swapped_events = &get_last_swapped_events()[swapped_events.len() - 2..];
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![Asset::new(HDX, amount_to_sell)],
outputs: vec![Asset::new(LRNA, 49999997360044)],
fees: vec![Fee::new(LRNA, 24999998680, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 3),
ExecutionType::Router(4),
ExecutionType::Omnipool(5)
],
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![Asset::new(LRNA, 49974997361364)],
outputs: vec![Asset::new(DAI, 71214367826179)],
fees: vec![Fee::new(DAI, 178482124878, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::DCA(schedule_id, 3),
ExecutionType::Router(4),
ExecutionType::Omnipool(5)
],
})
]
);
});
}

#[test]
fn sell_schedule_be_retried_when_route_is_invalid() {
TestNet::reset();
Expand Down Expand Up @@ -4032,7 +4226,6 @@ pub fn run_to_block(from: BlockNumber, to: BlockNumber) {
for b in from..=to {
do_trade_to_populate_oracle(DAI, HDX, UNITS);
set_relaychain_block_number(b);
do_trade_to_populate_oracle(DAI, HDX, UNITS);
}
}

Expand Down
89 changes: 87 additions & 2 deletions integration-tests/src/exchange_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use frame_support::traits::fungible::Balanced;
use frame_support::traits::tokens::Precision;
use frame_support::weights::Weight;
use frame_support::{assert_ok, pallet_prelude::*};
use hydradx_runtime::AssetRegistry;
use hydradx_runtime::Omnipool;
use hydradx_runtime::Router;
use hydradx_runtime::RuntimeEvent;
use hydradx_runtime::RuntimeOrigin;
use hydradx_runtime::TempAccountForXcmAssetExchange;
use hydradx_runtime::{AssetRegistry, LRNA};
use hydradx_traits::AssetKind;
use hydradx_traits::Create;
use orml_traits::currency::MultiCurrency;
Expand All @@ -21,7 +26,6 @@ use sp_runtime::DispatchResult;
use sp_runtime::{FixedU128, Permill, TransactionOutcome};
use sp_std::sync::Arc;
use xcm_emulator::TestExt;

pub const SELL: bool = true;
pub const BUY: bool = false;

Expand Down Expand Up @@ -120,6 +124,86 @@ fn hydra_should_swap_assets_when_receiving_from_acala_with_sell() {
// We receive about 39_101 HDX (HDX is super cheap in our test)
let received = 39_101 * UNITS + BOB_INITIAL_NATIVE_BALANCE + 207_131_554_396;
assert_eq!(hydradx_runtime::Balances::free_balance(AccountId::from(BOB)), received);

let last_swapped_events = get_last_swapped_events();
let last_two_swapped_events = &last_swapped_events[last_swapped_events.len() - 2..];
let topic_id = [
180, 44, 225, 230, 61, 43, 219, 219, 222, 9, 44, 219, 86, 193, 219, 212, 120, 169, 197, 209, 39, 180, 219,
225, 224, 182, 134, 141, 41, 162, 96, 54,
];
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: TempAccountForXcmAssetExchange::get(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get original acc or just this temp acc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately only the temp acc as the actual trade happens by that account (on behalf of user), that's how we could implement asset exchange back then.

filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![pallet_support::types::Asset::new(ACA, 50000000000000),],
outputs: vec![pallet_support::types::Asset::new(LRNA::get(), 49180327868852)],
fees: vec![Fee::new(LRNA::get(), 24590163934, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::Xcm(topic_id, 0),
ExecutionType::XcmExchange(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No topic here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API of AssetExchange does the full xcm instructions, so can't have the topic ID easily

	_origin: Option<&Location>,
	give: AssetsInHolding,
	want: &Assets,
	maximal: bool,

What we could maybe do is to read the topic from our stack storage, as at this point, the Xcm([u8; 32], IncrementalIdType) should be there. Not sure if it is always there, otherwise we could do use Optional type. WDYT?

ExecutionType::Router(2),
ExecutionType::Omnipool(3)
],
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: TempAccountForXcmAssetExchange::get(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![pallet_support::types::Asset::new(LRNA::get(), 49155737704918),],
outputs: vec![pallet_support::types::Asset::new(HDX, 39101207131554396)],
fees: vec![Fee::new(HDX, 97998012861039, Omnipool::protocol_account()),],
operation_stack: vec![
ExecutionType::Xcm(topic_id, 0),
ExecutionType::XcmExchange(1),
ExecutionType::Router(2),
ExecutionType::Omnipool(3)
],
})
]
);

//We assert that another trade doesnt have the xcm exchange type on stack
assert_ok!(Router::sell(
RuntimeOrigin::signed(ALICE.into()),
HDX,
ACA,
1 * UNITS,
0,
vec![],
));

let last_swapped_events = get_last_swapped_events();
let last_two_swapped_events = &last_swapped_events[last_swapped_events.len() - 2..];
pretty_assertions::assert_eq!(
last_two_swapped_events,
vec![
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![pallet_support::types::Asset::new(HDX, 1 * UNITS),],
outputs: vec![pallet_support::types::Asset::new(LRNA::get(), 1308673515)],
fees: vec![Fee::new(LRNA::get(), 654336, Omnipool::protocol_account()),],
operation_stack: vec![ExecutionType::Router(4), ExecutionType::Omnipool(5)],
}),
RuntimeEvent::AmmSupport(pallet_support::Event::Swapped {
swapper: ALICE.into(),
filler: Omnipool::protocol_account(),
filler_type: pallet_support::types::Filler::Omnipool,
operation: pallet_support::types::TradeOperation::ExactIn,
inputs: vec![pallet_support::types::Asset::new(LRNA::get(), 1308019179),],
outputs: vec![pallet_support::types::Asset::new(ACA, 1348602600)],
fees: vec![Fee::new(ACA, 3379957, Omnipool::protocol_account()),],
operation_stack: vec![ExecutionType::Router(4), ExecutionType::Omnipool(5)],
})
]
);
});
}

Expand Down Expand Up @@ -1143,6 +1227,7 @@ fn half(asset: &Asset) -> Asset {
id: asset.clone().id,
}
}
use pallet_support::types::{ExecutionType, Fee};
use rococo_runtime::xcm_config::BaseXcmWeight;
use xcm_builder::FixedWeightBounds;
use xcm_executor::traits::WeightBounds;
Expand Down
Loading
Loading