Skip to content

Releases: SmarDex-Ecosystem/usdn-contracts

v0.19.1

24 Sep 14:02
2f6ac03

Choose a tag to compare

0.19.1 (2024-09-24)

Bug Fixes

v0.19.0

24 Sep 13:10
98af962

Choose a tag to compare

0.19.0 (2024-09-24)

⚠ BREAKING CHANGES

  • liquidate: the iterations parameter of the liquidate function has been removed
  • add deadline variable in initiateOpenPosition, initiateClosePosition,initiateDeposit, and initiateWithdrawal functions. Also, I have added It inside the Rebalancer on initiateClosePosition function
  • IBaseLiquidationRewardsManager.getLiquidationRewards now expects an array of liquidated ticks info and the current asset price for the first two parameters. ILiquidationRewardsManager has more parameters in setRewardsParameters and the associated RewardsParametersUpdated event. IUsdnProtocolActions.liquidate now returns an array of LiqTickInfo. The LiquidationsEffects struct has a new type LiqTickInfo[] for the liquidatedTicks member.
  • initialize: MIN_INIT_DEPOSIT() is not available anymore
  • The external function vaultTradingExpoWithFunding has been removed
  • remove permit2TokenBitfield variable in initiateOpenPosition and initiateDeposit functions.
  • initiateDeposit has a new argument named amountMinOut and initiateWithdrawal has a new argument named amountMinOut. The user can set the minimum accepted stETh or USDN wants to be received
  • add min price on initiate close (#569)

Features

  • add deadline on each initiate actions (#588) (97f4d4b)
  • add max price on initiate open (#562) (2a8adb1)
  • add min max leverage on initialize position (#579) (853ef63)
  • add min price on initiate close (#569) (c977bae)
  • add slippage vault side (#581) (4da907d)
  • add stETH and wstETH mock contracts (#570) (71e21f5)
  • callback on initiates and remove permit2 (#582) (47e5701)
  • fix struct (#589) (0461194)
  • implementation initialization (#593) (433f1f1)
  • initialize: add checks on amounts to make sure positions can be opened (#584) (f8469a6)
  • liquidate: removes the iterations parameter for the external function (#586) (51d1a5b)
  • withdraw: add callback for router to transfer shares (#592) (03ec9f9)

Bug Fixes

  • enforce CEI pattern in validate actions (#598) (41ed217)
  • middleware: fix flaky tests (#591) (68ff15e)
  • slither: ignore slither arbitrary-send-eth error in permissioned function (#590) (46ce477)
  • the trading expo cannot become negative anymore (#573) (a0e9cbc)
  • usdn: rounding edge case (#597) (ef17cb8)

Performance Improvements

  • delete ActionsVault lib and change functions visibility (#577) (611d162)
  • reduce validateActionablePendingActions gas usage (#574) (12baa7a)
  • reduce protocol size (#600) (83515b5)

Code Refactoring

v0.18.0

12 Sep 16:06
84d1465

Choose a tag to compare

0.18.0 (2024-09-12)

⚠ BREAKING CHANGES

  • vault: the InitiatedDeposit and InitiatedWithdrawal events have an additional feeBps field. The ValidatedDeposit event now shows the deposit amount after fees. The ValidatedWithdrawal event now shows the withdrawn amount after fees. IUsdnProtocolFallback.previewWithdraw takes the price as a uint128 for consistency with previewDeposit. DepositPendingAction and WithdrawalPendingAction structs now use the third member to store the feeBps
  • IBaseOracleMiddleware now exposes getLowLatencyDelay. The ValidationDeadlineUpdated event was renamed to ValidationDeadlinesUpdated and has two parameters. The IUsdnProtocol.getValidationDeadline function was renamed to getLowLatencyValidationDeadline and a new function getOnChainValidationDeadline was added.
  • long: the IUsdnProtocolTypes.PendingAction struct (and associated action-specific structs) has an additional uint24 field.
  • open: maxTick was removed, the closeLiqMultiplier member of LongPendingAction was renamed to liqMultiplier.
  • vault: the UsdnProtocolInvalidVaultExpo error was renamed to UsdnProtocolEmptyVault.
  • rebalancer: Everything regarding the imbalance has been removed from the rebalancer contract (event and functions)
  • the liquidation penalty is now expressed in ticks and is stored as a uint24. This affects the LiquidationPenaltyUpdated event, functions getLiquidationPenalty, setLiquidationPenalty, getLongPosition, getTickLiquidationPenalty, and the TickDat struct
  • protocol: The setExpoImbalanceLimits now takes an additional parameter, as well as the ImbalanceLimitsUpdated event, both representing the closeLimitBps of the rebalancer position

Features

  • add fees on imbalance calculation during the initialization of position closure (#560) (2e8555a)
  • add max leverage on init open (#559) (aa4e4ce)
  • add pausable mechanism to the protocol (#514) (3dcd974)
  • add roles on middleware (#527) (cb62662)
  • change coverage command (#526) (0a368b1)
  • more granularity for liquidation penalty (#516) (5957adf)
  • new validation flow (#544) (5348772)
  • only owner initialize (#525) (521cd94)
  • oracle: let the middleware return the chainlink price if Pyth reverts for initiate actions (#515) (0647f45)
  • protocol: add an imbalance setting for the rebalancer and the check for the close action (#503) (e380a1b)
  • rebalancer: adjust default max leverage (#566) (2ddf1a0)
  • refund security deposit for stale pending actions (#538) (bb2c808)
  • script: add a script to upgrade the proxy of the USDN protocol (#539) (25e9202)
  • simplify _update (#550) (46cabba)
  • use getTickAtPrice instead of getClosestTickAtPrice (#547) (f65acc3)

Bug Fixes

  • chainlink: fix the previous round ID checks too allow the first ID of a phase to be used (#548) (0d24fb4)
  • consistency on imbalance checks (#558) (70047da)
  • core: handle excess assets in _removeBlockedPendingAction (#528) (38e90f8)
  • events: removed the indexation of structs in protocol events (#555) (72e04b2)
  • long: add funding on trading expo when opening a position (#552) (cbad22e)
  • long: store and use liquidation penalty for position closing (#549) (79c617b)
  • open: apply funding to positions that change tick (#530) (052fd28)
  • rebalancer-trigger: only gift the previous position value when dealing with dust (#536) (89bfea7)
  • rebalancer: add a check in initiateClosePosition to revert if the user was liquidated (#534) (570b65f)
  • rebalancer: remove the imbalance setting as it is now part of the USDN protocol (#529) (3196f32)
  • rewards only when rebalancer is triggered (#561) (905f168)
  • round up sdex fee (#551) (052afbd)
  • stale to validator at initiate (#565) (ac8fd0f)
  • vault: _calcMintUsdnShares now reverts if the vault balance is zero (#533) (3ed4dc4)
  • vault: apply fees on amounts and not price + ignore funding before initiate + include fee in imbalance calc (#557) (088eb03)
  • withdrawal and deposit underflow (#532) (8b41653)

Performance Improvements

Details

  • Pausable
  • Use Chainlink automatically if Pyth revert
  • Only owner can initialize the protocol
  • Users in rebalancer have more strict imbalance requirement to exit the rebalancer
  • New role in middleware to pause the oracle
  • Upgrade script
  • Store liquidation ...
Read more

v0.17.2

15 Aug 15:34
6df17ca

Choose a tag to compare

0.17.2 (2024-08-15)

Features

Bug Fixes

v0.17.1

08 Aug 07:41
86a1012

Choose a tag to compare

0.17.1 (2024-08-08)

Bug Fixes

v0.17.0

07 Aug 15:04
b1fbb75

Choose a tag to compare

0.17.0 (2024-08-07)

⚠ BREAKING CHANGES

  • middleware: IOracleMiddleware does not have the functions getPenaltyBps, setRedstoneRecentPriceDelay, setPenaltyBps anymore.
  • uups proxy (#475)
  • The getMinLiquidationprice function has been removed
  • core: IUsdnProtocolCore.funding returns an additional parameter fundingPerDay_. IUsdnProtocolCore.calcEMA now expects the last funding rate (per day) as first argument instead of the last funding value. IUsdnProtocolStorage.getLastFunding was renamed to getLastFundingPerDay and now returns the last funding rate. IUsdnProtocolTypes.Storage has a _lastFundingPerDay field that replaces _lastFunding.
  • Remove the error UsdnProtocolAmountToCloseIsZero to use UsdnProtocolZeroAmount instead in initiateClosePosition
  • rebalancer: the IRebalancer.initiateClosePosition function does not have a validator parameter anymore

Features

Bug Fixes

  • add redstone feed id in env.example (#394) (0189e72)
  • avoid empty rebalancer update (#465) (6a52466)
  • core: always update the EMA with the funding rate (per day) and adjust funding calculations to reflect this change (#428) (df50aa1)
  • core: calcEMA formula (#390) (9d4a828)
  • deploy: set block time and --slow when using the deploy script (#417) (d58957d)
  • gas-usage: fix the gas usage tests (#375) (a737d1e)
  • ignore gas test in CI (#434) (52cff74)
  • mock: set the timestamp at block.timestamp in the wsteth mock oracle middleware (#495) (555b051)
  • open: reflect the position fees immediately on the balances (#452) (9bb1d75)
  • package.json script and unused file (#449) (bfca9c4)
  • rebalancer: disallow choosing the validator address on closing (#397) (d4e0f9e)
  • remove unused enum (#455) (6993021)
  • trigger-rebalancer: fix the previous position value counted twice in balanceLong (#384) (401c33c)
  • use adminPrank modifier when possible (#408) (4e6f565)

Performance Improvements

  • avoid using a delegatecall for casting (#381) (d1b1416)
  • cache "immutable" storage accesses (#388) (c30cc0a)
  • optimize _checkPendingFee and add tests (#387) (538b6fe)
  • rebalancer: avoid loading from storage more than once (#393) (a59c0d9)
  • regroup functions related to removeBlockedPendingAction (#380) (9db577a)
  • return lastPrice_ in _applyPnlAndFunding (#400) (7fb6efa)

Code Refactoring

  • middleware: move Redstone logic to a separate middleware (#476) (a7c02c8)
  • remove an error for the zero amount check in initiateClosePosition to use an existing one (#404) (4374a03)

v0.16.0

21 Jun 16:13
ff2b96f

Choose a tag to compare

0.16.0 (2024-06-21)

⚠ BREAKING CHANGES

  • rebalancer: withdrawal in two steps (#361)
  • rebalancer: depositAssets becomes initiateDepositAssets and must be followed by validateDepositAssets after a mandatory delay, rebalancer events have changed
  • Usage of Ownable2Step instead of Ownable (#329)
  • remove router (#340)
  • rename package (#335)
  • actions: a new parameter permit2TokenBitfield of type Permit2TokenBitfield.Bitfield (an alias for uint8) was added to initiateDeposit and initiateOpenPosition to indicate whether permit2 should be used for the asset token and sdex.
  • middleware: the constructor for the oracle middleware takes an additional parameter for the redstone feed ID, IOracleMiddleware.setRecentPriceDelay renamed to become IOracleMiddleware.setPythRecentPriceDelay, IPythOracle.getRecentPriceDelay renamed to become IPythOracle.getPythRecentPriceDelay, IOracleMiddlewareEvents.RecentPriceDelayUpdated renamed to become IOracleMiddlewareEvents.PythRecentPriceDelayUpdated

Features

  • actions: add native support for permit2 transfers (#318) (ff4d88a)
  • change in external (#326) (d606d6c)
  • limits: changed initial limits for opening position and depositing in vault (#311) (89bb976)
  • liquidation-rewards-manager: add the setting for the rebalancer trigger's gas used (#356) (e1b720b)
  • middleware: add sanity check on Pyth price timestamp (#365) (da5c5dc)
  • middleware: add support for redstone oracle (#304) (7b851e0)
  • new initial values (#316) (c820f45)
  • preview deposit (#339) (c522ef8)
  • rebalancer: add a case to deal with dust in the position (#367) (073446e)
  • rebalancer: add the rebalancer gas usage to the liquidation rewards calculations (#372) (045a5e0)
  • rebalancer: add the reentrancy guard to the rebalancer's initiateClosePosition function (#358) (901f72e)
  • rebalancer: add the trigger of the rebalancer when the imbalance is too high (#289) (1593e34)
  • rebalancer: close imbalance limit bps (#325) (da690f6)
  • rebalancer: deposit in two steps (#353) (846f83d)
  • rebalancer: handle refunds (#359) (c07c257)
  • rebalancer: include close bonus (#360) (2829bdf)
  • rebalancer: no trigger condition on close limit (#344) (84bec22)
  • rebalancer: partial close (#343) (0695099)
  • rebalancer: support eip-165 and IOwnershipCallback (#313) (885cc11)
  • rebalancer: withdrawal in two steps (#361) (5609432)
  • relative imports in test folder (#336) (a030466)
  • router: validate open position (#306) (df22c84)
  • Usage of Ownable2Step instead of Ownable (#329) (bdc88e3)
  • usdn: wusdn tests and wrapShares (#346) (b561544)

Bug Fixes

Performance Improvements

Miscellaneous Chores

Code Refactoring

Details

  • Rebalancer - completed - deposit and withdraw in 2 steps, see a scheme here
  • Use Ownable2Step instead of Ownable
  • Router has been moved to another repo
  • Native support of permit2
  • New parameter permit2TokenBitfield for initiateDeposit and initiateOpenPosition. This will indicate whether permit2 should be used for the asset token and sdex
  • Add Redston...
Read more

v0.15.0

06 Jun 11:48
bce4408

Choose a tag to compare

0.15.0 (2024-06-06)

⚠ BREAKING CHANGES

  • actions: initiateClosePosition has a new validator argument, validateClosePosition now expects the validator as first argument, the InitiatedClosePosition event has an additional validator parameter, the ValidatedClosePosition event now reports the validator address instead of the owner.
  • actions: the initiateOpenPosition action now returns a boolean as first argument on top of the position ID
  • middleware: the IBaseOracleMiddleware.parseAndValidatePrice function has an additional bytes32 parameter for the unique action identifier
  • rewards: the getLiquidationRewards function has an additional parameter for the protocol action enum
  • rebalancer: setExpoImbalanceLimits has a fifth argument called newLongImbalanceTargetBps, and the ImbalanceLimitsUpdated event has the same fifth argument. Also, the getter getExpoImbalanceLimits has been removed and split into 4 functions, one for each imbalance limit.
  • protocol: _unadjustPrice and _adjustPrice are not public anymore

Features

  • actions: add validator argument to initiateClosePosition (#302) (ad88128)
  • actions: allow rebalancer user position close with full amount (#270) (4422071)
  • actions: block actions if there are pending liquidations (#227) (d10bb22)
  • actions: return success status in all external user actions (#281) (28120c3)
  • actions: transfer position ownership (#282) (9a0fee7)
  • admin: remove blocked pending action (#293) (c8d354b)
  • protocol: increase the default validation deadline (#286) (186a58b)
  • oracle: use the price feed for ETH/USD instead of stETH/USD (#298) (c4eab34)
  • middleware: allows to use chainlink to validate an action (#292) (8399439)
  • oracle: add penaltyBps (#291) (ddab421)
  • rebalancer: add a variable for the max leverage of the rebalancer (#267) (6784245)
  • rebalancer: add a variable to track which version got liquidated last (#266) (7f4c984)
  • rebalancer: add imbalance target setting (#263) (296b53b)
  • rebalancer: set allowance of the usdn protocol (#271) (b5b684b)
  • rewards: add protocol action to the rewards manager input (#274) (7a14bdf)
  • router: add commands for wsteth and steth (#277) (995d6b0)
  • router: add ethAmount in src and tests (#301) (95d5a02)
  • router: initiate deposit command (#278) (02ea2e4)
  • router: initiate open position (#296) (777cbbf)
  • router: initiate withdrawal (#285) (d4379ed)
  • router: refacto natspec (#300) (115ba2e)
  • router: retrieve success from external call (#294) (f965832)
  • router: universal router skeleton (#245) (844b4f7)
  • router: validate deposit (#297) (bb71753)
  • router: validate withdraw (#299) (ba2b8f0)
  • standardize and fix natspec erros (#303) (8b3f871)

Bug Fixes

  • actions: disallow closing a position that was not validated (#295) (ff8f8cb)
  • actions: take pending vault actions into account in imbalance checks (#287) (045c9b7)
  • init: add imbalance checks during initialization (#290) (5689657)

Code Refactoring

  • middleware: add unique action ID to middleware params (#284) (ceccd7a)

v0.14.0

17 May 14:51
b9098fa

Choose a tag to compare

0.14.0 (2024-05-17)

⚠ BREAKING CHANGES

  • actions: add to and validator in pending actions (#242)
  • rebalancer: adds the Rebalancer in the USDN protocol, deployment script etc. (#259)
  • usdn: The LiquidationRewardsManager.getLiquidationRewards function has an additional argument rebaseCallbackResult of type bytes.
  • middleware: getConfRatio is now called getConfRatioBps. getMaxConfRatio has been replaced by MAX_CONF_RATIO. getConfRatioDenom has been replaced by BPS_DIVISOR.
  • order-manager: everything related to the order manager has been removed

Features

  • actions: add to and validator in pending actions (#242) (5d134a8)
  • add separate fee parameter for vault actions (#244) (ccad861)
  • order-manager: adds the order manager and tests (#249) (1a59ba0)
  • order-manager: remove all the components of the order manager as well as the contract itself (#246) (fcaee82)
  • params: add new parameter for the rebalancer bonus (#260) (f775065)
  • rebalancer: adds the Rebalancer in the USDN protocol, deployment script etc. (#259) (924f73f)
  • set a minimum deposit for user in the rebalancer (#265) (f542684)
  • usdn: add rebase callback (#253) (0f75211)

Bug Fixes

  • usdn: decrease allowance even if token amount is zero (#248) (030d90f)

Code Refactoring

Details

  • add to and validator in pending actions
  • add the rebalancer in the USDN protocol. Previously named Order Manager.
  • add separate fee parameter for vault actions
  • add rebase callback for USDN
  • Fix : decrease allowance even if token amount is zero

Data Structure

Update
  • rename user into validator in PendingAction

Function

New

ChainLinkOracle

  • PRICE_TOO_OLD() returns (int256)

OracleMiddleware

  • BPS_DIVISOR()

UsdnProtocol

  • setVaultFeeBps(uint16 newVaultFee)
  • setRebalancerBonusBps(uint16 newBonus)

Usdn

  • rebaseCallback(uint256 oldDivisor, uint256 newDivisor)
  • convertToTokensRoundUp(uint256 amountShares)
  • setRebaseHandler(IRebaseCallback newHandler)
  • rebaseHandler()
Update

LiquidationReward

  • getLiquidationRewards(
    uint16 tickAmount,
    int256 remainingCollateral,
    bool rebased,
    bytes calldata priceData) -> getLiquidationRewards(
    uint16 tickAmount,
    int256 remainingCollateral,
    bool rebased,
    bytes calldata rebaseCallbackResult,
    bytes calldata priceData)

OracleMiddleware

  • getMaxConfRatio() -> MAX_CONF_RATIO()
  • getConfRatio() -> getConfRatioBps()

UsdnProtocol

  • setOrderManager(IOrderManager newOrderManager) -> setRebalancer(IRebalancer newRebalancer)
  • initiateDeposit(
    uint128 amount,
    address to,
    address validator,
    bytes calldata currentPriceData,
    PreviousActionsData calldata previousActionsData)
  • validateDeposit(
    address validator,
    bytes calldata depositPriceData,
    PreviousActionsData calldata previousActionsData)
  • initiateWithdrawal(
    uint152 usdnShares,
    address to,
    address validator,
    bytes calldata currentPriceData,
    PreviousActionsData calldata previousActionsData)
  • validateWithdrawal(
    address validator,
    bytes calldata withdrawalPriceData,
    PreviousActionsData calldata previousActionsData)
  • initiateOpenPosition(
    uint128 amount,
    uint128 desiredLiqPrice,
    address to,
    address validator,
    bytes calldata currentPriceData,
    PreviousActionsData calldata previousActionsData)
  • validateOpenPosition(
    address validator,
    bytes calldata openPriceData,
    PreviousActionsData calldata previousActionsData)
  • initiateClosePosition(
    PositionId calldata posId,
    uint128 amountToClose,
    address to,
    bytes calldata currentPriceData,
    PreviousActionsData calldata previousActionsData)
  • validateClosePosition(
    address owner,
    bytes calldata closePriceData,
    PreviousActionsData calldata previousActionsData)
Delete

OracleMiddleware

  • getConfRatioDenom()

Events

New

Usdn

  • RebaseHandlerUpdated(IRebaseCallback newHandler)

UsdnProtocol

  • VaultFeeUpdated(uint256 vaultFee)
  • RebalancerBonusUpdated(uint256 bonus)
Update

UsdnProtocol

  • InitiatedDeposit(address indexed to, address indexed validator, uint256 amount, uint256 timestamp)
  • ValidatedDeposit(
    address indexed to, address indexed validator, uint256 amountDeposited, uint256 usdnMinted, uint256 timestamp)
  • InitiatedWithdrawal(address indexed to, address indexed validator, uint256 usdnAmount, uint256 timestamp)
  • ValidatedWithdrawal(
    address indexed to, address indexed validator, uint256 amountWithdrawn, uint256 usdnBurned, uint256 timestamp)
  • InitiatedOpenPosition(
    address indexed owner,
    address indexed validator,
    uint40 timestamp,
    uint128 totalExpo,
    uint128 amount,
    uint128 startPrice,
    PositionId posId)
  • ValidatedOpenPosition(
    address indexed owner, address indexed validator, uint128 totalExpo, uint128 newStartPrice, PositionId posId)
  • InitiatedClosePosition(
    address indexed owner,
    address indexed to,
    PositionId posId,
    uint128 originalAmount,
    uint128 amountToClose,
    uint128 totalExpoRemaining)
  • ValidatedClosePosition(
    address indexed owner, address indexed to, PositionId posId, uint256 amountReceived, int256 profit)
  • StalePendingActionRemoved(address indexed validator, PositionId posId)
  • OrderManagerUpdated(address newAddress) -> RebalancerUpdated(address newAddress)
  • SecurityDepositRefunded(address indexed pendingActionValidator, address indexed receivedBy, uint256 amount)
  • getOrderManager() -> getRebalancer()
  • getVaultFeeBps()
  • getRebalancerBonusBps()

Errors

New

UsdnProtocol

  • UsdnProtocolInvalidAddressValidator()
  • UsdnProtocolInvalidVaultFee()
  • UsdnProtocolInvalidRebalancerBonus()

Usdn

  • UsdnInvalidDivisor()

v0.13.0

03 May 14:12
f1b2e82

Choose a tag to compare

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 PositionId wherever 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 getMinLongPosition function 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 previewWithdraw function (#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 _maxInitializedTick into _highestPopulatedTick (#203) (a418d5c)
  • types: removed common struct in all pending actions structs (#237) (78b2175)
  • use PositionId wherever 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 p...
Read more