Skip to content

Commit

Permalink
Merge pull request #231 from Ithil-protocol/audit-fix-i11
Browse files Browse the repository at this point in the history
fix i11
  • Loading branch information
OxMarco authored Dec 20, 2023
2 parents 2fd628b + a4cbbc3 commit 4621cea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/services/debit/GmxService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ contract GmxService is AuctionRateModel, DebitService {

function _open(Agreement memory agreement, bytes memory /*data*/) internal override {
if (agreement.loans.length != 1) revert InvalidParams();
if (agreement.collaterals.length != 1) revert InvalidParams();
// First collateral token is GLP
// Second collateral token is USDG
// There's no need to specify the collateral tokens since they are enforced in the code
if (agreement.collaterals.length != 2) revert InvalidParams();

if (IERC20(agreement.loans[0].token).allowance(address(this), address(glpManager)) == 0) {
IERC20(agreement.loans[0].token).approve(address(glpManager), type(uint256).max);
Expand All @@ -72,7 +75,7 @@ contract GmxService is AuctionRateModel, DebitService {
agreement.collaterals[0].amount = routerV2.mintAndStakeGlp(
agreement.loans[0].token,
agreement.loans[0].amount + agreement.loans[0].margin,
0,
agreement.collaterals[1].amount,
agreement.collaterals[0].amount
);

Expand Down
6 changes: 4 additions & 2 deletions test/services/GmxService.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ contract GmxServiceTest is BaseIntegrationServiceTest {
IService.ItemType[] memory itemTypes = new IService.ItemType[](1);
itemTypes[0] = IService.ItemType.ERC20;

address[] memory collateralTokens = new address[](1);
address[] memory collateralTokens = new address[](2);
collateralTokens[0] = address(0);
collateralTokens[1] = address(0);

uint256[] memory collateralAmounts = new uint256[](1);
collateralAmounts[0] = 0;
Expand Down Expand Up @@ -139,8 +140,9 @@ contract GmxServiceTest is BaseIntegrationServiceTest {
IService.ItemType[] memory itemTypes = new IService.ItemType[](1);
itemTypes[0] = IService.ItemType.ERC20;

address[] memory collateralTokens = new address[](1);
address[] memory collateralTokens = new address[](2);
collateralTokens[0] = address(0);
collateralTokens[1] = address(0);

uint256[] memory collateralAmounts = new uint256[](1);
collateralAmounts[0] = ((loans[0] + margins[0]) * 99 * 1e12) / 100;
Expand Down

0 comments on commit 4621cea

Please sign in to comment.