@oldzeppelin/contract 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docker/Dockerfile +17 -0
- package/.dockerignore +7 -0
- package/.env.sample +24 -0
- package/.gitlab-ci.yml +51 -0
- package/.gitmodules +15 -0
- package/.prettierrc +10 -0
- package/.solcover.js +4 -0
- package/.vscode/settings.json +23 -0
- package/LICENSE.MD +51 -0
- package/README.md +135 -0
- package/contracts/arbitrum/contracts/controllers/UniswapV2ControllerArbitrum.sol +37 -0
- package/contracts/arbitrum/contracts/controllers/UniswapV3ControllerArbitrum.sol +46 -0
- package/contracts/arbitrum/contracts/oracle/PriceOracleArbitrum.sol +51 -0
- package/contracts/main/contracts/controllers/Controller.sol +61 -0
- package/contracts/main/contracts/controllers/IController.sol +81 -0
- package/contracts/main/contracts/controllers/OneInchV5Controller.sol +332 -0
- package/contracts/main/contracts/controllers/UnoswapV2Controller.sol +789 -0
- package/contracts/main/contracts/controllers/UnoswapV3Controller.sol +1018 -0
- package/contracts/main/contracts/core/CoreWhitelist.sol +192 -0
- package/contracts/main/contracts/core/ICoreWhitelist.sol +92 -0
- package/contracts/main/contracts/core/IUFarmCore.sol +95 -0
- package/contracts/main/contracts/core/UFarmCore.sol +402 -0
- package/contracts/main/contracts/fund/FundFactory.sol +59 -0
- package/contracts/main/contracts/fund/IUFarmFund.sol +68 -0
- package/contracts/main/contracts/fund/UFarmFund.sol +504 -0
- package/contracts/main/contracts/oracle/ChainlinkedOracle.sol +71 -0
- package/contracts/main/contracts/oracle/IChainlinkAggregator.sol +18 -0
- package/contracts/main/contracts/oracle/IPriceOracle.sol +55 -0
- package/contracts/main/contracts/oracle/PriceOracle.sol +20 -0
- package/contracts/main/contracts/oracle/PriceOracleCore.sol +212 -0
- package/contracts/main/contracts/oracle/WstETHOracle.sol +64 -0
- package/contracts/main/contracts/permissions/Permissions.sol +54 -0
- package/contracts/main/contracts/permissions/UFarmPermissionsModel.sol +136 -0
- package/contracts/main/contracts/pool/IPoolAdmin.sol +57 -0
- package/contracts/main/contracts/pool/IUFarmPool.sol +304 -0
- package/contracts/main/contracts/pool/PerformanceFeeLib.sol +81 -0
- package/contracts/main/contracts/pool/PoolAdmin.sol +437 -0
- package/contracts/main/contracts/pool/PoolFactory.sol +74 -0
- package/contracts/main/contracts/pool/PoolWhitelist.sol +70 -0
- package/contracts/main/contracts/pool/UFarmPool.sol +959 -0
- package/contracts/main/shared/AssetController.sol +194 -0
- package/contracts/main/shared/ECDSARecover.sol +91 -0
- package/contracts/main/shared/NZGuard.sol +99 -0
- package/contracts/main/shared/SafeOPS.sol +128 -0
- package/contracts/main/shared/UFarmCoreLink.sol +83 -0
- package/contracts/main/shared/UFarmErrors.sol +16 -0
- package/contracts/main/shared/UFarmMathLib.sol +80 -0
- package/contracts/main/shared/UFarmOwnableUUPS.sol +59 -0
- package/contracts/main/shared/UFarmOwnableUUPSBeacon.sol +34 -0
- package/contracts/test/Block.sol +15 -0
- package/contracts/test/InchSwapTestProxy.sol +292 -0
- package/contracts/test/MockPoolAdmin.sol +8 -0
- package/contracts/test/MockUFarmPool.sol +8 -0
- package/contracts/test/MockV3wstETHstETHAgg.sol +128 -0
- package/contracts/test/MockedWETH9.sol +72 -0
- package/contracts/test/OneInchToUFarmTestEnv.sol +466 -0
- package/contracts/test/StableCoin.sol +25 -0
- package/contracts/test/UFarmMockSequencerUptimeFeed.sol +44 -0
- package/contracts/test/UFarmMockV3Aggregator.sol +145 -0
- package/contracts/test/UUPSBlock.sol +19 -0
- package/contracts/test/ufarmLocal/MulticallV3.sol +220 -0
- package/contracts/test/ufarmLocal/controllers/UniswapV2ControllerUFarm.sol +27 -0
- package/contracts/test/ufarmLocal/controllers/UniswapV3ControllerUFarm.sol +43 -0
- package/deploy/100_test_env_setup.ts +483 -0
- package/deploy/20_deploy_uniV2.ts +48 -0
- package/deploy/21_create_pairs_uniV2.ts +149 -0
- package/deploy/22_deploy_mocked_aggregators.ts +123 -0
- package/deploy/22_deploy_wsteth_oracle.ts +65 -0
- package/deploy/23_deploy_uniV3.ts +80 -0
- package/deploy/24_create_pairs_uniV3.ts +140 -0
- package/deploy/25_deploy_oneInch.ts +38 -0
- package/deploy/2_deploy_multicall.ts +34 -0
- package/deploy/30_deploy_price_oracle.ts +33 -0
- package/deploy/3_deploy_lido.ts +114 -0
- package/deploy/40_deploy_pool_beacon.ts +19 -0
- package/deploy/41_deploy_poolAdmin_beacon.ts +19 -0
- package/deploy/42_deploy_ufarmcore.ts +29 -0
- package/deploy/43_deploy_fund_beacon.ts +19 -0
- package/deploy/4_deploy_tokens.ts +76 -0
- package/deploy/50_deploy_poolFactory.ts +35 -0
- package/deploy/51_deploy_fundFactory.ts +29 -0
- package/deploy/60_init_contracts.ts +101 -0
- package/deploy/61_whitelist_tokens.ts +18 -0
- package/deploy/70_deploy_uniV2Controller.ts +70 -0
- package/deploy/71_deploy_uniV3Controller.ts +67 -0
- package/deploy/72_deploy_oneInchController.ts +25 -0
- package/deploy/79_whitelist_controllers.ts +125 -0
- package/deploy/ufarm/arbitrum/1_prepare_env.ts +82 -0
- package/deploy/ufarm/arbitrum/2_deploy_ufarm.ts +178 -0
- package/deploy/ufarm/arbitrum-sepolia/1000_prepare_arb_sepolia_env.ts +308 -0
- package/deploy-config.json +112 -0
- package/deploy-data/oracles.csv +32 -0
- package/deploy-data/protocols.csv +10 -0
- package/deploy-data/tokens.csv +32 -0
- package/docker-compose.yml +67 -0
- package/hardhat.config.ts +449 -0
- package/index.js +93 -0
- package/package.json +82 -0
- package/scripts/_deploy_helpers.ts +992 -0
- package/scripts/_deploy_network_options.ts +49 -0
- package/scripts/activatePool.ts +51 -0
- package/scripts/createPool.ts +62 -0
- package/scripts/deploy_1inch_proxy.ts +98 -0
- package/scripts/pool-data.ts +420 -0
- package/scripts/post-deploy.sh +24 -0
- package/scripts/setUniV2Rate.ts +252 -0
- package/scripts/swapOneInchV5.ts +94 -0
- package/scripts/swapUniswapV2.ts +65 -0
- package/scripts/swapUniswapV3.ts +71 -0
- package/scripts/test.ts +61 -0
- package/scripts/typings-copy-artifacts.ts +83 -0
- package/tasks/boostPool.ts +39 -0
- package/tasks/createFund.ts +44 -0
- package/tasks/deboostPool.ts +48 -0
- package/tasks/grantUFarmPermissions.ts +57 -0
- package/tasks/index.ts +7 -0
- package/tasks/mintUSDT.ts +62 -0
- package/test/Periphery.test.ts +640 -0
- package/test/PriceOracle.test.ts +82 -0
- package/test/TestCases.MD +109 -0
- package/test/UFarmCore.test.ts +331 -0
- package/test/UFarmFund.test.ts +406 -0
- package/test/UFarmPool.test.ts +4736 -0
- package/test/_fixtures.ts +783 -0
- package/test/_helpers.ts +2195 -0
- package/test/_oneInchTestData.ts +632 -0
- package/tsconfig.json +12 -0
@@ -0,0 +1,304 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
import {AssetsStructs} from '../../shared/AssetController.sol';
|
6
|
+
|
7
|
+
interface IUFarmPool {
|
8
|
+
enum PoolStatus {
|
9
|
+
Draft,
|
10
|
+
Created,
|
11
|
+
Active,
|
12
|
+
Deactivating,
|
13
|
+
Terminated
|
14
|
+
}
|
15
|
+
|
16
|
+
// Struct to avoid stack too deep error:
|
17
|
+
struct CreationSettingsWithLinks {
|
18
|
+
CreationSettings params;
|
19
|
+
address ufarmCore;
|
20
|
+
address ufarmFund;
|
21
|
+
}
|
22
|
+
|
23
|
+
struct CreationSettings {
|
24
|
+
uint256 minInvestment;
|
25
|
+
uint256 maxInvestment;
|
26
|
+
uint256 managementCommission;
|
27
|
+
uint256 packedPerformanceCommission;
|
28
|
+
uint128 withdrawalLockupPeriod;
|
29
|
+
address valueToken;
|
30
|
+
Staff[] staff;
|
31
|
+
string name;
|
32
|
+
string symbol;
|
33
|
+
}
|
34
|
+
|
35
|
+
struct PerformanceCommissionStep {
|
36
|
+
uint16 step;
|
37
|
+
uint16 commission;
|
38
|
+
}
|
39
|
+
struct Staff {
|
40
|
+
address addr;
|
41
|
+
uint256 permissionsMask;
|
42
|
+
}
|
43
|
+
|
44
|
+
struct DepositRequest {
|
45
|
+
uint256 amountToInvest;
|
46
|
+
bytes32 salt;
|
47
|
+
address poolAddr;
|
48
|
+
uint96 deadline;
|
49
|
+
}
|
50
|
+
|
51
|
+
struct WithdrawRequest {
|
52
|
+
uint256 sharesToBurn;
|
53
|
+
bytes32 salt;
|
54
|
+
address poolAddr;
|
55
|
+
}
|
56
|
+
|
57
|
+
struct SignedDepositRequest {
|
58
|
+
DepositRequest body;
|
59
|
+
bytes signature;
|
60
|
+
}
|
61
|
+
|
62
|
+
struct SignedWithdrawalRequest {
|
63
|
+
WithdrawRequest body;
|
64
|
+
bytes signature;
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @notice Emitted when a deposit is made
|
69
|
+
* @param investor - investor address
|
70
|
+
* @param tokenIn - token address deposited
|
71
|
+
* @param valueIn - amount of tokens deposited
|
72
|
+
* @param sharesOut - amount of shares minted
|
73
|
+
*/
|
74
|
+
event Deposit(
|
75
|
+
address indexed investor,
|
76
|
+
address indexed tokenIn,
|
77
|
+
uint256 valueIn,
|
78
|
+
uint256 sharesOut
|
79
|
+
);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @notice Emitted when a deposit request is executed
|
83
|
+
* @param investor - investor that made the deposit
|
84
|
+
* @param depositRequestHash - hash of the deposit request
|
85
|
+
*/
|
86
|
+
event DepositRequestExecuted(address indexed investor, bytes32 indexed depositRequestHash);
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @notice Emitted when a withdrawal request is received
|
90
|
+
* @param investor - investor that made the withdrawal request
|
91
|
+
* @param withdrawRequestHash - hash of the withdrawal request
|
92
|
+
* @param timestamp - timestamp of the withdrawal request received
|
93
|
+
*/
|
94
|
+
event WithdrawRequestReceived(
|
95
|
+
address indexed investor,
|
96
|
+
bytes32 indexed withdrawRequestHash,
|
97
|
+
uint256 timestamp
|
98
|
+
);
|
99
|
+
|
100
|
+
/**
|
101
|
+
* @notice Emitted when a withdrawal request is executed
|
102
|
+
* @param investor - investor that made the withdrawal request
|
103
|
+
* @param sharesBurned - amount of the Pool shares burned
|
104
|
+
* @param withdrawRequestHash - hash of the withdrawal request
|
105
|
+
*/
|
106
|
+
event WithdrawRequestExecuted(
|
107
|
+
address indexed investor,
|
108
|
+
uint256 sharesBurned,
|
109
|
+
bytes32 indexed withdrawRequestHash
|
110
|
+
);
|
111
|
+
|
112
|
+
/**
|
113
|
+
* @notice Emitted when a withdrawal is made. Emits more than one event if the withdrawal is partial.
|
114
|
+
* @param investor - investor address
|
115
|
+
* @param tokenOut - token address withdrawn
|
116
|
+
* @param amountOut - amount of tokens withdrawn
|
117
|
+
* @param requestHash - hash of the withdrawal request
|
118
|
+
*/
|
119
|
+
event Withdraw(
|
120
|
+
address indexed investor,
|
121
|
+
address indexed tokenOut,
|
122
|
+
uint256 amountOut,
|
123
|
+
bytes32 indexed requestHash
|
124
|
+
);
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @notice Emitted when fees are accrued
|
128
|
+
* @param protocolFee - protocol fee paid in ValueToken
|
129
|
+
* @param managementFee - management fee paid in ValueToken
|
130
|
+
* @param performanceFee - performance fee paid in ValueToken
|
131
|
+
* @param sharesToUFarm - shares minted to UFarmCore
|
132
|
+
* @param sharesToFund - shares minted to UFarmFund
|
133
|
+
*/
|
134
|
+
event FeeAccrued(
|
135
|
+
uint256 protocolFee,
|
136
|
+
uint256 managementFee,
|
137
|
+
uint256 performanceFee,
|
138
|
+
uint256 sharesToUFarm,
|
139
|
+
uint256 sharesToFund
|
140
|
+
);
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @notice Emitted when pool status is changed
|
144
|
+
* @param newStatus - new pool status
|
145
|
+
*/
|
146
|
+
event PoolStatusChanged(PoolStatus newStatus);
|
147
|
+
|
148
|
+
/**
|
149
|
+
* @notice Emitted when a controller function is called
|
150
|
+
* @param controllerHashedName - controller name
|
151
|
+
*/
|
152
|
+
event SuccessfullControllerCall(bytes32 controllerHashedName);
|
153
|
+
|
154
|
+
error InvalidInvestmentAmount(uint256 amount, uint256 min, uint256 max);
|
155
|
+
error InvalidWithdrawalAmount(uint256 amount, uint256 balance);
|
156
|
+
error LockupPeriodNotPassed(uint256 unlockTimestamp);
|
157
|
+
error AssetsWeightAboveMax(uint256 weight);
|
158
|
+
error AnotherPoolExpected(address _expectedPool, address _gotPool);
|
159
|
+
error DeadlineExpired(uint256 _deadline, uint256 _now);
|
160
|
+
error InvalidPoolStatus(PoolStatus requiredStatus, PoolStatus currentStatus);
|
161
|
+
error InsufficientDepositAmount(uint256 amount, uint256 minFundDeposit);
|
162
|
+
|
163
|
+
/**
|
164
|
+
* @notice Used by controller to add new ERC20 asset to the pool
|
165
|
+
* @param _asset - Address of the ERC20 asset
|
166
|
+
* @param _controllerOrZero - Controller hashed name or zero if asset is not controlled
|
167
|
+
*/
|
168
|
+
function addERC20(address _asset, bytes32 _controllerOrZero) external;
|
169
|
+
|
170
|
+
/**
|
171
|
+
* @notice Used by controller to remove ERC20 asset from the pool
|
172
|
+
* @param _asset - Address of the ERC20 asset
|
173
|
+
*/
|
174
|
+
function removeERC20(address _asset) external;
|
175
|
+
|
176
|
+
/**
|
177
|
+
* @notice Used by controller to add new ERC721 asset to the pool
|
178
|
+
* @param _asset - Address of the ERC721 asset
|
179
|
+
* @param _ids - List of ERC721 asset ids
|
180
|
+
*/
|
181
|
+
function addERC721(address _asset, uint256[] memory _ids) external;
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @notice Used by controller to remove ERC721 asset from the pool
|
185
|
+
* @param _asset - Address of the ERC721 asset
|
186
|
+
* @param _ids - List of ERC721 asset ids
|
187
|
+
*/
|
188
|
+
function removeERC721(address _asset, uint256[] memory _ids) external;
|
189
|
+
|
190
|
+
/**
|
191
|
+
* @notice Returns the pool state as PoolStatus enum
|
192
|
+
*/
|
193
|
+
function status() external view returns (PoolStatus);
|
194
|
+
|
195
|
+
/**
|
196
|
+
* @notice Returns UFarmCore contract address
|
197
|
+
*/
|
198
|
+
function ufarmCore() external view returns (address);
|
199
|
+
|
200
|
+
/**
|
201
|
+
* @notice Returns UFarmFund contract address
|
202
|
+
*/
|
203
|
+
function ufarmFund() external view returns (address);
|
204
|
+
|
205
|
+
/**
|
206
|
+
* @notice Returns value token contract address
|
207
|
+
*/
|
208
|
+
function valueToken() external view returns (address);
|
209
|
+
|
210
|
+
/**
|
211
|
+
* @notice Returns high water mark in value token
|
212
|
+
*/
|
213
|
+
function highWaterMark() external view returns (uint256);
|
214
|
+
|
215
|
+
/**
|
216
|
+
* @notice Returns last accrual timestamp
|
217
|
+
*/
|
218
|
+
function lastAccrual() external view returns (uint256);
|
219
|
+
|
220
|
+
/**
|
221
|
+
* @notice Returns number of decimals of the pool shares
|
222
|
+
*/
|
223
|
+
function decimals() external view returns (uint8);
|
224
|
+
|
225
|
+
/**
|
226
|
+
* @notice Returns exchange rate of the pool
|
227
|
+
* @dev Exchange rate is the amount of value token required to buy one share of the pool
|
228
|
+
* @return exchangeRate - exchange rate of the pool
|
229
|
+
*/
|
230
|
+
function getExchangeRate() external view returns (uint256 exchangeRate);
|
231
|
+
|
232
|
+
/**
|
233
|
+
* @notice Total cost of the pool in terms of value token
|
234
|
+
*
|
235
|
+
* @return totalCost Amount of value token required to buy all assets
|
236
|
+
*/
|
237
|
+
function getTotalCost() external view returns (uint256 totalCost);
|
238
|
+
|
239
|
+
/**
|
240
|
+
* @notice Returns list of common assets in the pool
|
241
|
+
* @dev Common assets are assets that can be used for trading, lending, doesn't include LPs, staking tokens, etc.
|
242
|
+
* @return tokenAssets - list of token addresses
|
243
|
+
*/
|
244
|
+
function erc20CommonAssets() external view returns (address[] memory tokenAssets);
|
245
|
+
|
246
|
+
/**
|
247
|
+
* @notice Returns list of ERC20 assets with controllers in the pool
|
248
|
+
* @return liquidityAssets - list of controlled ERC20 assets
|
249
|
+
*/
|
250
|
+
function erc20ControlledAssets()
|
251
|
+
external
|
252
|
+
view
|
253
|
+
returns (AssetsStructs.ControlledERC20[] memory liquidityAssets);
|
254
|
+
|
255
|
+
/**
|
256
|
+
* @notice Returns list of ERC721 assets in the pool
|
257
|
+
* @return liquidityAssetsERC721 - list of controlled ERC721 assets
|
258
|
+
*/
|
259
|
+
function erc721ControlledAssets()
|
260
|
+
external
|
261
|
+
view
|
262
|
+
returns (AssetsStructs.ControlledERC721[] memory liquidityAssetsERC721);
|
263
|
+
|
264
|
+
function __init_UFarmPool(
|
265
|
+
CreationSettingsWithLinks memory _settings,
|
266
|
+
address _poolAdmin
|
267
|
+
) external;
|
268
|
+
|
269
|
+
/**
|
270
|
+
* @notice Invests into the pool
|
271
|
+
* @dev Checks if investment amount is within the limits
|
272
|
+
* @dev Emits `Deposit` event
|
273
|
+
* @param _amountToInvest Amount of investment tokens to invest
|
274
|
+
*/
|
275
|
+
function deposit(uint256 _amountToInvest) external returns (uint256 toMint);
|
276
|
+
|
277
|
+
/**
|
278
|
+
* @notice Withdraws from the pool in exchange for value token (if Pool has enough) or every token partially
|
279
|
+
* @dev Emits `Withdraw` event
|
280
|
+
* @param _withdrawalRequest - Withdrawal request
|
281
|
+
*/
|
282
|
+
function withdraw(
|
283
|
+
SignedWithdrawalRequest calldata _withdrawalRequest
|
284
|
+
) external returns (uint256 burnedAssetsCost);
|
285
|
+
|
286
|
+
/**
|
287
|
+
* @notice Changes pool status
|
288
|
+
* @dev Callable by the Pool Admin contract only
|
289
|
+
* @param _newStatus - New pool status
|
290
|
+
*/
|
291
|
+
function changeStatus(IUFarmPool.PoolStatus _newStatus) external;
|
292
|
+
|
293
|
+
/**
|
294
|
+
* @notice Returns current protocol target during the delegatecall
|
295
|
+
* @dev Callable by the protocol contract only
|
296
|
+
*/
|
297
|
+
function _protocolTarget() external view returns (address);
|
298
|
+
|
299
|
+
/**
|
300
|
+
* @notice Returns current withdrawal hash during withdrawal
|
301
|
+
* @dev Callable by the protocol contract only
|
302
|
+
*/
|
303
|
+
function _withdrawalHash() external view returns (bytes32);
|
304
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
/// INTERFACES
|
6
|
+
import {IUFarmCore} from '../core/IUFarmCore.sol';
|
7
|
+
import {IUFarmPool} from '../pool/IUFarmPool.sol';
|
8
|
+
import {IPoolAdmin} from '../pool/IPoolAdmin.sol';
|
9
|
+
|
10
|
+
/// CONTRACTS
|
11
|
+
import {UFarmCoreLink} from '../../shared/UFarmCoreLink.sol';
|
12
|
+
import {NZGuard} from '../../shared/NZGuard.sol';
|
13
|
+
|
14
|
+
library PerformanceFeeLib {
|
15
|
+
uint16 internal constant MAX_COMMISSION_STEP = type(uint16).max;
|
16
|
+
uint16 internal constant ONE_HUNDRED_PERCENT = 10000;
|
17
|
+
/**
|
18
|
+
* @notice Reverts if fee steps count is invalid
|
19
|
+
*/
|
20
|
+
error InvalidPerformanceCommissionStepsCount();
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @notice Reverts if step is invalid
|
24
|
+
*/
|
25
|
+
error InvalidPerformanceCommissionStep(uint16 step, uint16 fee);
|
26
|
+
|
27
|
+
function _getPerformanceCommission(
|
28
|
+
uint256 packedPerformanceFee,
|
29
|
+
uint16 apyRate
|
30
|
+
) internal pure returns (uint16 commission) {
|
31
|
+
if (apyRate == 0 || packedPerformanceFee == 0) return 0;
|
32
|
+
|
33
|
+
uint8 filledLength = _getPerformanceCommissionStepsCount(packedPerformanceFee);
|
34
|
+
IUFarmPool.PerformanceCommissionStep memory pfs;
|
35
|
+
for (uint8 i; i < filledLength; ++i) {
|
36
|
+
pfs = _getPerformanceCommissionStep(packedPerformanceFee, i);
|
37
|
+
if (apyRate > pfs.step) commission = pfs.commission;
|
38
|
+
else break;
|
39
|
+
}
|
40
|
+
|
41
|
+
return commission;
|
42
|
+
}
|
43
|
+
|
44
|
+
function _getPerformanceCommissionStepsCount(
|
45
|
+
uint256 packedPerformanceFee
|
46
|
+
) internal pure returns (uint8 filledLength) {
|
47
|
+
assembly {
|
48
|
+
// Initialize filledLength to 0
|
49
|
+
filledLength := 0
|
50
|
+
|
51
|
+
// Load the packedPerformanceFee value into a temporary variable
|
52
|
+
let temp := packedPerformanceFee
|
53
|
+
|
54
|
+
// Iterate through the packedPerformanceFee value
|
55
|
+
for {
|
56
|
+
|
57
|
+
} gt(temp, 0) {
|
58
|
+
|
59
|
+
} {
|
60
|
+
// Increment filledLength by 1
|
61
|
+
filledLength := add(filledLength, 1)
|
62
|
+
|
63
|
+
// Right shift the temporary variable by 32 bits
|
64
|
+
temp := shr(32, temp)
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
function _getPerformanceCommissionStep(
|
70
|
+
uint256 packedPerformanceCommissionStep,
|
71
|
+
uint8 stepNumber
|
72
|
+
) internal pure returns (IUFarmPool.PerformanceCommissionStep memory) {
|
73
|
+
return
|
74
|
+
IUFarmPool.PerformanceCommissionStep({
|
75
|
+
step: uint16((packedPerformanceCommissionStep >> (stepNumber * 32)) & MAX_COMMISSION_STEP),
|
76
|
+
commission: uint16(
|
77
|
+
(packedPerformanceCommissionStep >> (stepNumber * 32 + 16)) & MAX_COMMISSION_STEP
|
78
|
+
)
|
79
|
+
});
|
80
|
+
}
|
81
|
+
}
|