Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
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 :
(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 ?