yearn / yearn-protocol

Yearn smart contracts
https://yearn.finance
GNU Affero General Public License v3.0
441 stars 212 forks source link

YRegistry.getVaultsInfo() doesn't return vault addresses #11

Closed banteg closed 3 years ago

banteg commented 4 years ago

I think it would make sense to add vault addresses to getVaultsInfo() in the next iteration of registry so it returns complete information. It also might be better to return an array of structs as opposed to unzipped arrays of different params.

Consider this example.

$ brownie console --network mainnet
Brownie v1.11.5 - Python development framework for Ethereum

No project was loaded.
Brownie environment is ready.
>>> registry = Contract.from_explorer('registry.ychad.eth')
Fetching source of 0x3eE41C098f9666ed2eA246f4D2558010e59d63A0 from api.etherscan.io...
>>> registry.getVaultsInfo()
(('0x2be5D998C95DE70D9A38b3d78e49751F10F9E88b', '0x2be5D998C95DE70D9A38b3d78e49751F10F9E88b', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080', '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080'), ('0xA64BD6C70Cb9051F6A9ba1F163Fdc07E0DfB5F84', '0x514910771AF9Ca656af840dff83E8264EcF986CA', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', '0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8', '0x0000000000085d4780B73119b644AE5ecd22b376', '0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xdAC17F958D2ee523a2206206994597C13D831ec7', '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e', '0x3B3Ac5386837Dc563660FB6a0937DFAa5924333B', '0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), ('0x25fAcA21dd2Ad7eDB3a027d543e617496820d8d6', '0x25fAcA21dd2Ad7eDB3a027d543e617496820d8d6', '0xA30d1D98C502378ad61Fe71BcDc3a808CF60b897', '0xc999fb87AcA383A63D804A575396F65A55aa5aC8', '0x1d91E3F77271ed069618b4BA06d19821BC2ed8b0', '0xAa880345A3147a1fC6889080401C791813ed08Dc', '0x787C771035bDE631391ced5C083db424A4A64bD8', '0x40BD98e3ccE4F34c087a73DD3d05558733549afB', '0x2EE856843bB65c244F527ad302d6d2853921727e', '0x4FEeaecED575239b46d70b50E13532ECB62e4ea8', '0x932fc4fd0eEe66F22f1E23fBA74D7058391c0b15'), (False, True, False, False, False, False, False, False, False, False, False), (True, True, False, False, False, False, False, False, False, False, False))
>>> registry.getVaults()
("0x29E240CFD7946BA20895a7a02eDb25C210f9f324", "0x881b06da56BB5675c54E4Ed311c21E54C5025298", "0x597aD1e0c13Bfe8025993D9e79C69E1c0233522e", "0x5dbcF33D8c2E976c6b560249878e6F1491Bca25c", "0x37d19d1c4E1fa9DC47bD1eA12f742a0887eDa74a", "0xACd43E627e64355f1861cEC6d3a6688B31a6F952", "0x2f08119C6f07c006695E079AAFc638b8789FAf18", "0xBA2E7Fed597fd0E3e70f5130BcDbbFE06bB94fe1", "0x2994529C0652D127b7842094103715ec5299bBed", "0x7Ff566E1d69DEfF32a7b244aE7276b9f90e9D0f6", "0xe1237aA7f535b0CC33Fd973D66cBf830354D16c7")
>>> fields = ['vault', 'controller', 'token', 'strategy', 'is_wrapped', 'is_delegated']
>>> [dict(zip(fields, values)) for values in zip(registry.getVaults(), *registry.getVaultsInfo())]
[
    {
        'controller': "0x2be5D998C95DE70D9A38b3d78e49751F10F9E88b",
        'is_delegated': True,
        'is_wrapped': False,
        'strategy': "0x25fAcA21dd2Ad7eDB3a027d543e617496820d8d6",
        'token': "0xA64BD6C70Cb9051F6A9ba1F163Fdc07E0DfB5F84",
        'vault': "0x29E240CFD7946BA20895a7a02eDb25C210f9f324"
    },
…
    {
        'controller': "0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080",
        'is_delegated': False,
        'is_wrapped': False,
        'strategy': "0x932fc4fd0eEe66F22f1E23fBA74D7058391c0b15",
        'token': "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        'vault': "0xe1237aA7f535b0CC33Fd973D66cBf830354D16c7"
    }
]

With the proposed changes it would be as simple as:

>>> registry = Contract.from_explorer('registry.ychad.eth')
>>> fields = ['vault', 'controller', 'token', 'strategy', 'is_wrapped', 'is_delegated']
>>> [dict(zip(fields, values)) for values in registry.getVaultsInfo()]
banteg commented 4 years ago

Related to #9

lbertenasco commented 4 years ago

Yes, 100% agreed @banteg

knarz commented 3 years ago

It also might be better to return an array of structs as opposed to unzipped arrays of different params

You mean enabling the experimental v2 ABI encoder?

lbertenasco commented 3 years ago

It also might be better to return an array of structs as opposed to unzipped arrays of different params

You mean enabling the experimental v2 ABI encoder?

Yes, it'd need experimental ABI encoder for that.

saltyfacu commented 3 years ago

77