Skip to content

Commit

Permalink
feat: add Aave v2 incentives read functions (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
iherger authored Oct 3, 2023
1 parent dcc5c92 commit 10dc299
Showing 1 changed file with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Viem } from "@enzymefinance/sdk/Utils";
import * as ExternalPositionManager from "@enzymefinance/sdk/internal/ExternalPositionManager";
import { type Address, type Hex, decodeAbiParameters, encodeAbiParameters } from "viem";
import { type Address, type Hex, type PublicClient, decodeAbiParameters, encodeAbiParameters } from "viem";

export type Action = typeof Action[keyof typeof Action];
export const Action = {
Expand Down Expand Up @@ -155,3 +156,58 @@ export function repayBorrowDecode(encoded: Hex): RepayBorrowArgs {
amounts,
};
}

//--------------------------------------------------------------------------------------------
// EXTERNAL CONTRACT METHODS
//--------------------------------------------------------------------------------------------

const aaveIncentivesControllerAbi = [
{
inputs: [
{ internalType: "address[]", name: "assets", type: "address[]" },
{ internalType: "address", name: "user", type: "address" },
],
name: "getRewardsBalance",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [{ internalType: "address", name: "_user", type: "address" }],
name: "getUserUnclaimedRewards",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
] as const;

export async function getRewardsBalance(
client: PublicClient,
args: Viem.ContractCallParameters<{
aaveIncentivesController: Address;
assets: Address[];
user: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: aaveIncentivesControllerAbi,
functionName: "getRewardsBalance",
address: args.aaveIncentivesController,
args: [args.assets, args.user],
});
}

export async function getUserUnclaimedRewards(
client: PublicClient,
args: Viem.ContractCallParameters<{
aaveIncentivesController: Address;
user: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: aaveIncentivesControllerAbi,
functionName: "getUserUnclaimedRewards",
address: args.aaveIncentivesController,
args: [args.user],
});
}

0 comments on commit 10dc299

Please sign in to comment.