From 6a65b1a395bf04ed4a05c314264b0b346cbab99b Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:18:26 -0400 Subject: [PATCH 01/12] implementation --- contracts/libraries/Allowance.sol | 28 +++++++++++++++++++++++ contracts/p0/mixins/Trading.sol | 9 ++++++-- contracts/p1/mixins/Trading.sol | 9 ++++++-- contracts/plugins/trading/GnosisTrade.sol | 10 +++++--- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 contracts/libraries/Allowance.sol diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol new file mode 100644 index 0000000000..86eb2d73e4 --- /dev/null +++ b/contracts/libraries/Allowance.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BlueOak-1.0.0 +pragma solidity 0.8.19; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +library AllowanceLib { + /// An approve helper that: + /// 1. Sets initial allowance to 0 + /// 2. Tries to set the provided allowance + /// 3. Falls back to setting a maximum allowance, if (2) fails + function safeApproveFallbackToMax( + IERC20 token, + address spender, + uint256 value + ) internal { + // 1. Set initial allowance to 0 + require(token.approve(spender, 0), "failed to set 0 allowance"); + + // 2. Try to set the provided allowance + bool success; // bool success = false; + try token.approve(spender, value) returns (bool _success) { + success = _success; + } catch {} + + // 3. Fall-back to setting a maximum allowance + if (!success) token.approve(spender, type(uint256).max); + } +} diff --git a/contracts/p0/mixins/Trading.sol b/contracts/p0/mixins/Trading.sol index b49aee3f11..d0c5f7496f 100644 --- a/contracts/p0/mixins/Trading.sol +++ b/contracts/p0/mixins/Trading.sol @@ -6,6 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../../interfaces/IBroker.sol"; import "../../interfaces/IMain.sol"; import "../../interfaces/ITrade.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "./Rewardable.sol"; @@ -68,8 +69,12 @@ abstract contract TradingP0 is RewardableP0, ITrading { IBroker broker = main.broker(); assert(address(trades[req.sell.erc20()]) == address(0)); - req.sell.erc20().safeApprove(address(broker), 0); - req.sell.erc20().safeApprove(address(broker), req.sellAmount); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax(req.sell.erc20(), address(broker), req.sellAmount); trade = broker.openTrade(kind, req, prices); trades[req.sell.erc20()] = trade; diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 863f7ab113..9c8daba201 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/Multicall.sol"; import "../../interfaces/ITrade.sol"; import "../../interfaces/ITrading.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "./Component.sol"; import "./RewardableLib.sol"; @@ -120,8 +121,12 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl IERC20 sell = req.sell.erc20(); assert(address(trades[sell]) == address(0)); - IERC20Upgradeable(address(sell)).safeApprove(address(broker), 0); - IERC20Upgradeable(address(sell)).safeApprove(address(broker), req.sellAmount); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax(req.sell.erc20(), address(broker), req.sellAmount); trade = broker.openTrade(kind, req, prices); trades[sell] = trade; diff --git a/contracts/plugins/trading/GnosisTrade.sol b/contracts/plugins/trading/GnosisTrade.sol index e8413c5fea..25b9c1ba44 100644 --- a/contracts/plugins/trading/GnosisTrade.sol +++ b/contracts/plugins/trading/GnosisTrade.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import "../../libraries/Allowance.sol"; import "../../libraries/Fixed.sol"; import "../../interfaces/IBroker.sol"; import "../../interfaces/IGnosis.sol"; @@ -130,9 +131,12 @@ contract GnosisTrade is ITrade { // == Interactions == - // Set allowance (two safeApprove calls to support USDT) - IERC20Upgradeable(address(sell)).safeApprove(address(gnosis), 0); - IERC20Upgradeable(address(sell)).safeApprove(address(gnosis), initBal); + // Set allowance via custom approval -- first sets allowance to 0, then sets allowance + // to either the requested amount or the maximum possible amount, if that fails. + // + // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve + // amount is > 0 and < type(uint256).max. + AllowanceLib.safeApproveFallbackToMax(sell, address(gnosis), initBal); auctionId = gnosis.initiateAuction( sell, From a4d95470041209ee0e1d66dca34598755723f86d Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:19:18 -0400 Subject: [PATCH 02/12] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c40e6a6de..693d32bd91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +# 3.0.1 + +### Upgrade steps + +Update `BackingManager`, both `RevenueTraders` (rTokenTrader/rsrTrader), and call `Broker.setBatchTradeImplementation()` passing in the new `GnosisTrade` address. + # 3.0.0 ### Upgrade Steps From 700f202c9730f1eb8123b45deb52a463ae40d799 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:23:20 -0400 Subject: [PATCH 03/12] implementation nits --- contracts/libraries/Allowance.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index 86eb2d73e4..de5e20bb2e 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -8,6 +8,8 @@ library AllowanceLib { /// 1. Sets initial allowance to 0 /// 2. Tries to set the provided allowance /// 3. Falls back to setting a maximum allowance, if (2) fails + /// Context: Some new-age ERC20s think it's a good idea to revert for allowances + /// that are > 0 but < type(uint256).max. function safeApproveFallbackToMax( IERC20 token, address spender, @@ -16,6 +18,8 @@ library AllowanceLib { // 1. Set initial allowance to 0 require(token.approve(spender, 0), "failed to set 0 allowance"); + if (value == 0) return; + // 2. Try to set the provided allowance bool success; // bool success = false; try token.approve(spender, value) returns (bool _success) { From 5ee29e362be0287e98a79b12552ef260c1f30e84 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:42:57 -0400 Subject: [PATCH 04/12] add regression test, confirmed fails on previous code --- contracts/plugins/mocks/BadERC20.sol | 10 ++++++++++ test/scenario/BadERC20.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/contracts/plugins/mocks/BadERC20.sol b/contracts/plugins/mocks/BadERC20.sol index 99c7791e84..11570a4e4c 100644 --- a/contracts/plugins/mocks/BadERC20.sol +++ b/contracts/plugins/mocks/BadERC20.sol @@ -11,6 +11,7 @@ contract BadERC20 is ERC20Mock { uint8 private _decimals; uint192 public transferFee; // {1} bool public revertDecimals; + bool public revertApprove; // if true, reverts for any approve > 0 and < type(uint256).max mapping(address => bool) public censored; @@ -34,6 +35,10 @@ contract BadERC20 is ERC20Mock { censored[account] = val; } + function setRevertApprove(bool newRevertApprove) external { + revertApprove = newRevertApprove; + } + function decimals() public view override returns (uint8) { bytes memory data = abi.encodePacked((bytes4(keccak256("absentDecimalsFn()")))); @@ -42,6 +47,11 @@ contract BadERC20 is ERC20Mock { return _decimals; } + function approve(address spender, uint256 amount) public virtual override returns (bool) { + if (revertApprove && amount > 0 && amount < type(uint256).max) revert("revertApprove"); + return super.approve(spender, amount); + } + function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); if (censored[owner] || censored[to]) revert("censored"); diff --git a/test/scenario/BadERC20.test.ts b/test/scenario/BadERC20.test.ts index 6874a021ca..13adebdcdd 100644 --- a/test/scenario/BadERC20.test.ts +++ b/test/scenario/BadERC20.test.ts @@ -396,4 +396,28 @@ describe(`Bad ERC20 - P${IMPLEMENTATION}`, () => { ) }) }) + + describe('with fussy approvals', function () { + let issueAmt: BigNumber + + beforeEach(async () => { + issueAmt = initialBal.div(100) + await token0.connect(addr1).approve(rToken.address, issueAmt) + await token0.setRevertApprove(true) + await rToken.connect(addr1).issue(issueAmt) + }) + + it('Regression test wcUSDCv3 10/10/2023 -- should not revert during recollateralization', async () => { + await basketHandler.setPrimeBasket( + [token0.address, backupToken.address], + [fp('0.5'), fp('0.5')] + ) + await basketHandler.refreshBasket() + + // Should launch recollateralization auction successfully + await expect(backingManager.rebalance(TradeKind.BATCH_AUCTION)) + .to.emit(backingManager, 'TradeStarted') + .withArgs(anyValue, token0.address, backupToken.address, anyValue, anyValue) + }) + }) }) From 3b2b5796afece36c6de1341f5ba97122f3cc2854 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:48:07 -0400 Subject: [PATCH 05/12] slightly better implementation --- contracts/libraries/Allowance.sol | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index de5e20bb2e..b8da24064b 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -16,17 +16,24 @@ library AllowanceLib { uint256 value ) internal { // 1. Set initial allowance to 0 - require(token.approve(spender, 0), "failed to set 0 allowance"); + token.approve(spender, 0); + require(token.allowance(address(this), spender) == 0, "allowance not 0"); if (value == 0) return; // 2. Try to set the provided allowance bool success; // bool success = false; - try token.approve(spender, value) returns (bool _success) { - success = _success; + try token.approve(spender, value) returns (bool) { + success = token.allowance(address(this), spender) == value; } catch {} // 3. Fall-back to setting a maximum allowance - if (!success) token.approve(spender, type(uint256).max); + if (!success) { + token.approve(spender, type(uint256).max); + require( + token.allowance(address(this), spender) == type(uint256).max, + "allowance not max" + ); + } } } From 233eec6934874580b53d8c159930484c94a92e27 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 12:58:34 -0400 Subject: [PATCH 06/12] add documentation comment to RevenueTrader._distributeTokenToBuy() --- contracts/p0/RevenueTrader.sol | 3 +++ contracts/p1/RevenueTrader.sol | 3 +++ 2 files changed, 6 insertions(+) diff --git a/contracts/p0/RevenueTrader.sol b/contracts/p0/RevenueTrader.sol index 2f380927fe..a62cf8bd18 100644 --- a/contracts/p0/RevenueTrader.sol +++ b/contracts/p0/RevenueTrader.sol @@ -130,6 +130,9 @@ contract RevenueTraderP0 is TradingP0, IRevenueTrader { uint256 bal = tokenToBuy.balanceOf(address(this)); tokenToBuy.safeApprove(address(main.distributor()), 0); tokenToBuy.safeApprove(address(main.distributor()), bal); + // do not need to use AllowanceLib.safeApproveFallbackToCustom here because + // tokenToBuy can be assumed to be either RSR or the RToken + main.distributor().distribute(tokenToBuy, bal); } } diff --git a/contracts/p1/RevenueTrader.sol b/contracts/p1/RevenueTrader.sol index fe7b409b50..43253c6b0e 100644 --- a/contracts/p1/RevenueTrader.sol +++ b/contracts/p1/RevenueTrader.sol @@ -179,6 +179,9 @@ contract RevenueTraderP1 is TradingP1, IRevenueTrader { uint256 bal = tokenToBuy.balanceOf(address(this)); tokenToBuy.safeApprove(address(distributor), 0); tokenToBuy.safeApprove(address(distributor), bal); + + // do not need to use AllowanceLib.safeApproveFallbackToCustom here because + // tokenToBuy can be assumed to be either RSR or the RToken distributor.distribute(tokenToBuy, bal); } From 61079639ce6d6d13c98ad59fcd458d0e1b62ae7d Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 13:02:09 -0400 Subject: [PATCH 07/12] add second regression test for revenue auctions --- test/scenario/BadERC20.test.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/test/scenario/BadERC20.test.ts b/test/scenario/BadERC20.test.ts index 13adebdcdd..220ed60d0f 100644 --- a/test/scenario/BadERC20.test.ts +++ b/test/scenario/BadERC20.test.ts @@ -407,17 +407,28 @@ describe(`Bad ERC20 - P${IMPLEMENTATION}`, () => { await rToken.connect(addr1).issue(issueAmt) }) - it('Regression test wcUSDCv3 10/10/2023 -- should not revert during recollateralization', async () => { - await basketHandler.setPrimeBasket( - [token0.address, backupToken.address], - [fp('0.5'), fp('0.5')] - ) - await basketHandler.refreshBasket() - - // Should launch recollateralization auction successfully - await expect(backingManager.rebalance(TradeKind.BATCH_AUCTION)) - .to.emit(backingManager, 'TradeStarted') - .withArgs(anyValue, token0.address, backupToken.address, anyValue, anyValue) + context('Regression tests wcUSDCv3 10/10/2023', () => { + it('should not revert during recollateralization', async () => { + await basketHandler.setPrimeBasket( + [token0.address, backupToken.address], + [fp('0.5'), fp('0.5')] + ) + await basketHandler.refreshBasket() + + // Should launch recollateralization auction successfully + await expect(backingManager.rebalance(TradeKind.BATCH_AUCTION)) + .to.emit(backingManager, 'TradeStarted') + .withArgs(anyValue, token0.address, backupToken.address, anyValue, anyValue) + }) + + it('should not revert during revenue auction', async () => { + await token0.mint(rsrTrader.address, issueAmt) + + // Should launch revenue auction successfully + await expect(rsrTrader.manageTokens([token0.address], [TradeKind.BATCH_AUCTION])) + .to.emit(rsrTrader, 'TradeStarted') + .withArgs(anyValue, token0.address, rsr.address, anyValue, anyValue) + }) }) }) }) From 1f49f794e5431f011b4524173cfef9bf9726ef6a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 10 Oct 2023 15:31:54 -0400 Subject: [PATCH 08/12] slight tweak to implementation to account for ERC20s that do not handle max allowances the same way --- contracts/libraries/Allowance.sol | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index b8da24064b..e0855f6af2 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -30,10 +30,7 @@ library AllowanceLib { // 3. Fall-back to setting a maximum allowance if (!success) { token.approve(spender, type(uint256).max); - require( - token.allowance(address(this), spender) == type(uint256).max, - "allowance not max" - ); + require(token.allowance(address(this), spender) >= value, "allowance missing"); } } } From ded1f1f8045103ff98f3ec3aaf9f3227f37097db Mon Sep 17 00:00:00 2001 From: Akshat Mittal Date: Wed, 11 Oct 2023 15:57:08 +0530 Subject: [PATCH 09/12] Additional fix for USDT-like tokens with no return value --- contracts/libraries/Allowance.sol | 12 +++++++++--- contracts/p0/mixins/Trading.sol | 6 +++++- contracts/p1/mixins/Trading.sol | 6 +++++- contracts/plugins/trading/GnosisTrade.sol | 2 +- hardhat.config.ts | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index e0855f6af2..849fa3f1da 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: BlueOak-1.0.0 pragma solidity 0.8.19; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +interface IERC20ApproveOnly { + function approve(address spender, uint256 value) external; + + function allowance(address owner, address spender) external view returns (uint256); +} library AllowanceLib { /// An approve helper that: @@ -11,10 +15,12 @@ library AllowanceLib { /// Context: Some new-age ERC20s think it's a good idea to revert for allowances /// that are > 0 but < type(uint256).max. function safeApproveFallbackToMax( - IERC20 token, + address token_address, address spender, uint256 value ) internal { + IERC20ApproveOnly token = IERC20ApproveOnly(token_address); + // 1. Set initial allowance to 0 token.approve(spender, 0); require(token.allowance(address(this), spender) == 0, "allowance not 0"); @@ -23,7 +29,7 @@ library AllowanceLib { // 2. Try to set the provided allowance bool success; // bool success = false; - try token.approve(spender, value) returns (bool) { + try token.approve(spender, value) { success = token.allowance(address(this), spender) == value; } catch {} diff --git a/contracts/p0/mixins/Trading.sol b/contracts/p0/mixins/Trading.sol index d0c5f7496f..52fc993eea 100644 --- a/contracts/p0/mixins/Trading.sol +++ b/contracts/p0/mixins/Trading.sol @@ -74,7 +74,11 @@ abstract contract TradingP0 is RewardableP0, ITrading { // // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve // amount is > 0 and < type(uint256).max. - AllowanceLib.safeApproveFallbackToMax(req.sell.erc20(), address(broker), req.sellAmount); + AllowanceLib.safeApproveFallbackToMax( + address(req.sell.erc20()), + address(broker), + req.sellAmount + ); trade = broker.openTrade(kind, req, prices); trades[req.sell.erc20()] = trade; diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 9c8daba201..8801c0e6dc 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -126,7 +126,11 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl // // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve // amount is > 0 and < type(uint256).max. - AllowanceLib.safeApproveFallbackToMax(req.sell.erc20(), address(broker), req.sellAmount); + AllowanceLib.safeApproveFallbackToMax( + address(req.sell.erc20()), + address(broker), + req.sellAmount + ); trade = broker.openTrade(kind, req, prices); trades[sell] = trade; diff --git a/contracts/plugins/trading/GnosisTrade.sol b/contracts/plugins/trading/GnosisTrade.sol index 25b9c1ba44..9f52e6387a 100644 --- a/contracts/plugins/trading/GnosisTrade.sol +++ b/contracts/plugins/trading/GnosisTrade.sol @@ -136,7 +136,7 @@ contract GnosisTrade is ITrade { // // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve // amount is > 0 and < type(uint256).max. - AllowanceLib.safeApproveFallbackToMax(sell, address(gnosis), initBal); + AllowanceLib.safeApproveFallbackToMax(address(sell), address(gnosis), initBal); auctionId = gnosis.initiateAuction( sell, diff --git a/hardhat.config.ts b/hardhat.config.ts index 7b540748d4..9dddd006bf 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -38,7 +38,7 @@ const config: HardhatUserConfig = { // network for tests/in-process stuff forking: useEnv('FORK') ? { - url: forkRpcs[(useEnv('FORK_NETWORK') ?? 'mainnet') as Network], + url: forkRpcs[useEnv('FORK_NETWORK', 'mainnet') as Network], blockNumber: Number(useEnv(`FORK_BLOCK`, forkBlockNumber['default'].toString())), } : undefined, From 9c7803691f67bd9d4c8c727fe5e59916af537127 Mon Sep 17 00:00:00 2001 From: Akshat Mittal Date: Wed, 11 Oct 2023 16:01:32 +0530 Subject: [PATCH 10/12] Make linter happy --- contracts/libraries/Allowance.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index 849fa3f1da..c383ee7f8b 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -15,11 +15,11 @@ library AllowanceLib { /// Context: Some new-age ERC20s think it's a good idea to revert for allowances /// that are > 0 but < type(uint256).max. function safeApproveFallbackToMax( - address token_address, + address tokenAddress, address spender, uint256 value ) internal { - IERC20ApproveOnly token = IERC20ApproveOnly(token_address); + IERC20ApproveOnly token = IERC20ApproveOnly(tokenAddress); // 1. Set initial allowance to 0 token.approve(spender, 0); From a1b2be1b344cd30381048bb146e749956e8d77ad Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Wed, 11 Oct 2023 09:58:28 -0400 Subject: [PATCH 11/12] gas opt. --- contracts/p1/mixins/Trading.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 8801c0e6dc..12c8f115bf 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -127,7 +127,7 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve // amount is > 0 and < type(uint256).max. AllowanceLib.safeApproveFallbackToMax( - address(req.sell.erc20()), + address(sell), address(broker), req.sellAmount ); From 59565d2d40d59273b7ba0e7972fa8e9fa965617e Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Wed, 11 Oct 2023 10:04:02 -0400 Subject: [PATCH 12/12] lint clean --- contracts/libraries/Allowance.sol | 1 + contracts/p1/mixins/Trading.sol | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/contracts/libraries/Allowance.sol b/contracts/libraries/Allowance.sol index c383ee7f8b..c3e5f62e5d 100644 --- a/contracts/libraries/Allowance.sol +++ b/contracts/libraries/Allowance.sol @@ -31,6 +31,7 @@ library AllowanceLib { bool success; // bool success = false; try token.approve(spender, value) { success = token.allowance(address(this), spender) == value; + // solhint-disable-next-line no-empty-blocks } catch {} // 3. Fall-back to setting a maximum allowance diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 12c8f115bf..24b2044d38 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -126,11 +126,7 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl // // Context: wcUSDCv3 has a non-standard approve() function that reverts if the approve // amount is > 0 and < type(uint256).max. - AllowanceLib.safeApproveFallbackToMax( - address(sell), - address(broker), - req.sellAmount - ); + AllowanceLib.safeApproveFallbackToMax(address(sell), address(broker), req.sellAmount); trade = broker.openTrade(kind, req, prices); trades[sell] = trade;