-
Notifications
You must be signed in to change notification settings - Fork 452
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
feature: introduce a ITokenFeeFetcher
fallback
#603
Conversation
Graphite Automations"Request reviewers once CI passes on smart-order-router repo" took an action on this PR • (06/12/24)3 reviewers were added and 1 assignee was added to this PR based on 's automation. |
if (this.tokenFeeFetcherFallback) { | ||
// If a fallback fetcher is provided, we will use it to fetch fees for tokens that were not fetched by the primary fetcher. | ||
const addressesToFetchFeesWithFallbackFetcher = addressesToFetchFees.filter( | ||
(address) => !tokenFeeMap[address] | ||
); | ||
if (addressesToFetchFeesWithFallbackFetcher.length > 0) { | ||
try { | ||
const tokenFeeMapFromFallback = await this.tokenFeeFetcherFallback.fetchFees( | ||
addressesToFetchFeesWithFallbackFetcher, | ||
providerConfig | ||
); | ||
tokenFeeMap = { | ||
...tokenFeeMap, | ||
...tokenFeeMapFromFallback, | ||
}; | ||
} catch (err) { | ||
log.error( | ||
{ err }, | ||
`Error fetching fees for tokens ${addressesToFetchFeesWithFallbackFetcher} using fallback` | ||
); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about creating a GraphQlTokenFeeFetcherWithFallback
implementation of ITokenFeeFetcher
, and we put that in routing-api
instead of here?
That way we could avoid all changes in SOR, we just need to make sure that the tokenFeeFetcher
can be overwritten in routing-api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not a bad idea, let me do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like @mikeki 's idea. Then in routing-api, we can create a traffic switch fetcher class (similar to lib/handlers/quote/provider-migration/v3/traffic-switch-on-chain-quote-provider.ts), that can achieve:
- beginning by shadow calling GQL token fetcher without affecting online path
- compare the results between GQL token fetcher and direct on-chain token fetcher
- gradually switching from direct on-chain token fetcher to GQL token fetcher
- and the existing traffic switch implementation already guarantees that in case GQL token fetcher throws error, it will fallback to use GQL token fetcher. We will just have to tweak the implementation a bit, so that when GQL token fetcher returns 0 fee, it also fallback to direct on-chain token fetcher to try fetching the FOT fee again. Since direct on-chain token fetcher is wrapped with in-memory cache, perf penalty in those fallbacks are minimized.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feature
What is the current behavior? (You can also link to an open issue here)
We currently use one
ITokenFeeFetcher
implementation to retrieve token feesWhat is the new behavior (if this is a feature change)?
we are introducing an optional fallback
ITokenFeeFetcher
that will be used to retrieve token fee info in case primary fails, or if some tokens are not present in primary.Plan is to use primary for our graphQL provider, then fallback to onchain fetch in case anything goes wrong or missing.
Other information:
a separate PR will follow on routing-api repo