From 783fa320cf62fd8072568d2e1af0c36af69407f6 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 15 Mar 2024 19:41:34 +0900 Subject: [PATCH] fix: approve `quote` with sum of coupons --- contracts/BorrowControllerV2.sol | 2 +- contracts/libraries/ControllerV2.sol | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/contracts/BorrowControllerV2.sol b/contracts/BorrowControllerV2.sol index 80b7f52..3d80084 100644 --- a/contracts/BorrowControllerV2.sol +++ b/contracts/BorrowControllerV2.sol @@ -15,7 +15,7 @@ import {Epoch, EpochLibrary} from "./libraries/Epoch.sol"; import {ControllerV2} from "./libraries/ControllerV2.sol"; import {ERC20PermitParams, PermitSignature, PermitParamsLibrary} from "./libraries/PermitParams.sol"; -contract BorrowController is IBorrowControllerV2, ControllerV2, IPositionLocker { +contract BorrowControllerV2 is IBorrowControllerV2, ControllerV2, IPositionLocker { using PermitParamsLibrary for *; using EpochLibrary for Epoch; diff --git a/contracts/libraries/ControllerV2.sol b/contracts/libraries/ControllerV2.sol index 2ab1283..d0928c2 100644 --- a/contracts/libraries/ControllerV2.sol +++ b/contracts/libraries/ControllerV2.sol @@ -57,7 +57,7 @@ abstract contract ControllerV2 is IControllerV2, ERC1155Holder, Ownable2Step, Re address weth ) Ownable(msg.sender) { _wrapped1155Factory = IWrapped1155Factory(wrapped1155Factory); - _cloberController = IController(_cloberController); + _cloberController = IController(cloberController); _couponManager = ICouponManager(couponManager); _bookManager = IBookManager(bookManager); @@ -98,10 +98,15 @@ abstract contract ControllerV2 is IControllerV2, ERC1155Holder, Ownable2Step, Re IController.ERC20PermitParams[] memory erc20PermitParamsList; IController.ERC721PermitParams[] memory erc721PermitParamsList; + uint256 amount; + address quote; // all quote is same + length = couponsToBurn.length; for (uint256 i = 0; i < length; ++i) { - actionList[couponsToBurn.length + i] = IController.Action.TAKE; + actionList[i] = IController.Action.TAKE; IBookManager.BookKey memory key = _couponBuyMarkets[couponsToBurn[i].key.toId()]; + quote = Currency.unwrap(key.quote); + amount += couponsToBurn[i].amount; paramsDataList[i] = abi.encode( IController.TakeOrderParams({ id: key.toId(), @@ -111,12 +116,13 @@ abstract contract ControllerV2 is IControllerV2, ERC1155Holder, Ownable2Step, Re }) ); } + if (quote != address (0)) IERC20(quote).approve(address(_cloberController), amount); length = couponsToMint.length; for (uint256 i = 0; i < length; ++i) { - actionList[i] = IController.Action.SPEND; + actionList[couponsToBurn.length + i] = IController.Action.SPEND; IBookManager.BookKey memory key = _couponSellMarkets[couponsToMint[i].key.toId()]; - uint256 amount = couponsToMint[i].amount; + amount = couponsToMint[i].amount; paramsDataList[couponsToBurn.length + i] = abi.encode( IController.SpendOrderParams({ id: key.toId(), @@ -212,7 +218,7 @@ abstract contract ControllerV2 is IControllerV2, ERC1155Holder, Ownable2Step, Re BookId buyMarketBookId = buyBookKey.toId(); if ( _bookManager.getBookKey(sellMarketBookId).unit != sellBookKey.unit - || _bookManager.getBookKey(buyMarketBookId).unit != buyMarketBookId.unit + || _bookManager.getBookKey(buyMarketBookId).unit != buyBookKey.unit ) { revert InvalidMarket(); }