@cowprotocol/cow-sdk 0.0.6 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -7
- package/dist/CowSdk.d.ts +23 -0
- package/dist/{src/src/api → api}/cow/errors/OperatorError.d.ts +1 -1
- package/dist/{src/src/api → api}/cow/errors/QuoteError.d.ts +1 -1
- package/dist/{src/src/api → api}/cow/index.d.ts +8 -8
- package/dist/{src/src/api → api}/cow/types.d.ts +3 -2
- package/dist/api/cow-subgraph/graphql.d.ts +2603 -0
- package/dist/api/cow-subgraph/index.d.ts +17 -0
- package/dist/api/cow-subgraph/queries.d.ts +3 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/metadata/index.d.ts +11 -0
- package/dist/api/metadata/types.d.ts +15 -0
- package/dist/{src/appData.schema-d44994e0.js → appData.schema-d44994e0.js} +0 -0
- package/dist/{src/appData.schema-d44994e0.js.map → appData.schema-d44994e0.js.map} +0 -0
- package/dist/{src/appData.schema-fb2df827.js → appData.schema-fb2df827.js} +0 -0
- package/dist/{src/appData.schema-fb2df827.js.map → appData.schema-fb2df827.js.map} +0 -0
- package/dist/{src/src/constants → constants}/chains.d.ts +0 -0
- package/dist/{src/src/constants → constants}/index.d.ts +1 -0
- package/dist/{src/src/constants → constants}/tokens.d.ts +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +29 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +29 -0
- package/dist/index.module.js.map +1 -0
- package/dist/{src/src/types → types}/index.d.ts +2 -1
- package/dist/utils/appData.d.ts +10 -0
- package/dist/{src/src/utils → utils}/common.d.ts +2 -0
- package/dist/utils/context.d.ts +39 -0
- package/dist/utils/ipfs.d.ts +8 -0
- package/dist/{src/src/utils → utils}/sign.d.ts +1 -1
- package/dist/{src/src/utils → utils}/tokens.d.ts +1 -1
- package/package.json +48 -26
- package/.eslintrc.json +0 -15
- package/.github/workflows/publish.yml +0 -23
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -5
- package/COPYRIGHT.md +0 -13
- package/LICENSE-APACHE +0 -201
- package/LICENSE-MIT +0 -21
- package/babel.config.js +0 -6
- package/dist/src/cow-sdk.esm.js +0 -2
- package/dist/src/cow-sdk.esm.js.map +0 -1
- package/dist/src/cow-sdk.js +0 -2
- package/dist/src/cow-sdk.js.map +0 -1
- package/dist/src/cow-sdk.modern.js +0 -2
- package/dist/src/cow-sdk.modern.js.map +0 -1
- package/dist/src/src/CowSdk.d.ts +0 -16
- package/dist/src/src/api/index.d.ts +0 -1
- package/dist/src/src/index.d.ts +0 -4
- package/dist/src/src/utils/appData.d.ts +0 -7
- package/dist/src/src/utils/context.d.ts +0 -24
- package/docs/images/CoW.png +0 -0
- package/src/CowSdk.ts +0 -31
- package/src/api/cow/errors/OperatorError.ts +0 -140
- package/src/api/cow/errors/QuoteError.ts +0 -114
- package/src/api/cow/index.ts +0 -343
- package/src/api/cow/types.ts +0 -82
- package/src/api/index.ts +0 -1
- package/src/constants/chains.ts +0 -11
- package/src/constants/index.ts +0 -14
- package/src/constants/tokens.ts +0 -16
- package/src/index.ts +0 -4
- package/src/schemas/appData.schema.json +0 -70
- package/src/types/index.ts +0 -5
- package/src/utils/appData.spec.ts +0 -66
- package/src/utils/appData.ts +0 -32
- package/src/utils/common.ts +0 -27
- package/src/utils/context.ts +0 -42
- package/src/utils/price.ts +0 -44
- package/src/utils/sign.ts +0 -224
- package/src/utils/tokens.ts +0 -12
- package/src/workflows/publish.sh +0 -77
- package/tsconfig.json +0 -18
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { validateAppDataDocument } from './appData'
|
|
2
|
-
|
|
3
|
-
const VALID_RESULT = {
|
|
4
|
-
result: true,
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
test('Valid minimal document', async () => {
|
|
8
|
-
const validation = await validateAppDataDocument({
|
|
9
|
-
version: '0.1.0',
|
|
10
|
-
metadata: {},
|
|
11
|
-
})
|
|
12
|
-
expect(validation).toEqual(VALID_RESULT)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('Valid minimal document + appCode', async () => {
|
|
16
|
-
const validation = await validateAppDataDocument({
|
|
17
|
-
version: '0.1.0',
|
|
18
|
-
appCode: 'MyApp',
|
|
19
|
-
metadata: {},
|
|
20
|
-
})
|
|
21
|
-
expect(validation).toEqual(VALID_RESULT)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('Valid minimal document + appCode + referrer', async () => {
|
|
25
|
-
const validation = await validateAppDataDocument({
|
|
26
|
-
version: '0.1.0',
|
|
27
|
-
appCode: 'MyApp',
|
|
28
|
-
metadata: {
|
|
29
|
-
referrer: {
|
|
30
|
-
version: '0.1.0',
|
|
31
|
-
address: '0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
})
|
|
35
|
-
expect(validation).toEqual(VALID_RESULT)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('Invalid: Bad referrer', async () => {
|
|
39
|
-
const validation = await validateAppDataDocument({
|
|
40
|
-
version: '0.1.0',
|
|
41
|
-
appCode: 'MyApp',
|
|
42
|
-
metadata: {
|
|
43
|
-
referrer: {
|
|
44
|
-
version: '0.1.0',
|
|
45
|
-
address: 'this is not an ethereum address',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
expect(validation.result).toBeFalsy()
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('Invalid: No version', async () => {
|
|
53
|
-
const validation = await validateAppDataDocument({
|
|
54
|
-
appCode: 'MyApp',
|
|
55
|
-
metadata: {},
|
|
56
|
-
})
|
|
57
|
-
expect(validation.result).toBeFalsy()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test('Invalid: No metadata', async () => {
|
|
61
|
-
const validation = await validateAppDataDocument({
|
|
62
|
-
version: '0.1.0',
|
|
63
|
-
appCode: 'MyApp',
|
|
64
|
-
})
|
|
65
|
-
expect(validation.result).toBeFalsy()
|
|
66
|
-
})
|
package/src/utils/appData.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Ajv, { ErrorObject, ValidateFunction } from 'ajv'
|
|
2
|
-
|
|
3
|
-
let validate: ValidateFunction | undefined
|
|
4
|
-
let ajv: Ajv
|
|
5
|
-
|
|
6
|
-
interface ValidationResult {
|
|
7
|
-
result: boolean
|
|
8
|
-
errors?: ErrorObject[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async function getValidator(): Promise<{ ajv: Ajv; validate: ValidateFunction }> {
|
|
12
|
-
if (!ajv) {
|
|
13
|
-
ajv = new Ajv()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!validate) {
|
|
17
|
-
const appDataSchema = await import('../schemas/appData.schema.json')
|
|
18
|
-
validate = ajv.compile(appDataSchema)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return { ajv, validate }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function validateAppDataDocument(appDataDocument: any): Promise<ValidationResult> {
|
|
25
|
-
const { ajv, validate } = await getValidator()
|
|
26
|
-
const result = !!(await validate(appDataDocument))
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
result,
|
|
30
|
-
errors: ajv.errors ?? undefined,
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/utils/common.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export class CowError extends Error {
|
|
2
|
-
error_code?: string
|
|
3
|
-
|
|
4
|
-
constructor(message: string, error_code?: string) {
|
|
5
|
-
super(message)
|
|
6
|
-
this.error_code = error_code
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function objectToQueryString(o: any): string {
|
|
11
|
-
if (!o) {
|
|
12
|
-
return ''
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const qs = new URLSearchParams()
|
|
16
|
-
|
|
17
|
-
for (const key of Object.keys(o)) {
|
|
18
|
-
const value = o[key]
|
|
19
|
-
if (value) {
|
|
20
|
-
qs.append(key, value)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const qsResult = qs.toString()
|
|
25
|
-
|
|
26
|
-
return qsResult ? `?${qsResult}` : ''
|
|
27
|
-
}
|
package/src/utils/context.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Signer } from 'ethers'
|
|
2
|
-
import { CowError } from './common'
|
|
3
|
-
import { DEFAULT_APP_DATA_HASH } from '/constants'
|
|
4
|
-
|
|
5
|
-
export interface CowContext {
|
|
6
|
-
appDataHash?: string
|
|
7
|
-
isDevEnvironment?: boolean
|
|
8
|
-
signer?: Signer
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const DefaultCowContext = { appDataHash: DEFAULT_APP_DATA_HASH, isDevEnvironment: false }
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @export
|
|
17
|
-
* @class Context
|
|
18
|
-
* @implements {Required<CowContext>}
|
|
19
|
-
*/
|
|
20
|
-
export class Context implements Required<CowContext> {
|
|
21
|
-
private context: CowContext
|
|
22
|
-
|
|
23
|
-
constructor(context: CowContext) {
|
|
24
|
-
this.context = { ...DefaultCowContext, ...context }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get appDataHash(): string {
|
|
28
|
-
return this.context.appDataHash ?? DefaultCowContext.appDataHash
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get isDevEnvironment(): boolean {
|
|
32
|
-
return this.context.isDevEnvironment ?? DefaultCowContext.isDevEnvironment
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get signer(): Signer {
|
|
36
|
-
if (this.context.signer) {
|
|
37
|
-
return this.context.signer
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new CowError('No signer was provided')
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/utils/price.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { GetQuoteResponse } from '@gnosis.pm/gp-v2-contracts'
|
|
2
|
-
import { OrderMetaData } from '/api/cow/types'
|
|
3
|
-
|
|
4
|
-
export interface QuoteParams {
|
|
5
|
-
quoteParams: FeeQuoteParams
|
|
6
|
-
fetchFee: boolean
|
|
7
|
-
previousFee?: FeeInformation
|
|
8
|
-
isPriceRefresh: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface FeeInformation {
|
|
12
|
-
expirationDate: string
|
|
13
|
-
amount: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface PriceInformation {
|
|
17
|
-
token: string
|
|
18
|
-
amount: string | null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// GetQuoteResponse from @gnosis.pm/gp-v2-contracts types Timestamp and BigNumberish
|
|
22
|
-
// do not play well with our existing methods, using string instead
|
|
23
|
-
export type SimpleGetQuoteResponse = Pick<GetQuoteResponse, 'from'> & {
|
|
24
|
-
// We need to map BigNumberIsh and Timestamp to what we use: string
|
|
25
|
-
quote: Omit<GetQuoteResponse['quote'], 'sellAmount' | 'buyAmount' | 'feeAmount' | 'validTo'> & {
|
|
26
|
-
sellAmount: string
|
|
27
|
-
buyAmount: string
|
|
28
|
-
validTo: string
|
|
29
|
-
feeAmount: string
|
|
30
|
-
}
|
|
31
|
-
expiration: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type FeeQuoteParams = Pick<OrderMetaData, 'sellToken' | 'buyToken' | 'kind'> & {
|
|
35
|
-
amount: string
|
|
36
|
-
userAddress?: string | null
|
|
37
|
-
receiver?: string | null
|
|
38
|
-
validTo: number
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type PriceQuoteParams = Omit<FeeQuoteParams, 'sellToken' | 'buyToken'> & {
|
|
42
|
-
baseToken: string
|
|
43
|
-
quoteToken: string
|
|
44
|
-
}
|
package/src/utils/sign.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
domain as domainGp,
|
|
3
|
-
signOrder as signOrderGp,
|
|
4
|
-
signOrderCancellation as signOrderCancellationGp,
|
|
5
|
-
EcdsaSignature,
|
|
6
|
-
Order,
|
|
7
|
-
OrderCancellation as OrderCancellationGp,
|
|
8
|
-
Signature,
|
|
9
|
-
TypedDataV3Signer,
|
|
10
|
-
IntChainIdTypedDataV4Signer,
|
|
11
|
-
SigningScheme,
|
|
12
|
-
} from '@gnosis.pm/gp-v2-contracts'
|
|
13
|
-
import log from 'loglevel'
|
|
14
|
-
|
|
15
|
-
import { SupportedChainId as ChainId } from '/constants/chains'
|
|
16
|
-
import { GP_SETTLEMENT_CONTRACT_ADDRESS } from '/constants'
|
|
17
|
-
import { TypedDataDomain, Signer } from '@ethersproject/abstract-signer'
|
|
18
|
-
import { CowError } from './common'
|
|
19
|
-
|
|
20
|
-
// For error codes, see:
|
|
21
|
-
// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal
|
|
22
|
-
// - https://www.jsonrpc.org/specification#error_object
|
|
23
|
-
const METAMASK_SIGNATURE_ERROR_CODE = -32603
|
|
24
|
-
const METHOD_NOT_FOUND_ERROR_CODE = -32601
|
|
25
|
-
const V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i
|
|
26
|
-
const V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i
|
|
27
|
-
const RPC_REQUEST_FAILED_REGEX = /RPC request failed/i
|
|
28
|
-
const METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i
|
|
29
|
-
|
|
30
|
-
export type UnsignedOrder = Omit<Order, 'receiver'> & { receiver: string }
|
|
31
|
-
|
|
32
|
-
export interface SignOrderParams {
|
|
33
|
-
chainId: ChainId
|
|
34
|
-
signer: Signer
|
|
35
|
-
order: UnsignedOrder
|
|
36
|
-
signingScheme: SigningScheme
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// posted to /api/v1/orders on Order creation
|
|
40
|
-
// serializable, so no BigNumbers
|
|
41
|
-
// See https://protocol-rinkeby.dev.gnosisdev.com/api/
|
|
42
|
-
export interface OrderCreation extends UnsignedOrder {
|
|
43
|
-
signingScheme: SigningScheme // signed method
|
|
44
|
-
|
|
45
|
-
// Signature is used for:
|
|
46
|
-
// - Signature: EIP-712,ETHSIGN
|
|
47
|
-
// - Owner address: for PRESIGN
|
|
48
|
-
signature: string // 65 bytes encoded as hex without `0x` prefix. r + s + v from the spec
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface SingOrderCancellationParams {
|
|
52
|
-
chainId: ChainId
|
|
53
|
-
signer: Signer
|
|
54
|
-
orderId: string
|
|
55
|
-
signingScheme: SigningScheme
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface OrderCancellation extends OrderCancellationGp {
|
|
59
|
-
signature: string
|
|
60
|
-
signingScheme: SigningScheme
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type SigningSchemeValue = 'eip712' | 'ethsign' | 'eip1271' | 'presign'
|
|
64
|
-
|
|
65
|
-
interface SchemaInfo {
|
|
66
|
-
libraryValue: number
|
|
67
|
-
apiValue: SigningSchemeValue
|
|
68
|
-
}
|
|
69
|
-
const mapSigningSchema: Map<SigningScheme, SchemaInfo> = new Map([
|
|
70
|
-
[SigningScheme.EIP712, { libraryValue: 0, apiValue: 'eip712' }],
|
|
71
|
-
[SigningScheme.ETHSIGN, { libraryValue: 1, apiValue: 'ethsign' }],
|
|
72
|
-
[SigningScheme.EIP1271, { libraryValue: 2, apiValue: 'eip1271' }],
|
|
73
|
-
[SigningScheme.PRESIGN, { libraryValue: 3, apiValue: 'presign' }],
|
|
74
|
-
])
|
|
75
|
-
|
|
76
|
-
function _getSigningSchemeInfo(ecdaSigningScheme: SigningScheme): SchemaInfo {
|
|
77
|
-
const value = mapSigningSchema.get(ecdaSigningScheme)
|
|
78
|
-
if (value === undefined) {
|
|
79
|
-
throw new CowError('Unknown schema ' + ecdaSigningScheme)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return value
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface ProviderRpcError extends Error {
|
|
86
|
-
message: string
|
|
87
|
-
code: number
|
|
88
|
-
data?: unknown
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function isProviderRpcError(error: unknown): error is ProviderRpcError {
|
|
92
|
-
return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function getSigningSchemeApiValue(ecdaSigningScheme: SigningScheme): string {
|
|
96
|
-
return _getSigningSchemeInfo(ecdaSigningScheme).apiValue
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function getSigningSchemeLibValue(ecdaSigningScheme: SigningScheme): number {
|
|
100
|
-
return _getSigningSchemeInfo(ecdaSigningScheme).libraryValue
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function _getDomain(chainId: ChainId): TypedDataDomain {
|
|
104
|
-
// Get settlement contract address
|
|
105
|
-
const settlementContract = GP_SETTLEMENT_CONTRACT_ADDRESS[chainId]
|
|
106
|
-
|
|
107
|
-
if (!settlementContract) {
|
|
108
|
-
throw new CowError('Unsupported network. Settlement contract is not deployed')
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return domainGp(chainId, settlementContract)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function _signOrder(params: SignOrderParams): Promise<Signature> {
|
|
115
|
-
const { chainId, signer, order, signingScheme } = params
|
|
116
|
-
|
|
117
|
-
const domain = _getDomain(chainId)
|
|
118
|
-
|
|
119
|
-
return signOrderGp(domain, order, signer, getSigningSchemeLibValue(signingScheme))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function _signOrderCancellation(params: SingOrderCancellationParams): Promise<Signature> {
|
|
123
|
-
const { chainId, signer, signingScheme, orderId } = params
|
|
124
|
-
|
|
125
|
-
const domain = _getDomain(chainId)
|
|
126
|
-
|
|
127
|
-
return signOrderCancellationGp(domain, orderId, signer, getSigningSchemeLibValue(signingScheme))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type SigningResult = { signature: string; signingScheme: SigningScheme }
|
|
131
|
-
|
|
132
|
-
async function _signPayload(
|
|
133
|
-
payload: any,
|
|
134
|
-
signFn: typeof _signOrder | typeof _signOrderCancellation,
|
|
135
|
-
signer: Signer,
|
|
136
|
-
signingMethod: 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'
|
|
137
|
-
): Promise<SigningResult> {
|
|
138
|
-
const signingScheme = signingMethod === 'eth_sign' ? SigningScheme.ETHSIGN : SigningScheme.EIP712
|
|
139
|
-
let signature: Signature | null = null
|
|
140
|
-
|
|
141
|
-
let _signer
|
|
142
|
-
try {
|
|
143
|
-
switch (signingMethod) {
|
|
144
|
-
case 'v3':
|
|
145
|
-
_signer = new TypedDataV3Signer(signer)
|
|
146
|
-
break
|
|
147
|
-
case 'int_v4':
|
|
148
|
-
_signer = new IntChainIdTypedDataV4Signer(signer)
|
|
149
|
-
break
|
|
150
|
-
default:
|
|
151
|
-
_signer = signer
|
|
152
|
-
}
|
|
153
|
-
} catch (e) {
|
|
154
|
-
log.error('Wallet not supported:', e)
|
|
155
|
-
throw new CowError('Wallet not supported')
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now
|
|
160
|
-
} catch (e) {
|
|
161
|
-
if (!isProviderRpcError(e)) {
|
|
162
|
-
// Some other error signing. Let it bubble up.
|
|
163
|
-
log.error(e)
|
|
164
|
-
throw e
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (e.code === METHOD_NOT_FOUND_ERROR_CODE || RPC_REQUEST_FAILED_REGEX.test(e.message)) {
|
|
168
|
-
// Maybe the wallet returns the proper error code? We can only hope 🤞
|
|
169
|
-
// OR it failed with a generic message, there's no error code set, and we also hope it'll work
|
|
170
|
-
// with other methods...
|
|
171
|
-
switch (signingMethod) {
|
|
172
|
-
case 'v4':
|
|
173
|
-
return _signPayload(payload, signFn, signer, 'v3')
|
|
174
|
-
case 'v3':
|
|
175
|
-
return _signPayload(payload, signFn, signer, 'eth_sign')
|
|
176
|
-
default:
|
|
177
|
-
throw e
|
|
178
|
-
}
|
|
179
|
-
} else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {
|
|
180
|
-
// Metamask now enforces chainId to be an integer
|
|
181
|
-
return _signPayload(payload, signFn, signer, 'int_v4')
|
|
182
|
-
} else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {
|
|
183
|
-
// We tried to sign order the nice way.
|
|
184
|
-
// That works fine for regular MM addresses. Does not work for Hardware wallets, though.
|
|
185
|
-
// See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020
|
|
186
|
-
// So, when that specific error occurs, we know this is a problem with MM + HW.
|
|
187
|
-
// Then, we fallback to ETHSIGN.
|
|
188
|
-
return _signPayload(payload, signFn, signer, 'eth_sign')
|
|
189
|
-
} else if (V4_ERROR_MSG_REGEX.test(e.message)) {
|
|
190
|
-
// Failed with `v4`, and the wallet does not set the proper error code
|
|
191
|
-
return _signPayload(payload, signFn, signer, 'v3')
|
|
192
|
-
} else if (V3_ERROR_MSG_REGEX.test(e.message)) {
|
|
193
|
-
// Failed with `v3`, and the wallet does not set the proper error code
|
|
194
|
-
return _signPayload(payload, signFn, signer, 'eth_sign')
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return { signature: signature!.data.toString(), signingScheme }
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Returns the signature for the specified order with the signing scheme encoded
|
|
201
|
-
* into the signature.
|
|
202
|
-
* @export
|
|
203
|
-
* @param {UnsignedOrder} order The order to sign.
|
|
204
|
-
* @param {ChainId} chainId The chain Id
|
|
205
|
-
* @param {Signer} signer The owner for the order used to sign.
|
|
206
|
-
* @return {*} Encoded signature including signing scheme for the order.
|
|
207
|
-
*/
|
|
208
|
-
export async function signOrder(order: UnsignedOrder, chainId: ChainId, signer: Signer): Promise<SigningResult> {
|
|
209
|
-
return _signPayload({ order, chainId }, _signOrder, signer)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Returns the signature for the Order Cancellation with the signing scheme encoded
|
|
214
|
-
* into the signature.
|
|
215
|
-
*
|
|
216
|
-
* @export
|
|
217
|
-
* @param {string} orderId The unique identifier of the order being cancelled.
|
|
218
|
-
* @param {ChainId} chainId The chain Id
|
|
219
|
-
* @param {Signer} signer The owner for the order used to sign.
|
|
220
|
-
* @return {*} Encoded signature including signing scheme for the order.
|
|
221
|
-
*/
|
|
222
|
-
export async function signOrderCancellation(orderId: string, chainId: ChainId, signer: Signer): Promise<SigningResult> {
|
|
223
|
-
return _signPayload({ orderId, chainId }, _signOrderCancellation, signer)
|
|
224
|
-
}
|
package/src/utils/tokens.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { SupportedChainId as ChainId } from '/constants/chains'
|
|
2
|
-
import { NATIVE, WRAPPED_NATIVE_TOKEN } from '/constants/tokens'
|
|
3
|
-
|
|
4
|
-
export function toErc20Address(tokenAddress: string, chainId: ChainId): string {
|
|
5
|
-
let checkedAddress = tokenAddress
|
|
6
|
-
|
|
7
|
-
if (tokenAddress === NATIVE[chainId]) {
|
|
8
|
-
checkedAddress = WRAPPED_NATIVE_TOKEN[chainId].address
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return checkedAddress
|
|
12
|
-
}
|
package/src/workflows/publish.sh
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -o nounset
|
|
4
|
-
set -o pipefail
|
|
5
|
-
set -o errexit
|
|
6
|
-
|
|
7
|
-
fail_if_unset () {
|
|
8
|
-
local var_name="$1"
|
|
9
|
-
if [[ -z "${!var_name:-""}" ]]; then
|
|
10
|
-
printf '%s not set\n' "$var_name" >&2
|
|
11
|
-
exit 1
|
|
12
|
-
fi
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
package_exists () {
|
|
16
|
-
npm view --json "$1" &>/dev/null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
fail_if_unset GITLAB_TRIGGER_TOKEN
|
|
20
|
-
fail_if_unset BUCKET_NAME
|
|
21
|
-
fail_if_unset PUBLISH_SERVER
|
|
22
|
-
fail_if_unset AWS_ACCESS_KEY_ID
|
|
23
|
-
fail_if_unset AWS_SECRET_ACCESS_KEY
|
|
24
|
-
fail_if_unset AWS_REGION
|
|
25
|
-
|
|
26
|
-
git_username="GitHub Actions"
|
|
27
|
-
git_useremail="GitHub-Actions@cow-sdk"
|
|
28
|
-
|
|
29
|
-
package_name="$(jq --raw-output .name ./package.json)"
|
|
30
|
-
version="$(jq --raw-output .version ./package.json)"
|
|
31
|
-
|
|
32
|
-
if package_exists "$package_name" && grep --silent --line-regexp --fixed-strings -- "$version" \
|
|
33
|
-
<(npm view --json "$package_name" | jq '.versions[] | .' --raw-output); then
|
|
34
|
-
echo "Version $version already published"
|
|
35
|
-
exit 1
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
version_tag="v$version"
|
|
39
|
-
if git fetch --end-of-options origin "refs/tags/$version_tag" 2>/dev/null; then
|
|
40
|
-
echo "Tag $version_tag is already present"
|
|
41
|
-
exit 1
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
yarn pack --filename package.tgz
|
|
45
|
-
|
|
46
|
-
aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID"
|
|
47
|
-
aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
|
|
48
|
-
aws configure set region "$AWS_REGION"
|
|
49
|
-
if ! aws s3 cp package.tgz "s3://$BUCKET_NAME/cow-sdk/cow-sdk-$version.tgz"; then
|
|
50
|
-
echo "Failed upload to aws"
|
|
51
|
-
exit 1
|
|
52
|
-
fi
|
|
53
|
-
|
|
54
|
-
if ! pipeline_url="$(\
|
|
55
|
-
curl --silent --request POST \
|
|
56
|
-
--form-string "token=$GITLAB_TRIGGER_TOKEN" \
|
|
57
|
-
--form-string "ref=master" \
|
|
58
|
-
--form-string "variables[PROJECT]=$package_name" \
|
|
59
|
-
--form-string "variables[VERSION]=$version" \
|
|
60
|
-
--form-string "variables[TOKEN]=$GITLAB_TRIGGER_TOKEN" \
|
|
61
|
-
"$PUBLISH_SERVER" \
|
|
62
|
-
| jq -e '.web_url'\
|
|
63
|
-
)"; then
|
|
64
|
-
echo "Error triggering publish request"
|
|
65
|
-
exit 1
|
|
66
|
-
fi
|
|
67
|
-
|
|
68
|
-
if ! git config --get user.name &>/dev/null; then
|
|
69
|
-
git config user.name "$git_username"
|
|
70
|
-
git config user.email "$git_useremail"
|
|
71
|
-
fi
|
|
72
|
-
git tag -m "Version $version" --end-of-options "$version_tag"
|
|
73
|
-
|
|
74
|
-
git push origin "refs/tags/$version_tag"
|
|
75
|
-
|
|
76
|
-
echo "Package $package_name version $version successfully submitted for publication."
|
|
77
|
-
echo "Progress can be tracked here: $pipeline_url"
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"paths": {
|
|
5
|
-
"/*": ["src/*"]
|
|
6
|
-
},
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"target": "ESNext",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"alwaysStrict": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"noUnusedLocals": true,
|
|
17
|
-
}
|
|
18
|
-
}
|