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

build: allow max uint #204

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions .github/workflows/foundry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,16 @@ jobs:
- ubuntu-latest
architecture:
- "x64"
python-version:
- "3.10"
node_version:
- 16

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}

- name: Install Ape
uses: ApeWorX/[email protected]
with:
python-version: '3.10'

- name: install vyper
run: pip install git+https://github.com/vyperlang/vyper

- name: Compile contracts
# Compile Ape contracts to get dependencies
run: ape compile --force --size


- name: Install Vyper
run: pip install vyper==0.3.7

- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
with:
fetch-depth: 1

- name: Set up python 3.8
- name: Set up python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Set pip cache directory path
id: pip-cache-dir-path
Expand Down
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
[submodule "lib/erc4626-tests"]
path = lib/erc4626-tests
url = https://github.com/a16z/erc4626-tests
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
release = v4.9.5
[submodule "lib/tokenized-strategy"]
path = lib/tokenized-strategy
url = https://github.com/yearn/tokenized-strategy
18 changes: 12 additions & 6 deletions contracts/VaultV3.vy
Original file line number Diff line number Diff line change
Expand Up @@ -663,19 +663,25 @@ def _deposit(sender: address, recipient: address, assets: uint256) -> uint256:
vault accounting.
"""
assert self.shutdown == False # dev: shutdown
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove shutdown check

assert assets <= self._max_deposit(recipient), "exceed deposit limit"

amount: uint256 = assets
# Deposit all if sent with max uint
if amount == max_value(uint256):
amount = ERC20(self.asset).balanceOf(msg.sender)

assert amount <= self._max_deposit(recipient), "exceed deposit limit"

# Transfer the tokens to the vault first.
self._erc20_safe_transfer_from(self.asset, msg.sender, self, assets)
self._erc20_safe_transfer_from(self.asset, msg.sender, self, amount)
# Record the change in total assets.
self.total_idle += assets
self.total_idle += amount

# Issue the corresponding shares for assets.
shares: uint256 = self._issue_shares_for_amount(assets, recipient)
# Issue the corresponding shares for amount.
shares: uint256 = self._issue_shares_for_amount(amount, recipient)

assert shares > 0, "cannot mint zero"

log Deposit(sender, recipient, assets, shares)
log Deposit(sender, recipient, amount, shares)
return shares

@internal
Expand Down
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ libs = ['lib']
remappings = [
'forge-std/=lib/forge-std/src/',
'erc4626-tests/=lib/erc4626-tests/',
"@tokenized-strategy=contracts/.cache/tokenized-strategy/v3.0.2",
'@openzeppelin/contracts=contracts/.cache/openzeppelin/v4.9.5/',
"@tokenized-strategy=lib/tokenized-strategy/src",
'@openzeppelin/=lib/openzeppelin-contracts/',
]
fs_permissions = [{ access = "read", path = "./"}]

Expand Down
18 changes: 18 additions & 0 deletions foundry_tests/tests/ERC4626Std.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ contract VaultERC4626StdTest is ERC4626Test, Setup {
super.test_maxRedeem(init);
}

//Avoid special case for deposits of uint256 max
function test_previewDeposit(
Init memory init,
uint assets
) public override {
if (assets == type(uint256).max) assets -= 1;
super.test_previewDeposit(init, assets);
}

function test_deposit(
Init memory init,
uint assets,
uint allowance
) public override {
if (assets == type(uint256).max) assets -= 1;
super.test_deposit(init, assets, allowance);
}

function clamp(
Init memory init,
uint max
Expand Down
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at bd325d
1 change: 1 addition & 0 deletions lib/tokenized-strategy
Submodule tokenized-strategy added at 0d90de
23 changes: 23 additions & 0 deletions tests/unit/vault/test_erc4626.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,29 @@ def test_max_redeem__with_withdraw_limit_module(
assert vault.maxRedeem(bunny.address) == 0


def test_deposit__with_max_uint(
asset, fish, fish_amount, gov, create_vault, deploy_limit_module, user_deposit
):
vault = create_vault(asset)
assets = fish_amount

assert asset.balanceOf(fish) == fish_amount

asset.approve(vault.address, assets, sender=fish)

# Should go through now
tx = vault.deposit(MAX_INT, fish.address, sender=fish)

event = list(tx.decode_logs(vault.Deposit))[0]

assert event.assets == assets
assert event.shares == assets
assert event.owner == fish
assert event.sender == fish
assert vault.balanceOf(fish.address) == assets
assert asset.balanceOf(vault.address) == assets


def test_deposit__with_deposit_limit_module(
asset, fish, fish_amount, gov, create_vault, deploy_limit_module, user_deposit
):
Expand Down
Loading