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.
- Add tick checking when swap
- MarketRegistry allow feeManager to set feeDiscountRatio
- Change MarkPrice's marketPrice to 15-second market TWAP.
- Apply the
sqrtPriceLimitX96
config when closing a position.
- Remove admin function,
ClearingHouseConfig.setPartialCloseRatio
- Add
MarketRegistry.setFeeDiscountRatio()
to set a fee discount ratio to a trader. - Add
MarketRegistry.getMarketInfoByTrader()
to get a market info related to a trader. - Refine
Orderbook.replaySwap
to retrieve market info from arguments.
- Remove legacy code for mark price sanity check.
- Switch
IPriceFeedV2
toIPriceFeedDispatcher
inBaseToken
. - Update
ClearingHouseConfig.setTwapInterval()
to support 0 interval.
- Add
AccountBalance.getMarkPrice()
to return the mark price of given market. - Add
ClearingHouseConfig.getMarkPriceConfig()
to return marketTwapInterval and premiumInterval used for mark price calculations. - Add
Exchange.getSqrtMarketTwapX96()
to return market twap.
- Move events in ClearingHouseConfig to IClearingHouseConfigEvent in IClearingHouseConfig.sol
- BackstopLiquidityProvider from ClearingHouseConfig & IClearingHouseConfig and comments added to ClearingHouseConfigStorage
Exchange.getSqrtMarkTwapX96(address baseToken, uint32 twapInterval)
will be deprecated at later releases. Suggest to useExchange.getSqrtMarketTwapX96()
instead.
- Added a new field, maxPriceSpreadRatio, to the
IMarketRegistry.MarketInfo
struct. TheMarketRegistry.getMarketInfo
function will now return the maxPriceSpreadRatio value for a market.
- Ensure that the market price should be within a price band (defaulting to the index price +/- 10%, but adaptable to market conditions) before performing any swaps, including opening, reducing, or closing positions.
- Fix margin requirement check for reducing positions when leverage exceeds 10x.
- Update the price limit check on last tick of markets per 15 (Exchange._PRICE_LIMIT_INTERVAL) seconds.
- Ensure the trader's free collateral is enough for minimum maintenance requirement after closing a position.
- Transaction will fail if closing 25% of trader's position exceeds the max price impact per timestamp.
- Add
CollateralManager.getDebtThresholdByTrader()
- Add
CollateralManager.getTotalWhitelistedDebtThreshold()
- Add
InsuranceFund.distributeFee()
- Add
InsuranceFund.getDistributionThreshold()
- Add
InsuranceFund.getSurplusBeneficiary()
- Add new event
ThresholdChanged
,SurplusBeneficiaryChanged
,FeeDistributed
toInsuranceFund
- Support remove all liquidity in
quitMarket()
if user has orders in closed market
- Fix rounding issue (expect amount is not equal to response) when open position with
isBaseToQuote: false
andisExactInput: true
- Change
_MAX_PRICE_SPREAD_RATIO
from 20% to 10%
- Add
InsuranceFund.getInsuranceFundCapacity()
- Add
Vault.settleBadDebt()
- Add
InsuranceFund.repay()
- Add new event
Repaid
,BadDebtSettled
- Remove
InsuranceFund.borrow()
AccountBalance.getLiquidatablePositionSize()
returns entire position size if the position value is less than _MIN_PARTIAL_LIQUIDATE_POSITION_VALUE.
- Add
Vault.withdrawAll()
to withdraw all free collateral(specified) from vault - Add
Vault.withdrawAllEther()
to withdraw all ETH from vault
- Update return parameter names in NatSpec
- Fix rounding issue when liquidating collaterals in full
- Fix collateral value precision and underlying rounding issues
- 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.
-
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;
-
- Add
AccountBalance.getLiquidatablePositionSize()
to calculate the liquidatable position size for trader.
function liquidate(address trader, address baseToken, uint256 oppositeAmountBound)
- Add
DelegateApproval
- Currently only allow delegating
ClearingHouseOpenPosition
- Currently only allow delegating
- Add
ClearingHouse.openPositionFor()
- Add
ClearingHouse.getDelegateApproval()
- Add
BaseToken.cacheTwap
to offer the flexibility of updating index prices by either users or ourselves.
ClearingHouse.getAccountValue()
function now callsVault.getAccountValue()
Vault.deposit()
,Vault.withdraw()
,Vault.depositFor()
can be used for non-settlement token
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
- 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
toClearingHouse
, will emit inquitMarket(address, address)
- emit
PositionChanged
event incancelExcessOrders
andcancelAllExcessOrders
- Add
IClearingHouse.liquidate(address, address, uint)
to liquidate with slippage protection.
- Deploy
SOL
market to optimism
- Deploy
LUNA
market to optimism
- Deploy
AVAX
market to optimism
- Add _backstopLiquidityProviderMap in ClearingHouseConfigStorageV2. It's for only configured backstopLiquidityProvider can liquidate the trader's position who has bad debt.
- Upgrade AccountBalance, ClearingHouse, ClearingHouseConfig, Exchange, Vault
- Revert swap if _maxTickCrossedWithinBlockMap[baseToken] is 0
- Upgrade Exchange on Optimism
- Upgrade Exchange for zero tick crossing
Code is same as v1.0.8-staging
.
- Upgrade ClearingHouse on Optimism
- revert when reducing position with bad debt
- Upgrade ClearingHouse on Optimism Kovan
- Upgrade vBTC and vETH on Optimism
- add
BaseToken.setPriceFeed()
to set address of price feed.
- Upgrade vBTC and vETH on Optimism Kovan
- Only includes new deployments on Optimism Kovan compared with
1.0.5
.
- 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
.
- Deploy
AVAXUSDBandPriceFeed
on Optimism. - Deploy
LUNAUSDBandPriceFeed
on Optimism. - Deploy
SOLUSDBandPriceFeed
on Optimism.
- Add fluctuation limit on
exchange.swap
- Fix permission check in
setttleFunding
andupdateFundingGrowthAndLiquidityCoefficientInFundingPayment
- Fix permission check in
setttleFunding
andupdateFundingGrowthAndLiquidityCoefficientInFundingPayment
- Code is the same as
1.0.0
, but it's a clean deploy to Optimism Mainnet. - Contract source code is also included.
- Code is the same as
1.0.0-staging
, but it's a clean deploy to Optimism Mainnet.
- Code is the same as
0.15.1-staging
, but it's a clean deploy to Optimism Kovan and Arbitrum Rinkeby.
- No public change in this version.
-
rename
ClearingHouse.settleAllFundingAndPendingFee
toClearingHouse.settleAllFunding
-
rename
AccountBalance.addTakerBalances
toAccountBalance.modifyTakerBalance
-
rename params of
AccountBalance.modifyTakerBalance
deltaTakerBase
tobase
deltaTakerQuote
toquote
-
rename params of
AccountBalance.settleBalanceAndDeregister
deltaTakerBase
totakerBase
deltaTakerQuote
totakerQuote
-
rename
AccountBalance.addOwedRealizedPnl
toAccountBalance.modifyOwedRealizedPnl
-
rename param
delta
ofAccountBalance.modifyOwedRealizedPnl
asamount
-
rename the param
sqrtPriceAfter
in theClearingHouse.PositionChanged
event tosqrtPriceAfterX96
-
rename error codes in
ClearingHouse
CH_NEO
toCH_CLWTISO
CH_PSC
toCH_PSCF
CH_ANC
toCH_ENC
CH_ANC
toCH_TFNC
-
rename params of
ClearingHouse.openPosition
deltaBase
tobase
deltaQuote
toquote
-
rename params of
ClearingHouse.closePosition
deltaBase
tobase
deltaQuote
toquote
-
rename error code in
Exchange
:EX_ANC
toEX_BNC
-
rename params in struct
Exchange.SwapResponse
deltaAvailableBase
tobase
deltaAvailableQuote
toquote
-
rename params in struct
Exchange.RealizePnlParams
deltaAvailableBase
tobase
deltaAvailableQuote
toquote
-
rename
OrderBook.getOwedFee
asOrderBook.getPendingFee
-
rename params in struct
OrderBook.RemoveLiquidityResponse
deltaTakerBase
totakerBase
deltaTakerQuote
totakerQuote
-
rename params of
OrderBook.updateOrderDebt
deltaBaseDebt
tobase
deltaQuoteDebt
toquote
-
rename params in struct
AccountMarket.Info
takerBaseBalance
totakerPositionSize
takerQuoteBalance
totakerOpenNotional
-
rename error codes in
Vault
V_ANC
toV_CHNC
V_ANC
toV_TFNC
-
move event
FundingPaymentSettled
to ClearingHouse
- add a new parameter
insuranceFundArg
toinitialize
of ClearingHouse - add a new parameter
orderBookArg
toinitialize
of AccountBalance
- remove
AccountBalance.getNetQuoteBalanceAndPendingFee
- remove parameter
exchangeArg
frominitialize
of AccountBalance - remove parameter
insuranceFundArg
frominitialize
of Exchange - remove
Exchange.getTick
- remove
Exchange.getFundingGrowthGlobalAndTwaps
- remove
OrderBook.getFeeGrowthGlobal
- add
OrderBook.getTotalQuoteBalance()
- add
OrderBook.getTotalOrderDebt()
- add
OrderBook.getMakerBalance()
- add
Clearinghouse.settleAllFundingAndPendingFee()
-
move
PositionChanged
event fromExchange
toClearingHouse
-
move
Exchange.getTotalOpenNotional
toAccountBalance.getTotalOpenNotional
-
move
Exchange.getTakerOpenNotional
toAccountBalance.getTakerOpenNotional
-
rename
OrderBook.getTotalTokenAmountInPool
toOrderBook.getTotalTokenAmountInPoolAndPendingFee
-
rename
AccountBalance.getOwedAndUnrealizedPnl
toAccountBalance.getPnlAndPendingFee
-
rename
AccountBalance.getNetQuoteBalance
toAccountBalance.getNetQuoteBalanceAndPendingFee
-
rename
AccountBalance.settleQuoteToPnl
toAccountBalance.settleQuoteToOwedRealizedPnl
-
add new second return value
pendingFee
ofAccountBalance.getOwedAndUnrealizedPnl
-
add new second return value
pendingFee
ofAccountBalance.getNetQuoteBalance
-
add new second return value
totalPendingFee
ofOrderBook.getTotalQuoteBalance
-
add new second return value
totalPendingFee
ofOrderBook.getTotalTokenAmountInPool
- remove
AccountBalance.getTakerQuote
- rename
useTakerPosition
touseTakerBalance
inClearingHouse.AddLiquidityParams
- update artifacts
- add
optimismKovan.json
andrinkeby.json
ofv0.12.7
- use the new NPM package name:
@perp/curie-contract
- rename
AccountBalance.getLiquidateMarginRequirement
toAccountBalance.getMarginRequirementForLiquidation
- rename
Vault.balanceOf
toVault.getBalance
- rename
AccountBalance.getPositionSize
toAccountBalance.getTotalPositionSize
- rename
AccountBalance.getPositionValue
toAccountBalance.getTotalPositionValue
- rename
Exchange.getOpenNotional
toExchange.getTotalOpenNotional
- fix error codes in
Exchange
EX_OPIBS
toEX_OPLBS
EX_OPIAS
toEX_OPLAS
- add field
useTakerPosition
toClearingHouse.AddLiquidityParams
- move event
LiquidityChanged
fromOrderBook
toClearingHouse
- add
AccountBalance.getTakerQuote()
to get taker's quote balance - add
Exchange.getTakerOpenNotional()
to get taker's open notional - add
ClearingHouseConfig.getMaxFundingRate()
andClearingHouseConfig.setMaxFundingRate()
- add
MarketRegistry.hasPool()
- add event
MaxFundingRateChanged
toClearingHouseConfig
- add event
TrustedForwarderChanged
toClearingHouse
- add event
TakerBalancesChanged
toAccountBalance
- add event
MaxTickCrossedWithinBlockChanged
toExchange
- add event
AccountBalanceChanged
toExchange
- add event
BorrowerChanged
toInsuranceFund
- remove state
_versionRecipient
fromClearingHouse
andVault
- remove
Quoter
andMulticall2
contracts from core.- You can find these contracts in @perp/curie-periphery-contract.
- deploy on Optimism Kovan
- bug fixes
- rounding error at
ClearingHouse.closePosition()
andVault.withdraw()
- rounding error at
- deploy 0.12.4 on Rinkeby
- changed the returned value of
ClearingHouse.getAccountValue
to 18 decimals
- add
AccountBalance.getTotalAbsPositionValue()
- add
ClearingHouseConfig.getSettlementTokenBalanceCap()
- add a new parameter
insuranceFundArg
toinitialize
of Exchange - add a new event
SettlementTokenBalanceCapChanged
to ClearingHouseConfig - add a new field
sqrtPriceAfter
toPositionChanged
of Exchange
- remove parameter
insuranceFundArg
frominitialize
of ClearingHouse - remove event
PositionChanged
from ClearingHouse - remove
getTotalAbsPositionValue
fromAccountBalance
- remove parameter
marketRegistryArg
frominitialize
of AccountBalance
- move event
PositionChanged
to Exchange - combine
getTotalUnrealizedPnl
andgetOwedRealizedPnl
togetOwedAndUnrealizedPnl
- move
getLiquidateMarginRequirement
fromVault
toAccountBalance
- rename
CleairngHouseConfig.liquidationPenaltyRatio
toClearingHouseConfig.getLiquidationPenaltyRatio
- rename
CleairngHouseConfig.partialCloseRatio
toClearingHouseConfig.getPartialCloseRatio
- rename
CleairngHouseConfig.twapInterval
toClearingHouseConfig.getTwapInterval
- rename
CleairngHouseConfig.maxMarketsPerAccount
toClearingHouseConfig.getMaxMarketsPerAccount
- rename
MarketRegistry.clearingHouse
toMarketRegistry.getClearingHouse
- rename
MarketRegistry.maxOrdersPerMarket
toMarketRegistry.getMaxOrdersPerMarket
- rename
Vault.totalDebt
toVault.getTotalDebt
- Error messages emitted by ClearingHouse._checkSlippage()
CH_TLR
toCH_TLRS
orCH_TLRL
, depending on the sideCH_TMR
toCH_TMRS
orCH_TMRL
, depending on the side
- bug fixing
- add
AccountBalance.getBaseTokens()
- add a new parameter
sqrtPriceX96
toSwapResponse
ofQuoter.swap()
- add
ClearingHouseConfig
contract - add
OrderBook
contract - add
AccountBalance
contract - add
MarketRegistry
contract
- remove
getOwedRealizedPnlWithPendingFundingPayment
from AccountBalance - remove
getLastUpdatedTick
from Exchange
TwapIntervalChanged
now emitted by ClearingHouseConfigLiquidationPenaltyRatioChanged
now emitted by ClearingHouseConfigPartialCloseRatioChanged
now emitted by ClearingHouseConfigReferredPositionChanged
now emitted by ClearingHouseConfigMaxMarketsPerAccountChanged
now emitted by ClearingHouseConfig- The following function move from ClearingHouse to AccountBalance
getOwedRealizedPnl
getTotalAbsPositionValue
getTotalDebtValue
getTotalUnrealizedPnl
getNetQuoteBalance
getPositionSize
getPositionValue
getOpenNotional
moved to ExchangesetMaxTickCrossedWithinBlock
andgetMaxTickCrossedWithinBlock
moved to ExchangegetPendingFundingPayment
andgetAllPendingFundingPayment
moved to Exchange
- remove
twapIntervalArg
fromClearinHouse.getPositionValue()
- add
Exchange
contract - add
BaseToken
contract - add
MetaTxGateway
contract
- 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 byExchange
LiquidityChanged
now emitted by ExchangeSwapped
is renamed toPositionChanged
and still emitted byClearingHouse
- 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 toFundingUpdated
and still emitted byClearingHouse
- event parameters also changed
event FundingUpdated(
address indexed baseToken,
uint256 markTwap,
uint256 indexTwap
);
FundingSettled
is renamed toFundingPaymentSettled
and still emitted byClearingHouse
- QuoteToken inherits from
VirtualToken
contract - All BaseTokens inherit from
BaseToken
contract
- add
ClearingHouse.getTotalInitialMarginRequirement()
- 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()
- replace hourly-based funding with block-based funding
- replace
cancelExcessOrders(maker, baseToken)
withcancelAllExcessOrders(maker, baseToken)
andcancelExcessOrders(maker, baseToken, orderIds)
- now
cancelAllExcessOrders()
will not automatically remove all liquidity
- now
- remove
ClearingHouse.updateFunding()
- remove
fundingPayment
andbadDebt
fromSwapped
event
- fix how realizedPnl and openNotional calculate for maker/taker
- add whitelist feature for
VirtualToken
- add
Quoter
contract
- rename
ClearingHouse.getTotalMarketPnl
toClearingHouse.getTotalUnrealizedPnl
- fix
Vault.getFreeCollateral
wrong numbers
- add
InsuranceFund
contract - add
ClearingHouse.getBuyingPower()
- add
ClearingHouse.liquidate()
- change the interface of
ClearingHouse.addLiquidity()
andClearingHouse.removeLiquidity()
- support slippage protection
- fix
ClearingHouse.swap()
- fix
TransferHelper::SafeTransfer: Transfer Failed
when opening a short position
- fix
- fix
ClearingHouse.getAccountValue()
- re-deployed all contracts
- implemented quote-only fee
- changed event parameters of
FundingRateUpdated
,FundingSettled
, andSwapped
:
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
);
- fix
Vault
is missing from@perp/curie-contract/artifacts/contracts
- add
Vault
contract
- move
ClearingHouse.deposit
toVault.deposit
- move
ClearingHouse.withdraw
toVault.withdraw
- move
ClearingHouse.getFreeCollateral
toVault.getFreeCollateral