Skip to content

Commit

Permalink
Fix issue signing using WC for some wallets (#528)
Browse files Browse the repository at this point in the history
* Use cowprotocol NPM package and allow to sign using default signer

* Fix code style issues with Prettier

* Fix typo

Co-authored-by: dave <[email protected]>

Co-authored-by: Lint Action <[email protected]>
Co-authored-by: dave <[email protected]>
  • Loading branch information
3 people authored May 5, 2022
1 parent 9bb45e8 commit 1a7b9d4
Show file tree
Hide file tree
Showing 22 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cypress-custom/integration/fee.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WETH9 as WETH } from '@uniswap/sdk-core'
import { GetQuoteResponse } from '@gnosis.pm/gp-v2-contracts'
import { GetQuoteResponse } from '@cowprotocol/contracts'
import { parseUnits } from 'ethers/lib/utils'

const DAI = '0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"@babel/runtime": "^7.17.0",
"@cowprotocol/contracts": "^1.1.3-RC.0",
"@davatar/react": "1.8.1",
"@ethersproject/abi": "^5.4.1",
"@ethersproject/abstract-provider": "^5.4.1",
Expand All @@ -210,7 +211,6 @@
"@fontsource/inter": "^4.5.1",
"@gnosis.pm/cow-runner-game": "^0.2.9",
"@gnosis.pm/dex-js": "^0.14.0",
"@gnosis.pm/gp-v2-contracts": "^1.1.2",
"@gnosis.pm/safe-apps-web3-react": "^0.6.0",
"@gnosis.pm/safe-service-client": "^0.1.1",
"@lingui/cli": "^3.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/custom/api/gnosisProtocol/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SupportedChainId as ChainId, SupportedChainId } from 'constants/chains'
import { OrderKind, QuoteQuery } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind, QuoteQuery } from '@cowprotocol/contracts'
import { stringify } from 'qs'
import {
getSigningSchemeApiValue,
Expand Down
2 changes: 1 addition & 1 deletion src/custom/api/matcha-0x/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'

import { NetworkID } from 'paraswap'
import { SupportedChainId as ChainId } from 'constants/chains'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/api/paraswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'

import { ParaSwap, SwapSide, NetworkID } from 'paraswap'
import { OptimalRate } from 'paraswap-core'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/components/Version/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from 'styled-components/macro'
import { ExternalLink, ThemedText } from 'theme'

import { version as WEB_VERSION } from '@src/../package.json'
import { version as CONTRACTS_VERSION } from '@gnosis.pm/gp-v2-contracts/package.json'
import { version as CONTRACTS_VERSION } from '@cowprotocol/contracts/package.json'
import { SupportedChainId as ChainId } from 'constants/chains'
import { getEtherscanLink } from 'utils'
import { CODE_LINK, GP_VAULT_RELAYER, GP_SETTLEMENT_CONTRACT_ADDRESS } from 'constants/index'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Token, Fraction, Percent } from '@uniswap/sdk-core'

import { GPv2Settlement, GPv2VaultRelayer } from '@gnosis.pm/gp-v2-contracts/networks.json'
import { GPv2Settlement, GPv2VaultRelayer } from '@cowprotocol/contracts/networks.json'
import { WalletInfo, SUPPORTED_WALLETS as SUPPORTED_WALLETS_UNISWAP } from 'constants/wallet'

import { SupportedChainId as ChainId } from 'constants/chains'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/hooks/usePriceImpact/useQuoteAndSwap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { useTradeExactInWithFee } from 'state/swap/extension'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/hooks/useSwapCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useENS from '@src/hooks/useENS'
// import useTransactionDeadline from './useTransactionDeadline'

// MOD
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'
import { INITIAL_ALLOWED_SLIPPAGE_PERCENT, NATIVE_CURRENCY_BUY_TOKEN } from 'constants/index'
import { AddOrderCallback, AddUnserialisedPendingOrderParams, useAddPendingOrder } from 'state/orders/hooks'
import { useWrapEther, Wrap } from 'hooks/useWrapEther'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/orders/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SupportedChainId as ChainId } from 'constants/chains'
import { SerializedToken } from '@src/state/user/actions'
import { SafeMultisigTransactionResponse } from '@gnosis.pm/safe-service-client'
import { BigNumberish } from '@ethersproject/bignumber'
export { OrderKind } from '@gnosis.pm/gp-v2-contracts'
export { OrderKind } from '@cowprotocol/contracts'

export enum OrderStatus {
PENDING = 'pending',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef } from 'react'
import { timestamp } from '@gnosis.pm/gp-v2-contracts'
import { timestamp } from '@cowprotocol/contracts'

import { useActiveWeb3React } from 'hooks/web3'

Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/orders/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'
import { Price } from '@uniswap/sdk-core'

import { ONE_HUNDRED_PERCENT } from 'constants/misc'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/price/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createReducer, PayloadAction, current } from '@reduxjs/toolkit'
import { SupportedChainId as ChainId } from 'constants/chains'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'
import { updateQuote, setQuoteError, getNewQuote, refreshQuote, QuoteError } from './actions'
import { Writable } from 'custom/types'
import { PrefillStateRequired } from '../orders/reducer'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/price/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEFAULT_DECIMALS } from 'custom/constants'

import { UnsupportedToken } from 'api/gnosisProtocol'
import { FeeQuoteParams as FeeQuoteParamsFull } from 'utils/price'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'

import { useSwapState } from 'state/swap/hooks'
import tryParseCurrencyAmount from 'lib/utils/tryParseCurrencyAmount'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/swap/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import { QuoteInformationObject } from 'state/price/reducer'
import TradeGp, { _constructTradePrice } from './TradeGp'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'

interface TradeParams {
parsedAmount?: CurrencyAmount<Currency>
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/swap/trade.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseUnits } from '@ethersproject/units'
import { DEFAULT_PRECISION, LONG_PRECISION } from 'constants/index'
import { CurrencyAmount, Fraction, Price, Currency, Percent, Token, TradeType } from '@uniswap/sdk-core'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'
import { stringToCurrency } from './extension'
import { SupportedChainId as ChainId } from 'constants/chains'
import { WRAPPED_NATIVE_CURRENCY as WETH } from 'constants/tokens'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SupportedChainId as ChainId } from 'constants/chains'
import { Market } from 'types/index'
import { OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { OrderKind } from '@cowprotocol/contracts'

export const isTruthy = <T>(value: T | null | undefined | false): value is T => !!value

Expand Down
4 changes: 2 additions & 2 deletions src/custom/utils/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'api/matcha-0x'

import { OptimalRate } from 'paraswap-core'
import { GetQuoteResponse, OrderKind } from '@gnosis.pm/gp-v2-contracts'
import { GetQuoteResponse, OrderKind } from '@cowprotocol/contracts'
import { ChainId } from 'state/lists/actions'
import { toErc20Address } from 'utils/tokens'
import { GpPriceStrategy } from 'hooks/useGetGpPriceStrategy'
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface PriceInformation {
amount: string | null
}

// GetQuoteResponse from @gnosis.pm/gp-v2-contracts types Timestamp and BigNumberish
// GetQuoteResponse from @cowprotocol/contracts types Timestamp and BigNumberish
// do not play well with our existing methods, using string instead
export type SimpleGetQuoteResponse = Pick<GetQuoteResponse, 'from'> & {
// We need to map BigNumberIsh and Timestamp to what we use: string
Expand Down
13 changes: 9 additions & 4 deletions src/custom/utils/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
Order,
OrderCancellation as OrderCancellationGp,
Signature,
TypedDataV3Signer,
TypedDataVersionedSigner,
IntChainIdTypedDataV4Signer,
SigningScheme,
} from '@gnosis.pm/gp-v2-contracts'
} from '@cowprotocol/contracts'

import { SupportedChainId as ChainId } from 'constants/chains'
import { GP_SETTLEMENT_CONTRACT_ADDRESS } from 'constants/index'
Expand Down Expand Up @@ -137,16 +137,19 @@ async function _signPayload(
payload: any,
signFn: typeof _signOrder | typeof _signOrderCancellation,
signer: Signer,
signingMethod: 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'
signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'
): Promise<SigningResult> {
const signingScheme = signingMethod === 'eth_sign' ? SigningScheme.ETHSIGN : SigningScheme.EIP712
let signature: Signature | null = null

let _signer
try {
switch (signingMethod) {
case 'default':
_signer = new TypedDataVersionedSigner(signer)
break
case 'v3':
_signer = new TypedDataV3Signer(signer)
_signer = new TypedDataVersionedSigner(signer, 'v3')
break
case 'int_v4':
_signer = new IntChainIdTypedDataV4Signer(signer)
Expand All @@ -173,6 +176,8 @@ async function _signPayload(
// with other methods...
switch (signingMethod) {
case 'v4':
return _signPayload(payload, signFn, signer, 'default')
case 'default':
return _signPayload(payload, signFn, signer, 'v3')
case 'v3':
return _signPayload(payload, signFn, signer, 'eth_sign')
Expand Down
2 changes: 1 addition & 1 deletion src/custom/utils/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Signer } from '@ethersproject/abstract-signer'
import { RADIX_DECIMAL, AMOUNT_PRECISION } from 'constants/index'
import { SupportedChainId as ChainId } from 'constants/chains'
import { formatSmart } from 'utils/format'
import { SigningScheme } from '@gnosis.pm/gp-v2-contracts'
import { SigningScheme } from '@cowprotocol/contracts'
import { getTrades, getProfileData } from 'api/gnosisProtocol/api'

export interface PostOrderParams {
Expand Down
2 changes: 1 addition & 1 deletion src/custom/writeVersion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs')
const { version: WEB_VERSION } = require('../../package.json')
const { version: CONTRACTS_VERSION } = require('@gnosis.pm/gp-v2-contracts/package.json')
const { version: CONTRACTS_VERSION } = require('@cowprotocol/contracts/package.json')

const OUTPUT_FILE = 'public/version.json'

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,11 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@cowprotocol/contracts@^1.1.3-RC.0":
version "1.1.3-RC.0"
resolved "https://registry.yarnpkg.com/@cowprotocol/contracts/-/contracts-1.1.3-RC.0.tgz#23c400a7cbf50c1c2e7dca317a0b2940975b6867"
integrity sha512-WwPvBKbBvRIj/W3I1/8yJPh0DLMx8EoDw/MTpF07rDq2W0QQ1r9GXq+GWIclt5Rcw7ZGwZMRlnM3XOYEWA+qpg==

"@craco/craco@^5.7.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@craco/craco/-/craco-5.9.0.tgz#dcd34330b558596a4841374743071b7fa041dce9"
Expand Down Expand Up @@ -2142,11 +2147,6 @@
"@gnosis.pm/dex-contracts" "^0.5.0"
bignumber.js "^9.0.2"

"@gnosis.pm/gp-v2-contracts@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@gnosis.pm/gp-v2-contracts/-/gp-v2-contracts-1.1.2.tgz#0453bb097377dc63cf46ee195f7e521d429f7e22"
integrity sha512-BvZMNS+fwITb+qs+trs2fyvYksa6MPjjLze9AOXPnvcKVYFEGwG6cfsecBswEMo+xevLIQNDyF7HZRhN7ply8w==

"@gnosis.pm/[email protected]":
version "0.9.3"
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-apps-provider/-/safe-apps-provider-0.9.3.tgz#d8913b0f8abc15fdca229571eefc5f9385c82ea7"
Expand Down

0 comments on commit 1a7b9d4

Please sign in to comment.