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

Feature/cross chain swaps #1657

Open
wants to merge 76 commits into
base: develop
Choose a base branch
from
Open

Conversation

valentunn
Copy link
Member

@valentunn valentunn commented Sep 17, 2024

Crorr chain swaps base branch

Stage 1 - PoC

  • Architecture draft
  • Build works
  • Merge with current dev
  • Cross chain transfers exchange implementation
  • Make swaps utilize new custom fee payment mechanism
  • Multi-chain fees (domain).
  • Filter out directions that do not allow to send or receive the asset
    • Always allow native for the first path segment
    • When multiple hydration edges are chained, only the first one is checked against fee requirements
    • Cross-chain edges also take delivery fees into account
    • Individual edge check should be as fast as possible as we need to check a lot of edges
    • Do not allow to send insufficient assets to avoid trapped assets
    • Filter out routes account cannot authorize transactions in
  • Swaps work
    • When performing BUY, only first segment uses BUY. Rest use SELL
    • Include rough fee estimations when choosing the best quoted path
  • Implement swap execution corrections

Stage 2 - Secondary features

  • Validations
  • Include intermediate (e.g. cross-chain) fees to the amount while determining the SwapLimit
  • Multi-chain fees (presentation)
  • Routing (presentation)
  • Estimate swap execution duration
  • Clenup up setup swap & confirms swap screens
    • Stop quoting and fee calculation after submission has been started

Stage 3 - Operations manager

  • Persistent storage for multi-segment swaps
  • Design a cross-chain indexer for swaps
  • State detection from indexer
  • Error recovery (retry failed step)

Stage 4 - Multi-origin swaps

  • Research consolidating all fees on reserve chain before converting them
  • Architecture draft
  • More to come...

Misc

  • Use in memory store for passing state to swap confirmation
  • Remove MinimumBalanceBuyIn
  • Hydra swaps done in one batch transaction
  • Weight euristics for supported segments to faciliate better swaps
  • Allow for native intermediate fees when handling edges starting with native asset
  • Adapt Fraction abstraction for swaps
  • More precise rough fee estimation for cross chains
  • Try adding more dynamic weights to path finding
  • Combine on-chain swap with succeeding cross-chain swap into one batch
  • Use DryRunApi for xcm fee estimations
  • Clean up FeeMixin (?) (remove DecimalFee)

Optimizations

  • Path finding: Do not store nodeList in QueueElement but rather utilize currentPath for checking whether node exists in the path: 33% performance improvement on fully connected graph
  • Path finding: Check Yen's_algorithm
  • Subscriptions: Do not run them for each chain

@valentunn valentunn marked this pull request as draft September 17, 2024 09:42
# Conflicts:
#	bindings/hydra-dx-math/src/main/java/io/novafoundation/nova/hydra_dx_math/HydraDxMathConversions.kt
#	bindings/hydra-dx-math/src/main/java/io/novafoundation/nova/hydra_dx_math/xyk/HYKSwapMathBridge.java
#	common/src/main/java/io/novafoundation/nova/common/utils/KotlinExt.kt
#	common/src/main/java/io/novafoundation/nova/common/utils/graph/Graph.kt
#	feature-swap-api/src/main/java/io/novafoundation/nova/feature_swap_api/domain/model/SwapQuote.kt
#	feature-swap-api/src/main/java/io/novafoundation/nova/feature_swap_api/domain/model/SwapQuoteArgs.kt
#	feature-swap-core/src/main/java/io/novafoundation/nova/feature_swap_core/data/assetExchange/conversion/types/hydra/impl/stableswap/model/StablePool.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/AssetExchange.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/assetConversion/AssetConversionExchange.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/hydraDx/HydraDxExchange.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/hydraDx/HydraDxSwapSource.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/hydraDx/omnipool/OmniPoolSwapSource.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/hydraDx/stableswap/StableSwapSource.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/data/assetExchange/hydraDx/xyk/XYKSwapSource.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/di/exchanges/HydraDxExchangeModule.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/domain/swap/RealSwapService.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/presentation/confirmation/SwapConfirmationViewModel.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/presentation/confirmation/payload/SwapConfirmationPayloadFormatter.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/presentation/main/SwapMainSettingsFragment.kt
#	feature-swap-impl/src/main/java/io/novafoundation/nova/feature_swap_impl/presentation/main/SwapMainSettingsViewModel.kt
valentunn and others added 24 commits November 8, 2024 18:05
# Conflicts:
#	app/src/main/java/io/novafoundation/nova/app/root/navigation/Navigator.kt
#	app/src/main/res/navigation/main_nav_graph.xml
#	app/src/main/res/navigation/start_swap_nav_graph.xml
#	common/src/main/java/io/novafoundation/nova/common/presentation/AssetIconProvider.kt
#	feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowViewModel.kt
#	feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/swap/executor/ReselectSwapFlowExecutor.kt
# Conflicts:
#	feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/AssetListMixin.kt
#	feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/ExpandableAssetsMixin.kt
# Conflicts:
#	build.gradle
#	feature-account-impl/src/main/java/io/novafoundation/nova/feature_account_impl/data/fee/types/hydra/HydrationConversionFeePayment.kt
@valentunn valentunn marked this pull request as ready for review November 24, 2024 18:50
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.

2 participants