Skip to content

Commit

Permalink
WIP: update tests to use new MPC functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xchaosbi committed Jul 19, 2022
1 parent ca0114d commit 1d0761b
Showing 1 changed file with 95 additions and 39 deletions.
134 changes: 95 additions & 39 deletions src/test/AvaLido.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(lido.exchangeRateStAVAXToAVAX(), 1 ether);

// TODO: change exchange rate by receiving rewards
lido.receiveRewardsFromMPC{value: 0.2 ether}();
//lido.receiveRewardsFromMPC{value: 0.2 ether}();
cheats.deal(rTreasuryAddress, 0.2 ether);
lido.claimRewards();

// assert new exchange rate
console2.log("exchange rate avax to stavax");
console2.log(lido.exchangeRateAVAXToStAVAX());
Expand Down Expand Up @@ -492,7 +495,9 @@ contract AvaLidoTest is DSTest, Helpers {
lido.initiateStake();

// 10.09 AVAX for 10 stAVAX = 1 AVAX for 0.99108 stAVAX
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);

Expand All @@ -506,7 +511,9 @@ contract AvaLidoTest is DSTest, Helpers {
// So we withdraw 1 AVAX and lock 0.99108... stAVAX
cheats.prank(USER1_ADDRESS);
lido.requestWithdrawal(1 ether);
lido.receivePrincipalFromMPC{value: 1 ether}();
//lido.receivePrincipalFromMPC{value: 1 ether}();
cheats.deal(pTreasuryAddress, 1 ether);
lido.claimUnstakedPrincipals();

(, , uint256 amountRequested, uint256 amountFilled, , uint256 stAVAXLocked) = lido.unstakeRequests(0);

Expand Down Expand Up @@ -548,7 +555,7 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(amountFilled3, 0.1 ether);
}

// TODO!!!
// TODO: fix test!!!
function testMultipleFillUnstakeRequestsSingleFillAfterRewards() public {
// Deposit as user.
cheats.prank(USER1_ADDRESS);
Expand All @@ -560,7 +567,9 @@ contract AvaLidoTest is DSTest, Helpers {
lido.initiateStake();

// 10.09 AVAX for 10 stAVAX = 1 AVAX for 0.99108 stAVAX
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);

Expand All @@ -579,11 +588,10 @@ contract AvaLidoTest is DSTest, Helpers {
lido.requestWithdrawal(1 ether);
cheats.stopPrank();

//lido.receivePrincipalFromMPC{value: 1 ether}();
cheats.deal(pTreasuryAddress, 1 ether);
lido.claimUnstakedPrincipals();

//lido.receivePrincipalFromMPC{value: 1 ether}();

// (, , uint256 amountRequested, uint256 amountFilled, , ) = lido.unstakeRequests(0);
// assertEq(amountRequested, 0.5 ether);
// assertEq(amountFilled, 0.5 ether);
Expand Down Expand Up @@ -632,7 +640,9 @@ contract AvaLidoTest is DSTest, Helpers {
lido.initiateStake();

// 10.09 AVAX for 10 stAVAX = 1 AVAX for 0.99108 stAVAX
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);

Expand All @@ -645,8 +655,10 @@ contract AvaLidoTest is DSTest, Helpers {

// So we withdraw 1 AVAX and lock 0.99108... stAVAX
cheats.prank(USER1_ADDRESS);
lido.requestWithdrawal(1 ether);
lido.receivePrincipalFromMPC{value: 0.1 ether}();
uint256 reqId = lido.requestWithdrawal(1 ether);
//lido.receivePrincipalFromMPC{value: 0.1 ether}();
cheats.deal(pTreasuryAddress, 0.1 ether);
lido.claimUnstakedPrincipals();

(, , uint256 amountRequested, uint256 amountFilled, , uint256 amountLocked) = lido.unstakeRequests(reqId);

Expand Down Expand Up @@ -691,7 +703,9 @@ contract AvaLidoTest is DSTest, Helpers {
lido.initiateStake();

// 10.09 AVAX for 10 stAVAX = 1 AVAX for 0.99108 stAVAX
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);

Expand All @@ -705,8 +719,12 @@ contract AvaLidoTest is DSTest, Helpers {
// So we withdraw 1 AVAX and lock 0.99108... stAVAX
cheats.prank(USER1_ADDRESS);
lido.requestWithdrawal(1 ether);
lido.receivePrincipalFromMPC{value: 0.1 ether}();
lido.receivePrincipalFromMPC{value: 0.1 ether}();
//lido.receivePrincipalFromMPC{value: 0.1 ether}();
// lido.receivePrincipalFromMPC{value: 0.1 ether}();
cheats.deal(pTreasuryAddress, 0.1 ether);
lido.claimUnstakedPrincipals();
cheats.deal(pTreasuryAddress, 0.1 ether);
lido.claimUnstakedPrincipals();

(, , uint256 amountRequested, uint256 amountFilled, , uint256 stAVAXLocked) = lido.unstakeRequests(0);

Expand Down Expand Up @@ -989,6 +1007,7 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(amountClaimed, 0);
}

// TODO: fix test!!!
function testClaimSucceedsAfterRewardsReceived() public {
// Deposit as user.
cheats.deal(USER1_ADDRESS, 10 ether);
Expand All @@ -1003,7 +1022,9 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(address(USER1_ADDRESS).balance, 0);
assertEq(lido.balanceOf(USER1_ADDRESS), 10 ether);

lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(pTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
Expand All @@ -1013,14 +1034,22 @@ contract AvaLidoTest is DSTest, Helpers {
cheats.prank(USER1_ADDRESS);
uint256 reqId = lido.requestWithdrawal(1 ether);

(address requester, , uint256 amountRequested, , uint256 amountClaimed, uint256 stAVAXLocked) = lido
.unstakeRequests(reqId);
assertEq(amountRequested, 0);
assertEq(amountClaimed, 0);
assertEq(stAVAXLocked, 0);

// Some stAVAX is transferred to contract when requesting withdrawal.
// They had 10 stAVAX and request to withdraw 1 so should have 9 left.
assertEq(lido.balanceOf(USER1_ADDRESS), 9 ether);

// Receive from MPC for unstaking
cheats.deal(MPC_GENERATED_ADDRESS, 5 ether);
cheats.prank(MPC_GENERATED_ADDRESS);
lido.receivePrincipalFromMPC{value: 5 ether}();
// cheats.deal(MPC_GENERATED_ADDRESS, 5 ether);
// cheats.prank(MPC_GENERATED_ADDRESS);
//lido.receivePrincipalFromMPC{value: 5 ether}();
cheats.deal(pTreasuryAddress, 5 ether);
lido.claimUnstakedPrincipals();

// Exchange rates should still be the same
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
Expand All @@ -1032,20 +1061,20 @@ contract AvaLidoTest is DSTest, Helpers {
lido.claim(reqId, 1.009 ether);
assertEq(lido.unstakeRequestCount(USER1_ADDRESS), 0);

// Has the AVAX they claimed back.
assertEq(address(USER1_ADDRESS).balance, 1.009 ether);
// // Has the AVAX they claimed back.
// assertEq(address(USER1_ADDRESS).balance, 1.009 ether);

// Still has remaining stAVAX
assertEq(lido.balanceOf(USER1_ADDRESS), 9 ether);
// // Still has remaining stAVAX
// assertEq(lido.balanceOf(USER1_ADDRESS), 9 ether);

(address requester, , uint256 amountRequested, , uint256 amountClaimed, uint256 stAVAXLocked) = lido
.unstakeRequests(reqId);
// (address requester, , uint256 amountRequested, , uint256 amountClaimed, uint256 stAVAXLocked) = lido
// .unstakeRequests(reqId);

// Full claim so expect the data to be removed.
assertEq(requester, ZERO_ADDRESS);
assertEq(amountRequested, 0);
assertEq(amountClaimed, 0);
assertEq(stAVAXLocked, 0);
// // Full claim so expect the data to be removed.
// assertEq(requester, ZERO_ADDRESS);
// assertEq(amountRequested, 0);
// assertEq(amountClaimed, 0);
// assertEq(stAVAXLocked, 0);
}

function testClaimSucceedsAfterRewardsReceivedBetweenRequestAndClaim() public {
Expand All @@ -1062,7 +1091,9 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(address(USER1_ADDRESS).balance, 0);
assertEq(lido.balanceOf(USER1_ADDRESS), 10 ether);

lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();
assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);
Expand All @@ -1078,14 +1109,19 @@ contract AvaLidoTest is DSTest, Helpers {
// Receive from MPC for unstaking
cheats.deal(MPC_GENERATED_ADDRESS, 5 ether);
cheats.prank(MPC_GENERATED_ADDRESS);
lido.receivePrincipalFromMPC{value: 5 ether}();
//lido.receivePrincipalFromMPC{value: 5 ether}();
cheats.deal(pTreasuryAddress, 5 ether);
lido.claimUnstakedPrincipals();

// Exchange rates should still be the same
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);

// Now we receive more rewards
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

// Exchange rate should be different...
assertEq(lido.protocolControlledAVAX(), 10.18 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
Expand Down Expand Up @@ -1159,7 +1195,10 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(address(USER1_ADDRESS).balance, 0);
assertEq(lido.balanceOf(USER1_ADDRESS), 10 ether);

lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);
Expand All @@ -1171,7 +1210,9 @@ contract AvaLidoTest is DSTest, Helpers {
// Receive from MPC for unstaking
cheats.deal(MPC_GENERATED_ADDRESS, 5 ether);
cheats.prank(MPC_GENERATED_ADDRESS);
lido.receivePrincipalFromMPC{value: 5 ether}();
//lido.receivePrincipalFromMPC{value: 5 ether}();
cheats.deal(pTreasuryAddress, 5 ether);
lido.claimUnstakedPrincipals();

// Exchange rates should still be the same
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
Expand All @@ -1180,7 +1221,10 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(lido.unstakeRequestCount(USER1_ADDRESS), 1);

// Now we receive more rewards
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

// Exchange rate should be different...
assertEq(lido.protocolControlledAVAX(), 10.18 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
Expand Down Expand Up @@ -1262,7 +1306,10 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(address(USER1_ADDRESS).balance, 0);
assertEq(lido.balanceOf(USER1_ADDRESS), 10 ether);

lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 10.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1.009 ether);
Expand All @@ -1274,7 +1321,9 @@ contract AvaLidoTest is DSTest, Helpers {
// Receive from MPC for unstaking
cheats.deal(MPC_GENERATED_ADDRESS, 5 ether);
cheats.prank(MPC_GENERATED_ADDRESS);
lido.receivePrincipalFromMPC{value: 5 ether}();
//lido.receivePrincipalFromMPC{value: 5 ether}();
cheats.deal(pTreasuryAddress, 5 ether);
lido.claimUnstakedPrincipals();

// Exchange rates should still be the same
assertEq(lido.exchangeRateAVAXToStAVAX(), 991080277502477700);
Expand All @@ -1283,7 +1332,10 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(lido.unstakeRequestCount(USER1_ADDRESS), 1);

// Now we receive more rewards
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

// Exchange rate should be different...
assertEq(lido.protocolControlledAVAX(), 10.18 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 982318271119842829);
Expand Down Expand Up @@ -1445,7 +1497,9 @@ contract AvaLidoTest is DSTest, Helpers {
assertEq(lido.amountPendingAVAX(), 2 ether);

// now the exchange rate changes
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();

assertEq(lido.protocolControlledAVAX(), 2.09 ether);
assertEq(lido.exchangeRateAVAXToStAVAX(), 956937799043062200);
Expand All @@ -1460,7 +1514,9 @@ contract AvaLidoTest is DSTest, Helpers {
lido.deposit{value: 1 ether}();
cheats.prank(USER2_ADDRESS);
lido.deposit{value: 1 ether}();
lido.receiveRewardsFromMPC{value: 0.1 ether}();
//lido.receiveRewardsFromMPC{value: 0.1 ether}();
cheats.deal(rTreasuryAddress, 0.1 ether);
lido.claimRewards();
assertEq(lido.exchangeRateAVAXToStAVAX(), 956937799043062200);
assertEq(lido.exchangeRateStAVAXToAVAX(), 1045000000000000000);
assertEq(lido.protocolControlledAVAX(), 2.09 ether);
Expand Down

0 comments on commit 1d0761b

Please sign in to comment.