@@ -32,6 +32,7 @@ import {
3232 type CreditAccountDataSlice ,
3333 type RouterCloseResult ,
3434} from "../router" ;
35+ import { iBaseRewardPoolAbi } from "../sdk-legacy" ;
3536import type { ILogger , MultiCall , RawTx } from "../types" ;
3637import { childLogger } from "../utils" ;
3738import { 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+
162171export 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 (
0 commit comments