Skip to content

Commit db7d3a5

Browse files
authored
Merge pull request #333 from Gearbox-protocol/v4-rewards-service
fix: v4 rewards service
2 parents 38c139b + 533c081 commit db7d3a5

File tree

11 files changed

+48
-1204
lines changed

11 files changed

+48
-1204
lines changed

src/sdk/accounts/CreditAccountsService.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
type CreditAccountDataSlice,
3333
type RouterCloseResult,
3434
} from "../router";
35+
import { iBaseRewardPoolAbi } from "../sdk-legacy";
3536
import type { ILogger, MultiCall, RawTx } from "../types";
3637
import { childLogger } from "../utils";
3738
import { simulateMulticall } from "../utils/viem";
@@ -159,6 +160,14 @@ export interface PermitResult {
159160
nonce: bigint;
160161
}
161162

163+
export interface Rewards {
164+
adapter: Address;
165+
stakedPhantomToken: Address;
166+
calls: Array<MultiCall>;
167+
168+
rewards: Array<Asset>;
169+
}
170+
162171
export class CreditAccountsService extends SDKConstruct {
163172
#compressor: Address;
164173
#batchSize?: number;
@@ -288,14 +297,50 @@ export class CreditAccountsService extends SDKConstruct {
288297
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
289298
}
290299

291-
async getRewards(account: Address): Promise<RewardInfo[]> {
300+
async getRewards(creditAccount: Address): Promise<Array<Rewards>> {
292301
const rewards = await this.provider.publicClient.readContract({
293302
abi: iRewardsCompressorAbi,
294303
address: this.rewardCompressor,
295304
functionName: "getRewards",
296-
args: [account],
305+
args: [creditAccount],
297306
});
298-
return [...rewards];
307+
308+
const r = rewards.reduce<Record<string, Rewards>>((acc, r) => {
309+
const adapter = r.adapter.toLowerCase() as Address;
310+
const stakedPhantomToken = r.adapter.toLowerCase() as Address;
311+
const rewardToken = r.rewardToken.toLowerCase() as Address;
312+
313+
const key = [adapter, stakedPhantomToken].join("-");
314+
315+
if (!acc[key]) {
316+
const callData = encodeFunctionData({
317+
abi: iBaseRewardPoolAbi,
318+
functionName: "getReward",
319+
args: [],
320+
});
321+
322+
acc[adapter] = {
323+
adapter,
324+
stakedPhantomToken,
325+
calls: [
326+
{
327+
target: adapter,
328+
callData,
329+
},
330+
],
331+
rewards: [],
332+
};
333+
}
334+
335+
acc[adapter].rewards.push({
336+
token: rewardToken,
337+
balance: r.amount,
338+
});
339+
340+
return acc;
341+
}, {});
342+
343+
return Object.values(r);
299344
}
300345

301346
async getActiveBots(

src/sdk/sdk-legacy/core/rewardClaimer/aura.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/sdk/sdk-legacy/core/rewardClaimer/auraAbi.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/sdk/sdk-legacy/core/rewardClaimer/convex.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/sdk/sdk-legacy/core/rewardClaimer/index.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)