Skip to content

Commit f51cb56

Browse files
committed
Make deployable to testnets
1 parent bba4e78 commit f51cb56

File tree

12 files changed

+140
-39
lines changed

12 files changed

+140
-39
lines changed

.env.example

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Contracts admin.
22
ADMIN=
3-
# Rebalance caller.
4-
REBALANCE_CALLER=
3+
# Address that can increase/decerease LP conversion rate.
4+
ADJUSTER=
55
# Deposits to Liquidity Hub are only allowed till this limit is reached.
66
ASSETS_LIMIT=
77
# Liquidity mining tiers. Multiplier will be divided by 100. So 175 will result in 1.75x.
@@ -12,8 +12,21 @@ TIER_2_SECONDS=15552000
1212
TIER_2_MULTIPLIER=80
1313
TIER_3_SECONDS=31104000
1414
TIER_3_MULTIPLIER=200
15+
# Rebalance caller.
16+
REBALANCE_CALLER=
17+
# Liquidity Pool parameters.
18+
MIN_HEALTH_FACTOR=500
19+
DEFAULT_LTV=20
20+
MPC_ADDRESS=
21+
WITHDRAW_PROFIT=
22+
# General deployment parameters.
1523
DEPLOYER_PRIVATE_KEY=
1624
VERIFY=false
25+
BASE_SEPOLIA_RPC=
26+
ETHEREUM_SEPOLIA_RPC=
27+
ETHERSCAN_BASE_SEPOLIA=
28+
ETHERSCAN_ETHEREUM_SEPOLIA=
29+
# Testing parameters.
1730
FORK_PROVIDER=https://eth-mainnet.public.blastapi.io
1831
USDC_OWNER_ADDRESS=0x7713974908Be4BEd47172370115e8b1219F4A5f0
1932
RPL_OWNER_ADDRESS=0xdC7b28976d6eb13082a5Be7C66f9dCFE0115738f

contracts/LiquidityPool.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ contract LiquidityPool is AccessControlUpgradeable, EIP712Upgradeable {
186186
userAccountData.ltv,
187187
userAccountData.healthFactor
188188
) = pool.getUserAccountData(address(this));
189-
if (userAccountData.healthFactor < _getStorage().minHealthFactor) revert HealthFactorTooLow();
189+
if (userAccountData.healthFactor < _getStorage().minHealthFactor) revert HealthFactorTooLow();
190190
emit WithdrawnFromAave(withdrawn);
191191
}
192192

contracts/testing/TestLiquidityPool.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
77

88
contract TestLiquidityPool is ILiquidityPool, AccessControl {
99
IERC20 public immutable COLLATERAL;
10+
bytes32 public constant LIQUIDITY_ADMIN_ROLE = "LIQUIDITY_ADMIN_ROLE";
1011

1112
event Deposit();
1213

1314
constructor(IERC20 collateral) {
1415
COLLATERAL = collateral;
1516
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
17+
_grantRole(LIQUIDITY_ADMIN_ROLE, _msgSender());
1618
}
1719

1820
function deposit() external override {
1921
emit Deposit();
2022
}
2123

22-
function withdraw(address to, uint256 amount) external override onlyRole(DEFAULT_ADMIN_ROLE) {
24+
function withdraw(address to, uint256 amount) external override onlyRole(LIQUIDITY_ADMIN_ROLE) {
2325
SafeERC20.safeTransfer(COLLATERAL, to, amount);
2426
}
2527
}

hardhat.config.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ function isSet(param?: string) {
1010
return param && param.length > 0;
1111
}
1212

13+
const accounts: string[] = isSet(process.env.DEPLOYER_PRIVATE_KEY) ? [process.env.DEPLOYER_PRIVATE_KEY || ""] : [];
14+
1315
const config: HardhatUserConfig = {
1416
solidity: {
1517
version: "0.8.28",
@@ -26,9 +28,13 @@ const config: HardhatUserConfig = {
2628
},
2729
[Network.BASE_SEPOLIA]: {
2830
chainId: networkConfig.BASE_SEPOLIA.chainId,
29-
url: "https://sepolia.base.org",
30-
accounts:
31-
isSet(process.env.DEPLOYER_PRIVATE_KEY) ? [process.env.DEPLOYER_PRIVATE_KEY || ""] : [],
31+
url: process.env.BASE_SEPOLIA_RPC || "https://sepolia.base.org",
32+
accounts,
33+
},
34+
[Network.ETHEREUM_SEPOLIA]: {
35+
chainId: networkConfig.ETHEREUM_SEPOLIA.chainId,
36+
url: process.env.ETHEREUM_SEPOLIA_RPC || "",
37+
accounts,
3238
},
3339
hardhat: {
3440
forking: {
@@ -37,7 +43,13 @@ const config: HardhatUserConfig = {
3743
},
3844
},
3945
sourcify: {
40-
enabled: true,
46+
enabled: false,
47+
},
48+
etherscan: {
49+
apiKey: {
50+
baseSepolia: process.env.ETHERSCAN_BASE_SEPOLIA || "",
51+
sepolia: process.env.ETHERSCAN_ETHEREUM_SEPOLIA || "",
52+
},
4153
},
4254
};
4355

network.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as AAVEPools from "@bgd-labs/aave-address-book";
2+
13
export enum Network {
24
ETHEREUM = "ETHEREUM",
35
AVALANCHE = "AVALANCHE",
@@ -34,6 +36,7 @@ export interface NetworkConfig {
3436
Routes?: RoutesConfig;
3537
IsTest: boolean;
3638
IsHub: boolean;
39+
Aave?: string;
3740
};
3841

3942
type NetworksConfig = {
@@ -54,6 +57,7 @@ export const networkConfig: NetworksConfig = {
5457
Domains: [Network.BASE],
5558
Providers: [Provider.CCTP],
5659
},
60+
Aave: AAVEPools.AaveV3Ethereum.POOL_ADDRESSES_PROVIDER,
5761
},
5862
AVALANCHE: {
5963
chainId: 43114,
@@ -64,6 +68,7 @@ export const networkConfig: NetworksConfig = {
6468
USDC: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
6569
IsTest: false,
6670
IsHub: false,
71+
Aave: AAVEPools.AaveV3Avalanche.POOL_ADDRESSES_PROVIDER,
6772
},
6873
OP_MAINNET: {
6974
chainId: 10,
@@ -74,6 +79,7 @@ export const networkConfig: NetworksConfig = {
7479
USDC: "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
7580
IsTest: false,
7681
IsHub: false,
82+
Aave: AAVEPools.AaveV3Optimism.POOL_ADDRESSES_PROVIDER,
7783
},
7884
ARBITRUM_ONE: {
7985
chainId: 42161,
@@ -84,6 +90,7 @@ export const networkConfig: NetworksConfig = {
8490
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
8591
IsTest: false,
8692
IsHub: false,
93+
Aave: AAVEPools.AaveV3Arbitrum.POOL_ADDRESSES_PROVIDER,
8794
},
8895
BASE: {
8996
chainId: 8453,
@@ -98,6 +105,7 @@ export const networkConfig: NetworksConfig = {
98105
Domains: [Network.ETHEREUM],
99106
Providers: [Provider.CCTP],
100107
},
108+
Aave: AAVEPools.AaveV3Base.POOL_ADDRESSES_PROVIDER,
101109
},
102110
POLYGON_MAINNET: {
103111
chainId: 137,
@@ -108,6 +116,7 @@ export const networkConfig: NetworksConfig = {
108116
USDC: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
109117
IsTest: false,
110118
IsHub: false,
119+
Aave: AAVEPools.AaveV3Polygon.POOL_ADDRESSES_PROVIDER,
111120
},
112121
ETHEREUM_SEPOLIA: {
113122
chainId: 11155111,
@@ -122,6 +131,7 @@ export const networkConfig: NetworksConfig = {
122131
Domains: [Network.BASE_SEPOLIA],
123132
Providers: [Provider.CCTP],
124133
},
134+
Aave: AAVEPools.AaveV3Sepolia.POOL_ADDRESSES_PROVIDER,
125135
},
126136
AVALANCHE_FUJI: {
127137
chainId: 43113,
@@ -132,6 +142,7 @@ export const networkConfig: NetworksConfig = {
132142
USDC: "0x5425890298aed601595a70ab815c96711a31bc65",
133143
IsTest: true,
134144
IsHub: false,
145+
Aave: AAVEPools.AaveV3Fuji.POOL_ADDRESSES_PROVIDER,
135146
},
136147
OP_SEPOLIA: {
137148
chainId: 11155420,
@@ -142,6 +153,7 @@ export const networkConfig: NetworksConfig = {
142153
USDC: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7",
143154
IsTest: true,
144155
IsHub: false,
156+
Aave: AAVEPools.AaveV3OptimismSepolia.POOL_ADDRESSES_PROVIDER,
145157
},
146158
ARBITRUM_SEPOLIA: {
147159
chainId: 421614,
@@ -152,6 +164,7 @@ export const networkConfig: NetworksConfig = {
152164
USDC: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
153165
IsTest: true,
154166
IsHub: false,
167+
Aave: AAVEPools.AaveV3ArbitrumSepolia.POOL_ADDRESSES_PROVIDER,
155168
},
156169
BASE_SEPOLIA: {
157170
chainId: 84532,
@@ -166,6 +179,7 @@ export const networkConfig: NetworksConfig = {
166179
Domains: [Network.ETHEREUM_SEPOLIA],
167180
Providers: [Provider.CCTP],
168181
},
182+
Aave: AAVEPools.AaveV3BaseSepolia.POOL_ADDRESSES_PROVIDER,
169183
},
170184
POLYGON_AMOY: {
171185
chainId: 80002,

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"deploy": "hardhat run ./scripts/deploy.ts",
99
"deploy-local": "hardhat run ./scripts/deploy.ts --network localhost",
1010
"deploy-basesepolia": "hardhat run ./scripts/deploy.ts --network BASE_SEPOLIA",
11+
"deploy-ethereumsepolia": "hardhat run ./scripts/deploy.ts --network ETHEREUM_SEPOLIA",
1112
"node": "hardhat node",
1213
"hardhat": "hardhat",
1314
"lint": "npm run lint:solidity && npm run lint:ts",
@@ -42,6 +43,7 @@
4243
"typescript-eslint": "^8.19.1"
4344
},
4445
"dependencies": {
46+
"@bgd-labs/aave-address-book": "^4.10.0",
4547
"@openzeppelin/contracts": "^5.1.0",
4648
"@openzeppelin/contracts-upgradeable": "^5.1.0"
4749
}

scripts/deploy.ts

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
import dotenv from "dotenv";
22
dotenv.config();
3-
43
import hre from "hardhat";
54
import {isAddress, MaxUint256, getBigInt} from "ethers";
6-
import {ZERO_BYTES32} from "../test/helpers";
5+
import {toBytes32} from "../test/helpers";
76
import {
87
assert, getVerifier, isSet, ProviderSolidity, DomainSolidity, deployProxy,
98
getProxyCreateAddress,
109
} from "./helpers";
1110
import {
1211
TestUSDC, SprinterUSDCLPShare, LiquidityHub,
13-
TestLiquidityPool, SprinterLiquidityMining, TestCCTPTokenMessenger, TestCCTPMessageTransmitter,
14-
Rebalancer,
12+
SprinterLiquidityMining, TestCCTPTokenMessenger, TestCCTPMessageTransmitter,
13+
Rebalancer, LiquidityPool,
1514
} from "../typechain-types";
1615
import {networkConfig, Network, Provider, NetworkConfig} from "../network.config";
1716

1817
async function main() {
18+
// Rework granting admin roles on deployments so that deployer does not have to be admin.
1919
const [deployer] = await hre.ethers.getSigners();
2020
const admin: string = isAddress(process.env.ADMIN) ? process.env.ADMIN : deployer.address;
21-
const rebalanceCaller: string = isAddress(process.env.REBALANCE_CALLER) ?
22-
process.env.REBALANCE_CALLER : deployer.address;
2321
const adjuster: string = isAddress(process.env.ADJUSTER) ? process.env.ADJUSTER : deployer.address;
2422
const maxLimit: bigint = MaxUint256 / 10n ** 12n;
2523
const assetsLimit: bigint = getBigInt(process.env.ASSETS_LIMIT || maxLimit);
2624

25+
const rebalanceCaller: string = isAddress(process.env.REBALANCE_CALLER) ?
26+
process.env.REBALANCE_CALLER : deployer.address;
27+
28+
const mpcAddress: string = isAddress(process.env.MPC_ADDRESS) ?
29+
process.env.MPC_ADDRESS : deployer.address;
30+
const withdrawProfit: string = isAddress(process.env.WITHDRAW_PROFIT) ?
31+
process.env.WITHDRAW_PROFIT : deployer.address;
32+
const minHealthFactor: bigint = getBigInt(process.env.MIN_HEALTH_FACTOR || 500n) * 10n ** 18n / 100n;
33+
const defaultLTV: bigint = getBigInt(process.env.DEFAULT_LTV || 20n) * 10n ** 18n / 100n;
34+
35+
const LIQUIDITY_ADMIN_ROLE = toBytes32("LIQUIDITY_ADMIN_ROLE");
36+
const WITHDRAW_PROFIT_ROLE = toBytes32("WITHDRAW_PROFIT_ROLE");
37+
2738
const verifier = getVerifier();
2839

2940
let config: NetworkConfig;
3041
if (Object.values(Network).includes(hre.network.name as Network)) {
3142
config = networkConfig[hre.network.name as Network];
3243
} else {
44+
console.log("TEST: Using TEST USDC and CCTP");
3345
const testUSDC = (await verifier.deploy("TestUSDC", deployer)) as TestUSDC;
3446
const cctpTokenMessenger = (await verifier.deploy("TestCCTPTokenMessenger", deployer)) as TestCCTPTokenMessenger;
3547
const cctpMessageTransmitter = (
@@ -51,8 +63,27 @@ async function main() {
5163
};
5264
}
5365

54-
console.log("TEST: Using TEST Liquidity Pool");
55-
const liquidityPool = (await verifier.deploy("TestLiquidityPool", deployer, {}, config.USDC)) as TestLiquidityPool;
66+
let liquidityPool: LiquidityPool;
67+
if (config.Aave) {
68+
const {target, targetAdmin: liquidityPoolAdmin} = await deployProxy<LiquidityPool>(
69+
verifier.deploy,
70+
"LiquidityPool",
71+
deployer,
72+
admin,
73+
[config.USDC, config.Aave],
74+
[
75+
admin,
76+
minHealthFactor,
77+
defaultLTV,
78+
mpcAddress,
79+
],
80+
);
81+
liquidityPool = target;
82+
console.log(`LiquidityPoolProxyAdmin: ${liquidityPoolAdmin.target}`);
83+
} else {
84+
console.log("TEST: Using TEST Liquidity Pool");
85+
liquidityPool = (await verifier.deploy("TestLiquidityPool", deployer, {}, [config.USDC])) as LiquidityPool;
86+
}
5687

5788
const rebalancerVersion = config.IsTest ? "TestRebalancer" : "Rebalancer";
5889

@@ -70,10 +101,8 @@ async function main() {
70101
],
71102
);
72103

73-
const DEFAULT_ADMIN_ROLE = ZERO_BYTES32;
74-
75-
console.log("TEST: Using default admin role for Rebalancer on Pool");
76-
await liquidityPool.grantRole(DEFAULT_ADMIN_ROLE, rebalancer);
104+
await liquidityPool.grantRole(LIQUIDITY_ADMIN_ROLE, rebalancer);
105+
await liquidityPool.grantRole(WITHDRAW_PROFIT_ROLE, withdrawProfit);
77106

78107
if (config.IsHub) {
79108
const tiers = [];
@@ -94,9 +123,13 @@ async function main() {
94123
const startingNonce = await deployer.getNonce();
95124

96125
const liquidityHubAddress = await getProxyCreateAddress(deployer, startingNonce + 1);
97-
const lpToken = (
98-
await verifier.deploy("SprinterUSDCLPShare", deployer, {nonce: startingNonce + 0}, liquidityHubAddress)
99-
) as SprinterUSDCLPShare;
126+
const lpToken = (await verifier.deploy(
127+
"SprinterUSDCLPShare",
128+
deployer,
129+
{},
130+
[liquidityHubAddress],
131+
"contracts/SprinterUSDCLPShare.sol:SprinterUSDCLPShare"
132+
)) as SprinterUSDCLPShare;
100133

101134
const {target: liquidityHub, targetAdmin: liquidityHubAdmin} = await deployProxy<LiquidityHub>(
102135
verifier.deploy,
@@ -109,13 +142,11 @@ async function main() {
109142

110143
assert(liquidityHubAddress == liquidityHub.target, "LiquidityHub address mismatch");
111144
const liquidityMining = (
112-
await verifier.deploy("SprinterLiquidityMining", deployer, {}, admin, liquidityHub, tiers)
145+
await verifier.deploy("SprinterLiquidityMining", deployer, {}, [admin, liquidityHub, tiers])
113146
) as SprinterLiquidityMining;
114147

115-
console.log("TEST: Using default admin role for Hub on Pool");
116-
await liquidityPool.grantRole(DEFAULT_ADMIN_ROLE, liquidityHub);
148+
await liquidityPool.grantRole(LIQUIDITY_ADMIN_ROLE, liquidityHub);
117149

118-
console.log();
119150
console.log(`SprinterUSDCLPShare: ${lpToken.target}`);
120151
console.log(`LiquidityHub: ${liquidityHub.target}`);
121152
console.log(`LiquidityHubProxyAdmin: ${liquidityHubAdmin.target}`);

0 commit comments

Comments
 (0)