Skip to content

Commit

Permalink
Add AavePoolAPIResponseAny, GetReserveDataParams; implement getUserAc…
Browse files Browse the repository at this point in the history
…countData and getReserveData functions.
  • Loading branch information
Munchies69 committed Oct 7, 2024
1 parent 936c7f3 commit f62f9ac
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions packages/moon-react/src/hooks/useMoonAaveV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Aave,
GetAllATokensParams,
PoolAddressProviderRegistryAPIResponseAnyArray,
AavePoolAPIResponseAny,
GetReserveDataParams,
} from "@moonup/moon-api";

type NetworkConfigType = {
Expand Down Expand Up @@ -110,8 +112,6 @@ export const useMoonAaveV3 = () => {
const { handleTransaction } = useMoonTransaction();
const { moon } = context;



const getAaveSDK = useCallback((): Aave => {
const aaveSDK = moon?.getAaveSDK();
if (!aaveSDK) throw new Error("Moon aaveSDK not initialized");
Expand Down Expand Up @@ -304,7 +304,7 @@ export const useMoonAaveV3 = () => {
async (
payload: GetAllATokensParams
): Promise<PoolAddressProviderRegistryAPIResponseAnyArray> => {
return handleTransaction("getUserRewards", async () => {
return handleTransaction("getAllATokens", async () => {
const avveSDK = getAaveSDK();
const response = await avveSDK.getAllATokens(payload);
return response;
Expand All @@ -313,6 +313,44 @@ export const useMoonAaveV3 = () => {
[moon]
);

const getUserAccountData = useCallback(
async (payload: {
account: string;
chainId: string;
}): Promise<AavePoolAPIResponseAny> => {
return handleTransaction("getUserAccountData", async () => {
const avveSDK = getAaveSDK();
const poolAdd = await getAaveV3PoolAddress(
payload.account,
payload.chainId
);
if (!poolAdd) {
throw new Error("Market pool Address not found");
}
const response = await avveSDK.getUserAccountData({
account: payload.account,
address: poolAdd,
chainId: payload.chainId,
user: payload.account,
});
return response;
});
},
[moon]
);

const getReserveData = useCallback(
async (payload: GetReserveDataParams): Promise<AavePoolAPIResponseAny> => {
return handleTransaction("getReserveData", async () => {
const avveSDK = getAaveSDK();

const response = await avveSDK.getReserveData(payload);
return response;
});
},
[moon]
);

return {
supply,
withdraw,
Expand All @@ -326,6 +364,8 @@ export const useMoonAaveV3 = () => {
getUserRewards,
getAaveV3PoolAddress,
getAllATokens,
getUserAccountData,
getReserveData,
networkConfig,
};
};

0 comments on commit f62f9ac

Please sign in to comment.