Skip to content

Commit

Permalink
docs: add info about TradingSDK to main readme (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 authored Dec 24, 2024
1 parent 6f3f5c0 commit 7658e39
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,50 @@
yarn add @cowprotocol/cow-sdk
```

### Content
## [Trading SDK](./src/trading/README.md)

CoW Protocol is intent based, decentralized trading protocol that allows users to trade ERC-20 tokens.

The basic swap flow:
1. 🔎 Get a quote (price) for a trade (_or define your own price with a limit order_)
2. ✍️ Sign the order
3. ✅ Post the order to the order-book

The easiest way to start trading is to use the `TradingSdk`:

```typescript
import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'

// Initialize the SDK
const sdk = new TradingSdk({
chainId: SupportedChainId.SEPOLIA,
signer: '<privateKeyOrEthersSigner>',
appCode: '<YOUR_APP_CODE>',
})

// Define trade parameters
const parameters: TradeParameters = {
kind: OrderKind.BUY,
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
sellTokenDecimals: 18,
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
buyTokenDecimals: 18,
amount: '120000000000000000'
}

// Post the order
const orderId = await sdk.postSwapOrder(parameters)

console.log('Order created, id: ', orderId)
```

This example is the simplest way to trade on CoW Protocol.

You might want to use more advanced parameters like `receiver`, `partiallyFillable`, `validTo` and others.
Check the [Trading SDK documentation](./src/trading/README.md) for more details.


## Other utilities

- `OrderBookApi` - provides the ability to retrieve orders and trades from the CoW Protocol order-book, as well as add and cancel them
- `OrderSigningUtils` - serves to sign orders and cancel them using [EIP-712](https://eips.ethereum.org/EIPS/eip-712)
Expand All @@ -38,8 +81,6 @@ const subgraphApi = new SubgraphApi({ chainId })
const orderSigningUtils = new OrderSigningUtils()
```

## Quick start

### Sign, fetch, post and cancel order

For clarity, let's look at the use of the API with a practical example:
Expand Down
Binary file modified docs/images/CoW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/trading/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Trading SDK

CoW Protocol is intent based, decentralized trading protocol that allows users to trade ERC-20 tokens.

The basic swap flow:
1. 🔎 Get a quote (price) for a trade
2. ✍️ Sign the order
3. ✅ Post the order to the order-book

The CoW Protocol provides very flexible and powerful trading capabilities.
However, this flexibility comes with a cost: the complexity of the protocol.
This SDK serves to simplify the interaction with the CoW Protocol.
Expand All @@ -25,6 +32,10 @@ The SDK provides three main functions:
- `postLimitOrder` - create a limit order
- `getQuote` - fetch a quote for a swap order

And two for specific cases:
- `postSellNativeCurrencyOrder` - create an order to sell blockchain native tokens (ETH for Ethereum)
- `getPreSignTransaction` - get a transaction to sign the order with a smart-contract wallet (EIP-1271)

### Initialization

The SDK requires the following parameters:
Expand Down

0 comments on commit 7658e39

Please sign in to comment.