Skip to content

Commit

Permalink
oasis-network-primer: Better estimate staking rewards after Damask
Browse files Browse the repository at this point in the history
By using different estimates for epochs per hour before and after Damask.
  • Loading branch information
lukaw3d committed Nov 2, 2023
1 parent 0904b39 commit fcdcf9d
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 243 deletions.
26 changes: 22 additions & 4 deletions docs/general/oasis-network/staking_rewards/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import data from './data.json';
const knownOffsets = {
beta: { epoch: 0, date: '2020-10-01T16:00:00Z' },
mainnet: { epoch: 1170, date: '2020-11-18T16:00:00.000Z' },
recent: { epoch: 15835, date: '2022-07-20T16:11:11.000Z' },
epoch15835: { epoch: 15835, date: '2022-07-20T16:11:11.000Z' },
epoch18653: { epoch: 18653, date: '2022-11-13T13:33:25.000Z' },

// epoch from https://oasismonitor.com/block/4000000
// time from https://www.oasisscan.com/blocks/4000000
Expand All @@ -18,11 +19,24 @@ const knownOffsets = {
block6M: { epoch: 9992, date: '2021-11-19T23:18:41.000Z' },
block7M: { epoch: 11656, date: '2022-01-28T05:06:25.000Z' },
block8M: { epoch: 13320, date: '2022-04-07T22:49:44.000Z' },
// Damask Upgrade was at https://api.oasisscan.com/mainnet/chain/block/8048956
block9M: { epoch: 14987, date: '2022-06-15T16:22:57.000Z' },
block10M: { epoch: 16653, date: '2022-08-23T09:29:12.000Z' },
block11M: { epoch: 18320, date: '2022-10-30T22:41:53.000Z' },
block12M: { epoch: 19987, date: '2023-01-07T03:06:08.000Z' },
block13M: { epoch: 21653, date: '2023-03-16T05:47:42.000Z' },
block14M: { epoch: 23320, date: '2023-05-22T22:04:26.000Z' },
block15M: { epoch: 24987, date: '2023-07-29T13:10:58.000Z' },
block16M: { epoch: 26653, date: '2023-10-05T04:13:33.000Z' },

recent: { epoch: 27320, date: '2023-11-01T03:48:29.000Z' },
};
const offsetFrom = knownOffsets.recent;

const estimatedEpochsPerHour = (knownOffsets.recent.epoch - knownOffsets.mainnet.epoch) / ((new Date(knownOffsets.recent.date).getTime() - new Date(knownOffsets.mainnet.date).getTime()) / 1000 / 60 / 60);
// Estimate up to epoch 15835 instead of Damask for consistency with how we made
// the first iteration of estimations. And it mostly covers pre-Damask epochs.
// Switch between estimates at steeper curve at epoch 18653.
const estimatedEpochsPerHourPreDamask = (knownOffsets.epoch15835.epoch - knownOffsets.mainnet.epoch) / ((new Date(knownOffsets.epoch15835.date).getTime() - new Date(knownOffsets.mainnet.date).getTime()) / 1000 / 60 / 60);
const estimatedEpochsPerHourAfterDamask = (knownOffsets.recent.epoch - knownOffsets.block12M.epoch) / ((new Date(knownOffsets.recent.date).getTime() - new Date(knownOffsets.block12M.date).getTime()) / 1000 / 60 / 60);

// From genesis "reward_factor_epoch_signed": "1"
const rewardFactorEpochSigned = 1;
Expand All @@ -32,6 +46,9 @@ const rewardAmountDenominator = 100_000_000;
const estimateEpochDatesAndAPY = (data: Array<{ untilEpoch: number, scale: number }>) => {
return data
.map(({ untilEpoch, scale }) => {
const estimatedEpochsPerHour = untilEpoch > knownOffsets.epoch18653.epoch ? estimatedEpochsPerHourAfterDamask : estimatedEpochsPerHourPreDamask
const offsetFrom = untilEpoch > knownOffsets.epoch18653.epoch ? knownOffsets.recent : knownOffsets.epoch15835;

const timeOffset = (untilEpoch - offsetFrom.epoch) / estimatedEpochsPerHour * 60 * 60 * 1000;
const date = new Date(new Date(offsetFrom.date).getTime() + timeOffset).toISOString();

Expand Down Expand Up @@ -134,7 +151,8 @@ function testEstimatedEpochDates() {
maximumFractionDigits: 1,
});

console.info('DEV: estimatedEpochsPerHour', estimatedEpochsPerHour);
console.info('DEV: estimatedEpochsPerHourPreDamask', estimatedEpochsPerHourPreDamask);
console.info('DEV: estimatedEpochsPerHourAfterDamask', estimatedEpochsPerHourAfterDamask);
console.info(
'DEV: diff between estimates and known dates',
Object.entries(knownOffsets).map(([epochName, {epoch, date}]) => {
Expand Down
Loading

0 comments on commit fcdcf9d

Please sign in to comment.