cowprotocol / cow-sdk

CoW protocol SDK
https://docs.cow.fi/cow-protocol/reference/sdks/cow-sdk
Other
31 stars 9 forks source link

Add Conditional Order factory #151

Closed anxolin closed 1 year ago

anxolin commented 1 year ago

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: https://github.com/cowprotocol/tenderly-watch-tower/pull/16

github-actions[bot] commented 1 year ago

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 commented 1 year ago

Coverage Status

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