Skip to content

Commit

Permalink
Merge pull request #4556 from cowprotocol/release/2024-06-17
Browse files Browse the repository at this point in the history
chore(release): 2024 06 17
  • Loading branch information
alfetopito authored Jun 18, 2024
2 parents 50e1f39 + ad50711 commit 93e1c19
Show file tree
Hide file tree
Showing 277 changed files with 3,076 additions and 2,806 deletions.
2 changes: 1 addition & 1 deletion apps/cow-fi/pages/widget/terms-and-conditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function TermsAndConditionsPage({ siteConfigData }: { siteConfigD
<div>
<h1>Terms and Conditions for the CoW Swap Widget &amp; Partner Fee Program</h1>
<p>
These Terms and Conditions (the "Terms") govern the integration of the CoW Swap Widgetr (the "Widget"). The
These Terms and Conditions (the "Terms") govern the integration of the CoW Swap Widget (the "Widget"). The
Widget is provided to you ("you", the "Partner") by CoW DAO (the "Provider", "we", "our", or "us").
</p>
<p>
Expand Down
2 changes: 2 additions & 0 deletions apps/cowswap-frontend-e2e/src/support/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const TEST_ADDRESS_NEVER_USE = new Wallet(INTEGRATION_TEST_PRIVATE_KEY).a
// Redefined bridge to fix a supper annoying issue making some contract calls to fail
// See https://github.com/ethers-io/ethers.js/issues/1683
class CustomizedBridge extends Eip1193Bridge {
autoConnect = true

chainId = CHAIN_ID

async sendAsync(...args: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
OrderQuoteSideKindBuy,
OrderQuoteSideKindSell,
PartialApiContext,
PriceQuality,
SigningScheme,
SupportedChainId as ChainId,
TotalSurplus,
Expand All @@ -31,9 +30,8 @@ import { LegacyFeeQuoteParams as FeeQuoteParams } from 'legacy/state/price/types

import { getAppData } from 'modules/appData'

import { ApiErrorCodes } from 'api/gnosisProtocol/errors/OperatorError'
import GpQuoteError, { GpQuoteErrorDetails, mapOperatorErrorToQuoteError } from 'api/gnosisProtocol/errors/QuoteError'

import { ApiErrorCodes } from './errors/OperatorError'
import QuoteApiError, { QuoteApiErrorDetails, mapOperatorErrorToQuoteError } from './errors/QuoteError'
import { getIsOrderBookTypedError } from './getIsOrderBookTypedError'

function getProfileUrl(): Partial<Record<ChainId, string>> {
Expand Down Expand Up @@ -172,7 +170,7 @@ export async function getQuote(params: FeeQuoteParams): Promise<OrderQuoteRespon
return Promise.reject(
mapOperatorErrorToQuoteError({
errorType: ApiErrorCodes.SameBuyAndSellToken,
description: GpQuoteErrorDetails.SameBuyAndSellToken,
description: QuoteApiErrorDetails.SameBuyAndSellToken,
})
)
}
Expand All @@ -181,7 +179,7 @@ export async function getQuote(params: FeeQuoteParams): Promise<OrderQuoteRespon
if (getIsOrderBookTypedError(error)) {
const errorObject = mapOperatorErrorToQuoteError(error.body)

return Promise.reject(errorObject ? new GpQuoteError(errorObject) : error)
return Promise.reject(errorObject ? new QuoteApiError(errorObject) : error)
}

return Promise.reject(error)
Expand Down Expand Up @@ -252,16 +250,3 @@ export async function getProfileData(chainId: ChainId, address: string): Promise
return response.json()
}
}

export function getPriceQuality(props: { fast?: boolean; verifyQuote: boolean | undefined }): PriceQuality {
const { fast = false, verifyQuote } = props
if (fast) {
return PriceQuality.FAST
}

if (verifyQuote) {
return PriceQuality.VERIFIED
}

return PriceQuality.OPTIMAL
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ApiErrorCodes, ApiErrorObject } from './OperatorError'

export interface GpQuoteErrorObject {
errorType: GpQuoteErrorCodes
export interface QuoteApiErrorObject {
errorType: QuoteApiErrorCodes
description: string
data?: any
}

// Conforms to backend API
// https://github.com/cowprotocol/services/blob/main/crates/orderbook/openapi.yml
export enum GpQuoteErrorCodes {
export enum QuoteApiErrorCodes {
UnsupportedToken = 'UnsupportedToken',
InsufficientLiquidity = 'InsufficientLiquidity',
FeeExceedsFrom = 'FeeExceedsFrom',
Expand All @@ -18,9 +18,9 @@ export enum GpQuoteErrorCodes {
UNHANDLED_ERROR = 'UNHANDLED_ERROR',
}

export const SENTRY_IGNORED_GP_QUOTE_ERRORS = [GpQuoteErrorCodes.FeeExceedsFrom]
export const SENTRY_IGNORED_QUOTE_ERRORS = [QuoteApiErrorCodes.FeeExceedsFrom]

export enum GpQuoteErrorDetails {
export enum QuoteApiErrorDetails {
UnsupportedToken = 'One of the tokens you are trading is unsupported. Please read the FAQ for more info.',
InsufficientLiquidity = 'Token pair selected has insufficient liquidity.',
FeeExceedsFrom = 'Current fee exceeds entered "from" amount.',
Expand All @@ -31,62 +31,61 @@ export enum GpQuoteErrorDetails {
UNHANDLED_ERROR = 'Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later.',
}

export function mapOperatorErrorToQuoteError(error?: ApiErrorObject): GpQuoteErrorObject {
export function mapOperatorErrorToQuoteError(error?: ApiErrorObject): QuoteApiErrorObject {
switch (error?.errorType) {
case ApiErrorCodes.NotFound:
case ApiErrorCodes.NoLiquidity:
return {
errorType: GpQuoteErrorCodes.InsufficientLiquidity,
description: GpQuoteErrorDetails.InsufficientLiquidity,
errorType: QuoteApiErrorCodes.InsufficientLiquidity,
description: QuoteApiErrorDetails.InsufficientLiquidity,
}

case ApiErrorCodes.SellAmountDoesNotCoverFee:
return {
errorType: GpQuoteErrorCodes.FeeExceedsFrom,
description: GpQuoteErrorDetails.FeeExceedsFrom,
errorType: QuoteApiErrorCodes.FeeExceedsFrom,
description: QuoteApiErrorDetails.FeeExceedsFrom,
data: error?.data,
}

case ApiErrorCodes.UnsupportedToken:
return {
errorType: GpQuoteErrorCodes.UnsupportedToken,
errorType: QuoteApiErrorCodes.UnsupportedToken,
description: error.description,
}
case ApiErrorCodes.TransferEthToContract:
return {
errorType: GpQuoteErrorCodes.TransferEthToContract,
errorType: QuoteApiErrorCodes.TransferEthToContract,
description: error.description,
}

case ApiErrorCodes.SameBuyAndSellToken:
return {
errorType: GpQuoteErrorCodes.SameBuyAndSellToken,
description: GpQuoteErrorDetails.SameBuyAndSellToken,
errorType: QuoteApiErrorCodes.SameBuyAndSellToken,
description: QuoteApiErrorDetails.SameBuyAndSellToken,
}

default:
return { errorType: GpQuoteErrorCodes.UNHANDLED_ERROR, description: GpQuoteErrorDetails.UNHANDLED_ERROR }
return { errorType: QuoteApiErrorCodes.UNHANDLED_ERROR, description: QuoteApiErrorDetails.UNHANDLED_ERROR }
}
}

// TODO: rename it or delete it
export default class GpQuoteError extends Error {
export default class QuoteApiError extends Error {
name = 'QuoteErrorObject'
type: GpQuoteErrorCodes
type: QuoteApiErrorCodes
description: string
// any data attached
data?: any

// Status 400 errors
// https://github.com/cowprotocol/services/blob/9014ae55412a356e46343e051aefeb683cc69c41/orderbook/openapi.yml#L563
static quoteErrorDetails = GpQuoteErrorDetails
static quoteErrorDetails = QuoteApiErrorDetails

public static async getErrorMessage(response: Response) {
try {
const orderPostError: GpQuoteErrorObject = await response.json()
const orderPostError: QuoteApiErrorObject = await response.json()

if (orderPostError.errorType) {
const errorMessage = GpQuoteError.quoteErrorDetails[orderPostError.errorType]
const errorMessage = QuoteApiError.quoteErrorDetails[orderPostError.errorType]
// shouldn't fall through as this error constructor expects the error code to exist but just in case
return errorMessage || orderPostError.errorType
} else {
Expand All @@ -95,7 +94,7 @@ export default class GpQuoteError extends Error {
}
} catch (error: any) {
console.error('Error handling 400/404 error. Likely a problem deserialising the JSON response')
return GpQuoteError.quoteErrorDetails.UNHANDLED_ERROR
return QuoteApiError.quoteErrorDetails.UNHANDLED_ERROR
}
}

Expand All @@ -114,16 +113,16 @@ export default class GpQuoteError extends Error {
return 'Error fetching quote'
}
}
constructor(quoteError: GpQuoteErrorObject) {
constructor(quoteError: QuoteApiErrorObject) {
super(quoteError.description)

this.type = quoteError.errorType
this.description = quoteError.description
this.message = GpQuoteError.quoteErrorDetails[quoteError.errorType]
this.message = QuoteApiError.quoteErrorDetails[quoteError.errorType]
this.data = quoteError?.data
}
}

export function isValidQuoteError(error: any): error is GpQuoteError {
return error instanceof GpQuoteError
export function isValidQuoteError(error: any): error is QuoteApiError {
return error instanceof QuoteApiError
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GP_ORDER_UPDATE_INTERVAL } from '@cowprotocol/common-const'
import { ORDER_BOOK_API_UPDATE_INTERVAL } from '@cowprotocol/common-const'
import { EnrichedOrder } from '@cowprotocol/cow-sdk'
import { useWalletInfo } from '@cowprotocol/wallet'

Expand All @@ -8,7 +8,7 @@ import { useSWROrdersRequest } from 'modules/orders/hooks/useSWROrdersRequest'

import { getOrders } from './api'

export function useGpOrders(): EnrichedOrder[] {
export function useOrdersFromOrderBook(): EnrichedOrder[] {
const { chainId } = useWalletInfo()

const requestParams = useSWROrdersRequest()
Expand All @@ -21,7 +21,7 @@ export function useGpOrders(): EnrichedOrder[] {

return getOrders(requestParams, { chainId })
},
{ refreshInterval: GP_ORDER_UPDATE_INTERVAL }
{ refreshInterval: ORDER_BOOK_API_UPDATE_INTERVAL }
)

return currentEnvOrders || []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RAW_CODE_LINK } from '@cowprotocol/common-const'
import { environmentName } from '@cowprotocol/common-utils'
import { SupportedChainId, mapSupportedNetworks } from '@cowprotocol/cow-sdk'

import { GpPriceStrategy } from 'legacy/state/gas/atoms'
import { PriceStrategy as PriceStrategyEnum } from 'legacy/state/gas/atoms'

const API_NAME = 'CoW Protocol'
const STRATEGY_URL_BASE = RAW_CODE_LINK + '/configuration/config/'
Expand All @@ -12,8 +12,8 @@ const STRATEGY_URL = STRATEGY_URL_BASE + ENV_BASE + '/strategies'
const STRATEGY_API_URL = mapSupportedNetworks((chainId: SupportedChainId) => `${STRATEGY_URL}/strategy-${chainId}.json`)

export type PriceStrategy = {
primary: GpPriceStrategy
secondary: GpPriceStrategy
primary: PriceStrategyEnum
secondary: PriceStrategyEnum
}

function _getPriceStrategyApiBaseUrl(chainId: SupportedChainId): string {
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions apps/cowswap-frontend/src/common/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
} from '@cowprotocol/abis'
import {
COWSWAP_ETHFLOW_CONTRACT_ADDRESS,
GP_SETTLEMENT_CONTRACT_ADDRESS,
V_COW_CONTRACT_ADDRESS,
WRAPPED_NATIVE_CURRENCIES,
} from '@cowprotocol/common-const'
import { getContract, isEns, isProd, isStaging } from '@cowprotocol/common-utils'
import { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '@cowprotocol/cow-sdk'
import { useWalletInfo } from '@cowprotocol/wallet'
import { useWalletProvider } from '@cowprotocol/wallet-provider'
import { Contract } from '@ethersproject/contracts'
Expand Down Expand Up @@ -76,7 +76,7 @@ export function useEthFlowContract(): CoWSwapEthFlow | null {
export function useGP2SettlementContract(): GPv2Settlement | null {
const { chainId } = useWalletInfo()
return useContract<GPv2Settlement>(
chainId ? GP_SETTLEMENT_CONTRACT_ADDRESS[chainId] : undefined,
chainId ? COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId] : undefined,
GPv2SettlementAbi,
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function useGetMarketDimension() {
const tradeTypeInfo = useTradeTypeInfo()
const derivedTradeState = useDerivedTradeState()

const sellSymbol = derivedTradeState?.state?.inputCurrency?.symbol
const buySymbol = derivedTradeState?.state?.outputCurrency?.symbol
const sellSymbol = derivedTradeState?.inputCurrency?.symbol
const buySymbol = derivedTradeState?.outputCurrency?.symbol
const tradePair = sellSymbol && buySymbol ? `${sellSymbol},${buySymbol}` : null

return useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMemo } from 'react'

import { GP_VAULT_RELAYER } from '@cowprotocol/common-const'
import { COW_PROTOCOL_VAULT_RELAYER_ADDRESS } from '@cowprotocol/cow-sdk'
import { useWalletInfo } from '@cowprotocol/wallet'

export function useTradeSpenderAddress(): string | undefined {
const { chainId } = useWalletInfo()

return useMemo(() => (chainId ? GP_VAULT_RELAYER[chainId] : undefined), [chainId])
return useMemo(() => (chainId ? COW_PROTOCOL_VAULT_RELAYER_ADDRESS[chainId] : undefined), [chainId])
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { COW } from '@cowprotocol/common-const'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { CurrencyAmount, Percent } from '@uniswap/sdk-core'

import { inputCurrencyInfoMock } from 'mocks/tradeStateMock'

import { PriceImpact } from 'legacy/hooks/usePriceImpact'
import { Field } from 'legacy/state/types'

Expand All @@ -21,16 +23,7 @@ export const defaultCurrencyInputPanelProps: CurrencyInputPanelProps & { priceIm
currencyInfo: {
field: Field.INPUT,
isIndependent: false,
receiveAmountInfo: {
type: 'from',
amountBeforeFees: '30',
amountAfterFees: '20',
amountAfterFeesRaw: CurrencyAmount.fromRawAmount(currency, 20 * 10 ** 18),
feeAmount: '10',
feeAmountRaw: CurrencyAmount.fromRawAmount(currency, 10 * 10 ** 18),
partnerFeeAmount: '0',
partnerFeeAmountRaw: CurrencyAmount.fromRawAmount(currency, 0),
},
receiveAmountInfo: inputCurrencyInfoMock.receiveAmountInfo,
currency,
balance,
amount: CurrencyAmount.fromRawAmount(currency, 20 * 10 ** 18),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { Field } from 'legacy/state/types'

import { ReceiveAmountInfo } from 'modules/swap/helpers/tradeReceiveAmount'
import { ReceiveAmountInfo } from 'modules/trade/types'

export interface CurrencyInfo {
label?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ExecutionPriceProps {
hideSeparator?: boolean
separatorSymbol?: string
hideFiat?: boolean
className?: string
}

export function ExecutionPrice({
Expand All @@ -20,14 +21,15 @@ export function ExecutionPrice({
separatorSymbol = '≈',
hideSeparator,
hideFiat,
className,
}: ExecutionPriceProps) {
const executionPriceFiat = useExecutionPriceFiat(hideFiat ? null : executionPrice, isInverted)
const quoteCurrency = isInverted ? executionPrice?.baseCurrency : executionPrice?.quoteCurrency
const baseCurrency = isInverted ? executionPrice?.quoteCurrency : executionPrice?.baseCurrency
const oneBaseCurrency = tryParseCurrencyAmount('1', baseCurrency)

return (
<span>
<span className={className}>
{showBaseCurrency && <TokenAmount amount={oneBaseCurrency} tokenSymbol={baseCurrency} />}
{!hideSeparator && ` ${separatorSymbol} `}
<TokenAmount amount={isInverted ? executionPrice.invert() : executionPrice} tokenSymbol={quoteCurrency} />
Expand Down
15 changes: 15 additions & 0 deletions apps/cowswap-frontend/src/common/pure/NetworkCostsSuffix/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import { UI } from '@cowprotocol/ui'

import styled from 'styled-components/macro'

const Wrapper = styled.span`
color: var(${UI.COLOR_TEXT_OPACITY_70});
font-size: 12px;
margin-left: 4px;
`

export function NetworkCostsSuffix() {
return <Wrapper> + gas</Wrapper>
}
Loading

0 comments on commit 93e1c19

Please sign in to comment.