Skip to content

gogonimago/cowswap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests Styled With Prettier

CoW Swap is the first trading interface built on top of CoW Protocol.

It allows you to buy and sell tokens using gasless orders that are settled peer-to-peer among its users or into any on-chain liquidity source while providing MEV protection.

Please see the:

You can block an entire list of tokens by passing in a tokenlist like here or you can block specific tokens by adding them to unsupported.tokenlist.json.

Install Dependencies

yarn

Run

yarn start

build

yarn build

# Analyze CoW Swap bundle
#   Use one of the following templates: "sunburst" | "treemap" | "network" | "raw-data" | "list";
ANALYZE_BUNDLE=true ANALYZE_BUNDLE_TEMPLATE=sunburst yarn build

Unit testing

yarn test

Integration test

Make sure you add the required environment varianbles to your .env.local file with:

  • INTEGRATION_TEST_PRIVATE_KEY=<your-private-key>: Private key
  • INTEGRATION_TESTS_INFURA_KEY=<your-infura-key>: Infura key

To launch it with our development server (so you have live-reloading):

yarn start
yarn cypress

Alternativelly, you can build the project and launch the integration test.

yarn build
yarn integration-test

If we want to use the Cypress UI:

yarn build
yarn serve
yarn cypress

Run cosmos

This will start a server on the http://localhost:5000/

yarn run cosmos

Build/test UI Library

CoW Swap has a library of reusable components.

yarn ui:build
yarn ui:test

Configuring the environment

The app has some default configuration, but it's highly encouraged to define your own.

Local configuration

Make a copy of .env named .env.local, this will allow you to set your own configuration only in your local environment.

What is the mandatory minimum to be able to run the application?

Your environment MUST have the following variables defined: REACT_APP_INFURA_KEY=YOUR_INFURA_KEY REACT_APP_NETWORK_URL_1=https://mainnet.infura.io/v3/{YOUR_INFURA_KEY} REACT_APP_NETWORK_URL_5=https://goerli.infura.io/v3/{YOUR_INFURA_KEY}

Additionally, to successfully run E2E / Integration tests locally you must have; INTEGRATION_TESTS_INFURA_KEY=YOUR_INFURA_KEY INTEGRATION_TESTS_PRIVATE_KEY=YOUR_TEST_WALLET_PRIVATE_KEY

Production configuration

Modify the environment variables in .env.production, or override them in build time.

Price feeds

CoW Swap tries to find the best price available on-chain using some price feeds.

All price feeds are enabled by default, but they can be individually disabled by using an environment variable:

Name Environment variable Type Description
CoW Protocol REACT_APP_PRICE_FEED_GP_ENABLED boolean (default = true) CoW Protocol price estimation. Used for all price estimation.
Paraswap REACT_APP_PRICE_FEED_PARASWAP_ENABLED boolean (default = true) Paraswap price estimation. Used for all price estimations.
1inch REACT_APP_PRICE_FEED_1INCH_ENABLED boolean (default = true) Paraswap price estimation. Used for all price estimations.
0x REACT_APP_PRICE_FEED_0X_ENABLED boolean (default = true) 0x price estimation. Used for all price estimation.

Metadata attached to orders (AppData)

The app will attach some metadata to all orders.

This metadata will be sent to the smart contract as a hexadecimal value in an order field called AppData. This value comes from hashing the content of a metadata JSON containing some information about the trade (using keccak256 on the UTF-8 bytes).

The format of the JSON follows this typescript format: <src/utils/metadata.ts>

To set your own AppData, change REACT_APP_FULL_APP_DATA_<environment> environment variable. For more details, check out the environment file (<.env>)

Supported networks

You should set your own RPC endpoints by defining the following environment variables:

# Define your own RPC endpoints
REACT_APP_NETWORK_URL_1=https://mainnet.infura.io/v3/{YOUR_INFURA_KEY}
REACT_APP_NETWORK_URL_5=https://goerli.infura.io/v3/{YOUR_INFURA_KEY}
REACT_APP_NETWORK_URL_100=https://rpc.gnosischain.com

If you plan to use Infura, you can omit defining the RPC endpoints, and just define the REACT_APP_INFURA_KEY environment variable.

# Alternatively you can just define your Infura key (instead of defining the RPC endpoints)
REACT_APP_INFURA_KEY={YOUR_INFURA_KEY}

### API endpoints

Fee quote requests and posting orders are sent to an API. This API has the responsibility of collecting orders and
handing them to the solvers.

The reference implementation of the API is [gp-v2-services](https://github.com/cowprotocol/services).

The API endpoint is configured using the environment variable ` {XDAI|GOERLI|MAINNET}` to e.g. `"http://localhost:8080/api"` when running the services locally.

### Wallet Connect bridge

Wallet Connect allows to connect the app to any [Wallet Connect supported wallet](https://walletconnect.org/wallets).

In order to do so, it uses a Websocket, that can be configured using: the env var `WALLET_CONNECT_BRIDGE`.

## Sitemap

The sitemap can be found in <./public/sitemap.xml>

To update its content:

1. Edit the list of pages in <./src/sitemap.js>
2. Run `yarn sitemap`
3. Commit the changes to git

## Service worker

In case of problems with the service worker cache you force a reset using [emergency.js](apps/cowswap-frontend/public/emergency.js)
The plan:

1. `const resetCacheInCaseOfEmergency = false` - change `false` to `true`
2. Deploy a new version to production

`emergency.js` is not cached by browser and loaded before all.

## Wallet Connect

The app uses a Wallet Connect v1 bridge.

You can define your own bridge by setting the following environment variable:

```ini
REACT_APP_WALLET_CONNECT_V1_BRIDGE='https://bridge.walletconnect.org'
```

## Documentation

1. [Oveall Architecture](docs/architecture-overview.md)
2. [Amounts formatting](apps/cowswap-frontend/src/utils/amountFormat/README.md)
3. [ABIs](libs/abis/README.md)

About

🐮 CowSwap: First CoW Protocol UI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.4%
  • Other 0.6%