Skip to content

Commit 98cae8d

Browse files
authored
Merge pull request #120 from onflow/holyfuchs/small-fixes
Clean up naming, make rounding explicit, and remove non-ASCII chars
2 parents ccf14c2 + 0f3f1f5 commit 98cae8d

20 files changed

Lines changed: 783 additions & 808 deletions

solidity/.solhint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "solhint:recommended",
33
"rules": {
44
"func-visibility": ["warn", { "ignoreConstructors": true }],
5-
"function-max-lines": ["warn", 60 ],
5+
"function-max-lines": ["warn", 65 ],
66
"gas-indexed-events": "off",
77
"gas-strict-inequalities": "off",
88
"import-path-check": "off",

solidity/deployments/mainnet.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chainId = 747
55

66
# --- Tokens ---
77
# WBTC
8-
collateral = "0x717DAE2BaF7656BE9a9B01deE31d571a9d4c9579"
8+
collateralToken = "0x717DAE2BaF7656BE9a9B01deE31d571a9d4c9579"
99
# PYUSD0
1010
loanToken = "0x99aF3EeA856556646C98c8B9b2548Fe815240750"
1111
# FUSDEV
@@ -32,14 +32,16 @@ healthFactorMaxTarget = "1430948419301164725" # 860000000000000000 * 100 / 60.1
3232
healthFactorMax = "1433333333333333333" # 860000000000000000 * 100 / 60 (LTV 60%)
3333

3434
# --- FlowSwap V3 pool fee tiers ---
35-
feeYieldDebt = 100
36-
feeAssetDebt = 3000
35+
# Pool addresses are derived from swapFactory + these fees in ConfiguredScript.
36+
yieldLoanPoolFee = 100
37+
collateralLoanPoolFee = 3000
3738

3839
# --- Periphery ---
40+
# yieldOracle: optional pre-deployed oracle; omit (or leave unset) to have
41+
# DeployVault deploy a fresh YieldTokenOracle reading the yield token's rate.
3942
yieldOracle = "0x144F613490DD55C9844Ef139CFB9B63433dD349F"
4043
swapFactory = "0xca6d7Bb03334bBf135902e1d919a5feccb461632"
41-
yieldDebtPool = "0x9196e243b7562B0866309013f2F9EB63F83A690f"
4244

4345
# --- Timelocked emergency recovery ---
44-
# Delay (seconds) between scheduling and executing a recovery. 604800 = 7 days.
45-
recoveryDelay = 604800
46+
# Delay is now a contract constant (FCMVault.RECOVERY_DELAY = 7 days), no
47+
# longer configured here.

solidity/script/ConfiguredScript.s.sol

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@ abstract contract ConfiguredScript is Script {
2020

2121
struct Config {
2222
uint256 chainId;
23-
address collateral;
23+
24+
address collateralToken;
2425
address loanToken;
2526
address yieldToken;
26-
address marketOracle;
27-
address marketIrm;
28-
uint256 marketLltv;
29-
uint24 feeYieldDebt;
30-
uint24 feeAssetDebt;
27+
3128
uint256 healthFactorMin;
32-
uint256 healthFactorMax;
3329
uint256 healthFactorMinTarget;
30+
uint256 healthFactorMax;
3431
uint256 healthFactorMaxTarget;
3532
uint256 yieldFactorMax;
36-
address yieldOracle;
33+
3734
address swapFactory;
38-
address yieldDebtPool;
39-
address assetDebtPool;
40-
uint256 recoveryDelay;
35+
address collateralLoanPool;
36+
uint24 collateralLoanPoolFee;
37+
address yieldLoanPool;
38+
uint24 yieldLoanPoolFee;
39+
40+
address marketOracle;
41+
address marketIrm;
42+
uint256 marketLltv;
43+
address yieldOracle;
4144
}
4245

4346
function _loadConfig() internal view returns (Config memory c) {
@@ -51,33 +54,33 @@ abstract contract ConfiguredScript is Script {
5154
c.chainId == block.chainid, string.concat("config chainId does not match RPC chain (network=", network, ")")
5255
);
5356

54-
c.collateral = vm.parseTomlAddress(toml, ".collateral");
57+
c.collateralToken = vm.parseTomlAddress(toml, ".collateralToken");
5558
c.loanToken = vm.parseTomlAddress(toml, ".loanToken");
5659
c.yieldToken = vm.parseTomlAddress(toml, ".yieldToken");
57-
c.marketOracle = vm.parseTomlAddress(toml, ".marketOracle");
58-
c.marketIrm = vm.parseTomlAddress(toml, ".marketIrm");
59-
c.marketLltv = vm.parseTomlUint(toml, ".marketLltv");
60-
c.feeYieldDebt = uint24(vm.parseTomlUint(toml, ".feeYieldDebt"));
61-
c.feeAssetDebt = uint24(vm.parseTomlUint(toml, ".feeAssetDebt"));
60+
6261
c.healthFactorMin = vm.parseTomlUint(toml, ".healthFactorMin");
6362
c.healthFactorMax = vm.parseTomlUint(toml, ".healthFactorMax");
6463
c.healthFactorMinTarget = vm.parseTomlUint(toml, ".healthFactorMinTarget");
6564
c.healthFactorMaxTarget = vm.parseTomlUint(toml, ".healthFactorMaxTarget");
6665
c.yieldFactorMax = vm.parseTomlUint(toml, ".yieldFactorMax");
67-
c.yieldOracle = vm.parseTomlAddress(toml, ".yieldOracle");
66+
6867
c.swapFactory = vm.parseTomlAddress(toml, ".swapFactory");
69-
c.yieldDebtPool = vm.parseTomlAddress(toml, ".yieldDebtPool");
70-
// Derived from the factory rather than a separate config field: the canonical
71-
// collateral/loan pool at the asset/debt fee tier, which harvest's leg 2 routes
72-
// through. Existence is asserted in `_requirePoolsExist`.
73-
c.assetDebtPool = IUniswapV3Factory(c.swapFactory).getPool(c.collateral, c.loanToken, c.feeAssetDebt);
74-
c.recoveryDelay = vm.parseTomlUint(toml, ".recoveryDelay");
68+
c.collateralLoanPool =
69+
IUniswapV3Factory(c.swapFactory).getPool(c.collateralToken, c.loanToken, c.collateralLoanPoolFee);
70+
c.collateralLoanPoolFee = uint24(vm.parseTomlUint(toml, ".collateralLoanPoolFee"));
71+
c.yieldLoanPool = IUniswapV3Factory(c.swapFactory).getPool(c.yieldToken, c.loanToken, c.yieldLoanPoolFee);
72+
c.yieldLoanPoolFee = uint24(vm.parseTomlUint(toml, ".yieldLoanPoolFee"));
73+
74+
c.marketOracle = vm.parseTomlAddress(toml, ".marketOracle");
75+
c.marketIrm = vm.parseTomlAddress(toml, ".marketIrm");
76+
c.marketLltv = vm.parseTomlUint(toml, ".marketLltv");
77+
c.yieldOracle = vm.parseTomlAddress(toml, ".yieldOracle");
7578
}
7679

7780
function _marketParams(Config memory c) internal pure returns (MarketParams memory) {
7881
return MarketParams({
7982
loanToken: c.loanToken,
80-
collateralToken: c.collateral,
83+
collateralToken: c.collateralToken,
8184
oracle: c.marketOracle,
8285
irm: c.marketIrm,
8386
lltv: c.marketLltv
@@ -100,10 +103,10 @@ abstract contract ConfiguredScript is Script {
100103

101104
/// @dev Both FlowSwap pools the vault trades on must exist.
102105
function _requirePoolsExist(Config memory c) internal view {
103-
address yieldPool = IUniswapV3Factory(c.swapFactory).getPool(c.yieldToken, c.loanToken, c.feeYieldDebt);
106+
address yieldPool = IUniswapV3Factory(c.swapFactory).getPool(c.yieldToken, c.loanToken, c.yieldLoanPoolFee);
104107
require(yieldPool != address(0), "yield/debt pool missing");
105-
require(yieldPool == c.yieldDebtPool, "config yieldDebtPool does not match factory");
106-
require(c.assetDebtPool != address(0), "asset/debt pool missing");
108+
require(yieldPool == c.yieldLoanPool, "config yieldLoanPool does not match factory");
109+
require(c.collateralLoanPool != address(0), "asset/debt pool missing");
107110
}
108111

109112
/// @dev The account whose key signs broadcast transactions. Must be

solidity/script/DeployVault.s.sol

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,23 @@ contract DeployVault is ConfiguredScript {
6161

6262
FCMVault vault = new FCMVault(
6363
IFCMVault.InitParams({
64-
collateral: IERC20(c.collateral),
64+
collateralToken: IERC20(c.collateralToken),
6565
loanToken: IERC20(c.loanToken),
6666
yieldToken: IERC20(c.yieldToken),
67-
marketOracle: c.marketOracle,
68-
marketIrm: c.marketIrm,
69-
marketLltv: c.marketLltv,
70-
feeYieldDebt: c.feeYieldDebt,
71-
feeAssetDebt: c.feeAssetDebt,
72-
yieldDebtPool: c.yieldDebtPool,
73-
assetDebtPool: c.assetDebtPool,
7467
healthFactorMin: c.healthFactorMin,
75-
healthFactorMax: c.healthFactorMax,
7668
healthFactorMinTarget: c.healthFactorMinTarget,
69+
healthFactorMax: c.healthFactorMax,
7770
healthFactorMaxTarget: c.healthFactorMaxTarget,
7871
yieldFactorMax: c.yieldFactorMax,
72+
collateralLoanPool: c.collateralLoanPool,
73+
collateralLoanPoolFee: c.collateralLoanPoolFee,
74+
yieldLoanPool: c.yieldLoanPool,
75+
yieldLoanPoolFee: c.yieldLoanPoolFee,
76+
marketOracle: c.marketOracle,
77+
marketIrm: c.marketIrm,
78+
marketLltv: c.marketLltv,
7979
yieldOracle: IOracle(yieldOracle),
80-
admin: deployer,
81-
recoveryDelay: c.recoveryDelay,
80+
owner: deployer,
8281
name: name,
8382
symbol: symbol
8483
})
@@ -89,6 +88,9 @@ contract DeployVault is ConfiguredScript {
8988
vault.grantEarlyAccess(grantees[i]);
9089
}
9190
vault.setMaxTvl(maxTvl);
91+
// maxSlippageBps defaults to 0 (not in InitParams); set the 1% production
92+
// default here so rebalance swaps don't no-op against an off-oracle pool.
93+
vault.setMaxSlippageBps(100);
9294
vm.stopBroadcast();
9395

9496
console.log("=== deployment complete ===");

solidity/script/Status.s.sol

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ contract Status is ConfiguredScript {
5050

5151
function _reportPools(Config memory c) internal view {
5252
console.log("--- FlowSwap pools");
53-
address yieldPool = IUniswapV3Factory(c.swapFactory).getPool(c.yieldToken, c.loanToken, c.feeYieldDebt);
54-
address assetPool = IUniswapV3Factory(c.swapFactory).getPool(c.collateral, c.loanToken, c.feeAssetDebt);
55-
console.log("yield/debt pool (fee %s): %s", c.feeYieldDebt, yieldPool);
56-
console.log("asset/debt pool (fee %s): %s", c.feeAssetDebt, assetPool);
57-
if (yieldPool != c.yieldDebtPool) {
58-
console.log("CONFIG MISMATCH: yieldDebtPool in config is %s", c.yieldDebtPool);
53+
address yieldPool = IUniswapV3Factory(c.swapFactory).getPool(c.yieldToken, c.loanToken, c.yieldLoanPoolFee);
54+
address assetPool =
55+
IUniswapV3Factory(c.swapFactory).getPool(c.collateralToken, c.loanToken, c.collateralLoanPoolFee);
56+
console.log("yield/debt pool (fee %s): %s", c.yieldLoanPoolFee, yieldPool);
57+
console.log("asset/debt pool (fee %s): %s", c.collateralLoanPoolFee, assetPool);
58+
if (yieldPool != c.yieldLoanPool) {
59+
console.log("CONFIG MISMATCH: yieldLoanPool in config is %s", c.yieldLoanPool);
5960
}
6061
if (yieldPool != address(0)) {
6162
(, int24 tick,,,,,) = IUniswapV3Pool(yieldPool).slot0();
@@ -88,7 +89,7 @@ contract Status is ConfiguredScript {
8889
if (deployer == address(0)) return;
8990
console.log("--- Deployer %s", deployer);
9091
console.log("native FLOW (gas): %s", deployer.balance);
91-
console.log("collateral balance: %s", IERC20(c.collateral).balanceOf(deployer));
92+
console.log("collateral balance: %s", IERC20(c.collateralToken).balanceOf(deployer));
9293
console.log("loan token balance: %s", IERC20(c.loanToken).balanceOf(deployer));
9394
}
9495
}

0 commit comments

Comments
 (0)