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

Rndlabs chore repo prep #136

Merged
merged 7 commits into from
Aug 4, 2023
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
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ jobs:
yarn install --cache-folder ./.yarncache --frozen-lockfile
rm -rf .yarncache
yarn cache clean
- name: Run tests
- name: Run tests with coverage
run: yarn run test:coverage
if: env.COVERALLS_REPO_TOKEN != ''
- name: Run tests without coverage
run: yarn run test
if: env.COVERALLS_REPO_TOKEN == ''

- name: Comment in failing tests
uses: mattallty/[email protected]
Expand All @@ -48,6 +52,6 @@ jobs:

- name: Coveralls Report
uses: coverallsapp/[email protected]
if: success() || failure()
if: (success() || failure()) && env.COVERALLS_REPO_TOKEN != ''
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
"format": "prettier --write \"src/**/*.+(ts|json)\"",
"test": "jest",
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && cat ./coverage/lcov.info | coveralls",
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
"codegen": "npm run graphql:codegen && npm run swagger:codegen",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/main/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false"
mfw78 marked this conversation as resolved.
Show resolved Hide resolved
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.117.1/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false"
},
"dependencies": {
"@cowprotocol/contracts": "^1.4.0",
Expand Down
4 changes: 4 additions & 0 deletions src/common/chains.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Supported chains and their `chainId` for the SDK.
* @enum
*/
export enum SupportedChainId {
MAINNET = 1,
GOERLI = 5,
Expand Down
48 changes: 48 additions & 0 deletions src/common/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { SupportedChainId } from './chains'
import { BackoffOptions } from 'exponential-backoff'
import { RateLimiterOpts } from 'limiter/dist/esm'

/**
* IPFS configuration.
*
* For production use, consider using {@link Pinata: https://www.pinata.cloud/}
* @property {string} [uri] The URI of the IPFS node to use.
* @property {string} [writeUri] The URI of the IPFS node to use for writing.
* @property {string} [readUri] The URI of the IPFS node to use for reading.
* @property {string} [pinataApiKey] The API key to use for Pinata.
* @property {string} [pinataApiSecret] The API secret to use for Pinata.
*/
export interface IpfsConfig {
uri?: string
writeUri?: string
Expand All @@ -10,25 +20,63 @@ export interface IpfsConfig {
pinataApiSecret?: string
}

/**
* @property {RateLimiterOpts} [limiterOpts] The options to use for the rate limiter.
* @property {BackoffOptions} [backoffOpts] The options to use for the backoff.
*/
export interface RequestOptions {
limiterOpts?: RateLimiterOpts
backoffOpts?: BackoffOptions
}

/**
* The environment to use for the Cow API.
*/
export type CowEnv = 'prod' | 'staging'

/**
* Override some properties of the {@link ApiContext}.
*/
export type PartialApiContext = Partial<ApiContext>

/**
* @property {string} [1] The base URL for the mainnet API.
* @property {string} [5] The base URL for the Goerli testnet API.
* @property {string} [100] The base URL for the Gnosis Chain API.
*/
export type ApiBaseUrls = Record<SupportedChainId, string>

/**
* Define the context to use for the CoW Protocol API.
*
* CoW Protocol is a set of smart contracts and off-chain services, deployed on **multiple chains**.
* {@link SupportedChainId Supported chains} are:
* - Mainnet
* - Goerli
* - Gnosis Chain
*
* Each chain has it's own API, and each API has it's own base URL.
*
* Options may be selectively overridden by passing a {@link PartialApiContext} to the constructor.
* @see {@link https://api.cow.fi/docs/#/}
* @property {SupportedChainId} chainId The `chainId`` corresponding to this CoW Protocol API instance.
* @property {CowEnv} env The environment that this context corresponds to.
* @property {ApiBaseUrls} [baseUrls] URls that may be used to connect to this context.
*/
export interface ApiContext {
chainId: SupportedChainId
env: CowEnv
baseUrls?: ApiBaseUrls
}

/**
* The list of available environments.
*/
export const ENVS_LIST: CowEnv[] = ['prod', 'staging']

/**
* The default CoW Protocol API context.
*/
export const DEFAULT_COW_API_CONTEXT: ApiContext = {
env: 'prod',
chainId: SupportedChainId.MAINNET,
Expand Down
8 changes: 8 additions & 0 deletions src/common/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import contractNetworks from '@cowprotocol/contracts/networks.json'

const { GPv2Settlement } = JSON.parse(contractNetworks as unknown as string) as typeof contractNetworks

export const BUY_ETH_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'

/**
* The list of supported chains.
*/
export const ALL_SUPPORTED_CHAIN_IDS: SupportedChainId[] = [
SupportedChainId.MAINNET,
SupportedChainId.GOERLI,
SupportedChainId.GNOSIS_CHAIN,
]

/**
* An object containing the addresses of the CoW Protocol settlement contracts for each supported chain.
*/
export const COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS = ALL_SUPPORTED_CHAIN_IDS.reduce<Record<number, string>>(
(acc, chainId) => ({
...acc,
Expand Down
2 changes: 1 addition & 1 deletion src/order-book/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CowError } from '../common/cow-error'
import { OrderBookApi } from './api'
import { BuyTokenDestination, EcdsaSigningScheme, OrderKind, SellTokenSource, SigningScheme } from './generated'
import { SupportedChainId } from '../common/chains'
import { BUY_ETH_ADDRESS } from './transformOrder'
import { BUY_ETH_ADDRESS } from '../common/consts'
import { AUCTION } from './mock'

enableFetchMocks()
Expand Down
Loading
Loading