Exemple #1
0
def test_steth_positive_rebase(vault, vault_user, stranger, liquidations_admin,
                               steth_token, mock_bridge_connector,
                               withdraw_from_terra, lido_oracle_report,
                               steth_adjusted_ammount, helpers):
    amount = 1 * 10**18
    adjusted_amount = steth_adjusted_ammount(amount)

    steth_token.approve(vault, amount, {'from': vault_user})
    vault.submit(amount, TERRA_ADDRESS, '0xab', vault.version(),
                 {'from': vault_user})
    assert mock_bridge_connector.terra_beth_balance_of(TERRA_ADDRESS) == amount

    vault_steth_balance_before = steth_token.balanceOf(vault)
    assert helpers.equal_with_precision(vault_steth_balance_before, amount, 10)

    lido_oracle_report(steth_rebase_mult=1.01)

    vault_steth_balance_after = steth_token.balanceOf(vault)
    assert vault_steth_balance_after > vault_steth_balance_before

    assert helpers.equal_with_precision(vault.get_rate(), 10**18, max_diff=100)

    vault.collect_rewards({'from': liquidations_admin})

    assert helpers.equal_with_precision(vault.get_rate(), 10**18, max_diff=100)

    withdraw_from_terra(TERRA_ADDRESS, to_address=stranger, amount=amount)
    vault.withdraw(amount, vault.version(), {'from': stranger})

    assert helpers.equal_with_precision(steth_token.balanceOf(stranger),
                                        adjusted_amount, 100)
Exemple #2
0
def test_rate_changes(vault, lido_oracle_report, vault_user,
                      liquidations_admin, steth_token, helpers):
    assert vault.get_rate() == 10**18

    steth_token.approve(vault, 10**18, {'from': vault_user})
    vault.submit(10**18, TERRA_ADDRESS, b'', vault.version(),
                 {'from': vault_user})

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff=1000)

    lido_oracle_report(steth_rebase_mult=1.1)

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff=1000)

    vault.collect_rewards({'from': liquidations_admin})

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff=1000)

    lido_oracle_report(steth_rebase_mult=0.9)

    assert helpers.equal_with_precision(vault.get_rate(),
                                        int((1 / 0.9) * 10**18),
                                        max_diff=1000)

    lido_oracle_report(steth_rebase_mult=1.01)

    assert helpers.equal_with_precision(vault.get_rate(),
                                        int((1 / 0.909) * 10**18),
                                        max_diff=1000)

    chain.mine(timedelta=3600 * 24 + 1)
    vault.collect_rewards({'from': liquidations_admin})

    assert helpers.equal_with_precision(vault.get_rate(),
                                        int((1 / 0.909) * 10**18),
                                        max_diff=1000)

    lido_oracle_report(steth_rebase_mult=2.0)

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff=1000)

    chain.mine(timedelta=3600 * 24 + 1)
    vault.collect_rewards({'from': liquidations_admin})

    assert helpers.equal_with_precision(vault.get_rate(),
                                        int((1 / 0.909) * 10**18),
                                        max_diff=1000)
Exemple #3
0
def test_insurance_is_not_counted_as_rewards(
    vault,
    vault_user,
    another_vault_user,
    liquidations_admin,
    steth_token,
    steth_adjusted_ammount,
    lido_oracle_report,
    apply_insurance,
    helpers,
):
    amount = steth_adjusted_ammount(10**18)

    steth_token.approve(vault, amount, {'from': vault_user})
    vault.submit(amount, TERRA_ADDRESS, b'', vault.version(),
                 {'from': vault_user})

    vault_steth_balance_before = steth_token.balanceOf(vault)

    lido_oracle_report(steth_rebase_mult=0.99)
    vault.collect_rewards({'from': liquidations_admin})

    assert helpers.equal_with_precision(vault.get_rate(),
                                        int((1 / 0.99) * 10**18), 100)

    chain.mine(timedelta=24 * 3600 + 1)
    apply_insurance(steth_rebase_mult=1 / 0.99)

    assert vault.get_rate() >= 10**18

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff_percent=0.1)

    tx = vault.collect_rewards({'from': liquidations_admin})

    helpers.assert_single_event_named('RewardsCollected',
                                      tx,
                                      source=vault,
                                      evt_keys_dict={
                                          'steth_amount': 0,
                                          'ust_amount': 0
                                      })

    assert helpers.equal_with_precision(vault.get_rate(),
                                        10**18,
                                        max_diff_percent=0.1)
Exemple #4
0
def test_steth_rewards_after_penalties(
        vault, vault_user, another_vault_user, stranger, another_stranger,
        liquidations_admin, steth_token, beth_token, withdraw_from_terra,
        lido_oracle_report, mock_bridge_connector, helpers,
        steth_adjusted_ammount):
    amount = 1 * 10**18
    adjusted_amount = steth_adjusted_ammount(amount)
    negative_rebase_multiplier = 0.99
    positive_rebase_multiplier = 1 / negative_rebase_multiplier

    steth_token.approve(vault, amount, {'from': vault_user})
    vault.submit(amount, TERRA_ADDRESS, b'', vault.version(),
                 {'from': vault_user})

    lido_oracle_report(steth_rebase_mult=negative_rebase_multiplier)

    assert helpers.equal_with_precision(
        vault.get_rate(), (1 / negative_rebase_multiplier) * 10**18, 100)

    tx = vault.collect_rewards({'from': liquidations_admin})

    helpers.assert_single_event_named('RewardsCollected',
                                      tx,
                                      source=vault,
                                      evt_keys_dict={
                                          'steth_amount': 0,
                                          'ust_amount': 0
                                      })

    steth_token.approve(vault, amount, {'from': another_vault_user})
    vault.submit(amount, ANOTHER_TERRA_ADDRESS, b'', vault.version(),
                 {'from': another_vault_user})

    lido_oracle_report(steth_rebase_mult=positive_rebase_multiplier)
    chain.mine(timedelta=3600 * 24 + 1)
    vault.collect_rewards({'from': liquidations_admin})

    withdraw_from_terra(
        TERRA_ADDRESS,
        to_address=stranger,
        amount=mock_bridge_connector.terra_beth_balance_of(TERRA_ADDRESS))
    vault.withdraw(beth_token.balanceOf(stranger), vault.version(),
                   {'from': stranger})

    assert helpers.equal_with_precision(
        steth_token.balanceOf(stranger),
        steth_adjusted_ammount(adjusted_amount * negative_rebase_multiplier),
        10**10)

    withdraw_from_terra(ANOTHER_TERRA_ADDRESS,
                        to_address=another_stranger,
                        amount=mock_bridge_connector.terra_beth_balance_of(
                            ANOTHER_TERRA_ADDRESS))
    vault.withdraw(beth_token.balanceOf(another_stranger), vault.version(),
                   {'from': another_stranger})

    assert helpers.equal_with_precision(
        steth_token.balanceOf(another_stranger), adjusted_amount, 10**10)
Exemple #5
0
def test_steth_negative_rebase(vault, vault_user, stranger, liquidations_admin,
                               steth_token, mock_bridge_connector,
                               withdraw_from_terra, lido_oracle_report,
                               steth_adjusted_ammount, helpers):
    amount = 1 * 10**18
    adjusted_amount = steth_adjusted_ammount(amount)

    steth_token.approve(vault, amount, {'from': vault_user})
    vault.submit(amount, TERRA_ADDRESS, '0xab', vault.version(),
                 {'from': vault_user})
    assert mock_bridge_connector.terra_beth_balance_of(TERRA_ADDRESS) == amount

    vault_steth_balance_before = steth_token.balanceOf(vault)
    assert helpers.equal_with_precision(vault_steth_balance_before, amount, 10)

    lido_oracle_report(steth_rebase_mult=0.99)

    vault_steth_balance_after = steth_token.balanceOf(vault)
    assert vault_steth_balance_after < vault_steth_balance_before

    expected_withdraw_rate = int((1 / 0.99) * 10**18)

    assert helpers.equal_with_precision(vault.get_rate(),
                                        expected_withdraw_rate, 100)

    withdraw_from_terra(TERRA_ADDRESS, to_address=stranger, amount=amount)

    tx = vault.collect_rewards({'from': liquidations_admin})

    helpers.assert_single_event_named('RewardsCollected',
                                      tx,
                                      source=vault,
                                      evt_keys_dict={
                                          'steth_amount': 0,
                                          'ust_amount': 0
                                      })

    assert helpers.equal_with_precision(vault.get_rate(),
                                        expected_withdraw_rate, 100)

    vault.withdraw(amount, vault.version(), {'from': stranger})

    assert helpers.equal_with_precision(
        steth_token.balanceOf(stranger),
        steth_adjusted_ammount(adjusted_amount * 0.99), 100)