v0.13.0
0.13.0 (2024-05-03)
⚠ BREAKING CHANGES
- open-pos: The fourth argument of InitiatedOpenPosition is now the position total expo instead of its leverage
- use
PositionIdwherever possible (#238) - types: removed common struct in all pending actions structs (#237)
- initial-close: A position cannot be partially closed if the remaining amount of collateral is greater than 0 and lower than _minLongPosition
- The
getMinLongPositionfunction now returns an amount in_assets - removed getLiquidationMultiplier; function getEffectiveTickForPrice(uint128 price, uint256 liqMultiplier) has been replaced with getEffectiveTickForPrice(uint128 price, uint256 assetPrice, uint256 longTradingExpo, HugeUint.Uint512 memory accumulator, int24 tickSpacing); function getEffectivePriceForTick(int24 tick, uint256 liqMultiplier) has been replaced with getEffectivePriceForTick(int24 tick, uint256 assetPrice, uint256 longTradingExpo, HugeUint.Uint512 memory accumulator); the PendingAction struct now uses a struct PendingActionCommonData for its first field, replacing action, timestamp, user to, securityDepositValue. For consistency, the amount field was renamed to var2, var2 to var3, etc.; the DepositPendingAction, WithdrawalPendingAction and LongPendingAction now use the new PendingActionCommonData struct as first field; for LongPendingAction, the field closeTotalExpo was renamed to closePosTotalExpo and is used for a different purpose.; the field closeTempTransfer was renamed to closeBoundedPositionValue.
- oracle-middleware: error OracleMiddlewareInsufficientFee has been renamed OracleMiddlewareIncorrectFee
- change the name of the function getMaxInitializedTick to getHighestPopulatedTick
- add to parameter in main functions (#109)
- initiate-close: The event now contins the original value on the position and the amount to be subtracted from it
Features
- actions: event when the security deposit is refunded (#222) (be37f6f)
- add _calcTickWithoutPenalty (#241) (77d4f86)
- add
previewWithdrawfunction (#218) (237a474) - add to parameter in main functions (#109) (257092f)
- change minLongPosition to represent the amount of collateral (#229) (08f63dc)
- initial-close: revert if the remaining position not greater or equal to _minLongPosition (#236) (6e0c256)
- open-pos: replace the leverage by the position total expo in the open position events (#239) (9b4f5a4)
- oracle-middleware: make the oracle middleware revert if the validation cost is not exact (#217) (e92be5d)
- reward user actions when a position is liquidated (#205) (76091ee)
- rewards: add priceData to the parameters sent to the liquidation rewards manager (#233) (1b1cc88)
- rewards: apply the multiplicator only on the tick liquidation cost (#231) (5eaebbd)
Bug Fixes
- init-open: remove a residue of the min position value check (#243) (3f9e405)
- outdated pyth data (#221) (bf249b3)
Code Refactoring
- initiate-close: change the values sent in the InitiatedClosePosition event (#210) (cf67c66)
- replace liquidation multiplier with accumulator (#206) (d60a3a9)
- test and rename
_maxInitializedTickinto_highestPopulatedTick(#203) (a418d5c) - types: removed common struct in all pending actions structs (#237) (78b2175)
- use
PositionIdwherever possible (#238) (d0f7ee1)
Details
- Long position can't be partially closed if the remaining value is under minimum position value
- Add to parameter in deposit/withdraw/open/close functions
- Replace the leverage by the position total expo in the open position events
- Make the oracle middleware revert if the validation cost is not exact
- Reward user actions when a position is liquidated
- Update the liquidation reward calculation
- Replace liquidation multiplier with accumulator
- The minimum long position is now in wstETH instead of USD
Data Structure
Update
-
struct PendingAction
- add address to
-
struct DepositPendingAction
- add address to
-
struct WithdrawalPendingAction
- add address to
-
struct LongPendingAction
- add address to
- uint128 closeTotalExpo -> uint128 closePosTotalExpo
- uint256 closeTempTransfer -> uint256 closeBoundedPositionValue
Function
New
OracleMiddleware
- withdrawEther(address to)
UsdnProtocol
- getLiqMultiplierAccumulator() external view returns (HugeUint.Uint512 memory)
- getHighestPopulatedTick()
Update
LiquidationReward
- REWARDS_MULTIPLIER_DENOMINATOR() -> BPS_DIVISOR()
- getLiquidationRewards(uint16 tickAmount, int256 remainingCollateral, bool rebased) -> getLiquidationRewards(
uint16 tickAmount,
int256 remainingCollateral,
bool rebased,
bytes priceData)
UsdnProtocol
- initiateDeposit(
uint128 amount,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData) -> initiateDeposit(
uint128 amount,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData,
address to) - initiateWithdrawal(
uint152 usdnShares,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData) -> initiateWithdrawal(
uint152 usdnShares,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData,
address to) - initiateOpenPosition(
uint128 amount,
uint128 desiredLiqPrice,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData) -> initiateOpenPosition(
uint128 amount,
uint128 desiredLiqPrice,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData,
address to) - initiateClosePosition(
int24 tick,
uint256 tickVersion,
uint256 index,
uint128 amountToClose,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData) -> initiateClosePosition(
PositionId calldata posId,
uint128 amountToClose,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData,
address to) - getLongPosition(int24 tick, uint256 tickVersion, uint256 index)
returns (Position memory, uint8) -> getLongPosition(PositionId calldata posId)
returns (Position memory pos_, uint8 liquidationPenalty_) - getPositionValue(int24 tick, uint256 tickVersion, uint256 index, uint128 price, uint128 timestamp) -> getPositionValue(PositionId calldata posId, uint128 price, uint128 timestamp)
- getEffectiveTickForPrice(uint128 price, uint256 liqMultiplier) -> getEffectiveTickForPrice(
uint128 price,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
int24 tickSpacing) - getEffectivePriceForTick(int24 tick, uint256 liqMultiplier) -> getEffectivePriceForTick(
int24 tick,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator)
Delete
UsdnProtocol
- getLiquidationMultiplier(uint128 timestamp)
- SECURITY_DEPOSIT_FACTOR()
- getLiquidationMultiplier()
- getMaxInitializedTick()
Events
New
UsdnProtocol
- SecurityDepositRefunded(address indexed paidBy, address indexed receivedBy, uint256 amount)
Update
UsdnProtocol
- InitiatedDeposit(address indexed user, uint256 amount, uint256 timestamp) -> InitiatedDeposit(address indexed user, address indexed to, uint256 amount, uint256 timestamp)
- ValidatedDeposit(address indexed user, uint256 amountDeposited, uint256 usdnMinted, uint256 timestamp) -> ValidatedDeposit(
address indexed user, address indexed to, uint256 amountDeposited, uint256 usdnMinted, uint256 timestamp) - InitiatedWithdrawal(address indexed user, uint256 usdnAmount, uint256 timestamp) -> InitiatedWithdrawal(address indexed user, address indexed to, uint256 usdnAmount, uint256 timestamp)
- ValidatedWithdrawal(address indexed user, uint256 amountWithdrawn, uint256 usdnBurned, uint256 timestamp) -> ValidatedWithdrawal(
address indexed user, address indexed to, uint256 amountWithdrawn, uint256 usdnBurned, uint256 timestamp) - InitiatedOpenPosition(
address indexed user,
uint40 timestamp,
uint128 leverage,
uint128 amount,
uint128 startPrice,
int24 tick,
uint256 tickVersion,
uint256 index) -> InitiatedOpenPosition(
address indexed user,
address indexed to,
uint40 timestamp,
uint128 totalExpo,
uint128 amount,
uint128 startPrice,
PositionId posId) - ValidatedOpenPosition(
address indexed user, uint128 newLeverage, uint128 newStartPrice, int24 tick, uint256 tickVersion, uint256 index) -> ValidatedOpenPosition(
address indexed user, address indexed to, uint128 totalExpo, uint128 newStartPrice, PositionId posId) - LiquidationPriceUpdated(
int24 indexed oldTick,
uint256 indexed oldTickVersion,
uint256 indexed oldIndex,
int24 newTick,
uint256 newTickVersion,
uint256 newIndex) -> LiquidationPriceUpdated(PositionId indexed oldPosId, PositionId newPosId) - InitiatedClosePosition(
address indexed user,
int24 tick,
uint256 tickVersion,
uint256 index,
uint128 amountRemaining,
uint128 totalExpoRemaining) -> InitiatedClosePosition(
address indexed user,
address indexed to,
PositionId posId,
uint128 originalAmount,
uint128 amountToClose,
uint128 totalExpoRemaining) - ValidatedClosePosition(
address indexed user, int24 tick, uint256 tickVersion, uint256 index, uint256 amountReceived, int256 profit) -> ValidatedClosePosition(
address indexed user, address indexed to, PositionId posId, uint256 amountReceived, int256 profit) - LiquidatedPosition(
address indexed user,
int24 tick,
uint256 tickVersion,
uint256 index,
uint256 liquidationPrice,
uint256 effectiveTickPrice) -> LiquidatedPosition(
address indexed user, PositionId posId, uint256 liquidationPrice, uint256 effectiveTickPrice) - StalePendingActionRemoved(address indexed user, int24 tick, uint256 tickVersion, uint256 index) -> StalePendingActionRemoved(address indexed user, PositionId posId)
Errors
New
OracleMiddleware
- OracleMiddlewareTransferToZeroAddress()
- OracleMiddlewareTransferFailed(address to)
UsdnProtocol
- UsdnProtocolInvalidAddressTo()
- UsdnProtocolZeroLongTradingExpo()
Update
OracleMiddleware
- OracleMiddlewareInsufficientFee() -> OracleMiddlewareIncorrectFee()
Delete
OracleMiddleware
- OracleMiddlewareEtherRefundFailed()