@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,220 @@
|
|
1
|
+
/**
|
2
|
+
*Submitted for verification at Etherscan.io on 2022-03-09
|
3
|
+
*/
|
4
|
+
|
5
|
+
// SPDX-License-Identifier: BUSL-1.1
|
6
|
+
pragma solidity 0.8.12;
|
7
|
+
|
8
|
+
/// @title Multicall3
|
9
|
+
/// @notice Aggregate results from multiple function calls
|
10
|
+
/// @dev Multicall & Multicall2 backwards-compatible
|
11
|
+
/// @dev Aggregate methods are marked `payable` to save 24 gas per call
|
12
|
+
/// @author Michael Elliot <mike@makerdao.com>
|
13
|
+
/// @author Joshua Levine <joshua@makerdao.com>
|
14
|
+
/// @author Nick Johnson <arachnid@notdot.net>
|
15
|
+
/// @author Andreas Bigger <andreas@nascent.xyz>
|
16
|
+
/// @author Matt Solomon <matt@mattsolomon.dev>
|
17
|
+
contract Multicall3 {
|
18
|
+
struct Call {
|
19
|
+
address target;
|
20
|
+
bytes callData;
|
21
|
+
}
|
22
|
+
|
23
|
+
struct Call3 {
|
24
|
+
address target;
|
25
|
+
bool allowFailure;
|
26
|
+
bytes callData;
|
27
|
+
}
|
28
|
+
|
29
|
+
struct Call3Value {
|
30
|
+
address target;
|
31
|
+
bool allowFailure;
|
32
|
+
uint256 value;
|
33
|
+
bytes callData;
|
34
|
+
}
|
35
|
+
|
36
|
+
struct Result {
|
37
|
+
bool success;
|
38
|
+
bytes returnData;
|
39
|
+
}
|
40
|
+
|
41
|
+
/// @notice Backwards-compatible call aggregation with Multicall
|
42
|
+
/// @param calls An array of Call structs
|
43
|
+
/// @return blockNumber The block number where the calls were executed
|
44
|
+
/// @return returnData An array of bytes containing the responses
|
45
|
+
function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData) {
|
46
|
+
blockNumber = block.number;
|
47
|
+
uint256 length = calls.length;
|
48
|
+
returnData = new bytes[](length);
|
49
|
+
Call calldata call;
|
50
|
+
for (uint256 i = 0; i < length;) {
|
51
|
+
bool success;
|
52
|
+
call = calls[i];
|
53
|
+
(success, returnData[i]) = call.target.call(call.callData);
|
54
|
+
require(success, "Multicall3: call failed");
|
55
|
+
unchecked { ++i; }
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
/// @notice Backwards-compatible with Multicall2
|
60
|
+
/// @notice Aggregate calls without requiring success
|
61
|
+
/// @param requireSuccess If true, require all calls to succeed
|
62
|
+
/// @param calls An array of Call structs
|
63
|
+
/// @return returnData An array of Result structs
|
64
|
+
function tryAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (Result[] memory returnData) {
|
65
|
+
uint256 length = calls.length;
|
66
|
+
returnData = new Result[](length);
|
67
|
+
Call calldata call;
|
68
|
+
for (uint256 i = 0; i < length;) {
|
69
|
+
Result memory result = returnData[i];
|
70
|
+
call = calls[i];
|
71
|
+
(result.success, result.returnData) = call.target.call(call.callData);
|
72
|
+
if (requireSuccess) require(result.success, "Multicall3: call failed");
|
73
|
+
unchecked { ++i; }
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
/// @notice Backwards-compatible with Multicall2
|
78
|
+
/// @notice Aggregate calls and allow failures using tryAggregate
|
79
|
+
/// @param calls An array of Call structs
|
80
|
+
/// @return blockNumber The block number where the calls were executed
|
81
|
+
/// @return blockHash The hash of the block where the calls were executed
|
82
|
+
/// @return returnData An array of Result structs
|
83
|
+
function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
|
84
|
+
blockNumber = block.number;
|
85
|
+
blockHash = blockhash(block.number);
|
86
|
+
returnData = tryAggregate(requireSuccess, calls);
|
87
|
+
}
|
88
|
+
|
89
|
+
/// @notice Backwards-compatible with Multicall2
|
90
|
+
/// @notice Aggregate calls and allow failures using tryAggregate
|
91
|
+
/// @param calls An array of Call structs
|
92
|
+
/// @return blockNumber The block number where the calls were executed
|
93
|
+
/// @return blockHash The hash of the block where the calls were executed
|
94
|
+
/// @return returnData An array of Result structs
|
95
|
+
function blockAndAggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
|
96
|
+
(blockNumber, blockHash, returnData) = tryBlockAndAggregate(true, calls);
|
97
|
+
}
|
98
|
+
|
99
|
+
/// @notice Aggregate calls, ensuring each returns success if required
|
100
|
+
/// @param calls An array of Call3 structs
|
101
|
+
/// @return returnData An array of Result structs
|
102
|
+
function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData) {
|
103
|
+
uint256 length = calls.length;
|
104
|
+
returnData = new Result[](length);
|
105
|
+
Call3 calldata calli;
|
106
|
+
for (uint256 i = 0; i < length;) {
|
107
|
+
Result memory result = returnData[i];
|
108
|
+
calli = calls[i];
|
109
|
+
(result.success, result.returnData) = calli.target.call(calli.callData);
|
110
|
+
assembly {
|
111
|
+
// Revert if the call fails and failure is not allowed
|
112
|
+
// `allowFailure := calldataload(add(calli, 0x20))` and `success := mload(result)`
|
113
|
+
if iszero(or(calldataload(add(calli, 0x20)), mload(result))) {
|
114
|
+
// set "Error(string)" signature: bytes32(bytes4(keccak256("Error(string)")))
|
115
|
+
mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
116
|
+
// set data offset
|
117
|
+
mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
|
118
|
+
// set length of revert string
|
119
|
+
mstore(0x24, 0x0000000000000000000000000000000000000000000000000000000000000017)
|
120
|
+
// set revert string: bytes32(abi.encodePacked("Multicall3: call failed"))
|
121
|
+
mstore(0x44, 0x4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000)
|
122
|
+
revert(0x00, 0x64)
|
123
|
+
}
|
124
|
+
}
|
125
|
+
unchecked { ++i; }
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
/// @notice Aggregate calls with a msg value
|
130
|
+
/// @notice Reverts if msg.value is less than the sum of the call values
|
131
|
+
/// @param calls An array of Call3Value structs
|
132
|
+
/// @return returnData An array of Result structs
|
133
|
+
function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData) {
|
134
|
+
uint256 valAccumulator;
|
135
|
+
uint256 length = calls.length;
|
136
|
+
returnData = new Result[](length);
|
137
|
+
Call3Value calldata calli;
|
138
|
+
for (uint256 i = 0; i < length;) {
|
139
|
+
Result memory result = returnData[i];
|
140
|
+
calli = calls[i];
|
141
|
+
uint256 val = calli.value;
|
142
|
+
// Humanity will be a Type V Kardashev Civilization before this overflows - andreas
|
143
|
+
// ~ 10^25 Wei in existence << ~ 10^76 size uint fits in a uint256
|
144
|
+
unchecked { valAccumulator += val; }
|
145
|
+
(result.success, result.returnData) = calli.target.call{value: val}(calli.callData);
|
146
|
+
assembly {
|
147
|
+
// Revert if the call fails and failure is not allowed
|
148
|
+
// `allowFailure := calldataload(add(calli, 0x20))` and `success := mload(result)`
|
149
|
+
if iszero(or(calldataload(add(calli, 0x20)), mload(result))) {
|
150
|
+
// set "Error(string)" signature: bytes32(bytes4(keccak256("Error(string)")))
|
151
|
+
mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000)
|
152
|
+
// set data offset
|
153
|
+
mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
|
154
|
+
// set length of revert string
|
155
|
+
mstore(0x24, 0x0000000000000000000000000000000000000000000000000000000000000017)
|
156
|
+
// set revert string: bytes32(abi.encodePacked("Multicall3: call failed"))
|
157
|
+
mstore(0x44, 0x4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000)
|
158
|
+
revert(0x00, 0x84)
|
159
|
+
}
|
160
|
+
}
|
161
|
+
unchecked { ++i; }
|
162
|
+
}
|
163
|
+
// Finally, make sure the msg.value = SUM(call[0...i].value)
|
164
|
+
require(msg.value == valAccumulator, "Multicall3: value mismatch");
|
165
|
+
}
|
166
|
+
|
167
|
+
/// @notice Returns the block hash for the given block number
|
168
|
+
/// @param blockNumber The block number
|
169
|
+
function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
|
170
|
+
blockHash = blockhash(blockNumber);
|
171
|
+
}
|
172
|
+
|
173
|
+
/// @notice Returns the block number
|
174
|
+
function getBlockNumber() public view returns (uint256 blockNumber) {
|
175
|
+
blockNumber = block.number;
|
176
|
+
}
|
177
|
+
|
178
|
+
/// @notice Returns the block coinbase
|
179
|
+
function getCurrentBlockCoinbase() public view returns (address coinbase) {
|
180
|
+
coinbase = block.coinbase;
|
181
|
+
}
|
182
|
+
|
183
|
+
/// @notice Returns the block difficulty
|
184
|
+
function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
|
185
|
+
difficulty = block.difficulty;
|
186
|
+
}
|
187
|
+
|
188
|
+
/// @notice Returns the block gas limit
|
189
|
+
function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
|
190
|
+
gaslimit = block.gaslimit;
|
191
|
+
}
|
192
|
+
|
193
|
+
/// @notice Returns the block timestamp
|
194
|
+
function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
|
195
|
+
timestamp = block.timestamp;
|
196
|
+
}
|
197
|
+
|
198
|
+
/// @notice Returns the (ETH) balance of a given address
|
199
|
+
function getEthBalance(address addr) public view returns (uint256 balance) {
|
200
|
+
balance = addr.balance;
|
201
|
+
}
|
202
|
+
|
203
|
+
/// @notice Returns the block hash of the last block
|
204
|
+
function getLastBlockHash() public view returns (bytes32 blockHash) {
|
205
|
+
unchecked {
|
206
|
+
blockHash = blockhash(block.number - 1);
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
/// @notice Gets the base fee of the given block
|
211
|
+
/// @notice Can revert if the BASEFEE opcode is not implemented by the given chain
|
212
|
+
function getBasefee() public view returns (uint256 basefee) {
|
213
|
+
basefee = block.basefee;
|
214
|
+
}
|
215
|
+
|
216
|
+
/// @notice Returns the chain id
|
217
|
+
function getChainId() public view returns (uint256 chainid) {
|
218
|
+
chainid = block.chainid;
|
219
|
+
}
|
220
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
import {UnoswapV2Controller} from '../../../main/contracts/controllers/UnoswapV2Controller.sol';
|
6
|
+
|
7
|
+
contract UniswapV2ControllerUFarm is UnoswapV2Controller {
|
8
|
+
bytes32 private constant _PROTOCOL = keccak256(abi.encodePacked('UniswapV2'));
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @notice UnoswapV2Controller constructor
|
12
|
+
* @param _factory - address of the UnoswapV2 factory
|
13
|
+
* @param _router - address of the UnoswapV2 router
|
14
|
+
* @param _priceOracle - address of the PriceOracle
|
15
|
+
* @param _factoryInitCodeHash - init code hash of the UnoswapV2 factory
|
16
|
+
*/
|
17
|
+
constructor(
|
18
|
+
address _factory,
|
19
|
+
address _router,
|
20
|
+
address _priceOracle,
|
21
|
+
bytes32 _factoryInitCodeHash
|
22
|
+
) UnoswapV2Controller(_factory, _router, _priceOracle, _factoryInitCodeHash) {}
|
23
|
+
|
24
|
+
function PROTOCOL() public pure override returns (bytes32) {
|
25
|
+
return _PROTOCOL;
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
import {IController} from '../../../main/contracts/controllers/IController.sol';
|
6
|
+
import {UnoswapV3Controller} from '../../../main/contracts/controllers/UnoswapV3Controller.sol';
|
7
|
+
import {Controller} from '../../../main/contracts/controllers/Controller.sol';
|
8
|
+
|
9
|
+
contract UniswapV3ControllerUFarm is UnoswapV3Controller {
|
10
|
+
bytes32 private constant _PROTOCOL = keccak256(abi.encodePacked('UniswapV3'));
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @notice UnoswapV3Controller constructor
|
14
|
+
* @param _swapRouter - address of the Uniswap SwapRouter
|
15
|
+
* @param _swapFactory - address of the UniswapV3 factory
|
16
|
+
* @param _nfpm - address of the UniswapV3 NonfungiblePositionManager
|
17
|
+
* @param _priceOracle - address of the PriceOracle
|
18
|
+
* @param _initHash - init code hash of the UniswapV3 factory
|
19
|
+
*/
|
20
|
+
constructor(
|
21
|
+
address _swapRouter,
|
22
|
+
address _swapFactory,
|
23
|
+
address _nfpm,
|
24
|
+
address _priceOracle,
|
25
|
+
bytes32 _initHash
|
26
|
+
)
|
27
|
+
UnoswapV3Controller(
|
28
|
+
_swapRouter,
|
29
|
+
_swapFactory,
|
30
|
+
_nfpm,
|
31
|
+
_priceOracle,
|
32
|
+
_initHash
|
33
|
+
)
|
34
|
+
{}
|
35
|
+
|
36
|
+
function PROTOCOL() public pure override(IController, Controller) returns (bytes32) {
|
37
|
+
return _PROTOCOL;
|
38
|
+
}
|
39
|
+
|
40
|
+
function TWAP_PERIOD() public pure override returns (uint32) {
|
41
|
+
return 1800; // 30 minutes
|
42
|
+
}
|
43
|
+
}
|