From 2a8c8a03157aa41b67a84e22b9904fc0aa619d84 Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:03:13 +0530 Subject: [PATCH] Add APY calculation (#436) --- script/APYCalc.s.sol | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 script/APYCalc.s.sol diff --git a/script/APYCalc.s.sol b/script/APYCalc.s.sol new file mode 100644 index 00000000..47aa5d31 --- /dev/null +++ b/script/APYCalc.s.sol @@ -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); + } +}