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

token list provider fallback #367

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
use separate error log
  • Loading branch information
jsy1218 committed Sep 13, 2023
commit fe27b693caddfbe9fbe3af6919986b77c7b8802b
20 changes: 10 additions & 10 deletions lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export const SUPPORTED_CHAINS: ChainId[] = [
ChainId.BASE,
]
const DEFAULT_TOKEN_LIST = 'https://cloudflare-ipfs.com/ipns/tokens.uniswap.org'
const FALLBACK_DEFAULT_TOKEN_LIST_URLS = ['https://ipfs.io/ipfs/QmXd7oP5j6dv25YtCjQs17GsSoJxnG2BmHSUiSoQGA7kPN', 'https://gateway.ipfs.io/ipns/tokens.uniswap.org']
const FALLBACK_DEFAULT_TOKEN_LIST_URLS = [
'https://ipfs.io/ipfs/QmXd7oP5j6dv25YtCjQs17GsSoJxnG2BmHSUiSoQGA7kPN',
'https://gateway.ipfs.io/ipns/tokens.uniswap.org',
]

export interface RequestInjected<Router> extends BaseRInj {
chainId: ChainId
Expand Down Expand Up @@ -213,30 +216,27 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
`AWS Token List Provider failed with ${DEFAULT_TOKEN_LIST}, trying ${FALLBACK_DEFAULT_TOKEN_LIST_URLS}`
)

let tokenListProvider: ITokenListProvider & ITokenProvider | undefined = undefined
let errors = []
let tokenListProvider: (ITokenListProvider & ITokenProvider) | undefined = undefined
for (const fallbackUrl of FALLBACK_DEFAULT_TOKEN_LIST_URLS) {
if (tokenListProvider) {
break;
break
}

try {
tokenListProvider = await AWSTokenListProvider.fromTokenListS3Bucket(
chainId,
TOKEN_LIST_CACHE_BUCKET!,
fallbackUrl
chainId,
TOKEN_LIST_CACHE_BUCKET!,
fallbackUrl
)
} catch (err) {
errors.push(err)
log.error({ err }, `AWS Token List Provider failed with ${FALLBACK_DEFAULT_TOKEN_LIST_URLS}`)
}
}

if (!tokenListProvider) {
// we intentionally don't catch here, because the token-list provider
// either fetch the default token list,
// or the entire routing lambda lifecycle fails
log.error(`AWS Token List Provider failed with ${FALLBACK_DEFAULT_TOKEN_LIST_URLS} with errors ${errors}`)

throw new Error('Failed to build token list provider')
} else {
return tokenListProvider
Expand Down
Loading