This repository was archived by the owner on Jan 8, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +53
-2
lines changed
packages/contract-helpers/src Expand file tree Collapse file tree 4 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,34 @@ describe('GovernanceService', () => {
400400 expect ( spy ) . toHaveBeenCalled ( ) ;
401401 expect ( power [ 0 ] ) . toEqual ( userPowerMock ) ;
402402 } ) ;
403+
404+ it ( 'Expects token power obj for each token asked with blocknumber' , async ( ) => {
405+ const instance = new AaveGovernanceService ( provider , {
406+ GOVERNANCE_ADDRESS ,
407+ GOVERNANCE_HELPER_ADDRESS ,
408+ } ) ;
409+
410+ const spy = jest
411+ . spyOn ( IGovernanceV2Helper__factory , 'connect' )
412+ . mockReturnValue ( {
413+ getTokensPower : async ( ) => Promise . resolve ( [ userPowerMock ] ) ,
414+ } as unknown as IGovernanceV2Helper ) ;
415+
416+ const power = await instance . getTokensPower (
417+ {
418+ user,
419+ tokens,
420+ } ,
421+ {
422+ blockTag :
423+ '0xbd04f4b86a8ca7592077f62f1b12e56e5684a69e70fb21b4c7fd47e516db71b2' ,
424+ } ,
425+ ) ;
426+
427+ expect ( spy ) . toHaveBeenCalled ( ) ;
428+ expect ( power [ 0 ] ) . toEqual ( userPowerMock ) ;
429+ } ) ;
430+
403431 it ( 'Expects to fail if gov address not eth address' , async ( ) => {
404432 const instance = new AaveGovernanceService ( provider , {
405433 GOVERNANCE_ADDRESS : 'asdf' ,
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ import {
3838 GovDelegateTokensBySig ,
3939} from './types' ;
4040
41+ export type Options = {
42+ blockTag ?: string ;
43+ } ;
44+
4145export const humanizeProposal = ( rawProposal : ProposalRPC ) : Proposal => {
4246 return {
4347 id : Number ( rawProposal . id . toString ( ) ) ,
@@ -182,13 +186,15 @@ export class AaveGovernanceService
182186 @isEthAddress ( 'user' )
183187 @isEthAddressArray ( 'tokens' )
184188 { user, tokens } : GovGetPower ,
189+ opts : Options = { } ,
185190 ) : Promise < Power [ ] > {
186191 const helper : IGovernanceV2Helper = IGovernanceV2Helper__factory . connect (
187192 this . aaveGovernanceV2HelperAddress ,
188193 this . provider ,
189194 ) ;
195+ const blockTag = opts . blockTag ? opts . blockTag : 'latest' ;
190196
191- return helper . getTokensPower ( user , tokens ) ;
197+ return helper . getTokensPower ( user , tokens , { blockTag } ) ;
192198 }
193199
194200 @GovValidator
Original file line number Diff line number Diff line change 11import { providers } from 'ethers' ;
22import { isAddress } from 'ethers/lib/utils' ;
3+ import { Options } from '../governance-contract' ;
4+
35import { WalletBalanceProvider as WalletBalanceProviderContract } from './typechain/WalletBalanceProvider' ;
46import { WalletBalanceProviderFactory } from './typechain/WalletBalanceProviderFactory' ;
7+
58import {
69 BalanceOfResponse ,
710 BatchBalanceOfResponse ,
@@ -56,6 +59,7 @@ export class WalletBalanceProvider {
5659 public async batchBalanceOf (
5760 users : string [ ] ,
5861 tokens : string [ ] ,
62+ opts : Options = { } ,
5963 ) : Promise < BatchBalanceOfResponse > {
6064 if ( ! users . every ( u => isAddress ( u ) ) ) {
6165 throw new Error (
@@ -69,7 +73,9 @@ export class WalletBalanceProvider {
6973 ) ;
7074 }
7175
72- return this . _contract . batchBalanceOf ( users , tokens ) ;
76+ const blockTag = opts . blockTag ? opts . blockTag : 'latest' ;
77+
78+ return this . _contract . batchBalanceOf ( users , tokens , { blockTag } ) ;
7379 }
7480
7581 /**
Original file line number Diff line number Diff line change @@ -84,6 +84,17 @@ describe('WalletBalanceProvider', () => {
8484 ) ,
8585 ) . resolves . not . toThrow ( ) ;
8686 } ) ;
87+
88+ it ( 'should not throw if users and tokens and blockHash are a all valid' , async ( ) => {
89+ const instance = createValidInstance ( ) ;
90+ await expect (
91+ instance . batchBalanceOf (
92+ [ mockValidEthereumAddress ] ,
93+ [ mockValidEthereumAddress ] ,
94+ { blockTag : 'latest' } ,
95+ ) ,
96+ ) . resolves . not . toThrow ( ) ;
97+ } ) ;
8798 } ) ;
8899
89100 describe ( 'getUserWalletBalancesForLendingPoolProvider' , ( ) => {
You can’t perform that action at this time.
0 commit comments