Skip to content

Commit

Permalink
fix: staked token types
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem committed Jan 3, 2024
1 parent 666caa6 commit a59b646
Show file tree
Hide file tree
Showing 5 changed files with 1,546 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,20 @@ export class AaveTokenV3Service {
});
}

public async getPowers(
user: string,
) {
public async getPowers(user: string) {
const powers = await this._contract.getPowersCurrent(user);
return {
votingPower: powers[0],
propositionPower: powers[1]
}
propositionPower: powers[1],
};
}

public async getDelegateeData(
user: string,
) {
public async getDelegateeData(user: string) {
const data = await this._contract.getDelegates(user);
return {
votingDelegatee: data[0],
propositionDelegatee: data[1],
}
};
}

public getDelegateTxData(
Expand Down
22 changes: 11 additions & 11 deletions packages/contract-helpers/src/staking-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
} from '../commons/validators/paramValidators';
import { ERC20_2612Interface, ERC20_2612Service } from '../erc20-2612';
import { ERC20Service, IERC20ServiceInterface } from '../erc20-contract';
import { IStakedAaveV3 } from './typechain/IStakedAaveV3';
import { IStakedAaveV3__factory } from './typechain/IStakedAaveV3__factory';
import { StakedAaveV3 } from './typechain/IStakedAaveV3';
import { StakedAaveV3__factory } from './typechain/IStakedAaveV3__factory';

export interface StakingInterface {
stakingContractAddress: tEthereumAddress;
Expand Down Expand Up @@ -62,7 +62,7 @@ type StakingServiceConfig = {
};

export class StakingService
extends BaseService<IStakedAaveV3>
extends BaseService<StakedAaveV3>
implements StakingInterface
{
public readonly stakingContractAddress: tEthereumAddress;
Expand All @@ -75,7 +75,7 @@ export class StakingService
provider: providers.Provider,
stakingServiceConfig: StakingServiceConfig,
) {
super(provider, IStakedAaveV3__factory);
super(provider, StakedAaveV3__factory);

this.erc20Service = new ERC20Service(provider);

Expand All @@ -91,7 +91,7 @@ export class StakingService
deadline: string,
): Promise<string> {
const { getTokenData } = this.erc20Service;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
// eslint-disable-next-line new-cap
Expand Down Expand Up @@ -153,7 +153,7 @@ export class StakingService
): Promise<EthereumTransactionTypeExtended[]> {
const txs: EthereumTransactionTypeExtended[] = [];
const { decimalsOf } = this.erc20Service;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
// eslint-disable-next-line new-cap
Expand Down Expand Up @@ -195,7 +195,7 @@ export class StakingService
): Promise<EthereumTransactionTypeExtended[]> {
const txs: EthereumTransactionTypeExtended[] = [];
const { decimalsOf, isApproved, approve } = this.erc20Service;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
// eslint-disable-next-line new-cap
Expand Down Expand Up @@ -247,7 +247,7 @@ export class StakingService
@isPositiveOrMinusOneAmount() amount: string,
): Promise<EthereumTransactionTypeExtended[]> {
let convertedAmount: string;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
if (amount === '-1') {
Expand Down Expand Up @@ -281,7 +281,7 @@ export class StakingService
public cooldown(
@isEthAddress() user: tEthereumAddress,
): EthereumTransactionTypeExtended[] {
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);

Expand All @@ -305,7 +305,7 @@ export class StakingService
@isPositiveOrMinusOneAmount() amount: string,
): Promise<EthereumTransactionTypeExtended[]> {
let convertedAmount: string;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
if (amount === '-1') {
Expand Down Expand Up @@ -345,7 +345,7 @@ export class StakingService
@isPositiveOrMinusOneAmount() amount: string,
): Promise<EthereumTransactionTypeExtended[]> {
let convertedAmount: string;
const stakingContract: IStakedAaveV3 = this.getContractInstance(
const stakingContract: StakedAaveV3 = this.getContractInstance(
this.stakingContractAddress,
);
if (amount === '-1') {
Expand Down
124 changes: 53 additions & 71 deletions packages/contract-helpers/src/staking-contract/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
transactionType,
} from '../commons/types';
import { gasLimitRecommendations, valueToWei } from '../commons/utils';
import { IStakedAaveV3 } from './typechain/IStakedAaveV3';
import { IStakedAaveV3__factory } from './typechain/IStakedAaveV3__factory';
import { StakedAaveV3 } from './typechain/IStakedAaveV3';
import { StakedAaveV3__factory } from './typechain/IStakedAaveV3__factory';
import { StakingService } from './index';

jest.mock('../commons/gasStation', () => {
Expand Down Expand Up @@ -70,12 +70,10 @@ describe('StakingService', () => {
address: '0x0000000000000000000000000000000000000006',
}),
);
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);

const nonce = 1;

Expand Down Expand Up @@ -155,10 +153,10 @@ describe('StakingService', () => {
address: '0x0000000000000000000000000000000000000006',
}),
);
jest.spyOn(IStakedAaveV3__factory, 'connect').mockReturnValue({
jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
} as unknown as StakedAaveV3);

jest
.spyOn(instance.erc20_2612Service, 'getNonce')
Expand All @@ -178,7 +176,7 @@ describe('StakingService', () => {
const signature =
'0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c';

const { populateTransaction } = IStakedAaveV3__factory.connect(
const { populateTransaction } = StakedAaveV3__factory.connect(
TOKEN_STAKING_ADDRESS,
provider,
);
Expand All @@ -195,13 +193,11 @@ describe('StakingService', () => {
.spyOn(instance.erc20Service, 'decimalsOf')
.mockReturnValue(Promise.resolve(decimals));

const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);

const stakeTxObj = await instance.stakeWithPermit(
user,
Expand Down Expand Up @@ -287,18 +283,16 @@ describe('StakingService', () => {
jest.clearAllMocks();
});

const { populateTransaction } = IStakedAaveV3__factory.connect(
const { populateTransaction } = StakedAaveV3__factory.connect(
TOKEN_STAKING_ADDRESS,
provider,
);
it('Expects the tx object when all params passed with no approval needed', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, { TOKEN_STAKING_ADDRESS });

jest
Expand Down Expand Up @@ -339,13 +333,11 @@ describe('StakingService', () => {
expect(gasPrice?.gasPrice).toEqual('1');
});
it('Expects the tx object when all params passed and no onBehalfOf with approval needed', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, { TOKEN_STAKING_ADDRESS });

jest
Expand Down Expand Up @@ -441,18 +433,16 @@ describe('StakingService', () => {
jest.clearAllMocks();
});

const { populateTransaction } = IStakedAaveV3__factory.connect(
const { populateTransaction } = StakedAaveV3__factory.connect(
TOKEN_STAKING_ADDRESS,
provider,
);
it('Expects the tx object when all params passed and specific amount', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, { TOKEN_STAKING_ADDRESS });

jest
Expand Down Expand Up @@ -485,13 +475,11 @@ describe('StakingService', () => {
expect(gasPrice?.gasPrice).toEqual('1');
});
it('Expects the tx object when all params passed and -1 amount', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, { TOKEN_STAKING_ADDRESS });

const amount = '-1';
Expand Down Expand Up @@ -556,18 +544,16 @@ describe('StakingService', () => {
jest.clearAllMocks();
});

const { populateTransaction } = IStakedAaveV3__factory.connect(
const { populateTransaction } = StakedAaveV3__factory.connect(
TOKEN_STAKING_ADDRESS,
provider,
);
it('Expects the tx object when all params passed and specific amount', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, {
TOKEN_STAKING_ADDRESS,
});
Expand Down Expand Up @@ -608,13 +594,11 @@ describe('StakingService', () => {
expect(gasPrice?.gasPrice).toEqual('1');
});
it('Expects the tx object when all params passed and -1 amount', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
STAKED_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, {
TOKEN_STAKING_ADDRESS,
});
Expand Down Expand Up @@ -744,18 +728,16 @@ describe('StakingService', () => {
jest.clearAllMocks();
});

const { populateTransaction } = IStakedAaveV3__factory.connect(
const { populateTransaction } = StakedAaveV3__factory.connect(
TOKEN_STAKING_ADDRESS,
provider,
);
it('Expects the tx object when all params passed with specific amount', async () => {
const spy = jest
.spyOn(IStakedAaveV3__factory, 'connect')
.mockReturnValue({
populateTransaction,
REWARD_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as IStakedAaveV3);
const spy = jest.spyOn(StakedAaveV3__factory, 'connect').mockReturnValue({
populateTransaction,
REWARD_TOKEN: async () =>
Promise.resolve('0x0000000000000000000000000000000000000006'),
} as unknown as StakedAaveV3);
const instance = new StakingService(provider, { TOKEN_STAKING_ADDRESS });

jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export declare namespace DistributionTypes {
};
}

export interface IStakedAaveV3Interface extends utils.Interface {
export interface StakedAaveV3Interface extends utils.Interface {
functions: {
'CLAIM_HELPER_ROLE()': FunctionFragment;
'COOLDOWN_ADMIN_ROLE()': FunctionFragment;
Expand Down Expand Up @@ -1041,7 +1041,7 @@ export type UserIndexUpdatedEvent = TypedEvent<
export type UserIndexUpdatedEventFilter =
TypedEventFilter<UserIndexUpdatedEvent>;

export interface IStakedAaveV3 extends BaseContract {
export interface StakedAaveV3 extends BaseContract {
connect(signerOrProvider: Signer | Provider | string): this;
attach(addressOrName: string): this;
deployed(): Promise<this>;
Expand Down
Loading

0 comments on commit a59b646

Please sign in to comment.