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

Add support for decoding Swap Orders in Multisends #1348

Merged
merged 2 commits into from
Apr 2, 2024
Merged

Conversation

fmrsabino
Copy link
Contributor

  • Swap Orders inside a Multisend should be decoded in the same way as regular ones.
  • Detection of a Multisend order happens on the first level of transactions (i.e. it does not detect Swap transactions if a Multisend contains another Multisend).
  • The mapSwapOrder function also changed:
    • It is no longer restricted to a MultisigTransaction or ModuleTransaction – this was done to support nested transactions which do not have all the properties of a Multisig or Module transactions.
    • It no longer maps to a CustomTransactionInfo – this is now a decision left for the callers. Instead, the promise is rejected if the swap transaction couldn't be decoded successfully.

- Swap Orders inside a Multisend should be decoded in the same way as regular ones.
- Detection of a Multisend order happens on the first level of transactions (i.e. it does not detect Swap transactions if a Multisend contains another Multisend).
- The `mapSwapOrder` function also changed:
  * It is no longer restricted to a `MultisigTransaction` or `ModuleTransaction` – this was done to support nested transactions which do not have all the properties of a Multisig or Module transactions.
  * It no longer maps to a `CustomTransactionInfo` – this is now a decision left for the callers. Instead, the promise is rejected if the swap transaction couldn't be decoded successfully.
@fmrsabino fmrsabino self-assigned this Mar 27, 2024
@fmrsabino fmrsabino requested a review from a team as a code owner March 27, 2024 14:27
@coveralls
Copy link

coveralls commented Mar 27, 2024

Pull Request Test Coverage Report for Build 8522264835

Details

  • 25 of 35 (71.43%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 93.138%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/routes/transactions/mappers/common/swap-order.mapper.ts 8 9 88.89%
src/routes/transactions/mappers/common/transaction-info.mapper.ts 16 25 64.0%
Files with Coverage Reduction New Missed Lines %
src/routes/transactions/entities/tests/human-description.builder.ts 1 90.0%
Totals Coverage Status
Change from base Build 8436155577: -0.1%
Covered Lines: 6493
Relevant Lines: 6719

💛 - Coveralls

Copy link
Member

@hectorgomezv hectorgomezv left a comment

Choose a reason for hiding this comment

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

Great job! Only small comments 🙂

Comment on lines +244 to +245
// TODO If we can build a sorted hash map of the transactions, we can avoid iterating all of them
// as we know the pattern of a Swap Order.
Copy link
Member

@hectorgomezv hectorgomezv Apr 1, 2024

Choose a reason for hiding this comment

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

Sounds like a good solution, but building the hash map would also imply iterating the full array, wouldn't it? The worst-case scenario is the transactions array does not contain a swap order so the iteration reaches the last element.

Btw, related to it: is it possible to have several swap orders in the same multisend transaction? My understanding here is only one can be present, as the code is returning the first occurrence, is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good solution, but building the hash map would also imply iterating the full array, wouldn't it? The worst-case scenario is the transactions array does not contain a swap order so the iteration reaches the last element.

Correct. The Hash Map solution would be mostly to optimise accessing the collection while keeping the iterative properties.

Btw, related to it: is it possible to have several swap orders in the same multisend transaction? My understanding here is only one can be present, as the code is returning the first occurrence, is this correct?

It is. However the interface (and the CGW) will only support decoding of a single transaction in that collection. The expected use case is to have a MultiSend with a Token Approval + Swapping (although the MultiSend can contain anything).

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks for clarifying!

private isCoWSwapOrder(
transaction: MultisigTransaction | ModuleTransaction,
): boolean {
private isSwapOrder(transaction: { data?: `0x${string}` }): boolean {
Copy link
Member

@hectorgomezv hectorgomezv Apr 1, 2024

Choose a reason for hiding this comment

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

Very nitpicky: I'm under the impression that mapSwapOrder determines whether a transaction is a swap order or not. So this function name is a bit confusing at first glance, I'd say this one checks the data within the transaction, what about renaming it to isSwapOrderData? Do you think it would make the class API clearer?

Not a strong opinion btw, I left this up to you 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nitpicky: I'm under the impression that mapSwapOrder determines whether a transaction is a swap order or not. So this function name is a bit confusing at first glance, I'd say this one checks the data within the transaction, what about renaming it to isSwapOrderData? Do you think it would make the class API clearer?

Not a strong opinion btw, I left this up to you 🙂

The goal of mapSwapOrder is to map a transaction to a Swap Order, it's not really to check if the transaction is a Swap Order although it can be used for that (nullability test).

The isSwapOrder is a utility function which works on the "transaction" level as in, it should work with any object that is a transaction-like (that's why the requirement of the argument is to have an optional data argument).

So in summary:

  • isSwapOrder – returns true if the transaction is a Swap Order.
  • mapSwapOrder – returns the SwapOrder if the transaction was successfully mapped to a Swap Order, null otherwise.

Copy link
Member

@hectorgomezv hectorgomezv left a comment

Choose a reason for hiding this comment

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

🚀🚀🚀

@fmrsabino fmrsabino merged commit b402850 into main Apr 2, 2024
16 checks passed
@fmrsabino fmrsabino deleted the multisend-cowswap branch April 2, 2024 14:31
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.

3 participants