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(permit): typefy hooks and allow only 1 permit #4726

Merged
merged 11 commits into from
Jul 17, 2024

Conversation

alfetopito
Copy link
Collaborator

Summary

Follow up/complement to #4721 and #4719

Makes sure there is ever only 1 permit, and only set it if really needed.

To Test

See test steps on #4719 and #4721

  • Should be able to place permit orders
  • Should not have double permit hooks
  • Should not have permit when not needed
  • Should allow to place regular orders

Copy link

vercel bot commented Jul 16, 2024

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

Name Status Preview Updated (UTC)
cosmos 🔄 Building (Inspect) Visit Preview Jul 17, 2024 10:35am
cowfi 🔄 Building (Inspect) Visit Preview Jul 17, 2024 10:35am
explorer-dev 🔄 Building (Inspect) Visit Preview Jul 17, 2024 10:35am
swap-dev 🔄 Building (Inspect) Visit Preview Jul 17, 2024 10:35am
widget-configurator 🔄 Building (Inspect) Visit Preview Jul 17, 2024 10:35am

: mergedHooks

console.log(`bug:updateHooksOnAppData`, noDuplicateHooks)
const filteredHooks = filterHooks(doc.metadata.hooks, preHooksFilter, postHooksFilter)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We shouldn't merge it here, because at this point we can't tell which hook is what

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Although this might have broken the hook store logic. Will need to address that, but probably in a different PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed the merging logic

Comment on lines +52 to +61
const preInteractionHooks = preHooks.map<TypedCowHook>((hookDetails) =>
cowHookToTypedCowHook(hookDetails.hook, 'hookStore')
)
const postInteractionHooks = postHooks.map<TypedCowHook>((hookDetails) =>
cowHookToTypedCowHook(hookDetails.hook, 'hookStore')
)
const hooks = buildAppDataHooks<TypedCowHook[], TypedAppDataHooks>({
preInteractionHooks: permitData
? preInteractionHooks.concat([cowHookToTypedCowHook(permitData, 'permit')])
: preInteractionHooks,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whatever hooks are created in the hook store, type then accordingly for later.

@@ -107,4 +107,4 @@ export const removeAppDataFromUploadQueueAtom = atom(
/**
* In memory atom for storing the current appData hooks info
*/
export const appDataHooksAtom = atom<AppDataHooks | undefined>(undefined)
export const appDataHooksAtom = atom<TypedAppDataHooks | undefined>(undefined)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Store typed hooks instead of plain ones.


import { AppDataHooks, CowHook, TypedAppDataHooks, TypedCowHook } from '../types'

export function cowHookToTypedCowHook(hook: CowHook, type: TypedCowHook['type']): TypedCowHook {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Utils for converting back and forth between the different hook formats (typed and regular)

return rest
}

export function addPermitHookToHooks(hooks: TypedAppDataHooks | undefined, permit: CowHook): AppDataHooks | undefined {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "merger" or regular hooks with permit hooks.
Takes care of replacing whatever permit there was before, if any.

const hooks = buildAppDataHooks({
preInteractionHooks: [permitData],
})
const hooks = addPermitHookToHooks(typedHooks, permitData)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is where the "merge" happens.
Permit is not added to the order anywhere else.

@elena-zh
Copy link
Contributor

elena-zh commented Jul 17, 2024

Hey @alfetopito , I've been able to sign a permit request in the wallet, but a LIMIT order placing has failed due to this error
image
I was placing USDC-DAI and COW/USDC limit order on Ethereum.

The next issue: I see that a trade hook is recorded into the next trade:
To reproduce:

  1. Select not approved permittable token, specify a trade
  2. Sign the approval message in the wallet, but do not place a trade
  3. Change a token pair: pick another token, that is already approved, into the sell field
  4. Place an order

AR: a hook inside appdata is displayed https://dev.explorer.cow.fi/orders/0x41ba5826bdf78d434447cec347ea679ef724430f347cdc2de[…]a3c00a92ec5f96b1ad2527ab41b3932efeda58669776d9?tab=overview

Copy link
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

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

Hey @alfetopito , great job, thank you for fixing this!
I have found only one issue, but it should not be a blocker for the current hotfix as it is related to the hooks store and can be addressed later. I opened #4727 task for this.

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.

2 participants