Skip to content

Commit

Permalink
feat: token delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem committed Dec 21, 2023
1 parent 7ec0959 commit 7ec04b0
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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'),
};
}
}

0 comments on commit 7ec04b0

Please sign in to comment.