Skip to content

Commit

Permalink
fix: domain
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem committed Jan 3, 2024
1 parent b6faacd commit 40ce955
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/contract-helpers/src/staking-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export class StakingService

readonly erc20_2612Service: ERC20_2612Interface;

readonly aaveTokenV3Service: AaveTokenV3Service;

constructor(
provider: providers.Provider,
stakingServiceConfig: StakingServiceConfig,
Expand All @@ -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;
}

Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions packages/contract-helpers/src/staking-contract/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 40ce955

Please sign in to comment.