From 7ec04b025cebd9f9f6eb0c1b7d4dd0960f354110 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Thu, 21 Dec 2023 09:59:39 -0600 Subject: [PATCH] feat: token delegate --- .../src/governance-v3/aave-token-v3/index.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/contract-helpers/src/governance-v3/aave-token-v3/index.ts b/packages/contract-helpers/src/governance-v3/aave-token-v3/index.ts index 22f9bcca..6f0b4c7b 100644 --- a/packages/contract-helpers/src/governance-v3/aave-token-v3/index.ts +++ b/packages/contract-helpers/src/governance-v3/aave-token-v3/index.ts @@ -1,14 +1,16 @@ -import { providers } from 'ethers'; +import { BigNumber, PopulatedTransaction, providers } from 'ethers'; import { AaveTokenV3 } from '../typechain/AaveTokenV3'; import { AaveTokenV3__factory } from '../typechain/factories/AaveTokenV3__factory'; export enum GovernancePowerType { VOTING, PROPOSITION, + ALL, } export class AaveTokenV3Service { readonly _contract: AaveTokenV3; + readonly _contractInterface = AaveTokenV3__factory.createInterface(); constructor(tokenAddress: string, provider: providers.Provider) { this._contract = AaveTokenV3__factory.connect(tokenAddress, provider); @@ -27,4 +29,29 @@ export class AaveTokenV3Service { blockTag: blockNumber, }); } + + public getDelegateTxData( + user: string, + delegateTo: string, + type: GovernancePowerType, + ): PopulatedTransaction { + const tx: PopulatedTransaction = {}; + if (type === GovernancePowerType.ALL) { + tx.data = this._contractInterface.encodeFunctionData('delegate', [ + delegateTo, + ]); + } else { + tx.data = this._contractInterface.encodeFunctionData('delegateByType', [ + delegateTo, + type, + ]); + } + + return { + ...tx, + to: this._contract.address, + from: user, + gasLimit: BigNumber.from('1000000'), + }; + } }