1.0.3 • Published 2 years ago

@predy/v2-contracts v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Predy v2 contracts

npm.io codecov

Overview

Predy V2 is AMM(Automated Market Maker) for Perpetual Contracts. It supports portfolio margin trading of Squared perpetual and Perpetual future. Portfolio Margin is a margin method that utilizes the unrealized profits of other positions in the relevant asset to avoid liquidations on the positions using the same settlement asset. As a result, Predy's margin requirements for perpetual positions are significantly reduced compared to traditional policy rules.

Contracts

PerpetualMarket.sol is entry point of traders and liquidity providers. It manages traders' vault storage and holds funds from traders and liquidity providers.

PerpetualMarketCore.sol is the contract to manage perpetual pool positions and calculate amount of collaterals. It inherits ERC20 Token representing liquidity provider token.

FlashHedge.sol is the contract helps to swap underlying assets and USDC tokens with Uniswap for delta hedging.

Libraries

lib/TraderVaultLib.sol has functions to calculate position value and minimum collateral for implementing margin wallet.

lib/NettingLib.sol has functions to calculate pool's required collateral.

lib/SpreadLib.sol has functions to manage spread. It is to protect AMM from short-term volatility.

lib/IndexPricer.sol has functions to calculate index price, delta and gamma of Squared perpetual and Perpetual future.

lib/EntryPriceMath.sol has functions to calculate new entry price and profit from previous entry price and trade price for implementing margin wallet.

lib/Math.sol has functions for basic mathematical calculation.

Reference

Docs

Audit

Development

Run typechain

npm run typechain

Run all tests

npm test

Check contract size

npx hardhat size-contracts

Deploy

To deploy contract on testnet or mainnet, you'll need to provide an infura key to connect to an infura node. Copy .env.example file as .env and specify your keys there.

npx hardhat run --network rinkebyArbitrum ./scripts/deploy.ts

Call Contracts

Gets vault status.

npx hardhat vault --network rinkebyArbitrum

Using foundry

forge install openzeppelin/openzeppelin-contracts@v3.4.2-solc-0.7
forge install uniswap/v3-core@1.0.0
forge install uniswap/v3-periphery
forge install smartcontractkit/chainlink
forge install foundry-rs/forge-std
forge build --hardhat

Testing

forge test

# specify test case
forge test --match-path test/foundry/PerpetualMarketCore.t.sol

# verbose mode
forge test -vvv --match-path test/foundry/PerpetualMarketCore.t.sol