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

Add APY calculation #436

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions script/APYCalc.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

import "forge-std/Script.sol";
import {Addresses} from "contracts/utils/Addresses.sol";
import {IMintableERC20} from "contracts/interfaces/IMintableERC20.sol";
import {ExponentialStaking} from "contracts/ExponentialStaking.sol";
import {FixedRateRewardsSource} from "contracts/FixedRateRewardsSource.sol";

contract APYCalc is Script {
uint256 constant BASE_SCALE = 10_000 ether;

function run() external {
IMintableERC20 ogn = IMintableERC20(Addresses.OGN);
ExponentialStaking xogn = ExponentialStaking(0x63898b3b6Ef3d39332082178656E9862bee45C57);
FixedRateRewardsSource ognRewardsSource = FixedRateRewardsSource(0x7609c88E5880e934dd3A75bCFef44E31b1Badb8b);

(, uint192 rewardsPerSecond) = ognRewardsSource.rewardConfig();
uint256 rewardsPerYear = rewardsPerSecond * 60 * 60 * 24 * 365;

uint256 xognTotalSupply = xogn.totalSupply();

/// Global APY
uint256 globalApy = (BASE_SCALE * rewardsPerYear / xognTotalSupply) / 1 ether;
console.log("Global APY (1e4): %i", globalApy);

/// User APY
address userAddress = address(11);
uint256 stakeAmount = 10000 ether;
uint256 duration = 365 days;

(uint256 xognPreview,) = xogn.previewPoints(stakeAmount, duration);
uint256 userRewardShare = (BASE_SCALE * xognPreview) / (xognTotalSupply + xognPreview);
uint256 userProjectedRewards = (rewardsPerYear * userRewardShare) / 1 ether;
uint256 userApy = userProjectedRewards / stakeAmount;
console.log("User APY (1e4): %i", userApy);
}
}
Loading