@@ -55,6 +55,7 @@ contract FlashMintLeveragedZeroEx is ReentrancyGuard, Ownable {
55
55
56
56
struct LeveragedTokenData {
57
57
address collateralToken;
58
+ address collateralAToken;
58
59
uint256 collateralAmount;
59
60
address debtToken;
60
61
uint256 debtAmount;
@@ -397,9 +398,17 @@ contract FlashMintLeveragedZeroEx is ReentrancyGuard, Ownable {
397
398
function approveSetToken (ISetToken _setToken , bool _isAave ) external {
398
399
LeveragedTokenData memory leveragedTokenData = _getLeveragedTokenData (_setToken, 1 ether, true , _isAave);
399
400
400
- _approveToken (IERC20 (leveragedTokenData.collateralToken));
401
401
402
- _approveToken (IERC20 (leveragedTokenData.debtToken));
402
+ if (_isAave){
403
+ _approveToken (IERC20 (leveragedTokenData.collateralAToken));
404
+ _approveToken (IERC20 (leveragedTokenData.debtToken));
405
+ _approveTokenToLendingPool (IERC20 (leveragedTokenData.collateralToken));
406
+ _approveTokenToLendingPool (IERC20 (leveragedTokenData.debtToken));
407
+ } else {
408
+ _approveToken (IERC20 (leveragedTokenData.collateralToken));
409
+ _approveToken (IERC20 (leveragedTokenData.debtToken));
410
+
411
+ }
403
412
}
404
413
405
414
/* ============ Internal Functions ============ */
@@ -592,13 +601,15 @@ contract FlashMintLeveragedZeroEx is ReentrancyGuard, Ownable {
592
601
if (equityPositions[0 ] > 0 ){
593
602
return LeveragedTokenData (
594
603
_isAave ? IAToken (components[0 ]).UNDERLYING_ASSET_ADDRESS () : components[0 ],
604
+ _isAave ? components[0 ] : address (0 ),
595
605
equityPositions[0 ] + ROUNDING_ERROR_MARGIN,
596
606
components[1 ],
597
607
debtPositions[1 ]
598
608
);
599
609
} else {
600
610
return LeveragedTokenData (
601
611
_isAave ? IAToken (components[1 ]).UNDERLYING_ASSET_ADDRESS () : components[1 ],
612
+ _isAave ? components[1 ] : address (0 ),
602
613
equityPositions[1 ] + ROUNDING_ERROR_MARGIN,
603
614
components[0 ],
604
615
debtPositions[0 ]
@@ -617,6 +628,23 @@ contract FlashMintLeveragedZeroEx is ReentrancyGuard, Ownable {
617
628
_safeApprove (_token, address (debtIssuanceModule), MAX_UINT256);
618
629
}
619
630
631
+ /**
632
+ * Approves max amount of token to lending pool
633
+ *
634
+ * @param _token Address of the token to approve
635
+ */
636
+ function _approveTokenToLendingPool (
637
+ IERC20 _token
638
+ )
639
+ internal
640
+ {
641
+ uint256 allowance = _token.allowance (address (this ), address (aavePool));
642
+ if (allowance > 0 ) {
643
+ _token.approve (address (aavePool), 0 );
644
+ }
645
+ _token.approve (address (aavePool), MAX_UINT256);
646
+ }
647
+
620
648
/**
621
649
* Initiates a flashloan call with the correct parameters for issuing set tokens in the callback
622
650
* Borrows correct amount of collateral token and and forwards encoded memory to controll issuance in the callback.
0 commit comments