Perpetual Protocol Curie (v2) core contracts

Overview

perp-curie-contract

@perp/curie-contract on npm @perp/curie-deployments on npm

This repository contains the core smart contracts for Perpetual Protocol Curie (v2).

Contract source code and metadata are also published as npm packages:

Get Started

Please check out:

Deployments

Perpetual Protocol Curie (v2) are deployed on Optimism mainnet (an Ethereum Layer 2 network).

Contract addresses:

You could also find the deployed contract addresses inside the npm package @perp/curie-deployments.

Local Development

You need Node.js 16+ to build. Use nvm to install it.

Clone this repository, install Node.js dependencies, and build the source code:

git clone [email protected]:perpetual-protocol/perp-curie-contract.git
npm i
npm run build

If the installation failed on your machine, please try a vanilla install instead:

npm run clean
rm -rf node_modules/
rm package-lock.json
npm install
npm run build

Run all the test cases:

npm run test

Changelog

See CHANGELOG.

Audit Reports

See audits.

Bug Bounty Program

This repository is subject to the Perpetual Protocol v2 bug bounty program, per the terms defined on ImmuneFi.

Grant Program

Projects, ideas and events that benefit Perpetual Protocol and its ecosystem are eligible for grants!

Related Projects

Comments
  • Test/fix failed test plan b

    Test/fix failed test plan b

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    opened by tienshaoku 1
  • Release/v2.3.0

    Release/v2.3.0

    version: 2.3.0

    • PR: #27

    • To see the specific tasks where the Asana app for GitHub is being used, see below:
      • https://app.asana.com/0/0/1203405735831446
      • https://app.asana.com/0/0/1203405735831447
    opened by 42bchen 1
  • Release/v2.2.4

    Release/v2.2.4

    version 2.2.4

    • PR: #25

    • To see the specific tasks where the Asana app for GitHub is being used, see below:
      • https://app.asana.com/0/0/1203407421302362
      • https://app.asana.com/0/0/1203407421302363
    opened by 42bchen 1
  • feat: rename markTwap to marketTwap and remove redundant import

    feat: rename markTwap to marketTwap and remove redundant import

    Because the price spread and funding rate will keep referring to market twap after applying mark price. To avoid variable name confusion, this PR is to rename markTwap to marketTwap.

    v2.5.0 
    opened by tailingchen 0
  • feat/apply-internal-audit-suggestions

    feat/apply-internal-audit-suggestions

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    v2.6.0 
    opened by tienshaoku 0
  • feat: cache index twap in settleFunding for mark price calculation

    feat: cache index twap in settleFunding for mark price calculation

    The ClearingHouseConfig.twapInterval will be set as 0 after applying new oracle , and we still need to cache index twap to calculate mark price.

    This PR is to cache index twap in settleFunding by using ClearingHouseConfig.markPricePremiumInterval instead of ClearingHouseConfig.twapInterval.

    opened by tailingchen 0
  • Feature/simplify mark price

    Feature/simplify mark price

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    opened by Wraecca 0
  • refactor/ClearingHouseConfig-cleanup

    refactor/ClearingHouseConfig-cleanup

    … IClearingHouseConfig.sol.

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    opened by tienshaoku 0
  • Hotfix/14204

    Hotfix/14204

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    opened by vinta 0
  • refactor ClearingHouseConfig

    refactor ClearingHouseConfig

    This PR is to refactor ClearingHouseConfig contract.

    1. Migrated ClearingHouseConfig tests to foundry.
    2. Removed deprecated BackstopLiquidityProvider config setting.
    3. Moved ClearingHouseConfig events from ClearingHouseConfig contract to IClearingHouseConfig contract.
    v2.5.0 
    opened by tienshaoku 0
  • Refactor/mark price config

    Refactor/mark price config

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    opened by tienshaoku 0
  • Release/v2.5.0

    Release/v2.5.0

    Release v2.5.0 includes the following features:

    • https://github.com/perpetual-protocol/perp-curie-contract/pull/30
    • https://github.com/perpetual-protocol/perp-curie-contract/pull/44
    opened by tailingchen 0
  • Feature/add new oracle

    Feature/add new oracle

    PR Reminders

    Be ware of the followings

    • [ ] implement deployment script for your changes in deployment repo
    • [ ] add verification in hardhat simulation(000-prepare-simulation-check, 902-newMarket-check or 903-simulation-check) and system test(901-system-test) in deployment repo
    • [ ] update change log

    1. Contract: make sure the code follows our convention, ex: naming, explicit returns, etc.; if uncertain, discuss with others

    2. Test: make sure tests can cover most normal and edge cases; if not, open follow-up tickets. Also, look out for failed tests and fix them!

    3. CHANGELOG.md: update when external interfaces are changed

    4. Workflow:

      • Github: assign the pr to yourself; if pairing, can merge directly; else, assign someone to help review
      • Asana: assign the corresponding ticket to yourself and leave the pr link on it for easier follow-ups
      • Discord: if someone is mentioned in this pr, tag on Discord
    v2.6.0 
    opened by tienshaoku 0
  • Feature: mark price

    Feature: mark price

    Background

    Currently, in PERP V2, we use the index TWAP as the basis for margin calculation and liquidations. The reason to use index TWAP is it’s hard to make price manipulation on index TWAP. On the other hands, it brings the risk to protocol. At most of time, index TWAP can not response the actual market status. Protocol will get high risk once the spread between index TWAP and market price is getting bigger. The problems are

    1. Trader accounts that should be liquidated are not liquidated due to the delayed reaction of index TWAP to current market conditions.
    2. When the index TWAP is too different from the market price, the liquidation capacity will decrease. Since PERP v2 uses index TWAP as the close price for liquidation, the liquidators have no incentives to take over the liquidated positions if the discount taking over price is not better than market price.

    To reduce potential risks mentioned above, we propose a new mark price calculation which will be used for margin calculation and liquidation.

    The Mark Price is the median of three prices as below.

    1. current market price
    2. market twap with 30 mins
    3. index price + premium with 15 mins

    This PR is to implement the mark price calculation and apply on the calculation of position value and liquidation.


    TODO:

    • [x] Update changelog

    • To see the specific tasks where the Asana app for GitHub is being used, see below:
      • https://app.asana.com/0/0/1203306706086173
    v2.5.0 
    opened by tailingchen 0
  • Access request to feeGrowthOutside specs notion page

    Access request to feeGrowthOutside specs notion page

    https://github.com/perpetual-protocol/perp-curie-contract/blob/f98ff086f4147680d579f68db7f3baedd6fc0063/contracts/lib/Tick.sol#L70-L79

    We're currently doing some uniswap v3/trident stuffs, accidentally we found some articles about the uniswap's underflow issue.

    According to this (https://github.com/Uniswap/v3-periphery/issues/164), I assume that this is why perpetual team does not use safemath on the fee growth calculation logic.

    However, I cannot understand that how the under/overflow situation occurs. To resolve this, I wanna get an access to that notion page.

    Thanks.

    opened by junomonster 0
Releases(v2.4.0)
  • v2.4.0(Dec 8, 2022)

    Changelog

    All notable changes to this project will be documented in this file.

    The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

    [unreleased]

    [2.4.0] - 2022-12-02

    Added

    • Add CollateralManager.getDebtThresholdByTrader()
    • Add CollateralManager.getTotalWhitelistedDebtThreshold()

    [2.3.0] - 2022-12-02

    Added

    • Add Insurance.distributeFee()
    • Add Insurance.getThreshold()
    • Add Insurance.getSurplusBeneficiary()
    • Add new event ThresholdChanged, SurplusBeneficiaryChanged, FeeDistributed to InsuranceFund

    [2.2.4] - 2022-12-02

    • Support remove all liquidity in quitMarket() if user has orders in closed market

    [2.2.3] - 2022-10-24

    Changed

    • Fix rounding issue (expect amount is not equal to response) when open position with isBaseToQuote: false and isExactInput: true

    [2.2.2] - 2022-10-13

    Changed

    • Change _MAX_PRICE_SPREAD_RATIO from 20% to 10%

    [2.2.1] - 2022-10-11

    • Add InsuranceFund.getInsuranceFundCapacity()

    [2.2.0] - 2022-09-30

    Added

    • Add Vault.settleBadDebt()
    • Add InsuranceFund.repay()
    • Add new event Repaid, BadDebtSettled

    Removed

    • Remove InsuranceFund.borrow()

    [2.1.1] - 2022-09-21

    Changed

    • AccountBalance.getLiquidatablePositionSize() returns entire position size if the position value is less than _MIN_PARTIAL_LIQUIDATE_POSITION_VALUE.

    [2.1.0] - 2022-08-16

    Added

    • Add Vault.withdrawAll() to withdraw all free collateral(specified) from vault
    • Add Vault.withdrawAllEther() to withdraw all ETH from vault

    Changed

    • Update return parameter names in NatSpec

    Fixed

    • Fix rounding issue when liquidating collaterals in full
    • Fix collateral value precision and underlying rounding issues

    [2.0.1] - 2022-08-10

    Added

    • Add DelegateApproval.canAddLiquidityFor to check if can add liquidity for another maker.
    • Add DelegateApproval.canRemoveLiquidityFor to check if can remove liquidity belonging to another maker.

    [2.0.0] - 2022-08-10

    Changed

    • liquidate() becomes position transfer instead of market selling. So liquidators now require collaterals to do liquidation.

      • liquidate() has new interfaces:

        function liquidate(
            address trader,
            address baseToken,
            int256 positionSize
        ) external;
        
        // liquidate as much as possible
        function liquidate(
            address trader,
            address baseToken,
        ) external;
        

    Added

    • Add AccountBalance.getLiquidatablePositionSize() to calculate the liquidatable position size for trader.

    Deprecated

    • function liquidate(address trader, address baseToken, uint256 oppositeAmountBound)

    [1.4.0] - 2022-07-05

    Added

    • Add DelegateApproval
      • Currently only allow delegating ClearingHouseOpenPosition
    • Add ClearingHouse.openPositionFor()
    • Add ClearingHouse.getDelegateApproval()

    [1.3.0] - 2022-06-20

    Added

    • Add BaseToken.cacheTwap to offer the flexibility of updating index prices by either users or ourselves.

    [1.2.0] - 2022-04-28

    Changed

    • ClearingHouse.getAccountValue() function now calls Vault.getAccountValue()
    • Vault.deposit(), Vault.withdraw(), Vault.depositFor() can be used for non-settlement token

    Added

    • Vault now supports depositing non-settlement token as collateral
    • Add CollateralManager contract for non-settlement collateral related params management
    • Add Vault.depositEther(), Vault.depositEtherFor() Vault.withdrawEther() for ETH deposit/withdraw
    • Add Vault.getAccountValue() to get the account value in settlement token's decimals
    • Add Vault.getBalanceByToken() to query collateral balance by token address
    • Add Vault.getCollateralTokens() to query all non-settlement collateral token addresses of a trader
    • Add Vault.getFreeCollateralByToken() to query free collateral by given collateral token addresses
    • Add Vault.getSettlementTokenValue() to query trader's settlement token value
    • Add Vault.isLiquidatable() to check if a trader's non-settlement collateral can be liquidated
    • Add Vault.getMarginRequirementForCollateralLiquidation() to get the margin requirement that a trader's non-settlement collateral is eligible to be liquidated
    • Add Vault.getCollateralMmRatio() to get the mmRatio for collateral liquidation
    • Add Vault.getLiquidatableCollateralBySettlement() to get the liquidatable collateral amount by given repaid settlement amount
    • Add Vault.getRepaidSettlementByCollateral to get the repaid settlement amount by given collateral amount for liquidation
    • Add Vault.getMaxRepaidSettlementAndLiquidatableCollateral() to query the max repaid settlement amount and max collateral amount for liquidation
    • Add Vault.liquidateCollateral to liquidate trader's non-settlement collateral

    [1.1.0] - 2022-04-12

    • Add BaseToken.pause() (only owner)
    • Add BaseToken.close(uint256) (only owner)
    • Add IBaseToken.close()
    • Add IBaseToken.getPausedTimestamp()
    • Add IBaseToken.getPausedIndexPrice()
    • Add IBaseToken.getClosedPrice()
    • Add IBaseToken.isOpen()
    • Add IBaseToken.isPaused()
    • Add IBaseToken.isClosed()
    • Add IVault.depositFor(address, address, uint256)
    • Add IClearingHouse.quitMarket(address, address)
    • Add new event PositionClosed to ClearingHouse, will emit in quitMarket(address, address)

    [1.0.15] - 2022-02-09

    Changed

    • emit PositionChanged event in cancelExcessOrders and cancelAllExcessOrders

    [1.0.14] - 2022-01-28

    Added

    • Add IClearingHouse.liquidate(address, address, uint) to liquidate with slippage protection.

    [1.0.13] - 2022-01-21

    Deploy

    • Deploy SOL market to optimism

    [1.0.12] - 2022-01-20

    Deploy

    • Deploy LUNA market to optimism

    [1.0.11] - 2022-01-18

    Deploy

    • Deploy AVAX market to optimism

    [1.0.10] - 2022-01-17

    Changed

    • Add _backstopLiquidityProviderMap in ClearingHouseConfigStorageV2. It's for only configured backstopLiquidityProvider can liquidate the trader's position who has bad debt.

    Deploy

    • Upgrade AccountBalance, ClearingHouse, ClearingHouseConfig, Exchange, Vault

    [1.0.9] - 2022-01-14

    Changed

    • Revert swap if _maxTickCrossedWithinBlockMap[baseToken] is 0

    Deploy

    • Upgrade Exchange on Optimism

    [1.0.9-staging] - 2022-01-13

    • Upgrade Exchange for zero tick crossing

    [1.0.8] - 2022-01-12

    Code is same as v1.0.8-staging.

    Deploy

    • Upgrade ClearingHouse on Optimism

    [1.0.8-staging] - 2022-01-11

    Fixed

    • revert when reducing position with bad debt

    Deploy

    • Upgrade ClearingHouse on Optimism Kovan

    [1.0.7] - 2022-01-06

    Deploy

    • Upgrade vBTC and vETH on Optimism

    [1.0.7-staging] - 2022-01-05

    Added

    • add BaseToken.setPriceFeed() to set address of price feed.

    Deploy

    • Upgrade vBTC and vETH on Optimism Kovan

    [1.0.6] - 2022-01-05

    • Only includes new deployments on Optimism Kovan compared with 1.0.5.

    [1.0.6-staging] - 2022-01-04

    • Clean deploy all contracts on Optimism Kovan except external contracts (DefaultProxyAdmin, USDC, UniswapV3Factory). Note that the contract proxy addresses has been changed. Can find all contract addresses in ./metadata/optimismKovan.json.

    [1.0.5] - 2022-01-03

    Added

    • Deploy AVAXUSDBandPriceFeed on Optimism.
    • Deploy LUNAUSDBandPriceFeed on Optimism.
    • Deploy SOLUSDBandPriceFeed on Optimism.

    [1.0.4] - 2021-12-23

    • Add fluctuation limit on exchange.swap

    [1.0.3] - 2021-12-10

    • Fix permission check in setttleFunding and updateFundingGrowthAndLiquidityCoefficientInFundingPayment

    [1.0.3-staging] - 2021-12-10

    • Fix permission check in setttleFunding and updateFundingGrowthAndLiquidityCoefficientInFundingPayment

    [1.0.1] - 2021-11-25

    • Code is the same as 1.0.0, but it's a clean deploy to Optimism Mainnet.
    • Contract source code is also included.

    [1.0.0] - 2021-11-24

    • Code is the same as 1.0.0-staging, but it's a clean deploy to Optimism Mainnet.

    [1.0.0-staging] - 2021-11-24

    • Code is the same as 0.15.1-staging, but it's a clean deploy to Optimism Kovan and Arbitrum Rinkeby.

    [0.15.1-staging] - 2021-11-23

    • No public change in this version.

    [0.15.0-staging] - 2021-11-22

    Changed

    • rename ClearingHouse.settleAllFundingAndPendingFee to ClearingHouse.settleAllFunding

    • rename AccountBalance.addTakerBalances to AccountBalance.modifyTakerBalance

    • rename params of AccountBalance.modifyTakerBalance

      1. deltaTakerBase to base
      2. deltaTakerQuote to quote
    • rename params of AccountBalance.settleBalanceAndDeregister

      1. deltaTakerBase to takerBase
      2. deltaTakerQuote to takerQuote
    • rename AccountBalance.addOwedRealizedPnl to AccountBalance.modifyOwedRealizedPnl

    • rename param delta of AccountBalance.modifyOwedRealizedPnl as amount

    • rename the param sqrtPriceAfter in the ClearingHouse.PositionChanged event to sqrtPriceAfterX96

    • rename error codes in ClearingHouse

      1. CH_NEO to CH_CLWTISO
      2. CH_PSC to CH_PSCF
      3. CH_ANC to CH_ENC
      4. CH_ANC to CH_TFNC
    • rename params of ClearingHouse.openPosition

      1. deltaBase to base
      2. deltaQuote to quote
    • rename params of ClearingHouse.closePosition

      1. deltaBase to base
      2. deltaQuote to quote
    • rename error code in Exchange: EX_ANC to EX_BNC

    • rename params in struct Exchange.SwapResponse

      1. deltaAvailableBase to base
      2. deltaAvailableQuote to quote
    • rename params in struct Exchange.RealizePnlParams

      1. deltaAvailableBase to base
      2. deltaAvailableQuote to quote
    • rename OrderBook.getOwedFee as OrderBook.getPendingFee

    • rename params in struct OrderBook.RemoveLiquidityResponse

      1. deltaTakerBase to takerBase
      2. deltaTakerQuote to takerQuote
    • rename params of OrderBook.updateOrderDebt

      1. deltaBaseDebt to base
      2. deltaQuoteDebt to quote
    • rename params in struct AccountMarket.Info

      1. takerBaseBalance to takerPositionSize
      2. takerQuoteBalance to takerOpenNotional
    • rename error codes in Vault

      1. V_ANC to V_CHNC
      2. V_ANC to V_TFNC
    • move event FundingPaymentSettled to ClearingHouse

    Added

    • add a new parameter insuranceFundArg to initialize of ClearingHouse
    • add a new parameter orderBookArg to initialize of AccountBalance

    Removed

    • remove AccountBalance.getNetQuoteBalanceAndPendingFee
    • remove parameter exchangeArg from initialize of AccountBalance
    • remove parameter insuranceFundArg from initialize of Exchange
    • remove Exchange.getTick
    • remove Exchange.getFundingGrowthGlobalAndTwaps
    • remove OrderBook.getFeeGrowthGlobal

    [0.14.0-staging] - 2021-11-17

    Added

    • add OrderBook.getTotalQuoteBalance()
    • add OrderBook.getTotalOrderDebt()
    • add OrderBook.getMakerBalance()
    • add Clearinghouse.settleAllFundingAndPendingFee()

    Changed

    • move PositionChanged event from Exchange to ClearingHouse

    • move Exchange.getTotalOpenNotional to AccountBalance.getTotalOpenNotional

    • move Exchange.getTakerOpenNotional to AccountBalance.getTakerOpenNotional

    • rename OrderBook.getTotalTokenAmountInPool to OrderBook.getTotalTokenAmountInPoolAndPendingFee

    • rename AccountBalance.getOwedAndUnrealizedPnl to AccountBalance.getPnlAndPendingFee

    • rename AccountBalance.getNetQuoteBalance to AccountBalance.getNetQuoteBalanceAndPendingFee

    • rename AccountBalance.settleQuoteToPnl to AccountBalance.settleQuoteToOwedRealizedPnl

    • add new second return value pendingFee of AccountBalance.getOwedAndUnrealizedPnl

    • add new second return value pendingFee of AccountBalance.getNetQuoteBalance

    • add new second return value totalPendingFee of OrderBook.getTotalQuoteBalance

    • add new second return value totalPendingFee of OrderBook.getTotalTokenAmountInPool

    Removed

    • remove AccountBalance.getTakerQuote

    [0.13.3-staging] - 2021-11-11

    Changed

    • rename useTakerPosition to useTakerBalance in ClearingHouse.AddLiquidityParams

    [0.13.2-staging] - 2021-11-11

    Changed

    • update artifacts

    [0.13.1-staging] - 2021-11-11

    Added

    • add optimismKovan.json and rinkeby.json of v0.12.7

    [0.13.0-staging] - 2021-11-10

    Changed

    • use the new NPM package name: @perp/curie-contract
    • rename AccountBalance.getLiquidateMarginRequirement to AccountBalance.getMarginRequirementForLiquidation
    • rename Vault.balanceOf to Vault.getBalance
    • rename AccountBalance.getPositionSize to AccountBalance.getTotalPositionSize
    • rename AccountBalance.getPositionValue to AccountBalance.getTotalPositionValue
    • rename Exchange.getOpenNotional to Exchange.getTotalOpenNotional
    • fix error codes in Exchange
      1. EX_OPIBS to EX_OPLBS
      2. EX_OPIAS to EX_OPLAS
    • add field useTakerPosition to ClearingHouse.AddLiquidityParams
    • move event LiquidityChanged from OrderBook to ClearingHouse

    Added

    • add AccountBalance.getTakerQuote() to get taker's quote balance
    • add Exchange.getTakerOpenNotional() to get taker's open notional
    • add ClearingHouseConfig.getMaxFundingRate() and ClearingHouseConfig.setMaxFundingRate()
    • add MarketRegistry.hasPool()
    • add event MaxFundingRateChanged to ClearingHouseConfig
    • add event TrustedForwarderChanged to ClearingHouse
    • add event TakerBalancesChanged to AccountBalance
    • add event MaxTickCrossedWithinBlockChanged to Exchange
    • add event AccountBalanceChanged to Exchange
    • add event BorrowerChanged to InsuranceFund

    Removed

    • remove state _versionRecipient from ClearingHouse and Vault
    • remove Quoter and Multicall2 contracts from core.

    [0.12.7] - 2021-11-09

    • deploy on Optimism Kovan

    [0.12.6] - 2021-10-25

    • bug fixes
      • rounding error at ClearingHouse.closePosition() and Vault.withdraw()

    [0.12.5] - 2021-10-22

    • deploy 0.12.4 on Rinkeby

    [0.12.4] - 2021-10-21

    Changed

    • changed the returned value of ClearingHouse.getAccountValue to 18 decimals

    [0.11.1] - 2021-10-08

    Added

    • add AccountBalance.getTotalAbsPositionValue()

    [0.11.0] - 2021-10-08

    Added

    • add ClearingHouseConfig.getSettlementTokenBalanceCap()
    • add a new parameter insuranceFundArg to initialize of Exchange
    • add a new event SettlementTokenBalanceCapChanged to ClearingHouseConfig
    • add a new field sqrtPriceAfter to PositionChanged of Exchange

    Removed

    • remove parameter insuranceFundArg from initialize of ClearingHouse
    • remove event PositionChanged from ClearingHouse
    • remove getTotalAbsPositionValue from AccountBalance
    • remove parameter marketRegistryArg from initialize of AccountBalance

    Changed

    • move event PositionChanged to Exchange
    • combine getTotalUnrealizedPnl and getOwedRealizedPnl to getOwedAndUnrealizedPnl
    • move getLiquidateMarginRequirement from Vault to AccountBalance
    • rename CleairngHouseConfig.liquidationPenaltyRatio to ClearingHouseConfig.getLiquidationPenaltyRatio
    • rename CleairngHouseConfig.partialCloseRatio to ClearingHouseConfig.getPartialCloseRatio
    • rename CleairngHouseConfig.twapInterval to ClearingHouseConfig.getTwapInterval
    • rename CleairngHouseConfig.maxMarketsPerAccount to ClearingHouseConfig.getMaxMarketsPerAccount
    • rename MarketRegistry.clearingHouse to MarketRegistry.getClearingHouse
    • rename MarketRegistry.maxOrdersPerMarket to MarketRegistry.getMaxOrdersPerMarket
    • rename Vault.totalDebt to Vault.getTotalDebt

    [0.9.4] - 2021-09-28

    Changed

    • Error messages emitted by ClearingHouse._checkSlippage()
      • CH_TLR to CH_TLRS or CH_TLRL, depending on the side
      • CH_TMR to CH_TMRS or CH_TMRL, depending on the side

    [0.9.3] - 2021-09-27

    • bug fixing

    [0.9.2] - 2021-09-24

    Added

    • add AccountBalance.getBaseTokens()
    • add a new parameter sqrtPriceX96 to SwapResponse of Quoter.swap()

    [0.9.0] - 2021-09-22

    Added

    • add ClearingHouseConfig contract
    • add OrderBook contract
    • add AccountBalance contract
    • add MarketRegistry contract

    Removed

    • remove getOwedRealizedPnlWithPendingFundingPayment from AccountBalance
    • remove getLastUpdatedTick from Exchange

    Changed

    • TwapIntervalChanged now emitted by ClearingHouseConfig
    • LiquidationPenaltyRatioChanged now emitted by ClearingHouseConfig
    • PartialCloseRatioChanged now emitted by ClearingHouseConfig
    • ReferredPositionChanged now emitted by ClearingHouseConfig
    • MaxMarketsPerAccountChanged now emitted by ClearingHouseConfig
    • The following function move from ClearingHouse to AccountBalance
      • getOwedRealizedPnl
      • getTotalAbsPositionValue
      • getTotalDebtValue
      • getTotalUnrealizedPnl
      • getNetQuoteBalance
      • getPositionSize
      • getPositionValue
    • getOpenNotional moved to Exchange
    • setMaxTickCrossedWithinBlock and getMaxTickCrossedWithinBlock moved to Exchange
    • getPendingFundingPayment and getAllPendingFundingPayment moved to Exchange

    [0.5.3] - 2021-09-03

    Removed

    • remove twapIntervalArg from ClearinHouse.getPositionValue()

    [0.5.2] - 2021-09-02

    Added

    • add Exchange contract
    • add BaseToken contract
    • add MetaTxGateway contract

    Changed

    • Set ClearingHouse.setMaxMarketsPerAccount(10)
    • Set Exchange.setMaxOrdersPerMarket(100)
    • Set Exchange.setFeeRatio(baseToken, 1000) (0.1%) for all BaseTokens
    • Set Exchange.setInsuranceFundFeeRatio(baseToken, 100000) (10%) for all BaseTokens
    • PoolAdded now emitted by Exchange
    • LiquidityChanged now emitted by Exchange
    • Swapped is renamed to PositionChanged and still emitted by ClearingHouse
      • event parameters also changed
    event PositionChanged(
        address indexed trader,
        address indexed baseToken,
        int256 exchangedPositionSize,
        int256 exchangedPositionNotional,
        uint256 fee,
        int256 openNotional,
        int256 realizedPnl
    );
    
    • GlobalFundingGrowthUpdated is renamed to FundingUpdated and still emitted by ClearingHouse
      • event parameters also changed
    event FundingUpdated(
        address indexed baseToken,
        uint256 markTwap,
        uint256 indexTwap
    );
    
    • FundingSettled is renamed to FundingPaymentSettled and still emitted by ClearingHouse
    • QuoteToken inherits from VirtualToken contract
    • All BaseTokens inherit from BaseToken contract

    [0.4.2] - 2021-08-24

    Added

    • add ClearingHouse.getTotalInitialMarginRequirement()

    [0.4.0] - 2021-08-23

    Added

    • add new global arguments to ClearingHouse:
      • ClearingHouse.setMaxOrdersPerMarket()
      • ClearingHouse.setMaxMarketsPerAccount()
      • ClearingHouse.setPartialCloseRatio()
      • ClearingHouse.setLiquidationPenaltyRatio()
      • ClearingHouse.setTwapInterval()
    • add new market-specific arguments to ClearingHouse:
      • ClearingHouse.setFeeRatio()
      • ClearingHouse.setInsuranceFundFeeRatio()
      • ClearingHouse.setMaxTickCrossedWithinBlock()

    Changed

    • replace hourly-based funding with block-based funding
    • replace cancelExcessOrders(maker, baseToken) with cancelAllExcessOrders(maker, baseToken) and cancelExcessOrders(maker, baseToken, orderIds)
      • now cancelAllExcessOrders() will not automatically remove all liquidity

    Removed

    • remove ClearingHouse.updateFunding()
    • remove fundingPayment and badDebt from Swapped event

    [0.3.3] - 2021-08-13

    Fixed

    • fix how realizedPnl and openNotional calculate for maker/taker

    Added

    • add whitelist feature for VirtualToken
    • add Quoter contract

    [0.2.0] - 2021-08-04

    Changed

    • rename ClearingHouse.getTotalMarketPnl to ClearingHouse.getTotalUnrealizedPnl
    • fix Vault.getFreeCollateral wrong numbers

    [0.1.5] - 2021-08-03

    Added

    • add InsuranceFund contract
    • add ClearingHouse.getBuyingPower()
    • add ClearingHouse.liquidate()

    Changed

    • change the interface of ClearingHouse.addLiquidity() and ClearingHouse.removeLiquidity()
      • support slippage protection

    Fixed

    • fix ClearingHouse.swap()
      • fix TransferHelper::SafeTransfer: Transfer Failed when opening a short position
    • fix ClearingHouse.getAccountValue()

    [0.1.4] - 2021-07-29

    Changed

    • re-deployed all contracts

    [0.1.3] - 2021-07-28

    Changed

    • implemented quote-only fee
    • changed event parameters of FundingRateUpdated, FundingSettled, and Swapped:
    event FundingRateUpdated(address indexed baseToken, int256 rate, uint256 underlyingPrice);
    
    event FundingSettled(
        address indexed trader,
        address indexed baseToken,
        uint256 nextPremiumFractionIndex,
        int256 amount
    );
    
    event Swapped(
        address indexed trader,
        address indexed baseToken,
        int256 exchangedPositionSize,
        int256 exchangedPositionNotional,
        uint256 fee,
        int256 settledFundingPayment,
        uint256 badDebt
    );
    

    [0.1.1] - 2021-07-26

    Fixed

    • fix Vault is missing from @perp/curie-contract/artifacts/contracts

    [0.1.0] - 2021-07-23

    Added

    • add Vault contract

    Changed

    • move ClearingHouse.deposit to Vault.deposit
    • move ClearingHouse.withdraw to Vault.withdraw
    • move ClearingHouse.getFreeCollateral to Vault.getFreeCollateral
    Source code(tar.gz)
    Source code(zip)
Owner
Perpetual Protocol
Decentralized perpetual contract for every assets
Perpetual Protocol
Elrond blockchain CLI helper tools - interaction with APIs, smart contracts and protocol

Buildo Begins ?? Meet Buildo. He is here to help you start creating in the Elrond blockchain ecosystem. Here is where everything begins. I'm going on

Elrond's Dev Guild 22 Dec 30, 2022
🌳📝 Smart contracts for the Arbor Protocol

Arbor Smart Contracts app testnet landing docs discord blog twitter Security Please report any security issues to [email protected] V1 Smart Contr

Always Be Growing 15 Nov 21, 2022
Gym Project to Learn ASP.NET Core

OneFitnessVue Gym Project to Learn ASP.NET Core. Read the Documentation » ⚡️ This is Sample Project Which Does not Contain All Features. ?? Buy Comple

Saineshwar Bageri 31 Jan 3, 2023
io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

Konstantin Knyazev 3 May 23, 2022
Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Khalid Abuhakmeh 5 Feb 16, 2022
Create a C# .NET core EntityFramework ORM from your schema.prisma file

A note of forewarning to the would-be user... This was a failure. I'm making a note here: huge regret. It's hard to overstate my dissatisfaction. ?? S

Ian Ray 9 Dec 24, 2022
A port of bitcoin-core that will (over time) become TS friendly.

bitcoin-core A modern Bitcoin Core REST and RPC client to execute administrative tasks, multiwallet operations and queries about network and the block

null 6 Nov 22, 2022
Template Repository for making your own budder Module. CORE is not included, this is just for the module.

A quick copy of the "How to make your own module" section Check out the official budderAPI repository Template Repository for making your own budder M

Logic 2 Apr 3, 2022
SUID is all a set of utils and components ported from MUI Core and much more.

Solid.js User Interface Design (SUID) A port of Material-UI (MUI) built with Solid.js SUID is all a set of utils and components ported from MUI Core a

null 311 Jan 1, 2023
Smart Territory Framework Core using NEC Scorpio 2.0 and AWS serverless services

Smart Territory Framework Core - STF Core using NEC Scorpio Broker ⚠️ This stack is for demonstration purposes only. The nested stack deploying the NE

AWS Samples 9 Sep 30, 2022
The Termpura loader core package.

This project is a Work in Progress and currently in development. The API is subject to change without warning. Install npm install @termpura/core Usag

Termpura 2 Oct 15, 2022
The Easel Javascript library provides a full, hierarchical display list, a core interaction model, and helper classes to make working with the HTML5 Canvas element much easier.

EaselJS EaselJS is a library for building high-performance interactive 2D content in HTML5. It provides a feature-rich display list to allow you to ma

CreateJS 8k Dec 29, 2022
MUI Core is a collection of React UI libraries for shipping new features faster. Start with Material UI, our fully-loaded component library, or bring your own design system to our production-ready components.

MUI Core MUI Core contains foundational React UI component libraries for shipping new features faster. Material UI is a comprehensive library of compo

MUI 83.6k Dec 30, 2022
this project show how to deal with core programming scriptprogramming and local storage

this project show how to deal with core programming scriptprogramming and local storage

Sameh Tantawy 5 Jul 25, 2022
The smallest CMS engine ever, made with ASP. NET Core and Dapper

TinyCMS The smallest CMS engine ever, made with ASP.NET Core and Dapper. Currently, only static content is supported, but adding new pages is as simpl

Marco Minerva 12 Dec 29, 2022
Shield is a development framework for circom developers. The core reason is to provide libraries, plugins, and testing tools to ensure code quality and security.

SHIELD Shield is a development framework for circom developers but we plan it to other languages such as CAIRO, SNARKYJS etc. The core reason is to pr

Xord 41 Dec 22, 2022
ASP.NET core, PostgreSQL

Technologies CityApp is built using the following technologies: Visual Studio 2017 ASP.NET Core (Targeting .net 4.61) SQL Server 2014/Azure SQL for da

Dredsoft 3 Sep 15, 2022
Buildable's core open-source offering for actions that makes it easy to collect, centralize and action your backend system activity

What are Action Templates? Action Templates are open-source functions that save developers hundreds of hours when integrating databases, apps and othe

Buildable 6 Nov 5, 2022
✅ The core functionality of JetVil

@jetvil/core The core functionality based on primitive validation and utility tools for ES6+ and Typescript projects ✅ . Includes parts of @jetvil/typ

JetVil 4 Oct 19, 2022