@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.
Files changed (127) hide show
  1. package/.docker/Dockerfile +17 -0
  2. package/.dockerignore +7 -0
  3. package/.env.sample +24 -0
  4. package/.gitlab-ci.yml +51 -0
  5. package/.gitmodules +15 -0
  6. package/.prettierrc +10 -0
  7. package/.solcover.js +4 -0
  8. package/.vscode/settings.json +23 -0
  9. package/LICENSE.MD +51 -0
  10. package/README.md +135 -0
  11. package/contracts/arbitrum/contracts/controllers/UniswapV2ControllerArbitrum.sol +37 -0
  12. package/contracts/arbitrum/contracts/controllers/UniswapV3ControllerArbitrum.sol +46 -0
  13. package/contracts/arbitrum/contracts/oracle/PriceOracleArbitrum.sol +51 -0
  14. package/contracts/main/contracts/controllers/Controller.sol +61 -0
  15. package/contracts/main/contracts/controllers/IController.sol +81 -0
  16. package/contracts/main/contracts/controllers/OneInchV5Controller.sol +332 -0
  17. package/contracts/main/contracts/controllers/UnoswapV2Controller.sol +789 -0
  18. package/contracts/main/contracts/controllers/UnoswapV3Controller.sol +1018 -0
  19. package/contracts/main/contracts/core/CoreWhitelist.sol +192 -0
  20. package/contracts/main/contracts/core/ICoreWhitelist.sol +92 -0
  21. package/contracts/main/contracts/core/IUFarmCore.sol +95 -0
  22. package/contracts/main/contracts/core/UFarmCore.sol +402 -0
  23. package/contracts/main/contracts/fund/FundFactory.sol +59 -0
  24. package/contracts/main/contracts/fund/IUFarmFund.sol +68 -0
  25. package/contracts/main/contracts/fund/UFarmFund.sol +504 -0
  26. package/contracts/main/contracts/oracle/ChainlinkedOracle.sol +71 -0
  27. package/contracts/main/contracts/oracle/IChainlinkAggregator.sol +18 -0
  28. package/contracts/main/contracts/oracle/IPriceOracle.sol +55 -0
  29. package/contracts/main/contracts/oracle/PriceOracle.sol +20 -0
  30. package/contracts/main/contracts/oracle/PriceOracleCore.sol +212 -0
  31. package/contracts/main/contracts/oracle/WstETHOracle.sol +64 -0
  32. package/contracts/main/contracts/permissions/Permissions.sol +54 -0
  33. package/contracts/main/contracts/permissions/UFarmPermissionsModel.sol +136 -0
  34. package/contracts/main/contracts/pool/IPoolAdmin.sol +57 -0
  35. package/contracts/main/contracts/pool/IUFarmPool.sol +304 -0
  36. package/contracts/main/contracts/pool/PerformanceFeeLib.sol +81 -0
  37. package/contracts/main/contracts/pool/PoolAdmin.sol +437 -0
  38. package/contracts/main/contracts/pool/PoolFactory.sol +74 -0
  39. package/contracts/main/contracts/pool/PoolWhitelist.sol +70 -0
  40. package/contracts/main/contracts/pool/UFarmPool.sol +959 -0
  41. package/contracts/main/shared/AssetController.sol +194 -0
  42. package/contracts/main/shared/ECDSARecover.sol +91 -0
  43. package/contracts/main/shared/NZGuard.sol +99 -0
  44. package/contracts/main/shared/SafeOPS.sol +128 -0
  45. package/contracts/main/shared/UFarmCoreLink.sol +83 -0
  46. package/contracts/main/shared/UFarmErrors.sol +16 -0
  47. package/contracts/main/shared/UFarmMathLib.sol +80 -0
  48. package/contracts/main/shared/UFarmOwnableUUPS.sol +59 -0
  49. package/contracts/main/shared/UFarmOwnableUUPSBeacon.sol +34 -0
  50. package/contracts/test/Block.sol +15 -0
  51. package/contracts/test/InchSwapTestProxy.sol +292 -0
  52. package/contracts/test/MockPoolAdmin.sol +8 -0
  53. package/contracts/test/MockUFarmPool.sol +8 -0
  54. package/contracts/test/MockV3wstETHstETHAgg.sol +128 -0
  55. package/contracts/test/MockedWETH9.sol +72 -0
  56. package/contracts/test/OneInchToUFarmTestEnv.sol +466 -0
  57. package/contracts/test/StableCoin.sol +25 -0
  58. package/contracts/test/UFarmMockSequencerUptimeFeed.sol +44 -0
  59. package/contracts/test/UFarmMockV3Aggregator.sol +145 -0
  60. package/contracts/test/UUPSBlock.sol +19 -0
  61. package/contracts/test/ufarmLocal/MulticallV3.sol +220 -0
  62. package/contracts/test/ufarmLocal/controllers/UniswapV2ControllerUFarm.sol +27 -0
  63. package/contracts/test/ufarmLocal/controllers/UniswapV3ControllerUFarm.sol +43 -0
  64. package/deploy/100_test_env_setup.ts +483 -0
  65. package/deploy/20_deploy_uniV2.ts +48 -0
  66. package/deploy/21_create_pairs_uniV2.ts +149 -0
  67. package/deploy/22_deploy_mocked_aggregators.ts +123 -0
  68. package/deploy/22_deploy_wsteth_oracle.ts +65 -0
  69. package/deploy/23_deploy_uniV3.ts +80 -0
  70. package/deploy/24_create_pairs_uniV3.ts +140 -0
  71. package/deploy/25_deploy_oneInch.ts +38 -0
  72. package/deploy/2_deploy_multicall.ts +34 -0
  73. package/deploy/30_deploy_price_oracle.ts +33 -0
  74. package/deploy/3_deploy_lido.ts +114 -0
  75. package/deploy/40_deploy_pool_beacon.ts +19 -0
  76. package/deploy/41_deploy_poolAdmin_beacon.ts +19 -0
  77. package/deploy/42_deploy_ufarmcore.ts +29 -0
  78. package/deploy/43_deploy_fund_beacon.ts +19 -0
  79. package/deploy/4_deploy_tokens.ts +76 -0
  80. package/deploy/50_deploy_poolFactory.ts +35 -0
  81. package/deploy/51_deploy_fundFactory.ts +29 -0
  82. package/deploy/60_init_contracts.ts +101 -0
  83. package/deploy/61_whitelist_tokens.ts +18 -0
  84. package/deploy/70_deploy_uniV2Controller.ts +70 -0
  85. package/deploy/71_deploy_uniV3Controller.ts +67 -0
  86. package/deploy/72_deploy_oneInchController.ts +25 -0
  87. package/deploy/79_whitelist_controllers.ts +125 -0
  88. package/deploy/ufarm/arbitrum/1_prepare_env.ts +82 -0
  89. package/deploy/ufarm/arbitrum/2_deploy_ufarm.ts +178 -0
  90. package/deploy/ufarm/arbitrum-sepolia/1000_prepare_arb_sepolia_env.ts +308 -0
  91. package/deploy-config.json +112 -0
  92. package/deploy-data/oracles.csv +32 -0
  93. package/deploy-data/protocols.csv +10 -0
  94. package/deploy-data/tokens.csv +32 -0
  95. package/docker-compose.yml +67 -0
  96. package/hardhat.config.ts +449 -0
  97. package/index.js +93 -0
  98. package/package.json +82 -0
  99. package/scripts/_deploy_helpers.ts +992 -0
  100. package/scripts/_deploy_network_options.ts +49 -0
  101. package/scripts/activatePool.ts +51 -0
  102. package/scripts/createPool.ts +62 -0
  103. package/scripts/deploy_1inch_proxy.ts +98 -0
  104. package/scripts/pool-data.ts +420 -0
  105. package/scripts/post-deploy.sh +24 -0
  106. package/scripts/setUniV2Rate.ts +252 -0
  107. package/scripts/swapOneInchV5.ts +94 -0
  108. package/scripts/swapUniswapV2.ts +65 -0
  109. package/scripts/swapUniswapV3.ts +71 -0
  110. package/scripts/test.ts +61 -0
  111. package/scripts/typings-copy-artifacts.ts +83 -0
  112. package/tasks/boostPool.ts +39 -0
  113. package/tasks/createFund.ts +44 -0
  114. package/tasks/deboostPool.ts +48 -0
  115. package/tasks/grantUFarmPermissions.ts +57 -0
  116. package/tasks/index.ts +7 -0
  117. package/tasks/mintUSDT.ts +62 -0
  118. package/test/Periphery.test.ts +640 -0
  119. package/test/PriceOracle.test.ts +82 -0
  120. package/test/TestCases.MD +109 -0
  121. package/test/UFarmCore.test.ts +331 -0
  122. package/test/UFarmFund.test.ts +406 -0
  123. package/test/UFarmPool.test.ts +4736 -0
  124. package/test/_fixtures.ts +783 -0
  125. package/test/_helpers.ts +2195 -0
  126. package/test/_oneInchTestData.ts +632 -0
  127. package/tsconfig.json +12 -0
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ /// CONTRACTS
6
+ import {UFarmErrors} from './UFarmErrors.sol';
7
+ import {NZGuard} from './NZGuard.sol';
8
+ import {OwnableUpgradeable} from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
9
+ import {UUPSUpgradeable} from '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
10
+
11
+ /**
12
+ * @title UFarmOwnableUUPS contract
13
+ * @author https://ufarm.digital/
14
+ * @notice UUPS + Ownable contract for permissioned upgrades
15
+ */
16
+ abstract contract UFarmOwnableUUPS is OwnableUpgradeable, UUPSUpgradeable {
17
+ /// @dev Address of the contract deployer, used for delayed permissioned initialization
18
+ /// @custom:oz-upgrades-unsafe-allow state-variable-assignment state-variable-immutable
19
+ address private immutable _deployer = msg.sender;
20
+ /// @custom:oz-upgrades-unsafe-allow state-variable-assignment state-variable-immutable
21
+ address private immutable __self = address(this);
22
+
23
+ /**
24
+ * @dev Error thrown when a function is called without delegatecall.
25
+ */
26
+ error NotDelegateCalled();
27
+
28
+ /**
29
+ * @dev Modifier to check if function is called via delegatecall.
30
+ */
31
+ modifier checkDelegateCall() {
32
+ if (address(this) == __self) revert NotDelegateCalled();
33
+ _;
34
+ }
35
+ /**
36
+ * @dev Modifier to check if function is called by the deployer.
37
+ */
38
+ modifier onlyDeployer() {
39
+ if (msg.sender != _deployer) revert UFarmErrors.NonAuthorized();
40
+ _;
41
+ }
42
+
43
+ /**
44
+ * @notice Prohibits renouncing ownership to prevent potential state with no owner
45
+ */
46
+ function renounceOwnership() public pure override {
47
+ revert UFarmErrors.NonAuthorized();
48
+ }
49
+
50
+ function __init__UFarmOwnableUUPS() internal virtual onlyInitializing {
51
+ __Ownable_init();
52
+ }
53
+
54
+ function __init_UFarmOwnableUUPS_unchained() internal virtual onlyInitializing {}
55
+
56
+ function _authorizeUpgrade(address newImplementation) internal virtual override onlyOwner {}
57
+
58
+ uint256[50] private __gap;
59
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {UFarmOwnableUUPS} from './UFarmOwnableUUPS.sol';
6
+ // import {IBeaconUpgradeable} from '@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol';
7
+
8
+ /**
9
+ * @title UFarmOwnableUUPSBeacon contract
10
+ * @author https://ufarm.digital/
11
+ * @notice Prohibits implementation upgrades from proxy, only external called upgrades are allowed
12
+ */
13
+ abstract contract UFarmOwnableUUPSBeacon is UFarmOwnableUUPS {
14
+ /**
15
+ * @dev Upgrade the implementation of the proxy to `newImplementation`.
16
+ * Upgrades only the implementation, not the beacon proxy
17
+ * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
18
+ */
19
+ function upgradeTo(address newImplementation) public virtual override onlyProxy notDelegated {
20
+ _authorizeUpgrade(newImplementation);
21
+ _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
22
+ }
23
+
24
+ function __init_UFarmOwnableUUPSBeacon() internal virtual onlyInitializing {
25
+ __init__UFarmOwnableUUPS();
26
+ __init_UFarmOwnableUUPSBeacon_unchained();
27
+ }
28
+
29
+ function __init_UFarmOwnableUUPSBeacon_unchained() internal virtual onlyInitializing {
30
+ _transferOwnership(address(0)); // Implementation is UFarmOwnableUUPS, so Beacon should not have an owner
31
+ }
32
+
33
+ uint256[50] private __gap;
34
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ contract Block {
6
+ uint256 blockNumber;
7
+
8
+ function setBlockNumber(uint256 _blockNumber) public {
9
+ blockNumber = _blockNumber;
10
+ }
11
+
12
+ function getBlockTimestamp() public view returns (uint256) {
13
+ return block.timestamp;
14
+ }
15
+ }
@@ -0,0 +1,292 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {IUFarmCore} from '../main/contracts/core/IUFarmCore.sol';
6
+ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
7
+
8
+ /// LIBRARIES
9
+ import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
10
+ import {SafeOPS} from '../main/shared/SafeOPS.sol';
11
+ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
12
+
13
+ import {UFarmErrors} from '../main/shared/UFarmErrors.sol';
14
+ import {NZGuard} from '../main/shared/NZGuard.sol';
15
+ import {Controller, IController} from '../main/contracts/controllers/Controller.sol';
16
+ import {SafeOPS} from '../main/shared/SafeOPS.sol';
17
+ import {IUniswapV2Pair} from './Uniswap/contracts/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
18
+ import {BytesLib} from './UniswapV3/@uniswap/v3-periphery/contracts/libraries/BytesLib.sol';
19
+
20
+ interface IAggregationExecutor {
21
+ /// @notice propagates information about original msg.sender and executes arbitrary data
22
+ function execute(address msgSender) external payable; // 0x4b64e492
23
+ }
24
+
25
+ interface IAggregationRouterV5 {
26
+ struct SwapDescription {
27
+ address srcToken;
28
+ address dstToken;
29
+ address payable srcReceiver;
30
+ address payable dstReceiver;
31
+ uint256 amount;
32
+ uint256 minReturnAmount;
33
+ uint256 flags;
34
+ }
35
+
36
+ function swap(
37
+ IAggregationExecutor executor,
38
+ SwapDescription calldata desc,
39
+ bytes calldata permit,
40
+ bytes calldata data
41
+ ) external payable returns (uint256 returnAmount, uint256 spentAmount);
42
+
43
+ function unoswap(
44
+ address srcToken,
45
+ uint256 amount,
46
+ uint256 minReturn,
47
+ uint256[] calldata pools
48
+ ) external payable returns (uint256 returnAmount);
49
+
50
+ function unoswapTo(
51
+ address payable recipient,
52
+ IERC20 srcToken,
53
+ uint256 amount,
54
+ uint256 minReturn,
55
+ uint256[] calldata pools
56
+ ) external payable returns (uint256 returnAmount);
57
+
58
+ function uniswapV3Swap(
59
+ uint256 amount,
60
+ uint256 minReturn,
61
+ uint256[] calldata pools
62
+ ) external payable returns (uint256 returnAmount);
63
+
64
+ function uniswapV3SwapTo(
65
+ address payable recipient,
66
+ uint256 amount,
67
+ uint256 minReturn,
68
+ uint256[] calldata pools
69
+ ) external payable returns (uint256 returnAmount);
70
+ }
71
+
72
+ interface IUniswapV3Pool {
73
+ function token0() external view returns (address);
74
+
75
+ function token1() external view returns (address);
76
+ }
77
+
78
+ contract InchSwapTestProxy {
79
+ mapping(bytes32 => address) public controllers;
80
+
81
+ function addController(bytes32 _protocol, address _controller) external {
82
+ controllers[_protocol] = _controller;
83
+ }
84
+
85
+ function justCall(address token, address callAddr, bytes calldata callData) public {
86
+ SafeOPS._forceApprove(token, callAddr, 1000 * 1 ether);
87
+ (bool success, bytes memory result) = callAddr.call(callData);
88
+ }
89
+
90
+ function protocolAction(bytes32 _protocol, bytes calldata _data) external {
91
+ _protocolAction(false, controllers[_protocol], _protocol, address(this), _data);
92
+ }
93
+
94
+ function _protocolAction(
95
+ bool _ignoreRevert,
96
+ address _controllerAddr,
97
+ bytes32 _protocolHash,
98
+ address _target,
99
+ bytes memory _data
100
+ ) private {
101
+ SafeOPS._safeDelegateCall(_ignoreRevert, _controllerAddr, _data);
102
+ }
103
+
104
+ function executeAny(address _target, bytes calldata _data) external {
105
+ (bool success, bytes memory result) = _target.delegatecall(_data);
106
+ if (!success) {
107
+ if (result.length > 0) {
108
+ // solhint-disable-next-line no-inline-assembly
109
+ assembly {
110
+ let data_size := mload(result)
111
+ revert(add(32, result), data_size)
112
+ }
113
+ } else revert('Call failed');
114
+ }
115
+ }
116
+ }
117
+
118
+ contract InchSwapTestController is Controller, NZGuard, UFarmErrors {
119
+ using BytesLib for bytes;
120
+
121
+ bytes32 internal constant _PROTOCOL = keccak256(abi.encodePacked('OneInchV5')); // Needs to be hardcoded in the contract to use it during delegation
122
+
123
+ address public aggregationRouterV5;
124
+ address public immutable thisAddr;
125
+
126
+ constructor(address _aggregationRouterV5) {
127
+ aggregationRouterV5 = _aggregationRouterV5;
128
+ thisAddr = address(this);
129
+ }
130
+
131
+ /**
132
+ * @notice Delegates swap to 1inch V5 aggregation router
133
+ * @param tokenIn - token to swap from
134
+ * @param tokenOut - token to swap to
135
+ * @param amountIn - amount of tokenIn to swap
136
+ * @param amountOut - minimum amount of tokenOut to receive
137
+ * @param protocol - protocol hashed name
138
+ */
139
+ event SwapOneInchV5(
140
+ address indexed tokenIn,
141
+ address indexed tokenOut,
142
+ uint256 amountIn,
143
+ uint256 amountOut,
144
+ bytes32 protocol
145
+ );
146
+
147
+ error InvalidPath();
148
+ error InvalidMethod(bytes4 method);
149
+ error InvalidRecipient();
150
+ error OneInchSwapFailed();
151
+
152
+ /**
153
+ * @inheritdoc IController
154
+ */
155
+ function PROTOCOL() public pure override returns (bytes32) {
156
+ return _PROTOCOL;
157
+ }
158
+
159
+ // IAggregationRouterV5.unoswap(srcToken: 0xdAC17F958D2ee523a2206206994597C13D831ec7, amount: 996999, minReturn: 988205, pools: [57896044618658097713242609637998371593005199524156639266814448023762806431658])
160
+ // OneInchV5Controller.delegated1InchSwap(_data: 0x0502b1c5000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000f368700000000000000000000000000000000000000000000000000000000000f142d0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000180000000000000003b6d0340d86a120a06255df8d4e2248ab04d4267e23adfaa8b1ccac8)
161
+ function delegated1InchSwap(bytes memory _data) external checkDelegateCall {
162
+ bytes4 method;
163
+ assembly {
164
+ method := mload(add(_data, 32)) // load first 4 bytes of data
165
+ }
166
+
167
+ uint256[] memory pools;
168
+ address srcToken;
169
+ address payable recipient;
170
+ uint256 amountIn;
171
+ uint256 amountOut;
172
+ address tokenIn;
173
+ address tokenOut;
174
+
175
+ if (method == IAggregationRouterV5.unoswapTo.selector) {
176
+ (recipient, srcToken, amountIn, amountOut, pools) = abi.decode(
177
+ _data.slice(4, _data.length - 4),
178
+ (address, address, uint256, uint256, uint256[])
179
+ );
180
+
181
+ if (recipient != address(this)) revert InvalidRecipient();
182
+
183
+ tokenIn = srcToken;
184
+
185
+ // _onlyIfTokenAllowed(srcToken);
186
+
187
+ address v2Pool;
188
+ for (uint256 i; i < pools.length; ++i) {
189
+ v2Pool = address(uint160(pools[i]));
190
+
191
+ (address token0, address token1) = (
192
+ IUniswapV2Pair(v2Pool).token0(),
193
+ IUniswapV2Pair(v2Pool).token1()
194
+ );
195
+
196
+ if (token0 == srcToken) {
197
+ // _onlyIfTokenAllowed(token1);
198
+ srcToken = token1;
199
+ } else if (token1 == srcToken) {
200
+ // _onlyIfTokenAllowed(token0);
201
+ srcToken = token0;
202
+ } else revert InvalidPath();
203
+ }
204
+ tokenOut = srcToken;
205
+ } else if (method == IAggregationRouterV5.uniswapV3SwapTo.selector) {
206
+ (recipient, amountIn, amountOut, pools) = abi.decode(
207
+ _data.slice(4, _data.length - 4),
208
+ (address, uint256, uint256, uint256[])
209
+ );
210
+
211
+ if (recipient != address(this)) revert InvalidRecipient();
212
+
213
+ uint256 length = pools.length;
214
+ for (uint256 i; i < length; ++i) {
215
+ address v2Pool = address(uint160(pools[i]));
216
+
217
+ bool zeroForOne = pools[0] & (1 << 255) == 0;
218
+
219
+ (address token0, address token1) = (
220
+ IUniswapV3Pool(v2Pool).token0(),
221
+ IUniswapV3Pool(v2Pool).token1()
222
+ );
223
+ if (i == 0) {
224
+ if (length == 1) {
225
+ tokenOut = zeroForOne ? token1 : token0;
226
+ // _onlyIfTokenAllowed(tokenOut);
227
+ }
228
+ // check src token
229
+ tokenIn = zeroForOne ? token0 : token1;
230
+ // _onlyIfTokenAllowed(tokenIn);
231
+ } else if (i < length) {
232
+ // check next dst token
233
+ // _onlyIfTokenAllowed(zeroForOne ? token1 : token0);
234
+ } else {
235
+ // check dst token
236
+ tokenOut = zeroForOne ? token1 : token0;
237
+ // _onlyIfTokenAllowed(tokenOut);
238
+ }
239
+ }
240
+ } else if (method == IAggregationRouterV5.unoswap.selector) {
241
+ (srcToken, amountIn, amountOut, pools) = abi.decode(
242
+ _data.slice(4, _data.length - 4),
243
+ (address, uint256, uint256, uint256[])
244
+ );
245
+
246
+ tokenIn = srcToken;
247
+
248
+ // _onlyIfTokenAllowed(srcToken);
249
+
250
+ address v2Pool;
251
+ for (uint256 i; i < pools.length; ++i) {
252
+ v2Pool = address(uint160(pools[i]));
253
+
254
+ (address token0, address token1) = (
255
+ IUniswapV2Pair(v2Pool).token0(),
256
+ IUniswapV2Pair(v2Pool).token1()
257
+ );
258
+
259
+ if (token0 == srcToken) {
260
+ // _onlyIfTokenAllowed(token1);
261
+ srcToken = token1;
262
+ } else if (token1 == srcToken) {
263
+ // _onlyIfTokenAllowed(token0);
264
+ srcToken = token0;
265
+ } else revert InvalidPath();
266
+ }
267
+ tokenOut = srcToken;
268
+ } else revert InvalidMethod(method);
269
+
270
+ address _aggregRouter = InchSwapTestController(payable(thisAddr)).aggregationRouterV5();
271
+
272
+ if (amountIn == 0 || amountOut == 0) revert OneInchSwapFailed();
273
+
274
+ SafeOPS._forceApprove(tokenIn, _aggregRouter, amountIn);
275
+
276
+ // uint256 balanceIn = IERC20(tokenIn).balanceOf(address(this));
277
+
278
+ // emit Data(_data);
279
+
280
+ (, bytes memory result) = SafeOPS._safeCall(_aggregRouter, _data);
281
+
282
+ uint256 amountOutResult;
283
+ assembly {
284
+ // return amount should be in 0x20 offset from any result
285
+ amountOutResult := mload(add(result, 0x20))
286
+ }
287
+
288
+ if (amountOutResult < amountOut) revert OneInchSwapFailed();
289
+
290
+ emit SwapOneInchV5(tokenIn, tokenOut, amountIn, amountOutResult, PROTOCOL());
291
+ }
292
+ }
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import '../../contracts/main/contracts/pool/PoolAdmin.sol';
6
+ import './Block.sol';
7
+
8
+ contract MockPoolAdmin is PoolAdmin, Block {}
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import '../../contracts/main/contracts/pool/UFarmPool.sol';
6
+ import './Block.sol';
7
+
8
+ contract MockUFarmPool is UFarmPool, Block {}
@@ -0,0 +1,128 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AggregatorV2V3Interface} from '@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol';
5
+ import {IUniswapV2Router02} from './Uniswap/contracts/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
6
+ import {ERC20} from '@oldzeppelin/contracts/token/ERC20/ERC20.sol';
7
+ import {UFarmMathLib} from '../main/shared/UFarmMathLib.sol';
8
+ import {IWstETH8, IStETH8} from '../test/lido/contracts/IWstETH8.sol';
9
+
10
+ /**
11
+ * @title MockV3wstETHstETHAgg
12
+ * @notice Based on the @chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol
13
+ */
14
+ contract MockV3wstETHstETHAgg is AggregatorV2V3Interface {
15
+ uint256 public constant override version = 0;
16
+
17
+ uint8 public immutable override decimals;
18
+ IStETH8 public immutable stETH;
19
+ IWstETH8 public immutable wstETH;
20
+
21
+ int256 public override latestAnswer;
22
+ uint256 public override latestTimestamp;
23
+ uint256 public override latestRound;
24
+
25
+ mapping(uint256 => int256) public override getAnswer;
26
+ mapping(uint256 => uint256) public override getTimestamp;
27
+ mapping(uint256 => uint256) private getStartedAt;
28
+
29
+ constructor(IWstETH8 _wstETH) {
30
+ decimals = 18;
31
+ wstETH = _wstETH;
32
+ stETH = IStETH8(_wstETH.stETH());
33
+ updateAnswer(getChainlinkFormattedPrice());
34
+ }
35
+
36
+ function getChainlinkFormattedPrice() public view returns (int256 chainlinkPrice) {
37
+ return int256(wstETH.stEthPerToken());
38
+ }
39
+
40
+ function _answerStETHToWstETH(int256 _stETHPrice) internal view returns (int256) {
41
+ int256 wstETH_stETHPrice = int256(wstETH.stEthPerToken());
42
+ return (_stETHPrice * wstETH_stETHPrice) / 10 ** 18;
43
+ }
44
+
45
+ function updateAnswerWithChainlinkPrice() public {
46
+ updateAnswer(getChainlinkFormattedPrice());
47
+ }
48
+
49
+ function updateAnswer(int256 _answer) public {
50
+ latestAnswer = _answer;
51
+ latestTimestamp = block.timestamp;
52
+ latestRound++;
53
+ getAnswer[latestRound] = _answer;
54
+ getTimestamp[latestRound] = block.timestamp;
55
+ getStartedAt[latestRound] = block.timestamp;
56
+ }
57
+
58
+ function updateRoundData(
59
+ uint80 _roundId,
60
+ int256 _answer,
61
+ uint256 _timestamp,
62
+ uint256 _startedAt
63
+ ) public {
64
+ latestRound = _roundId;
65
+ latestAnswer = _answer;
66
+ latestTimestamp = _timestamp;
67
+ getAnswer[latestRound] = _answer;
68
+ getTimestamp[latestRound] = _timestamp;
69
+ getStartedAt[latestRound] = _startedAt;
70
+ }
71
+
72
+ function getRoundData(
73
+ uint80 _roundId
74
+ )
75
+ external
76
+ view
77
+ override
78
+ returns (
79
+ uint80 roundId,
80
+ int256 answer,
81
+ uint256 startedAt,
82
+ uint256 updatedAt,
83
+ uint80 answeredInRound
84
+ )
85
+ {
86
+ return (
87
+ _roundId,
88
+ getAnswer[_roundId],
89
+ getStartedAt[_roundId],
90
+ getTimestamp[_roundId],
91
+ _roundId
92
+ );
93
+ }
94
+
95
+ function latestRoundData()
96
+ external
97
+ view
98
+ override
99
+ returns (
100
+ uint80 roundId,
101
+ int256 answer,
102
+ uint256 startedAt,
103
+ uint256 updatedAt,
104
+ uint80 answeredInRound
105
+ )
106
+ {
107
+ answer = getChainlinkFormattedPrice();
108
+ uint80 updateTime = uint80(block.timestamp - 600);
109
+ // return (
110
+ // uint80(latestRound),
111
+ // getAnswer[latestRound],
112
+ // getStartedAt[latestRound],
113
+ // getTimestamp[latestRound],
114
+ // uint80(latestRound)
115
+ // );
116
+ return (
117
+ uint80(block.timestamp),
118
+ answer,
119
+ getStartedAt[latestRound],
120
+ updateTime,
121
+ uint80(latestRound)
122
+ );
123
+ }
124
+
125
+ function description() external pure override returns (string memory) {
126
+ return 'v0.8/tests/MockV3Aggregator.sol';
127
+ }
128
+ }
@@ -0,0 +1,72 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity =0.6.6;
3
+
4
+ contract MockedWETH9 {
5
+ string public name = 'Wrapped Ether';
6
+ string public symbol = 'WETH';
7
+ uint8 public decimals = 18;
8
+
9
+ event Approval(address indexed src, address indexed guy, uint wad);
10
+ event Transfer(address indexed src, address indexed dst, uint wad);
11
+ event Deposit(address indexed dst, uint wad);
12
+ event Withdrawal(address indexed src, uint wad);
13
+
14
+ mapping(address => uint) public balanceOf;
15
+ mapping(address => mapping(address => uint)) public allowance;
16
+
17
+ function deposit() public payable {
18
+ uint256 toDeposit = msg.value * 1 ether;
19
+ balanceOf[msg.sender] += toDeposit;
20
+ emit Deposit(msg.sender, toDeposit);
21
+ }
22
+
23
+ function withdraw(uint wad) public {
24
+ require(balanceOf[msg.sender] >= wad, '');
25
+ balanceOf[msg.sender] -= wad;
26
+ uint256 toWithdraw = wad / 1 ether;
27
+ if (toWithdraw > 0) {
28
+ msg.sender.transfer(toWithdraw);
29
+ }
30
+ emit Withdrawal(msg.sender, wad);
31
+ }
32
+
33
+ function totalSupply() public view returns (uint) {
34
+ return address(this).balance;
35
+ }
36
+
37
+ function approve(address guy, uint wad) public returns (bool) {
38
+ allowance[msg.sender][guy] = wad;
39
+ emit Approval(msg.sender, guy, wad);
40
+ return true;
41
+ }
42
+
43
+ function transfer(address dst, uint wad) public returns (bool) {
44
+ return transferFrom(msg.sender, dst, wad);
45
+ }
46
+
47
+ function transferFrom(address src, address dst, uint wad) public returns (bool) {
48
+ require(balanceOf[src] >= wad, '');
49
+
50
+ if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
51
+ require(allowance[src][msg.sender] >= wad, '');
52
+ allowance[src][msg.sender] -= wad;
53
+ }
54
+
55
+ balanceOf[src] -= wad;
56
+ balanceOf[dst] += wad;
57
+
58
+ emit Transfer(src, dst, wad);
59
+
60
+ return true;
61
+ }
62
+
63
+ function mintWeth(address guy, uint wad) public {
64
+ balanceOf[guy] += wad;
65
+ emit Deposit(guy, wad);
66
+ }
67
+
68
+ function burnWeth(address guy, uint wad) public {
69
+ balanceOf[guy] -= wad;
70
+ emit Withdrawal(guy, wad);
71
+ }
72
+ }