Skip to content

A decentralized perpetual contract trading platform’s smart contract codebase

Notifications You must be signed in to change notification settings

hau823823/pairEx-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PairEx Contract

Introduction

Node Hardhat

PairEx Homepage

PairEx, available at pairex.io, is a preeminent decentralized perpetual exchange that leverages the Arbitrum Network to provide a seamless trading experience to its users. Its user-friendly platform is built on a transparent and secure trading infrastructure, enabling users to decentralize their trades and assets with confidence.

Note

This codebase focuses on the smart contracts and not include backend services or frontend interfaces.

Contract Address

Interact with contract

The main entry contract for frontend interfaces or users opening and closing interactions is PEXTradingV1, which includes functionalities such as market and limit order openings and closings, as well as take profit and stop loss adjustments.

openTrade

Market and limit order positions opening

Name Types Description Other
trader address opening address in same structure
pairIndex uint opening asset (BTC 0, ETH 1) in same structure
index uint fill with 0 in same structure
initialPosUSDT uint fill with 0 in same structure
positionSizeUsdt uint margin amount in same structure
openPrice uint Opening Price in same structure
buy bool long or short in same structure
leverage uint in same structure
tp uint take profit in same structure
sl uint stop loss all of the above are within the same structure
orderType uint market 0, limit 1
slippageP uint max acceptable slippage for market order opening
monthPassId uint default 0 holding can reduce transaction fees

closeTradeMarket

Positions closing

Name Types Description Other
pairIndex uint closing asset (BTC 0, ETH 1)
index uint existing positions index

updateTp

Update the take profit price

Name Types Description Other
pairIndex uint closing asset (BTC 0, ETH 1)
index uint existing positions index
newTp uint new price PRECISION 10

updateSl

Update the sell loss price

Name Types Description Other
pairIndex uint closing asset (BTC 0, ETH 1)
index uint existing positions index
newSl uint new price PRECISION 10

UML

Tip

This UML diagram primarily illustrates the contract interaction logic and cash flow logic

PairEx UML

Repository Structure

Main contracts are held within the contracts/v1_0 and contracts/v1_1 folder.
And the utilities including deploy script are held within the tools/deploy folder.

.
├── config
│   ├── config.yaml
│   └── getConfig.js
├── contracts
│   ├── PEXUSDT
│   ├── interfaces
│   ├── libraries
│   ├── oracle
│   ├── timelock
│   ├── v1_0
│   └── v1_1
├── test
│   ├── NFTV1_1
│   ├── PEXAdlClosingV1_1
│   ├── PEXReferralStorageV1_1
│   ├── PEXTradingV1
│   ├── PTokenv1
│   └── shared
├── tools
│   ├── deploy
│   └── traderBot
├── hardhat.config.js
├── package-lock.json
├── package.json
└── README.md

Deploy and Test

Note

Node version v16.17.0
Hardhat version v2.12.5

To deploy the contracts by yourself, you can clone this repo and follow the steps bellow.

npm install
cd ./tools/deploy
cp deployData/dev_config.yaml ../../config/config.yaml

Change the private key, dependency addresses, RPC, and API key in the config to your own deployment private key and the network environment you wish to deploy (example uses Arbitrum Sepolia).

npx hardhat compile
npx hardhat run deploy.js --network arbitrumSepolia

Or you can directly run the Hardhat framework tests and use the files under the test folder to familiarize yourself with and run the project

npx hardhat test

About

A decentralized perpetual contract trading platform’s smart contract codebase

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published