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

Optimized v2 oracle implementation [SC-1132] #128

Merged
merged 5 commits into from
Apr 17, 2024
Merged

Optimized v2 oracle implementation [SC-1132] #128

merged 5 commits into from
Apr 17, 2024

Conversation

simplyoptimistic
Copy link
Contributor

before:
gasUsed VelodromeV2Oracle WETH -> USDC 160768
gasUsed VelodromeV2Oracle USDC -> WETH 160928
gasUsed VelodromeV2Oracle WETH -> OP -> USDC 267972

after:
gasUsed VelodromeV2Oracle WETH -> USDC 50244
gasUsed VelodromeV2Oracle USDC -> WETH 50313
gasUsed VelodromeV2Oracle WETH -> OP -> USDC 75466

Achieved by:

  • Not iterating through the factory registry (different pool types require different oracles).
  • Generate pool address without external call.
  • Fetch reserves directly from pool, without additional external call to router.

@simplyoptimistic simplyoptimistic changed the title refactor: optimized v2 oracle implementation Optimized v2 oracle implementation Apr 4, 2024
@zZoMROT zZoMROT changed the title Optimized v2 oracle implementation Optimized v2 oracle implementation [SC-1132] Apr 9, 2024
@zZoMROT
Copy link
Contributor

zZoMROT commented Apr 17, 2024

// ✔ OffchainOracle with 1 connector, WETH -> USDC price
gasUsed offchainOracle current version 196073
gasUsed offchainOracle new version 192270 // diff oracles for diff factories
gasUsed offchainOracle new version 183686 // 1 oracle
gasUsed offchainOracle new version 164376 // 1 oracle w/o Slipstream factory

// ✔ OffchainOracle with 2 connector, WETH -> USDC price
gasUsed offchainOracle current version 419621
gasUsed offchainOracle new version 398382 // diff oracles for diff factories
gasUsed offchainOracle new version 386564 // 1 oracle
gasUsed offchainOracle new version 328625 // 1 oracle w/o Slipstream factory

@zZoMROT
Copy link
Contributor

zZoMROT commented Apr 17, 2024

Good point! 👍
I've tweaked your idea a bit to enhance its functionality even further.
Thank you for your contribution to improving the service!

@zZoMROT zZoMROT merged commit 12fd543 into 1inch:master Apr 17, 2024
1 of 5 checks passed
@zZoMROT
Copy link
Contributor

zZoMROT commented Apr 17, 2024

Before deploying the new oracle, I noticed that one of the factories is the first Velodrome Finance, and the other is also a fork of Solidly. This indicates that the oracle for the factory pool_factory does not require a separate oracle; instead, we can reuse the SolidlyOracle, which turns out to be more cost-effective:

gasUsed offchainOracleNew (1 connector) WETH -> USDC 98666
gasUsed offchainOracleNew (2 connector) WETH -> USDC 157936

Check PR

@simplyoptimistic simplyoptimistic deleted the refactor/optimize-velodrome-oracle branch April 17, 2024 23:02
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.

2 participants