{
  "schemaVersion": 1,
  "slug": "defi-yield-calculator",
  "category": "crypto",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "a5f077452fa698eb41e1f681c10c3334bdb6257934128949aa2c564348a4bb3c",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/defi-yield-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "Gross = principal × (1 + APY/100)^(days/365); implied APY from APR = (1 + APR/(100n))^n − 1",
    "vars": [
      [
        "P",
        "Principal"
      ],
      [
        "a",
        "APY (%)"
      ],
      [
        "n",
        "Compounding periods/year"
      ],
      [
        "days",
        "Period (days)"
      ],
      [
        "G",
        "Gross balance"
      ],
      [
        "F",
        "Final balance"
      ],
      [
        "IL",
        "Impermanent loss (%)"
      ]
    ],
    "note": "Gross balance = principal × (1 + APY/100)^(days/365). APY is effective and already includes compounding; compound the base APR separately only to show its implied effective annual yield."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const vals=[principal,apy,days,apr,gasCost,impermanentLossPct];if(vals.some(v=>!Number.isFinite(v))||principal<0||apy<0||apy>10000||days<1||days>36500||apr<0||apr>10000||gasCost<0||impermanentLossPct<0||impermanentLossPct>100||![1,4,12,52,365].includes(Number(compounding)))return {finalBalance:null,interestEarned:null,netProfit:null,effectivePeriodRate:null,aprEquivalent:null,dailyEarnings:null,impermanentLoss:null,__error:'inputError'};const years=days/365,n=Number(compounding),apyRate=apy/100,gross=principal*Math.pow(1+apyRate,years),interest=gross-principal,il=principal*impermanentLossPct/100,finalBalance=gross-il,profit=finalBalance-principal-gasCost;return {finalBalance,interestEarned:interest,netProfit:profit,effectivePeriodRate:principal>0?profit/principal*100:0,aprEquivalent:(Math.pow(1+apr/100/n,n)-1)*100,dailyEarnings:interest/days,impermanentLoss:il};",
    "inputs": [
      {
        "name": "principal",
        "type": "number",
        "default": 10000,
        "min": 0,
        "max": 1000000000,
        "step": 1
      },
      {
        "name": "apy",
        "type": "number",
        "default": 12,
        "min": 0,
        "max": 10000,
        "step": 0.01
      },
      {
        "name": "days",
        "type": "number",
        "default": 365,
        "min": 1,
        "max": 36500,
        "step": 1
      },
      {
        "name": "apr",
        "type": "number",
        "default": 11.3,
        "min": 0,
        "max": 10000,
        "step": 0.01
      },
      {
        "name": "compounding",
        "type": "select",
        "default": 365,
        "options": [
          {
            "value": 365
          },
          {
            "value": 52
          },
          {
            "value": 12
          },
          {
            "value": 4
          },
          {
            "value": 1
          }
        ]
      },
      {
        "name": "gasCost",
        "type": "number",
        "default": 20,
        "min": 0,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "impermanentLossPct",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 100,
        "step": 0.1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "finalBalance",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "interestEarned",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "netProfit",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "effectivePeriodRate",
        "precision": 3,
        "unit": "%"
      },
      {
        "name": "aprEquivalent",
        "precision": 2,
        "unit": "%"
      },
      {
        "name": "dailyEarnings",
        "precision": 4,
        "unit": "$"
      },
      {
        "name": "impermanentLoss",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
