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

fix: synchronize buyAssetAccountId to sellAssetAccountNumber on swapper mount #6124

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Feb 3, 2024

Description

Does what it says on the box - when the swapper originally mounts, the buyAssetAccountId should be synchronized with the sellAssetAccountId's account number, if there is a matching account on that index on the buy side.

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

closes #6121

Risk

High Risk PRs Require 2 approvals

Theoretically low, effectively medium in terms of domain touched. While this technically brings back the behavior that was intended (see the removed/reworded comment), if we got this wrong, there is a risk of funds ending up in the wrong account

What protocols, transaction types or contract interactions might be affected by this PR?

None

Testing

  • Have a balance of buy asset that is higher on any 1+ account than on your 0th account

  • On swapper original mount, ensure that the buy account number is matching the sell account number

  • Ensure it is still possible to choose another account, both on the buy and the sell side, and that they do not synchronize after the original mount and synchronization

  • Play around with account selection and ensure you're still getting quotes

  • Ensure funds are landing in the right account

Engineering

  • ☝🏽

Operations

  • ☝🏽

Screenshots (if applicable)

Default buy account

  • Develop
develop.mov
  • This diff
this.diff.mov

Quotes are happy, and funds are ending in the correct address

correct.account.mov

Copy link
Contributor Author

gomesalexandre commented Feb 3, 2024

Comment on lines -15 to -16
// currently, a multi-hop trade will be automagically routed though the accountId corresponding to
// the accountNumber for the first hop.
Copy link
Contributor Author

@gomesalexandre gomesalexandre Feb 3, 2024

Choose a reason for hiding this comment

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

That was the intent, but wasn't working as intended - comment reworded and moved on top of buyAssetAccountId

Comment on lines +246 to +247
sellAssetAccountId: initialSellAssetAccountId,
buyAssetAccountId: initialBuyAssetAccountId,
Copy link
Contributor Author

@gomesalexandre gomesalexandre Feb 3, 2024

Choose a reason for hiding this comment

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

Technically no only defaults, but making it clear that the main intent of these is to get initial values - else if all we cared about was selecting the buy/sell AccountIds, we could directly use the selectors that are consumed there

@gomesalexandre gomesalexandre marked this pull request as ready for review February 3, 2024 22:46
@gomesalexandre gomesalexandre requested a review from a team as a code owner February 3, 2024 22:46
@woodenfurniture woodenfurniture self-assigned this Feb 4, 2024
@0xApotheosis 0xApotheosis self-assigned this Feb 4, 2024
// - if this was to fail for any reason, we default to the first account number as a default
const buyAssetAccountId = useAppSelector(state =>
selectLastHopBuyAccountId(state, { accountId: maybeMatchingBuyAccountId }),
)
Copy link
Member

Choose a reason for hiding this comment

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

I'd be inclined to move all of this business logic into a new selector selectLastHopDefaultBuyAccountId (or similar, better name) which means the concept of maybe passing in a filter that is assumed to be maybeMatchingBuyAccountId is no longer required.

i.e revert the original selectLastHopBuyAccountId and create a new selector encapsulating all of the above business logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the original intent and would be much nicer, unfortunately this isn't possible because of the different arities of selectors, and the fact we can't use a selector's return value as input for the next one ☹️

Copy link
Member

@woodenfurniture woodenfurniture left a comment

Choose a reason for hiding this comment

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

requested changes regarding 1 comment, happy to discuss further

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

Tested functionally, specifically with a wallet that has a higher balance on a non-0 sell account and confirmed that the buy account successfully synchronised accordingly.

Looking good pending the resolution of woody's blocking comment.

@0xApotheosis
Copy link
Contributor

Checked in with @gomesalexandre, confirmed we can dismiss the current blocking comment from @woodenfurniture as we cannot implement it at this time (see #6124 (comment)).

@0xApotheosis 0xApotheosis merged commit 4d9be32 into develop Feb 5, 2024
4 checks passed
@0xApotheosis 0xApotheosis deleted the fix_synchronize_accountids_mount branch February 5, 2024 23:13
@0xApotheosis 0xApotheosis mentioned this pull request Feb 16, 2024
3 tasks
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.

Swapper sell and buy accounts should synchronize by default
3 participants