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

Dex offchain rebalance swap #2219

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

Dex offchain rebalance swap #2219

wants to merge 22 commits into from

Conversation

zqhxuyuan
Copy link
Contributor

@zqhxuyuan zqhxuyuan commented Jun 20, 2022

closes: #2137

  • set_rebalance_swap_info set the threshold and supply amount of token. if target swapped amount is less than threshold, no rebalance happened. We're using treasury account to do rebalance swap, so the treasury account should have balance for specified token.
  • offchain worker construct key:CurrencyId-> values:[CurrencyId] from DEX::TradingPairStatuses which help decide the rebalance swap path in the case of pure DEX. i.e. if trading pair has [A,B],[A,C],[B,C], then datastructure is: A-[B,C], B-[C], and (A,B,C) can be rebalance path, the final trading path is Dex(A,B,C) + Dex(C,A).
  • add specified aggregated swap path: RebalanceSwapPaths, it's only used by offchain worker, not used by normal aggregated dex swap.
  • integration test for Taiga(KSM,LKSM) + Dex(LKSM, KSM) or 3USD pool: Taiga(AUSD,USDC)+Taiga(USDC,USDT)+Taiga(USDT,AUSD).

Copy link
Member

@xlc xlc left a comment

Choose a reason for hiding this comment

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

I am thinking if we want to implement this in aggregated-dex so it can also rebalance pools with stable asset pools.

modules/dex/src/lib.rs Outdated Show resolved Hide resolved
.push(pair.second());
});
for (currency_id, trading_tokens) in trading_pair_values_map {
let _ = TradingPairNodes::<T>::try_mutate(currency_id, |maybe_trading_tokens| -> DispatchResult {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can mutate storages in offchain worker? at least the storages won't be saved. you need to use offchain worker db for that

Copy link
Contributor Author

@zqhxuyuan zqhxuyuan Aug 8, 2022

Choose a reason for hiding this comment

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

TradingPairNodes type is CurrencyId->[CurrencyId], I think this datastructure is too complicate for offchain db. Current I'm moving this storage mutate part to on_idle.

Copy link
Contributor Author

@zqhxuyuan zqhxuyuan Aug 8, 2022

Choose a reason for hiding this comment

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

remove TradingPairNodes, and direct calculate without on chain storage.

@zqhxuyuan zqhxuyuan changed the title Dex offchain triangle swap Dex offchain rebalance swap Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offchain worker to automatically rebalance swap pools
2 participants