delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
33 stars 4 forks source link

Bug: Negative interest in non standard decimals test #386

Closed gtowle03 closed 10 months ago

gtowle03 commented 1 year ago

https://github.com/delvtech/hyperdrive/actions/runs/5347568272

jalextowle commented 1 year ago

I'd suggest that you take the parameters from the failing run and hardcode those into the test. It should fail with the same error, which will allow you to log data and poke around to see what causes the issue.

My guess is that the problem is caused because one of the trade sizes is really small, and we could fix the problem by increasing the minimum; however, it could be the opposite problem and we'd need to decrease the maximum trade sizes.

gtowle03 commented 1 year ago

Failure at line 283 on NonstandardDecimals.sol with longBasePaid = 279154570667275 and shortAmount = 0

jalextowle commented 1 year ago

I just saw this again in CI: https://github.com/delvtech/hyperdrive/actions/runs/6344968653/job/17236114278?pr=593.

jrhea commented 1 year ago

I just saw this again in CI: https://github.com/delvtech/hyperdrive/actions/runs/6344968653/job/17236114278?pr=593.

I saw one in my PR that is similar. This is what I tracked down:

Here is another failing test that is interesting:

    function test_nonstandard_decimals_lp_edge_cases() external {
        uint256 longBasePaid = 2141061247565828640207640148726033314; // 279_000_050.816564
        uint256 shortAmount = 0; // 0.100000
        _test_nonstandard_decimals_lp(longBasePaid, shortAmount);
    }

it's odd that this check in openLong()

        if (
            _initialSharePrice.mulDown(
                _effectiveShareReserves() + shareReservesDelta
            ) > _marketState.bondReserves - bondReservesDelta
        ) {
            revert IHyperdrive.NegativeInterest();
        }

passes, but this check in openShort()

        if (shareReservesDelta.mulDown(_sharePrice) > _bondAmount)
            revert IHyperdrive.NegativeInterest();

doesn't. The test passes if i:

jrhea commented 10 months ago

resolved in #609