npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ccip-sdk

v4.0.24

Published

```bash yarn add ccip-sdk ```

Downloads

47

Readme

Installation

yarn add ccip-sdk

Content

  • 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
import { OrderBookApi, OrderSigningUtils, SubgraphApi } from 'ccip-sdk'

const chainId = 100 // Gnosis chain

const orderBookApi = new OrderBookApi({ chainId })

const orderSigningUtils = new OrderSigningUtils()

Quick start

import { OrderBookApi, OrderSigningUtils, SupportedChainId } from '@cowprotocol/cow-sdk'
import { Web3Provider } from '@ethersproject/providers'

const account = 'YOUR_WALLET_ADDRESS'
const chainId = 5 // Goerli
const provider = new Web3Provider(window.ethereum)
const signer = provider.getSigner()

const quoteRequest = {
  sellToken: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', // WETH goerli
  buyToken: '0x02abbdbaaa7b1bb64b5c878f7ac17f8dda169532', // GNO goerli
  from: account,
  receiver: account,
  sellAmountBeforeFee: (0.4 * 10 ** 18).toString(), // 0.4 WETH
  kind: OrderQuoteSide.kind.SELL,
}

const orderBookApi = new OrderBookApi({ chainId: SupportedChainId.GOERLI })

async function main() {
    const { quote } = await orderBookApi.getQuote(quoteRequest)

    const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)

    const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })

    const order = await orderBookApi.getOrder(orderId)

    const trades = await orderBookApi.getTrades({ orderId })

    const orderCancellationSigningResult = await OrderSigningUtils.signOrderCancellations([orderId], chainId, signer)

    const cancellationResult = await orderBookApi.sendSignedOrderCancellations({...orderCancellationSigningResult, orderUids: [orderId] })

    console.log('Results: ', { orderId, order, trades, orderCancellationSigningResult, cancellationResult })
}

OrderBookApi

OrderBookApi - is a main tool for working Since the API supports different networks and environments, there are some options to configure it.

Environment configuration

chainId - can be one of SupportedChainId.MAINNET, SupportedChainId.GNOSIS_CHAIN, or SupportedChainId.GOERLI

env - this parameter affects which environment will be used:

  • https://api.cow.fi for prod (default)
  • https://barn.api.cow.fi for staging
import { OrderBookApi } from '@cowprotocol/cow-sdk'

const orderBookApi = new OrderBookApi({
  chainId: SupportedChainId.GOERLI,
  env: 'staging' // <-----
})

API urls configuration

In case you need to use custom endpoints (e.g. you use a proxy), you can do it this way:

import { OrderBookApi } from '@cowprotocol/cow-sdk'

const orderBookApi = new OrderBookApi({
  chainId: SupportedChainId.GOERLI,
  baseUrls: { // <-----
    [SupportedChainId.MAINNET]: 'https://YOUR_ENDPOINT/mainnet',
    [SupportedChainId.GNOSIS_CHAIN]: 'https://YOUR_ENDPOINT/xdai',
    [SupportedChainId.GOERLI]: 'https://YOUR_ENDPOINT/goerli',
  }
})

The client's limiter settings can be configured as well:

import { OrderBookApi } from '@cowprotocol/cow-sdk'
import { BackoffOptions } from 'exponential-backoff'
import { RateLimiterOpts } from 'limiter'

const limiterOpts: RateLimiterOpts = {
  tokensPerInterval: 5,
  interval: 'second',
}

const backOffOpts: BackoffOptions = {
  numOfAttempts: 5,
  maxDelay: Infinity,
  jitter: 'none',
}

const orderBookApi = new OrderBookApi(
  {chainId: SupportedChainId.GOERLI, limiterOpts, backOffOpts},
)

Architecture

One way to make the most out of the SDK is to get familiar with its architecture.

Development

Install Dependencies

yarn

Build

yarn build

# Build in watch mode
yarn start

Unit testing

yarn test

Code generation

Some parts of the SDK are automatically generated. This is the case for the Order Book API and the Subgraph API

# Re-create automatically generated code
yarn codegen