Git Product home page Git Product logo

basic-perpetuals's Introduction

Hello! My name is Gabriel! 👋

I'm a software engineer turning into a security researcher.

    Rust ・ Solidity ・ JavaScript ・ TypeScript
    Programming ・ Cybersecurity ・ Quality
    Sway ・ Emacs ・ Nix ・ Linux
    Portuguese ・ English
    PostgreSQL

TwitterE-mailDiscordLinkedIn

basic-perpetuals's People

Contributors

gabr1sr avatar

Watchers

 avatar

basic-perpetuals's Issues

Create Position function

Create Position

Is a function used to create a Position.

User must provide the following arguments:

  • collateral - the amount of collateral in uint256.
  • size - the amount of size in uint256.
  • long - if the Position is long (true) or short (false) in bool.

Requirements

Logic

  • Check if collateral is greater than 0.
  • Check if size is greater than 0.
  • 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 store entryPrice inside the Position.
  • Increase collateral to the total traders deposits.

Long Position-specific

  • Increase size to the open long interests in size and size price in assets to the open long interests.

Short Position-specific

  • Increase size to the open short interests in size and size price in assets to the open short interests.

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 Vault
  • Positions.sol - Position Manager
  • DataFeed.sol - Chainlink Data Feed Consumer

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 1 size token in collateral token (ex.: 1 BTC in USD).
  • long the Position is long (true) or short (false).

Functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.