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: add Aave v2 incentives read functions #176

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
});
}
Loading