Skip to content

Releases: SmarDex-Ecosystem/usdn-contracts

v0.12.0

04 Apr 17:03
86842da
Compare
Choose a tag to compare

0.12.0 (2024-04-04)

⚠ BREAKING CHANGES

  • withdraw: initiateWithdrawal now takes an input amount of USDN shares instead of USDN tokens, and the type is uint152. The VaultPendingAction type has been replaced by DepositPendingAction and WithdrawalPendingAction, the PendingAction and LongPendingAction types have re-ordered fields.
  • sdex-burn: A user calling initiateDeposit now needs to have enough SDEX tokens and to have approved the spending of his tokens by the USDN protocol. getUsdnDecimals has been removed, use TOKENS_DECIMALS instead, or the decimals() function on the token contract instead.
  • actions: PendingAction, VaultPendingAction and LongPendingAction have now a variable to keep the value of the security deposit done in the initialise action
  • actions: getPositionValue now returns a signed int which is negative in case of bad debt

Features

  • actions: security deposit (#137) (c09d964)
  • add minimum long position value (#167) (6ffb50a)
  • add wusdn and test (#156) (3ca9024)
  • rebase: change default values for rebase parameters (#162) (27a9ccd)
  • sdex-burn: depositing assets in the protocol now requires the user to have enough SDEX in his wallet to support the burn fee. (6d08982)
  • storage: update initial target usdn price (#168) (bd5568b)
  • usdn: add functions to transfer, mint, burn shares (#163) (f9bc31c)

Bug Fixes

  • actions: fix handling of bad debt in case of single position liq (#160) (d60d99b)
  • withdraw: use USDN shares for withdrawal input and burn (#173) (9f1879f)

Details

  • Add the security deposit. The security deposit is a fixed amount of eth
    that the user must provide to the contract to be able to call an initiate function.
    Users who fail to validate their initiate action before the validation deadline will
    forfeit their deposit to the users who validate their actions.
  • Long positions need to have a minimum value of $5,000
  • WUsdn contract is added
  • Deposit will burn an amount of SDEX proportional to the amount of minted USDN
  • The USDN will rebase when the price is >$1.0087
  • Users can burn and transfer USDN shares
  • USDN withdraw action use shares as a parameter

Data Structure

Update
  • PendingAction
    • add uint24 securityDepositValue
  • Rename VaultPendingAction -> DepositPendingAction
    • add uint24 securityDepositValue
  • Add WithdrawalPendingAction
  • LongPendingAction
    • add uint24 securityDepositValue

Function

New

UsdnProtocol

  • setSdexBurnOnDepositRatio(uint32 newRatio)
  • setSecurityDepositValue(uint256 securityDepositValue)
  • setMinLongPosition(uint256 newMinLongPosition)
  • SDEX_BURN_ON_DEPOSIT_DIVISOR()
  • SECURITY_DEPOSIT_FACTOR()
  • getSdex()
  • getSdexBurnOnDepositRatio()
  • getSecurityDepositValue()
  • getMinLongPosition()

Usdn

  • transferShares(address to, uint256 value)
  • transferSharesFrom(address from, address to, uint256 value)
  • mintShares(address to, uint256 amount)
  • burnShares(uint256 value)
  • burnSharesFrom(address account, uint256 value)
Update

UsdnProtocol

  • getUsdnDecimals() -> TOKENS_DECIMALS()

Events

New

UsdnProtocol

  • BurnSdexOnDepositRatioUpdated(uint256 newRatio)
  • SecurityDepositValueUpdated(uint256 securityDepositValue)
  • MinLongPositionUpdated(uint256 minLongPosition)

Errors

New

Usdn

  • UsdnInsufficientSharesBalance(address sender, uint256 balance, uint256 needed)

UsdnProtocol

  • UsdnProtocolInvalidTokenDecimals()
  • UsdnProtocolLongPositionTooSmall()
  • UsdnProtocolInvalidBurnSdexOnDepositRatio()
  • UsdnProtocolSecurityDepositTooLow()
  • UsdnProtocolInvalidSecurityDepositValue()
  • UsdnProtocolUnexpectedBalance()
  • UsdnProtocolInvalidMinLongPosition()

v0.11.1

25 Mar 16:12
078edd8
Compare
Choose a tag to compare

0.11.1 (2024-03-25)

Bug Fixes

  • middleware: infinite loop in mock contract (#164) (64ef1a0)

v0.11.0

22 Mar 08:33
1fa04a4
Compare
Choose a tag to compare

0.11.0 (2024-03-21)

⚠ BREAKING CHANGES

  • middleware: removed getPythDecimals from oracle middleware
  • getTotalExpoByTick now doesn't require the tick version anymore, getPositionsInTick now doesn't require the tick version anymore, getLongPositionsLength was removed as it was doing the same thing as getPositionsInTick
  • new parameter timestamp in events InitiatedDeposit, InitiatedWithdrawal, ValidatedDeposit and ValidatedWithdrawal

Features

Bug Fixes

  • disable slither false positive (2672f14)
  • funding: decimals in returned values (#150) (18a58a7)
  • gas-test: fix liquidation gas usage test (2672f14)
  • middleware: unify types and fix some bugs (#141) (cfae831)

Code Refactoring

  • remove tick version parameter to external functions and delete duplicated function (2672f14)

Details

  • Can validate pending actions manually
  • Add timestamp in vault events
  • Limits when the protocol is unbalanced between vault and long
  • Cached pyth price

Data Structure

Update
  • OracleMiddleware
    • FormattedPythPrice
      • remove int128 expo
      • update int256 price in uint256 price
      • update uint128 publishTime in uint256 publishTime

Function

New

UsdnProtocol

  • validateActionablePendingActions(PreviousActionsData, uint256)
  • setExpoImbalanceLimits(
    uint256 newOpenLimitBps,
    uint256 newDepositLimitBps,
    uint256 newWithdrawalLimitBps,
    uint256 newCloseLimitBps )
  • getExpoImbalanceLimits()

OracleMiddleware

  • getChainlinkDecimals() returns (uint256)
  • getPriceFeed() returns AggregatorV3Interface
  • getPyth() returns (address)
  • getPriceID() returns (bytes32)
  • getRecentPriceDelay() returns (uint64)
Update

UsdnProtocol

  • getLongPositionsLength(int24 tick) -> getPositionsInTick(int24 tick)
  • getTotalExpoByTick(int24 tick, uint256 version) -> getTotalExpoByTick(int24 tick)
Remove

OracleMiddleware

  • getPythDecimals()

UsdnProtocol

  • getPositionsInTick(int24 tick, uint256 version)

Events

New

UsdnProtocol

  • ImbalanceLimitsUpdated(
    uint256 newOpenLimitBps, uint256 newDepositLimitBps, uint256 newWithdrawalLimitBps, uint256 newCloseLimitBps)
Update

UsdnProtocol

  • InitiatedDeposit(address indexed user, uint256 amount, uint256 timestamp)
  • ValidatedDeposit(address indexed user, uint256 amountDeposited, uint256 usdnMinted, uint256 timestamp)
  • InitiatedWithdrawal(address indexed user, uint256 usdnAmount, uint256 timestamp)
  • ValidatedWithdrawal(address indexed user, uint256 amountWithdrawn, uint256 usdnBurned, uint256 timestamp)

Errors

New

OracleMiddleware

  • OracleMiddlewarePythPositiveExponent(int32 expo)

UsdnProtocol

  • UsdnProtocolInvalidExpoImbalanceLimit()
  • UsdnProtocolImbalanceLimitReached(int256 imbalanceBps)
  • UsdnProtocolInvalidVaultExpo()
  • UsdnProtocolInvalidLongExpo()

v0.10.0

15 Mar 08:26
f50cbb4
Compare
Choose a tag to compare

0.10.0 (2024-03-14)

⚠ BREAKING CHANGES

  • actions: initiateDeposit, validateDeposit, initiateWithdrawal, validateWithdrawal, initiateOpenPosition, validateOpenPosition, initiateClosePosition and validateClosePosition now take a PreviousActionsData struct as last argument. getActionablePendingAction for now returns a single action and its corresponding rawIndex. DoubleEndedQueue returns a second argument with the raw index for methods front, back and at.
  • close-long: Position and PendingAction structs do not return the leverage anymore, they have the position expo instead
  • core: changed visibility of funding and fundingAsset functions (#143)
  • core: view functions for balances now consider funding and fees (#131)
  • usdn: ADJUSTMENT_ROLE becomes REBASER_ROLE, adjustDivisor becomes rebase, DivisorAdjusted becomes Rebase

Features

  • actions: separated external functions in multiple internal functions (#135) (3bdab81)
  • close-long: add the ability to partially close a position (#130) (62ff252)
  • core: changed visibility of funding and fundingAsset functions (#143) (d63cb41)
  • core: view functions for balances now consider funding and fees (#131) (4c323c9)
  • usdn: add automatic rebase (#124) (007df26)

Bug Fixes

  • assettotransfer: fix the double subtraction in asset to transfer when validating a close position (#138) (8bc712c)
  • position-totalexpo: use the liq price without penalty to calculate the position total expo (#134) (90b2ca4)

Code Refactoring

  • actions: allow to pass a list of pending actions data (#133) (efaea43)

Details

  • Funding function now takes only the timestamp and fundingAsset is now internal
  • Modify long/vaultAssetAvailableWithFunding to subtract fees to the returned values
  • Add the ability to partially close a position
  • Add automatic rebase for USDN
  • Can pass a list of prices signatures instead of one when validating pending action
  • Fix: The amount received by the user when closing a position is now calculated correctly
  • Fix: Use the liquidation price without a penalty when calculating the position exposition

Data Structure

New
  • PreviousActionsData :
    • bytes[] priceData An array of bytes, each representing the data to be forwarded to the oracle middleware to validate
    • uint128[] rawIndices An array of raw indices in the pending actions queue, in the same order as the corresponding
Update
  • RewardsParameters:
    • add rebaseGasUsed: uint32

Function

New

UsdnProtocol

  • setTargetUsdnPrice(uint128 newPrice)
  • setUsdnRebaseThreshold(uint128 newThreshold)
  • setUsdnRebaseInterval(uint256 newInterval)
  • calcEMA(int256 lastFunding, uint128 secondsElapsed, uint128 emaPeriod, int256 previousEMA) returns (int256)
  • getUsdnMinDivisor() returns (uint256)
  • getTargetUsdnPrice() returns (uint128)
  • getUsdnRebaseThreshold() returns (uint128)
  • getUsdnRebaseInterval() returns (uint256)
  • getLastRebaseCheck() returns (uint256)
Update

LiquidationRewardsManager

  • getLiquidationRewards(uint16 tickAmount, int256 amountLiquidated, bool rebased)
  • function setRewardsParameters( uint32 gasUsedPerTick,
    uint32 otherGasUsed,
    uint32 rebaseGasUsed,
    uint64 gasPriceLimit,
    uint32 multiplierBps )

Usdn

  • adjustDivisor(uint256 divisor) -> rebase(uint256 divisor)
  • ADJUSTMENT_ROLE() -> REBASER_ROLE()

UsdnProtocol

  • initiateClosePosition(
    int24 tick,
    uint256 tickVersion,
    uint256 index,
    uint128 amountToClose,
    bytes calldata currentPriceData,
    bytes calldata previousActionPriceData)
  • initiateDeposit, validateDeposit, initiateWithdrawal, validateWithdrawal,
    initiateOpenPosition, validateOpenPosition, initiateClosePosition
    and validateClosePosition last parameter is no longer bytes calldata previousActionPriceData
    but PreviousActionsData calldata previousActionsData instead
    see PreviousActionsData for more details
  • DEFAULT_QUEUE_MAX_ITER() -> MAX_ACTIONABLE_PENDING_ACTIONS()
  • getActionablePendingAction(uint256 maxIter) returns (PendingAction memory action_) ->
    getActionablePendingActions(address currentUser) returns (PendingAction[] memory actions_, uint128[] memory rawIndices_)
Remove

UsdnProtocol

  • fundingAsset(uint128 timestamp) -> internal

Events

New

UsdnProtocol

  • TargetUsdnPriceUpdated(uint128 price)
  • UsdnRebaseThresholdUpdated(uint128 threshold)
  • UsdnRebaseIntervalUpdated(uint256 interval)
Update

LiquidationRewardsManager

  • RewardsParametersUpdated(
    uint32 gasUsedPerTick, uint32 otherGasUsed, uint32 rebaseGasUsed, uint64 gasPriceLimit, uint32 multiplierBps
    )

Usdn

  • DivisorAdjusted(uint256 oldDivisor, uint256 newDivisor) -> Rebase(uint256 oldDivisor, uint256 newDivisor)

UsdnProtocol

  • InitiatedClosePosition(
    address indexed user,
    int24 tick,
    uint256 tickVersion,
    uint256 index,
    uint128 amountRemaining,
    uint128 totalExpoRemaining)

Errors

New

LiquidationRewardsManager

  • LiquidationRewardsManagerRebaseGasUsedTooHigh(uint256 value)

UsdnProtocol

  • UsdnProtocolInvalidTargetUsdnPrice()
  • UsdnProtocolInvalidUsdnRebaseThreshold()
  • UsdnProtocolAmountToCloseHigherThanPositionAmount(uint128 amountToClose, uint128 positionAmount)
  • UsdnProtocolAmountToCloseIsZero()
  • UsdnProtocolInvalidPendingActionData()
Remove

Usdn

  • UsdnInvalidDivisor(uint256 divisor)

v0.9.0

07 Mar 20:58
1ad9a72
Compare
Choose a tag to compare

0.9.0 (2024-03-07)

⚠ BREAKING CHANGES

  • positions: Position and PendingAction structs do not return the leverage anymore, they have the position expo instead

Features

  • priceProcessing: entry/exit fees and oracle price confidence ratio (#82) (48d897b)
  • update Hermes api endpoint to Ra2 Pyth node (#125) (0c3dd15)

Code Refactoring

  • positions: replace the leverage by the position expo in position and action structs (#113) (7317c4d)

Details

  • Replace the leverage by the position expo in position and action structs
  • Add confidence price: Pyth price provides down, neutral and up confidence levels.
    Instead of using 100% of the confidence price, we added a confidence ratio.
    The default value is 40%. The max possible is 200% and min 0%.
  • Add entry and exit fees to the protocol. Used when a user deposits, withdraw, open or close.
    Impact the price used. It will be indirectly distributed to the vault. Default is 0.04%, the max value is 20% and min 0%.

Deploy

  • In the broadcast file after the deployment, each deployed contract will feature their addresses in the .json.
    It's to avoid parsing the transactions block. The path for the address is .returns.ContractName_.value

Data Structure

Update
  • Position

    • Remove leverage
    • Add totalExpo
  • LongPendingAction

    • Remove closeLeverage
    • Add closeTotalExpo

Function

New

OracleMiddleware

  • getMaxConfRatio()
  • getConfRatioDenom()
  • getConfRatio()
  • setConfRatio(uint16 newConfRatio)

UsdnProtocol

  • setPositionFeeBps(uint16 newPositionFee)
  • getPositionFeeBps()

Events

New

OracleMiddleware

  • ConfRatioUpdated(uint256 newConfRatio)

UsdnProtocol

  • PositionFeeUpdated(uint256 positionFee)

Errors

New

OracleMiddleware

  • OracleMiddlewareConfRatioTooHigh()

UsdnProtocol

  • UsdnProtocolInvalidPositionFee()

v0.8.0

29 Feb 17:31
a89e364
Compare
Choose a tag to compare

0.8.0 (2024-02-29)

NOTE: the 0.8.0 version does not exist inside the npm registry. But it's functionally identical to the 0.8.1-main.2e73343e0d042087341283705e3ec7c43fdc2d87.0 version which is available.

⚠ BREAKING CHANGES

  • getPositionValue now expects a timestamp parameter
  • protocol: view and admin functions (#93)
  • removed default position and added protection in funding calculation (#102)

Features

  • protocol: view and admin functions (#93) (d3dfaf2)
  • removed default position and added protection in funding calculation (#102) (5907e66)

Bug Fixes

Details

  • Admin and view functions
  • Removal of the default long 1000 wei position.
  • Addition of new conditions in funding calculation for edge cases where the vault and long exposures are at their limits. See PR #102 for more details
  • Fix balance when bad dept

Function

New

LiquidationRewardsManager

  • REWARDS_MULTIPLIER_DENOMINATOR
  • BASE_GAS_COST

OracleMiddleware

  • setRecentPriceDelay(uint64 newDelay)

UsdnProtocol

  • MIN_INIT_DEPOSIT
  • setOracleMiddleware(IOracleMiddleware newOracleMiddleware)
  • setLiquidationRewardsManager(ILiquidationRewardsManager newLiquidationRewardsManager)
  • setMinLeverage(uint256 newMinLeverage)
  • setMaxLeverage(uint256 newMaxLeverage)
  • setValidationDeadline(uint256 newValidationDeadline)
  • setLiquidationPenalty(uint24 newLiquidationPenalty)
  • setSafetyMarginBps(uint256 newSafetyMarginBps)
  • setLiquidationIteration(uint16 newLiquidationIteration)
  • setEMAPeriod(uint128 newEMAPeriod)
  • setFundingSF(uint256 newFundingSF)
  • getUserPendingAction(address user)
  • getEffectiveTickForPrice(uint128 price, uint256 liqMultiplier)
  • getEffectivePriceForTick(int24 tick, uint256 liqMultiplier)

UsdnProtocolStorage

  • getAsset
  • getPriceFeedDecimals
  • getAssetDecimals
  • getUsdn
  • getUsdnDecimals
  • getOracleMiddleware
  • getValidationDeadline
  • getLiquidationPenalty
  • getSafetyMarginBps
  • getLiquidationIteration
  • getEMAPeriod
  • getFundingSF
  • getMiddlewareValidationDelay
  • getLastFunding
  • getLastPrice
  • getLastUpdateTimestamp
  • getPendingAction(address user)
  • getPendingActionAt(uint256 index)
  • getBalanceVault
  • getEMA
  • getBalanceLong
  • getTotalExpo
  • getTickVersion(int24 tick)
  • getTotalExpoByTick(int24 tick, uint256 version)
  • getPositionsInTick(int24 tick, uint256 version)
  • getCurrentLongPosition(int24 tick, uint256 index)
  • getCurrentTotalExpoByTick(int24 tick)
  • getCurrentPositionsInTick(int24 tick)
  • getMaxInitializedTick
  • getTotalLongPositions
  • tickHash(int24 tick, uint256 version)
Update

MockLiquidationRewardsManager

  • mockedGasPrice -> getWstethMockedPrice
  • wstethMockedConfPct -> getWstethMockedConfPct
  • wstethMockedConfDenom -> getWstethMockedConfDenom

MockLiquidationRewardsManager

  • mockedGasPrice -> getMockedGasPrice

ChainlinkOracle

  • chainlinkDecimals -> getChainlinkDecimals
  • priceFeed -> getPriceFeed

PythOracle

  • pythDecimals -> getPythDecimals
  • pyth -> getPyth
  • priceID -> getPriceID

OracleMiddleware

  • validationDelay -> getValidationDelay
  • decimals -> getDecimals
  • updateValidationDelay -> setValidationDelay
  • updateChainlinkTimeElapsedLimit -> setChainlinkTimeElapsedLimit

UsdnProtocolStorage

  • tickSpacing -> getTickSpacing
  • minLeverage -> getMinLeverage
  • maxLeverage -> getMaxLeverage
  • liquidationMultiplier -> getLiquidationMultiplier
  • liquidationRewardsManager -> getLiquidationRewardsManager
  • pendingProtocolFee -> getPendingProtocolFee
  • feeThreshold -> getFeeThreshold
  • feeCollector -> getFeeCollector
  • protocolFeeBps -> getProtocolFeeBps

UsdnProtocol

  • setFeeBps -> setProtocolFeeBps
  • funding(uint128 currentPrice, uint128 timestamp) -> funding(uint128 timestamp)
  • fundingAsset(uint128 currentPrice, uint128 timestamp) -> fundingAsset(uint128 timestamp)
  • getLiquidationMultiplier(uint128 currentPrice, uint128 timestamp) -> getLiquidationMultiplier(uint128 timestamp)
  • getPositionValue(int24 tick, uint256 tickVersion, uint256 index, uint128 currentPrice) -> getPositionValue(int24 tick, uint256 tickVersion, uint256 index, uint128 price, uint128 timestamp)

Events

New

OracleMiddleware

  • ValidationDelayUpdated(uint256 newValidationDelay)
  • RecentPriceDelayUpdated(uint64 newDelay)

UsdnProtocol

  • OracleMiddlewareUpdated(address newMiddleware)
  • MinLeverageUpdated(uint256 newMinLeverage)
  • MaxLeverageUpdated(uint256 newMaxLeverage)
  • ValidationDeadlineUpdated(uint256 newValidationDeadline)
  • LiquidationPenaltyUpdated(uint24 newLiquidationPenalty)
  • SafetyMarginBpsUpdated(uint256 newSafetyMargin)
  • LiquidationIterationUpdated(uint16 newLiquidationIteration)
  • EMAPeriodUpdated(uint128 newEMAPeriod)
  • FundingSFUpdated(uint256 newFundingSF)
Update

IUsdnProtocolEvents

  • LiquidationPriceChanged -> LiquidationPriceUpdated

Errors

New
  • UsdnProtocolInvalidMinLeverage()
  • UsdnProtocolInvalidMaxLeverage()
  • UsdnProtocolInvalidValidationDeadline()
  • UsdnProtocolInvalidLiquidationPenalty()
  • UsdnProtocolInvalidSafetyMarginBps()
  • UsdnProtocolInvalidLiquidationIteration()
  • UsdnProtocolInvalidEMAPeriod()
  • UsdnProtocolInvalidFundingSF()
  • UsdnProtocolInvalidLiquidationRewardsManagerAddress()
Update

IUsdnProtocolErrors

  • UsdnProtocolLiquidationRewardsManagerIsZeroAddress ->
    UsdnProtocolInvalidLiquidationRewardsManagerAddress

v0.7.0

22 Feb 17:15
95cd761
Compare
Choose a tag to compare

0.7.0 (2024-02-22)

⚠ BREAKING CHANGES

  • LiquidationRewards: Implement the LiquidationRewardsManager contract and transfer liquidation rewards to the liquidator (#91)
  • the constructor now takes feeCollector address

Features

  • add protocol fee (#90) (088810c)
  • LiquidationRewards: Implement the LiquidationRewardsManager contract and transfer liquidation rewards to the liquidator (#91) (c860fa6)

Bug Fixes

  • Adjust the total expo when the leverage of the position change on validation (#104) (908c8e1)
  • ema: protection when secondElapsed >= EMAPeriod (#99) (c3bf2b3)
  • middleware: validation logic for liquidation (#95) (681ffb3)

Details

  • Add reward for liquidation.
    Will take the lowest between chainlink data feed and tx.gasprice for the calculation of the reward.
    New contract to handle it LiquidationRewardsManager
  • Can use Pyth price everywhere. When the Chainlink price is too old, it will be replaced by the Pyth price.
  • Add protocol fees. When the balance between vault and long is updated, the protocol fees are calculated and sent to an external address.
  • Fix: Pyth price could not be used in the liquidation process.
  • Add a tool to visualize logs

Deployment

  • Add FORK_CHAIN_ID
  • Add CHAINLINK_GAS_PRICE_ADDRESS
  • Add CHAINLINK_GAS_PRICE_VALIDITY
  • Add CHAINLINK_STETH_PRICE_VALIDITY
  • Add FEE_COLLECTOR
  • Add LIQUIDATION_REWARDS_MANAGER_ADDRESS
  • Add INIT_LONG_LIQPRICE
  • Deploy the LiquidationRewardsManager contract
  • Deposit more ETH at the initialization of the protocol

Data structure

New
  • RewardsParameters in ILiquidationRewardsManager
  • ChainlinkPriceInfo in OracleMiddleware

Function

New
  • see interface ILiquidationRewardsManager
  • getChainlinkTimeElapsedLimit() in OracleMiddleware
  • updateChainlinkTimeElapsedLimit(uint256 newTimeElapsedLimit) in OracleMiddleware
  • setFeeBps(uint16 feeBps) in UsdnProtocol
  • setFeeCollector(address feeCollector) in UsdnProtocol
  • setFeeThreshold(uint256 feeThreshold) in UsdnProtocol
  • liquidationRewardsManager() in UsdnProtocol
  • pendingProtocolFee() in UsdnProtocol
  • feeThreshold() in UsdnProtocol
  • feeCollector() in UsdnProtocol
  • protocolFeeBps() in UsdnProtocol
Update
  • PERCENTAGE_DIVISOR -> BPS_DIVISOR in UsdnProtocol

Events

New
  • see interface ILiquidationRewardsManagerErrorsEventsTypes
  • TimeElapsedLimitUpdated(uint256 newTimeElapsedLimit) in OracleMiddleware
  • LiquidatorRewarded(address indexed liquidator, uint256 rewards) in UsdnProtocol
  • LiquidationRewardsManagerUpdated(address newAddress) in UsdnProtocol
  • ProtocolFeeDistributed(address feeCollector, uint256 amount) in UsdnProtocol
  • FeeBpsUpdated(uint256 feeBps) in UsdnProtocol
  • FeeCollectorUpdated(address feeCollector) in UsdnProtocol
  • FeeThresholdUpdated(uint256 feeThreshold) in UsdnProtocol

Errors

New
  • see interface ILiquidationRewardsManagerErrorsEventsTypes
  • OracleMiddlewareInvalidRecentPriceDelay(uint64 newDelay) in OracleMiddleware
  • UsdnProtocolLiquidationRewardsManagerIsZeroAddress() in UsdnProtocol
  • UsdnProtocolInvalidProtocolFeeBps() in UsdnProtocol
  • UsdnProtocolInvalidFeeCollector() in UsdnProtocol
Update
  • OracleMiddlewarePriceTooOld(uint256 timestamp) in OracleMiddleware

v0.6.0

15 Feb 16:11
d9be95d
Compare
Choose a tag to compare

0.6.0 (2024-02-15)

⚠ BREAKING CHANGES

  • transfer remaining collateral to vault upon liquidation (#89)
  • events: Position has no startPrice anymore, InitiatedOpenPosition and ValidatedOpenPosition have different fields
  • middleware: some unused errors don't exist anymore

Features

  • transfer remaining collateral to vault upon liquidation (#89) (92f43e7)
  • update position tick if leverage exceeds max leverage (#76) (aad0e50)

Bug Fixes

  • liquidation: use neutral price and liquidate whenever possible (#94) (92f13b5)
  • middleware: remove unused errors (#83) (6a95a11)
  • only pass required ether to middleware and refund excess (#87) (7c777e4)

Code Refactoring

  • events: remove unused or unneeded fields from events and structs (#88) (672e4f7)

Details

  • Update position tick if leverage exceeds max leverage. If leverage above 10, then update tick to the lower tick with leverage under 10.
  • Fix: ether refund from oracle middleware, was unable to validate two times in the same tx/
  • Update balance between vault and long when a position is liquidated. If there is a gain, the vault will receive the gain, if there is a loss, the vault will pay the loss.
  • Use neutral pyth price for liquidation.

Deployment

  • PYTH_WSTETH_PRICE_ID removed

Data structure

  • Remove uint128 startPrice from Position

Events

Update
  • event InitiatedOpenPosition( address indexed user, Position position, int24 tick, uint256 tickVersion, uint256 index)
    -> event InitiatedOpenPosition( address indexed user, uint40 timestamp, uint128 leverage, uint128 amount, uint128 startPrice, int24 tick, uint256 tickVersion, uint256 index );
  • event ValidatedOpenPosition( address indexed user, Position position, int24 tick, uint256 tickVersion, uint256 index, uint128 liquidationPrice ); -> event ValidatedOpenPosition( address indexed user, uint128 newLeverage, uint128 newStartPrice, int24 tick, uint256 tickVersion, uint256 index );
  • event LiquidatedTick( int24 indexed tick, uint256 indexed oldTickVersion, uint256 liquidationPrice, uint256 effectiveTickPrice );->event LiquidatedTick( int24 indexed tick, uint256 indexed oldTickVersion, uint256 liquidationPrice, uint256 effectiveTickPrice, int256 remainingCollateral )

Errors

New
  • OracleMiddlewareInsufficientFee()
  • OracleMiddlewareEtherRefundFailed()
  • UsdnProtocolInsufficientOracleFee()
  • UsdnProtocolEtherRefundFailed()
Removed
  • OracleMiddlewarePriceRequestTooEarly()
  • OracleMiddlewareOracleMiddlewareWrongPriceTimestamp(uint64 min, uint64 max, uint64 result)
  • OracleMiddlewareUnsupportedAction(ProtocolAction action)
  • OracleMiddlewarePythValidationFailed()

v0.5.0

08 Feb 16:26
18a74cf
Compare
Choose a tag to compare

0.5.0 (2024-02-08)

⚠ BREAKING CHANGES

  • long: the input desired liquidation price to initiateOpenPosition is now considered to already include the liquidation penalty.
  • pending: the queue PendingActions now store Validate... protocol actions
  • long: initiateClosePosition removes the position from the tick/protocol (#70)
  • liquidation-core: fix two calculation bugs with liquidation tick selection and sign of fundingAsset (#72)
  • interfaces: some public functions are now private
  • middleware: oracle middleware minor changes (#66)
  • UsdnProtocolLong: add liquidation price in LiquidatedTick event (#65)

Features

  • interfaces: create and refactor interfaces (#64) (e6dbad5)
  • middleware: mock oracle middleware for fork environment (#78) (97bc06d)
  • new funding calculation (#73) (740f4a2)
  • storage: add two functions to fetch internal variables (#75) (b81a6cb)
  • UsdnProtocolLong: add liquidation price in LiquidatedTick event (#65) (32a6301)

Bug Fixes

  • liquidation-core: fix two calculation bugs with liquidation tick selection and sign of fundingAsset (#72) (df335ae)
  • long: desired liq price now includes liquidation penalty (#80) (f842ca7)
  • pending: remove pending action from third party user when it gets validated (#81) (da0350b)
  • pending: store Validate... protocol actions in pending actions (#79) (79bfe56)
  • pending: user validating their own action while it's actionable by anyone (#77) (df5b8c2)

Code Refactoring

  • long: initiateClosePosition removes the position from the tick/protocol (#70) (a3f87c6)
  • middleware: oracle middleware minor changes (#66) (ff39bb3)

Details

Deployment

  • Docs are in the npm package
  • add a mock price oracle

Data structure

  • struct PendingAction doesn't change but is the generic type for new structs (Vault|Long)PendingAction, each of them have different use of data :
    • struct VaultPendingAction { ProtocolAction action; uint40 timestamp; address user; int24 _unused; uint128 amount; uint128 assetPrice; uint256 totalExpo; uint256 balanceVault; uint256 balanceLong; uint256 usdnTotalSupply; }
    • struct LongPendingAction { ProtocolAction action; uint40 timestamp; address user; int24 tick; uint128 closeAmount; uint128 closeLeverage; uint256 tickVersion; uint256 index; uint256 closeLiqMultiplier; uint256 closeTempTransfer; }

Functions

Update
  • ChainLink oracle : _priceFeed() -> priceFeed()
  • Pyth oracle :
    • _pyth() -> pyth
    • _priceID() -> priceID()
New
  • OracleMiddleware :
    • updateValidationDelay(uint256 _newValidationDelay) onlyOwner
  • Long :
    • getPositionValue(int24 tick, uint256 tickVersion, uint256 index, uint128 currentPrice)
  • Storage :
    • minLeverage()
    • maxLeverage()
    • liquidationMultiplier()
Remove
  • updateBalances(bytes calldata priceData)
  • findMaxInitializedTick(int24 searchStart)

Event

Update
  • LiquidatedTick(int24 indexed tick, uint256 indexed oldTickVersion) -> LiquidatedTick(int24 indexed tick, uint256 indexed oldTickVersion, uint256 liquidationPrice, uint256 effectiveTickPrice)
New
  • LiquidatedPosition( address indexed user, int24 tick, uint256 tickVersion, uint256 index, uint256 liquidationPrice, uint256 effectiveTickPrice )

Errors

New
  • UsdnProtocolInvalidAssetDecimals(uint8 assetDecimals)
Update
  • PythValidationFailed() -> OracleMiddlewarePythValidationFailed()
  • WrongPrice(int256 price) -> OracleMiddlewareWrongPrice(int256 price)
  • PriceTooOld(int256 price, uint256 timestamp) -> OracleMiddlewarePriceTooOld(int256 price, uint256 timestamp)
  • OracleMiddlewareWrongPriceTimestamp(uint64 min, uint64 max, uint64 result) -> OracleMiddlewareOracleMiddlewareWrongPriceTimestamp(uint64 min, uint64 max, uint64 result)

v0.4.0

01 Feb 17:00
3be50b1
Compare
Choose a tag to compare

0.4.0 (2024-02-01)

⚠ BREAKING CHANGES

  • middleware: wsteth oracle (#62)
  • core: make getActionablePendingAction a view function (#61)
  • long: events related to long positions now emit the tick version, many functions require tick, tick version and index to identify a position

Features

Code Refactoring

  • core: make getActionablePendingAction a view function (#61) (146adf8)
  • long: add tick version as part of unique position identifier (#57) (308a31e)

Details

Deployment

  • PYTH_WSTETH_PRICE_ID variable replaced by PYTH_STETH_PRICE_ID
  • add deploy shell script

Data structure

  • In PendingAction struct : totalExpo is now totalExpoOrTickVersion (totalExpo is used for deposit/withdraw and tickVersion for open/close)

Oracles

  • Chainlink will retrieve the stETH price and transform it in wstETH
  • Pyth price need to be in stETH and will be transformed onchain into wstETH

Functions

Update
  • function initiateClosePosition(int24 tick, uint256 index, bytes calldata currentPriceData, bytes calldata previousActionPriceData) -> function initiateClosePosition(int24 tick, uint256 tickVersion, uint256 index, bytes calldata currentPriceData, bytes calldata previousActionPriceData)
  • function getLongPosition(int24 tick, uint256 index) -> function getLongPosition(int24 tick, uint256 tickVersion, uint256 index)
New
  • function getActionablePendingAction(uint256 maxIter) : Retrieve a pending action that must be validated by the next user action in the protocol

Event

Update
  • event InitiatedOpenPosition(address indexed user, Position position, int24 tick, uint256 index); -> event InitiatedOpenPosition(address indexed user, Position position, int24 tick, uint256 tickVersion, uint256 index);
  • event ValidatedOpenPosition(address indexed user, Position position, int24 tick, uint256 index, uint128 liquidationPrice); -> event ValidatedOpenPosition(address indexed user, Position position, int24 tick, uint256 tickVersion, uint256 index, uint128 liquidationPrice);
  • event LiquidationPriceChanged(int24 indexed oldTick, uint256 indexed oldIndex, int24 newTick, uint256 newIndex); -> event LiquidationPriceChanged(int24 indexed oldTick, uint256 indexed oldTickVersion, uint256 indexed oldIndex, int24 newTick, uint256 newTickVersion, uint256 newIndex);
  • event InitiatedClosePosition(address indexed user, int24 tick, uint256 index); -> event InitiatedClosePosition(address indexed user, int24 tick, uint256 tickVersion, uint256 index);
  • event ValidatedClosePosition(address indexed user, int24 tick, uint256 index, uint256 amountReceived, int256 profit); -> event ValidatedClosePosition(address indexed user, int24 tick, uint256 tickVersion, uint256 index, uint256 amountReceived, int256 profit);
New
  • event LiquidatedTick(int24 indexed tick, uint256 indexed oldTickVersion);
  • event StalePendingActionRemoved(address indexed user, int24 tick, uint256 tickVersion, uint256 index);

Errors

New

error UsdnProtocolOutdatedTick(uint256 currentVersion, uint256 providedVersion);
Indicates that the provided tick version is outdated (transactions have been liquidated)