Skip to content

Commit

Permalink
Use recommended solhint rules (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
larryob authored Sep 20, 2022
1 parent 60c2c07 commit dc66ce7
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 87 deletions.
34 changes: 17 additions & 17 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BaseStrategyTest:testSweep() (gas: 104595)
BaseStrategyTest:testSweep() (gas: 104683)
BaseVaultTest:testGetWithdrawalQueue() (gas: 9739612)
BaseVaultTest:testHarvest() (gas: 703581)
BaseVaultTest:testLiquidate() (gas: 671698)
Expand All @@ -21,7 +21,7 @@ EmergencyWithdrawalQueueTest:testCorreclyEnqueueReturningUser() (gas: 396989)
EmergencyWithdrawalQueueTest:testDequeueSuccess() (gas: 338261)
EmergencyWithdrawalQueueTest:testEnqueueOnlyVaultCanEnqueue() (gas: 99813)
EmergencyWithdrawalQueueTest:testEnqueueSuccess() (gas: 181763)
EmergencyWithdrawalQueueTest:testOnlyGovernanceCanReLinkVault() (gas: 33016)
EmergencyWithdrawalQueueTest:testOnlyGovernanceCanReLinkVault() (gas: 33038)
ForwardTest:testDoubleDeposit() (gas: 217754)
ForwardTest:testTransactVaultAndBasket() (gas: 618648)
CompoundStratTest:testDivestFromStrategy() (gas: 2672953)
Expand All @@ -38,30 +38,30 @@ L1VaultTest:testprocessFundRequest() (gas: 475072)
AAVEStratTest:testStrategyDivestsOnlyAmountNeeded() (gas: 488057)
AAVEStratTest:testStrategyMakesMoney() (gas: 557749)
AAVEStratTest:testTVL() (gas: 416089)
L2VaultTest:testCheckEmeregencyWithdrawalQueueBeforeRedeem() (gas: 532261)
L2VaultTest:testCheckEmeregencyWithdrawalQueueBeforeWithdraw() (gas: 534071)
L2VaultTest:testCheckEmeregencyWithdrawalQueueBeforeRedeem() (gas: 532175)
L2VaultTest:testCheckEmeregencyWithdrawalQueueBeforeWithdraw() (gas: 533984)
L2VaultTest:testDeploy() (gas: 20615)
L2VaultTest:testDepositRedeem(uint128) (runs: 256, μ: 200916, ~: 200924)
L2VaultTest:testDepositWithdraw(uint128) (runs: 256, μ: 200661, ~: 200669)
L2VaultTest:testDepositWithdraw(uint128) (runs: 256, μ: 200662, ~: 200669)
L2VaultTest:testDetailedPrice() (gas: 176683)
L2VaultTest:testEmergencyWithdrawal(uint128) (runs: 256, μ: 507475, ~: 507482)
L2VaultTest:testEmergencyWithdrawalQueueNotStarved() (gas: 718368)
L2VaultTest:testEmergencyWithdrawalRequestDrop() (gas: 467663)
L2VaultTest:testEmergencyWithdrawalWithRedeem(uint128) (runs: 256, μ: 508000, ~: 508008)
L2VaultTest:testEmergencyWithdrawal(uint128) (runs: 256, μ: 507457, ~: 507465)
L2VaultTest:testEmergencyWithdrawalQueueNotStarved() (gas: 718351)
L2VaultTest:testEmergencyWithdrawalRequestDrop() (gas: 467646)
L2VaultTest:testEmergencyWithdrawalWithRedeem(uint128) (runs: 256, μ: 507983, ~: 507991)
L2VaultTest:testL1ToL2Rebalance() (gas: 145998)
L2VaultTest:testL1ToL2RebalanceWithEmergencyWithdrawalQueueDebt() (gas: 138021)
L2VaultTest:testL2ToL1Rebalance() (gas: 180917)
L2VaultTest:testL2ToL1RebalanceWithEmergencyWithdrawalQueueDebt() (gas: 172853)
L2VaultTest:testLockedProfit() (gas: 341776)
L2VaultTest:testLockedTVL() (gas: 162662)
L2VaultTest:testManagementFee() (gas: 425828)
L2VaultTest:testLockedProfit() (gas: 341864)
L2VaultTest:testLockedTVL() (gas: 162685)
L2VaultTest:testManagementFee() (gas: 425845)
L2VaultTest:testMinDeposit() (gas: 155485)
L2VaultTest:testMint(uint128) (runs: 256, μ: 176191, ~: 176502)
L2VaultTest:testReceiveTVL() (gas: 172669)
L2VaultTest:testReceiveTVL() (gas: 172627)
L2VaultTest:testSettingFees() (gas: 49249)
L2VaultTest:testSettingForwarder() (gas: 40951)
L2VaultTest:testVaultPause() (gas: 308861)
L2VaultTest:testWithdrawalFee() (gas: 234192)
L2VaultTest:testVaultPause() (gas: 308879)
L2VaultTest:testWithdrawalFee() (gas: 234210)
RouterTest:testMultipleDeposits() (gas: 626366)
BtcEthBasketTest:testAssetLimit() (gas: 721407)
BtcEthBasketTest:testBuySplits() (gas: 191783)
Expand All @@ -79,8 +79,8 @@ L1WormholeRouterTest:testReceiveFunds() (gas: 80765)
L1WormholeRouterTest:testReinitializeFails() (gas: 14956)
L1WormholeRouterTest:testReportTVL() (gas: 64462)
L1WormholeRouterTest:testReportTransferredFund() (gas: 63622)
L2WormholeRouterTest:testMessageValidation() (gas: 1337543)
L2WormholeRouterTest:testReceiveFunds() (gas: 320333)
L2WormholeRouterTest:testMessageValidation() (gas: 1348192)
L2WormholeRouterTest:testReceiveFunds() (gas: 320316)
L2WormholeRouterTest:testReceiveFundsInvariants() (gas: 143689)
L2WormholeRouterTest:testReceiveTVL() (gas: 180921)
L2WormholeRouterTest:testReceiveTVLInvariants() (gas: 19805)
Expand Down
9 changes: 7 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "solhint:default",
"extends": "solhint:recommended",
"rules": {
"max-line-length": "off"
"max-line-length": "off",
"compiler-version": ["error", "^0.8.0"],
"state-visibility": "off",
"not-rely-on-time": "off",
"no-empty-blocks": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
5 changes: 4 additions & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ artifacts/
cache/
coverage/
node_modules/
typechain/
typechain/
src/test
src/testnet
src/external/Multicall.sol
16 changes: 8 additions & 8 deletions src/ethereum/L1CompoundStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract L1CompoundStrategy is BaseStrategy {
if (amount == 0) {
return 0;
}
require(cToken.mint(amount) == 0, "_depositWant(): minting cToken failed.");
require(cToken.mint(amount) == 0, "CompStrat: mint failed");
return amount;
}

Expand Down Expand Up @@ -180,17 +180,17 @@ contract L1CompoundStrategy is BaseStrategy {

// This function will choose a path of [A, B] if either A or B is WETH (or equivalent on other EVM chains)
// If neither is WETH, then it gives a path of [A, WETH, B]
function getTokenOutPathV2(address _token_in, address _token_out) internal view returns (address[] memory _path) {
bool is_wrapped_native = _token_in == address(wrappedNative) || _token_out == address(wrappedNative);
function getTokenOutPathV2(address inToken, address outToken) internal view returns (address[] memory _path) {
bool isWrappedNative = inToken == address(wrappedNative) || outToken == address(wrappedNative);

_path = new address[](is_wrapped_native ? 2 : 3);
_path[0] = _token_in;
_path = new address[](isWrappedNative ? 2 : 3);
_path[0] = inToken;

if (is_wrapped_native) {
_path[1] = _token_out;
if (isWrappedNative) {
_path[1] = outToken;
} else {
_path[1] = address(wrappedNative);
_path[2] = _token_out;
_path[2] = outToken;
}
}
}
4 changes: 2 additions & 2 deletions src/ethereum/L1WormholeRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract L1WormholeRouter is WormholeRouter, Initializable {
_validateWormholeMessageEmitter(vm);
nextValidNonce = vm.nonce + 1;
(bytes32 msgType, uint256 amount) = abi.decode(vm.payload, (bytes32, uint256));
require(msgType == Constants.L2_FUND_TRANSFER_REPORT);
require(msgType == Constants.L2_FUND_TRANSFER_REPORT, "WR: bad msg type");

vault.bridgeEscrow().l1ClearFund(amount, data);
emit TransferFromL2(amount);
Expand All @@ -71,7 +71,7 @@ contract L1WormholeRouter is WormholeRouter, Initializable {
_validateWormholeMessageEmitter(vm);
nextValidNonce = vm.nonce + 1;
(bytes32 msgType, uint256 amount) = abi.decode(vm.payload, (bytes32, uint256));
require(msgType == Constants.L2_FUND_REQUEST);
require(msgType == Constants.L2_FUND_REQUEST, "WR: bad msg type");

L1Vault(address(vault)).processFundRequest(amount);
}
Expand Down
3 changes: 1 addition & 2 deletions src/external/Multicall.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// forked from https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/Multicall.sol

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.13;

// forked from https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/Multicall.sol
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall {
Expand Down
2 changes: 1 addition & 1 deletion src/polygon/EmergencyWithdrawalQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract EmergencyWithdrawalQueue is AccessControl {
if (!hasRole(DEFAULT_ADMIN_ROLE, _msgSender())) {
require(address(vault) == address(0), "Vault is already linked");
}
require(_vault.emergencyWithdrawalQueue() == this);
require(_vault.emergencyWithdrawalQueue() == this, "EWQ: bad vault");
_grantRole(OPERATOR_ROLE, address(_vault));
vault = _vault;
}
Expand Down
14 changes: 7 additions & 7 deletions src/polygon/L2AAVEStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ contract L2AAVEStrategy is BaseStrategy {

/// @dev This function will choose a path of [A, B] if either A or B is WETH (or equivalent on other EVM chains)
// If neither is WETH, then it gives a path of [A, WETH, B]
function getTokenOutPathV2(address _token_in, address _token_out) internal view returns (address[] memory _path) {
bool is_wrapped_native = _token_in == address(wrappedNative) || _token_out == address(wrappedNative);
function getTokenOutPathV2(address inToken, address outToken) internal view returns (address[] memory _path) {
bool isWrappedNative = inToken == address(wrappedNative) || outToken == address(wrappedNative);

_path = new address[](is_wrapped_native ? 2 : 3);
_path[0] = _token_in;
_path = new address[](isWrappedNative ? 2 : 3);
_path[0] = inToken;

if (is_wrapped_native) {
_path[1] = _token_out;
if (isWrappedNative) {
_path[1] = outToken;
} else {
_path[1] = address(wrappedNative);
_path[2] = _token_out;
_path[2] = outToken;
}
}
}
42 changes: 18 additions & 24 deletions src/polygon/L2Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract L2Vault is
using FixedPointMathLib for uint256;

// TVL of L1 denominated in `token` (e.g. USDC). This value will be updated by oracle.
uint256 public L1TotalLockedValue;
uint256 public l1TotalLockedValue;

/**
* FEES
Expand Down Expand Up @@ -84,7 +84,7 @@ contract L2Vault is
address _governance,
ERC20 _token,
address _wormholeRouter,
BridgeEscrow _BridgeEscrow,
BridgeEscrow _bridgeEscrow,
EmergencyWithdrawalQueue _emergencyWithdrawalQueue,
address forwarder,
uint256 _l1Ratio,
Expand All @@ -94,7 +94,7 @@ contract L2Vault is
__ERC20_init("Alpine Save", "alpSave");
__UUPSUpgradeable_init();
__Pausable_init();
BaseVault.baseInitialize(_governance, _token, _wormholeRouter, _BridgeEscrow);
BaseVault.baseInitialize(_governance, _token, _wormholeRouter, _bridgeEscrow);

emergencyWithdrawalQueue = _emergencyWithdrawalQueue;
l1Ratio = _l1Ratio;
Expand Down Expand Up @@ -237,10 +237,7 @@ contract L2Vault is

/// @notice See {IERC4262-redeem}
function redeem(uint256 shares, address receiver, address owner) external whenNotPaused returns (uint256 assets) {
require(
shares + emergencyWithdrawalQueue.debtToOwner(owner) <= balanceOf(owner),
"Not enough share available in owners balance"
);
require(shares + emergencyWithdrawalQueue.debtToOwner(owner) <= balanceOf(owner), "L2Vault: min shares");
(uint256 assetsToUser, uint256 assetsFee) = _previewRedeem(shares);
assets = assetsToUser;

Expand Down Expand Up @@ -280,10 +277,7 @@ contract L2Vault is
returns (uint256 shares)
{
shares = previewWithdraw(assets);
require(
shares + emergencyWithdrawalQueue.debtToOwner(owner) <= balanceOf(owner),
"Not enough share available in owners balance"
);
require(shares + emergencyWithdrawalQueue.debtToOwner(owner) <= balanceOf(owner), "L2Vault: min shares");

address caller = _msgSender();

Expand Down Expand Up @@ -328,7 +322,7 @@ contract L2Vault is

/// @notice See {IERC4262-totalAssets}
function totalAssets() public view returns (uint256 totalManagedAssets) {
return vaultTVL() + L1TotalLockedValue - lockedProfit() - lockedTVL();
return vaultTVL() + l1TotalLockedValue - lockedProfit() - lockedTVL();
}

/// @notice See {IERC4262-convertToShares}
Expand Down Expand Up @@ -490,41 +484,41 @@ contract L2Vault is
revert("Rebalance in progress");
}

// Update L1TotalLockedValue to match what we received from L1
// Update l1TotalLockedValue to match what we received from L1
// Any increase in L1's tvl will unlock linearly, just as when harvesting from strategies
uint256 oldL1TVL = L1TotalLockedValue;
uint256 oldL1TVL = l1TotalLockedValue;
uint256 totalProfit = tvl > oldL1TVL ? tvl - oldL1TVL : 0;
maxLockedTVL = lockedTVL() + totalProfit;
lastTVLUpdate = block.timestamp;
L1TotalLockedValue = tvl;
l1TotalLockedValue = tvl;

(bool invest, uint256 delta) = _computeRebalance();
if (delta == 0) {
return;
}
_L1L2Rebalance(invest, delta);
_l1L2Rebalance(invest, delta);
}

function _computeRebalance() internal view returns (bool, uint256) {
uint256 numSlices = l1Ratio + l2Ratio;
// We want to keep enough funds to satisfy emergency withdrawal queue plus l2Ratio of remaining funds
// so that we have a l1Ratio:l2Ratio distribution in both layers after emergency withdrawal queue is
// satisfied.
uint256 L1IdealAmount =
(l1Ratio * (vaultTVL() + L1TotalLockedValue - emergencyWithdrawalQueue.totalDebt())) / numSlices;
uint256 l1IdealAmount =
(l1Ratio * (vaultTVL() + l1TotalLockedValue - emergencyWithdrawalQueue.totalDebt())) / numSlices;

bool invest;
uint256 delta;
if (L1IdealAmount >= L1TotalLockedValue) {
if (l1IdealAmount >= l1TotalLockedValue) {
invest = true;
delta = L1IdealAmount - L1TotalLockedValue;
delta = l1IdealAmount - l1TotalLockedValue;
} else {
delta = L1TotalLockedValue - L1IdealAmount;
delta = l1TotalLockedValue - l1IdealAmount;
}
return (invest, delta);
}

function _L1L2Rebalance(bool invest, uint256 amount) internal {
function _l1L2Rebalance(bool invest, uint256 amount) internal {
if (invest) {
// Increase balance of `token` to `delta` by withdrawing from strategies.
// Then transfer `amount` of `token` to L1.
Expand All @@ -546,7 +540,7 @@ contract L2Vault is
// Update bridge state and L1 TVL
// It's important to update this number now so that totalAssets() returns a smaller number
canTransferToL1 = false;
L1TotalLockedValue += amount;
l1TotalLockedValue += amount;

// Let L1 know how much money we sent
L2WormholeRouter(wormholeRouter).reportTransferredFund(amount);
Expand All @@ -562,7 +556,7 @@ contract L2Vault is

function afterReceive(uint256 amount) external {
require(_msgSender() == address(bridgeEscrow), "Only L2 BridgeEscrow.");
L1TotalLockedValue -= amount;
l1TotalLockedValue -= amount;
canRequestFromL1 = true;
emit ReceiveFromL1(amount);
}
Expand Down
4 changes: 2 additions & 2 deletions src/polygon/L2WormholeRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract L2WormholeRouter is WormholeRouter, Initializable {
_validateWormholeMessageEmitter(vm);
nextValidNonce = vm.nonce + 1;
(bytes32 msgType, uint256 amount) = abi.decode(vm.payload, (bytes32, uint256));
require(msgType == Constants.L1_FUND_TRANSFER_REPORT);
require(msgType == Constants.L1_FUND_TRANSFER_REPORT, "WR: bad msg type");
vault.bridgeEscrow().l2ClearFund(amount);
emit TransferFromL1(amount);
}
Expand All @@ -63,7 +63,7 @@ contract L2WormholeRouter is WormholeRouter, Initializable {
_validateWormholeMessageEmitter(vm);
nextValidNonce = vm.nonce + 1;
(bytes32 msgType, uint256 tvl, bool received) = abi.decode(vm.payload, (bytes32, uint256, bool));
require(msgType == Constants.L1_TVL, "Not a TVL message");
require(msgType == Constants.L1_TVL, "WR: bad msg type");
L2Vault(address(vault)).receiveTVL(tvl, received);
}
}
2 changes: 1 addition & 1 deletion src/test/BridgeEscrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract L2BridgeEscrowTest is TestPlus {
// So we can call "afterReceive" and decrement the total locked value
vm.store(
address(vault),
bytes32(stdstore.target(address(vault)).sig("L1TotalLockedValue()").find()),
bytes32(stdstore.target(address(vault)).sig("l1TotalLockedValue()").find()),
bytes32(uint256(200))
);

Expand Down
Loading

0 comments on commit dc66ce7

Please sign in to comment.