Skip to content
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