Skip to content

Create cow trading package#26

Merged
jeffersonBastos merged 18 commits into
bleu/refactorfrom
jefferson/cow-430-create-cow-trading-package
Jun 25, 2025
Merged

Create cow trading package#26
jeffersonBastos merged 18 commits into
bleu/refactorfrom
jefferson/cow-430-create-cow-trading-package

Conversation

@jeffersonBastos
Copy link
Copy Markdown

@jeffersonBastos jeffersonBastos commented Jun 19, 2025

This PR refactors the trading package.
It also refactors the adapters and the integration interface, which led to changes in other packages and their corresponding tests.

alfetopito and others added 7 commits June 18, 2025 06:55
…eed up base branch sync (cowprotocol#354)

* chore: switch to pnpm and update Node.js to v20

* chore: reorganize project structure under packages/cow-sdk

* feat: init monorepo structure with Turborepo

* chore: format codebase with pnpm script

* chore: eslint config.

* chore: update lint config, .npmrc, and VSCode settings

* feat: copy entire src, tests folders, and package/tsconfig files from app-data project into the monorepo

* feat: add typescript-config

* feat: create common package with abstract adapter and context classes

* feat: implement adapters for ethers v5, ethers v6, and viem

* chore: update pnpm-lock

* chore: remove appdata and cow-sdk from build

* feat: create config package

* chore: fix eslint tsconfig path

* feat: refactor config

* chore: update pnpm-lock

* feat: add contracts-ts package

* feat: refactor contracts-ts

* feat: update adapters with new contracts-ts features

* feat: add tests for contracts-ts

* feat: move order-signing to new package

* feat: refactor order-signing

* feat: add new order-signing features to adapters

* feat: refactor order-signing tests

* feat: implement adapter usage in app-data; update app-data config and test files

* chore: update pnpm-lock file

* chore: fix lint and remove cow-sdk from lint.

* chore: update sdk-config tsconfig

* feat: add contracts-ts package

* feat: refactor contracts-ts

* feat: update adapters with new contracts-ts features

* feat: add tests for contracts-ts

* chore: update contracts-ts config

* chore(order-book): move order-book to monorepo package

* restore: bring back deleted type files with their history

* restore: bring back deleted config and path files with their history

* refactor: move cow-error and wallets.ts and remove duplicate types

* feat(order-book): setup order-book package, jest and tsconfig

* feat(order-book): refact order-book

* feat(monorepo-config): adjust all package.json and scripts

* chore(lint): lint

* chore(subgraph): move subgraph to monorepo package

* chore(subgraph): create package, tsconfig and jest config

* feat(subgraph): refactor subgraph package

* chore(subgraph): update pnpm-lock and run lint

* chore: add hashDomain to abstract utils

* feat: move composable package from original sdk to refactor sdk

* chore(subgraph): move cow-shed to monorepo package

* chore(cow-shed): copy wallets.ts

* feat(cow-shed): create package.json and tsconfig.json

* feat(cow-shed): add estimateGas method to SignerAdapters

* feat: refactor composable module to be framework-agnostic

* feat: enhance adapters and utils with composable features

* chore: move composable tests file to composable/tests

* feat: update tests to work with ethersV5 adapter

* feat: enhance composable to test the 3 adapters

* chore: remove console logs

* feat(cow-shed): refact on common and contract-ts

* chore(cow-shed): rename CowShedHooks test file

* feat(cow-shed): refact cow-she to use adapters and fix tests

* fix(cow-shed): fix adapters - estimateGas  and encodeAbi

* chore: lint files

* chore: move constants to sdk-common

* feat: update Node.js to version 22

* chore: align settings.json with .editorconfig configuration.

* chore: adjust cow-shed hooks test

* chore: add check to verify if the signature is the same across all three adapters in cowshedHooks test

* chore: apply PR suggestions

* chore: update pnpm-lock.json

* fix: viemUtils encodeAbi

---------

Co-authored-by: Jean Neiverth <jeanneiverth@gmail.com>
Co-authored-by: Jean Neiverth <79885562+jean-neiverth@users.noreply.github.com>
…, update tests, and add package, tsconfig and jest.config files
@jeffersonBastos jeffersonBastos self-assigned this Jun 19, 2025
@linear
Copy link
Copy Markdown

linear Bot commented Jun 19, 2025

@github-actions
Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all 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


0 out of 2 committers have signed the CLA.
@alfetopito
@jeffersonBastos
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@jeffersonBastos jeffersonBastos changed the title Jefferson/cow 430 create cow trading package Create cow trading package Jun 19, 2025
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Jun 19, 2025

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

@jeffersonBastos jeffersonBastos marked this pull request as ready for review June 19, 2025 21:35
Copy link
Copy Markdown

@jean-neiverth jean-neiverth left a comment

Choose a reason for hiding this comment

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

Took a look on the changes in composable, contracts-ts and order signing. They make sense to me, great job!

Comment thread package.json
Comment thread packages/app-data/jest.config.cjs Outdated
Comment thread packages/app-data/jest.config.cjs Outdated
Comment thread packages/app-data/babel.config.cjs Outdated
Comment thread packages/app-data/package.json
Comment thread packages/app-data/package.json
Comment thread packages/app-data/src/types/multiformats.d.ts Outdated
Comment thread packages/app-data/src/utils/stringify.ts Outdated
Comment thread packages/app-data/tsconfig.json Outdated
@@ -2,13 +2,15 @@
"extends": "@repo/typescript-config/base.json",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

#mustset a base config, not sure why this hasn't errored out before

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn’t get the issue... What exactly was supposed to throw an error?
Is it because it was overwriting the settings and should’ve thrown an error?
If so, it doesn’t actually throw an error—it allows overwriting the configurations, which is the expected behavior.
But I’ve already removed the specific settings from app-data.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the issue here is that there's no @reporight? So there's nowhere for TS to look for when you reference @repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I investigated the @repo reference issue, and here's what I found:
The @repo reference is working correctly because:

1 - The package has "@repo/typescript-config": "workspace:*" in its devDependencies
2 - PNPM workspace creates the necessary symlinks for TypeScript to resolve @repo
3 - The base config file exists at packages/typescript-config/base.json
4 - When I ran npx tsc --showConfig, it successfully loaded and merged the base configuration

Why it hasn't errored: TypeScript can resolve @repo through normal Node.js module resolution thanks to the workspace dependency. The workspace:* syntax tells pnpm to create a symlink, making @repo/typescript-config available in node_modules.

However, you're right that this could be more explicit. We could add a root tsconfig.json with proper path mapping for better clarity and IDE support. Would you like me to set that up?

Comment thread packages/common/src/abi/EthFlowAbi.ts
Comment thread packages/common/src/utils/index.ts
Comment thread packages/common/src/utils/privateKey.ts
Comment thread packages/composable/tests/Twap.spec.ts
Comment thread packages/contracts-ts/src/sign.ts
Comment thread packages/contracts-ts/src/sign.ts Outdated
setGlobalAdapter(adapters.viemAdapter)
const viemApi = new Api('mainnet', Environment.Prod)
const viemResult = await ethersV6Api.estimateTradeAmount(query)
const viemResult = await viemApi.estimateTradeAmount(query)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same as https://github.com/bleu/cow-sdk/pull/26/files#r2160984573. Also if this is an e2e test it should be marked as such.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Comment thread packages/contracts-ts/tests/api.test.ts
Comment thread packages/contracts-ts/tests/settlement.test.ts

// Create an encoder with incomplete price data
setGlobalAdapter(adapters[adapterNames[0]!])
setGlobalAdapter(adapters.ethersV5Adapter)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Comment thread packages/contracts-ts/tests/setup.ts
Copy link
Copy Markdown

@ribeirojose ribeirojose left a comment

Choose a reason for hiding this comment

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

another thing I noticed is that sometimes we're using a structure for packages with tests within the source folder (e.g. where pkg/src/**/*.ts and pkg/src/**/*.(test|spec).ts live all under the source folder. And sometimes we put tests in their own tests folder under on the same level of the src folder. I assume there's a specific reason for that, could you help me understand this?

Comment thread packages/typescript-config/base.json
Comment thread packages/trading/tsconfig.json
Comment thread packages/trading/tsconfig.json Outdated
'0x0000000000000000000000000000000000000000',
this.provider,
) as ethers.Signer & TypedDataSigner
// No signer provided, create VoidSigner for read-only operations
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤔 interesting pattern. Wouldn't read operations know that they don't need a signer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What do you mean? Read operations will always work—I believe the issue would be with write operations.
Are you asking if those operations need to be aware that it’s a void signer?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what I mean is should we even need a void signer if say we're only doing read operations?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think I get it now—I talked to Pedro to better understand this need. It’s true that there’s no need to create a void signer as the default; the client using the SDK can create a void signer if needed.

I’ll make some changes and let you know once they’re ready.
Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I updated the adapter by removing the default creation of the void signer.
Could you review it again? TKS!

Copy link
Copy Markdown

@ribeirojose ribeirojose left a comment

Choose a reason for hiding this comment

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

Huh, great job refactoring lots of stuff! I think I could review the most relevant parts of it and tried to leave helpful comments and suggestions. There's only #must IMO which is this comment. I highly encourage you to take a look at all the comments though. Happy to jump on a call / answer any other questions you might have wrt the review. Thanks for moving this forward!

@jeffersonBastos jeffersonBastos force-pushed the jefferson/cow-430-create-cow-trading-package branch from 76f1df7 to 0ac9a49 Compare June 23, 2025 19:24
@jeffersonBastos jeffersonBastos merged commit a0b36af into bleu/refactor Jun 25, 2025
3 of 8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 25, 2025
@jeffersonBastos jeffersonBastos removed their assignment Jun 26, 2025
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