Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit fa9aa1c

Browse files
authored
Feat/block tag gov votes (#580)
* fix: add optional blockhash * fix: test * chore: use options
1 parent 9a3f35c commit fa9aa1c

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

packages/contract-helpers/src/governance-contract/governance.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

packages/contract-helpers/src/governance-contract/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import {
3838
GovDelegateTokensBySig,
3939
} from './types';
4040

41+
export type Options = {
42+
blockTag?: string;
43+
};
44+
4145
export 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

packages/contract-helpers/src/wallet-balance-provider/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { providers } from 'ethers';
22
import { isAddress } from 'ethers/lib/utils';
3+
import { Options } from '../governance-contract';
4+
35
import { WalletBalanceProvider as WalletBalanceProviderContract } from './typechain/WalletBalanceProvider';
46
import { WalletBalanceProviderFactory } from './typechain/WalletBalanceProviderFactory';
7+
58
import {
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
/**

packages/contract-helpers/src/wallet-balance-provider/wallet-balance-provider.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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', () => {

0 commit comments

Comments
 (0)