Skip to content

Commit 7417d1f

Browse files
committed
fix: reincorporate linting in CI and commit formatter changes
1 parent e2222d4 commit 7417d1f

26 files changed

+2930
-1446
lines changed

sdk/.eslintrc.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"extends": [
33
"eslint:recommended",
4-
"plugin:@typescript-eslint/recommended"
4+
"plugin:@typescript-eslint/recommended",
5+
"plugin:prettier/recommended",
6+
"rainbow"
57
],
68
"parser": "@typescript-eslint/parser",
79
"plugins": ["@typescript-eslint"],
@@ -12,7 +14,8 @@
1214
},
1315
"parserOptions": {
1416
"ecmaVersion": 2020,
15-
"sourceType": "module"
17+
"sourceType": "module",
18+
"project": "./tsconfig.eslint.json"
1619
},
1720
"rules": {
1821
"no-console": "off",

sdk/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@typescript-eslint/parser": "^6.21.0",
1919
"dotenv": "^16.4.7",
2020
"eslint": "^8.57.0",
21+
"eslint-plugin-jest": "^27.9.0",
2122
"jest": "^29.7.0",
2223
"ts-jest": "^29.2.5",
2324
"typescript": "^4.4.4"
@@ -41,7 +42,9 @@
4142
"@uniswap/sdk-core": "^3.0.0",
4243
"decimal.js": "^10.5.0",
4344
"jsbi": "^4.3.0",
44-
"tiny-invariant": "^1.3.3"
45+
"tiny-invariant": "^1.3.3",
46+
"eslint-config-rainbow": "4.3.0",
47+
"prettier": "^3.3.3"
4548
},
4649
"author": "Christopher Howard",
4750
"files": [
@@ -57,7 +60,7 @@
5760
"prepare": "yarn build",
5861
"pretest": "grep -v '^IS_TESTING=' .env > .env.tmp 2>/dev/null || true; echo 'IS_TESTING=true' >> .env.tmp; mv .env.tmp .env",
5962
"test": "./scripts/test.sh",
60-
"lint": "eslint '**/*.{js,ts}'",
63+
"lint": "eslint 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
6164
"format:check": "prettier --check '**/*.{js,ts,json,md}'",
6265
"format:fix": "prettier --write '**/*.{js,ts,json,md}'",
6366
"clean": "rm -rf dist"

sdk/src/api/getAirdropSuggestions.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const getAirdropSuggestions = async (
66
config: SDKConfig
77
): Promise<GetAirdropSuggestionsResponse> => {
88
let url;
9-
let headers: HeadersInit = {
9+
const headers: HeadersInit = {
1010
'Content-Type': 'application/json',
1111
};
1212
switch (config.MODE) {
@@ -20,10 +20,7 @@ export const getAirdropSuggestions = async (
2020
default:
2121
throw new Error('Invalid mode');
2222
}
23-
return await rainbowFetch(
24-
`${url}/v1/airdrop/${userAddress}/suggestions`,
25-
{
26-
headers,
27-
}
28-
);
29-
};
23+
return await rainbowFetch(`${url}/v1/airdrop/${userAddress}/suggestions`, {
24+
headers,
25+
});
26+
};

sdk/src/api/getRainbowSuperToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const getRainbowSuperTokenByUri = async (
66
config: SDKConfig
77
): Promise<GetRainbowSuperTokenResponse> => {
88
let url;
9-
let headers: HeadersInit = {
9+
const headers: HeadersInit = {
1010
'Content-Type': 'application/json',
1111
};
1212
switch (config.MODE) {

sdk/src/api/getRainbowSuperTokens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { rainbowFetch } from './utils/rainbowFetch';
22
import { GetRainbowSuperTokensResponse, SDKConfig } from '../types';
33

4-
export const getRainbowSuperTokens = async (config: SDKConfig): Promise<GetRainbowSuperTokensResponse> => {
4+
export const getRainbowSuperTokens = async (
5+
config: SDKConfig
6+
): Promise<GetRainbowSuperTokensResponse> => {
57
let url;
6-
let headers: HeadersInit = {
8+
const headers: HeadersInit = {
79
'Content-Type': 'application/json',
810
};
911
switch (config.MODE) {

sdk/src/api/submitRainbowSuperToken.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { rainbowFetch } from './utils/rainbowFetch';
2-
import { DeployRainbowSuperTokenRequest, DeployRainbowSuperTokenResponse, SDKConfig } from '../types';
2+
import {
3+
DeployRainbowSuperTokenRequest,
4+
DeployRainbowSuperTokenResponse,
5+
SDKConfig,
6+
} from '../types';
37

48
export const submitRainbowSuperToken = async (
59
payload: DeployRainbowSuperTokenRequest,
610
config: SDKConfig
711
): Promise<DeployRainbowSuperTokenResponse> => {
812
let url;
9-
let headers: HeadersInit = {
13+
const headers: HeadersInit = {
1014
'Content-Type': 'application/json',
1115
};
1216
switch (config.MODE) {

sdk/src/api/utils/rainbowFetch.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { RainbowFetchError } from '../../types'
1+
import { RainbowFetchError } from '../../types';
22

33
export async function rainbowFetch(input: RequestInfo | URL, init?: RequestInit) {
4-
const response = await fetch(input, init)
5-
4+
const response = await fetch(input, init);
5+
66
if (!response.ok) {
7-
const errorBody = await response.text()
7+
const errorBody = await response.text();
88

99
throw new RainbowFetchError(
1010
`HTTP error ${response.status}: ${response.statusText}\nDetails: ${errorBody}`,
1111
response.status,
1212
errorBody
13-
)
13+
);
1414
}
15-
const responseData = await response.json()
16-
return responseData
15+
const responseData = await response.json();
16+
return responseData;
1717
}
1818

1919
export function createRainbowHeaders(authToken?: string): HeadersInit {
2020
const headers: HeadersInit = {
2121
'Content-Type': 'application/json',
22-
}
22+
};
2323

2424
if (authToken) {
25-
headers['Authorization'] = `Bearer ${authToken}`
25+
headers['Authorization'] = `Bearer ${authToken}`;
2626
}
2727

28-
return headers
28+
return headers;
2929
}

sdk/src/errors.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
export enum TokenLauncherErrorCode {
2-
// API errors
3-
API_REQUEST_FAILED = "API_REQUEST_FAILED",
4-
API_RESPONSE_INVALID = "API_RESPONSE_INVALID",
5-
SUBMISSION_DETAILS_MISSING = "SUBMISSION_DETAILS_MISSING",
6-
7-
// Blockchain errors
8-
TRANSACTION_FAILED = "TRANSACTION_FAILED",
9-
CONTRACT_INTERACTION_FAILED = "CONTRACT_INTERACTION_FAILED",
10-
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
11-
GAS_ESTIMATION_FAILED = "GAS_ESTIMATION_FAILED",
12-
INVALID_SALT = "INVALID_SALT",
13-
14-
// Parameter errors
15-
INVALID_PARAMS = "INVALID_PARAMS",
16-
MISSING_REQUIRED_PARAM = "MISSING_REQUIRED_PARAM",
17-
18-
// Wallet errors
19-
WALLET_CONNECTION_ERROR = "WALLET_CONNECTION_ERROR",
20-
21-
// Generic errors
22-
UNKNOWN_ERROR = "UNKNOWN_ERROR"
23-
}
24-
25-
export class TokenLauncherSDKError extends Error {
26-
readonly code: TokenLauncherErrorCode;
27-
readonly context: {
2+
// API errors
3+
API_REQUEST_FAILED = 'API_REQUEST_FAILED',
4+
API_RESPONSE_INVALID = 'API_RESPONSE_INVALID',
5+
SUBMISSION_DETAILS_MISSING = 'SUBMISSION_DETAILS_MISSING',
6+
7+
// Blockchain errors
8+
TRANSACTION_FAILED = 'TRANSACTION_FAILED',
9+
CONTRACT_INTERACTION_FAILED = 'CONTRACT_INTERACTION_FAILED',
10+
INSUFFICIENT_FUNDS = 'INSUFFICIENT_FUNDS',
11+
GAS_ESTIMATION_FAILED = 'GAS_ESTIMATION_FAILED',
12+
INVALID_SALT = 'INVALID_SALT',
13+
14+
// Parameter errors
15+
INVALID_PARAMS = 'INVALID_PARAMS',
16+
MISSING_REQUIRED_PARAM = 'MISSING_REQUIRED_PARAM',
17+
18+
// Wallet errors
19+
WALLET_CONNECTION_ERROR = 'WALLET_CONNECTION_ERROR',
20+
21+
// Generic errors
22+
UNKNOWN_ERROR = 'UNKNOWN_ERROR',
23+
}
24+
25+
export class TokenLauncherSDKError extends Error {
26+
readonly code: TokenLauncherErrorCode;
27+
readonly context: {
28+
operation: string;
29+
params?: any;
30+
source: 'api' | 'chain' | 'sdk';
31+
chainId?: number;
32+
transactionHash?: string;
33+
originalError?: any;
34+
};
35+
36+
constructor(
37+
code: TokenLauncherErrorCode,
38+
message: string,
39+
context: {
2840
operation: string;
2941
params?: any;
30-
source: "api" | "chain" | "sdk";
42+
source: 'api' | 'chain' | 'sdk';
3143
chainId?: number;
3244
transactionHash?: string;
3345
originalError?: any;
34-
};
35-
36-
constructor(
37-
code: TokenLauncherErrorCode,
38-
message: string,
39-
context: {
40-
operation: string;
41-
params?: any;
42-
source: "api" | "chain" | "sdk";
43-
chainId?: number;
44-
transactionHash?: string;
45-
originalError?: any;
46-
}
47-
) {
48-
super(`${code}: ${message}`);
49-
this.name = "TokenLauncherSDKError";
50-
this.code = code;
51-
this.context = context;
52-
53-
// Maintain proper stack trace in V8 engines
54-
Object.setPrototypeOf(this, TokenLauncherSDKError.prototype);
5546
}
47+
) {
48+
super(`${code}: ${message}`);
49+
this.name = 'TokenLauncherSDKError';
50+
this.code = code;
51+
this.context = context;
52+
53+
// Maintain proper stack trace in V8 engines
54+
Object.setPrototypeOf(this, TokenLauncherSDKError.prototype);
5655
}
57-
58-
// Helper function to format and throw errors
59-
export function throwTokenLauncherError(
60-
code: TokenLauncherErrorCode,
61-
message: string,
62-
context: Omit<TokenLauncherSDKError["context"], "source"> & { source?: "api" | "chain" | "sdk" }
63-
): never {
64-
throw new TokenLauncherSDKError(code, message, {
65-
...context,
66-
source: context.source || "sdk"
67-
});
68-
}
56+
}
57+
58+
// Helper function to format and throw errors
59+
export function throwTokenLauncherError(
60+
code: TokenLauncherErrorCode,
61+
message: string,
62+
context: Omit<TokenLauncherSDKError['context'], 'source'> & { source?: 'api' | 'chain' | 'sdk' }
63+
): never {
64+
throw new TokenLauncherSDKError(code, message, {
65+
...context,
66+
source: context.source || 'sdk',
67+
});
68+
}

sdk/src/getInitialTick.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { priceToInitialTick } from './utils/tickMath'
2-
import { BigNumber, BigNumberish } from '@ethersproject/bignumber'
3-
import { parseUnits } from '@ethersproject/units'
1+
import { priceToInitialTick } from './utils/tickMath';
2+
import { BigNumber, BigNumberish } from '@ethersproject/bignumber';
3+
import { parseUnits } from '@ethersproject/units';
44

55
const TICK_SPACING = 200;
66

77
/**
8-
* Computes the initial tick given a desired token price (expressed in ETH).
9-
*
10-
* @param tokenPrice The token’s price in ETH (for example, "0.000035" or 1, 2, 0.5, etc.)
11-
* @returns The nearest valid tick.
12-
*/
13-
export function getInitialTick(tokenPrice: BigNumberish): number {
14-
const scaledPrice =
15-
typeof tokenPrice === 'string'
16-
? parseUnits(tokenPrice, 18)
17-
: BigNumber.from(tokenPrice);
18-
return priceToInitialTick(scaledPrice, TICK_SPACING);
19-
}
8+
* Computes the initial tick given a desired token price (expressed in ETH).
9+
*
10+
* @param tokenPrice The token’s price in ETH (for example, "0.000035" or 1, 2, 0.5, etc.)
11+
* @returns The nearest valid tick.
12+
*/
13+
export function getInitialTick(tokenPrice: BigNumberish): number {
14+
const scaledPrice =
15+
typeof tokenPrice === 'string' ? parseUnits(tokenPrice, 18) : BigNumber.from(tokenPrice);
16+
return priceToInitialTick(scaledPrice, TICK_SPACING);
17+
}

sdk/src/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import { GetAirdropSuggestionsResponse, GetRainbowSuperTokenResponse, GetRainbowSuperTokensResponse, LaunchTokenParams, SDKConfig, LaunchTokenResponse, LaunchTokenAndBuyParams } from './types'
2-
import { launchRainbowSuperToken, launchRainbowSuperTokenAndBuy } from './launchToken'
3-
import { getAirdropSuggestions, getRainbowSuperTokenByUri, getRainbowSuperTokens } from './api'
1+
import {
2+
GetAirdropSuggestionsResponse,
3+
GetRainbowSuperTokenResponse,
4+
GetRainbowSuperTokensResponse,
5+
LaunchTokenParams,
6+
SDKConfig,
7+
LaunchTokenResponse,
8+
LaunchTokenAndBuyParams,
9+
} from './types';
10+
import { launchRainbowSuperToken, launchRainbowSuperTokenAndBuy } from './launchToken';
11+
import { getAirdropSuggestions, getRainbowSuperTokenByUri, getRainbowSuperTokens } from './api';
412
import { BigNumber } from '@ethersproject/bignumber';
513
import { getInitialTick } from './getInitialTick';
614

@@ -31,7 +39,9 @@ class TokenLauncherSDK {
3139
return launchRainbowSuperToken(params, this.config);
3240
}
3341

34-
public async launchTokenAndBuy(params: LaunchTokenAndBuyParams): Promise<LaunchTokenResponse | undefined> {
42+
public async launchTokenAndBuy(
43+
params: LaunchTokenAndBuyParams
44+
): Promise<LaunchTokenResponse | undefined> {
3545
return launchRainbowSuperTokenAndBuy(params, this.config);
3646
}
3747

@@ -49,10 +59,10 @@ class TokenLauncherSDK {
4959
}
5060

5161
// Export singleton instance
52-
export const TokenLauncher = TokenLauncherSDK.getInstance()
62+
export const TokenLauncher = TokenLauncherSDK.getInstance();
5363

5464
// Export types
55-
export type {
65+
export {
5666
TokenMetadata,
5767
AirdropMetadata,
5868
GetAirdropSuggestionsResponse,
@@ -68,7 +78,4 @@ export type {
6878
SDKConfig,
6979
} from './types';
7080

71-
export {
72-
TokenLauncherErrorCode,
73-
TokenLauncherSDKError,
74-
} from './errors';
81+
export { TokenLauncherErrorCode, TokenLauncherSDKError } from './errors';

0 commit comments

Comments
 (0)