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

Fetch pools historical #413

Closed
wants to merge 13 commits into from

Conversation

alfulinku
Copy link

@alfulinku alfulinku commented Aug 24, 2023

EDIT: I think I found de cleaner way of doing this directly in the SDK: balancer/balancer-sdk#525

Hello Balancer team,

I wondered if I could use your offline SOR/SDK to fetch data about the balancer protocol but historically (like "what was the best price I could get on WETH/USDC at block 17 000 000") and was left without a solution so I tried to add the feature to the SOR.

I don't really understand how to work with the SDK, I have the feeling that the files that need to implements the changes are in the SDK repository (subgraphPoolDataService.ts and onChainData.ts) but because it all starts by creating a SOR object from this repository, I guess the feature must come from here first?

Anyway I added the historical capability here and created a small test file very similar to test\testScripts\swapExample.ts, the new one is: test\testScripts\swapHistoricalExample.ts

To run this test file, you need to set your env variable RPC_URL_MAINNET to an archive node RPC (my infura works well)

The idea in that file is that I first instantiate a sor object using fetchPools like this:

const targetBlockNumber = 17_000_000;
await sor.fetchPools(undefined, undefined, targetBlockNumber);

and another instance of sor using the basic fetchPool call
await sorNow.fetchPools();

and I call the getSwaps() function with both of these sor objects to see the difference, outputing these two lines in the console:

1 WETH is 1664.098257 USDC using the most recent data
1 WETH was 1862.210233 USDC at block 17000000

Etherscan gives me 1864 usd per ETH at this block so this looks like a win.

Again, I think this is only the first step, the real implementation will have to be done on the sdk repository. And it would be very much simpler to use the SDK like I do for another project :

const balancer = new BalancerSDK({
        network: 100, // gnosis
        rpcUrl: rpcUrl,
    });

const swapsService = balancer.swaps; // Swaps module
await swapsService.fetchPools();

(but with the possibility to give the blockNumber to the fetchPools function)

Using the sor directly seems harder as it would mean having to import the SubgraphPoolDataService and getOnChainBalances on my project (at least).

What do you think? Is it a feature that could be usefull and added to the SOR/SDK ?

@alfulinku alfulinku marked this pull request as ready for review August 24, 2023 12:36
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