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

chore: release v1.690.0 #7927

Merged
merged 7 commits into from
Oct 14, 2024
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
3 changes: 3 additions & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ REACT_APP_FEATURE_USDT_APPROVAL_RESET=true
REACT_APP_FEATURE_PORTALS_SWAPPER=true
REACT_APP_FEATURE_RUNEPOOL=true
REACT_APP_FEATURE_MARKETS=true
REACT_APP_FEATURE_FOX_PAGE=false
REACT_APP_FEATURE_FOX_PAGE_RFOX=false
REACT_APP_FEATURE_FOX_PAGE_FOX_SECTION=true
REACT_APP_FEATURE_PHANTOM_WALLET=false

# absolute URL prefix
Expand Down
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# feature flags
REACT_APP_FEATURE_SOLANA=true
REACT_APP_FEATURE_FOX_PAGE=true
REACT_APP_FEATURE_FOX_PAGE_RFOX=true
REACT_APP_FEATURE_FOX_PAGE_FOX_SECTION=true

# logging
REACT_APP_REDUX_WINDOW=false
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/swapper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './constants'
export * from './swapper'
export * from './thorchain-utils'
export * from './safe-utils'
export * from './swappers/CowSwapper'
5 changes: 3 additions & 2 deletions packages/swapper/src/swappers/CowSwapper/CowSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type {
} from '../../types'
import { filterAssetIdsBySellable } from './filterAssetIdsBySellable/filterAssetIdsBySellable'
import { filterBuyAssetsBySellAssetId } from './filterBuyAssetsBySellAssetId/filterBuyAssetsBySellAssetId'
import { COW_SWAP_SETTLEMENT_ADDRESS, SIGNING_SCHEME } from './utils/constants'
import { CoWSwapSigningScheme } from './types'
import { COW_SWAP_SETTLEMENT_ADDRESS } from './utils/constants'
import { cowService } from './utils/cowService'
import { domain, getCowswapNetwork, getSignTypeDataPayload } from './utils/helpers/helpers'

Expand Down Expand Up @@ -54,7 +55,7 @@ export const cowSwapper: Swapper = {
`${config.REACT_APP_COWSWAP_BASE_URL}/${network}/api/v1/orders/`,
{
...orderToSign,
signingScheme: SIGNING_SCHEME,
signingScheme: CoWSwapSigningScheme.EIP712,
signature,
appData,
appDataHash,
Expand Down
29 changes: 14 additions & 15 deletions packages/swapper/src/swappers/CowSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { v4 as uuid } from 'uuid'

import { getDefaultSlippageDecimalPercentageForSwapper } from '../../constants'
import type {
CowSwapOrder,
EvmMessageToSign,
GetEvmTradeQuoteInput,
GetTradeQuoteInput,
Expand All @@ -21,17 +20,17 @@ import { SwapperName } from '../../types'
import { checkSafeTransactionStatus, createDefaultStatusResponse, getHopByIndex } from '../../utils'
import { isNativeEvmAsset } from '../utils/helpers/helpers'
import { getCowSwapTradeQuote } from './getCowSwapTradeQuote/getCowSwapTradeQuote'
import type {
CowSwapGetTradesResponse,
CowSwapGetTransactionsResponse,
CowSwapQuoteResponse,
} from './types'
import type { CowSwapOrder } from './types'
import {
COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS,
ERC20_TOKEN_BALANCE,
ORDER_KIND_SELL,
SIGNING_SCHEME,
} from './utils/constants'
CoWSwapBuyTokenDestination,
type CowSwapGetTradesResponse,
type CowSwapGetTransactionsResponse,
CoWSwapOrderKind,
type CowSwapQuoteResponse,
CoWSwapSellTokenSource,
CoWSwapSigningScheme,
} from './types'
import { COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS } from './utils/constants'
import { cowService } from './utils/cowService'
import {
deductAffiliateFeesFromAmount,
Expand Down Expand Up @@ -108,7 +107,7 @@ export const cowApi: SwapperApi = {
appDataHash,
partiallyFillable: false,
from,
kind: ORDER_KIND_SELL,
kind: CoWSwapOrderKind.Sell,
sellAmountBeforeFee: sellAmountIncludingProtocolFeesCryptoBaseUnit,
},
)
Expand Down Expand Up @@ -148,11 +147,11 @@ export const cowApi: SwapperApi = {
buyAmount: buyAmountAfterAffiliateFeesAndSlippageCryptoBaseUnit,
sellAmount: sellAmountPlusProtocolFees.toFixed(0),
// from,
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
quoteId: id,
appDataHash,
signingScheme: SIGNING_SCHEME,
signingScheme: CoWSwapSigningScheme.EIP712,
}

return { chainId, orderToSign }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
WETH,
XDAI,
} from '../../utils/test-data/assets'
import type { CowSwapQuoteResponse } from '../types'
import {
COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS,
DEFAULT_ADDRESS,
ERC20_TOKEN_BALANCE,
} from '../utils/constants'
CoWSwapBuyTokenDestination,
type CowSwapQuoteResponse,
CoWSwapSellTokenSource,
} from '../types'
import { COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS, DEFAULT_ADDRESS } from '../utils/constants'
import { cowService } from '../utils/cowService'
import type { CowSwapSellQuoteApiInput } from '../utils/helpers/helpers'
import { getCowSwapTradeQuote } from './getCowSwapTradeQuote'
Expand Down Expand Up @@ -356,8 +356,8 @@ describe('getCowTradeQuote', () => {
sellAmount: '985442057341242012',
buyAmount: '14707533959600717283163',
feeAmount: '14557942658757988',
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
},
},
} as unknown as AxiosResponse<CowSwapQuoteResponse>),
Expand Down Expand Up @@ -400,8 +400,8 @@ describe('getCowTradeQuote', () => {
sellAmount: '938195228120306016256',
buyAmount: '46868859830863283',
feeAmount: '61804771879693983744',
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
},
},
} as unknown as AxiosResponse<CowSwapQuoteResponse>),
Expand Down Expand Up @@ -444,8 +444,8 @@ describe('getCowTradeQuote', () => {
sellAmount: '20998812',
buyAmount: '21005367357465608755',
feeAmount: '1188',
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
},
},
} as unknown as AxiosResponse<CowSwapQuoteResponse>),
Expand Down Expand Up @@ -488,8 +488,8 @@ describe('getCowTradeQuote', () => {
sellAmount: '492056',
buyAmount: '141649103137616',
feeAmount: '7944',
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
},
},
} as unknown as AxiosResponse<CowSwapQuoteResponse>),
Expand Down Expand Up @@ -532,8 +532,8 @@ describe('getCowTradeQuote', () => {
sellAmount: '9854420573412420',
buyAmount: '145018118182475950905',
feeAmount: '1455794265875791',
sellTokenBalance: ERC20_TOKEN_BALANCE,
buyTokenBalance: ERC20_TOKEN_BALANCE,
sellTokenBalance: CoWSwapSellTokenSource.ERC20,
buyTokenBalance: CoWSwapBuyTokenDestination.ERC20,
},
},
} as unknown as AxiosResponse<CowSwapQuoteResponse>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import type { GetTradeQuoteInput, SwapErrorRight, SwapperConfig, TradeQuote } fr
import { SwapperName } from '../../../types'
import { createTradeAmountTooSmallErr } from '../../../utils'
import { isNativeEvmAsset } from '../../utils/helpers/helpers'
import type { CowSwapQuoteError, CowSwapQuoteResponse } from '../types'
import { CoWSwapOrderKind, type CowSwapQuoteError, type CowSwapQuoteResponse } from '../types'
import {
COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS,
COW_SWAP_VAULT_RELAYER_ADDRESS,
ORDER_KIND_SELL,
SUPPORTED_CHAIN_IDS,
} from '../utils/constants'
import { cowService } from '../utils/cowService'
Expand Down Expand Up @@ -83,7 +82,7 @@ export async function getCowSwapTradeQuote(
appDataHash,
partiallyFillable: false,
from: receiveAddress,
kind: ORDER_KIND_SELL,
kind: CoWSwapOrderKind.Sell,
sellAmountBeforeFee: sellAmountIncludingProtocolFeesCryptoBaseUnit,
},
)
Expand Down
2 changes: 2 additions & 0 deletions packages/swapper/src/swappers/CowSwapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './types'
export * from './utils'
48 changes: 48 additions & 0 deletions packages/swapper/src/swappers/CowSwapper/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ChainId } from '@shapeshiftoss/caip'
import type { KnownChainIds } from '@shapeshiftoss/types'

export type CowSwapQuoteResponse = {
Expand All @@ -24,13 +25,37 @@ enum CowSwapQuoteErrorType {
SellAmountDoesNotCoverFee = 'SellAmountDoesNotCoverFee',
NoLiquidity = 'NoLiquidity',
}

export type CowSwapQuoteError = {
errorType: CowSwapQuoteErrorType
description: string
// This is not documented by CoW API so we shouldn't make assumptions about the shape, nor presence of this guy
data?: any
}

export enum CoWSwapOrderKind {
Buy = 'buy',
Sell = 'sell',
}

export enum CoWSwapSigningScheme {
EIP712 = 'eip712',
EIP1271 = 'eip1271',
EthSign = 'ethsign',
PreSign = 'presign',
}

export enum CoWSwapSellTokenSource {
ERC20 = 'erc20',
External = 'external',
Internal = 'internal',
}

export enum CoWSwapBuyTokenDestination {
ERC20 = 'erc20',
Internal = 'internal',
}

export enum CowNetwork {
Mainnet = 'mainnet',
Xdai = 'xdai',
Expand All @@ -56,3 +81,26 @@ export type AffiliateAppDataFragment = {
recipient: string
}
}

export type CowSwapOrder = {
sellToken: string
buyToken: string
sellAmount: string
buyAmount: string
validTo: number
appData: string
appDataHash: string
feeAmount: string
kind: string
partiallyFillable: boolean
receiver: string
sellTokenBalance: CoWSwapSellTokenSource
buyTokenBalance: CoWSwapBuyTokenDestination
quoteId: number
signingScheme: CoWSwapSigningScheme
}

export type CowMessageToSign = {
chainId: ChainId
orderToSign: CowSwapOrder
}
4 changes: 0 additions & 4 deletions packages/swapper/src/swappers/CowSwapper/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export const DEFAULT_ADDRESS = zeroAddress
export const COW_SWAP_VAULT_RELAYER_ADDRESS = '0xc92e8bdf79f0507f65a392b0ab4667716bfe0110'
export const COW_SWAP_SETTLEMENT_ADDRESS = '0x9008D19f58AAbD9eD0D60971565AA8510560ab41'

export const ORDER_KIND_SELL = 'sell'
export const SIGNING_SCHEME = 'eip712'
export const ERC20_TOKEN_BALANCE = 'erc20'

// Address used by CowSwap to buy ETH
// See https://github.com/gnosis/gp-v2-contracts/commit/821b5a8da213297b0f7f1d8b17c893c5627020af#diff-12bbbe13cd5cf42d639e34a39d8795021ba40d3ee1e1a8282df652eb161a11d6R13
export const COW_SWAP_NATIVE_ASSET_MARKER_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import type { TypedData } from 'eip-712'
import type { TypedDataDomain, TypedDataField } from 'ethers'
import { keccak256, stringToBytes } from 'viem'

import type { CowSwapOrder, SwapErrorRight } from '../../../../types'
import type { SwapErrorRight } from '../../../../types'
import { TradeQuoteError } from '../../../../types'
import { makeSwapErrorRight } from '../../../../utils'
import { getTreasuryAddressFromChainId } from '../../../utils/helpers/helpers'
import type { AffiliateAppDataFragment, CowSwapQuoteResponse } from '../../types'
import type { AffiliateAppDataFragment, CowSwapOrder, CowSwapQuoteResponse } from '../../types'
import { CowNetwork } from '../../types'

export const ORDER_TYPE_FIELDS = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getCowswapNetwork } from './helpers'

export { getCowswapNetwork }
1 change: 1 addition & 0 deletions packages/swapper/src/swappers/CowSwapper/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './helpers'
24 changes: 1 addition & 23 deletions packages/swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { Result } from '@sniptt/monads'
import type { TypedData } from 'eip-712'
import type { InterpolationOptions } from 'node-polyglot'

import type { CowMessageToSign } from './swappers/CowSwapper/types'
import type { makeSwapperAxiosServiceMonadic } from './utils'

// TODO: Rename all properties in this type to be camel case and not react specific
Expand Down Expand Up @@ -236,24 +237,6 @@ export type TradeQuote = TradeQuoteBase & {

export type FromOrXpub = { from: string; xpub?: never } | { from?: never; xpub: string }

export type CowSwapOrder = {
sellToken: string
buyToken: string
sellAmount: string
buyAmount: string
validTo: number
appData: string
appDataHash: string
feeAmount: string
kind: string
partiallyFillable: boolean
receiver: string
sellTokenBalance: string
buyTokenBalance: string
quoteId: number
signingScheme: 'eip712' | 'ethsign'
}

export type GetUnsignedTxArgs = {
tradeQuote: TradeQuote
chainId: ChainId
Expand Down Expand Up @@ -349,11 +332,6 @@ export type EvmTransactionRequest = {
chainId: number
} & evm.types.Fees

export type CowMessageToSign = {
chainId: ChainId
orderToSign: CowSwapOrder
}

// TODO: one day this might be a union to support various implementations or generic 💀
export type EvmMessageToSign = CowMessageToSign

Expand Down
7 changes: 6 additions & 1 deletion packages/swapper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ export const makeSwapperAxiosServiceMonadic = (service: AxiosInstance, _swapperN
data: any,
config?: AxiosRequestConfig<any>,
) => Promise<Result<AxiosResponse<T>, SwapErrorRight>>
delete: <T = any>(
url: string,
data: any,
config?: AxiosRequestConfig<any>,
) => Promise<Result<AxiosResponse<T>, SwapErrorRight>>
}
>(service, {
get: (trappedAxios, method: 'get' | 'post') => {
get: (trappedAxios, method: 'get' | 'post' | 'delete') => {
const originalMethodPromise = trappedAxios[method]
return async (...args: [url: string, dataOrConfig?: any, dataOrConfig?: any]) => {
// getMixPanel()?.track(MixPanelEvent.SwapperApiRequest, {
Expand Down
Loading
Loading