Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/srm #358

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading