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

[WEB-1138-183] Feat: add multicall to getNormalizedValueUsdc #183

Closed
wants to merge 8 commits into from

Conversation

pmdaly
Copy link
Contributor

@pmdaly pmdaly commented Jan 10, 2022

Addressing #57 (comment), Support multicall getNormalizedValueUsdc for optimization

Quick solution that allows the return of normalized usdc values for a list of tokens and amounts.

.getNormalizedValueUsdc(...) for single calls
.getNormalizedValuesUsdc(...) for batch calls

the calls are made offchain so if the intention was to use a multicall-like contract this will need to be revised. Just posting a quick solution for feedback.

@yearn-linear-gh-sync yearn-linear-gh-sync bot changed the title Feat: add multicall to getNormalizedValueUsdc [WEB-1138-183] Feat: add multicall to getNormalizedValueUsdc Jan 10, 2022
@yearn-linear-gh-sync
Copy link

Linear reply from Fox Crypto:
@pmdaly <assignee

Copy link
Contributor

@jstashh jstashh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for kicking off the unit tests ❤️

let tokenAddress: string;
beforeAll(async () => {
const chainId = 1;
const rpcUrl = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does using process.env.WEB3_PROVIDER work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. I'll add it.

* @param overrides
* @returns Usdc exchange rate (6 decimals)
*/
async getNormalizedValuesUsdc(tokens: Address[], amounts: Integer[], overrides: CallOverrides = {}): Promise<Usdc[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, and is a useful addition. I think the issue is referring to using an on-chain multicall contract so calls to the web3 provider can be reduced if you wanted to have a go at implementing that and using it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll give it a shot and post updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on integrating https://github.com/indexed-finance/multicall and currently working out some issues in how the library handles inputs. Is this what you had in mind?

Copy link
Contributor Author

@pmdaly pmdaly Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstashh multicall should work now with the indexed finance multicall lib, still need to figure out how to use the CallOverrides, getting the following error

types/values length mismatch (count={"types":2,"values":3}, value={"types":[{"name":null,"type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":null,"type":"uint256","indexed":null,"compon
ents":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"values":["0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e","1000000000000000000",{}]}, code=INVALID_ARGUMENT, version=abi/5.5.0)

once this is resolved, I can lint/prettify and add more comprehensive tests.

Also, not sure why I can't send the this.contract.abi directly to the multicall as it's an interface. ContractInterface vs Interface. I've resorted to directly creating an interface out of the exported abi. I don't think this is the correct way but it works for now. Can update based on feedback.

Copy link
Collaborator

@FiboApe FiboApe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good integration tests!, left a few comments

async getNormalizedValuesUsdc(tokens: Address[], amounts: Integer[], overrides: CallOverrides = {}): Promise<any> {
const multi = new MultiCall(this.ctx.provider.read);
const inputs = [];
for (var i = 0, size = tokens.length; i < size; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use let instead of var.

Just for readability you could do i < tokens.length, there is no need to set size before it since you are not going to be modifying tokens

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add these changes. Just picking up Typescript so I appreciate the pointers. I think this general approach will be scrapped in favor of adding a multicall method to the associated lens contract.

[amount, amount]
);
console.log(normValues);
expect(+normValues[0]).toBeGreaterThan(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hack to convert strings to intergers, just to be consistent and more reliable we should do parseInt(normvalues[0], 10), so we always specify the base into which the string should be converted to

@@ -39,15 +39,18 @@
"eslint-plugin-simple-import-sort": "6",
"events": "3.3.0",
"size-limit": "7.0.4",
"ts-node": "^10.4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we try to keep dependencies versions fixed @jstashh ?

I know it is a requirement for yearn-finance-v3 repo

@FiboApe
Copy link
Collaborator

FiboApe commented Feb 8, 2022

Closing since this will be implemented on the lens contracts instead

@FiboApe FiboApe closed this Feb 8, 2022
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