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

feat: locked profit on deposit #273

Merged
9 commits merged into from
May 19, 2021
Merged

Conversation

Grandthrax
Copy link
Contributor

1 - Make sure that we deposit and withdraw at same share price
2 - Add onreleased profit to next lockedprofit

@fubuloubu fubuloubu requested review from fubuloubu and a user April 14, 2021 22:26
contracts/Vault.vy Outdated Show resolved Hide resolved
contracts/Vault.vy Outdated Show resolved Hide resolved
contracts/Vault.vy Outdated Show resolved Hide resolved
contracts/Vault.vy Outdated Show resolved Hide resolved
shares = precisionFactor * amount * totalSupply / self._totalAssets() / precisionFactor

freeFunds: uint256 = self._totalAssets() - self._calculateLockedProfit()
shares = precisionFactor * amount * totalSupply / freeFunds / precisionFactor
Copy link
Member

Choose a reason for hiding this comment

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

What testing do we have to make sure this change doesn't introduce a vulnerability?

Copy link
Contributor

Choose a reason for hiding this comment

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

can we modify the deposit and withdraw test in brownie for the same block to assert we got the exact amount of want tokens on both operations?

Copy link

@ghost ghost Apr 16, 2021

Choose a reason for hiding this comment

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

I tought in tests every blockchain call mines a block, I haven't seen an option to batch transactions.
Will look for how that's done.

Copy link
Member

Choose a reason for hiding this comment

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

You can shut off auto-mining

Copy link
Contributor

@storming0x storming0x left a comment

Choose a reason for hiding this comment

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

Changes look good, can we add or edit a test to check that deposit and withdraw in same block cannot make more want than possible?

contracts/Vault.vy Outdated Show resolved Hide resolved
@ghost ghost mentioned this pull request Apr 16, 2021
contracts/Vault.vy Outdated Show resolved Hide resolved
@fubuloubu fubuloubu changed the title feat: locked profit on deposit Locked profit on deposit Apr 20, 2021
@fubuloubu fubuloubu changed the title Locked profit on deposit feat: locked profit on deposit Apr 20, 2021
@fubuloubu
Copy link
Member

Disregard failing CI job, was testing something

@fubuloubu fubuloubu changed the title feat: locked profit on deposit locked profit on deposit Apr 20, 2021
@fubuloubu fubuloubu changed the title locked profit on deposit feat: locked profit on deposit Apr 20, 2021
@fubuloubu
Copy link
Member

Change looks good, needs further testing to merge

@ghost
Copy link

ghost commented Apr 30, 2021

I am missing something I couldn't find how to include multiple transactions within the same block.


def test_token_amount_does_not_change_on_deposit_withdrawal(chain, gov, token, vault, strategy, rando):
    # set fees to 0
    vault.setManagementFee(0, {"from": gov})
    vault.setPerformanceFee(0, {"from": gov})
    vault.updateStrategyPerformanceFee(strategy, 0, {"from": gov})
    vault.setLockedProfitDegration(
        1e16, {"from": gov}
    )
    web3.provider.make_request("miner_stop", [])

    deposit =vault.deposit(token.balanceOf(gov), {"from": gov, "required_confs": 0})
    withdraw = vault.withdraw({"from": gov,  "required_confs": 0})
    web3.provider.make_request("miner_start", [])
    chain.mine()

    assert(deposit.block == withdraw.block) 

@fubuloubu
Copy link
Member

Suggestion from audit: losses should take away from locked profits

@fubuloubu fubuloubu mentioned this pull request May 11, 2021
19 tasks
@fubuloubu
Copy link
Member

rebase on master

@ghost ghost force-pushed the withdrawatpricepershare branch from c8d1f36 to fdf4bd8 Compare May 18, 2021 09:28
@ghost
Copy link

ghost commented May 18, 2021

Rebased added losses on lockedProfit and force pushed

@ghost
Copy link

ghost commented May 18, 2021

Found a workaround to mine two transactions within the same block using evm_mine

web3.provider.make_request("evm_mine", [chain.time() + 5])

found the solution UMAprotocol/protocol#1151

contracts/Vault.vy Outdated Show resolved Hide resolved
tests/functional/vault/test_withdrawal.py Show resolved Hide resolved
@ghost ghost force-pushed the withdrawatpricepershare branch from 7ac332e to d162d65 Compare May 19, 2021 08:29
@ghost ghost force-pushed the withdrawatpricepershare branch from d162d65 to 041e731 Compare May 19, 2021 08:30
Steffel and others added 2 commits May 19, 2021 10:49
Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>
@ghost ghost force-pushed the withdrawatpricepershare branch from 041e731 to e8a18ea Compare May 19, 2021 08:50
@ghost ghost merged commit cc354d8 into yearn:master May 19, 2021
@ghost
Copy link

ghost commented May 19, 2021

Merged 🎉🎉🎉

orbxball pushed a commit to orbxball/yearn-vaults that referenced this pull request Aug 8, 2021
* feat: locked profit on deposit

* fix: refactor unused code

* fix: audit changes

* refactor: use cached value

* fix: rebase mistakes

* feat: remove loss from lockedProfit

* test: deposit and withdrawal within same block

* docs: error if division fail

Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>

* docs: ganache minning workaround

Co-authored-by: Sam Priestley <sfpriestley@hotmail.co.uk>
Co-authored-by: Just some guy <3859395+fubuloubu@users.noreply.github.com>
Co-authored-by: steffel <2143646+steffenix@users.noreply.github.com>
sambacha pushed a commit to sambacha/yearn-vaults that referenced this pull request Sep 7, 2021
* feat: locked profit on deposit

* fix: refactor unused code

* fix: audit changes

* refactor: use cached value

* fix: rebase mistakes

* feat: remove loss from lockedProfit

* test: deposit and withdrawal within same block

* docs: error if division fail

Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>

* docs: ganache minning workaround

Co-authored-by: Sam Priestley <sfpriestley@hotmail.co.uk>
Co-authored-by: Just some guy <3859395+fubuloubu@users.noreply.github.com>
Co-authored-by: steffel <2143646+steffenix@users.noreply.github.com>
This pull request was closed.
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