MarginAccount
Inherits: BaseMargin
Implements a margin account, allowing users to borrow against collateral to take leveraged positions.
State Variables
collateral
BaseCollateral public collateral;
borrowedAmount
uint256 public borrowedAmount;
collateralFactor
uint256 public collateralFactor;
Functions
constructor
constructor(address _owner, address _collateral, uint256 _collateralFactor) BaseMargin(_owner);
openMargin
Opens a new margin account by depositing initial collateral.
function openMargin(uint256 initialCollateral) external override;
Parameters
initialCollateral
uint256
The amount of collateral to deposit initially.
closeMargin
Closes the margin account, ensuring all borrowed funds are repaid.
function closeMargin() external override;
addCollateral
Adds additional collateral to the margin account.
function addCollateral(uint256 amount) external override;
Parameters
amount
uint256
The amount of collateral to add.
removeCollateral
Removes collateral from the margin account, ensuring it doesn’t violate the collateral factor.
function removeCollateral(uint256 amount) external override;
Parameters
amount
uint256
The amount of collateral to remove.
openPosition
Opens a leveraged position by borrowing against collateral.
function openPosition(uint256 size) external override;
Parameters
size
uint256
The size of the position to open.
closePosition
Closes a leveraged position by repaying borrowed funds.
function closePosition(uint256 size) external override;
Parameters
size
uint256
The size of the position to close.
getCollateralBalance
Retrieves the current collateral balance.
function getCollateralBalance() public pure returns (uint256);
Returns
<none>
uint256
The collateral balance.
Last updated
Was this helpful?