Skip to content

Commit 90fa97f

Browse files
authored
Merge pull request #91 from AztecProtocol/lh/liquity-linter-warnings
fix: linter warnings in liquity contracts
2 parents d3786f0 + e6b9bca commit 90fa97f

File tree

5 files changed

+79
-75
lines changed

5 files changed

+79
-75
lines changed

src/bridges/liquity/StabilityPoolBridge.sol

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,25 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
9191
* this scenario because I expect the liquidation bots to be so fast that the scenario will never occur. Checking
9292
* for it would only waste gas.
9393
*
94-
* @param inputAssetA - LUSD (Deposit) or SPB (Withdrawal)
95-
* @param outputAssetA - SPB (Deposit) or LUSD (Withdrawal)
96-
* @param inputValue - the amount of LUSD to deposit or the amount of SPB to burn and exchange for LUSD
94+
* @param _inputAssetA - LUSD (Deposit) or SPB (Withdrawal)
95+
* @param _outputAssetA - SPB (Deposit) or LUSD (Withdrawal)
96+
* @param _inputValue - the amount of LUSD to deposit or the amount of SPB to burn and exchange for LUSD
9797
* @return outputValueA - the amount of SPB (Deposit) or LUSD (Withdrawal) minted/transferred to
9898
* the RollupProcessor.sol
9999
*/
100100
function convert(
101-
AztecTypes.AztecAsset calldata inputAssetA,
101+
AztecTypes.AztecAsset calldata _inputAssetA,
102102
AztecTypes.AztecAsset calldata,
103-
AztecTypes.AztecAsset calldata outputAssetA,
103+
AztecTypes.AztecAsset calldata _outputAssetA,
104104
AztecTypes.AztecAsset calldata,
105-
uint256 inputValue,
105+
uint256 _inputValue,
106106
uint256,
107107
uint64,
108108
address
109109
)
110110
external
111111
payable
112-
override
112+
override(IDefiBridge)
113113
returns (
114114
uint256 outputValueA,
115115
uint256,
@@ -118,34 +118,34 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
118118
{
119119
if (msg.sender != ROLLUP_PROCESSOR) revert InvalidCaller();
120120

121-
if (inputAssetA.erc20Address == LUSD && outputAssetA.erc20Address == address(this)) {
121+
if (_inputAssetA.erc20Address == LUSD && _outputAssetA.erc20Address == address(this)) {
122122
// Deposit
123123
// Provides LUSD to the pool and claim rewards.
124-
STABILITY_POOL.provideToSP(inputValue, FRONTEND_TAG);
125-
swapRewardsToLUSDAndDeposit();
126-
uint256 totalLUSDOwnedBeforeDeposit = STABILITY_POOL.getCompoundedLUSDDeposit(address(this)) - inputValue;
124+
STABILITY_POOL.provideToSP(_inputValue, FRONTEND_TAG);
125+
_swapRewardsToLUSDAndDeposit();
126+
uint256 totalLUSDOwnedBeforeDeposit = STABILITY_POOL.getCompoundedLUSDDeposit(address(this)) - _inputValue;
127127
uint256 totalSupply = this.totalSupply();
128128
// outputValueA = how much SPB should be minted
129129
if (totalSupply == 0) {
130130
// When the totalSupply is 0, I set the SPB/LUSD ratio to be 1.
131-
outputValueA = inputValue;
131+
outputValueA = _inputValue;
132132
} else {
133133
// totalSupply / totalLUSDOwnedBeforeDeposit = how much SPB one LUSD is worth
134134
// When I multiply this ^ with the amount of LUSD deposited I get the amount of SPB to be minted.
135-
outputValueA = (totalSupply * inputValue) / totalLUSDOwnedBeforeDeposit;
135+
outputValueA = (totalSupply * _inputValue) / totalLUSDOwnedBeforeDeposit;
136136
}
137137
_mint(address(this), outputValueA);
138-
} else if (inputAssetA.erc20Address == address(this) && outputAssetA.erc20Address == LUSD) {
138+
} else if (_inputAssetA.erc20Address == address(this) && _outputAssetA.erc20Address == LUSD) {
139139
// Withdrawal
140140
// Claim rewards and swap them to LUSD.
141141
STABILITY_POOL.withdrawFromSP(0);
142-
swapRewardsToLUSDAndDeposit();
142+
_swapRewardsToLUSDAndDeposit();
143143

144144
// stabilityPool.getCompoundedLUSDDeposit(address(this)) / this.totalSupply() = how much LUSD is one SPB
145145
// outputValueA = amount of LUSD to be withdrawn and sent to RollupProcessor.sol
146-
outputValueA = (STABILITY_POOL.getCompoundedLUSDDeposit(address(this)) * inputValue) / this.totalSupply();
146+
outputValueA = (STABILITY_POOL.getCompoundedLUSDDeposit(address(this)) * _inputValue) / this.totalSupply();
147147
STABILITY_POOL.withdrawFromSP(outputValueA);
148-
_burn(address(this), inputValue);
148+
_burn(address(this), _inputValue);
149149
} else {
150150
revert IncorrectInput();
151151
}
@@ -162,7 +162,7 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
162162
)
163163
external
164164
payable
165-
override
165+
override(IDefiBridge)
166166
returns (
167167
uint256,
168168
uint256,
@@ -175,7 +175,7 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
175175
/**
176176
* @dev See {IERC20-totalSupply}.
177177
*/
178-
function totalSupply() public view override returns (uint256) {
178+
function totalSupply() public view override(ERC20) returns (uint256) {
179179
return super.totalSupply() - DUST;
180180
}
181181

@@ -186,7 +186,7 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
186186
* liquidations rewards (ETH) to LUSD as well, I will first swap LQTY to WETH and then swap it all through USDC to
187187
* LUSD.
188188
*/
189-
function swapRewardsToLUSDAndDeposit() internal {
189+
function _swapRewardsToLUSDAndDeposit() internal {
190190
uint256 lqtyBalance = IERC20(LQTY).balanceOf(address(this));
191191
if (lqtyBalance > DUST) {
192192
UNI_ROUTER.exactInputSingle(

src/bridges/liquity/StakingBridge.sol

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,25 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
8383
* the method. If this is not the case, the function will revert (either in STAKING_CONTRACT.stake(...) or during
8484
* SB burn).
8585
*
86-
* @param inputAssetA - LQTY (Staking) or SB (Unstaking)
87-
* @param outputAssetA - SB (Staking) or LQTY (Unstaking)
88-
* @param inputValue - the amount of LQTY to stake or the amount of SB to burn and exchange for LQTY
86+
* @param _inputAssetA - LQTY (Staking) or SB (Unstaking)
87+
* @param _outputAssetA - SB (Staking) or LQTY (Unstaking)
88+
* @param _inputValue - the amount of LQTY to stake or the amount of SB to burn and exchange for LQTY
8989
* @return outputValueA - the amount of SB (Staking) or LQTY (Unstaking) minted/transferred to
9090
* the RollupProcessor.sol
9191
*/
9292
function convert(
93-
AztecTypes.AztecAsset calldata inputAssetA,
93+
AztecTypes.AztecAsset calldata _inputAssetA,
9494
AztecTypes.AztecAsset calldata,
95-
AztecTypes.AztecAsset calldata outputAssetA,
95+
AztecTypes.AztecAsset calldata _outputAssetA,
9696
AztecTypes.AztecAsset calldata,
97-
uint256 inputValue,
97+
uint256 _inputValue,
9898
uint256,
9999
uint64,
100100
address
101101
)
102102
external
103103
payable
104+
override(IDefiBridge)
104105
returns (
105106
uint256 outputValueA,
106107
uint256,
@@ -109,34 +110,34 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
109110
{
110111
if (msg.sender != ROLLUP_PROCESSOR) revert InvalidCaller();
111112

112-
if (inputAssetA.erc20Address == LQTY && outputAssetA.erc20Address == address(this)) {
113+
if (_inputAssetA.erc20Address == LQTY && _outputAssetA.erc20Address == address(this)) {
113114
// Deposit
114115
// Stake and claim rewards
115-
STAKING_CONTRACT.stake(inputValue);
116-
swapRewardsToLQTYAndStake();
116+
STAKING_CONTRACT.stake(_inputValue);
117+
_swapRewardsToLQTYAndStake();
117118
uint256 totalSupply = this.totalSupply();
118119
// outputValueA = how much SB should be minted
119120
if (totalSupply == 0) {
120121
// When the totalSupply is 0, I set the SB/LQTY ratio to be 1.
121-
outputValueA = inputValue;
122+
outputValueA = _inputValue;
122123
} else {
123-
uint256 totalLQTYOwnedBeforeDeposit = STAKING_CONTRACT.stakes(address(this)) - inputValue;
124+
uint256 totalLQTYOwnedBeforeDeposit = STAKING_CONTRACT.stakes(address(this)) - _inputValue;
124125
// totalSupply / totalLQTYOwnedBeforeDeposit = how much SB one LQTY is worth
125126
// When I multiply this ^ with the amount of LQTY deposited I get the amount of SB to be minted.
126-
outputValueA = (totalSupply * inputValue) / totalLQTYOwnedBeforeDeposit;
127+
outputValueA = (totalSupply * _inputValue) / totalLQTYOwnedBeforeDeposit;
127128
}
128129
_mint(address(this), outputValueA);
129-
} else if (inputAssetA.erc20Address == address(this) && outputAssetA.erc20Address == LQTY) {
130+
} else if (_inputAssetA.erc20Address == address(this) && _outputAssetA.erc20Address == LQTY) {
130131
// Withdrawal
131132
// Claim rewards
132133
STAKING_CONTRACT.unstake(0);
133-
swapRewardsToLQTYAndStake();
134+
_swapRewardsToLQTYAndStake();
134135

135136
// STAKING_CONTRACT.stakes(address(this)) / this.totalSupply() = how much LQTY is one SB
136137
// outputValueA = amount of LQTY to be withdrawn and sent to rollupProcessor
137-
outputValueA = (STAKING_CONTRACT.stakes(address(this)) * inputValue) / this.totalSupply();
138+
outputValueA = (STAKING_CONTRACT.stakes(address(this)) * _inputValue) / this.totalSupply();
138139
STAKING_CONTRACT.unstake(outputValueA);
139-
_burn(address(this), inputValue);
140+
_burn(address(this), _inputValue);
140141
} else {
141142
revert IncorrectInput();
142143
}
@@ -153,6 +154,7 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
153154
)
154155
external
155156
payable
157+
override(IDefiBridge)
156158
returns (
157159
uint256,
158160
uint256,
@@ -165,7 +167,7 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
165167
/**
166168
* @dev See {IERC20-totalSupply}.
167169
*/
168-
function totalSupply() public view override returns (uint256) {
170+
function totalSupply() public view override(ERC20) returns (uint256) {
169171
return super.totalSupply() - DUST;
170172
}
171173

@@ -176,7 +178,7 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
176178
* liquidation rewards (ETH) to LQTY as well, I will first swap LUSD to WETH through USDC and then swap it all
177179
* to LQTY
178180
*/
179-
function swapRewardsToLQTYAndStake() internal {
181+
function _swapRewardsToLQTYAndStake() internal {
180182
uint256 lusdBalance = IERC20(LUSD).balanceOf(address(this));
181183
if (lusdBalance > DUST) {
182184
UNI_ROUTER.exactInput(

src/bridges/liquity/TroveBridge.sol

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,29 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
125125
* the method. If this is not the case, the function will revert.
126126
*
127127
* Borrowing Repaying Redeeming
128-
* @param inputAssetA - ETH TB TB
129-
* @param inputAssetB - None LUSD None
130-
* @param outputAssetA - TB ETH ETH
131-
* @param outputAssetB - LUSD None None
132-
* @param inputValue - amount of ETH amount of TB and LUSD amount of TB
133-
* @param interactionNonce - nonce nonce nonce
134-
* @param auxData - max borrower fee 0 0
128+
* @param _inputAssetA - ETH TB TB
129+
* @param _inputAssetB - None LUSD None
130+
* @param _outputAssetA - TB ETH ETH
131+
* @param _outputAssetB - LUSD None None
132+
* @param _inputValue - amount of ETH amount of TB and LUSD amount of TB
133+
* @param _interactionNonce - nonce nonce nonce
134+
* @param _auxData - max borrower fee 0 0
135135
* @return outputValueA - amount of TB amount of ETH amount of ETH
136136
* @return outputValueB - amount of LUSD 0 0
137137
*/
138138
function convert(
139-
AztecTypes.AztecAsset calldata inputAssetA,
140-
AztecTypes.AztecAsset calldata inputAssetB,
141-
AztecTypes.AztecAsset calldata outputAssetA,
142-
AztecTypes.AztecAsset calldata outputAssetB,
143-
uint256 inputValue,
144-
uint256 interactionNonce,
145-
uint64 auxData,
139+
AztecTypes.AztecAsset calldata _inputAssetA,
140+
AztecTypes.AztecAsset calldata _inputAssetB,
141+
AztecTypes.AztecAsset calldata _outputAssetA,
142+
AztecTypes.AztecAsset calldata _outputAssetB,
143+
uint256 _inputValue,
144+
uint256 _interactionNonce,
145+
uint64 _auxData,
146146
address
147147
)
148148
external
149149
payable
150+
override(IDefiBridge)
150151
returns (
151152
uint256 outputValueA,
152153
uint256 outputValueB,
@@ -160,36 +161,36 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
160161
address lowerHint = SORTED_TROVES.getNext(address(this));
161162

162163
if (
163-
inputAssetA.assetType == AztecTypes.AztecAssetType.ETH &&
164-
outputAssetA.erc20Address == address(this) &&
165-
outputAssetB.erc20Address == LUSD
164+
_inputAssetA.assetType == AztecTypes.AztecAssetType.ETH &&
165+
_outputAssetA.erc20Address == address(this) &&
166+
_outputAssetB.erc20Address == LUSD
166167
) {
167168
// Borrowing
168169
if (troveStatus != Status.active) revert IncorrectStatus(Status.active, troveStatus);
169170
// outputValueA = by how much debt will increase and how much TB to mint
170-
outputValueB = computeAmtToBorrow(inputValue); // LUSD amount to borrow
171+
outputValueB = computeAmtToBorrow(_inputValue); // LUSD amount to borrow
171172

172173
(uint256 debtBefore, , , ) = TROVE_MANAGER.getEntireDebtAndColl(address(this));
173-
BORROWER_OPERATIONS.adjustTrove{value: inputValue}(auxData, 0, outputValueB, true, upperHint, lowerHint);
174+
BORROWER_OPERATIONS.adjustTrove{value: _inputValue}(_auxData, 0, outputValueB, true, upperHint, lowerHint);
174175
(uint256 debtAfter, , , ) = TROVE_MANAGER.getEntireDebtAndColl(address(this));
175176

176177
// outputValueA = debt increase = amount of TB to mint
177178
outputValueA = debtAfter - debtBefore;
178179
_mint(address(this), outputValueA);
179180
} else if (
180-
inputAssetA.erc20Address == address(this) &&
181-
inputAssetB.erc20Address == LUSD &&
182-
outputAssetA.assetType == AztecTypes.AztecAssetType.ETH
181+
_inputAssetA.erc20Address == address(this) &&
182+
_inputAssetB.erc20Address == LUSD &&
183+
_outputAssetA.assetType == AztecTypes.AztecAssetType.ETH
183184
) {
184185
// Repaying
185186
if (troveStatus != Status.active) revert IncorrectStatus(Status.active, troveStatus);
186187
(, uint256 coll, , ) = TROVE_MANAGER.getEntireDebtAndColl(address(this));
187-
outputValueA = (coll * inputValue) / this.totalSupply(); // Amount of collateral to withdraw
188-
BORROWER_OPERATIONS.adjustTrove(0, outputValueA, inputValue, false, upperHint, lowerHint);
189-
_burn(address(this), inputValue);
190-
IRollupProcessor(ROLLUP_PROCESSOR).receiveEthFromBridge{value: outputValueA}(interactionNonce);
188+
outputValueA = (coll * _inputValue) / this.totalSupply(); // Amount of collateral to withdraw
189+
BORROWER_OPERATIONS.adjustTrove(0, outputValueA, _inputValue, false, upperHint, lowerHint);
190+
_burn(address(this), _inputValue);
191+
IRollupProcessor(ROLLUP_PROCESSOR).receiveEthFromBridge{value: outputValueA}(_interactionNonce);
191192
} else if (
192-
inputAssetA.erc20Address == address(this) && outputAssetA.assetType == AztecTypes.AztecAssetType.ETH
193+
_inputAssetA.erc20Address == address(this) && _outputAssetA.assetType == AztecTypes.AztecAssetType.ETH
193194
) {
194195
// Redeeming
195196
if (troveStatus != Status.closedByRedemption)
@@ -198,9 +199,9 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
198199
BORROWER_OPERATIONS.claimCollateral();
199200
collateralClaimed = true;
200201
}
201-
outputValueA = (address(this).balance * inputValue) / this.totalSupply();
202-
_burn(address(this), inputValue);
203-
IRollupProcessor(ROLLUP_PROCESSOR).receiveEthFromBridge{value: outputValueA}(interactionNonce);
202+
outputValueA = (address(this).balance * _inputValue) / this.totalSupply();
203+
_burn(address(this), _inputValue);
204+
IRollupProcessor(ROLLUP_PROCESSOR).receiveEthFromBridge{value: outputValueA}(_interactionNonce);
204205
} else {
205206
revert IncorrectInput();
206207
}
@@ -245,6 +246,7 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
245246
)
246247
external
247248
payable
249+
override(IDefiBridge)
248250
returns (
249251
uint256,
250252
uint256,
@@ -257,7 +259,7 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
257259
/**
258260
* @notice Compute how much LUSD to borrow against collateral in order to keep ICR constant and by how much total
259261
* trove debt will increase.
260-
* @param collateral Amount of ETH denominated in Wei
262+
* @param _collateral Amount of ETH denominated in Wei
261263
* @return amtToBorrow Amount of LUSD to borrow to keep ICR constant.
262264
* + borrowing fee)
263265
* @dev I don't use view modifier here because the function updates PriceFeed state.
@@ -273,13 +275,13 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
273275
* Note2: Step 4 is necessary to avoid loss of precision. BORROWING_RATE / DECIMAL_PRECISION was rounded to 0.
274276
* Note3: The borrowing fee computation is on this line in Liquity code: https://github.com/liquity/dev/blob/cb583ddf5e7de6010e196cfe706bd0ca816ea40e/packages/contracts/contracts/TroveManager.sol#L1433
275277
*/
276-
function computeAmtToBorrow(uint256 collateral) public returns (uint256 amtToBorrow) {
278+
function computeAmtToBorrow(uint256 _collateral) public returns (uint256 amtToBorrow) {
277279
uint256 price = TROVE_MANAGER.priceFeed().fetchPrice();
278280
bool isRecoveryMode = TROVE_MANAGER.checkRecoveryMode(price);
279281
if (TROVE_MANAGER.getTroveStatus(address(this)) == 1) {
280282
// Trove is active - use current ICR and not the initial one
281283
uint256 icr = TROVE_MANAGER.getCurrentICR(address(this), price);
282-
amtToBorrow = (collateral * price) / icr;
284+
amtToBorrow = (_collateral * price) / icr;
283285
if (!isRecoveryMode) {
284286
// Liquity is not in recovery mode so borrowing fee applies
285287
uint256 borrowingRate = TROVE_MANAGER.getBorrowingRateWithDecay();
@@ -288,7 +290,7 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
288290
} else {
289291
// Trove is inactive - I will use initial ICR to compute debt
290292
// 200e18 - 200 LUSD gas compensation to liquidators
291-
amtToBorrow = (collateral * price) / INITIAL_ICR - 200e18;
293+
amtToBorrow = (_collateral * price) / INITIAL_ICR - 200e18;
292294
if (!isRecoveryMode) {
293295
// Liquity is not in recovery mode so borrowing fee applies
294296
uint256 borrowingRate = TROVE_MANAGER.getBorrowingRateWithDecay();
@@ -300,7 +302,7 @@ contract TroveBridge is ERC20, Ownable, IDefiBridge {
300302
/**
301303
* @dev See {IERC20-totalSupply}.
302304
*/
303-
function totalSupply() public view override returns (uint256) {
305+
function totalSupply() public view override(ERC20) returns (uint256) {
304306
return super.totalSupply() - DUST;
305307
}
306308
}

src/test/liquity/StabilityPoolBridgeInternal.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract StabilityPoolBridgeTestInternal is TestUtil, StabilityPoolBridge(addres
3030
payable(address(0)).transfer(address(this).balance - 1 ether);
3131

3232
uint256 depositedLUSDBeforeSwap = STABILITY_POOL.getCompoundedLUSDDeposit(address(this));
33-
swapRewardsToLUSDAndDeposit();
33+
_swapRewardsToLUSDAndDeposit();
3434
uint256 depositedLUSDAfterSwap = STABILITY_POOL.getCompoundedLUSDDeposit(address(this));
3535

3636
// Verify that rewards were swapped for non-zero amount and correctly staked

0 commit comments

Comments
 (0)