Giter Site home page Giter Site logo

gnosis / cowswap Goto Github PK

View Code? Open in Web Editor NEW
114.0 11.0 55.0 66.69 MB

๐Ÿฎ CowSwap: First Gnosis Protocol v2 UI

Home Page: https://gnosis.io

License: GNU General Public License v3.0

HTML 0.18% JavaScript 0.47% Shell 0.14% TypeScript 99.22%

cowswap's Introduction

Gitpod ready-to-code

Lint Tests Styled With Prettier

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

It allows you to buy and sell tokens using gas-less 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

Unit testing

yarn test

Integration test

Normally:

yarn build
yarn integration-test

If we want to use the Cypress UI:

yarn build
yarn serve
yarn cypress

If we want to use the Cypress UI, and live reloading on the web app:

yarn start:default
yarn cypress

Run cosmos

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

yarn run cosmos

Configuring the environment (optional)

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.

Production configuration

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

Price feeds

CowSwap tries to find the best price available onchain 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.
0x REACT_APP_PRICE_FEED_0X_ENABLED boolean (default = true) 0x price estimation. Used for all price estimation.
Coingecko REACT_APP_PRICE_FEED_COINGECKO_ENABLED boolean (default = true) Coingecko price estimation. Used only for USD estimations to calculate the slippage on the trade.

Metadata attached to orders (AppData)

The app will attach some metadata to all orders.

This metadata will be sent to the smart contract as an 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.

Any web app or client using CoW Protocol can upload to IPFS a metadata JSON and use the digest hex to attach that information to the order.

For example, CowSwap uploaded the file https://cloudflare-ipfs.com/ipfs/QmTDarZ47oek1miuRd8uuNCy5AFfjzQbWJ7348izx9N8wQ which has the hexadecimal digest 0x487B02C558D729ABAF3ECF17881A4181E5BC2446429A0995142297E897B6EB37 (See CID Explorer for more details).

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

To set your own AppData, change REACT_APP_DOMAIN_REGEX_<environment> environment variable. Ask for yours at chat.cowswap.exchange/. For more details, check out the environment file (<.env>)

Supported networks

You can change the supported networks and their RPC endpoint.

To have the interface default to a different network when a wallet is not connected:

  1. Change REACT_APP_NETWORK_ID to "{YOUR_NETWORK_ID}". This will be your default network id
  2. Define your own list of supported networks:
REACT_APP_SUPPORTED_CHAIN_IDS="1,4,100"
REACT_APP_NETWORK_URL_1=https://mainnet.infura.io/v3/{YOUR_INFURA_KEY}
REACT_APP_NETWORK_URL_4=https://rinkeby.infura.io/v3/{YOUR_INFURA_KEY}
REACT_APP_NETWORK_URL_100=https://rpc.xdaichain.com

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 th API is gp-v2-services.

The API endpoint is configured using the environment variable {XDAI|RINKEBY|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.

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/custom/sitemap.js>
  2. Run yarn sitemap
  3. Commit the changes to git

cowswap's People

Contributors

alfetopito avatar alongoni avatar anxolin avatar avsavsavs avatar callil avatar chikeichan avatar crowdin-bot avatar dependabot[bot] avatar fairlighteth avatar fleupold avatar github-actions[bot] avatar hav-noms avatar haydenadams avatar henrypalacios avatar ianlapham avatar jfrankfurt avatar kennyt avatar lint-action avatar maria-vslvn avatar matextrem avatar mirshko avatar moodysalem avatar nenadv91 avatar noahzinsmeister avatar paulrberg avatar ramirotw avatar rossbulat avatar velenir avatar w3stside avatar zzmp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cowswap's Issues

Fee endpoint error

image

There's a lot of errors like ^^^

I also see that we make an error querying the fee for ETH or xDAI. We use the wrong token address...

Handle negative slippage

The app breaks when handling negative slippage. I believe it happens also in the original Uniswap.

We should handle the error, but also probably allow negative slippage to allow to create market orders in a hacky way.

  1. Click in the gear icon, for advanced settings
  2. Input a negative slippage

Orders are pending forever

Reported by @fleupold

Hi, small gp-swap bug report: Iโ€™m not getting my pending orders confirmed on the Rinkeby web (despite them getting
matched by the solver on chain). They just stay in โ€œpendingโ€ forever. I see my balance increase though.

Ideally, before solving it, it would be to have a cypress test to test there's no regression for this bug.

Probably we are not using the right version of the contracts (and with it, it's ethereum address).


Adding some screenshots:

I tried to trade WETH-DAI and DAI-WETH.
The trade happened in the contract
image
https://rinkeby.etherscan.io/tx/0xd90710f1ba733ae2a21a55ad25b483ebd6394217d0c5459f838443177ea1be3c

But the UI shows them as expired:
image

Do not include fee in the signed "sell amount"

"From" deducts fee in estimate but not in signed order

Assume the following order and a fee endpoint returinng a hardcoded 1 wxDAI:

image

The amount in To (estimated) is computed as if we were selling 1 wxDAI (From - fee). However the order that gets eventually signed and sent to the backend is for selling 2 wxDAI AND 1 wxDAI fee on top.

Given the current UX (which is under discussion in ) it should only be signed for a sell amount of 1 wxDAI. Otherwise the smart contract will take up 3 wxDAI from the User's balance and the user is signing a limit price that is way too pessimistic.

Cf this settlement where the fee was 0.1 wxDAI (and I typed in 2 in the From field): https://blockscout.com/poa/xdai/tx/0xd2a58cec3c5ea3a9a6780699a260d42021e49290f3a96e2b260c6874b138e34e/token-transfers

Implement cancelation of orders

Part of https://github.com/gnosis/gp-ui/issues/55

Add support for cancelation of orders

Hard/Soft/both cancelation?

Hard => SC
Soft => API

Workflow:

  • close/trash/๐Ÿ’ฃ/ icon on pending meta-tx
  • Popup with confirmation: Soft / Hard cancelation
    title: Cancel order
    content: make proposal explainning that one is free, one u pay, one u trust the operator, one u don't. Non of them gives u arantees of cancelation.
  • Soft: DELETE "/orders/" call to the API
  • Hard: Send tx to SC.

EDIT: Probably is best to start with soft cancelations. TBD how we authenticate the user. There must be some kind of authentication (include a signature in the deletion headers or sth)

Discussion:
https://gnosisinc.slack.com/archives/CPZA1AGKY/p1613139211144100

Specs:
It would be good to add the specs too
https://docs.google.com/document/d/1ko1oDAECz3Oy1g0MxdrBzEuUsMhKcRHr8mMH-yTCzfs/edit

Related:

[Uni-v3.2.3] Blocked addresses

#160 introduced a feature, to prevent "Specially Designated Nationals and Blocked Persons Ethereum addresses" from using the site

<Blocklist />

Consult with legal, and see if this is useful.
Basically, allows you to prevent an user from using the UI if it's in your BLOCKED_ADDRESSES

Trade confirmation modal: Improve the message

image

Change this text: Input is estimated. You will sell at most 0.669872 ETH or the transaction will revert.

Our tx don't REVERT. They EXPIRE.

Input is estimated. You will sell at most 0.669872 ETH or the transaction will expire in XXXX min

Same for these other tooltips:

image
image

We shouldn't use the REVERT word.

Release stable swap

Address the open issues and close version in staging.

Version 1:

Version 2: Try to have a version for the challenge

Version 3:

  • Fee calculation?

Tokens by network

xDAI, Rinkeby, Mainnet have different tokens

If we want it to be really a multi-network app, we should allow to:

  • Remember your selection for each network
  • Have different lists depending on the network

It would be nice also to create our own list, specially for Rinkeby and xDAI

Explorer: Show pending transaction links

Now we can include the link for the pending transactions too (and for the old ones in recent activity)

image

Also, it would be good to review all the labels and not says etherscan always, just write a more generic message or be specific: GP Explorer / Blockscout / Etherscan

Kind of related to #147 and #139. This issue is for the pending things to adapt

[nice to have] Load open orders

The swap UI keeps track of the open orders, and notify when they are executed.

The open orders and recent orders are saved in the local storage.This implies that they won't be seen in a different browser.
One improvement could be to use the API to load the orders. This would allow a better UX and multi-browser experience

Ideally we would leverage what we have. It's nice to show the orders persisted in the browsers in case the API fails, or while the API is giving us the open/recent orders.

Intercept approve calls

Approve a different contract (not Uniswap)

Intercept approve call, use another contract (OBA is not deployed, so we can use a mock)

Handle issues with native ETH/xDAI

The issue is that for ETH it's requesting:

in xDAI, it also request for ETH.
My understanding is that we should use the "special address"

This task would be:

  • Handle ETH correctly for getting the fee for ETH
  • Make sure in xDAI we also handle it correctly. Verify with backend https://gnosisinc.slack.com/archives/CPZA1AGKY/p1611740985044600
  • Make sure the address is right when we sign the order (we use the special address). This should be already the case, but just in case. We use the special address when buying ETH
  • Verify the same for xDAI โ˜๏ธ. We use the special address when buying xDAI

[Uni-v3.2.3] Review analytics

Uniswap uses google analytics. Also they were trying cloudflare one.
Add our own codes, at least for our development addresses? Review with legal

<script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "a141524a42594f028627f6004b23ff75"}'></script>

Race conditions: ๐ŸŽ Cancelations, and Fullfillment

image

As you see in the image, my trade got both EXPIRED and FULFILLED.

This is obviously an error. The cancelation toast should have a small delay, giving chance to the potential fulfillment to arrive.

Fullfillement is dependent on events, that can have some latencies. Also, blocks are not EXACTLY mined at the time they claim. So it would be wise to give some time extra for the the fulfillment to arrive.

TIMELINE (now):

    1. Send order
    1. Filled but the event hasn't arrived yet
    1. Expiration kicks in ---> we show toast of EXPIRED
    1. [5 sec later] Receive event of "Filled" ---> we show toast of FILLED

TIMELINE (proposal):

    1. Send order
    1. Filled but the event hasn't arrived yet
    1. Expiration kicks in ---> Delay (20s) and then check order if still exipred ---> we show toast of EXPIRED
    1. [5 sec later] Receive event of "Filled" ---> we show toast of FILLED

QA Testing notes

Show the fee

We should show the fee to the user

I would suggest to not overcomplicate this change. We could just replace the "liquidity provider fee" by:

  • Protocol Fee
  • Gas fee

Also, as a specific case. We should account the case where the user inputs to little tokens, so then after fees, he receives 0, and therefore he cannot trade.

It's good that he cannot trade in that case, but he should be able to understand why. The minimum, is to show the fees, so he get an idea:

  • Minimum Received: 0
  • Price Impact: XX
  • Total fees: 1.000001 WXDAI
    • Protocol Fee: 0.000001 WXDAI
    • Gas Fee: 1 XWXDAI

image

@biocom what simple way you think we can show the fees. I thought maybe showing the total as "Protocol and Gas fees": 1.000001 WXDAI and the rest as a detail in the tooltip

Wallet name is wrong

image

It says, connected with Coinbase, even when your are connected with Metamask ๐Ÿคทโ€โ™‚๏ธ

[Swap] Set Destination Address

Allow to set the destination of the tokens:

NOTE: The functionality was removed in #267 (comment), so we need to revert the commit first. Also, e2e were disabled for this functionality.

  • Toggle for setting destination. We discussed that although now is "hidden" in the advances settings, maybe it would be better UX to have a toggle on it's own
  • Make sure we provide this information to the signed transactions
  • Works with URL: http://gp-swap.dev.gnosisdev.com/#/send?outputCurrency=ETH&recipient=bob.argent.xyz
  • Verify it works. Note that we will need to update to the version of the contracts implementing this feature (under development now)
  • Re-enable the skipped e2e tests #129

[MVP] Priority 1 Tasks

Priority 1 tasks to complete

Operator and Tips

Price Estimation

  • Sell Order: Calculate receiving tokens using the tip @W3stside #33 & #35
  • Buy Order: Calculate sold tokens using the tip @W3stside #33 & #35
  • Make sure hops are handle properly

Pending Transactions

  • Model transactions
  • Transactions global state: Pending, settled
  • Pending transaction counter
  • Notification of transactions
  • Create OBA trades
  • Handle exception signing a trade
  • Handle success signing the trade
  • Handle execution of trades

Logic for the counter of pending transaction

Logic for the counter of pending transaction: keeping the state

We should account for both meta-tx and transactions, so we need to override and enhance the state to take this into account

Warning for orders that are unfillable

(price moved beyond slippage)
AFTER confirmation modal and price changes, maybe show warning in "Pending" order history

Confirmation modal will warn user when price changes before submitting, but once you send that order nothing will warn the user if the price changes after submitting and that it may not fill.

Could add a warning to the "pending" order notification in the toast or in the History Transactions comp

When cancellation is possible users can then leverage that option as to not have failing tx.

[wireframes] Swap UI

Wireframes for the Swap UI:

  • Tailor it more to our needs
  • Incorporate ideas from other successful UIs: 1inch? matcha? others?
  • Validate the ideas, capture feedback

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.