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

chore: preconfigured orderbook #198

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/cow-sdk",
"version": "4.1.0",
"version": "5.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

will this affect to anything in learn.cow.fi?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no use of polling yet in any tutorials there.

"license": "(MIT OR Apache-2.0)",
"files": [
"/dist"
Expand Down
5 changes: 4 additions & 1 deletion src/composable/ConditionalOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OwnerContext, PollParams, PollResultCode, PollResultErrors } from './ty
import { BuyTokenDestination, OrderKind, SellTokenSource } from '../order-book/generated'
import { computeOrderUid } from '../utils'
import { GPv2Order } from './generated/ComposableCoW'
import { OrderBookApi } from '../order-book'

jest.mock('./contracts')

Expand Down Expand Up @@ -172,7 +173,9 @@ describe('Cabinet', () => {
describe('Poll Single Orders', () => {
const mockSingleOrders = jest.fn()
const mockGetTradeableOrderWithSignature = jest.fn()
const param = { owner: OWNER, chainId: 1, provider: {} } as PollParams
const chainId = 1
const orderBookApi = new OrderBookApi({ chainId })
const param = { owner: OWNER, chainId, provider: {}, orderBookApi } as PollParams

const mockPollValidate = jest.fn<Promise<PollResultErrors | undefined>, [params: PollParams], any>()

Expand Down
12 changes: 2 additions & 10 deletions src/composable/ConditionalOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
PollResultErrors,
} from './types'
import { getComposableCow, getComposableCowInterface } from './contracts'
import { OrderBookApi, UID } from '../order-book'
import { UID } from '../order-book'
import { computeOrderUid } from '../utils'

const orderBookCache: Record<string, OrderBookApi> = {}

/**
* An abstract base class from which all conditional orders should inherit.
*
Expand Down Expand Up @@ -249,7 +247,7 @@ export abstract class ConditionalOrder<D, S> {
* @returns The tradeable `GPv2Order.Data` struct and the `signature` for the conditional order.
*/
async poll(params: PollParams): Promise<PollResult> {
const { chainId, owner, provider, orderbookApiConfig } = params
const { chainId, owner, provider, orderBookApi } = params
const composableCow = getComposableCow(chainId, provider)

try {
Expand Down Expand Up @@ -285,12 +283,6 @@ export abstract class ConditionalOrder<D, S> {
[]
)

let orderBookApi = orderBookCache[chainId]
if (!orderBookApi) {
orderBookApi = new OrderBookApi({ ...orderbookApiConfig, chainId })
orderBookCache[chainId] = orderBookApi
}

const orderUid = await computeOrderUid(chainId, owner, fromStructToOrder(order))

// Check if the order is already in the order book
Expand Down
8 changes: 1 addition & 7 deletions src/composable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,16 @@ export type OwnerContext = {
}

export type PollParams = OwnerContext & {
orderBookApi: OrderBookApi
offchainInput?: string
proof?: string[]

/**
* If present, it can be used for custom conditional order validations. If not present, the orders will need to get the block info themselves
*/
blockInfo?: BlockInfo

/**
* Allows to optional pass the config of the orderbook API
*/
orderbookApiConfig?: OrderBookApiConfig
}

export type OrderBookApiConfig = Omit<ConstructorParameters<typeof OrderBookApi>[0], 'chainId'>

export type BlockInfo = {
blockNumber: number
blockTimestamp: number
Expand Down