Skip to content

Commit e89098c

Browse files
authored
fix: Use DexAdapterV3 in new FlashMint contracts (#190)
use DexAdapterV3 in new FlashMint contracts
1 parent b4b7216 commit e89098c

File tree

10 files changed

+120
-60
lines changed

10 files changed

+120
-60
lines changed

contracts/exchangeIssuance/FlashMintDex.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { IController } from "../interfaces/IController.sol";
3030
import { ISetToken } from "../interfaces/ISetToken.sol";
3131
import { IWETH } from "../interfaces/IWETH.sol";
3232
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
33-
import { DEXAdapterV2 } from "./DEXAdapterV2.sol";
33+
import { DEXAdapterV3 } from "./DEXAdapterV3.sol";
3434

3535
/**
3636
* @title FlashMintDex
@@ -41,7 +41,7 @@ import { DEXAdapterV2 } from "./DEXAdapterV2.sol";
4141
* The FlashMint SDK (https://github.com/IndexCoop/flash-mint-sdk) provides a unified interface for this and other FlashMint contracts.
4242
*/
4343
contract FlashMintDex is Ownable, ReentrancyGuard {
44-
using DEXAdapterV2 for DEXAdapterV2.Addresses;
44+
using DEXAdapterV3 for DEXAdapterV3.Addresses;
4545
using Address for address payable;
4646
using SafeMath for uint256;
4747
using PreciseUnitMath for uint256;
@@ -58,22 +58,22 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
5858
address public immutable WETH;
5959
IController public immutable setController;
6060
IController public immutable indexController;
61-
DEXAdapterV2.Addresses public dexAdapter;
61+
DEXAdapterV3.Addresses public dexAdapter;
6262

6363
/* ============ Structs ============ */
6464
struct IssueRedeemParams {
6565
ISetToken setToken; // The address of the SetToken to be issued/redeemed
6666
uint256 amountSetToken; // The amount of SetTokens to issue/redeem
67-
DEXAdapterV2.SwapData[] componentSwapData; // The swap data from WETH to each component token
67+
DEXAdapterV3.SwapData[] componentSwapData; // The swap data from WETH to each component token
6868
address issuanceModule; // The address of the issuance module to be used
6969
bool isDebtIssuance; // A flag indicating whether the issuance module is a debt issuance module
7070
}
7171

7272
struct PaymentInfo {
7373
IERC20 token; // The address of the input/output token for issuance/redemption
7474
uint256 limitAmt; // Max/min amount of payment token spent/received
75-
DEXAdapterV2.SwapData swapDataTokenToWeth; // The swap data from payment token to WETH
76-
DEXAdapterV2.SwapData swapDataWethToToken; // The swap data from WETH back to payment token
75+
DEXAdapterV3.SwapData swapDataTokenToWeth; // The swap data from payment token to WETH
76+
DEXAdapterV3.SwapData swapDataWethToToken; // The swap data from WETH back to payment token
7777
}
7878

7979
/* ============ Events ============ */
@@ -120,7 +120,7 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
120120
constructor(
121121
IController _setController,
122122
IController _indexController,
123-
DEXAdapterV2.Addresses memory _dexAddresses
123+
DEXAdapterV3.Addresses memory _dexAddresses
124124
)
125125
public
126126
{
@@ -208,7 +208,7 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
208208
*/
209209
function getIssueExactSet(
210210
IssueRedeemParams memory _issueParams,
211-
DEXAdapterV2.SwapData memory _swapDataInputTokenToWeth
211+
DEXAdapterV3.SwapData memory _swapDataInputTokenToWeth
212212
)
213213
external
214214
returns (uint256)
@@ -230,7 +230,7 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
230230
*/
231231
function getRedeemExactSet(
232232
IssueRedeemParams memory _redeemParams,
233-
DEXAdapterV2.SwapData memory _swapDataWethToOutputToken
233+
DEXAdapterV3.SwapData memory _swapDataWethToOutputToken
234234
)
235235
external
236236
returns (uint256)
@@ -375,7 +375,7 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
375375
}
376376

377377
/**
378-
* Swaps a given amount of an ERC20 token for WETH using the DEXAdapter.
378+
* Swaps a given amount of an ERC20 token for WETH using the DEXAdapterV3.
379379
*
380380
* @param _paymentToken Address of the ERC20 payment token
381381
* @param _paymentTokenAmount Amount of payment token to swap
@@ -386,7 +386,7 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
386386
function _swapPaymentTokenForWeth(
387387
IERC20 _paymentToken,
388388
uint256 _paymentTokenAmount,
389-
DEXAdapterV2.SwapData memory _swapData
389+
DEXAdapterV3.SwapData memory _swapData
390390
)
391391
internal
392392
returns (uint256 amountWethOut)
@@ -403,15 +403,15 @@ contract FlashMintDex is Ownable, ReentrancyGuard {
403403
}
404404

405405
/**
406-
* Swaps a given amount of an WETH for ERC20 using the DEXAdapter.
406+
* Swaps a given amount of an WETH for ERC20 using the DEXAdapterV3.
407407
*
408408
* @param _wethAmount Amount of WETH to swap for input token
409409
* @param _paymentToken Address of the input token
410410
* @param _swapData Swap data from WETH to input token
411411
*
412412
* @return amountOut Amount of ERC20 received after the swap
413413
*/
414-
function _swapWethForPaymentToken(uint256 _wethAmount, IERC20 _paymentToken, DEXAdapterV2.SwapData memory _swapData)
414+
function _swapWethForPaymentToken(uint256 _wethAmount, IERC20 _paymentToken, DEXAdapterV3.SwapData memory _swapData)
415415
internal
416416
returns (uint256 amountOut)
417417
{

contracts/exchangeIssuance/FlashMintNAV.sol

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ import { IController } from "../interfaces/IController.sol";
3131
import { ISetToken } from "../interfaces/ISetToken.sol";
3232
import { IWETH } from "../interfaces/IWETH.sol";
3333
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
34-
import { DEXAdapterV2 } from "./DEXAdapterV2.sol";
34+
import { DEXAdapterV3 } from "./DEXAdapterV3.sol";
3535

3636
/**
3737
* @title FlashMintNAV
3838
* @author Index Cooperative
3939
* @notice Part of a family of FlashMint contracts that allows users to issue and redeem SetTokens with a single input/output token (ETH/ERC20).
4040
* Allows the caller to combine a DEX swap and a SetToken issuance or redemption in a single transaction.
4141
* Supports SetTokens that use a NAV Issuance Module, and does not require use of off-chain APIs for swap quotes.
42-
* The SetToken must be configured with a reserve asset that has liquidity on the exchanges supported by the DEXAdapterV2 library.
42+
* The SetToken must be configured with a reserve asset that has liquidity on the exchanges supported by the DEXAdapterV3 library.
4343
*
4444
* See the FlashMint SDK for integrating any FlashMint contract (https://github.com/IndexCoop/flash-mint-sdk).
4545
*/
4646
contract FlashMintNAV is Ownable, ReentrancyGuard {
47-
using DEXAdapterV2 for DEXAdapterV2.Addresses;
47+
using DEXAdapterV3 for DEXAdapterV3.Addresses;
4848
using Address for address payable;
4949
using SafeMath for uint256;
5050
using PreciseUnitMath for uint256;
@@ -64,7 +64,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
6464

6565
/* ============ State Variables ============ */
6666

67-
DEXAdapterV2.Addresses public dexAdapter;
67+
DEXAdapterV3.Addresses public dexAdapter;
6868

6969
/* ============ Events ============ */
7070

@@ -85,16 +85,16 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
8585
);
8686

8787
/**
88-
* Initializes the contract with controller, issuance module, and DEXAdapterV2 library addresses.
88+
* Initializes the contract with controller, issuance module, and DEXAdapterV3 library addresses.
8989
*
9090
* @param _setController Address of the protocol controller contract
9191
* @param _navIssuanceModule NAV Issuance Module used to issue and redeem SetTokens
92-
* @param _dexAddresses Struct containing addresses for the DEXAdapterV2 library
92+
* @param _dexAddresses Struct containing addresses for the DEXAdapterV3 library
9393
*/
9494
constructor(
9595
IController _setController,
9696
INAVIssuanceModule _navIssuanceModule,
97-
DEXAdapterV2.Addresses memory _dexAddresses
97+
DEXAdapterV3.Addresses memory _dexAddresses
9898
)
9999
public
100100
{
@@ -117,7 +117,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
117117
address payable _to
118118
) external payable onlyOwner {
119119
for (uint256 i = 0; i < _tokens.length; i++) {
120-
if (address(_tokens[i]) == DEXAdapterV2.ETH_ADDRESS) {
120+
if (address(_tokens[i]) == DEXAdapterV3.ETH_ADDRESS) {
121121
_to.sendValue(address(this).balance);
122122
} else {
123123
_tokens[i].safeTransfer(_to, _tokens[i].balanceOf(address(this)));
@@ -162,7 +162,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
162162
ISetToken _setToken,
163163
address _inputToken,
164164
uint256 _inputTokenAmount,
165-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
165+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
166166
)
167167
external
168168
returns (uint256)
@@ -194,7 +194,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
194194
ISetToken _setToken,
195195
uint256 _setTokenAmount,
196196
address _outputToken,
197-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
197+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
198198
)
199199
external
200200
returns (uint256)
@@ -219,7 +219,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
219219
function issueSetFromExactETH(
220220
ISetToken _setToken,
221221
uint256 _minSetTokenAmount,
222-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
222+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
223223
)
224224
external
225225
payable
@@ -257,7 +257,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
257257
uint256 _minSetTokenAmount,
258258
IERC20 _inputToken,
259259
uint256 _inputTokenAmount,
260-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
260+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
261261
)
262262
external
263263
nonReentrant
@@ -292,7 +292,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
292292
ISetToken _setToken,
293293
uint256 _setTokenAmount,
294294
uint256 _minEthAmount,
295-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
295+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
296296
)
297297
external
298298
nonReentrant
@@ -334,7 +334,7 @@ contract FlashMintNAV is Ownable, ReentrancyGuard {
334334
uint256 _setTokenAmount,
335335
IERC20 _outputToken,
336336
uint256 _minOutputTokenAmount,
337-
DEXAdapterV2.SwapData memory _reserveAssetSwapData
337+
DEXAdapterV3.SwapData memory _reserveAssetSwapData
338338
)
339339
external
340340
nonReentrant

contracts/exchangeIssuance/FlashMintWrapped.sol

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { ISetToken} from "../interfaces/ISetToken.sol";
3131
import { IWETH} from "../interfaces/IWETH.sol";
3232
import { IWrapModuleV2} from "../interfaces/IWrapModuleV2.sol";
3333
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
34-
import { DEXAdapter } from "./DEXAdapter.sol";
34+
import { DEXAdapterV3 } from "./DEXAdapterV3.sol";
3535

3636
/**
3737
* @title FlashMintWrapped
@@ -53,7 +53,7 @@ import { DEXAdapter } from "./DEXAdapter.sol";
5353
* Set components at index 1 = cDAI; then -> ComponentSwapData[1].underlyingERC20 = DAI; (wrapping will happen)
5454
*/
5555
contract FlashMintWrapped is Ownable, ReentrancyGuard {
56-
using DEXAdapter for DEXAdapter.Addresses;
56+
using DEXAdapterV3 for DEXAdapterV3.Addresses;
5757
using Address for address payable;
5858
using Address for address;
5959
using SafeMath for uint256;
@@ -65,8 +65,8 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
6565
struct ComponentSwapData {
6666
// unwrapped token version, e.g. DAI
6767
address underlyingERC20;
68-
// swap data for DEX operation: fees, path, etc. see DEXAdapter.SwapData
69-
DEXAdapter.SwapData dexData;
68+
// swap data for DEX operation: fees, path, etc. see DEXAdapterV3.SwapData
69+
DEXAdapterV3.SwapData dexData;
7070
// ONLY relevant for issue, not used for redeem:
7171
// amount that has to be bought of the unwrapped token version (to cover required wrapped component amounts for issuance)
7272
// this amount has to be computed beforehand through the exchange rate of wrapped Component <> unwrappedComponent
@@ -92,7 +92,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
9292

9393
/* ============ State Variables ============ */
9494

95-
DEXAdapter.Addresses public dexAdapter;
95+
DEXAdapterV3.Addresses public dexAdapter;
9696

9797
/* ============ Events ============ */
9898

@@ -139,12 +139,12 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
139139
if (_inputToken != _outputToken) {
140140
require(
141141
_path[0] == _inputToken ||
142-
(_inputToken == dexAdapter.weth && _path[0] == DEXAdapter.ETH_ADDRESS),
142+
(_inputToken == dexAdapter.weth && _path[0] == DEXAdapterV3.ETH_ADDRESS),
143143
"FlashMint: INPUT_TOKEN_NOT_IN_PATH"
144144
);
145145
require(
146146
_path[_path.length - 1] == _outputToken ||
147-
(_outputToken == dexAdapter.weth && _path[_path.length - 1] == DEXAdapter.ETH_ADDRESS),
147+
(_outputToken == dexAdapter.weth && _path[_path.length - 1] == DEXAdapterV3.ETH_ADDRESS),
148148
"FlashMint: OUTPUT_TOKEN_NOT_IN_PATH"
149149
);
150150
}
@@ -162,7 +162,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
162162
* @param _wrapModule WrapModuleV2 used to obtain a valid wrap adapter
163163
*/
164164
constructor(
165-
DEXAdapter.Addresses memory _dexAddresses,
165+
DEXAdapterV3.Addresses memory _dexAddresses,
166166
IController _setController,
167167
IDebtIssuanceModule _issuanceModule,
168168
address _wrapModule
@@ -187,7 +187,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
187187
*/
188188
function withdrawTokens(IERC20[] calldata _tokens, address payable _to) external onlyOwner payable {
189189
for(uint256 i = 0; i < _tokens.length; i++) {
190-
if(address(_tokens[i]) == DEXAdapter.ETH_ADDRESS){
190+
if(address(_tokens[i]) == DEXAdapterV3.ETH_ADDRESS){
191191
_to.sendValue(address(this).balance);
192192
}
193193
else{
@@ -206,7 +206,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
206206
function approveSetToken(ISetToken _setToken) external isSetToken(_setToken) {
207207
address[] memory _components = _setToken.getComponents();
208208
for (uint256 i = 0; i < _components.length; ++i) {
209-
DEXAdapter._safeApprove(IERC20(_components[i]), address(issuanceModule), MAX_UINT256);
209+
DEXAdapterV3._safeApprove(IERC20(_components[i]), address(issuanceModule), MAX_UINT256);
210210
}
211211
}
212212

@@ -503,7 +503,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
503503
emit FlashMint(
504504
msg.sender,
505505
_setToken,
506-
_issueFromETH ? IERC20(DEXAdapter.ETH_ADDRESS) : _inputToken,
506+
_issueFromETH ? IERC20(DEXAdapterV3.ETH_ADDRESS) : _inputToken,
507507
spentInputTokenAmount,
508508
_amountSetToken
509509
);
@@ -567,7 +567,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
567567
emit FlashRedeem(
568568
msg.sender,
569569
_setToken,
570-
_redeemToETH ? IERC20(DEXAdapter.ETH_ADDRESS) : _outputToken,
570+
_redeemToETH ? IERC20(DEXAdapterV3.ETH_ADDRESS) : _outputToken,
571571
_amountSetToken,
572572
totalOutputTokenObtained
573573
);
@@ -796,7 +796,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
796796
* @param _outputToken Output token that will be bought
797797
* @param _amount Amount that will be bought
798798
* @param _maxAmountIn Maximum aount of input token that can be spent
799-
* @param _swapDexData DEXAdapter.SwapData with path, fees, etc. for inputToken -> outputToken swap
799+
* @param _swapDexData DEXAdapterV3.SwapData with path, fees, etc. for inputToken -> outputToken swap
800800
*
801801
* @return Amount of spent _inputToken
802802
*/
@@ -805,7 +805,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
805805
IERC20 _outputToken,
806806
uint256 _amount,
807807
uint256 _maxAmountIn,
808-
DEXAdapter.SwapData calldata _swapDexData
808+
DEXAdapterV3.SwapData calldata _swapDexData
809809
)
810810
internal
811811
isValidPath(_swapDexData.path, address(_inputToken), address(_outputToken))
@@ -822,15 +822,15 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
822822
* @param _inputToken Input token that will be sold
823823
* @param _outputToken Output token that will be bought
824824
* @param _amount Amount that will be sold
825-
* @param _swapDexData DEXAdapter.SwapData with path, fees, etc. for inputToken -> outputToken swap
825+
* @param _swapDexData DEXAdapterV3.SwapData with path, fees, etc. for inputToken -> outputToken swap
826826
*
827827
* @return amount of received _outputToken
828828
*/
829829
function _swapFromExact(
830830
IERC20 _inputToken,
831831
IERC20 _outputToken,
832832
uint256 _amount,
833-
DEXAdapter.SwapData calldata _swapDexData
833+
DEXAdapterV3.SwapData calldata _swapDexData
834834
)
835835
internal
836836
isValidPath(_swapDexData.path, address(_inputToken), address(_outputToken))
@@ -881,7 +881,7 @@ contract FlashMintWrapped is Ownable, ReentrancyGuard {
881881
);
882882

883883
// 3. approve token transfer from this to _wrapCallTarget
884-
DEXAdapter._safeApprove(
884+
DEXAdapterV3._safeApprove(
885885
IERC20(_underlyingToken),
886886
_wrapCallTarget,
887887
_wrapAmount

0 commit comments

Comments
 (0)