Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: double token delegation #522

Merged
merged 9 commits into from
Apr 4, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,85 @@ describe('GovernanceService', () => {
);
});
});
describe('delegateTokensBySig', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should populate the correct tx', async () => {
const instance = new AaveGovernanceService(provider, {
GOVERNANCE_ADDRESS,
GOVERNANCE_HELPER_ADDRESS,
});
const spy = jest
.spyOn(IGovernanceV2Helper__factory, 'connect')
.mockReturnValue({
populateTransaction: {
delegateTokensBySig: jest.fn(),
},
} as unknown as IGovernanceV2Helper);
const mockedUser = '0xA7499Aa6464c078EeB940da2fc95C6aCd010c3Cc';
const mockedDelegatee = '0x603696E8740b0Fa0b8aEFC202052ae757a59CF1b';
const mockedTokens = ['0xEE56e2B3D491590B5b31738cC34d5232F378a8D5'];
const mockedData = [
{
expiry: 123,
nonce: 1,
delegatee: mockedDelegatee,
v: '123',
r: '123',
s: '123',
},
];
const txs = await instance.delegateTokensBySig({
user: mockedUser,
tokens: mockedTokens,
data: mockedData,
});
expect(spy).toBeCalled();
expect(txs.length).toBe(1);
const result = await txs[0].tx();
expect(result.from).toBe(mockedUser);
});
});

describe('delegateTokensByTypeBySig', () => {
it('should work if correct parameters are supplied', async () => {
const instance = new AaveGovernanceService(provider, {
GOVERNANCE_ADDRESS,
GOVERNANCE_HELPER_ADDRESS,
});
const spy = jest
.spyOn(IGovernanceV2Helper__factory, 'connect')
.mockReturnValue({
populateTransaction: {
delegateTokensByTypeBySig: jest.fn(),
},
} as unknown as IGovernanceV2Helper);
const mockedUser = '0xA7499Aa6464c078EeB940da2fc95C6aCd010c3Cc';
const mockedDelegatee = '0x603696E8740b0Fa0b8aEFC202052ae757a59CF1b';
const mockedTokens = ['0xEE56e2B3D491590B5b31738cC34d5232F378a8D5'];
const mockedData = [
{
expiry: 123,
nonce: 1,
delegatee: mockedDelegatee,
delegationType: 1,
v: '123',
r: '123',
s: '123',
},
];
const txs = await instance.delegateTokensByTypeBySig({
user: mockedUser,
tokens: mockedTokens,
data: mockedData,
});

expect(spy).toBeCalled();
expect(txs.length).toBe(1);
const result = await txs[0].tx();
expect(result.from).toBe(mockedUser);
});
});
});
53 changes: 53 additions & 0 deletions packages/contract-helpers/src/governance-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
Power,
ProposalRPC,
Vote,
GovDelegateTokensByTypeBySig,
GovDelegateTokensBySig,
} from './types';

export const humanizeProposal = (rawProposal: ProposalRPC): Proposal => {
Expand Down Expand Up @@ -209,4 +211,55 @@ export class AaveGovernanceService

return (await govContract.getProposalsCount()).toNumber();
}

@GovHelperValidator
public async delegateTokensBySig(
@isEthAddress('user')
@isEthAddressArray('tokens')
{ user, tokens, data }: GovDelegateTokensBySig,
): Promise<EthereumTransactionTypeExtended[]> {
const helper = IGovernanceV2Helper__factory.connect(
this.aaveGovernanceV2HelperAddress,
this.provider,
);

const txCallback: () => Promise<transactionType> = this.generateTxCallback({
rawTxMethod: async () =>
helper.populateTransaction.delegateTokensBySig(tokens, data),
from: user,
});
return [
{
tx: txCallback,
txType: eEthereumTxType.GOV_DELEGATION_ACTION,
gas: this.generateTxPriceEstimation([], txCallback),
},
];
}

@GovHelperValidator
public async delegateTokensByTypeBySig(
@isEthAddress('user')
@isEthAddressArray('tokens')
{ user, tokens, data }: GovDelegateTokensByTypeBySig,
): Promise<EthereumTransactionTypeExtended[]> {
const helper = IGovernanceV2Helper__factory.connect(
this.aaveGovernanceV2HelperAddress,
this.provider,
);

const txCallback: () => Promise<transactionType> = this.generateTxCallback({
rawTxMethod: async () =>
helper.populateTransaction.delegateTokensByTypeBySig(tokens, data),
from: user,
});

return [
{
tx: txCallback,
txType: eEthereumTxType.GOV_DELEGATION_ACTION,
gas: this.generateTxPriceEstimation([], txCallback),
},
];
}
}
Loading