@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,123 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction, Deployment } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
deployContract,
|
7
|
+
isTestnet,
|
8
|
+
getTokenDeployments,
|
9
|
+
getInstanceFromDeployment,
|
10
|
+
mockedAggregatorName,
|
11
|
+
getDeployerSigner,
|
12
|
+
_deployTags,
|
13
|
+
} from '../scripts/_deploy_helpers'
|
14
|
+
import { StableCoin, UniswapV2Router02 } from '../typechain-types'
|
15
|
+
|
16
|
+
const deployMockedAggregators: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
17
|
+
if (!isTestnet(hre.network)) {
|
18
|
+
console.log(`Skipping Mocked Aggregators deployment`)
|
19
|
+
return
|
20
|
+
}
|
21
|
+
|
22
|
+
const tokenDeployments = await getTokenDeployments(hre)
|
23
|
+
const deployerSigner = await getDeployerSigner(hre)
|
24
|
+
|
25
|
+
const usdt_instance = getInstanceFromDeployment<StableCoin>(hre, tokenDeployments.USDT)
|
26
|
+
|
27
|
+
const uniswapV2Router_deployment = await hre.deployments.get('UniswapV2Router02')
|
28
|
+
const uniswapV2Router_instance = getInstanceFromDeployment<UniswapV2Router02>(
|
29
|
+
hre,
|
30
|
+
uniswapV2Router_deployment,
|
31
|
+
)
|
32
|
+
|
33
|
+
console.log('\nDeploying Mocked ChainLink Aggregators...')
|
34
|
+
|
35
|
+
async function deployMockedAggregator(
|
36
|
+
token: string,
|
37
|
+
tokenDeployment: Deployment,
|
38
|
+
args: any[] = [
|
39
|
+
8,
|
40
|
+
uniswapV2Router_instance.address,
|
41
|
+
tokenDeployment.address,
|
42
|
+
usdt_instance.address,
|
43
|
+
],
|
44
|
+
) {
|
45
|
+
const mockedAggregator = mockedAggregatorName(token, hre.network)
|
46
|
+
console.log(`Deploying ${mockedAggregator} ...`)
|
47
|
+
return await deployContract(hre, {
|
48
|
+
deploymentName: mockedAggregator,
|
49
|
+
from: deployerSigner.address,
|
50
|
+
args: args,
|
51
|
+
log: true,
|
52
|
+
skipIfAlreadyDeployed: true,
|
53
|
+
contract: 'UFarmMockV3Aggregator',
|
54
|
+
})
|
55
|
+
}
|
56
|
+
|
57
|
+
async function getStETHOracleOrDeploy(): Promise<{
|
58
|
+
stETHUSD: Deployment
|
59
|
+
wstETHstETH: Deployment
|
60
|
+
}> {
|
61
|
+
const steth_oracle_deployment = await hre.deployments.getOrNull(
|
62
|
+
mockedAggregatorName('STETH', hre.network),
|
63
|
+
)
|
64
|
+
const lido_oracle_deployment = await hre.deployments.getOrNull(
|
65
|
+
'LidoRateOracle'
|
66
|
+
)
|
67
|
+
|
68
|
+
if (!steth_oracle_deployment || !lido_oracle_deployment) {
|
69
|
+
const steth_deployment = tokenDeployments.STETH
|
70
|
+
const wsteth_deployment = tokenDeployments.WSTETH
|
71
|
+
|
72
|
+
const stETHUSD = await deployMockedAggregator('STETH', steth_deployment, [
|
73
|
+
18,
|
74
|
+
uniswapV2Router_instance.address,
|
75
|
+
steth_deployment.address,
|
76
|
+
usdt_instance.address,
|
77
|
+
])
|
78
|
+
const wstETHstETH = await deployContract(hre, {
|
79
|
+
deploymentName: 'LidoRateOracle',
|
80
|
+
from: deployerSigner.address,
|
81
|
+
args: [wsteth_deployment.address],
|
82
|
+
log: true,
|
83
|
+
skipIfAlreadyDeployed: true,
|
84
|
+
contract: 'MockV3wstETHstETHAgg',
|
85
|
+
})
|
86
|
+
return {
|
87
|
+
stETHUSD,
|
88
|
+
wstETHstETH,
|
89
|
+
}
|
90
|
+
} else {
|
91
|
+
return {
|
92
|
+
stETHUSD: steth_oracle_deployment,
|
93
|
+
wstETHstETH: lido_oracle_deployment,
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
console.log(`AllTokens: ${Object.keys(tokenDeployments)}`)
|
99
|
+
|
100
|
+
for (const [token, deployment] of Object.entries(tokenDeployments)) {
|
101
|
+
if (token === 'STETH') {
|
102
|
+
console.log('Skipping STETH Aggregator')
|
103
|
+
continue
|
104
|
+
}
|
105
|
+
|
106
|
+
const aggregatorName = mockedAggregatorName(token, hre.network)
|
107
|
+
|
108
|
+
console.log(`Deploying ${aggregatorName} ...`)
|
109
|
+
|
110
|
+
if (token === 'WSTETH') {
|
111
|
+
// Check for STETH oracle
|
112
|
+
const steth_oracle_deployment = await getStETHOracleOrDeploy()
|
113
|
+
} else {
|
114
|
+
await deployMockedAggregator(token, deployment)
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
console.log('\nMocked ChainLink Aggregators deployed!')
|
119
|
+
}
|
120
|
+
|
121
|
+
export default deployMockedAggregators
|
122
|
+
deployMockedAggregators.dependencies = _deployTags(['UniV2Pairs','Lido'])
|
123
|
+
deployMockedAggregators.tags = _deployTags(['MockedAggregators'])
|
@@ -0,0 +1,65 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
getDeployerSigner,
|
7
|
+
mockedAggregatorName,
|
8
|
+
_deployTags,
|
9
|
+
deployUpgradedContract,
|
10
|
+
retryOperation,
|
11
|
+
replaceUpdatedContract,
|
12
|
+
} from '../scripts/_deploy_helpers'
|
13
|
+
|
14
|
+
const deployWstETHOracle: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
15
|
+
const deployerSigner = await getDeployerSigner(hre)
|
16
|
+
|
17
|
+
console.log('\nDeploying WstETHOracle...')
|
18
|
+
|
19
|
+
const wsteth_deployment = await hre.deployments.get('WSTETH')
|
20
|
+
const stethUSD_oracle_deployment = await hre.deployments.get(
|
21
|
+
mockedAggregatorName('STETH', hre.network),
|
22
|
+
)
|
23
|
+
const LidoRateOracle = await hre.deployments.get('LidoRateOracle')
|
24
|
+
|
25
|
+
const wstethOracleDeployments = await deployUpgradedContract(hre, {
|
26
|
+
deploymentName: 'WSTETHOracle',
|
27
|
+
from: deployerSigner.address,
|
28
|
+
args: [wsteth_deployment.address, stethUSD_oracle_deployment.address, LidoRateOracle.address],
|
29
|
+
log: true,
|
30
|
+
skipIfAlreadyDeployed: true,
|
31
|
+
contract: 'WstETHOracle',
|
32
|
+
})
|
33
|
+
|
34
|
+
const ufarmCore_deployment = await hre.deployments.getOrNull('UFarmCore')
|
35
|
+
|
36
|
+
if (ufarmCore_deployment) {
|
37
|
+
if (wstethOracleDeployments.newDeployment) {
|
38
|
+
const ufarmCore_instance = await hre.ethers.getContractAt(
|
39
|
+
'UFarmCore',
|
40
|
+
ufarmCore_deployment.address,
|
41
|
+
deployerSigner,
|
42
|
+
)
|
43
|
+
const existingWstETHOracle = await ufarmCore_instance.tokenInfo(wsteth_deployment.address)
|
44
|
+
// if new oracle is deployed, update it in UFarmCore
|
45
|
+
if (
|
46
|
+
existingWstETHOracle.priceFeed.feedAddr !== wstethOracleDeployments.newDeployment.address
|
47
|
+
) {
|
48
|
+
if (existingWstETHOracle.priceFeed.feedAddr !== hre.ethers.constants.AddressZero) {
|
49
|
+
console.log(`Removing WstETHOracle from UFarmCore...`)
|
50
|
+
await retryOperation(async () => {
|
51
|
+
await ufarmCore_instance.blacklistTokens([wsteth_deployment.address])
|
52
|
+
}, 3)
|
53
|
+
console.log(`WstETH blacklisted in UFarmCore.`)
|
54
|
+
await replaceUpdatedContract(hre, 'WSTETHOracle')
|
55
|
+
} else {
|
56
|
+
console.log('WstETH is not whitelisted in UFarmCore yet.')
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
export default deployWstETHOracle
|
64
|
+
deployWstETHOracle.dependencies = _deployTags(['MockedAggregators'])
|
65
|
+
deployWstETHOracle.tags = _deployTags(['WstETHOracle'])
|
@@ -0,0 +1,80 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
deployContract,
|
7
|
+
isTestnet,
|
8
|
+
getTokenDeployments,
|
9
|
+
getDeployerSigner,
|
10
|
+
getInstanceFromDeployment,
|
11
|
+
_deployTags,
|
12
|
+
} from '../scripts/_deploy_helpers'
|
13
|
+
import { ethers } from 'hardhat'
|
14
|
+
import { UniswapV3Factory } from '../typechain-types'
|
15
|
+
|
16
|
+
const deployUniV3: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
17
|
+
if (!isTestnet(hre.network)){
|
18
|
+
console.log(`Skipping Uniswap V3 deployment`)
|
19
|
+
return
|
20
|
+
}
|
21
|
+
|
22
|
+
const tokenDeployments = await getTokenDeployments(hre)
|
23
|
+
const weth_deployment = tokenDeployments.WETH
|
24
|
+
|
25
|
+
console.log('\nDeploying UniswapV3...')
|
26
|
+
|
27
|
+
const deployerSigner = await getDeployerSigner(hre)
|
28
|
+
|
29
|
+
const uniswapV3Factory_deployment = await deployContract(hre, {
|
30
|
+
deploymentName: 'UniswapV3Factory',
|
31
|
+
from: deployerSigner.address,
|
32
|
+
args: [],
|
33
|
+
log: true,
|
34
|
+
skipIfAlreadyDeployed: true,
|
35
|
+
contract: 'UniswapV3Factory',
|
36
|
+
})
|
37
|
+
|
38
|
+
const uniswapV3Factory_instance = await getInstanceFromDeployment<UniswapV3Factory>(
|
39
|
+
hre,
|
40
|
+
uniswapV3Factory_deployment,
|
41
|
+
)
|
42
|
+
if ((await uniswapV3Factory_instance.feeAmountTickSpacing(100)) == 0)
|
43
|
+
await (await uniswapV3Factory_instance.connect(deployerSigner).enableFeeAmount(100, 1)).wait()
|
44
|
+
|
45
|
+
const uniswapV3_SwapRouter_deployment = await deployContract(hre, {
|
46
|
+
deploymentName: 'SwapRouter',
|
47
|
+
from: deployerSigner.address,
|
48
|
+
args: [uniswapV3Factory_deployment.address, weth_deployment.address],
|
49
|
+
log: true,
|
50
|
+
skipIfAlreadyDeployed: true,
|
51
|
+
contract: 'SwapRouter',
|
52
|
+
})
|
53
|
+
|
54
|
+
const uniswapV3_NonfungiblePositionManager_deployment = await deployContract(hre, {
|
55
|
+
deploymentName: 'NonfungiblePositionManager',
|
56
|
+
from: deployerSigner.address,
|
57
|
+
args: [
|
58
|
+
uniswapV3Factory_deployment.address,
|
59
|
+
weth_deployment.address,
|
60
|
+
ethers.constants.AddressZero,
|
61
|
+
],
|
62
|
+
log: true,
|
63
|
+
skipIfAlreadyDeployed: true,
|
64
|
+
contract: 'NonfungiblePositionManager',
|
65
|
+
})
|
66
|
+
|
67
|
+
const uniswapV3_Quoter_deployment = await deployContract(hre, {
|
68
|
+
deploymentName: 'QuoterV2',
|
69
|
+
from: deployerSigner.address,
|
70
|
+
args: [uniswapV3Factory_deployment.address, weth_deployment.address],
|
71
|
+
log: true,
|
72
|
+
skipIfAlreadyDeployed: true,
|
73
|
+
contract: 'QuoterV2',
|
74
|
+
})
|
75
|
+
console.log('\nUniswapV3 deployed!')
|
76
|
+
}
|
77
|
+
|
78
|
+
export default deployUniV3
|
79
|
+
deployUniV3.dependencies = _deployTags(['Tokens'])
|
80
|
+
deployUniV3.tags = _deployTags(['UniV3'])
|
@@ -0,0 +1,140 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
|
6
|
+
import {
|
7
|
+
isTestnet,
|
8
|
+
getTokenDeployments,
|
9
|
+
retryOperation,
|
10
|
+
getInstanceFromDeployment,
|
11
|
+
getDeployerSigner,
|
12
|
+
_deployTags,
|
13
|
+
} from '../scripts/_deploy_helpers'
|
14
|
+
import { BigNumberish } from 'ethers'
|
15
|
+
import { NonfungiblePositionManager, StableCoin, UniswapV3Factory, WETH9 } from '../typechain-types'
|
16
|
+
import {
|
17
|
+
MintableToken,
|
18
|
+
addLiquidityUniswapV3,
|
19
|
+
} from '../test/_helpers'
|
20
|
+
|
21
|
+
const createUniV3Pairs: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
22
|
+
async function isUniswapV3PairExist(
|
23
|
+
factoryContract: UniswapV3Factory,
|
24
|
+
token0Address: string,
|
25
|
+
token1Address: string,
|
26
|
+
fee: number,
|
27
|
+
): Promise<boolean> {
|
28
|
+
try {
|
29
|
+
const pairAddress = await factoryContract.getPool(token0Address, token1Address, fee)
|
30
|
+
return pairAddress !== hre.ethers.constants.AddressZero
|
31
|
+
} catch (error) {
|
32
|
+
console.error('Error checking pair existence:', error)
|
33
|
+
return false
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
async function checkAndCreateUniV3Pair(
|
38
|
+
token0Contract: MintableToken,
|
39
|
+
token1Contract: MintableToken,
|
40
|
+
amount0: BigNumberish,
|
41
|
+
amount1: BigNumberish,
|
42
|
+
fee: number,
|
43
|
+
signer: SignerWithAddress,
|
44
|
+
factoryContract: UniswapV3Factory,
|
45
|
+
positionManager: NonfungiblePositionManager,
|
46
|
+
maxRetries: number,
|
47
|
+
): Promise<void> {
|
48
|
+
const token0Address = token0Contract.address
|
49
|
+
const token1Address = token1Contract.address
|
50
|
+
|
51
|
+
const [token0Symbol, token1Symbol] = await Promise.all([
|
52
|
+
token0Contract.symbol(),
|
53
|
+
token1Contract.symbol(),
|
54
|
+
])
|
55
|
+
|
56
|
+
const pairName = `${token0Symbol}/${token1Symbol}`
|
57
|
+
|
58
|
+
if (await isUniswapV3PairExist(factoryContract, token0Address, token1Address, fee)) {
|
59
|
+
console.log(`${pairName} pair already exists!`)
|
60
|
+
} else {
|
61
|
+
console.log(`Creating ${pairName} pair...`)
|
62
|
+
|
63
|
+
await retryOperation(async () => {
|
64
|
+
await addLiquidityUniswapV3(
|
65
|
+
token0Contract,
|
66
|
+
token1Contract,
|
67
|
+
amount0,
|
68
|
+
amount1,
|
69
|
+
factoryContract,
|
70
|
+
positionManager,
|
71
|
+
signer,
|
72
|
+
fee,
|
73
|
+
)
|
74
|
+
}, maxRetries)
|
75
|
+
console.log(`${pairName} pair created!`)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if (!isTestnet(hre.network)){
|
80
|
+
console.log(`Skipping Uniswap V3 pairs creation`)
|
81
|
+
return
|
82
|
+
}
|
83
|
+
|
84
|
+
const tokenDeployments = await getTokenDeployments(hre)
|
85
|
+
const deployerSigner = await getDeployerSigner(hre)
|
86
|
+
|
87
|
+
const uniV3Factory_deployment = await hre.deployments.get('UniswapV3Factory')
|
88
|
+
const nfpm_deployment = await hre.deployments.get('NonfungiblePositionManager')
|
89
|
+
|
90
|
+
const uniV3Factory_instance = getInstanceFromDeployment<UniswapV3Factory>(
|
91
|
+
hre,
|
92
|
+
uniV3Factory_deployment,
|
93
|
+
)
|
94
|
+
const nfpm_instance = getInstanceFromDeployment<NonfungiblePositionManager>(
|
95
|
+
hre,
|
96
|
+
nfpm_deployment,
|
97
|
+
)
|
98
|
+
|
99
|
+
const allPairs = hre.testnetDeployConfig.initialRates
|
100
|
+
|
101
|
+
async function createV3PairForTokens(rate: typeof allPairs[0]) {
|
102
|
+
const [token0Name, token1Name] = [rate.rawName0, rate.rawName1]
|
103
|
+
const [token0_instance, token1_instance] = [
|
104
|
+
getInstanceFromDeployment<MintableToken>(hre, tokenDeployments[token0Name]),
|
105
|
+
getInstanceFromDeployment<MintableToken>(hre, tokenDeployments[token1Name]),
|
106
|
+
]
|
107
|
+
|
108
|
+
const [decimals0, decimals1] = await Promise.all([
|
109
|
+
token0_instance.decimals(),
|
110
|
+
token1_instance.decimals(),
|
111
|
+
])
|
112
|
+
|
113
|
+
console.log(`decimals0: ${decimals0}, decimals1: ${decimals1}`)
|
114
|
+
|
115
|
+
await checkAndCreateUniV3Pair(
|
116
|
+
token0_instance,
|
117
|
+
token1_instance,
|
118
|
+
rate.amount0,
|
119
|
+
rate.amount1,
|
120
|
+
3000,
|
121
|
+
deployerSigner,
|
122
|
+
uniV3Factory_instance,
|
123
|
+
nfpm_instance,
|
124
|
+
3,
|
125
|
+
)
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
console.log('\nCreating UniswapV3 pairs...')
|
130
|
+
|
131
|
+
for (const rate of allPairs) {
|
132
|
+
await createV3PairForTokens(rate)
|
133
|
+
}
|
134
|
+
|
135
|
+
console.log('\nUniswapV3 pairs created!')
|
136
|
+
}
|
137
|
+
|
138
|
+
export default createUniV3Pairs
|
139
|
+
createUniV3Pairs.dependencies = _deployTags(['UniV3', 'Tokens'])
|
140
|
+
createUniV3Pairs.tags = _deployTags(['UniV3Pairs'])
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
isTestnet,
|
7
|
+
deployContract,
|
8
|
+
getInstanceFromDeployment,
|
9
|
+
getDeployerSigner,
|
10
|
+
_deployTags,
|
11
|
+
} from '../scripts/_deploy_helpers'
|
12
|
+
|
13
|
+
const deployOneInch: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
14
|
+
if (!isTestnet(hre.network)){
|
15
|
+
console.log(`Skipping OneInch deployment`)
|
16
|
+
return
|
17
|
+
}
|
18
|
+
|
19
|
+
const deployerSigner = await getDeployerSigner(hre)
|
20
|
+
const weth_deployment = await hre.deployments.get('WETH')
|
21
|
+
|
22
|
+
console.log('\nDeploying OneInch...')
|
23
|
+
|
24
|
+
const oneInchV5Aggregator_deployment = await deployContract(hre, {
|
25
|
+
deploymentName: 'AggregationRouterV5',
|
26
|
+
from: deployerSigner.address,
|
27
|
+
args: [weth_deployment.address],
|
28
|
+
log: true,
|
29
|
+
skipIfAlreadyDeployed: true,
|
30
|
+
contract: 'AggregationRouterV5',
|
31
|
+
})
|
32
|
+
|
33
|
+
console.log('\n OneInch deployed!')
|
34
|
+
}
|
35
|
+
|
36
|
+
export default deployOneInch
|
37
|
+
deployOneInch.dependencies = _deployTags(['Tokens'])
|
38
|
+
deployOneInch.tags = _deployTags(['OneInch'])
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import { isTestnet, deployContract, getDeployerSigner, _deployTags } from '../scripts/_deploy_helpers'
|
6
|
+
|
7
|
+
const deployMulticall: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
8
|
+
if (!isTestnet(hre.network)){
|
9
|
+
console.log(`Skipping Multicall3 deployment`)
|
10
|
+
return
|
11
|
+
}
|
12
|
+
|
13
|
+
const deployerSigner = await getDeployerSigner(hre)
|
14
|
+
|
15
|
+
const deployerAddr = deployerSigner.address
|
16
|
+
const deployerBalance = await deployerSigner.getBalance()
|
17
|
+
console.log(`Deployer address: ${deployerAddr}\nDeployer balance: ${deployerBalance.toString()}`)
|
18
|
+
|
19
|
+
console.log('\nDeploying Multicall3...')
|
20
|
+
|
21
|
+
const multicallDeployment = await deployContract(hre, {
|
22
|
+
deploymentName: 'Multicall3',
|
23
|
+
from: deployerSigner.address,
|
24
|
+
log: true,
|
25
|
+
skipIfAlreadyDeployed: true,
|
26
|
+
contract: 'Multicall3',
|
27
|
+
})
|
28
|
+
|
29
|
+
console.log('\n Multicall3 deployed!')
|
30
|
+
}
|
31
|
+
|
32
|
+
export default deployMulticall
|
33
|
+
deployMulticall.dependencies = []
|
34
|
+
deployMulticall.tags = _deployTags(['Multicall3'])
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
deployProxyContract,
|
7
|
+
getDeployerSigner,
|
8
|
+
getPriceOracleContract,
|
9
|
+
_deployTags,
|
10
|
+
} from '../scripts/_deploy_helpers'
|
11
|
+
|
12
|
+
const deployPriceOracle: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
13
|
+
const deployerSigner = await getDeployerSigner(hre)
|
14
|
+
|
15
|
+
console.log('\nDeploying PriceOracle...')
|
16
|
+
const priceOracleContract = getPriceOracleContract(hre.network)
|
17
|
+
await deployProxyContract(
|
18
|
+
hre,
|
19
|
+
priceOracleContract.contract,
|
20
|
+
deployerSigner,
|
21
|
+
undefined,
|
22
|
+
{
|
23
|
+
kind: 'uups',
|
24
|
+
},
|
25
|
+
'PriceOracle',
|
26
|
+
)
|
27
|
+
|
28
|
+
console.log(`\n ${priceOracleContract.contract} deployed!`)
|
29
|
+
}
|
30
|
+
|
31
|
+
export default deployPriceOracle
|
32
|
+
deployPriceOracle.dependencies = _deployTags([])
|
33
|
+
deployPriceOracle.tags = _deployTags(['PriceOracle'])
|
@@ -0,0 +1,114 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import {
|
6
|
+
isTestnet,
|
7
|
+
deployContract,
|
8
|
+
getDeployerSigner,
|
9
|
+
_deployTags,
|
10
|
+
getNetworkType,
|
11
|
+
isMainnet,
|
12
|
+
} from '../scripts/_deploy_helpers'
|
13
|
+
|
14
|
+
const deployLido: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
15
|
+
if (!isTestnet(hre.network)) {
|
16
|
+
console.log(`Skipping Lido deployment`)
|
17
|
+
return
|
18
|
+
}
|
19
|
+
|
20
|
+
if (getNetworkType(hre.network) === 'arbitrumSepolia' || isMainnet(hre.network)) {
|
21
|
+
console.log('Skipping Lido deployment')
|
22
|
+
return
|
23
|
+
}
|
24
|
+
|
25
|
+
const deployerSigner = await getDeployerSigner(hre)
|
26
|
+
|
27
|
+
console.log('\nDeploying Lido...')
|
28
|
+
|
29
|
+
const lido_deposit = await deployContract(hre, {
|
30
|
+
deploymentName: 'DepositContractMock',
|
31
|
+
from: deployerSigner.address,
|
32
|
+
log: true,
|
33
|
+
skipIfAlreadyDeployed: true,
|
34
|
+
contract: 'DepositContractMock',
|
35
|
+
})
|
36
|
+
|
37
|
+
const lido_registry = await deployContract(hre, {
|
38
|
+
deploymentName: 'NodeOperatorsRegistry',
|
39
|
+
from: deployerSigner.address,
|
40
|
+
log: true,
|
41
|
+
skipIfAlreadyDeployed: true,
|
42
|
+
contract: 'NodeOperatorsRegistry',
|
43
|
+
})
|
44
|
+
|
45
|
+
const steth = await deployContract(hre, {
|
46
|
+
deploymentName: 'STETH',
|
47
|
+
from: deployerSigner.address,
|
48
|
+
log: true,
|
49
|
+
skipIfAlreadyDeployed: true,
|
50
|
+
contract: 'Lido',
|
51
|
+
args: [
|
52
|
+
lido_deposit.address,
|
53
|
+
deployerSigner.address,
|
54
|
+
lido_registry.address,
|
55
|
+
deployerSigner.address,
|
56
|
+
deployerSigner.address,
|
57
|
+
],
|
58
|
+
})
|
59
|
+
|
60
|
+
const wsteth = await deployContract(hre, {
|
61
|
+
deploymentName: 'WSTETH',
|
62
|
+
from: deployerSigner.address,
|
63
|
+
log: true,
|
64
|
+
skipIfAlreadyDeployed: true,
|
65
|
+
contract: 'WstETH',
|
66
|
+
args: [steth.address],
|
67
|
+
})
|
68
|
+
|
69
|
+
console.log('\n Lido contracts deployed!')
|
70
|
+
|
71
|
+
const randomBytes = hre.ethers.utils.randomBytes(32)
|
72
|
+
const withdrawalCredentials = hre.ethers.utils.hexlify(randomBytes)
|
73
|
+
const withdrawalCredentialsSet: boolean =
|
74
|
+
(await hre.deployments.read('STETH', 'getWithdrawalCredentials')) ===
|
75
|
+
hre.ethers.constants.HashZero
|
76
|
+
|
77
|
+
if (!withdrawalCredentialsSet) {
|
78
|
+
await hre.deployments.execute(
|
79
|
+
'NodeOperatorsRegistry',
|
80
|
+
{ from: deployerSigner.address, log: true },
|
81
|
+
'setLido',
|
82
|
+
steth.address,
|
83
|
+
)
|
84
|
+
await hre.deployments.execute(
|
85
|
+
'STETH',
|
86
|
+
{ from: deployerSigner.address, log: true },
|
87
|
+
'setWithdrawalCredentials',
|
88
|
+
withdrawalCredentials,
|
89
|
+
)
|
90
|
+
}
|
91
|
+
|
92
|
+
const currentOracle = (await hre.deployments.read('STETH', 'getOracle')) as string
|
93
|
+
if (currentOracle !== deployerSigner.address)
|
94
|
+
await hre.deployments.execute(
|
95
|
+
'STETH',
|
96
|
+
{ from: deployerSigner.address, log: true },
|
97
|
+
'setOracle',
|
98
|
+
deployerSigner.address,
|
99
|
+
)
|
100
|
+
|
101
|
+
const currentFee = (await hre.deployments.read('STETH', 'getFee')) as string
|
102
|
+
if (parseInt(currentFee) !== 0)
|
103
|
+
await hre.deployments.execute('STETH', { from: deployerSigner.address, log: true }, 'setFee', 0)
|
104
|
+
|
105
|
+
const isLidoStopped = (await hre.deployments.read('STETH', 'isStopped')) as boolean
|
106
|
+
if (isLidoStopped)
|
107
|
+
await hre.deployments.execute('STETH', { from: deployerSigner.address, log: true }, 'resume')
|
108
|
+
|
109
|
+
console.log('\n Lido contracts activated!\n')
|
110
|
+
}
|
111
|
+
|
112
|
+
export default deployLido
|
113
|
+
deployLido.dependencies = []
|
114
|
+
deployLido.tags = _deployTags(['Lido'])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import { getDeployerSigner, deployBeaconContract, _deployTags } from '../scripts/_deploy_helpers'
|
6
|
+
|
7
|
+
const deployPool: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
8
|
+
const deployerSigner = await getDeployerSigner(hre)
|
9
|
+
|
10
|
+
console.log('\nDeploying UFarmPool...')
|
11
|
+
|
12
|
+
await deployBeaconContract(hre, 'UFarmPool', deployerSigner)
|
13
|
+
|
14
|
+
console.log('\n UFarmPool deployed!')
|
15
|
+
}
|
16
|
+
|
17
|
+
export default deployPool
|
18
|
+
deployPool.dependencies = []
|
19
|
+
deployPool.tags = _deployTags(['UFarmPool'])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import { getDeployerSigner, deployBeaconContract, _deployTags } from '../scripts/_deploy_helpers'
|
6
|
+
|
7
|
+
const deployPoolAdmin: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
8
|
+
const deployerSigner = await getDeployerSigner(hre)
|
9
|
+
|
10
|
+
console.log('\nDeploying PoolAdmin...')
|
11
|
+
|
12
|
+
await deployBeaconContract(hre, 'PoolAdmin', deployerSigner)
|
13
|
+
|
14
|
+
console.log('\n PoolAdmin deployed!')
|
15
|
+
}
|
16
|
+
|
17
|
+
export default deployPoolAdmin
|
18
|
+
deployPoolAdmin.dependencies = []
|
19
|
+
deployPoolAdmin.tags = _deployTags(['PoolAdmin'])
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
2
|
+
|
3
|
+
import { DeployFunction } from 'hardhat-deploy/types'
|
4
|
+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
|
5
|
+
import { isTestnet, getDeployerSigner, deployProxyContract, _deployTags } from '../scripts/_deploy_helpers'
|
6
|
+
|
7
|
+
const deployUFarmCore: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
8
|
+
const deployerSigner = await getDeployerSigner(hre)
|
9
|
+
|
10
|
+
console.log('\nDeploying UFarmCore...')
|
11
|
+
|
12
|
+
const currentUFarmCoreDeployment = await hre.deployments.getOrNull('UFarmCore')
|
13
|
+
|
14
|
+
if (currentUFarmCoreDeployment) {
|
15
|
+
console.log(`Already deployed at: ${currentUFarmCoreDeployment.address}`)
|
16
|
+
} else {
|
17
|
+
const res = await deployProxyContract(hre, 'UFarmCore', deployerSigner, undefined, {
|
18
|
+
kind: 'uups',
|
19
|
+
})
|
20
|
+
|
21
|
+
console.log(`UFarmCore deployed at: ${res.address}`)
|
22
|
+
}
|
23
|
+
|
24
|
+
console.log('\n UFarmCore deployed!')
|
25
|
+
}
|
26
|
+
|
27
|
+
export default deployUFarmCore
|
28
|
+
deployUFarmCore.dependencies = []
|
29
|
+
deployUFarmCore.tags = _deployTags(['UFarmCore'])
|