-
Notifications
You must be signed in to change notification settings - Fork 38
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
asynchronously fetch token data #872
Conversation
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.
Looks good!
This would be a perfect candidate to test out batch web3 requests at some point.
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Yes! I had forgotten. Maybe I should do that now! |
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.
The previous implementation was naive and this one is much much faster!
Would be awesome to quantify how much faster - maybe just using the unix time
tool before and after to get an idea.
Old Script: New Script: Appears to be about 22x faster. This was executed with the following script: import { fetchTokenInfoFromExchange } from "../src/fee_token_liquidity";
import { getBatchExchange } from "./util";
module.exports = async (callback: Truffle.ScriptCallback) => {
try {
const exchange = await getBatchExchange(artifacts);
const numTokens = (await exchange.numTokens()).toNumber();
const tokens = Array(numTokens)
.fill(0)
.map((_, i) => i);
console.log(`Fetching info for ${numTokens} tokens`);
console.time("Execution Time");
await fetchTokenInfoFromExchange(exchange, tokens, artifacts);
console.timeEnd("Execution Time");
callback();
} catch (error) {
callback(error);
}
}; using npx truffle exec build/common/scripts/test_script.js --network rinkeby |
Awesome speed improvement! |
The previous implementation was naive and this one is much much faster!
closes #868 (Note that it was suggested to use web3-BatchRequest, but this is efficient as is and the web3 option seems to require passing around additional artifacts).
Test Plan
Can't really be tested without a wrapper script. The only script using this within the project is
scripts/ensure_owl_liquidity.ts