Skip to content

Commit

Permalink
Rndlabs chore repo prep (#136)
Browse files Browse the repository at this point in the history
* chore: coverage with and without coveralls

* fix: enforce reproducible build

* docs: inline typedoc

* chore: variable and const standardisation

* chore: remove dead code

* docs: inline

* fix: tag reference for upstream openapi.yml

---------

Co-authored-by: mfw78 <mfw78@protonmail.com>
  • Loading branch information
anxolin and mfw78 committed Aug 4, 2023
1 parent 9ce97c7 commit 3abfdcf
Show file tree
Hide file tree
Showing 16 changed files with 526 additions and 64 deletions.
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/jest-github-action@v1.0.3
Expand All @@ -48,6 +52,6 @@ jobs:

- name: Coveralls Report
uses: coverallsapp/github-action@1.1.3
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"
"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

0 comments on commit 3abfdcf

Please sign in to comment.