Skip to content

Commit

Permalink
Fix/srm (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdomrom authored Nov 14, 2024
1 parent e192933 commit 11592a9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[submodule "lib/chainlink"]
path = lib/chainlink
url = https://github.com/smartcontractkit/chainlink
ignore = untracked
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
Expand Down
1 change: 0 additions & 1 deletion scripts/deploy-perp-only-market.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ contract DeployPerpOnlyMarket is Utils {
PMRM(_getContract("BTC", "pmrm")).setWhitelistedCallee(address(market.iapFeed), true);
PMRM(_getContract("BTC", "pmrm")).setWhitelistedCallee(address(market.ibpFeed), true);
PMRM(_getContract("BTC", "pmrm")).setWhitelistedCallee(address(market.perpFeed), true);

} else {
_transferOwner(market, vm.envAddress("MAINNET_OWNER"));
}
Expand Down
4 changes: 2 additions & 2 deletions src/risk-managers/StandardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ contract StandardManager is IStandardManager, ILiquidatableManager, BaseManager,
riskAdding = true;
}
}
} else if (detail.assetType == AssetType.Option) {
// if the user is shorting more options, we need to check margin
} else {
// if the user is shorting more options, or removing collateral, we need to check margin
if (assetDeltas[i].delta < 0) {
riskAdding = true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/deploy-lrt-market-fork.t.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.18;

import "forge-std/console.sol";
import "../scripts/types.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ contract UNIT_TestStandardManager_Misc is TestStandardManagerBase {
assertEq(_getCashBalance(bobAcc), -int(btcSpot / 2));
}

function testCannotWithdrawBaseIfNegativeCash() public {
manager.setBorrowingEnabled(true);
cash.deposit(aliceAcc, uint(50000e18));

// can only borrow 50% of base asset's value
manager.setBaseAssetMarginFactor(btcMarketId, 0.5e18, 1e18);

// bob deposit 1 WBTC
wbtc.mint(address(this), 1e18);
wbtc.approve(address(wbtcAsset), 1e18);
wbtcAsset.deposit(bobAcc, uint(1e18));

vm.startPrank(bob);
// bob can borrow against this spot asset
cash.withdraw(bobAcc, uint(btcSpot / 2), bob);

assertEq(_getCashBalance(bobAcc), -int(btcSpot / 2));

vm.expectRevert(IStandardManager.SRM_PortfolioBelowMargin.selector);
wbtcAsset.withdraw(bobAcc, uint(1e18), bob);
}

function testCannotTradeMoreThanMaxAccountSize() public {
manager.setMaxAccountSize(10);

Expand Down

0 comments on commit 11592a9

Please sign in to comment.