@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,17 @@
|
|
1
|
+
FROM node:lts-slim AS BUILD
|
2
|
+
WORKDIR /usr/src/app
|
3
|
+
|
4
|
+
COPY package*.json ./
|
5
|
+
RUN npm install
|
6
|
+
|
7
|
+
COPY . .
|
8
|
+
RUN npm run compile
|
9
|
+
|
10
|
+
|
11
|
+
FROM node:20.9.0-alpine3.18 AS PRODUCTION
|
12
|
+
WORKDIR /usr/src/app
|
13
|
+
|
14
|
+
COPY --from=BUILD --chown=node /usr/src/app .
|
15
|
+
|
16
|
+
ENTRYPOINT [ "npm", "run" ]
|
17
|
+
CMD [ "deploy-ufarmDocker-all" ]
|
package/.dockerignore
ADDED
package/.env.sample
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Chain config
|
2
|
+
QUICKNODE_API_KEY = 'quick node key'
|
3
|
+
INFURA_API_KEY = 'your infura api key'
|
4
|
+
ETHSCAN_API_KEY =''
|
5
|
+
ARBISCAN_API_KEY =''
|
6
|
+
ARBITRUM_RPC_URL='htttps://your-arbitrum-rpc-url'
|
7
|
+
ONE_INCH_TOKEN = 'Bearer YOUR_1INCH_TOKEN'
|
8
|
+
|
9
|
+
UFARM_DEMO_URL = 'https://ufarm.digital'
|
10
|
+
UFARM_DEMO_CHAIN_ID = 123456
|
11
|
+
UFARM_DEV_URL = 'https://ufarm.dev.digital'
|
12
|
+
UFARM_DEV_CHAIN_ID = 123456
|
13
|
+
|
14
|
+
# Test config
|
15
|
+
TEST_MNEMONIC = 'twelve words mnemonic from our "usefull links" wiki page or any another' # Deployer will be the first one from that passphrase
|
16
|
+
DEPLOYMENTS_JSON = 'path to the deployments.json file to read in some scripts'
|
17
|
+
ONE_INCH_TOKEN = 'Bearer your1inch-token'
|
18
|
+
|
19
|
+
# General config
|
20
|
+
PANIC_MANAGER_ADDRESS=0xABCDEF1234567890ABCDEF1234567890ABCDEF12
|
21
|
+
FUND_APPROVER_ADDRESS=0xABCDEF1234567890ABCDEF1234567890ABCDEF12
|
22
|
+
UFARM_MANAGER_ADDRESS=0xABCDEF1234567890ABCDEF1234567890ABCDEF12
|
23
|
+
FUND_OWNER_ADDRESS=0xABCDEF1234567890ABCDEF1234567890ABCDEF12
|
24
|
+
OWNER_ADDRESS=0xABCDEF1234567890ABCDEF1234567890ABCDEF12
|
package/.gitlab-ci.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
image: docker:24.0.6
|
2
|
+
|
3
|
+
services:
|
4
|
+
- docker:24.0.6-dind
|
5
|
+
|
6
|
+
stages:
|
7
|
+
- test
|
8
|
+
- build
|
9
|
+
- deploy
|
10
|
+
|
11
|
+
variables:
|
12
|
+
DOCKER_TLS_CERTDIR: ""
|
13
|
+
DOCKER_HOST: tcp://docker:2375
|
14
|
+
DOCKER_CERT_PATH: "/certs/client"
|
15
|
+
|
16
|
+
.build: &build
|
17
|
+
script:
|
18
|
+
- git submodule update --init --recursive
|
19
|
+
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
|
20
|
+
- docker build -f .docker/Dockerfile -t $CI_REGISTRY_IMAGE:${CI_COMMIT_SHORT_SHA} -t $CI_REGISTRY_IMAGE:${ENV_TAG} .
|
21
|
+
- docker push --all-tags $CI_REGISTRY_IMAGE
|
22
|
+
|
23
|
+
before_script:
|
24
|
+
- apk add git openssh-client
|
25
|
+
- mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
26
|
+
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
|
27
|
+
- cp $SSH_PRIVATE_KEY ~/.ssh/id_ecdsa && chmod 0600 ~/.ssh/id_ecdsa
|
28
|
+
|
29
|
+
build-dev:
|
30
|
+
stage: build
|
31
|
+
variables:
|
32
|
+
ENV_TAG: latest
|
33
|
+
<<: *build
|
34
|
+
only:
|
35
|
+
- develop
|
36
|
+
|
37
|
+
build-demo:
|
38
|
+
stage: build
|
39
|
+
variables:
|
40
|
+
ENV_TAG: stable
|
41
|
+
<<: *build
|
42
|
+
only:
|
43
|
+
- master
|
44
|
+
|
45
|
+
build-prod:
|
46
|
+
stage: build
|
47
|
+
variables:
|
48
|
+
ENV_TAG: $CI_COMMIT_TAG
|
49
|
+
<<: *build
|
50
|
+
rules:
|
51
|
+
- if: $CI_COMMIT_TAG =~ /^v/
|
package/.gitmodules
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
[submodule "contracts/test/Uniswap"]
|
2
|
+
path = contracts/test/Uniswap
|
3
|
+
url = git@gitlab.com:ufarm-digital/uniswap-fork.git
|
4
|
+
[submodule "contracts/test/OneInch"]
|
5
|
+
path = contracts/test/OneInch
|
6
|
+
url = git@gitlab.com:ufarm-digital/1inch-fork.git
|
7
|
+
[submodule "contracts/test/UniswapV3"]
|
8
|
+
path = contracts/test/UniswapV3
|
9
|
+
url = git@gitlab.com:ufarm-digital/uniswap-v3-fork.git
|
10
|
+
[submodule "ufarm-evm-typings"]
|
11
|
+
path = ufarm-evm-typings
|
12
|
+
url = git@gitlab.com:ufarm-digital/ufarm-evm-typings.git
|
13
|
+
[submodule "contracts/test/lido"]
|
14
|
+
path = contracts/test/lido
|
15
|
+
url = git@gitlab.com:ufarm-digital/lido-fork.git
|
package/.prettierrc
ADDED
package/.solcover.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"prettier.prettierPath": "./node_modules/prettier",
|
3
|
+
"cSpell.words": [
|
4
|
+
"Aggr",
|
5
|
+
"Comission",
|
6
|
+
"IERC",
|
7
|
+
"Liqudity",
|
8
|
+
"mintable",
|
9
|
+
"nomicfoundation",
|
10
|
+
"nomiclabs",
|
11
|
+
"Numberish",
|
12
|
+
"NUMENATOR",
|
13
|
+
"oneinch",
|
14
|
+
"prtocols",
|
15
|
+
"Prty",
|
16
|
+
"routerv",
|
17
|
+
"Topup",
|
18
|
+
"typechain",
|
19
|
+
"UFARM",
|
20
|
+
"USDTWETH",
|
21
|
+
"Usefull"
|
22
|
+
]
|
23
|
+
}
|
package/LICENSE.MD
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Business Source License 1.1
|
2
|
+
|
3
|
+
License text copyright © 2023 MariaDB plc, All Rights Reserved. “Business Source License” is a trademark of MariaDB plc.
|
4
|
+
|
5
|
+
|
6
|
+
## Parameters
|
7
|
+
|
8
|
+
Licensor: VENT AI Limited
|
9
|
+
|
10
|
+
Licensed Work: UFarm EVM Contracts
|
11
|
+
|
12
|
+
Additional Use Grant: None
|
13
|
+
|
14
|
+
Change Date: 2027-01-01
|
15
|
+
|
16
|
+
Change License: GNU General Public License v2.0 or later
|
17
|
+
|
18
|
+
|
19
|
+
## Terms
|
20
|
+
|
21
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
22
|
+
|
23
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
24
|
+
|
25
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
26
|
+
|
27
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
28
|
+
|
29
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
30
|
+
|
31
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
32
|
+
|
33
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License).
|
34
|
+
|
35
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
36
|
+
|
37
|
+
MariaDB hereby grants you permission to use this License’s text to license your works, and to refer to it using the trademark “Business Source License”, as long as you comply with the Covenants of Licensor below.
|
38
|
+
|
39
|
+
|
40
|
+
## Covenants of Licensor
|
41
|
+
|
42
|
+
In consideration of the right to use this License’s text and the “Business Source License” name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
43
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where “compatible” means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
44
|
+
1. To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text “None”.
|
45
|
+
1. To specify a Change Date.
|
46
|
+
1. Not to modify this License in any other way.
|
47
|
+
|
48
|
+
|
49
|
+
## Notice
|
50
|
+
|
51
|
+
The Business Source License (this document, or the “License”) is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
|
package/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# UFarm EVM Contracts
|
2
|
+
|
3
|
+
[UFarm Digital](https://ufarm.digital) — Efficient digital asset management for everyone.
|
4
|
+
|
5
|
+
This repository contains the smart contracts of UFarm Digital Protocol.
|
6
|
+
|
7
|
+
## Development
|
8
|
+
|
9
|
+
Hardhat is used for smart-contracts development, testing and deploying.
|
10
|
+
|
11
|
+
### Prerequisites
|
12
|
+
|
13
|
+
- NodeJS v20.9.0 or newer
|
14
|
+
|
15
|
+
### Installation
|
16
|
+
|
17
|
+
```shell
|
18
|
+
git submodule update --init --recursive
|
19
|
+
npm install
|
20
|
+
```
|
21
|
+
|
22
|
+
### Compilation
|
23
|
+
|
24
|
+
To compile smart-contracts and typechain types use the command:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
npm run compile
|
28
|
+
```
|
29
|
+
|
30
|
+
It places aftifacts into the directories according to the template:
|
31
|
+
|
32
|
+
```
|
33
|
+
artifacts/contracts/<ContractName>.sol/
|
34
|
+
```
|
35
|
+
|
36
|
+
and typescript types into the directory:
|
37
|
+
|
38
|
+
```
|
39
|
+
typechain-types/
|
40
|
+
```
|
41
|
+
|
42
|
+
### Testing
|
43
|
+
|
44
|
+
Tests are launched by the command:
|
45
|
+
|
46
|
+
```
|
47
|
+
npm test
|
48
|
+
```
|
49
|
+
|
50
|
+
### Launching a node for the DApp
|
51
|
+
|
52
|
+
As the first step the ethereum node should be launched by the command:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
npm run start-no-deploy
|
56
|
+
```
|
57
|
+
|
58
|
+
It prints the URL of the JSON-RPC server, which might be used by the DApp.
|
59
|
+
|
60
|
+
Now in the second terminal the command deploying the contracts should be run:
|
61
|
+
|
62
|
+
```shell
|
63
|
+
npm run deploy-local-all
|
64
|
+
```
|
65
|
+
|
66
|
+
It deploys contracts into the local blockchain. Since that moment the DApp is able to use JSON-RPC API.
|
67
|
+
|
68
|
+
## Tasks
|
69
|
+
|
70
|
+
Create fund
|
71
|
+
|
72
|
+
```shell
|
73
|
+
npx hardhat createFund --name 'Fund Name' --appid '09fe49b3-4d2b-471c-ac04-36c9e706b85f' --network localhost
|
74
|
+
```
|
75
|
+
|
76
|
+
Popup user balance
|
77
|
+
|
78
|
+
```shell
|
79
|
+
npx hardhat mint-tokens --token '0xA37Fc726C2acc26a5807F32a40f7D2Fe7540F4cb' --user '0x024171cCcf21091B58Afe043146893381432225D' --amount '123654321' --isweth true --network localhost
|
80
|
+
# use --isweth true if token is WETH, false or not specified otherwise
|
81
|
+
```
|
82
|
+
|
83
|
+
Create pool
|
84
|
+
|
85
|
+
```shell
|
86
|
+
npx hardhat run scripts/createPool.ts --network localhost
|
87
|
+
```
|
88
|
+
|
89
|
+
Activate pool
|
90
|
+
|
91
|
+
```shell
|
92
|
+
npx hardhat run scripts/activatePool.ts --network localhost
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
UniV2 Swap
|
97
|
+
|
98
|
+
```shell
|
99
|
+
# Please, configure the script before running it
|
100
|
+
npx hardhat run scripts/swapUniswapV2.ts --network localhost
|
101
|
+
```
|
102
|
+
|
103
|
+
UniV3 Swap
|
104
|
+
|
105
|
+
```shell
|
106
|
+
# Please, configure the script before running it
|
107
|
+
npx hardhat run scripts/swapUniswapV3.ts --network localhost
|
108
|
+
```
|
109
|
+
|
110
|
+
OneInch Swap
|
111
|
+
|
112
|
+
```shell
|
113
|
+
# Please, configure the script before running it
|
114
|
+
npx hardhat run scripts/swapOneInchV5.ts --network localhost
|
115
|
+
```
|
116
|
+
|
117
|
+
Increase pool exchange rate in testnet
|
118
|
+
|
119
|
+
```shell
|
120
|
+
npx hardhat --network ufarm boostPool --pool 0x5253F189632bf2EFFA7D89820Cbf4b854c823989
|
121
|
+
```
|
122
|
+
|
123
|
+
Decrease pool exchange rate in testnet
|
124
|
+
|
125
|
+
```shell
|
126
|
+
npx hardhat --network ufarm deboostPool --pool 0x59ef217d6f783362eAB14180140Ee5367B5109Ff
|
127
|
+
```
|
128
|
+
|
129
|
+
## License
|
130
|
+
|
131
|
+
The UFarm EMV Contracts are primarily licensed under the Business Source License 1.1 (BUSL-1.1). Unless explicitly stated otherwise, all files fall under this license. You can review the terms of the BUSL-1.1 [here](./LICENSE.MD). Some files, as indicated by their SPDX headers, are licensed under the GNU General Public License v2.0 or later. If an SPDX header specifies UNLICENSED, then that file is not licensed. Please refer to the individual file headers for detailed licensing information.
|
132
|
+
|
133
|
+
## Copyright
|
134
|
+
|
135
|
+
(c) VENT AI Limited, 2024
|
@@ -0,0 +1,37 @@
|
|
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 {UnoswapV2Controller} from '../../../main/contracts/controllers/UnoswapV2Controller.sol';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @title UniswapV2 controller
|
10
|
+
* @author https://ufarm.digital/
|
11
|
+
* @notice Controller for UniswapV2
|
12
|
+
*/
|
13
|
+
contract UniswapV2ControllerArbitrum is UnoswapV2Controller {
|
14
|
+
/// @notice Protocol identifier for this controller
|
15
|
+
bytes32 private constant _PROTOCOL = keccak256(abi.encodePacked('UniswapV2'));
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @notice UnoswapV2Controller constructor
|
19
|
+
* @param _factory - address of the UnoswapV2 factory
|
20
|
+
* @param _router - address of the UnoswapV2 router
|
21
|
+
* @param _priceOracle - address of the PriceOracle
|
22
|
+
* @param _factoryInitCodeHash - init code hash of the UnoswapV2 factory
|
23
|
+
*/
|
24
|
+
constructor(
|
25
|
+
address _factory,
|
26
|
+
address _router,
|
27
|
+
address _priceOracle,
|
28
|
+
bytes32 _factoryInitCodeHash
|
29
|
+
) UnoswapV2Controller(_factory, _router, _priceOracle, _factoryInitCodeHash) {}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @inheritdoc IController
|
33
|
+
*/
|
34
|
+
function PROTOCOL() public pure override returns (bytes32) {
|
35
|
+
return _PROTOCOL;
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,46 @@
|
|
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
|
+
/**
|
10
|
+
* @title UniswapV3 controller
|
11
|
+
* @author https://ufarm.digital/
|
12
|
+
* @notice Controller for UniswapV3
|
13
|
+
*/
|
14
|
+
contract UniswapV3ControllerArbitrum is UnoswapV3Controller {
|
15
|
+
bytes32 private constant _PROTOCOL = keccak256(abi.encodePacked('UniswapV3'));
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @notice UnoswapV3Controller constructor
|
19
|
+
* @param _swapRouter - address of the Uniswap SwapRouter
|
20
|
+
* @param _swapFactory - address of the UniswapV3 factory
|
21
|
+
* @param _nfpm - address of the UniswapV3 NonfungiblePositionManager
|
22
|
+
* @param _priceOracle - address of the PriceOracle
|
23
|
+
* @param _factoryInitCodeHash - init code hash of the UniswapV3 factory
|
24
|
+
*/
|
25
|
+
constructor(
|
26
|
+
address _swapRouter,
|
27
|
+
address _swapFactory,
|
28
|
+
address _nfpm,
|
29
|
+
address _priceOracle,
|
30
|
+
bytes32 _factoryInitCodeHash
|
31
|
+
) UnoswapV3Controller(_swapRouter, _swapFactory, _nfpm, _priceOracle, _factoryInitCodeHash) {}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @inheritdoc IController
|
35
|
+
*/
|
36
|
+
function PROTOCOL() public pure override(Controller, IController) returns (bytes32) {
|
37
|
+
return _PROTOCOL;
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @inheritdoc UnoswapV3Controller
|
42
|
+
*/
|
43
|
+
function TWAP_PERIOD() public pure override returns (uint32) {
|
44
|
+
return 1800; // 30 minutes
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
import {PriceOracleCore} from '../../../main/contracts/oracle/PriceOracleCore.sol';
|
6
|
+
import {AggregatorV3Interface} from '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';
|
7
|
+
|
8
|
+
contract PriceOracleArbitrum is PriceOracleCore {
|
9
|
+
AggregatorV3Interface public sequencerUptimeFeed;
|
10
|
+
|
11
|
+
uint256 private constant GRACE_PERIOD_TIME = 3600; // 1 hour in seconds
|
12
|
+
|
13
|
+
event SequencerUptimeFeedSet(address indexed sequencerUptimeFeed);
|
14
|
+
|
15
|
+
error SequencerDown();
|
16
|
+
error GracePeriodNotOver();
|
17
|
+
|
18
|
+
function getCostERC20(
|
19
|
+
address tokenIn,
|
20
|
+
uint256 amountIn,
|
21
|
+
address tokenOut
|
22
|
+
) public view override returns (uint256 cost) {
|
23
|
+
// Check for awailability of the sequencer uptime feed on Arbitrum
|
24
|
+
(, int256 answer, uint256 startedAt, , ) = sequencerUptimeFeed.latestRoundData();
|
25
|
+
|
26
|
+
if (answer != 0) {
|
27
|
+
revert SequencerDown();
|
28
|
+
}
|
29
|
+
|
30
|
+
if ((block.timestamp - startedAt) < GRACE_PERIOD_TIME) {
|
31
|
+
revert GracePeriodNotOver();
|
32
|
+
}
|
33
|
+
|
34
|
+
return super.getCostERC20(tokenIn, amountIn, tokenOut);
|
35
|
+
}
|
36
|
+
|
37
|
+
function __init__PriceOracleArbitrum(
|
38
|
+
address ufarmCoreLink,
|
39
|
+
address _sequencerUptimeFeed
|
40
|
+
) external onlyDeployer initializer {
|
41
|
+
__init__PriceOracleCore(ufarmCoreLink);
|
42
|
+
__init__PriceOracleArbitrum_unchained(_sequencerUptimeFeed);
|
43
|
+
}
|
44
|
+
|
45
|
+
function __init__PriceOracleArbitrum_unchained(
|
46
|
+
address _sequencerUptimeFeed
|
47
|
+
) internal onlyInitializing {
|
48
|
+
sequencerUptimeFeed = AggregatorV3Interface(_sequencerUptimeFeed);
|
49
|
+
emit SequencerUptimeFeedSet(address(sequencerUptimeFeed));
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
import {IController} from './IController.sol';
|
6
|
+
import {IUFarmPool} from '../pool/IUFarmPool.sol';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @title Controller base contract
|
10
|
+
* @author https://ufarm.digital/
|
11
|
+
*/
|
12
|
+
abstract contract Controller is IController {
|
13
|
+
address private immutable __self = address(this);
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @dev Error thrown when an unsupported operation is attempted.
|
17
|
+
*/
|
18
|
+
error UnsupportedOperation();
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @dev Error thrown when a function is called without delegatecall.
|
22
|
+
*/
|
23
|
+
error NotDelegateCalled();
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @dev Modifier to check if function is called via delegatecall.
|
27
|
+
*/
|
28
|
+
modifier checkDelegateCall() {
|
29
|
+
if (address(this) == __self) revert NotDelegateCalled();
|
30
|
+
_;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @dev Fallback function that reverts any unsupported operations.
|
35
|
+
*/
|
36
|
+
fallback() external virtual payable {
|
37
|
+
revert UnsupportedOperation();
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @dev Receive function that reverts any unsupported operations.
|
42
|
+
*/
|
43
|
+
receive() external virtual payable {
|
44
|
+
revert UnsupportedOperation();
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @dev Returns the protocol identifier.
|
49
|
+
* @return bytes32 The protocol identifier.
|
50
|
+
*/
|
51
|
+
function PROTOCOL() public view virtual returns (bytes32);
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @dev Returns the target of protocol action.
|
55
|
+
*/
|
56
|
+
function _getTarget() internal view returns (address target, bytes32 withdrawalHash) {
|
57
|
+
return (IUFarmPool(address(this))._protocolTarget(), IUFarmPool(address(this))._withdrawalHash());
|
58
|
+
}
|
59
|
+
|
60
|
+
uint256[50] private __gap;
|
61
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @title Controller Interface
|
7
|
+
* @author https://ufarm.digital/
|
8
|
+
* @dev Interface for the Controller contract in the UFarm ecosystem.
|
9
|
+
* Provides protocol-level controls for pools.
|
10
|
+
*/
|
11
|
+
interface IController {
|
12
|
+
/**
|
13
|
+
* @dev Returns the protocol identifier.
|
14
|
+
* @return bytes32 The protocol identifier.
|
15
|
+
*/
|
16
|
+
function PROTOCOL() external view returns (bytes32);
|
17
|
+
}
|
18
|
+
|
19
|
+
interface IERC20CommonController is IController {}
|
20
|
+
|
21
|
+
interface IERC20SynthController is IController {
|
22
|
+
/**
|
23
|
+
* @dev Calculates the cost for a ERC20 token in terms of a value token.
|
24
|
+
* @param _tokenIn - token address to calculate the cost for.
|
25
|
+
* @param _amountIn - array of amounts of tokens to calculate the cost for.
|
26
|
+
* @param _valueToken - the address of the value token to calculate the cost in.
|
27
|
+
* @return cost - calculated cost in the value token.
|
28
|
+
*/
|
29
|
+
function getCostControlledERC20(
|
30
|
+
address _tokenIn,
|
31
|
+
uint256 _amountIn,
|
32
|
+
address _valueToken
|
33
|
+
) external view returns (uint256 cost);
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @notice Encodes data for a partial withdrawal from a Uniswap V2 liquidity pool
|
37
|
+
* @param _token - The address of the LP (liquidity provider) token
|
38
|
+
* @param _numerator - The numerator of the fraction of the position to withdraw, user balance in common
|
39
|
+
* @param _denominator - The denominator of the fraction of the position to withdraw, ufarmPool total supply
|
40
|
+
* @return encodedTxs - Encoded transactions array
|
41
|
+
*/
|
42
|
+
function encodePartialWithdrawalERC20(
|
43
|
+
address _token,
|
44
|
+
uint256 _numerator,
|
45
|
+
uint256 _denominator
|
46
|
+
) external view returns (bytes[] memory encodedTxs);
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @title ERC721 Controller Interface
|
51
|
+
* @dev Interface for the ERC721 Controller in the UFarm ecosystem.
|
52
|
+
* Provides specialized controls for ERC721 tokens within pools.
|
53
|
+
*/
|
54
|
+
interface IERC721Controller is IController {
|
55
|
+
/**
|
56
|
+
* @dev Calculates the cost for a set of ERC721 tokens in terms of a value token.
|
57
|
+
* @param _lpAddr The address of the liquidity pool.
|
58
|
+
* @param _ids Array of token IDs to calculate the cost for.
|
59
|
+
* @param _valueToken The address of the value token to calculate the cost in.
|
60
|
+
* @return cost The calculated cost in the value token.
|
61
|
+
*/
|
62
|
+
function getCostControlledERC721(
|
63
|
+
address _lpAddr,
|
64
|
+
uint256[] memory _ids,
|
65
|
+
address _valueToken
|
66
|
+
) external view returns (uint256 cost);
|
67
|
+
|
68
|
+
/**
|
69
|
+
* @notice Encodes data for a partial withdrawal from a Uniswap V3 liquidity pool
|
70
|
+
* @param _tokenId - The ID of the Uniswap V3 LP (liquidity provider) NFT
|
71
|
+
* @param _numerator - The numerator of the fraction of the position to withdraw
|
72
|
+
* @param _denominator - The denominator of the fraction of the position to withdraw
|
73
|
+
* @return withdrawalTxs - The encoded transactions data for the partial withdrawal
|
74
|
+
*/
|
75
|
+
function encodePartialWithdrawalERC721(
|
76
|
+
address _tokenAddress,
|
77
|
+
uint256 _tokenId,
|
78
|
+
uint256 _numerator,
|
79
|
+
uint256 _denominator
|
80
|
+
) external view returns (bytes[] memory withdrawalTxs);
|
81
|
+
}
|