basic-perpetuals's Introduction
basic-perpetuals's People
basic-perpetuals's Issues
Calculate Short PnL function
Increase Collateral function
Decrease Size function
Create Position function
Create Position
Is a function used to create a Position.
User must provide the following arguments:
collateral
- the amount of collateral inuint256
.size
- the amount of size inuint256
.long
- if the Position is long (true
) or short (false
) inbool
.
Requirements
Logic
- Check if
collateral
is greater than0
. - Check if
size
is greater than0
. - Check if user has enough
collateral
asset balance. - Check if the leverage is lower than the max leverage.
- Check if the liquidity pool has enough liquidity to cover profits
- Create a new Position with the provided
collateral
,size
,long
and storeentryPrice
inside the Position. - Increase
collateral
to the total traders deposits.
Long Position-specific
- Increase
size
to the open long interests in size andsize
price in assets to the open long interests.
Short Position-specific
- Increase
size
to the open short interests in size andsize
price in assets to the open short interests.
Size Price Calculation function
Liquidate Position internal function
Leverage Calculation function
Remove Liquidity function
Remove Liquidity
Function to liquidity providers be able to remove their liquidity when they want.
Split Contracts
Description
Split contracts into separated files:
Vault.sol
- ERC4626 VaultPositions.sol
- Position ManagerDataFeed.sol
- Chainlink Data Feed Consumer
Use only one Vault
Close Position function
Increase Size function
Add Liquidity function
Add Liquidity
Liquidity Providers can use this function to provide liquidity to the protocol.
Positions support
Positions
Positions are made up of the following:
- Size - how much “virtual” capital a trader is commanding, the size of a BTC perpetual position might be 1.5 BTC. If the price of BTC goes up, the trader is able to realize the profits earned on the 1.5 BTC in their position.
- Collateral - amount of assets used to “back” a trader’s position, when trader’s lose money, their losses come out of the collateral. If the amount of collateral is deemed insufficient for the size of a position, the position is liquidated or force closed.
Position struct
struct Position {
uint256 collateral;
uint256 size;
uint256 entryPrice;
bool long;
}
Where:
collateral
is the collateral used to back the trader's position.size
is the virtual capital a trader is commanding.entryPrice
the price of 1size
token incollateral
token (ex.: 1 BTC in USD).long
the Position is long (true
) or short (false
).
Functions
Decrease Collateral function
Calculate Long PnL function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.