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

Simplify TVL median calculations #29

Open
DenisCarriere opened this issue Nov 25, 2022 · 0 comments
Open

Simplify TVL median calculations #29

DenisCarriere opened this issue Nov 25, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@DenisCarriere
Copy link
Collaborator

Enhancement Proposal

Collect protocol's last 24 hours worth of 10 minute TVL data points (144 periods)

Requirements to receive reward: triggers report action

  1. Does protocol contain 21 hours worth of TVL oracle data points (126 periods)?
  2. Compute median TVL value in USD & EOS
  3. Is EOS TVL above min_tvl_report (ex: 200K EOS)

if all statements are true, send rewards

Result

  • More forgiving when Yield+ oracle missing updateall actions (3 hours of missing data would force a full recalibration instead of 1 hour per 8 hour period)
  • Simplify TVL median computation logic

Current mechanic

// generate report TVL to Yield+ Rewards
void oracle::generate_report( const name protocol, const time_point_sec period )
{
// yield config
auto config = get_config();
asset tvl = { 0, EOS };
asset usd = { 0, USD };
// slice values into 3 buckets of 8 hours each
uint64_t current_time_sec = current_time_point().sec_since_epoch();
uint64_t period_1 = current_time_sec - EIGHT_HOURS * 3;
uint64_t period_2 = period_1 + EIGHT_HOURS;
uint64_t period_3 = period_2 + EIGHT_HOURS;
// retrieve datapoint from timepoint
// skip generating report if any median contains no TVL
auto median_1 = get_median( protocol, period_1, period_2 );
if ( !median_1.tvl.amount ) return;
auto median_2 = get_median( protocol, period_2, period_3 );
if ( !median_2.tvl.amount ) return;
auto median_3 = get_median( protocol, period_3, current_time_sec );
if ( !median_3.tvl.amount ) return;
// compute the average of the 3 windows median
tvl += (median_1.tvl + median_2.tvl + median_3.tvl ) / 3;
usd += (median_1.usd + median_2.usd + median_3.usd ) / 3;
// send oracle report to Yield+ Rewards
yield::report_action report( config.yield_contract, { get_self(), "active"_n });
report.send( protocol, period, PERIOD_INTERVAL, tvl, usd );
}

@DenisCarriere DenisCarriere added the enhancement New feature or request label Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants