Skip to content

Commit

Permalink
Ideal function
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 16, 2025
1 parent 5b6eab3 commit 2b9fc07
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 35 deletions.
4 changes: 2 additions & 2 deletions const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { ethers } = require("hardhat");


export const D_18 = ethers.utils.parseUnits("1", 18);
export const D_4 = ethers.utils.parseUnits("4", 18);
export const D_4 = ethers.utils.parseUnits("1", 4);

export const ERROR = {
REGISTRY: {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const ERROR = {
STRATEGY_UTILITY: {
ADDRESS_NOT_STRATEGY: "_I_V1_EMP_REGISTRY.v1EMPStrategy_v1EMPStrategyId(_v1EMPStrategy) == 0",
ERC20_NO_ETH_VALUE_PROVIDER_AVAILABLE: "_I_V1_EMP_REGISTRY.eRC20_eRC20ETHValueProvider(_utilizedERC20[i]) == address(0)",
INVALID_ERC20_ALLOCATION_TOTAL: "utilizedERC20AllocationTotal != _PERCENT_ONE_HUNDRED",
INVALID_ERC20_ALLOCATION_TOTAL: "!_utilizationERC20",
INVALID_PARAMS_UPDATE_CONTAINS_DUPLICATES: "!IAddressArrayUtility(_I_V1_EMP_REGISTRY.addressArrayUtility()).isUnique(_utilizedERC20)",
INVALID_UTILIZED_ERC20_AMOUNT: "iV1EMPStrategy.utilizedERC20_utilizationERC20(utilizedERC20[i]).allocation != utilizedERC20AmountAllocationActual",
},
Expand Down
3 changes: 2 additions & 1 deletion contracts/V1EMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.so
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { IPercentUtility } from "@yield-sync/utility/contracts/interface/IPercentUtility.sol";

import { IERC20, IV1EMP } from "./interface/IV1EMP.sol";
import { IV1EMPRegistry } from "./interface/IV1EMPRegistry.sol";
Expand Down Expand Up @@ -53,7 +54,7 @@ contract V1EMP is

_I_V1_EMP_REGISTRY = IV1EMPRegistry(_v1EMPRegistry);

_PERCENT_ONE_HUNDRED = _I_V1_EMP_REGISTRY.PERCENT_ONE_HUNDRED();
_PERCENT_ONE_HUNDRED = IPercentUtility(_I_V1_EMP_REGISTRY.percentUtility()).PERCENT_ONE_HUNDRED();
}


Expand Down
2 changes: 0 additions & 2 deletions contracts/V1EMPRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ contract V1EMPRegistry is
address internal _v1EMPStrategyDeployer;
address internal _v1EMPStrategyUtility;

uint256 public constant override PERCENT_ONE_HUNDRED = 1e4;

uint256 public override v1EMPIdTracker;
uint256 public override v1EMPStrategyIdTracker;

Expand Down
15 changes: 6 additions & 9 deletions contracts/V1EMPStrategyUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IERC20ETHValueProvider
} from "@yield-sync/erc20-eth-value-provider/contracts/interface/IERC20ETHValueProvider.sol";
import { IAddressArrayUtility } from "@yield-sync/utility/contracts/interface/IAddressArrayUtility.sol";
import { IPercentUtility } from "@yield-sync/utility/contracts/interface/IPercentUtility.sol";

import { IV1EMPRegistry } from "./interface/IV1EMPRegistry.sol";
import { IV1EMPStrategy } from "./interface/IV1EMPStrategy.sol";
Expand All @@ -20,16 +21,12 @@ contract V1EMPStrategyUtility is
using SafeMath for uint256;


uint256 internal immutable _PERCENT_ONE_HUNDRED;

IV1EMPRegistry internal immutable _I_V1_EMP_REGISTRY;


constructor (address _v1EMPRegistry)
{
_I_V1_EMP_REGISTRY = IV1EMPRegistry(_v1EMPRegistry);

_PERCENT_ONE_HUNDRED = _I_V1_EMP_REGISTRY.PERCENT_ONE_HUNDRED();
}


Expand Down Expand Up @@ -94,9 +91,9 @@ contract V1EMPStrategyUtility is
}
}

uint256 utilizedERC20AmountAllocationActual = utilizedERC20AmountETHValue_[i].mul(_PERCENT_ONE_HUNDRED).div(
utilizedERC20AmountETHValueTotal_,
"!computed"
uint256 utilizedERC20AmountAllocationActual = IPercentUtility(_I_V1_EMP_REGISTRY.percentUtility()).percentOf(
utilizedERC20AmountETHValue_[i],
utilizedERC20AmountETHValueTotal_
);

if (iV1EMPStrategy.utilizedERC20_utilizationERC20(utilizedERC20[i]).allocation != utilizedERC20AmountAllocationActual)
Expand Down Expand Up @@ -203,9 +200,9 @@ contract V1EMPStrategyUtility is
}
}

if (utilizedERC20AllocationTotal != _PERCENT_ONE_HUNDRED)
if (utilizedERC20AllocationTotal != IPercentUtility(_I_V1_EMP_REGISTRY.percentUtility()).PERCENT_ONE_HUNDRED())
{
return (false, "utilizedERC20AllocationTotal != _PERCENT_ONE_HUNDRED");
return (false, "!_utilizationERC20");
}
}
}
2 changes: 1 addition & 1 deletion contracts/V1EMPUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract V1EMPUtility is
{
_I_V1_EMP_REGISTRY = IV1EMPRegistry(_v1EMPRegistry);

_PERCENT_ONE_HUNDRED = _I_V1_EMP_REGISTRY.PERCENT_ONE_HUNDRED();
_PERCENT_ONE_HUNDRED = IPercentUtility(_I_V1_EMP_REGISTRY.percentUtility()).PERCENT_ONE_HUNDRED();
}


Expand Down
11 changes: 0 additions & 11 deletions contracts/interface/IV1EMPRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ pragma solidity ^0.8.18;

interface IV1EMPRegistry
{
/**
* @dev [view-uint256]
* @notice One Hundred Percent
* @return {uint256}
*/
function PERCENT_ONE_HUNDRED()
external
view
returns (uint256)
;

/**
* @dev [view-uint256]
* @notice V1 EMP Id Tracker
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@yield-sync/erc20-eth-value-provider": "^0.0.5",
"@yield-sync/erc20-handler": "^0.0.5",
"@yield-sync/governance": "^0.0.42",
"@yield-sync/utility": "^0.0.15",
"@yield-sync/utility": "^0.0.16",
"chai": "^4.4.1",
"dotenv": "^16.0.3",
"ethers": "^5.7.2",
Expand Down
2 changes: 1 addition & 1 deletion test/5-EMPStrategy/1-deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe("[5.1] V1EMPStrategy.sol - Depositing Tokens", async () => {
}

// [main-test] Deposit ERC20 tokens into the strategy
await expect(strategy.utilizedERC20Deposit(depositAmounts)).to.be.not.rejected;
await strategy.utilizedERC20Deposit(depositAmounts);
});


Expand Down
7 changes: 4 additions & 3 deletions test/7-EMP/0-initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("[7.0] V1EMP.sol - Initialization", async () => {
let eMP: Contract;
let eMPUtility: Contract;
let registry: Contract;
let percentUtility: Contract;
let eRC20A: Contract;
let eRC20C: Contract;

Expand All @@ -22,7 +23,7 @@ describe("[7.0] V1EMP.sol - Initialization", async () => {


beforeEach("[beforeEach] Set up contracts..", async () => {
({ eMPs, eMPUtility, eRC20A, eRC20C, badActor, registry, strategies, } = await stageContracts());
({ eMPs, eMPUtility, eRC20A, eRC20C, badActor, registry, percentUtility, strategies, } = await stageContracts());

eMP = eMPs[2].contract;

Expand Down Expand Up @@ -56,7 +57,7 @@ describe("[7.0] V1EMP.sol - Initialization", async () => {
});

it("Should NOT allow greater than 100% fee rate..", async () => {
const PERCENT_ONE_HUNDRED = await registry.PERCENT_ONE_HUNDRED();
const PERCENT_ONE_HUNDRED = await percentUtility.PERCENT_ONE_HUNDRED();

await expect(
eMP.feeRateManagerUpdate(PERCENT_ONE_HUNDRED + 1)
Expand Down Expand Up @@ -84,7 +85,7 @@ describe("[7.0] V1EMP.sol - Initialization", async () => {
});

it("Should NOT allow greater than 100% fee rate..", async () => {
const PERCENT_ONE_HUNDRED = await registry.PERCENT_ONE_HUNDRED();
const PERCENT_ONE_HUNDRED = await percentUtility.PERCENT_ONE_HUNDRED();

await expect(
eMP.feeRateGovernanceUpdate(PERCENT_ONE_HUNDRED + 1)
Expand Down
6 changes: 2 additions & 4 deletions util/UtilStrategyTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { ethers } = require("hardhat");

import { BigNumber, Contract } from "ethers";

import { D_18 } from "../const"
import { D_18, D_4 } from "../const"


const LOCATION_IERC20: string = "contracts/test-contracts/MockERC20.sol:MockERC20";
Expand Down Expand Up @@ -44,9 +44,7 @@ export default class UtilStrategyTransfer
{
const ALLOCATION: BigNumber = UTILIZATION.allocation.mul(
ethers.utils.parseUnits("1", await MockERC20.decimals())
).div(
await this._registry.PERCENT_ONE_HUNDRED()
);
).div(D_4);

tokenAmount = ETHValue.mul(ALLOCATION).div(D_18);
}
Expand Down

0 comments on commit 2b9fc07

Please sign in to comment.