Skip to content

Commit

Permalink
Merge branch 'master' into shah/deploy-13
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro authored Jun 7, 2024
2 parents 735ab88 + 9076abb commit 7a32bdf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
23 changes: 15 additions & 8 deletions contracts/utils/GovProposalHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,34 @@ struct GovProposal {
library GovProposalHelper {
function id(GovProposal memory prop) internal view returns (uint256 proposalId) {
bytes32 descriptionHash = keccak256(bytes(prop.description));
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) = getParams(prop);
(address[] memory targets, uint256[] memory values,,, bytes[] memory calldatas) = getParams(prop);

proposalId = uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));
}

function getParams(GovProposal memory prop)
internal
view
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas)
returns (
address[] memory targets,
uint256[] memory values,
string[] memory sigs,
bytes[] memory data,
bytes[] memory calldatas
)
{
uint256 actionLen = prop.actions.length;
targets = new address[](actionLen);
values = new uint256[](actionLen);

string[] memory sigs = new string[](actionLen);
bytes[] memory data = new bytes[](actionLen);
sigs = new string[](actionLen);
data = new bytes[](actionLen);

for (uint256 i = 0; i < actionLen; ++i) {
targets[i] = prop.actions[i].target;
values[i] = prop.actions[i].value;
sigs[i] = prop.actions[i].fullsig;
data[i] = prop.actions[i].data;
values[i] = prop.actions[i].value;
}

calldatas = _encodeCalldata(sigs, data);
Expand Down Expand Up @@ -77,10 +83,11 @@ library GovProposalHelper {
}

function getProposeCalldata(GovProposal memory prop) internal view returns (bytes memory proposeCalldata) {
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) = getParams(prop);
(address[] memory targets, uint256[] memory values, string[] memory sigs, bytes[] memory data,) =
getParams(prop);

proposeCalldata = abi.encodeWithSignature(
"propose(address[],uint256[],bytes[],string)", targets, values, calldatas, prop.description
"propose(address[],uint256[],string[], bytes[],string)", targets, values, sigs, data, prop.description
);
}

Expand Down Expand Up @@ -148,7 +155,7 @@ library GovProposalHelper {
if (state == IGovernor.ProposalState.Active) {
console.log("Voting on proposal...");
// Vote on proposal
governance.castVote(proposalId, 1);
try governance.castVote(proposalId, 1) {} catch {}
// Wait for voting to end
vm.roll(governance.proposalDeadline(proposalId) + 20);
vm.warp(block.timestamp + 2 days);
Expand Down
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);
}
}

0 comments on commit 7a32bdf

Please sign in to comment.