Skip to content

Dex offchain rebalance swap#2219

Draft
zqhxuyuan wants to merge 22 commits into
masterfrom
dex_offchain_triangle
Draft

Dex offchain rebalance swap#2219
zqhxuyuan wants to merge 22 commits into
masterfrom
dex_offchain_triangle

Conversation

@zqhxuyuan

@zqhxuyuan zqhxuyuan commented Jun 20, 2022

Copy link
Copy Markdown
Contributor

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).

@xlc xlc left a comment

Copy link
Copy Markdown
Member

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.

Comment thread modules/dex/src/lib.rs Outdated
Comment thread modules/dex/src/lib.rs Outdated
.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
Copy Markdown
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

@zqhxuyuan zqhxuyuan Aug 8, 2022

Copy link
Copy Markdown
Contributor Author

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.

@zqhxuyuan zqhxuyuan Aug 8, 2022

Copy link
Copy Markdown
Contributor Author

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