Vault

This is main contract for managing all stakes, unstakes, deposits, withdraws, positions, and orders.

setVaultSettings

Owner Function

This is function to intialize contracts for combining relative contracts to Vault.
This is called only one time.
vault.setVaultSettings(
IPriceManager _priceManager,
ISettingsManager _settingsManager,
IPositionVault _positionVault
)
Example Input
('0x2c4478Dd91341Cb50521F2Af7174FB3C73A7DbEC', '0xce12b20F44E8fD27E4cd67eBc5c4F871400f84e7', '0x1dd07152b883c1d0A8490A35121A2e559dFE0702')
Example Output

deposit

This is a function to deposit USDC for getting vUSD.
Users can open and close positions with vUSD for getting profits via leverage.
So users need to deposit USDC at first time.
vault.deposit (
address _account,
address _token,
uint256 _amount
)
Example Input for depositing 100 USDC (USDC decimals is 6)
('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', '0x93F2394ceA60fa9E2E9AC215cd8ba04c30ed103b',
'100000000')
Example Output

withdraw

This is a function to withdraw USDC from vUSD. So after using this platform, if you want to withdraw your profits, then you can call this function.
vault.withdraw(
address _token,
address _account,
uint256 _amount
)
Example Input for withdawing 100 vUSD(vUSD decimals is 30)
('0x93F2394ceA60fa9E2E9AC215cd8ba04c30ed103b', '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
'10000000000000000000000000000000')
Example Output

stake

This is function to stake USDC for getting VLP.
By staking USDC, you will receive VLP.
Every time fees are generated, vlp price will be increased.
VLP holders will receive rewards from our platform fees.
vault.stake(
address _account,
address _token,
uint256 _amount
)
Example Input for staking 100 USDC(USDC decimals is 6)
('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', '0x93F2394ceA60fa9E2E9AC215cd8ba04c30ed103b', '100000000')
Example Output

unstake

This is a function to unstake VLP for getting rewards.
According to vlp amount and USDC amount(include platform fees), vlp price will be changed.
So, by unstaking VLP at higher price than staking price, user will get the reward.
There is cooldownduration for unstaking VLP.
So users need to wait for cooldownduration before unstaking.
vault.unstake(
address _tokenOut,
uint256 _vlpAmount,
address _receiver
)
Example Input for unstaking 100 VLP(VLP decimals is 18)
('0x93F2394ceA60fa9E2E9AC215cd8ba04c30ed103b', '100000000000000000000', '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
Example Output
// Some code

newPositionOrder

This is a function for opening new positions. You can open new position with market order, limit order, or stop-market order, stop-limit order.
vault.newPositionOrder(
address _indexToken,
bool _isLong,
OrderType _orderType,
uint256[] memory triggerPrices,
address _refer
)
(OrderType
Market Order -> 0,
Limit Order -> 1,
Stop-Market Order -> 2,
Stop-Limit Order -> 3
)
for all orders, triggerPrices[2] -> collateral, triggerPrices[3] -> position size amount
In Market Order's case, triggerPrices[0] -> mark price, triggerPrices[1] -> slippage percent,
In Limit Order's case, triggerPrices[0] -> limit price
In Stop-Market Order's case, triggerPrices[1] -> stop price,
In Stop-Limit Order's case, triggerPrices[0] -> limit price, triggerPrices[1] -> stop price
Example Input if you want to open BTC Long position for market order at 19,172(we allow slippage 1%, we use percentage basis points 100000, so it is 1000, means 100% * 1000/100000 = 1%), collateral 10, position size 100, so the leverage 10
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, 0, ['19172000000000000000000000000000000', '1000', '10000000000000000000000000000000', '100000000000000000000000000000000'], '0x000')
if you want to open BTC Short position for market order at 19,172(we allow slippage 1%, we use percentage basis points 100000, so it is 1000, means 100% * 1000/100000 = 1%), collateral 10, position size 100, so the leverage 10
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', false, 0, ['19172000000000000000000000000000000', '1000', '10000000000000000000000000000000', '100000000000000000000000000000000'], '0x000')
if you want to open BTC Long position for limit order at 19,372, collateral 10, position size 100, so the leverage 10
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, 1, ['19372000000000000000000000000000000', '0', '10000000000000000000000000000000', '100000000000000000000000000000000'], '0x000')
if you want to open BTC Long position for stop-market order at 19,202, collateral 10, position size 100, so the leverage 10
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, 2, ['0', '19202000000000000000000000000000000', '10000000000000000000000000000000', '100000000000000000000000000000000'], '0x000')
if you want to open BTC Long position for stop-limit order at limit 19,372, and stop price 19,202 collateral 10, position size 100, so the leverage 10
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, 3, ['19372000000000000000000000000000000', '19202000000000000000000000000000000', '10000000000000000000000000000000', '100000000000000000000000000000000'], '0x000')
Example Output

decreasePosition

This is function for decreasing or closing existing positions. there is close delay time for decreasing position. so users need to wait close delay time(default, it is 1 hour)
vault.decreasePosition(
address _indexToken,
uint256 _sizeDelta,
bool _isLong,
uint256 _posId
)
Example Input for decreasing position size 100
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', '10000000000000000000000000000000', true, '0')
Example Output

cancelPendingOrder

This is function for cancelling user's open pending orders
vault.cancelPendingOrder(
address _indexToken,
bool _isLong,
uint256 _posId
)
Example Input if your first position is for BTC Long Position with limit order, and it is still in pending, then you can cancel it.
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0')
Example Output

addOrRemoveCollateral

This is function for adding or removing user's collateral. so this will affect user's leverage.
vault.addOrRemoveCollateral(
address _indexToken,
bool _isLong,
uint256 _posId,
bool isPlus,
uint256 _amount
)
if you wanna add collateral, then you can set isPlus as true, for removing collateral, set isPlus as false
Example Input If you wanna add collateral 10, then
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0', true, '10000000000000000000000000000000')
If you wanna remove collateral 10, then
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0', false, '10000000000000000000000000000000')
Example Output

addPosition

This is a function for adding to your existing position. it keeps the same leverage, this will affect your profits for preventing front-runners, we are putting confirmDelay time. it will be added after the delay time.
vault.addPosition(
address _indexToken,
bool _isLong,
uint256 _posId,
uint256 _collateralDelta,
uint256 _sizeDelta
)
Example Input If you wanna add collateral 10, position size 100, then
('0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0', '10000000000000000000000000000000', '100000000000000000000000000000000')
Example Output

addTrailingStop

Users can add trailing stop to existing positions.
vault.addTrailingStop(
address _indexToken,
bool _isLong,
uint256 _posId,
uint256[] memory _params
)
_params[0] -> the collateral amount what you are going to add trailing stop for
_params[1] -> the position size what you are going to add trailing stop for
_params[2] -> trailing step type, so trailing step type = 0 means 'by price', type = 1 means 'by percent'
_params[3] -> step size
Example Input if you wanna add trailing stop by price change(so you want to take trail stop order when the last price exceeds 1$ change).
('0x70997970c51812dc3a010c7d01b50e0d17dc79c8', '0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0',
[
'10000000000000000000000000000000',
'100000000000000000000000000000000',
0,
'1000000000000000000000000000000'
])
if you wanna add trailing stop by percent change(so you want to take trail stop order when the last price exceeds 2% change)
('0x70997970c51812dc3a010c7d01b50e0d17dc79c8', '0xa36F5ea837A1925252eB5dc5A3605C9C3ba840ec', true, '0',
[
'10000000000000000000000000000000',
'100000000000000000000000000000000',
1,
'2000'
])
Example Output

transferBounty

Function
This is a function to transfer bounty to users who executed liquidatePosition. This function can be called only be Vault.
vaultUtils.transferBounty(
address _account,
uint256 _amount
)
Example Input
('0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
'1000000000000000000000000')
Example Output

getVLPPrice

This is a function for getting VLP Price it is based on BASIS_POINTS 100000. So if you get 124500, then it means vlp price is 124500/100000=1.245$
vault.getVLPPrice()
Example Input
Example Output
100000