IrrigationProtocol / irrigation-contracts-diamond

MIT License
3 stars 1 forks source link

Add Average Time Water held for Auto Irrigation #63

Closed Super-Genius closed 1 year ago

Super-Genius commented 1 year ago

Here's a method using the idea of a running weighted average for the monthly average of held Water:

mapping (uint256: poolStartTimeStamp => address => timeWeightedWaterHoldingsStruct) timeWeightedHoldings; 

Data Structure:

time_window: A time-period, starting at each pool period = (end of month timestamp - beginning of month timestamp)

struct timeWeightedWaterHoldingsStruct {
  total_time: uint256;              // total time deposits were held
  total_value: uint256;             // Weighted sum of all deposits with their held time.
  current_deposit_time: uint256;    // Timestamp of the first deposit (it gets updated upon withdrawal).
  current_deposit_value: uint256;   // The current total deposit value.
}

Every deposit/withdrawal will update these values.

Upon Deposit:

Upon Withdrawal:

Compute the Average:

Super-Genius commented 1 year ago

This can also be used to determine time-weighted holdings over the last 30 days for getting the % fees for auction listing and success.

Super-Genius commented 1 year ago

Closing, as new methodology for this.