Skip to content

Commit

Permalink
Merge pull request #51 from oxoxDev/fix/vest-ui-helper
Browse files Browse the repository at this point in the history
fix: vest ui helper
  • Loading branch information
deadshotryker authored Nov 21, 2024
2 parents 0d48e29 + 7ad5b4b commit 9af0d10
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 9 deletions.
27 changes: 20 additions & 7 deletions contracts/ui-helpers/VestUiHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ import {VestedZeroNFT} from "../vesting/VestedZeroNFT.sol";
import {OmnichainStakingToken} from "../locker/staking/OmnichainStakingToken.sol";
import {OmnichainStakingLP} from "../locker/staking/OmnichainStakingLP.sol";
import {ILocker} from "../interfaces/ILocker.sol";
import {ILPOracle} from "contracts/interfaces/ILPOracle.sol";

interface IOracle {
function latestAnswer() external view returns (int256);
}
/// @title VestedZeroNFT is a NFT based contract to hold all the user vests

contract VestUiHelper {
VestedZeroNFT public vestedZero;
OmnichainStakingToken public omnichainStaking;
OmnichainStakingLP public omnichainStakingLp;
ILPOracle public lpOracle;
IOracle public zeroOracle;

struct VestDetails {
uint256 id;
Expand Down Expand Up @@ -50,10 +57,18 @@ contract VestUiHelper {
uint256 apr;
}

constructor(address _vestedZeroNFT, address _omnichainStaking, address _omnichainStakingLp) {
constructor(
address _vestedZeroNFT,
address _omnichainStaking,
address _omnichainStakingLp,
address _lpOracle,
address _zeroOracle
) {
vestedZero = VestedZeroNFT(_vestedZeroNFT);
omnichainStaking = OmnichainStakingToken(_omnichainStaking);
omnichainStakingLp = OmnichainStakingLP(payable(_omnichainStakingLp));
lpOracle = ILPOracle(_lpOracle);
zeroOracle = IOracle(_zeroOracle);
}

function getVestedNFTData(address _userAddress) external view returns (VestDetails[] memory) {
Expand Down Expand Up @@ -99,8 +114,6 @@ contract VestUiHelper {
LockedBalanceWithApr memory lock;
ILocker.LockedBalance memory lockedBalance = lockedBalances[i];

uint256 vePower = omnichainStaking.getTokenPower(lockedBalance.amount);

uint256 scale = (lockedBalance.power != 0 && lockedBalance.amount != 0)
? (lockedBalance.power * 1e18) / lockedBalance.amount
: 1e18;
Expand All @@ -113,7 +126,7 @@ contract VestUiHelper {
lock.amount = lockedBalance.amount;
lock.start = lockedBalance.start;
lock.end = lockedBalance.end;
lock.power = vePower;
lock.power = lockedBalance.power;
lock.apr = aprScaled;

lockDetails[i] = lock;
Expand Down Expand Up @@ -146,10 +159,10 @@ contract VestUiHelper {
? (lockedBalance.power * 1e18) / lockedBalance.amount
: 1e18;

uint256 priceConversion = zeroToETH();
uint256 priceConversion = (lpOracle.getPrice() * 1e18 / uint256(zeroOracle.latestAnswer())) / 1e18;

uint256 poolRewardAnnual = rewardRate * 31536000;
uint256 apr = (priceConversion * (poolRewardAnnual * 1000)) / totalSupply;
uint256 poolRewardAnnual = priceConversion * rewardRate * 31536000 * 1000;
uint256 apr = (poolRewardAnnual * 1000) / totalSupply;
uint256 aprScaled = (apr * scale) / 1000;

lock.id = tokenIds[i];
Expand Down
8 changes: 6 additions & 2 deletions deploy/deploy-VestUiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ dotenv.config();
const VESTED_NFT_ADDRESS = "0x9FA72ea96591e486FF065E7C8A89282dEDfA6C12";
const OMNICHAIN_STAKING_TOKEN = "0xf374229a18ff691406f99CCBD93e8a3f16B68888";
const OMNICHAIN_STAKING_LP = "0x0374ae8e866723adae4a62dce376129f292369b4";
const LP_ORACLE = "0x303598dddebB8A48CE0132b3Ba6c2fDC14986647";
const ZERO_ORACLE = "0x130cc6e0301B58ab46504fb6F83BEE97Eb733054";

const deployAirdropRewarder = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const vestui = await deploy("VestUiHelper", {
const vestui = await deploy("VestUiHelperZerolend", {
from: deployer,
contract: "VestUiHelper",
args: [VESTED_NFT_ADDRESS, OMNICHAIN_STAKING_TOKEN, OMNICHAIN_STAKING_LP],
args: [VESTED_NFT_ADDRESS, OMNICHAIN_STAKING_TOKEN, OMNICHAIN_STAKING_LP, LP_ORACLE, ZERO_ORACLE],
autoMine: true,
log: true,
});
Expand All @@ -27,6 +29,8 @@ const deployAirdropRewarder = async function (hre: HardhatRuntimeEnvironment) {
VESTED_NFT_ADDRESS,
OMNICHAIN_STAKING_TOKEN,
OMNICHAIN_STAKING_LP,
LP_ORACLE,
ZERO_ORACLE,
],
});
};
Expand Down
Loading

0 comments on commit 9af0d10

Please sign in to comment.