Skip to content

Added perp redemption to vault recovery flow#159

Merged
aalavandhan merged 3 commits intodevfrom
vault-perp-redeem
Aug 15, 2023
Merged

Added perp redemption to vault recovery flow#159
aalavandhan merged 3 commits intodevfrom
vault-perp-redeem

Conversation

@aalavandhan
Copy link
Copy Markdown
Member

@aalavandhan aalavandhan commented May 17, 2023

  • As part of the batch recovery, we first redeem the earned perp tokens for the underlying tranches and then continue with the existing flow.
  • Updated perp methods "deposit", "redeem" and "rollover" to return data about the operation.

@aalavandhan aalavandhan requested review from brandoniles and nms-7 May 17, 2023 16:48
@aalavandhan aalavandhan changed the base branch from main to dev May 17, 2023 16:49
// Redeem perp for tranches
uint256 perpBalance = perp.balanceOf(address(this));
if (perpBalance > 0) {
(IERC20Upgradeable[] memory tranchesRedeemed, ) = perp.computeRedemptionAmts(perpBalance);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through the lens of efficiency...

  • We don't really care about computing the redemption amounts. We really only care about getting the list of reserve assets.
  • Both computeRedemptionAmts and redeem call updateState() on perp, even though we only need to do it once.

I wonder, would it be better if redeem() just returned the assets itself? Seems like it would be useful for clients, as this one shows. Then we could make just the one call.

We also may end up syncing a particular tranche more than once, if there are any in common between the perp redeem and the deployed set. The multiple syncs would probably require building up a list of assets to sync then doing them at the end, but I'm not sure the gas savings would pencil out

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed we can just make all 3 functions, ie) deposit, redeem and rollover return the full data.

external
returns (IERC20Upgradeable[] memory tokensOut, uint256[] memory tokenOutAmts);

struct RolloverPreview {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but wonder if this should be renamed since it's also a rollover return data payload.
If we do, maybe save it for just a rename PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename it to RolloverData

Copy link
Copy Markdown
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aalavandhan aalavandhan requested a review from ahnaguib August 8, 2023 18:00
@aalavandhan aalavandhan merged commit 31a2afc into dev Aug 15, 2023
@aalavandhan aalavandhan deleted the vault-perp-redeem branch August 15, 2023 17:50
aalavandhan added a commit that referenced this pull request Aug 15, 2023
* added perp redemption to vault recovery flow

* perp external functions returning ops data

* added natspec comments and renamed rollover preview struct
aalavandhan added a commit that referenced this pull request Feb 5, 2024
* added perp redemption to vault recovery flow

* perp external functions returning ops data

* added natspec comments and renamed rollover preview struct
aalavandhan added a commit that referenced this pull request Apr 16, 2024
* added perp redemption to vault recovery flow

* perp external functions returning ops data

* added natspec comments and renamed rollover preview struct
aalavandhan added a commit that referenced this pull request Apr 16, 2024
* Added perp redemption to vault recovery flow (#159)

* added perp redemption to vault recovery flow

* perp external functions returning ops data

* added natspec comments and renamed rollover preview struct

* refactors bond and tranche helpers, added a new method to compute proportional tranche balances

Signed-off-by: aalavandhann <[email protected]>

* meld method on rollover vault

Signed-off-by: aalavandhann <[email protected]>

* added todos

Signed-off-by: aalavandhann <[email protected]>

* Apply suggestions from code review

Co-authored-by: Brandon Iles <[email protected]>
Signed-off-by: aalavandhann <[email protected]>

* removed duplicate implementation

Signed-off-by: aalavandhann <[email protected]>

* unit tests for meld

Signed-off-by: aalavandhann <[email protected]>

* moved unused contracts to  folder

Signed-off-by: aalavandhann <[email protected]>

* imported sigmoid utility

Signed-off-by: aalavandhann <[email protected]>

* Fee strategy 2.0

Signed-off-by: aalavandhann <[email protected]>

* perp changes for fee strategy 2.0

Signed-off-by: aalavandhann <[email protected]>

* updated unit tests with the new fee scheme

Signed-off-by: aalavandhann <[email protected]>

* Apply suggestions from code review

Co-authored-by: Brandon Iles <[email protected]>
Co-authored-by: nms-7 <[email protected]>
Signed-off-by: aalavandhann <[email protected]>

* updated fee strategy

Signed-off-by: aalavandhann <[email protected]>

* using a normalized factor to compute sigmoid, rather than using a different target

Signed-off-by: aalavandhann <[email protected]>

* Update spot-contracts/contracts/strategies/FeeStrategy.sol

Signed-off-by: aalavandhann <[email protected]>

* using explicit cast instead of abs

Signed-off-by: aalavandhann <[email protected]>

* removed holding pen and discount math from perp

Signed-off-by: aalavandhann <[email protected]>

* perp cleanups, removed unused revert paramters

Signed-off-by: aalavandhann <[email protected]>

* updated peripheral contracts with the new fee mechanism and rollover scheme

Signed-off-by: aalavandhann <[email protected]>

* updated fee strategy to compute tranche ratios based on senior most tranche, rather than using discount adjusted ratios

Signed-off-by: aalavandhann <[email protected]>

* updated unit test suite

Signed-off-by: aalavandhann <[email protected]>

* removed deprecated fee strategy interface functions

Signed-off-by: aalavandhann <[email protected]>

* deleted deprecated contracts

Signed-off-by: aalavandhann <[email protected]>

* Apply suggestions from code review

Co-authored-by: Brandon Iles <[email protected]>
Signed-off-by: aalavandhann <[email protected]>

* updated rollover math condition

Signed-off-by: aalavandhann <[email protected]>

* removed dirty diff from rebase

Signed-off-by: aalavandhann <[email protected]>

* deleted unused contracts

Signed-off-by: aalavandhann <[email protected]>

* updated sigmoid utility, imported two pow code

Signed-off-by: aalavandhann <[email protected]>

* replaced == 0 conditions with <= 0

Signed-off-by: aalavandhann <[email protected]>

* reverted exp val snapping

Signed-off-by: aalavandhann <[email protected]>

* imported two pow tests

Signed-off-by: aalavandhann <[email protected]>

* handling zero vault deposit/redeem

Signed-off-by: aalavandhann <[email protected]>

* cleaned up error codes

Signed-off-by: aalavandhann <[email protected]>

* updated fee (monetary) policy for spot

Signed-off-by: aalavandhann <[email protected]>

* updated bond issuer

Signed-off-by: aalavandhann <[email protected]>

* updated perp

Signed-off-by: aalavandhann <[email protected]>

* removed meld from rollover vault

Signed-off-by: aalavandhann <[email protected]>

* vault code cleanup and private fn refactor

Signed-off-by: aalavandhann <[email protected]>

* vault v2 storage update, mint redeem and deployment fees

Signed-off-by: aalavandhann <[email protected]>

* moved rollover vault to parent dir

Signed-off-by: aalavandhann <[email protected]>

* Apply suggestions from code review

Co-authored-by: Brandon Iles <[email protected]>
Signed-off-by: aalavandhann <[email protected]>

* fee policy terminology updates and review fixes

Signed-off-by: aalavandhann <[email protected]>

* review pass, removed annualized rollover fees, comment and naming updates

Signed-off-by: aalavandhann <[email protected]>

* code review updates

Signed-off-by: aalavandhann <[email protected]>

* vault allows 2-way swap between perps and underlying

Signed-off-by: aalavandhann <[email protected]>

* subscription aware fee policy for swapping, using minting bond as the source of truth for tranche ratios

Signed-off-by: aalavandhann <[email protected]>

* removed unused interface fn from bond issuer

Signed-off-by: aalavandhann <[email protected]>

* fee policy updates for perp, skipping fees when used by vault, reverting to only one authorized roller ie vault

Signed-off-by: aalavandhann <[email protected]>

* utility to calculate ampl required to create x perps

Signed-off-by: aalavandhann <[email protected]>

* error and comment cleanup

Signed-off-by: aalavandhann <[email protected]>

* updated swap fee logic

Signed-off-by: aalavandhann <[email protected]>

* code review fixes

Signed-off-by: aalavandhann <[email protected]>

* Apply suggestions from code review

Co-authored-by: Brandon Iles <[email protected]>
Signed-off-by: aalavandhann <[email protected]>

* code review fixes

Signed-off-by: aalavandhann <[email protected]>

* removed perp as a vault asset, and redeeming perps only on swaps

Signed-off-by: aalavandhann <[email protected]>

* simplified fee policy interface, accepts sr instead of computing it

Signed-off-by: aalavandhann <[email protected]>

* Perp removed external pricing strategy and optimized tranche value computation

Signed-off-by: aalavandhann <[email protected]>

* Vault clean up, function reorg and optimized tvl comp

Signed-off-by: aalavandhann <[email protected]>

* Assuming that incoming tranches withold no fees, thus removing all bw fee related math

Signed-off-by: aalavandhann <[email protected]>

* interface cleanup

Signed-off-by: aalavandhann <[email protected]>

* fee policy: code review fixes

Signed-off-by: aalavandhann <[email protected]>

* perp: code review fixes

Signed-off-by: aalavandhann <[email protected]>

* vault: code review fixes

Signed-off-by: aalavandhann <[email protected]>

* interface: code review fixes

Signed-off-by: aalavandhann <[email protected]>

* removed string require errors infavor of custom errors

Signed-off-by: aalavandhann <[email protected]>

* feePolicy: updated fee policy interface

Signed-off-by: aalavandhann <[email protected]>

* perp: new fee policy interface, view methods regorg, skipping update state when paused, optimized cdr

Signed-off-by: aalavandhann <[email protected]>

* vault: handling dust

Signed-off-by: aalavandhann <[email protected]>

* vault: new fee policy interface, variable caching and tvl optimization, recoverAndRedeem and view methods reorg

Signed-off-by: aalavandhann <[email protected]>

* unit tests

Signed-off-by: aalavandhann <[email protected]>

* fee policy: code review fix

Signed-off-by: aalavandhann <[email protected]>

* perp: code review fix

Signed-off-by: aalavandhann <[email protected]>

* fee policy: updated dr condition

Signed-off-by: aalavandhann <[email protected]>

* vault : code review fix

Signed-off-by: aalavandhann <[email protected]>

* code review fix: unit-tests, perp expects valid vault

Signed-off-by: aalavandhann <[email protected]>

* reorg return data

Signed-off-by: aalavandhann <[email protected]>

* redemption amt calc optimization, assuming bond has only 2 tranches

Signed-off-by: aalavandhann <[email protected]>

* code review fix for commit 1&2

Signed-off-by: aalavandhann <[email protected]>

* updated lisc

Signed-off-by: aalavandhann <[email protected]>

* Renamed fee variable

Signed-off-by: aalavandhann <[email protected]>

* moved keeper only methods to its own section

Signed-off-by: aalavandhann <[email protected]>

* moved rollover vault

Signed-off-by: aalavandhann <[email protected]>

* ran linter

Signed-off-by: aalavandhann <[email protected]>

* bumped up solidity version to 0.8.20

Signed-off-by: aalavandhann <[email protected]>

* updated hyper-param methods, removed logs & zero checks

Signed-off-by: aalavandhann <[email protected]>

* comment fix

Signed-off-by: aalavandhann <[email protected]>

* nonReentrant updateState

Signed-off-by: aalavandhann <[email protected]>

* set keeper in init method

Signed-off-by: aalavandhann <[email protected]>

* comment update

Signed-off-by: aalavandhann <[email protected]>

* made transfer fn nonReentrant

Signed-off-by: aalavandhann <[email protected]>

* returning instead of reverting in deposit,redeem and rollover

Signed-off-by: aalavandhann <[email protected]>

* moved value fn into perp

Signed-off-by: aalavandhann <[email protected]>

* removed perp supply zero check on burn computation

Signed-off-by: aalavandhann <[email protected]>

* Removed reserve count method

Signed-off-by: aalavandhann <[email protected]>

* removed multiple reads

Signed-off-by: aalavandhann <[email protected]>

* refactored rollover condition

Signed-off-by: aalavandhann <[email protected]>

* removed paramter from rollover amt

Signed-off-by: aalavandhann <[email protected]>

* removed one time use variable

Signed-off-by: aalavandhann <[email protected]>

* removed zero price check

Signed-off-by: aalavandhann <[email protected]>

* added comment

Signed-off-by: aalavandhann <[email protected]>

* removed zero check

Signed-off-by: aalavandhann <[email protected]>

* added else if

Signed-off-by: aalavandhann <[email protected]>

* flipped rollover condition

Signed-off-by: aalavandhann <[email protected]>

* moved perp supply call into compute redemption amt method

Signed-off-by: aalavandhann <[email protected]>

* Renamed fee policy variable

Signed-off-by: aalavandhann <[email protected]>

* added fee initiailzier

Signed-off-by: aalavandhann <[email protected]>

* router preview deposit update return struct

Signed-off-by: aalavandhann <[email protected]>

* removed approve 0

Signed-off-by: aalavandhann <[email protected]>

* added back perp rollover zero price check for safety

Signed-off-by: aalavandhann <[email protected]>

* router assumming bond has only 2 tranches

Signed-off-by: aalavandhann <[email protected]>

* fee policy update, dr bounds

Signed-off-by: aalavandhann <[email protected]>

* moved rollover vault

Signed-off-by: aalavandhann <[email protected]>

* vault init cleanup

Signed-off-by: aalavandhann <[email protected]>

* minUnderlyingBal check

Signed-off-by: aalavandhann <[email protected]>

* removed address(0) check in updateFeePolicy

Signed-off-by: aalavandhann <[email protected]>

* non-reentrant transferERC20

Signed-off-by: aalavandhann <[email protected]>

* removed virtual updateKeeper

Signed-off-by: aalavandhann <[email protected]>

* removed deployedAmt from deploy

Signed-off-by: aalavandhann <[email protected]>

* rollover typo fix

Signed-off-by: aalavandhann <[email protected]>

* vault sync refactor

Signed-off-by: aalavandhann <[email protected]>

* rollover gas optimizaiton, removed storage read for

Signed-off-by: aalavandhann <[email protected]>

* rollover performs tranche cleanup

Signed-off-by: aalavandhann <[email protected]>

* made MAX_DEPLOYED_COUNT uint8

Signed-off-by: aalavandhann <[email protected]>

* recover comment fix

Signed-off-by: aalavandhann <[email protected]>

* vault deposit/redeem return zero instead of reverting

Signed-off-by: aalavandhann <[email protected]>

* renamed totalSupply_ to noteSupply

Signed-off-by: aalavandhann <[email protected]>

* removed whenNotPaused from recover and redeem

Signed-off-by: aalavandhann <[email protected]>

* using safeTransfer for transfer

Signed-off-by: aalavandhann <[email protected]>

* removed _enforceVaultComposition

Signed-off-by: aalavandhann <[email protected]>

* removed MIN_SWAP_UNITS check

Signed-off-by: aalavandhann <[email protected]>

* min underlying perc in vault

Signed-off-by: aalavandhann <[email protected]>

* renamed perp and vault share fee variables

Signed-off-by: aalavandhann <[email protected]>

* vault get tvl cleanup

Signed-off-by: aalavandhann <[email protected]>

* tranche helpers cleanup

Signed-off-by: aalavandhann <[email protected]>

* removed deployed count and deployed at

Signed-off-by: aalavandhann <[email protected]>

* comment update

Signed-off-by: aalavandhann <[email protected]>

* assuming bond has only two tranches, thus bond-tranches data structure has fixed len arrays

Signed-off-by: aalavandhann <[email protected]>

* increased vault's dust amt

Signed-off-by: aalavandhann <[email protected]>

* meld perps style change

Signed-off-by: aalavandhann <[email protected]>

* vault comment fix

Signed-off-by: aalavandhann <[email protected]>

* removed comment vault

n

Signed-off-by: aalavandhann <[email protected]>

* vault using cached variable

Signed-off-by: aalavandhann <[email protected]>

* cleaned up perp mint estimation, added comments

Signed-off-by: aalavandhann <[email protected]>

* sync asset made into online fn

Signed-off-by: aalavandhann <[email protected]>

* removed bond duration method

Signed-off-by: aalavandhann <[email protected]>

* bond helpers using return val for getSeniorTranche

Signed-off-by: aalavandhann <[email protected]>

* fixed sigmoid condition

Signed-off-by: aalavandhann <[email protected]>

* Ran linter

Signed-off-by: aalavandhann <[email protected]>

* removed bond/tranche double check in favor of one check for bond validity

Signed-off-by: aalavandhann <[email protected]>

* fixed bug, with underlying perc calc after swap

Signed-off-by: aalavandhann <[email protected]>

* using cached value of reserve count

Signed-off-by: aalavandhann <[email protected]>

* perp: renamed rollout condition and fixed order of checks in

Signed-off-by: aalavandhann <[email protected]>

* removed duplicate comment in bond helpers

Signed-off-by: aalavandhann <[email protected]>

* perp enforcing max len for reserve and using uint8 for reserve len,  returning only tokens up for rollover

Signed-off-by: aalavandhann <[email protected]>

* fee policy cleanup

Signed-off-by: aalavandhann <[email protected]>

* perp defensive check on rollover

Signed-off-by: aalavandhann <[email protected]>

* vault enforcing liquidity constraints on both swap functions

Signed-off-by: aalavandhann <[email protected]>

* bond helper minor style fix

Signed-off-by: aalavandhann <[email protected]>

* updated testcases, back to full coverage

Signed-off-by: aalavandhann <[email protected]>

* vault: removed redundant sync with redeem tranches on meld and rollover

Signed-off-by: aalavandhann <[email protected]>

* fixed router bug, with undeployed bonds

Signed-off-by: aalavandhann <[email protected]>

* removed returns in bond helper

Signed-off-by: aalavandhann <[email protected]>

* Fee delta update

Signed-off-by: aalavandhann <[email protected]>

* updated variable name

Signed-off-by: aalavandhann <[email protected]>

* updated tasks with the new interface

Signed-off-by: aalavandhann <[email protected]>

* testnet deployment

Signed-off-by: aalavandhann <[email protected]>

* Pre release fixes (#199)

* using fixed perc fees for ops

* removed some unreachable code

* added test case to check for dust recovery

* removed vault deployment fee

* pve002 router validation

* pve004 preview deposit mature bond handling

* Removed from paramters from asset transfer wrapper functions and using msg.sender directly, also using msg.sender instead of _msgSender

* ran linter

* updated unit tests

* pve001 updating constructors

* pve002-3 bond issuer tranche granularity check

* Removed redundant computeDeviationRatio method from fee policy

* openzeppelin defender report informational issues

* Reverted pve002

* deployed to sepolia testnet (#201)

Signed-off-by: aalavandhann <[email protected]>

* fixed liner issue

Signed-off-by: aalavandhann <[email protected]>

* V2 final updates (#204)

* updated sigmoid bound for 20% yearly rollover rate

* updated LICENSE

Signed-off-by: aalavandhann <[email protected]>

* natspec comment updates for variable reanmes

Signed-off-by: aalavandhann <[email protected]>

* moved hyper paramter controls to keeper

Signed-off-by: aalavandhann <[email protected]>

* a few more unit tests to improve coverage

Signed-off-by: aalavandhann <[email protected]>

* upgrade tasks

Signed-off-by: aalavandhann <[email protected]>

* v2 deployment

Signed-off-by: aalavandhann <[email protected]>

---------

Signed-off-by: aalavandhann <[email protected]>
Co-authored-by: Brandon Iles <[email protected]>
Co-authored-by: nms-7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants