Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unuse default token list uniswap #29

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cron/cache-token-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { S3 } from 'aws-sdk'
import axios from 'axios'
import { default as bunyan, default as Logger } from 'bunyan'

// TEMP no need default token list
const TOKEN_LISTS: any = []

const handler: ScheduledHandler = async (event: EventBridgeEvent<string, void>) => {
Expand Down
8 changes: 3 additions & 5 deletions lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ import { GraphQLTokenFeeFetcher } from '../graphql/graphql-token-fee-fetcher'
import { UniGraphQLProvider } from '../graphql/graphql-provider'
import { TrafficSwitcherITokenFeeFetcher } from '../util/traffic-switch/traffic-switcher-i-token-fee-fetcher'
import { OnChainTokenFeeFetcher } from '@sky-mavis/smart-order-router/dist/main/providers/token-fee-fetcher'

const DEFAULT_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'

export interface RequestInjected<Router> extends BaseRInj {
chainId: ChainId
metric: IMetric
Expand Down Expand Up @@ -123,7 +120,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
const {
POOL_CACHE_BUCKET_3,
POOL_CACHE_GZIP_KEY,
TOKEN_LIST_CACHE_BUCKET,
// TOKEN_LIST_CACHE_BUCKET,
ROUTES_TABLE_NAME,
ROUTES_CACHING_REQUEST_FLAG_TABLE_NAME,
CACHED_ROUTES_TABLE_NAME,
Expand Down Expand Up @@ -233,7 +230,8 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<

const [tokenListProvider, blockedTokenListProvider, v3SubgraphProvider, v2SubgraphProvider] =
await Promise.all([
AWSTokenListProvider.fromTokenListS3Bucket(chainId, TOKEN_LIST_CACHE_BUCKET!, DEFAULT_TOKEN_LIST),
// AWSTokenListProvider.fromTokenListS3Bucket(chainId, TOKEN_LIST_CACHE_BUCKET!, DEFAULT_TOKEN_LIST),
AWSTokenListProvider.fromTokenListS3Bucket(chainId),
CachingTokenListProvider.fromTokenList(chainId, UNSUPPORTED_TOKEN_LIST as TokenList, blockedTokenCache),
(async () => {
try {
Expand Down
80 changes: 51 additions & 29 deletions lib/handlers/router-entities/aws-token-list-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,74 @@ import {
CachingTokenListProvider,
ITokenListProvider,
ITokenProvider,
log,
NodeJSCache,
} from '@sky-mavis/smart-order-router'
import { TokenList } from '@uniswap/token-lists'
import S3 from 'aws-sdk/clients/s3'
import NodeCache from 'node-cache'

const TOKEN_LIST_CACHE = new NodeCache({ stdTTL: 600, useClones: false })
// const TOKEN_LIST_CACHE = new NodeCache({ stdTTL: 600, useClones: false })

const DEFAULT_TEMPLATE = {
"name": "Uniswap Labs Default",
"timestamp": "2024-11-18T15:56:01.725Z",
"version": {
"major": 12,
"minor": 26,
"patch": 0
},
"tags": {},
"logoURI": "ipfs://QmNa8mQkrNKp1WEEeGjFezDmDeodkWRevGFN8JCV7b4Xir",
"keywords": [
"uniswap",
"default"
],
"tokens": [
{
"chainId": 1,
"address": "0x3E5A19c91266aD8cE2477B91585d1856B84062dF",
"name": "Ancient8",
"symbol": "A8",
"decimals": 18,
"logoURI": "https://assets.coingecko.com/coins/images/39170/standard/A8_Token-04_200x200.png?1720798300"
},
]
}

export class AWSTokenListProvider extends CachingTokenListProvider {
public static async fromTokenListS3Bucket(
chainId: ChainId,
bucket: string,
tokenListURI: string
// bucket: string,
// tokenListURI: string
): Promise<ITokenListProvider & ITokenProvider> {
const s3 = new S3({ correctClockSkew: true, maxRetries: 3 })

const cachedTokenList = TOKEN_LIST_CACHE.get<TokenList>(tokenListURI)

// const s3 = new S3({ correctClockSkew: true, maxRetries: 3 })
// const cachedTokenList = TOKEN_LIST_CACHE.get<TokenList>(tokenListURI)
const tokenCache = new NodeCache({ stdTTL: 360, useClones: false })
return super.fromTokenList(chainId, DEFAULT_TEMPLATE, new NodeJSCache(tokenCache))

if (cachedTokenList) {
log.info(`Found token lists for ${tokenListURI} in local cache`)
return super.fromTokenList(chainId, cachedTokenList, new NodeJSCache(tokenCache))
}
// if (cachedTokenList) {
// log.info(`Found token lists for ${tokenListURI} in local cache`)
// return super.fromTokenList(chainId, DEFAULT_TEMPLATE, new NodeJSCache(tokenCache))
// }

try {
log.info(`Getting tokenLists from s3.`)
const tokenListResult = await s3.getObject({ Key: encodeURIComponent(tokenListURI), Bucket: bucket }).promise()
// try {
// log.info(`Getting tokenLists from s3.`)
// const tokenListResult = await s3.getObject({ Key: encodeURIComponent(tokenListURI), Bucket: bucket }).promise()

const { Body: tokenListBuffer } = tokenListResult
// const { Body: tokenListBuffer } = tokenListResult

if (!tokenListBuffer) {
return super.fromTokenListURI(chainId, tokenListURI, new NodeJSCache(tokenCache))
}
// if (!tokenListBuffer) {
// return super.fromTokenListURI(chainId, tokenListURI, new NodeJSCache(tokenCache))
// }

const tokenList = JSON.parse(tokenListBuffer.toString('utf-8')) as TokenList
// const tokenList = JSON.parse(tokenListBuffer.toString('utf-8')) as TokenList

log.info(`Got both tokenLists from s3. ${tokenList.tokens.length} tokens in main list.`)
// log.info(`Got both tokenLists from s3. ${tokenList.tokens.length} tokens in main list.`)

TOKEN_LIST_CACHE.set<TokenList>(tokenListURI, tokenList)
// TOKEN_LIST_CACHE.set<TokenList>(tokenListURI, tokenList)

return new CachingTokenListProvider(chainId, tokenList, new NodeJSCache(tokenCache))
} catch (err) {
log.info({ err }, `Failed to get tokenLists from s3.`)
return super.fromTokenListURI(chainId, tokenListURI, new NodeJSCache(tokenCache))
}
// return new CachingTokenListProvider(chainId, tokenList, new NodeJSCache(tokenCache))
// } catch (err) {
// log.info({ err }, `Failed to get tokenLists from s3.`)
// return super.fromTokenListURI(chainId, tokenListURI, new NodeJSCache(tokenCache))
// }
}
}
Loading