ExampleDerivatives

ExampleDerivatives

_ExampleDerivatives is used to increase and decrease positions.

The pluginIncreasePosition function will call the omniMint function from the router. The pluginIncreasePosition function will call the increasePosition function from the vault.

The pluginIncreasePosition function will deposit the tokens into the vault and mint the omniDepositTokens. And the pluginIncreasePosition function will mint the omniDepositTokens to the account. And increase the position size by the amount of tokens deposited.

The pluginDecreasePosition function will call the omniRedeem function from the router. The pluginDecreasePosition function will call the decreasePosition function from the vault.

The pluginDecreasePosition function will burn the omniDepositTokens from the account and redeem the omniDepositTokens from the vault. And the pluginDecreasePosition function will withdraw the tokens from the vault. And decrease the position size by the amount of tokens withdrawn.

router is the address of the OCP Router and is immutable.

remoteChainId is the chainId of the remote chain and is immutable.

depositToken is the address of the deposit token and is immutable.

vault is the address of the vault and is immutable. vault will be used to deposit and withdraw tokens. vault will be used to increase and decrease positions. vault will be used to get the position key and omniDepositToken will be deposited to the position key._

router

contract IOCPRouter router

remoteChainId

uint16 remoteChainId

depositToken

contract IERC20 depositToken

vault

contract Vault vault

constructor

constructor(address _router, uint16 _remoteChainId, address _depositToken, address _vault) public

_constructor is used to initialize the router, remote chain id, deposit token and vault.

The router is the address of the OCP Router.

The remote chain id is the chainId of the remote chain.

The deposit token is the address of the deposit token.

The vault is the address of the vault._

Parameters

NameTypeDescription

_router

address

The address of the OCP Router.

_remoteChainId

uint16

The chainId of the remote chain.

_depositToken

address

The address of the deposit token.

_vault

address

The address of the vault.

pluginIncreasePosition

function pluginIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, uint256 _amountIn, bool _isLong) external

_pluginIncreasePosition is used to increase positions.

The pluginIncreasePosition function will call the omniMint function from the router. Deposit the token into the vault and mint the omniDepositTokens. And the pluginIncreasePosition function will mint the omniDepositTokens to the account. And increase the position size by the amount of tokens deposited.

The pluginIncreasePosition function will call the increasePosition function from the vault. The increasePosition function will increase the position size by the amount of tokens deposited._

Parameters

NameTypeDescription

_account

address

The address of the account to increase the position for.

_collateralToken

address

The address of the collateral token to increase the position for.

_indexToken

address

The address of the index token to increase the position for.

_sizeDelta

uint256

The amount of tokens to increase the position size by.

_amountIn

uint256

The amount of tokens to deposit into the vault.

_isLong

bool

The direction of the position.

pluginDecreasePosition

function pluginDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, uint256 _amountIn, bool _isLong, address _receiver) external

_pluginDecreasePosition is used to decrease positions.

pluginDecreasePosition function will call the omniRedeem function from the router. Burn the omniDepositTokens from the account and redeem the omniDepositTokens from the vault. And the pluginDecreasePosition function will withdraw the tokens from the vault. And decrease the position size by the amount of tokens withdrawn.

The pluginDecreasePosition function will call the decreasePosition function from the vault. The decreasePosition function will decrease the position size by the amount of tokens withdrawn._

Parameters

NameTypeDescription

_account

address

The address of the account to decrease the position for.

_collateralToken

address

The address of the collateral token to decrease the position for.

_indexToken

address

The address of the index token to decrease the position for.

_collateralDelta

uint256

The amount of tokens to withdraw from the vault.

_sizeDelta

uint256

The amount of tokens to decrease the position size by.

_amountIn

uint256

The amount of tokens to burn from the account.

_isLong

bool

The direction of the position.

_receiver

address

The address to withdraw the tokens to.

Last updated