-
Notifications
You must be signed in to change notification settings - Fork 0
Create umbruella package #27
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| { | ||
| "name": "@cowprotocol/sdk", | ||
| "version": "7.0.0-RC.01", | ||
| "license": "(MIT OR Apache-2.0)", | ||
| "description": "CowProtocol SDK - Complete umbrella package for CoW Protocol interactions", | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "sideEffects": false, | ||
| "files": [ | ||
| "dist/**" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsup src/index.ts --format esm,cjs --dts", | ||
| "lint": "eslint src/**/*.ts", | ||
| "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
| }, | ||
| "devDependencies": { | ||
| "@repo/typescript-config": "workspace:*", | ||
| "@types/node": "^20.17.31", | ||
| "jest": "^29.7.0", | ||
| "ts-node": "^10.8.2", | ||
| "tsup": "^7.2.0", | ||
| "typescript": "^5.2.2" | ||
| }, | ||
| "dependencies": { | ||
| "@cowprotocol/sdk-common": "workspace:*", | ||
| "@cowprotocol/sdk-config": "workspace:*", | ||
| "@cowprotocol/sdk-contracts-ts": "workspace:*", | ||
| "@cowprotocol/sdk-app-data": "workspace:*", | ||
| "@cowprotocol/sdk-order-book": "workspace:*", | ||
| "@cowprotocol/sdk-subgraph": "workspace:*", | ||
| "@cowprotocol/sdk-cow-shed": "workspace:*", | ||
| "@cowprotocol/sdk-trading": "workspace:*", | ||
| "@cowprotocol/sdk-composable": "workspace:*", | ||
| "@cowprotocol/sdk-order-signing": "workspace:*" | ||
| }, | ||
| "peerDependencies": { | ||
| "cross-fetch": "^3.x", | ||
| "ipfs-only-hash": "^4.x", | ||
| "multiformats": "^9.x", | ||
| "@openzeppelin/merkle-tree": "^1.x" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "cross-fetch": { | ||
| "optional": false | ||
| }, | ||
| "ipfs-only-hash": { | ||
| "optional": true | ||
| }, | ||
| "multiformats": { | ||
| "optional": true | ||
| }, | ||
| "@openzeppelin/merkle-tree": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "keywords": [ | ||
| "cow-protocol", | ||
| "ethereum", | ||
| "defi", | ||
| "trading", | ||
| "dex", | ||
| "mev-protection", | ||
| "batch-auctions", | ||
| "sdk", | ||
| "typescript" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/cowprotocol/cow-sdk.git", | ||
| "directory": "packages/sdk" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/cowprotocol/cow-sdk/issues" | ||
| }, | ||
| "homepage": "https://github.com/cowprotocol/cow-sdk#readme" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { setGlobalAdapter } from '@cowprotocol/sdk-common' | ||
| import { MetadataApi } from '@cowprotocol/sdk-app-data' | ||
| import { OrderBookApi } from '@cowprotocol/sdk-order-book' | ||
| import { ApiBaseUrls, SupportedChainId } from '@cowprotocol/sdk-config' | ||
| import { ApiContext } from '@cowprotocol/sdk-config' | ||
| import { CowSdkOptions } from './types' | ||
| import { SubgraphApi } from '@cowprotocol/sdk-subgraph' | ||
| import { ContractsTs } from '@cowprotocol/sdk-contracts-ts' | ||
| import { CowShedSdk } from '@cowprotocol/sdk-cow-shed' | ||
| import { TradingSdk } from '@cowprotocol/sdk-trading' | ||
| import { ConditionalOrderFactory, Multiplexer, ProofLocation } from '@cowprotocol/sdk-composable' | ||
| import { OrderSigningUtils } from '@cowprotocol/sdk-order-signing' | ||
|
|
||
| // Re-export all components for easier access | ||
| export * from '@cowprotocol/sdk-app-data' | ||
| export * from '@cowprotocol/sdk-order-book' | ||
| export * from '@cowprotocol/sdk-subgraph' | ||
| export * from '@cowprotocol/sdk-contracts-ts' | ||
| export * from '@cowprotocol/sdk-cow-shed' | ||
| export * from '@cowprotocol/sdk-trading' | ||
| export * from '@cowprotocol/sdk-composable' | ||
| export * from '@cowprotocol/sdk-order-signing' | ||
|
|
||
| /** | ||
| * CowSdk is the main entry point for interacting with the CoW Protocol. | ||
| * Provides access to all modules in a single unified interface. | ||
| */ | ||
| export class CowSdk { | ||
| public readonly orderBook: OrderBookApi | ||
| public readonly appData: MetadataApi | ||
| public readonly subgraph: SubgraphApi | ||
| public readonly contracts: ContractsTs | ||
| public readonly cowShed?: CowShedSdk | ||
| public readonly trading?: TradingSdk | ||
| public readonly composable?: { | ||
| factory: ConditionalOrderFactory | ||
| multiplexer?: Multiplexer | ||
| } | ||
| public readonly orderSigning: OrderSigningUtils | ||
|
|
||
| private readonly chainId: SupportedChainId | ||
|
|
||
| /** | ||
| * Creates a new instance of CowSdk | ||
| * | ||
| * @param options Configuration options for the SDK | ||
| */ | ||
| constructor(options: CowSdkOptions) { | ||
| const { | ||
| adapter, | ||
| chainId, | ||
| env = 'prod', | ||
| orderBookOptions = {}, | ||
| orderBookBaseUrl, | ||
| subgraphOptions = {}, | ||
| subgraphBaseUrl, | ||
| tradingOptions = {}, | ||
| composableOptions = {}, | ||
| cowShedOptions = {}, | ||
| } = options | ||
|
|
||
| this.chainId = chainId | ||
|
|
||
| setGlobalAdapter(adapter) | ||
|
|
||
| const orderBookContext: ApiContext = { | ||
| chainId, | ||
| env, | ||
| ...orderBookOptions, | ||
| } | ||
|
|
||
| if (orderBookBaseUrl) { | ||
| orderBookContext.baseUrls = { | ||
| ...(orderBookContext.baseUrls || {}), | ||
| [chainId]: orderBookBaseUrl, | ||
| } as ApiBaseUrls | ||
| } | ||
|
|
||
| this.orderBook = new OrderBookApi(orderBookContext) | ||
|
|
||
| this.appData = new MetadataApi(adapter) | ||
|
|
||
| const subgraphContext = { | ||
| chainId, | ||
| env, | ||
| ...(subgraphOptions.context || {}), | ||
| ...(subgraphBaseUrl && { | ||
| baseUrls: Object.values(SupportedChainId).reduce( | ||
| (acc, chainId) => ({ | ||
| ...acc, | ||
| [chainId]: chainId === this.chainId ? subgraphBaseUrl : null, | ||
| }), | ||
| {}, | ||
| ) as Record<SupportedChainId, string | null>, | ||
| }), | ||
| } | ||
|
|
||
| this.subgraph = new SubgraphApi(subgraphContext, subgraphOptions.apiKey) | ||
|
|
||
| this.contracts = new ContractsTs(adapter) | ||
|
|
||
| this.cowShed = new CowShedSdk(adapter, cowShedOptions.factoryOptions) | ||
|
|
||
| this.trading = new TradingSdk( | ||
| tradingOptions.traderParams, | ||
| { | ||
| enableLogging: tradingOptions.options?.enableLogging, | ||
| orderBookApi: this.orderBook, | ||
| ...tradingOptions.options, | ||
| }, | ||
| adapter, | ||
| ) | ||
|
|
||
| this.composable = { | ||
| factory: new ConditionalOrderFactory(composableOptions.registry || {}, adapter), | ||
| multiplexer: new Multiplexer( | ||
| chainId, | ||
| composableOptions.orders, | ||
| composableOptions.root, | ||
| composableOptions.location || ProofLocation.PRIVATE, | ||
| ), | ||
| } | ||
|
|
||
| this.orderSigning = new OrderSigningUtils(adapter) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './CowSdk' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we export the types as well ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I will add this export. Tks! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { AbstractProviderAdapter } from '@cowprotocol/sdk-common' | ||
| import { | ||
| CowEnv, | ||
| PartialApiContext, | ||
| SupportedChainId, | ||
| PartialApiContext as OrderBookModuleOptions, | ||
| } from '@cowprotocol/sdk-config' | ||
|
|
||
| // Re-export constructor parameter types from individual packages | ||
| export type { ICoWShedOptions } from '@cowprotocol/sdk-cow-shed' | ||
| export type { TraderParameters } from '@cowprotocol/sdk-trading' | ||
| export type { ConditionalOrderRegistry, Orders, ProofLocation } from '@cowprotocol/sdk-composable' | ||
|
|
||
| /** | ||
| * SubgraphApi constructor: (context: PartialSubgraphApiContext = {}, apiKey?: string) | ||
| */ | ||
| export interface SubgraphModuleOptions { | ||
| context?: PartialApiContext | ||
| apiKey?: string | ||
| } | ||
|
|
||
| /** | ||
| * TradingSdk constructor: (traderParams: Partial<TraderParameters> = {}, options: Partial<TradingSdkOptions> = {}, adapter: AbstractProviderAdapter) | ||
| */ | ||
| export interface TradingModuleOptions { | ||
| traderParams?: Partial<TraderParameters> | ||
| options?: Partial<TradingSdkOptions> | ||
| } | ||
|
|
||
| // Re-export TradingSdkOptions from trading package | ||
| import type { TradingSdkOptions, TraderParameters } from '@cowprotocol/sdk-trading' | ||
|
|
||
| /** | ||
| * CowShedSdk constructor: (adapter: AbstractProviderAdapter, factoryOptions?: ICoWShedOptions) | ||
| */ | ||
| export interface CowShedModuleOptions { | ||
| factoryOptions?: ICoWShedOptions | ||
| } | ||
|
|
||
| // Re-export types needed for CowShed | ||
| import type { ICoWShedOptions } from '@cowprotocol/sdk-cow-shed' | ||
|
|
||
| /** | ||
| * ConditionalOrderFactory constructor: (registry: ConditionalOrderRegistry, adapter?: AbstractProviderAdapter) | ||
| * Multiplexer constructor: (chain: SupportedChainId, orders?: Orders, root?: string, location: ProofLocation = ProofLocation.PRIVATE) | ||
| */ | ||
| export interface ComposableModuleOptions { | ||
| registry?: ConditionalOrderRegistry | ||
| orders?: Orders | ||
| root?: string | ||
| location?: ProofLocation | ||
| } | ||
|
|
||
| // Re-export types needed for Composable | ||
| import type { ConditionalOrderRegistry, Orders, ProofLocation } from '@cowprotocol/sdk-composable' | ||
|
|
||
| /** | ||
| * Main CowSdk options interface | ||
| */ | ||
| export interface CowSdkOptions { | ||
| /** | ||
| * The chain ID to use for the SDK | ||
| */ | ||
| chainId: SupportedChainId | ||
|
|
||
| /** | ||
| * The adapter to use for signing transactions and blockchain interactions | ||
| */ | ||
| adapter: AbstractProviderAdapter | ||
|
|
||
| /** | ||
| * The environment to use (prod or staging) | ||
| * @default 'prod' | ||
| */ | ||
| env?: CowEnv | ||
|
|
||
| /** | ||
| * OrderBook API configuration options | ||
| */ | ||
| orderBookOptions?: OrderBookModuleOptions | ||
|
|
||
| /** | ||
| * Custom base URL for the OrderBook API | ||
| */ | ||
| orderBookBaseUrl?: string | ||
|
|
||
| /** | ||
| * Subgraph API configuration options | ||
| */ | ||
| subgraphOptions?: SubgraphModuleOptions | ||
|
|
||
| /** | ||
| * Custom base URL for the Subgraph API | ||
| */ | ||
| subgraphBaseUrl?: string | ||
|
|
||
| /** | ||
| * Trading SDK configuration options | ||
| */ | ||
| tradingOptions?: TradingModuleOptions | ||
|
|
||
| /** | ||
| * CoW Shed configuration options | ||
| */ | ||
| cowShedOptions?: CowShedModuleOptions | ||
|
|
||
| /** | ||
| * Composable CoW configuration options | ||
| */ | ||
| composableOptions?: ComposableModuleOptions | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "extends": "@repo/typescript-config/base.json", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again this is not referencing anything ❌ https://turborepo.com/docs/crafting-your-repository/structuring-a-repository#name |
||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "baseUrl": "src" | ||
| }, | ||
| "include": ["src/**/*"], | ||
| "exclude": ["node_modules", "dist"] | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 all other ones then are a subspace of this right?