// Copyright © Endless // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 import { EndlessConfig } from "../api/endlessConfig"; import { getEndlessIndexer, postEndlessIndexer } from "../client"; import { AccountAddress, AccountAddressInput } from "../core"; import { DelegatedPoolResponse, DelegationPoolResponse, PoolRewardResponse } from "../types"; export async function getDelegationPools(args: { endlessConfig: EndlessConfig; user?: AccountAddressInput; }): Promise { const { endlessConfig, user } = args; const { data } = await getEndlessIndexer<{}, DelegationPoolResponse[]>({ endlessConfig, originMethod: "getDelegationPools", path: "stake/delegation_pools", params: { user: user ? AccountAddress.from(user).toStringLong() : undefined, }, }); return data; } export async function batchGetPoolRewards(args: { endlessConfig: EndlessConfig; pools: AccountAddressInput[]; }): Promise { const { endlessConfig, pools } = args; const { data } = await postEndlessIndexer<{}, PoolRewardResponse[]>({ endlessConfig, originMethod: "batchGetPoolRewards", path: "stake/rewards", body: pools.map((pool) => AccountAddress.from(pool).toString()), }); return data; } export async function getPoolRewards(args: { endlessConfig: EndlessConfig; pool: AccountAddressInput; }): Promise { const { endlessConfig, pool } = args; const { data } = await getEndlessIndexer<{}, PoolRewardResponse>({ endlessConfig, originMethod: "getPoolRewards", path: `stake/${AccountAddress.from(pool).toString()}/rewards`, }); return data; } export async function getDelegatedPools(args: { endlessConfig: EndlessConfig; user: AccountAddressInput; }): Promise { const { endlessConfig, user } = args; const { data } = await getEndlessIndexer<{}, DelegatedPoolResponse[]>({ endlessConfig, originMethod: "getDelegatedPools", path: `stake/${AccountAddress.from(user).toString()}/delegated`, }); return data; }