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(eth-flow): update refund info for expired orders #3222

Merged
merged 4 commits into from
Oct 16, 2023

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Oct 13, 2023

Summary

Fixes #3218

The problem was in ExpiredOrdersUpdater, it was updating only orders created within the last 15 minutes, obviously, no one expired eth-flow order doesn't match this condition.

image

To Test

  1. Create an eth-flow order that won't be filled (I created sell 0,0009 ETH for USDC on Mainnet)
  2. Wait until the order become expired
  3. Open activities modal
  • Within next ~1 min the state of the order should be changed from "Initiating ETH refund..." to "ETH refunded"

@shoom3301 shoom3301 added the RELEASE Included in the release that is being closed label Oct 13, 2023
@shoom3301 shoom3301 requested a review from a team October 13, 2023 07:22
@shoom3301 shoom3301 self-assigned this Oct 13, 2023
@vercel
Copy link

vercel bot commented Oct 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Oct 13, 2023 11:14am

🌃 Cosmos ↗︎

Comment on lines 37 to 38
const pending = expiredRef.current.filter(({ owner, refundHash }) => {
return owner.toLowerCase() === lowerCaseAccount && !refundHash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, this might be a problem, because we'll forever try to update expired orders that are not ETH FLOW (don't have refundHash), and that's why this check was there in the first place.

Maybe it should only NOT have the limit when it's an ETH FLOW order.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch!
Added a check: 1a06dd7

Copy link
Contributor

Choose a reason for hiding this comment

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

But what if an order is expired, and we don't know if its traded or not trade?
we created the order, closed the browswe and came back 1h later

will we update the order and get the right state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we will.
It's actually this case: #3222 (comment)

@alfetopito alfetopito self-requested a review October 13, 2023 10:24
@anxolin
Copy link
Contributor

anxolin commented Oct 13, 2023

The PR healed my state automatically
image

owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash
)
const pending = expiredRef.current.filter(({ owner, refundHash }) => {
return owner.toLowerCase() === lowerCaseAccount && !refundHash
})

if (pending.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not from this PR, but i would just remove the ELSE. the IF already returns early, so there's no point

Copy link
Contributor

Choose a reason for hiding this comment

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

also delete the dead code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It actually makes sense.
If we don't have any pending orders, we should not move further.
I see only one exit before, when isUpdating.current is truth, but it's different

return (
owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash
)
const pending = expiredRef.current.filter(({ owner, refundHash }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this. We only check the new state on expired orders?
the method is called updateOrders, but it looks like is just for handling these type of orders

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we update for all orders: pending and expired+un-refunded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, as far as I understand, the updater does only one thing:
It takes expired eth-flow orders without refundHash value and set it if it exists in order-book

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

6b03ec1
Fixed namings to avoid confusion

Copy link
Collaborator

Choose a reason for hiding this comment

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

The initial goal of this updater (pre-ethflow) was to check orders that matched after the UI already considered them expired

return (
owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash
)
return isEthFlowOrder && owner.toLowerCase() === lowerCaseAccount && !refundHash
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about regular orders?
Now they are not checked at all.

I meant to keep the former behaviour for regular orders, and check ethflow orders without a refund hash indefinitely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But only eth-flow order might have refundHash, isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, you are 100% correct.
I was confusing this updated with the CancelledOrdersUpdater

@alfetopito alfetopito merged commit dede0d0 into release/1.48.0 Oct 16, 2023
6 checks passed
@alfetopito alfetopito deleted the fix/3218 branch October 16, 2023 10:54
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
RELEASE Included in the release that is being closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants