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 Conditional Order factory #151

Merged
merged 3 commits into from
Aug 29, 2023
Merged

Add Conditional Order factory #151

merged 3 commits into from
Aug 29, 2023

Conversation

anxolin
Copy link
Contributor

@anxolin anxolin commented Aug 24, 2023

This PR prepares the polling to hook it up to https://github.com/cowprotocol/tenderly-watch-tower

Conditional Order Factory

The main addition in this PR is this factory.

The factory responsibility is to create Conditional Orders from the ConditionalOrderParams (handler, salt, staticInput)

It has some config with the factory methods per handler.

Some basic usage is:

# Create factory
const factory = new ConditionalOrderFactory({
  // Register of all known order types
  [TWAP_ADDRESS]: (params) => Twap.fromParams(params),
})

# Then you can create an order just by 
const conditionalOrder = fromParams.fromParams({
   handler,
   salt
   staticInput
})

# Default Registry
The factory requires a registry in order to work
The registry has the different factory methods per handler

The SDK will also export some default config with all the handlers/facttory it knows: for now, only `Twap`: https://github.com/cowprotocol/cow-sdk/pull/151/files#diff-cc93eafdc1844adfa999909a952edcc111abb3031a0eac57403966f6a3c8d00eR5

# Use the order
console.log('Order: ', conditionalOrder.id)

# Now is easy to do polling (and custom validation), without even knowing what order we are processing
console.log('Polling result: ', await order.poll(owner, chainId, provider ))

Companion PR

This PR will have a companion PR in tenderly watch tower project:
cowprotocol/watch-tower#16

@github-actions
Copy link

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

@coveralls
Copy link
Collaborator

coveralls commented Aug 24, 2023

Coverage Status

coverage: 76.271% (-1.3%) from 77.586% when pulling 32e7421 on conditional-order-factory into e77585b on main.

@anxolin anxolin changed the title Add factory Add Conditional Order factory Aug 24, 2023
@anxolin anxolin marked this pull request as ready for review August 24, 2023 20:32
mfw78

This comment was marked as outdated.

Copy link
Contributor

@mfw78 mfw78 left a comment

Choose a reason for hiding this comment

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

Looks good, please see nits in the review here yet to be included (typos etc).

src/composable/orderTypes/Twap.ts Outdated Show resolved Hide resolved
src/composable/orderTypes/Twap.ts Show resolved Hide resolved
src/composable/orderTypes/index.ts Outdated Show resolved Hide resolved
@anxolin anxolin merged commit 34fbd9a into main Aug 29, 2023
5 of 6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2023
@alfetopito alfetopito deleted the conditional-order-factory branch August 30, 2023 08:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants