Skip to content

Commit 5d41c2b

Browse files
committed
feat: updated rewards controller
1 parent d7b5fc6 commit 5d41c2b

File tree

4 files changed

+430
-46
lines changed

4 files changed

+430
-46
lines changed

packages/contract-helpers/src/umbrella/RewardsDistributor.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@ import { RewardsDistributorService } from './';
99

1010
describe('Umbrella Rewards distributor', () => {
1111
const { address: STAKE_TOKEN } = makePair('STAKE_TOKEN');
12+
const { address: STAKE_TOKEN_2 } = makePair('STAKE_TOKEN_2');
1213
const { address: ALICE } = makePair('ALICE');
1314

1415
const REWARD_1 = makePair('REWARD_1').address;
1516
const REWARD_2 = makePair('REWARD_2').address;
1617

1718
const stakeTokenService = new RewardsDistributorService(STAKE_TOKEN);
1819
const stakeTokenInterface = IRewardsDistributor__factory.createInterface();
20+
describe('claimAllAvailableRewards', () => {
21+
it('should properly create the transaction', () => {
22+
const tx = stakeTokenService.claimAllAvailableRewards({
23+
stakeTokens: [STAKE_TOKEN, STAKE_TOKEN_2],
24+
sender: ALICE,
25+
});
26+
expect(tx.from).toEqual(ALICE);
27+
expect(tx.to).toEqual(STAKE_TOKEN);
28+
expectToBeDefined(tx.gasLimit);
29+
expectToBeDefined(tx.data);
30+
expect(tx.gasLimit.toString()).toEqual(
31+
gasLimitRecommendations[ProtocolAction.umbrellaClaimAllRewards]
32+
.recommended,
33+
);
34+
const decoded = stakeTokenInterface.decodeFunctionData(
35+
'claimAllRewards(address[],address)',
36+
tx.data,
37+
);
38+
expect(decoded).toHaveLength(2);
39+
expect(decoded[0]).toEqual([STAKE_TOKEN, STAKE_TOKEN_2]);
40+
expect(decoded[1]).toEqual(ALICE);
41+
});
42+
});
1943
describe('claimAllRewards', () => {
2044
it('should properly create the transaction', () => {
2145
const tx = stakeTokenService.claimAllRewards({
@@ -31,7 +55,7 @@ describe('Umbrella Rewards distributor', () => {
3155
.recommended,
3256
);
3357
const decoded = stakeTokenInterface.decodeFunctionData(
34-
'claimAllRewards',
58+
'claimAllRewards(address,address)',
3559
tx.data,
3660
);
3761
expect(decoded).toHaveLength(2);
@@ -56,7 +80,7 @@ describe('Umbrella Rewards distributor', () => {
5680
.recommended,
5781
);
5882
const decoded = stakeTokenInterface.decodeFunctionData(
59-
'claimSelectedRewards',
83+
'claimSelectedRewards(address,address[],address)',
6084
tx.data,
6185
);
6286
expect(decoded).toHaveLength(3);

packages/contract-helpers/src/umbrella/RewardsDistributor.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { gasLimitRecommendations } from '../commons/utils';
44
import { IRewardsDistributorInterface } from './typechain/IRewardsDistributor';
55
import { IRewardsDistributor__factory } from './typechain/IRewardsDistributor__factory';
66

7+
interface RewardsDistributorClaimAllAvailableRewardsParams {
8+
stakeTokens: string[];
9+
sender: string;
10+
}
11+
712
interface RewardsDistributorClaimAllRewardsParams {
813
stakeToken: string;
914
sender: string;
@@ -22,16 +27,37 @@ export class RewardsDistributorService {
2227
this.interface = IRewardsDistributor__factory.createInterface();
2328
}
2429

30+
// Claim all rewards across all stake tokens
31+
claimAllAvailableRewards({
32+
stakeTokens,
33+
sender,
34+
}: RewardsDistributorClaimAllAvailableRewardsParams) {
35+
const tx: PopulatedTransaction = {};
36+
const receiver = sender;
37+
tx.data = this.interface.encodeFunctionData(
38+
'claimAllRewards(address[],address)',
39+
[stakeTokens, receiver],
40+
);
41+
tx.from = sender;
42+
tx.to = this.rewardsDistributorAddress;
43+
tx.gasLimit = BigNumber.from(
44+
gasLimitRecommendations[ProtocolAction.umbrellaClaimAllRewards]
45+
.recommended,
46+
);
47+
return tx;
48+
}
49+
50+
// Claim all rewards for a specific stake token
2551
claimAllRewards({
2652
stakeToken,
2753
sender,
2854
}: RewardsDistributorClaimAllRewardsParams) {
2955
const tx: PopulatedTransaction = {};
3056
const receiver = sender;
31-
const txData = this.interface.encodeFunctionData('claimAllRewards', [
32-
stakeToken,
33-
receiver,
34-
]);
57+
const txData = this.interface.encodeFunctionData(
58+
'claimAllRewards(address,address)',
59+
[stakeToken, receiver],
60+
);
3561
tx.data = txData;
3662
tx.from = sender;
3763
tx.to = this.rewardsDistributorAddress;
@@ -49,11 +75,10 @@ export class RewardsDistributorService {
4975
}: RewardsDistributorClaimSelectedRewardsParams) {
5076
const tx: PopulatedTransaction = {};
5177
const receiver = sender;
52-
const txData = this.interface.encodeFunctionData('claimSelectedRewards', [
53-
stakeToken,
54-
rewards,
55-
receiver,
56-
]);
78+
const txData = this.interface.encodeFunctionData(
79+
'claimSelectedRewards(address,address[],address)',
80+
[stakeToken, rewards, receiver],
81+
);
5782
tx.data = txData;
5883
tx.from = sender;
5984
tx.to = this.rewardsDistributorAddress;

0 commit comments

Comments
 (0)