Skip to content

Commit

Permalink
fix: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
just-toby committed Aug 3, 2023
1 parent e57f045 commit 33f0a16
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"editor.defaultFormatter": "vscode.json-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"@types/lodash": "^4.14.179",
"@uniswap/token-lists": "^1.0.0-beta.33",
"dts-cli": "^1.4.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^7.0.4",
"size-limit": "^7.0.8",
"tslib": "^2.3.1",
"typescript": "^4.5.5"
"typescript": "^5.1.6",
"yarn-deduplicate": "^6.0.2"
},
"engines": {
"node": ">=16"
Expand Down Expand Up @@ -44,7 +46,8 @@
"prepare": "dts build",
"size": "size-limit",
"start": "dts watch",
"test": "dts test"
"test": "dts test",
"deduplicate": "yarn-deduplicate --strategy=highest"
},
"size-limit": [
{
Expand All @@ -65,7 +68,7 @@
"dotenv": "^16.0.1",
"ethers": "^5.6.5",
"lodash": "^4.17.21",
"prettier": "^2.7.1",
"prettier": "^3.0.1",
"web3": "^1.7.3"
}
}
13 changes: 6 additions & 7 deletions src/arbitrum/instantiate_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { providers } from 'ethers'
const networkID = 42161

const l2Rpc = (chainId: number) => {
if (chainId === 42161) return 'https://arb1.arbitrum.io/rpc';
else if (chainId === 421611) return 'https://rinkeby.arbitrum.io/rpc';
else if (chainId === 42170) return 'https://nova.arbitrum.io/rpc';
else if (chainId === 421613)
return 'https://goerli-rollup.arbitrum.io/rpc';
throw new Error('No L2 RPC detected');
};
if (chainId === 42161) return 'https://arb1.arbitrum.io/rpc'
else if (chainId === 421611) return 'https://rinkeby.arbitrum.io/rpc'
else if (chainId === 42170) return 'https://nova.arbitrum.io/rpc'
else if (chainId === 421613) return 'https://goerli-rollup.arbitrum.io/rpc'
throw new Error('No L2 RPC detected')
}

// ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/instantiate_bridge.ts
export const getNetworkConfig = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/constants/chainId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export enum ChainId {
AVALANCHE = 43114,

BASE = 8453,
BASE_GOERLI = 84531
BASE_GOERLI = 84531,
}
6 changes: 3 additions & 3 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export const DAI_BASE = new Token(
'0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb',
18,
'DAI',
'Dai Stablecoin',
'Dai Stablecoin'
)

export const DAI_BASE_GOERLI = new Token(
ChainId.BASE_GOERLI,
"0x174956bDfbCEb6e53089297cce4fE2825E58d92C",
'0x174956bDfbCEb6e53089297cce4fE2825E58d92C',
18,
'DAI',
'Dai Stablecoin',
'Dai Stablecoin'
)

export const USDT = new Token(
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Tokens: Partial<Record<ChainId, Record<string, TokenInfo>>> = {
DAI: tokenToTokenInfo(DAI_OPTIMISM),
COINBASE_WRAPPED_STAKED_ETH: tokenToTokenInfo(
COINBASE_WRAPPED_STAKED_ETH_OPTIMISM
)
),
},
[ChainId.BNB]: {
DAI: tokenToTokenInfo(DAI_BNB),
Expand All @@ -52,7 +52,7 @@ export const Tokens: Partial<Record<ChainId, Record<string, TokenInfo>>> = {
DAI: tokenToTokenInfo(DAI_BASE),
COINBASE_WRAPPED_STAKED_ETH: tokenToTokenInfo(
COINBASE_WRAPPED_STAKED_ETH_BASE
)
),
},
[ChainId.BASE_GOERLI]: {
DAI: tokenToTokenInfo(DAI_BASE_GOERLI),
Expand Down
27 changes: 12 additions & 15 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ it('outputs base goerli list correctly', async () => {
})

it('outputs base list correctly', async () => {
const tokenList = await chainifyTokenList(
[ChainId.BASE],
sampleL1TokenList_3
)
const tokenList = await chainifyTokenList([ChainId.BASE], sampleL1TokenList_3)
expect(tokenList).toBeDefined()
expect(tokenList?.version).toEqual(baseSampleTokenList_3.version)
expect(
Expand Down Expand Up @@ -309,7 +306,7 @@ describe(chainify, () => {
},
[ChainId.BASE_GOERLI]: {
tokenAddress: DAI_BASE_GOERLI.address,
}
},
},
},
},
Expand Down Expand Up @@ -350,9 +347,9 @@ describe(chainify, () => {
bridgeInfo: {
[ChainId.MAINNET]: {
tokenAddress: DAI.address,
}
}
}
},
},
},
},
{
...Tokens[ChainId.ARBITRUM_ONE]!.DAI,
Expand Down Expand Up @@ -385,10 +382,10 @@ describe(chainify, () => {
bridgeInfo: {
[ChainId.MAINNET]: {
tokenAddress: DAI.address,
}
}
}
}
},
},
},
},
])
})

Expand Down Expand Up @@ -433,9 +430,9 @@ describe(chainify, () => {
bridgeInfo: {
[ChainId.MAINNET]: {
tokenAddress: COINBASE_WRAPPED_STAKED_ETH.address,
}
}
}
},
},
},
},
{
...Tokens[ChainId.ARBITRUM_ONE]!.COINBASE_WRAPPED_STAKED_ETH,
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export function mergeTokenLists(
}

const merged = merge(group[0], group[1])
if (merged.extensions?.bridgeInfo) {
if (
merged.extensions?.bridgeInfo &&
typeof merged.extensions.bridgeInfo === 'object'
) {
// remove reference to self-chain from merge
delete merged.extensions.bridgeInfo[merged.chainId]
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/BaseGoerliMappingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class BaseGoerliMappingProvider implements MappingProvider {

let allTokens = await getTokenList(baseGoerliTokenListURL)

let opTokenId_baseGoerliAddressMap = {}
let opTokenId_baseGoerliAddressMap: Record<string, string> = {}
allTokens.tokens.forEach((token) => {
if (token.chainId === ChainId.BASE_GOERLI) {
if (typeof token.extensions?.opTokenId === 'string') {
Expand Down
5 changes: 2 additions & 3 deletions src/providers/BaseMappingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ export class BaseMappingProvider implements MappingProvider {

let allTokens = await getTokenList(baseGoerliTokenListURL)

let opTokenId_baseAddressMap = {}
let opTokenId_baseAddressMap: Record<string, string> = {}
allTokens.tokens.forEach((token) => {
if (token.chainId === ChainId.BASE) {
if (typeof token.extensions?.opTokenId === 'string') {
opTokenId_baseAddressMap[token.extensions.opTokenId] =
token.address
opTokenId_baseAddressMap[token.extensions.opTokenId] = token.address
}
}
})
Expand Down
5 changes: 2 additions & 3 deletions src/providers/OptimismMappingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ export class OptimismMappingProvider implements MappingProvider {

let allTokens = await getTokenList(optimismTokenListURL)

let opTokenId_baseAddressMap = {}
let opTokenId_baseAddressMap: Record<string, string> = {}
allTokens.tokens.forEach((token) => {
if (token.chainId === ChainId.OPTIMISM) {
if (typeof token.extensions?.opTokenId === 'string') {
opTokenId_baseAddressMap[token.extensions.opTokenId] =
token.address
opTokenId_baseAddressMap[token.extensions.opTokenId] = token.address
}
}
})
Expand Down
12 changes: 9 additions & 3 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function buildList(
} = {}
const l2MappingExtension = {
extensions: {
bridgeInfo: {},
bridgeInfo: {} as any,
},
}
// build out the extensions.bridgeInfo data containing mappings for each L2 chain
Expand Down Expand Up @@ -201,8 +201,14 @@ async function getChildTokenDetails(
childTokenAddress: string | undefined
decimals?: number | undefined
}> {
const existingMapping: undefined | string =
l1Token?.extensions?.bridgeInfo?.[chainId]?.tokenAddress
const bridgeInfo = l1Token?.extensions?.bridgeInfo
let existingMapping: undefined | string
if (bridgeInfo && typeof bridgeInfo === 'object') {
const bridgeInfoForChain = bridgeInfo[chainId]
if (bridgeInfoForChain && typeof bridgeInfoForChain === 'object') {
existingMapping = bridgeInfoForChain.tokenAddress as string
}
}
// use the externally fetched mappings if manual entry doesn't exist for the token/chain mapping
// and the given chain is supported for fetching mappings
if (
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function getRpcUrl(chainId: ChainId): string {
case ChainId.AVALANCHE:
return 'https://api.avax.network/ext/bc/C/rpc'
case ChainId.BASE:
return "https://mainnet.base.org"
return 'https://mainnet.base.org'
case ChainId.BASE_GOERLI:
return 'https://goerli.base.org'
default:
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"suppressImplicitAnyIndexErrors": true
}
}
}
Loading

0 comments on commit 33f0a16

Please sign in to comment.