Badger-Finance / gitcoin

Repo for gitcoin hack-a-thons,bonunties and code snippets.
7 stars 0 forks source link

Emission Rewards Viewer #23

Closed okjintao closed 2 years ago

okjintao commented 3 years ago

Badger Rewards Viewer

The Badger Rewards Logger is the source of truth for Badger Tree emissions per sett on chain. These on chain definitions for sett emissions correspond to the excel documents that are defined and approved in BIPs to determine protocol emissions.

Task

Create a dashboard to display the current active schedules for all setts. Each sett display should contain:

Additionally, per sett expose the full sett historical emission schedule. Differences in historic vs. current emission:

Ideally all values from the display would correspond 1:1 with the week numbers from the emission breakdowns from the BIP.

Resources

Ethereum Rewards Logger https://etherscan.io/address/0x0A4F4e92C3334821EbB523324D09E321a6B0d8ec

Matic Rewards Logger https://polygonscan.com/address/0xd0ee2a5108b8800d688abc834445fd03b3b2738e

Example Snippet of Rewards Logger Interaction

// create relevant contracts
const rewardsLogger = RewardsLogger__factory.connect(chain.rewardsLogger, chain.provider);

let sharesPerFragment = BigNumber.from(1);
if (chain.network === ChainNetwork.Ethereum) {
  const diggContract = Digg__factory.connect(TOKENS.DIGG, chain.provider);
  sharesPerFragment = await diggContract._sharesPerFragment();
}

// filter active unlock schedules
const unlockSchedules = await rewardsLogger.getAllUnlockSchedulesFor(settToken);

if (unlockSchedules.length === 0) {
  return [];
}

const cutoff = new Date();
cutoff.setMinutes(-20);
const cutOffTimestamp = parseInt((cutoff.getTime() / 1000).toString());
const includedTokens = new Set();
const activeSchedules = unlockSchedules
  .slice()
  .sort((a, b) => b.end.sub(a.end).toNumber())
  .filter((schedule) => {
    if (includedTokens.has(schedule.token)) {
      return false;
    }
    const isActive = schedule.start.lte(Date.now() * 1000) && schedule.end.gte(cutOffTimestamp);
    if (isActive) {
      includedTokens.add(schedule.token);
    }
    return isActive;
  });

/**
 * Calculate rewards emission percentages:
 *   - P: Price of Token
 *   - A: Amount of Token Emitted
 *   - D: Duration of Token Emission in Seconds
 *   - S: Number of Seconds Per Year
 *   - L: Amount of Value Locked in Sett
 *
 * Reward APR is determined by the extrapolated one year value emitted
 * from the unlock schedues as a percentage of the current locked value.
 *
 * APR = (P * A * (S / D)) / L * 100
 *
 * This vaule is calculated for all tokens emitted for any given sett
 * and persisted against that sett. There is a 20 minute grace period for
 * emission that have since ended, and only the latest active emission
 * will be used for yield calcuation.
 */
const emissionSources: ValueSource[] = [];
for (const schedule of activeSchedules) {
  const price = await getPrice(schedule.token);
  const token = getToken(schedule.token);
  let emission = schedule.totalAmount;
  if (token.address === TOKENS.DIGG) {
    emission = emission.div(sharesPerFragment);
  }
  const amount = formatBalance(emission, token.decimals);
  const durationScalar = ONE_YEAR_SECONDS / schedule.duration.toNumber();
  const yearlyEmission = price.usd * amount * durationScalar;
  const apr = (yearlyEmission / sett.value) * 100;
  emissionSources.push(createValueSource(`${token.name} Rewards`, uniformPerformance(apr), false, boostRange));
}

Bounty No bounty will be paid out for any dashboard that does not show accurate and complete data.

Beyond that, submissions will be judged based on. 1: Code quality/simplicity 2: The design of the frontend. 3: The ease/difficulty we had getting it to run 4: The engagement of the developer who made it with our community/community support for the work.

Bounties will be paid as follows: First place - 50 Badger Second place -30 badger Third place - 20 badger We will pay an additional 50 badger to any developer who's app we publish/deploy ourselves/continue to use.

To get in touch with our builder community, join our Builder Discord: https://discord.gg/Tf2PucrXcE

gitcoinbot commented 3 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 150.0 BADGER (3405.0 USD @ $22.7/BADGER) attached to it.

gitcoinbot commented 3 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of 150.0 BADGER (2814.0 USD @ $18.76/BADGER) attached to this issue has been cancelled by the bounty submitter