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

Generalized Perp Vaults #47

Open
wants to merge 7 commits into
base: wbtc/stakedao
Choose a base branch
from
Open

Generalized Perp Vaults #47

wants to merge 7 commits into from

Conversation

aparnakr
Copy link
Contributor

No description provided.

// keep track of underlying balance after
uint256 totalUnderlyingAfterDeposit = totalUnderlyingAsset();
require(totalUnderlyingAfterDeposit < cap, 'O7');
require(totalUnderlyingAfterDeposit.sub(totalUnderlyingBeforeDeposit) == amount);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

throw an error like in line 192 if it fails!

Also refer to the error codes in line 18 and add the error to it, make sure error codes are still valid, if not remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

done


// keep track of underlying balance after
uint256 totalUnderlyingAfterWithdrawal = totalUnderlyingAsset();
require(totalUnderlyingBeforeWithdrawal.sub(totalUnderlyingAfterWithdrawal) == underlyingShareOfRecipient);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add an error message :)

Copy link
Contributor

Choose a reason for hiding this comment

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

done

// send underlying to user
underlyingToken.safeTransfer(msg.sender, underlyingOwedToUser);
// withdraw underlying from vault
uint256 underlyingShareOfRecipient = _getWithdrawAmountByShares(_share);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the amount of underlying to transfer right? calling it share is a bit confusing, can you rename it to maybe underlyingToTransfer / something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

done. changed names to underlyingToRecipientBeforeFees and underlyingToRecipientAfterFees.

vaultTotal, 'internal balance is incorrect'
);
// check the underlying token balances
expect(vaultTotal).to.be.equal(UnderlyingBeforeDeposit.add(p1DepositAmount), 'internal underlying balance is incorrect');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you also check that vaultTotal == underlying.balanceOf(vault.address) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is true for p1 and p2 (and generally for any depositor before rollover) but not for p3. Added a manual check section that checks for this for p1 and p2 and does the necessary sanity check for p3 (reserve*(p1+p2)+p3 == underlying.balanceOf(vault.address) ) .

sdcrvRenWsbtcPrice.toNumber()
);
expect((await vault.balanceOf(depositor2.address)), 'incorrect amount of shares minted').to.be.equal(totalSharesMinted);
expect(totalSharesExisting, 'incorrect amount of shares existing').to.be.equal(sharesBefore.add(totalSharesMinted));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you also check that vaultTotal == underlying.balanceOf(vault.address) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

see previous comment

).to.be.true;

expect((await action1.lockedAsset()).eq(underlyingExpectedBeforeMintInActionLocked),'collateral should not be locked').to.be.true;
expect((await wbtc.balanceOf(action1.address)).eq(underlyingExpectedBeforeMintInActionUnlocked),'collateral should all be unlocked').to.be.true;
Copy link
Contributor Author

@aparnakr aparnakr Dec 23, 2021

Choose a reason for hiding this comment

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

can you also check that the action.currentVault is underlyingExpectedBeforeMintInActionUnlocked?

Copy link
Contributor

Choose a reason for hiding this comment

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

done (I guess you meant currentValue())


expect(sharesBefore, 'incorrect amount of shares withdrawn').to.be.equal(sharesAfter.add(sharesToWithdraw))
// check shares
expect(sharesAfter, 'incorrect amount of shares withdrawn').to.be.equal(sharesExpectedAfter);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check that vault.balanceOf(depositor1) is 0 (since they withdrew all so they should have no shares)

Copy link
Contributor

Choose a reason for hiding this comment

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

done. For all 3 users (since they all deposit all their wallet amount to the strategy and then withdraw it all) added a check user shares section which verifies that they are indeed 0 after withdrawal.

vaultSdECRVBalanceBefore.sub(sdcrvRenWsbtcWithdrawn).sub(1) as any,
vaultSdECRVBalanceBefore.sub(sdcrvRenWsbtcWithdrawn).add(1) as any,
);
expect(underlyingAfterWithdrawal, 'incorrect underlying remained in the vault').to.be.eq(underlyingExpectedAfterWithdrawal);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

check that amountWithdrawn = p1DepositorAmount + p1's share of premium.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also check that p1 ended up in a profitable position despite fees. (basically if mint and sell didn't happen, this test should fail and p1 should not have made a profit)

Copy link
Contributor

Choose a reason for hiding this comment

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

done. added a manual checks on profitability section on all 3 users with the above 2 tests. p1 and p2 are the same and follow the above comment's logic, p3 just loses the withdrawal fee since entrance was after rollover & mint so has no profit.

Copy link
Contributor Author

@aparnakr aparnakr left a comment

Choose a reason for hiding this comment

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

Great job on the PR Konstantinos! It was really hard and its awesome to see how rigorous you were and how you deeply understood the code!! :D

Konstantinos Gkolias and others added 3 commits January 2, 2022 02:56
* loss changes completed - 2 testings left to verify

* performance fee added

* Profit still in progress

* updates

* bignumber hack

* KG commit through Demola's Branch - fixed pricer, completed all calculations for profit scenario

* KG new commit through Demola's Branch - fixed some tests to work for loss too, fixed type of numbers for certain calculations,  first cleanup for profit scenario

Co-authored-by: Konstantinos Gkolias <[email protected]>

emit Withdraw(msg.sender, underlyingOwedToUser, _share);
}
console.log("Fee Recipient: %s",feeWithdrawalRecipient);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove console.logs :)

Comment on lines +425 to +429
console.log("premium:",premium.toString());
console.log("underlyingBeforeRollOverTotal:",underlyingBeforeRollOverTotal.toString());
console.log("underlyingExpectedAfterMintTotal:",underlyingExpectedAfterMintTotal.toString());
console.log("underlyingExpectedAfterMintInVault:",underlyingExpectedAfterMintInVault.toString());
console.log("underlyingExpectedBeforeMintInActionLocked:",underlyingExpectedBeforeMintInActionLocked);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could we remove all the console logs and convert them to tests? :D

Copy link
Contributor Author

@aparnakr aparnakr left a comment

Choose a reason for hiding this comment

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

Looks good once we remove al the console logs! :D

@KonGol33
Copy link
Contributor

Aparna this version of the code exists on branch generalized_cc_vault without any console logs anywhere. I will keep kg_testing_2 as is for further testing in future if needed.

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