Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollover vault #112

Merged
merged 14 commits into from
Apr 10, 2023
Merged

Rollover vault #112

merged 14 commits into from
Apr 10, 2023

Conversation

aalavandhan
Copy link
Member

@aalavandhan aalavandhan commented Nov 15, 2022

  • Users deposit AMPL for vault notes
  • Vault "deploys" ampl by tranching and performing rollover, it "recovers" AMPL by redeeming mature tranches
  • On redemption users get a slice of all the assets held by the vault

At any given time the vault could hold, the underlying asset (deposit asset AMPL), the earned asset (SPOT) and the deployed assets (tranches).

@aalavandhan aalavandhan force-pushed the rollover-vault branch 4 times, most recently from 2f93f0c to b15925c Compare November 16, 2022 14:46
@aalavandhan aalavandhan changed the base branch from main to dev November 16, 2022 16:08
@aalavandhan aalavandhan changed the title Rollover vault WIP: Rollover vault Dec 29, 2022
@aalavandhan aalavandhan force-pushed the rollover-vault branch 2 times, most recently from 37ea215 to 57bb76c Compare January 12, 2023 16:59
@aalavandhan aalavandhan changed the base branch from dev to main January 18, 2023 08:38
@aalavandhan aalavandhan changed the base branch from main to perp-updates January 18, 2023 08:39
@aalavandhan aalavandhan changed the title WIP: Rollover vault Rollover vault Jan 18, 2023
@aalavandhan aalavandhan added the next-release Changes for upcoming release label Feb 1, 2023
spot-contracts/contracts/_utils/BondHelpers.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
if (!bond.isMature()) {
bond.mature();
}
bond.redeemMature(address(tranche), tranche.balanceOf(address(this)));
Copy link
Member Author

@aalavandhan aalavandhan Feb 10, 2023

Choose a reason for hiding this comment

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

Something to be cognizant of is that this can revert when the entire supply is redeemed and brick our recoverAndRedeploy workflow.

https://github.com/buttonwood-protocol/tranche/blob/main/contracts/BondController.sol#L225

Options:

  1. We could wrap around try-catch
  2. Add logic to compute amounts discounting the min condition
  3. Handle manually if we ever run into this (deposit small amount of funds into the bond)

@nms-7 @brandoniles

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that's right, good point. Could happen on deposit too if we don't deploy enough. I would say (2) compute the amounts, but since MINIMUM_VALID_DEBT isn't exposed, (1) try-catch works

Copy link
Member

Choose a reason for hiding this comment

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

Yeah agree with @nms-7. #2 if it's possible.

I think try-catch is safe enough here though, since if it fails and continues, it's just a matter of lost capital efficiency. And it could be made more efficiently with a permissionless manual action.

@aalavandhan aalavandhan force-pushed the perp-updates branch 3 times, most recently from e2979d2 to 8ba96c7 Compare February 20, 2023 20:04
Base automatically changed from perp-updates to main February 23, 2023 15:06
Copy link
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.

This covers up through deposit() in RolloverVault.sol

spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
_redeemTranches();
}

/// @notice Deposits the provided asset from {msg.sender} into the vault and mints notes.
Copy link
Member

Choose a reason for hiding this comment

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

Should probably add a note saying it could be a good idea to call recover and deploy afterward.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
Copy link
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.

Covers up to right before the private write methods

/// @return The amount of notes.
function deposit(IERC20Upgradeable token, uint256 amount) external nonReentrant whenNotPaused returns (uint256) {
// NOTE: The vault only accepts the underlying asset tokens.
if (token != underlying) {
Copy link
Member

Choose a reason for hiding this comment

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

Something I was thinking about was making underlying immutable to give another layer of protection. Anytime a caller can specify a token to interact with, there's some danger of malicious code injection.

We'd have to add a constructor, though, in addition to the init function.

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont think we can have constructors in the proxy?

We could still get rid of the token parameter, don't think we need to generalize now. I'm okay with underlying not being strictly immutable, if the code doesn't have methods change it.

https://forum.openzeppelin.com/t/upgradable-contracts-instantiating-an-immutable-value/28763/2

Copy link
Member

Choose a reason for hiding this comment

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

Agree, that all sounds good to me 👍

spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
aalavandhan and others added 2 commits March 19, 2023 10:47
Co-authored-by: Brandon Iles <brandon@fragments.org>
Copy link
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.

_rollover

spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
spot-contracts/contracts/vaults/RolloverVault.sol Outdated Show resolved Hide resolved
@aalavandhan aalavandhan force-pushed the rollover-vault branch 5 times, most recently from 545ba47 to 2c16c13 Compare March 28, 2023 19:02
aalavandhan and others added 2 commits March 29, 2023 15:28
Co-authored-by: Brandon Iles <brandon@fragments.org>
Copy link
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 merged commit 4e49b37 into main Apr 10, 2023
@aalavandhan aalavandhan deleted the rollover-vault branch April 10, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-release Changes for upcoming release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants