Releases: SmarDex-Ecosystem/usdn-contracts
Releases · SmarDex-Ecosystem/usdn-contracts
v0.19.1
v0.19.0
0.19.0 (2024-09-24)
⚠ BREAKING CHANGES
- liquidate: the iterations parameter of the liquidate function has been removed
- add
deadlinevariable ininitiateOpenPosition,initiateClosePosition,initiateDeposit, andinitiateWithdrawalfunctions. Also, I have added It inside the Rebalancer oninitiateClosePositionfunction IBaseLiquidationRewardsManager.getLiquidationRewardsnow expects an array of liquidated ticks info and the current asset price for the first two parameters.ILiquidationRewardsManagerhas more parameters insetRewardsParametersand the associatedRewardsParametersUpdatedevent.IUsdnProtocolActions.liquidatenow returns an array ofLiqTickInfo. TheLiquidationsEffectsstruct has a new typeLiqTickInfo[]for theliquidatedTicksmember.- initialize: MIN_INIT_DEPOSIT() is not available anymore
- The external function vaultTradingExpoWithFunding has been removed
- remove
permit2TokenBitfieldvariable ininitiateOpenPositionandinitiateDepositfunctions. initiateDeposithas a new argument namedamountMinOutandinitiateWithdrawalhas a new argument namedamountMinOut. 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
validateActionablePendingActionsgas usage (#574) (12baa7a) - reduce protocol size (#600) (83515b5)
Code Refactoring
v0.18.0
0.18.0 (2024-09-12)
⚠ BREAKING CHANGES
- vault: the
InitiatedDepositandInitiatedWithdrawalevents have an additionalfeeBpsfield. TheValidatedDepositevent now shows the deposit amount after fees. TheValidatedWithdrawalevent now shows the withdrawn amount after fees.IUsdnProtocolFallback.previewWithdrawtakes the price as auint128for consistency withpreviewDeposit.DepositPendingActionandWithdrawalPendingActionstructs now use the third member to store thefeeBps IBaseOracleMiddlewarenow exposesgetLowLatencyDelay. TheValidationDeadlineUpdatedevent was renamed toValidationDeadlinesUpdatedand has two parameters. TheIUsdnProtocol.getValidationDeadlinefunction was renamed togetLowLatencyValidationDeadlineand a new functiongetOnChainValidationDeadlinewas added.- long: the
IUsdnProtocolTypes.PendingActionstruct (and associated action-specific structs) has an additionaluint24field. - open:
maxTickwas removed, thecloseLiqMultipliermember ofLongPendingActionwas renamed toliqMultiplier. - vault: the
UsdnProtocolInvalidVaultExpoerror was renamed toUsdnProtocolEmptyVault. - 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
LiquidationPenaltyUpdatedevent, functionsgetLiquidationPenalty,setLiquidationPenalty,getLongPosition,getTickLiquidationPenalty, and theTickDatstruct - 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
getTickAtPriceinstead ofgetClosestTickAtPrice(#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
initiateClosePositionto 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:
_calcMintUsdnSharesnow 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 ...
v0.17.2
v0.17.1
v0.17.0
0.17.0 (2024-08-07)
⚠ BREAKING CHANGES
- middleware:
IOracleMiddlewaredoes not have the functionsgetPenaltyBps,setRedstoneRecentPriceDelay,setPenaltyBpsanymore. - uups proxy (#475)
- The
getMinLiquidationpricefunction has been removed - core:
IUsdnProtocolCore.fundingreturns an additional parameterfundingPerDay_.IUsdnProtocolCore.calcEMAnow expects the last funding rate (per day) as first argument instead of the last funding value.IUsdnProtocolStorage.getLastFundingwas renamed togetLastFundingPerDayand now returns the last funding rate.IUsdnProtocolTypes.Storagehas a_lastFundingPerDayfield that replaces_lastFunding. - Remove the error
UsdnProtocolAmountToCloseIsZeroto useUsdnProtocolZeroAmountinstead ininitiateClosePosition - rebalancer: the
IRebalancer.initiateClosePositionfunction does not have avalidatorparameter anymore
Features
- add constants (#469) (74f36cb)
- emit an event when the highest populated tick is updated (#407) (a8a5383)
- event when funding rate updated (#470) (8d06050)
- fee collector callback when the treshold is reached (#402) (edba31d)
- refactor protocol (#468) (29ad6b5)
- remove the getMinLiquidationPrice function (c52bdfb)
- replace ownable by access control (#420) (4064e29)
- uups proxy (#475) (f920d30)
- validation step for deployment (#488) (e1f773f)
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
_checkPendingFeeand 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
v0.16.0
0.16.0 (2024-06-21)
⚠ BREAKING CHANGES
- rebalancer: withdrawal in two steps (#361)
- rebalancer:
depositAssetsbecomesinitiateDepositAssetsand must be followed byvalidateDepositAssetsafter a mandatory delay, rebalancer events have changed - Usage of Ownable2Step instead of Ownable (#329)
- remove router (#340)
- rename package (#335)
- actions: a new parameter
permit2TokenBitfieldof typePermit2TokenBitfield.Bitfield(an alias foruint8) was added toinitiateDepositandinitiateOpenPositionto 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.setRecentPriceDelayrenamed to becomeIOracleMiddleware.setPythRecentPriceDelay,IPythOracle.getRecentPriceDelayrenamed to becomeIPythOracle.getPythRecentPriceDelay,IOracleMiddlewareEvents.RecentPriceDelayUpdatedrenamed to becomeIOracleMiddlewareEvents.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
- actions: imbalance check on close (#342) (45f76a3)
- convert all absolute imports to relative (#363) (7d5f7d1)
- middleware interface (#341) (b597e48)
- slither errors (#321) (80f6793)
- use
_lastPricefor USDN rebase (#347) (2e80cf8)
Performance Improvements
- constants in a new lib (#364) (c97a739)
- hugeuint: use solady implementation for clz (#327) (3e4c763)
- refacto PositionData (#362) (91fd3cc)
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
permit2TokenBitfieldforinitiateDepositandinitiateOpenPosition. This will indicate whether permit2 should be used for the asset token and sdex - Add Redston...
v0.15.0
0.15.0 (2024-06-06)
⚠ BREAKING CHANGES
- actions:
initiateClosePositionhas a newvalidatorargument,validateClosePositionnow expects the validator as first argument, theInitiatedClosePositionevent has an additionalvalidatorparameter, theValidatedClosePositionevent now reports the validator address instead of the owner. - actions: the
initiateOpenPositionaction now returns a boolean as first argument on top of the position ID - middleware: the
IBaseOracleMiddleware.parseAndValidatePricefunction has an additionalbytes32parameter for the unique action identifier - rewards: the
getLiquidationRewardsfunction has an additional parameter for the protocol action enum - rebalancer:
setExpoImbalanceLimitshas a fifth argument callednewLongImbalanceTargetBps, and theImbalanceLimitsUpdatedevent has the same fifth argument. Also, the gettergetExpoImbalanceLimitshas been removed and split into 4 functions, one for each imbalance limit. - protocol:
_unadjustPriceand_adjustPriceare 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
v0.14.0
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.getLiquidationRewardsfunction has an additional argumentrebaseCallbackResultof typebytes. - middleware:
getConfRatiois now calledgetConfRatioBps.getMaxConfRatiohas been replaced byMAX_CONF_RATIO.getConfRatioDenomhas been replaced byBPS_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
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
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 p...