8000 feat(trade): use Trading SDK in trade flows by shoom3301 · Pull Request #5549 · cowprotocol/cowswap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(trade): use Trading SDK in trade flows #5549

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

Merged
merged 148 commits into from
Apr 23, 2025
Merged

Conversation

shoom3301
Copy link
Collaborator
@shoom3301 shoom3301 commented Mar 25, 2025

Summary

Finally, dog-fooded TradingSDK in CoW Swap.
It required some changes in the SDK: cowprotocol/cow-sdk#256

There are tow big changes:

  1. Quote fetching
  2. Order posting

Now we have a instance of TradingSdk in src/tradingSdk/tradingSdk plus TradingSdkUpdater for updating appCode, chainId, signer and env in TradingSdk.

Quote fetching

The most of the changes are in this commit: e02652f
There are other fixes on top of this commit, see them in the final changes.

Order posting

That part needs refactoring in the future!
As we discussed, it requires significant time to make the design better, so I only migrated existing code to TradingSDK.
The plan for the refactoring will be bellow.

You can find key changes by searching postSwapOrderFromQuote( and postLimitOrder( in the code.
Those calls are located in 6 flow functions:

  • swapFlow
  • ethFlow
  • safeBundleApprovalFlow
  • safeBundleEthFlow
  • limit orders tradeFlow
  • limit orders safeBundleFlow

In the next iterations would be great to merge the first 4 of flows into one.

Basically, I replaced signEthFlowOrderStep, signAndPostOrder, buildPresignTx functions with the calls above.

Refactoring plan

  1. Merge swapFlow, ethFlow, safeBundleApprovalFlow, safeBundleEthFlow into one flow in order to reduce code duplications
  2. The same for limit order flows
  3. Replace TradeFlowContext with tradeQuotesAtom state. Trade quote already contains all the necessary data and duplicates TradeFlowContext
  4. Replace getQuote from src/api/cowProtocol with TradingSDK. It's still in use in FullAmountQuoteUpdater and UnfillableOrdersUpdater

To Test

All the trading flows:

  • swap (EOA, Safe, SC)
  • limit orders (EOA, Safe, SC)
  • twap (EOA, Safe, SC)
  • eth-flow

Trade parameters:

  • slippage (default, manual, smart)
  • partner fee (cowswap, safe, widget)

Confirmation screen:

  • price updated

Quote:

  • all the parameters (partiallyFillable, receiver, etc.)
  • fast/optimal
  • quote API errors. I'm not sure they are processed well

App data:

  • all the parameters (partner fee, slippage, utm, referrer)

Approvals:

  • regular approvals
  • permits

Summary by CodeRabbit

  • New Features

    • Introduced a new Trading SDK integration, enabling enhanced order posting and quote management.
    • Added a Trading SDK updater component for seamless environment and wallet synchronization.
  • Refactor

    • Streamlined trade quote structure and management, resulting in more consistent and robust quoting and order flows.
    • Updated order posting, signing, and presigning logic across swap, limit, and bundle flows to use the new SDK.
    • Simplified context and state management for trade and quote data.
    • Removed legacy trade and profile data fetching functions and unused order signing utilities.
  • Bug Fixes

    • Improved error handling for failed fetches and operator errors, reducing unnecessary retries and enhancing user feedback.
  • Chores

    • Upgraded core dependencies, including a major update to the Cow Protocol SDK.
    • Removed unused dependencies and legacy code for a cleaner, more maintainable codebase.
  • Tests

    • Updated and added tests to reflect the new quote and order flow logic.

shoom3301 added 30 commits March 8, 2025 13:42
< 10000 batch-deferred-content class="d-inline-block" data-url="/commits/badges">
Copy link
Collaborator
@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

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

Working well both via EOA and Safe, at least the SWAP and Bundle SWAP flows respectively.

@shoom3301 shoom3301 merged commit d4eaad9 into develop Apr 23, 2025
14 of 15 checks passed
@shoom3301 shoom3301 deleted the feat/use-trading-sdk branch April 23, 2025 10:18
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0