Skip to content

Commit

Permalink
add getEarnedUser function on staking contract
Browse files Browse the repository at this point in the history
  • Loading branch information
hapetherw committed Apr 30, 2024
1 parent d2609c4 commit a6fba67
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 186 deletions.
19 changes: 19 additions & 0 deletions contracts/abis/LDYStaking.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "getEarnedUser",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
42 changes: 40 additions & 2 deletions contracts/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -30128,6 +30128,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "getEarnedUser",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -30689,7 +30708,7 @@
]
},
"LDYStaking_Implementation": {
"address": "0x1157f1b171DC382165389c43a70De2E73da3645E",
"address": "0xFFF42672fb476afe698142A9B6211b772b89b8Ee",
"abi": [
{
"inputs": [],
Expand Down Expand Up @@ -30930,6 +30949,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "getEarnedUser",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -33402,7 +33440,7 @@
]
},
"LUSDC_Implementation": {
"address": "0x2c0F4C6127693C688ff4b8794fdB22FfB235cd87",
"address": "0xE0434e00f3088Ed0cE950F985f9dbe9898A18153",
"abi": [
{
"anonymous": false,
Expand Down
20 changes: 20 additions & 0 deletions contracts/foundry/test/LDYStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ contract LDYStakingTest is Test, ModifiersExpectations {
ldyStaking.stake(amount2, stakingPeriodIndex2);
vm.stopPrank();

// check the lenght of earnedArray
uint256[] memory earnedArray = ldyStaking.getEarnedUser(account1);
assertEq(earnedArray.length, 2);

// account1 unstakes token from staking pool 1
uint256 skipDuration1 = stakingDurations[stakingPeriodIndex1];
skip(skipDuration1);
Expand All @@ -338,6 +342,10 @@ contract LDYStakingTest is Test, ModifiersExpectations {
vm.stopPrank();
assertEq(ldyToken.balanceOf(account1), amount1 + earned1);

// check the lenght of earnedArray
earnedArray = ldyStaking.getEarnedUser(account1);
assertEq(earnedArray.length, 1);

// account1 unstakes token from staking pool 2
uint256 skipDuration2 = stakingDurations[stakingPeriodIndex2];
skip(skipDuration2);
Expand All @@ -346,6 +354,10 @@ contract LDYStakingTest is Test, ModifiersExpectations {
ldyStaking.unstake(amount2, 0);
vm.stopPrank();
assertEq(ldyToken.balanceOf(account1), amount1 + earned1 + amount2 + earned2);

// check the lenght of earnedArray
earnedArray = ldyStaking.getEarnedUser(account1);
assertEq(earnedArray.length, 0);
}

function testFuzz_Unstake_2(address account, uint256 amount, uint8 stakingPeriodIndex) public {
Expand Down Expand Up @@ -374,6 +386,10 @@ contract LDYStakingTest is Test, ModifiersExpectations {
vm.stopPrank();
assertEq(ldyToken.balanceOf(account), partAmount);

// check the lenght of earnedArray
uint256[] memory earnedArray = ldyStaking.getEarnedUser(account);
assertEq(earnedArray.length, 1);

// account unstakes rest of token after 100 secs
uint256 restAmount = amount - partAmount;
skip(100);
Expand All @@ -383,6 +399,10 @@ contract LDYStakingTest is Test, ModifiersExpectations {
ldyStaking.unstake(restAmount, 0);
vm.stopPrank();
assertEq(ldyToken.balanceOf(account), amount + earned);

// check the lenght of earnedArray
earnedArray = ldyStaking.getEarnedUser(account);
assertEq(earnedArray.length, 0);
}

function testFuzz_GetReward_Failed(
Expand Down
41 changes: 21 additions & 20 deletions contracts/hardhat/deployments/baseSepolia/LDYStaking.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions contracts/hardhat/deployments/baseSepolia/LUSDC.json

Large diffs are not rendered by default.

176 changes: 88 additions & 88 deletions contracts/hardhat/deployments/baseSepolia/LUSDC_Implementation.json

Large diffs are not rendered by default.

Loading

0 comments on commit a6fba67

Please sign in to comment.