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

feature: introduce a ITokenFeeFetcher fallback #603

Closed
wants to merge 2 commits into from

Conversation

xrsv
Copy link
Contributor

@xrsv xrsv commented Jun 12, 2024

  • 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 fees

  • What 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

@xrsv xrsv requested a review from a team as a code owner June 12, 2024 20:11
@graphite-app graphite-app bot requested review from cgkol and mikeki June 12, 2024 20:13
@xrsv xrsv requested a review from jsy1218 June 12, 2024 20:14
Copy link

graphite-app bot commented Jun 12, 2024

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.

Comment on lines +127 to +150
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`
);
}
}
}

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

@jsy1218 jsy1218 Jun 13, 2024

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:

  1. beginning by shadow calling GQL token fetcher without affecting online path
  2. compare the results between GQL token fetcher and direct on-chain token fetcher
  3. gradually switching from direct on-chain token fetcher to GQL token fetcher
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants