From 40ce9552a8df44f564d3508db12e5652e4d9c8f2 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 3 Jan 2024 13:26:54 -0600 Subject: [PATCH] fix: domain --- .../src/staking-contract/index.ts | 14 ++++++-------- .../src/staking-contract/staking.test.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/contract-helpers/src/staking-contract/index.ts b/packages/contract-helpers/src/staking-contract/index.ts index b716a02d..44091840 100644 --- a/packages/contract-helpers/src/staking-contract/index.ts +++ b/packages/contract-helpers/src/staking-contract/index.ts @@ -72,8 +72,6 @@ export class StakingService readonly erc20_2612Service: ERC20_2612Interface; - readonly aaveTokenV3Service: AaveTokenV3Service; - constructor( provider: providers.Provider, stakingServiceConfig: StakingServiceConfig, @@ -84,11 +82,6 @@ export class StakingService this.erc20_2612Service = new ERC20_2612Service(provider); - this.aaveTokenV3Service = new AaveTokenV3Service( - stakingServiceConfig.TOKEN_STAKING_ADDRESS, - provider, - ); - this.stakingContractAddress = stakingServiceConfig.TOKEN_STAKING_ADDRESS; } @@ -107,7 +100,12 @@ export class StakingService const { decimals } = await getTokenData(stakedToken); const convertedAmount: string = valueToWei(amount, decimals); const { chainId } = await this.provider.getNetwork(); - const { name, version } = await this.aaveTokenV3Service.getEip712Domain(); + + const aaveTokenV3Service = new AaveTokenV3Service( + this.stakingContractAddress, + this.provider, + ); + const { name, version } = await aaveTokenV3Service.getEip712Domain(); const nonce = await this.erc20_2612Service.getNonce({ token: stakedToken, diff --git a/packages/contract-helpers/src/staking-contract/staking.test.ts b/packages/contract-helpers/src/staking-contract/staking.test.ts index 0ef10792..5b86cb55 100644 --- a/packages/contract-helpers/src/staking-contract/staking.test.ts +++ b/packages/contract-helpers/src/staking-contract/staking.test.ts @@ -6,6 +6,8 @@ import { transactionType, } from '../commons/types'; import { gasLimitRecommendations, valueToWei } from '../commons/utils'; +import { AaveTokenV3 } from '../governance-v3/typechain/AaveTokenV3'; +import { AaveTokenV3__factory } from '../governance-v3/typechain/factories/AaveTokenV3__factory'; import { StakedAaveV3 } from './typechain/IStakedAaveV3'; import { StakedAaveV3__factory } from './typechain/IStakedAaveV3__factory'; import { StakingService } from './index'; @@ -75,6 +77,20 @@ describe('StakingService', () => { Promise.resolve('0x0000000000000000000000000000000000000006'), } as unknown as StakedAaveV3); + const aaveV3TokenSpy = jest + .spyOn(AaveTokenV3__factory, 'connect') + .mockReturnValue({ + functions: { + eip712Domain: async () => + Promise.resolve({ + name: 'mockToken', + version: '2', + chainId: BigNumber.from(1), + verifyingContract: TOKEN_STAKING_ADDRESS, + }), + }, + } as unknown as AaveTokenV3); + const nonce = 1; jest @@ -88,6 +104,7 @@ describe('StakingService', () => { ); expect(spy).toHaveBeenCalled(); + expect(aaveV3TokenSpy).toHaveBeenCalled(); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { primaryType, domain, message } = await JSON.parse(signature);