Managing Borrow Positions
Moving assets between positions and opening/closing borrow positions is easy with the BorrowPositionRouter. You can find the address on the Smart Contract Addresses page.
Transferring Assets
library AccountBalanceLib {
/// Checks that either BOTH, FROM, or TO accounts do not have negative balances
enum BalanceCheckFlag {
Both,
From,
To,
None
}
}
interface IBorrowPositionRouter {
/**
* @param _isolationModeMarketId The market ID of the isolation mode token
* (0 if not using isolation mode)
* @param _fromAccountNumber The source account number
* @param _toAccountNumber The destination account number
* @param _marketId The ID of the market to transfer
* @param _amount The amount to transfer
* @param _balanceCheckFlag Flag indicating how to validate account balances
*/
function transferBetweenAccounts(
uint256 _isolationModeMarketId,
uint256 _fromAccountNumber,
uint256 _toAccountNumber,
uint256 _marketId,
uint256 _amount,
AccountBalanceLib.BalanceCheckFlag _balanceCheckFlag
) external;
}This function is used to transfer assets between accounts. For non-isolation mode assets, set the isolationModeMarketId to 0 and fill in the rest of the necessary information. For isolation-mode assets, isolationModeMarketId is the market ID of the vault and marketId is the market ID of the asset that will be transferred.
For isolation-mode transfers, we restrict transfers in the following ways:
The underlying isolation mode asset can only be transferred between the default account number and a non-default account number. For example, transferring from account number 0 to account number 123 is valid, but transferring from account number 123 to account number 150 would revert.
For all other assets within an isolation mode vault position, transfers can go from the owner to the vault or from the vault back to the owner. Transfers cannot be made within the vault. The direction of the transfer is determined by the
fromAccountNumberand thetoAccountNumber. If thefromAccountNumberis< 100and thetoAccoutNumberis>= 100, funds will go from the user's account to the isolation mode vault. If thefromAccountNumberis>= 100and thetoAccountNumberis< 100, funds will go from the isolation mode vault to the user's account.
Examples
Transferring 100 USDC from user's account number 0 to user's account number 123 while confirming that account number 0 does not go negative:
Transferring 100 GLP from the isolation mode vault default account to account number 123:
Transferring 100 USDC from the user's account number 0 to their isolation mode account number 123:
Transferring 100 USDC from isolation mode account number 123 to the user's account number 0 while confirming that account number 123 does not go negative:
Opening a Borrow Position
Examples
A user has 10 WETH in their default account (account number 0) and they want to open a borrow position with 1 WETH as collateral and then borrow 100 USDC against it.
A user has 10 GLP in their default isolation mode account and they want to open a borrow position with 1 GLP as collateral and borrow 100 USDC against it.
Closing a Borrow Position
Examples
Continuing from the example above where a user has 1 WETH collateral in account number 123 and borrowed 100 USDC. The user will now pay back the 100 USDC from account number 0 and close the borrow position.
Last updated
Was this helpful?