MarginTrading.sol
This contract allows users to manage margin accounts, provide collateral, borrow, and repay tokens.
How to Interact with a Margin Account directly
How To Deposit Collateral (UDSC, WBTC, ETH)
function provideERC20(uint marginAccountID, address token, uint amount) external nonReentrant onlyApprovedOrOwner(marginAccountID) {
marginAccount.provideERC20(marginAccountID, msg.sender, token, amount);
emit ProvideERC20(marginAccountID, msg.sender, token, amount);
}How to Deposit American-style options (Hegic Option Position)
function provideERC721(uint marginAccountID, address token, uint collateralTokenID) external nonReentrant onlyApprovedOrOwner(marginAccountID) {
require(modularSwapRouter.checkValidityERC721(token, BASE_TOKEN, collateralTokenID), "token id is not valid");
marginAccount.provideERC721(marginAccountID, msg.sender, token, collateralTokenID);
emit ProvideERC721(marginAccountID, msg.sender, token, collateralTokenID);
}How To Withdraw Collateral (USDC, WBTC, ETH)
How to Withdraw American-style option (Hegic Option Position)
How to Borrow (USDC, WBTC, ETH)
How to Repay
How to swap tokens
How to exercise American-style option (Hegic Option Position)
How to get the current margin account value in USDC
How to get the current debt across all liquidity pools in USDC (borrowed amount + interest to be paid)
How to get the current margin ratio
Last updated