Skip to content

Commit

Permalink
add helper method to donate amount to vault
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Oct 12, 2023
1 parent d23f6e0 commit 3f0cd36
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/pools/test_erc4626_swaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def mint_vault_tokens(deposit_amount, underlying_token, vault_contract, user):
return vault_contract.balanceOf(user)


def donate_to_vault(donation_amount, underlying_token, vault_contract, user):

donation_amount = donation_amount * 10 ** underlying_token.decimals()
mint_for_testing(user, donation_amount, underlying_token, False)
underlying_token.transfer(vault_contract, donation_amount, sender=user)


@pytest.fixture(scope="module")
def asset(deployer):
with boa.env.prank(deployer):
Expand Down Expand Up @@ -188,6 +195,40 @@ def test_swap(swap, i, j, charlie, pool_tokens, pool_erc20_tokens):
assert dy == pytest.approx(calculated)


@pytest.mark.parametrize("i,j", itertools.permutations(range(3), 2))
def test_donate_swap(swap, i, j, alice, charlie, pool_tokens, pool_erc20_tokens):

amount_erc20_in = 10 ** pool_erc20_tokens[i].decimals()

if amount_erc20_in > pool_erc20_tokens[i].balanceOf(charlie):
if i != 0:
bal_before = pool_erc20_tokens[i].balanceOf(charlie)
mint_for_testing(charlie, amount_erc20_in, pool_erc20_tokens[i], False)
amount_in = pool_erc20_tokens[i].balanceOf(charlie) - bal_before
else:
amount_in = mint_vault_tokens(amount_erc20_in, pool_erc20_tokens[0], pool_tokens[0], charlie)

pool_tokens[i].approve(swap, 2**256 - 1, sender=charlie)

# rebase:
if "RebasingConditional" in pool_tokens[i].filename:
pool_tokens[i].rebase()

# donate to vault:
donate_to_vault(10**5, pool_erc20_tokens[0], pool_tokens[0], alice)

# calculate expected output and swap:
calculated = swap.get_dy(i, j, amount_in)
dy = swap.exchange(i, j, amount_in, int(0.99 * calculated), sender=charlie)

# check:
try:
assert dy == calculated
except: # noqa: E722
assert 2 in [i, j] # rebasing token balances can have wonky math
assert dy == pytest.approx(calculated)


def test_rebase(swap, charlie, bob, pool_tokens):

amount_rewards = 10**4 * 10**18
Expand Down

0 comments on commit 3f0cd36

Please sign in to comment.