Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Issue 8: Vault and Strategy Holdings #30

Merged
2 commits merged into from
Dec 7, 2020
Merged

Issue 8: Vault and Strategy Holdings #30

2 commits merged into from
Dec 7, 2020

Conversation

miguel567
Copy link
Collaborator

Issue: #8

  • Added ./abi folder as a volume to docker-compose.yml file to ease development.
  • calculated Vault holdings and Strategy holdings and Pools Balance (virtualPrice * Totalsupply)
  • Storing price_usd from coingecko for vault's want tokens.
  • Created a new table called holdings.

I'm following the approach from dudesahn as defined here: hackmd.io/@dudesahn/BkxKfTzqw
TODO: We believe we are missing to calculate the pool balance of yWBTC token.
This is the pre-requirement for calculating TVL (my next step).

@miguel567 miguel567 closed this Nov 22, 2020
@miguel567
Copy link
Collaborator Author

I'm breaking APY/SAVE. need to fix it first.

@miguel567 miguel567 deleted the 8 branch November 22, 2020 23:36
@miguel567 miguel567 restored the 8 branch November 22, 2020 23:36
@miguel567 miguel567 reopened this Nov 23, 2020
@miguel567
Copy link
Collaborator Author

fixed the APY save endpoint which was broken before and removed ethereum-blocks-by-date.js file as this is not needed.

@miguel567 miguel567 closed this Nov 23, 2020
@miguel567 miguel567 reopened this Nov 23, 2020
@@ -276,7 +276,7 @@ const readVault = async (vault) => {
return data;
};

module.exports.handler = async () => {
const handler = async () => {
Copy link

Choose a reason for hiding this comment

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

why change this? was it broken?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the end of the file I have set:
module.exports = { handler, getVirtualPrice };

The reason is that I'm reusing the same getVirtualPrice function in : https://github.com/miguel567/yearn-api/blob/91c1696f5f5fa309126883fd17a51ee964a1448b/services/vaults/holdings/save/getHoldings.js#L94

so I had to modify the exports module to include both functions.

README.md Outdated

## Stages

- Currently four stages are available
Copy link

Choose a reason for hiding this comment

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

what is intention behind removing this README section?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally believe this is a mistake. Shoud I fix it and push again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

solved

}
try{
const holdings= await getHoldings(vault);
const priceFeed = await axios.get('https://api.coingecko.com/api/v3/coins/' + vault.price_id);
Copy link

Choose a reason for hiding this comment

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

can we get price on-chain from uniswap instead perhaps? this way we don't have to maintain the API

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I need to investigate how to perform that. Any guidance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we do this on an improvement ticket? Unless it is a blocker, I could make the other improvements easily, deliver the TVL endpoint and then focus on changing the price feed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the "earn" products: yWBTC, yCRV and ybCRV are using getVirtualPrice = on-chain price.
Rest of tokens are using coingecko. I would merge as it is and create a new issue to move all pricing infro to on-chain using chainlink, for example. issue: #34

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be good, we can just use Andre's keep3r price oracles, which already have all of the pairs we need. I updated with the relevant info on issue #34



module.exports = [
{
Copy link

Choose a reason for hiding this comment

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

Can we get vaults from vaults endpoint instead? The vaults endpoint pulls from the vault registry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yes, I saw you improved that part, I think I can do this easily.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Icannot use vaults from DB as the ABI is not stored. I could use:
const fetchAbi = async (address) => { const url =https://api.etherscan.io/api?module=contract&action=getabi&address=${address}&apikey=${etherscanApiKey}`;
const resp = await fetch(url).then((res) => res.json());
const abi = JSON.parse(resp.result);
await delay(delayTime);
return abi;
};
`
from services/vaults/holdings/save/handler.js, but we would rely on etherscan API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed in discord this cannot be done for now. We cannot fetch the ABI on-chain. Also, the services/vaults/holdings/save/vaults.js file is defining where the ABI is coming from. Also I cannot remove the vault.js file as, for instance the aLink and Link strategies have 6 decimals and there is no on-chain "decimals" method for these strategies for me to fetch the correct decimals. So for now we need to rely on the code in the files and not on-chain data :S

require('dotenv').config();
const _ = require('lodash');
const dynamodb = require('../../../utils/dynamoDb');
const fetch = require('node-fetch');
const Web3 = require('web3');
const yRegistryAbi = require('../../../abi/yRegistry.json');
const delay = require('delay');

const db = dynamodb.doc;
Copy link

Choose a reason for hiding this comment

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

nice fix, i spotted this as well

const vaultContract = new web3.eth.Contract(vault.vaultContractABI, vault.vaultContractAddress);
const vaultHoldings = await vaultContract.methods.balance().call() / Math.pow(1,vault.decimals);
const strategyHoldings = await strategyContract.methods.balanceOf().call() / Math.pow(1,vault.decimals);
/* console.log(holdings); */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove commented out console.log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in the new push all the commented out code.



return holdings;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need an empty line at end of file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

Comment on lines 43 to 46




Copy link
Collaborator

Choose a reason for hiding this comment

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

Personal opinion but I think 4 blank lines here is a lot, better to have 1 or 2. Same above as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

Copy link
Collaborator

@graham-u graham-u left a comment

Choose a reason for hiding this comment

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

There are quite a few instances of commented out code that I think we should remove unless it is there for a good reason.

@miguel567
Copy link
Collaborator Author

miguel567 commented Dec 5, 2020

I've reviewed your feedback @graham-u and @x48-crypto from the previous push, please check it above.

Also I've added to this push:

FYI: I'm following Dudesahn's documented holdings calculation guide: https://hackmd.io/@dudesahn/BkxKfTzqw

@ghost ghost merged commit 5262e73 into yearn:master Dec 7, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants