Skip to content

Commit

Permalink
Polygon support (#32)
Browse files Browse the repository at this point in the history
* adding polygon tests

* add axios retry
  • Loading branch information
snreynolds authored Dec 23, 2021
1 parent d0c5787 commit c99677a
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 56 deletions.
5 changes: 5 additions & 0 deletions lib/cron/cache-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const chainProtocols = [
chainId: ChainId.ARBITRUM_ONE,
provider: new V3SubgraphProvider(ChainId.ARBITRUM_ONE, 3, 90000),
},
{
protocol: Protocol.V3,
chainId: ChainId.POLYGON,
provider: new V3SubgraphProvider(ChainId.POLYGON, 3, 90000),
},
// Currently there is no working V3 subgraph for Gorli, Kovan, Optimism, Optimism Kovan, Arbitrum Rinkeby, so we use static providers.
// V2.
{
Expand Down
2 changes: 2 additions & 0 deletions lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const SUPPORTED_CHAINS: ChainId[] = [
ChainId.OPTIMISTIC_KOVAN,
ChainId.ARBITRUM_ONE,
ChainId.ARBITRUM_RINKEBY,
ChainId.POLYGON,
ChainId.POLYGON_MUMBAI,
// leaving goerli out for now
]
const DEFAULT_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'
Expand Down
19 changes: 15 additions & 4 deletions lib/handlers/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Currency, Ether } from '@uniswap/sdk-core'
import { AlphaRouterConfig, ChainId, ITokenListProvider, ITokenProvider } from '@uniswap/smart-order-router'
import { Currency } from '@uniswap/sdk-core'
import {
AlphaRouterConfig,
ChainId,
ITokenListProvider,
ITokenProvider,
NativeCurrencyName,
nativeOnChain,
} from '@uniswap/smart-order-router'
import Logger from 'bunyan'

export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (chainId: ChainId): AlphaRouterConfig => {
Expand Down Expand Up @@ -95,8 +102,12 @@ export async function tokenStringToCurrency(

let token: Currency | undefined = undefined

if (tokenRaw == 'ETH' || tokenRaw.toLowerCase() == '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
token = Ether.onChain(chainId)
if (
tokenRaw == NativeCurrencyName.ETHER ||
tokenRaw == NativeCurrencyName.MATIC ||
tokenRaw.toLowerCase() == '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
) {
token = nativeOnChain(chainId)
} else if (isAddress(tokenRaw)) {
token = await tokenListProvider.getTokenByAddress(tokenRaw)
}
Expand Down
114 changes: 93 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"axios-retry": "^3.2.4",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
Expand Down Expand Up @@ -90,7 +91,7 @@
"@types/stats-lite": "^2.2.0",
"@uniswap/router-sdk": "^1.0.1",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/smart-order-router": "^2.5.4",
"@uniswap/smart-order-router": "^2.5.7",
"@uniswap/token-lists": "^1.0.0-beta.24",
"@uniswap/v3-periphery": "^1.1.0",
"@uniswap/v3-sdk": "^3.7.1",
Expand Down
Loading

0 comments on commit c99677a

Please sign in to comment.