Badger-Finance / strategy-convex-staking-optimizer

GNU Affero General Public License v3.0
10 stars 8 forks source link

Optimize harvest #4

Open jazinheira opened 3 years ago

jazinheira commented 3 years ago

Optimized the harvest function by trying to: 1) Remove extra variables like those regarding the treeVaultPosition 2) Limit the amount of balance checks (these are expensive!) and reuse/calculate when possible 3) Consolidate to limit balance checks and extra ifs

I added minimums for some of the harvests and the want deposit, since in the example transaction the amount removed from 3curve costs less than the gas! Initially these vars should be 0 but can be updated by governance using the setMinPoolHarvest() function. Note about the minimums, they are actually right below the minimum; harvests run if the amount to harvest is greater than it. These vars are:

Gas Usage (using tests/test_custom.py and running tx.gas_usage):

Original - 5,547,060 Optimized0 - 5,503,783 Optimized* - 81,216

0 Setting all minimums to 0 so all harvests and deposits proceed. This shows a minimum savings of ~45,000 wei