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

All your rebase are belong to me (convert to non-rebasing token) #81

Merged
merged 22 commits into from
Jul 19, 2022

Conversation

0xchaosbi
Copy link
Contributor

@0xchaosbi 0xchaosbi commented Jul 15, 2022

Relates #75

Rebasing is dead, long live rebasing

TODO:

  • tests, incl. testing that the exchange rate only changes after the first rewards are received, and multiple stakes doesn't change the exchange rate
  • update unstake- and claim-related events to have both AVAX and stAVAX amounts
  • add getExchangeRate function

@0xchaosbi 0xchaosbi requested a review from Willyham July 15, 2022 22:00
src/AvaLido.sol Outdated Show resolved Hide resolved
src/AvaLido.sol Outdated Show resolved Hide resolved
src/AvaLido.sol Outdated Show resolved Hide resolved
src/stAVAX.sol Outdated Show resolved Hide resolved
@0xchaosbi 0xchaosbi changed the title [WIP] All your rebase are belong to me All your rebase are belong to me (convert to non-rebasing token) Jul 19, 2022
Copy link
Contributor

@jnic jnic left a comment

Choose a reason for hiding this comment

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

Some comments, nothing blocking.

lido.claimRewards();

// assert new exchange rate
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth pulling these out into constants to make it clear, e.g.

Suggested change
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
uint256 EXCHANGE_RATE = 982318271119842829; // 10e18 / 1.018
assertEq(lido.exchangeRateAVAXToStAVAX(), EXCHANGE_RATE);

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we testing unstaking or are we testing the exchange rate? I think the exchange rate calculations should be tested separately and here it's enough to assert that it's not 1 (if at all).

src/test/AvaLido.t.sol Show resolved Hide resolved
src/test/AvaLido.t.sol Show resolved Hide resolved

// NB: this test fails because the numbers chosen can never match up no matter the precision.
// Known issue of Solidity, floating point numbers & division. This round down behaviour is expected.
// function testCannotClaimMoreAVAXThanDepositedBeforeRewards() public {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could assert that the the amount you claim is <= the the amount deposited?

Or we could assert that it's within the range of our known rounding margin. Something like:

assert( abs (old - new - margin) == 0)?

) = lido.unstakeRequests(requestId);

assertEq(requester, USER1_ADDRESS);
assertEq(requestAt, uint64(block.timestamp));
assertEq(amountRequested, 5 ether);
assertEq(amountFilled, 0 ether);
assertEq(amountClaimed, 0 ether);
assertEq(stAVAXLocked, 5 ether);

// Second withdrawal.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what the second withdrawal is really testing here? Could simplify by having 1 test which tests multiple withdrawals and remove these second withdrawals from these tests?

Feels like we're testing too much in each test.

lido.claimRewards();

// assert new exchange rate
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we testing unstaking or are we testing the exchange rate? I think the exchange rate calculations should be tested separately and here it's enough to assert that it's not 1 (if at all).

Comment on lines +394 to +395
cheats.deal(rTreasuryAddress, 0.2 ether);
lido.claimRewards();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could make your life a bit simpler by using an unrealistic amount of rewards such that the value is 1:2. That makes the assertions clearer imo - I'm not sure if 5.09 is the right amount at a glance, but if it's 1:2 I can easily tell 5 -> 10 is correct

assertEq(amountClaimed, 0 ether);
assertEq(stAVAXLocked, 5 ether);

// Second withdrawal.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, not sure what this is testing

assertEq(amountRequested3, 0.1 ether);
assertEq(amountFilled3, 0.1 ether);
}

function testMultipleFillUnstakeRequestsSingleFillAfterRewards() public {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what this is really testing

Comment on lines +621 to +623
assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);
Copy link
Contributor

Choose a reason for hiding this comment

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

Again don't think we need to assert this

assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);

// So we withdraw 1 AVAX and lock 0.99108... stAVAX
Copy link
Contributor

Choose a reason for hiding this comment

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

same issue

Comment on lines +675 to +684
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);

// So we withdraw 1 AVAX and lock 0.99108... stAVAX
cheats.prank(USER1_ADDRESS);
lido.requestWithdrawal(1 ether);
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Comment on lines +1004 to +1006
assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than concerning the test with the values, you could do oldRate = lido.exchangeRate... and then later assert that the currentRate == oldRate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ps that would also make it viable to do a fuzz test where the rewards param is fuzzed

@0xchaosbi 0xchaosbi merged commit 8de3d5f into main Jul 19, 2022
@0xchaosbi 0xchaosbi deleted the allyourrebasearebelongtome branch July 19, 2022 22:50
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