@cowprotocol/cow-sdk 0.0.8-RC.0 → 0.0.9

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.
Files changed (52) hide show
  1. package/README.md +95 -23
  2. package/dist/CowSdk.d.ts +2 -1
  3. package/dist/api/cow-subgraph/graphql.d.ts +2576 -0
  4. package/dist/api/cow-subgraph/index.d.ts +17 -0
  5. package/dist/api/cow-subgraph/queries.d.ts +3 -0
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/metadata/index.d.ts +3 -1
  8. package/dist/index.d.ts +3 -2
  9. package/dist/index.js +28 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.modern.js +28 -1
  12. package/dist/index.modern.js.map +1 -1
  13. package/dist/index.module.js +28 -1
  14. package/dist/index.module.js.map +1 -1
  15. package/dist/utils/context.d.ts +12 -3
  16. package/dist/utils/ipfs.d.ts +8 -0
  17. package/package.json +24 -7
  18. package/.babelrc +0 -4
  19. package/.eslintrc.json +0 -15
  20. package/.github/workflows/build.yml +0 -50
  21. package/.github/workflows/lint.yml +0 -19
  22. package/.github/workflows/publish.yml +0 -20
  23. package/.github/workflows/test.yml +0 -47
  24. package/.nvmrc +0 -1
  25. package/.prettierignore +0 -1
  26. package/.prettierrc +0 -5
  27. package/COPYRIGHT.md +0 -13
  28. package/babel.config.js +0 -3
  29. package/docs/images/CoW.png +0 -0
  30. package/src/CowSdk.ts +0 -53
  31. package/src/api/cow/errors/OperatorError.ts +0 -142
  32. package/src/api/cow/errors/QuoteError.ts +0 -115
  33. package/src/api/cow/index.ts +0 -367
  34. package/src/api/cow/types.ts +0 -82
  35. package/src/api/index.ts +0 -2
  36. package/src/api/metadata/index.ts +0 -37
  37. package/src/api/metadata/types.ts +0 -17
  38. package/src/constants/chains.ts +0 -11
  39. package/src/constants/index.ts +0 -16
  40. package/src/constants/tokens.ts +0 -16
  41. package/src/index.ts +0 -4
  42. package/src/schemas/appData.schema.json +0 -70
  43. package/src/types/index.ts +0 -6
  44. package/src/utils/appData.spec.ts +0 -109
  45. package/src/utils/appData.ts +0 -58
  46. package/src/utils/common.ts +0 -35
  47. package/src/utils/context.ts +0 -89
  48. package/src/utils/price.ts +0 -44
  49. package/src/utils/sign.ts +0 -224
  50. package/src/utils/tokens.ts +0 -12
  51. package/src/workflows/publish.sh +0 -49
  52. package/tsconfig.json +0 -17
@@ -1,109 +0,0 @@
1
- import { validateAppDataDocument, getSerializedCID, loadIpfsFromCid } from './appData'
2
-
3
- const VALID_RESULT = {
4
- result: true,
5
- }
6
-
7
- const INVALID_CID_LENGTH = 'Incorrect length'
8
-
9
- test('Valid minimal document', async () => {
10
- const validation = await validateAppDataDocument({
11
- version: '0.1.0',
12
- metadata: {},
13
- })
14
- expect(validation).toEqual(VALID_RESULT)
15
- })
16
-
17
- test('Valid minimal document + appCode', async () => {
18
- const validation = await validateAppDataDocument({
19
- version: '0.1.0',
20
- appCode: 'MyApp',
21
- metadata: {},
22
- })
23
- expect(validation).toEqual(VALID_RESULT)
24
- })
25
-
26
- test('Valid minimal document + appCode + referrer', async () => {
27
- const validation = await validateAppDataDocument({
28
- version: '0.1.0',
29
- appCode: 'MyApp',
30
- metadata: {
31
- referrer: {
32
- version: '0.1.0',
33
- address: '0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52',
34
- },
35
- },
36
- })
37
- expect(validation).toEqual(VALID_RESULT)
38
- })
39
-
40
- test('Invalid: Bad referrer', async () => {
41
- const validation = await validateAppDataDocument({
42
- version: '0.1.0',
43
- appCode: 'MyApp',
44
- metadata: {
45
- referrer: {
46
- version: '0.1.0',
47
- address: 'this is not an ethereum address',
48
- },
49
- },
50
- })
51
- expect(validation.result).toBeFalsy()
52
- })
53
-
54
- test('Invalid: No version', async () => {
55
- const validation = await validateAppDataDocument({
56
- appCode: 'MyApp',
57
- metadata: {},
58
- })
59
- expect(validation.result).toBeFalsy()
60
- })
61
-
62
- test('Invalid: No metadata', async () => {
63
- const validation = await validateAppDataDocument({
64
- version: '0.1.0',
65
- appCode: 'MyApp',
66
- })
67
- expect(validation.result).toBeFalsy()
68
- })
69
-
70
- test('Invalid: No metadata', async () => {
71
- const validation = await validateAppDataDocument({
72
- version: '0.1.0',
73
- appCode: 'MyApp',
74
- })
75
- expect(validation.result).toBeFalsy()
76
- })
77
-
78
- test('Invalid: No metadata', async () => {
79
- const validation = await validateAppDataDocument({
80
- version: '0.1.0',
81
- appCode: 'MyApp',
82
- })
83
- expect(validation.result).toBeFalsy()
84
- })
85
-
86
- test('Valid serialized appData CID', async () => {
87
- const hash = '0xa6c81f4ca727252a05b108f1742a07430f28d474d2a3492d8f325746824d22e5'
88
- const serializedCidV0 = 'QmZZhNnqMF1gRywNKnTPuZksX7rVjQgTT3TJAZ7R6VE3b2'
89
- const cidV0 = await getSerializedCID(hash)
90
-
91
- expect(cidV0).toEqual(serializedCidV0)
92
- })
93
-
94
- test('Invalid: serialized appData CID format ', async () => {
95
- const invalidHash = '0xa6c81f4ca727252a05b108f1742'
96
- try {
97
- await getSerializedCID(invalidHash)
98
- } catch (e: any) {
99
- expect(e.message).toEqual(INVALID_CID_LENGTH)
100
- }
101
- })
102
-
103
- test('Valid IPFS appData from CID', async () => {
104
- const validSerializedCidV0 = 'QmZZhNnqMF1gRywNKnTPuZksX7rVjQgTT3TJAZ7R6VE3b2'
105
- const appDataDocument = await loadIpfsFromCid(validSerializedCidV0)
106
- const validation = await validateAppDataDocument(appDataDocument)
107
-
108
- expect(validation).toEqual(VALID_RESULT)
109
- })
@@ -1,58 +0,0 @@
1
- import Ajv, { ErrorObject, ValidateFunction } from 'ajv'
2
- import { fromHexString } from './common'
3
- import { DEFAULT_IPFS_GATEWAY_URI } from '../constants'
4
- import { AppDataDoc } from '../types'
5
-
6
- let validate: ValidateFunction | undefined
7
- let ajv: Ajv
8
-
9
- interface ValidationResult {
10
- result: boolean
11
- errors?: ErrorObject[]
12
- }
13
-
14
- async function getValidator(): Promise<{ ajv: Ajv; validate: ValidateFunction }> {
15
- if (!ajv) {
16
- ajv = new Ajv()
17
- }
18
-
19
- if (!validate) {
20
- const appDataSchema = await import('../schemas/appData.schema.json')
21
- validate = ajv.compile(appDataSchema)
22
- }
23
-
24
- return { ajv, validate }
25
- }
26
-
27
- export async function getSerializedCID(hash: string): Promise<void | string> {
28
- const cidVersion = 0x1 //cidv1
29
- const codec = 0x70 //dag-pb
30
- const type = 0x12 //sha2-256
31
- const length = 32 //256 bits
32
- const _hash = hash.replace(/(^0x)/, '')
33
-
34
- const hexHash = fromHexString(_hash)
35
-
36
- if (!hexHash) return
37
-
38
- const uint8array = Uint8Array.from([cidVersion, codec, type, length, ...hexHash])
39
- const { CID } = await import('multiformats/cid')
40
- return CID.decode(uint8array).toV0().toString()
41
- }
42
-
43
- export async function loadIpfsFromCid(cid: string, ipfsUri = DEFAULT_IPFS_GATEWAY_URI): Promise<AppDataDoc> {
44
- const { default: fetch } = await import('cross-fetch')
45
- const response = await fetch(`${ipfsUri}/${cid}`)
46
-
47
- return await response.json()
48
- }
49
-
50
- export async function validateAppDataDocument(appDataDocument: unknown): Promise<ValidationResult> {
51
- const { ajv, validate } = await getValidator()
52
- const result = !!validate(appDataDocument)
53
-
54
- return {
55
- result,
56
- errors: ajv.errors ?? undefined,
57
- }
58
- }
@@ -1,35 +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
- }
28
-
29
- export const logPrefix = 'cow-sdk:'
30
-
31
- export function fromHexString(hexString: string) {
32
- const stringMatch = hexString.match(/.{1,2}/g)
33
- if (!stringMatch) return
34
- return new Uint8Array(stringMatch.map((byte) => parseInt(byte, 16)))
35
- }
@@ -1,89 +0,0 @@
1
- import { Signer } from 'ethers'
2
- import log from 'loglevel'
3
- import { CowError, logPrefix } from './common'
4
- import { SupportedChainId as ChainId } from '../constants/chains'
5
- import { DEFAULT_APP_DATA_HASH, DEFAULT_IPFS_GATEWAY_URI } from '../constants'
6
-
7
- export interface CowContext {
8
- appDataHash?: string
9
- isDevEnvironment?: boolean
10
- signer?: Signer
11
- ipfsUri?: string
12
- }
13
-
14
- export const DefaultCowContext = {
15
- appDataHash: DEFAULT_APP_DATA_HASH,
16
- isDevEnvironment: false,
17
- ipfsUri: DEFAULT_IPFS_GATEWAY_URI,
18
- }
19
-
20
- /**
21
- *
22
- *
23
- * @export
24
- * @class Context
25
- * @implements {Required<CowContext>}
26
- */
27
- export class Context implements Partial<CowContext> {
28
- #context: CowContext
29
- #chainId: ChainId
30
-
31
- constructor(chainId: ChainId, context: CowContext) {
32
- this.#chainId = this.updateChainId(chainId)
33
- this.#context = { ...DefaultCowContext, ...context }
34
- }
35
-
36
- updateChainId(chainId: ChainId) {
37
- if (!ChainId[chainId]) {
38
- throw new CowError(`Invalid chainId: ${chainId}`)
39
- }
40
-
41
- log.debug(logPrefix, `Updating chainId to: ${chainId}`)
42
-
43
- this.#chainId = chainId
44
- return chainId
45
- }
46
-
47
- get chainId(): Promise<ChainId> {
48
- const provider = this.#context.signer?.provider
49
- if (!provider) {
50
- return Promise.resolve(this.#chainId)
51
- }
52
-
53
- log.debug(logPrefix, 'Getting chainId from provider')
54
-
55
- const getAndReconciliateNetwork = async () => {
56
- const network = await provider.getNetwork()
57
- const chainId = network.chainId
58
-
59
- if (chainId !== this.#chainId) {
60
- log.debug(
61
- logPrefix,
62
- `ChainId mismatch: Provider's chainId: ${chainId} vs Context's chainId: ${
63
- this.#chainId
64
- }. Updating Context's chainId`
65
- )
66
- this.updateChainId(chainId)
67
- }
68
- return chainId
69
- }
70
-
71
- return getAndReconciliateNetwork()
72
- }
73
-
74
- get appDataHash(): string {
75
- return this.#context.appDataHash ?? DefaultCowContext.appDataHash
76
- }
77
-
78
- get isDevEnvironment(): boolean {
79
- return this.#context.isDevEnvironment ?? DefaultCowContext.isDevEnvironment
80
- }
81
-
82
- get signer(): Signer | undefined {
83
- return this.#context.signer
84
- }
85
-
86
- get ipfsUri(): string {
87
- return this.#context.ipfsUri ?? DefaultCowContext.ipfsUri
88
- }
89
- }
@@ -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, logPrefix } 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(logPrefix, '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(logPrefix, 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
- }
@@ -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
- }
@@ -1,49 +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 NODE_AUTH_TOKEN
20
-
21
- git_username="GitHub Actions"
22
- git_useremail="GitHub-Actions@cow.fi"
23
-
24
- package_name="$(jq --raw-output .name ./package.json)"
25
- version="$(jq --raw-output .version ./package.json)"
26
-
27
- if package_exists "$package_name" && grep --silent --line-regexp --fixed-strings -- "$version" \
28
- <(npm view --json "$package_name" | jq '.versions[] | .' --raw-output); then
29
- echo "Version $version already published"
30
- exit 1
31
- fi
32
-
33
- version_tag="v$version"
34
- if git fetch --end-of-options origin "refs/tags/$version_tag" 2>/dev/null; then
35
- echo "Tag $version_tag is already present"
36
- exit 1
37
- fi
38
-
39
- yarn publish --access public
40
-
41
- if ! git config --get user.name &>/dev/null; then
42
- git config user.name "$git_username"
43
- git config user.email "$git_useremail"
44
- fi
45
- git tag -m "Version $version" --end-of-options "$version_tag"
46
-
47
- git push origin "refs/tags/$version_tag"
48
-
49
- echo "Package $package_name version $version successfully published."
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "moduleResolution": "node",
4
- "module": "ESNext",
5
- "target": "ESNext",
6
- "strict": true,
7
- "alwaysStrict": true,
8
- "resolveJsonModule": true,
9
- "allowSyntheticDefaultImports": true,
10
- "noEmit": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "noUnusedLocals": true
13
- },
14
- "exclude": [
15
- "dist"
16
- ]
17
- }