Skip to content

Commit

Permalink
feat(distributions): remove eligible rewards from get epoch return PE…
Browse files Browse the repository at this point in the history
…-7641
  • Loading branch information
fedellen committed Feb 17, 2025
1 parent 8810ec6 commit 4437eaa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
AoGatewayRegistrySettings,
AoGatewayVault,
AoGetCostDetailsParams,
AoGetEpochResult,
AoIncreaseUndernameLimitParams,
AoIncreaseVaultParams,
AoPaginatedAddressParams,
Expand All @@ -83,6 +84,7 @@ import {
getEpochDataFromGql,
paginationParamsToTags,
pruneTags,
removeEligibleDistributionsFromEpochData,
sortAndPaginateEpochDataIntoEligibleDistributions,
} from '../utils/arweave.js';
import { defaultArweave } from './arweave.js';
Expand Down Expand Up @@ -202,7 +204,7 @@ export class ARIOReadable implements AoARIORead {
}));
}

async getEpoch(epoch?: EpochInput): Promise<AoEpochData | undefined> {
async getEpoch(epoch?: EpochInput): Promise<AoGetEpochResult | undefined> {
const epochIndex = await this.computeEpochIndex(epoch);
const currentIndex = await this.computeCurrentEpochIndex();
if (epochIndex !== undefined && epochIndex < currentIndex) {
Expand All @@ -211,7 +213,8 @@ export class ARIOReadable implements AoARIORead {
epochIndex: epochIndex,
processId: this.process.processId,
});
return epochData;

return removeEligibleDistributionsFromEpochData(epochData);
}
// go to the process epoch and fetch the epoch data
const allTags = [
Expand Down
18 changes: 15 additions & 3 deletions src/types/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export type AoEpochDistributionRewards = {
distributed?: Record<WalletAddress, number>;
};

export type AoGetEpochDistributionRewards = Omit<
AoEpochDistributionRewards,
'eligible'
>;

export type AoGetEpochDistributionData = AoEpochDistributionData & {
rewards: AoGetEpochDistributionRewards;
};

export type AoEpochDistributionData = {
rewards: AoEpochDistributionRewards;
totalEligibleGateways: number;
Expand Down Expand Up @@ -173,7 +182,6 @@ export type AoEpochData = {
startTimestamp: Timestamp;
endTimestamp: Timestamp;
distributionTimestamp: Timestamp;
/** @deprecated - use `getDistributions` to get distribution data for a given epoch **/
distributions: AoEpochDistributionData;
arnsStats: {
totalReturnedNames: number;
Expand All @@ -183,7 +191,11 @@ export type AoEpochData = {
};
};

export type AoEligibleReward = {
export type AoGetEpochResult = Omit<AoEpochData, 'distributions'> & {
distributions?: AoGetEpochDistributionData;
};

export type AoEligibleDistribution = {
type: 'operatorReward' | 'delegateReward';
recipient: WalletAddress;
eligibleReward: number;
Expand Down Expand Up @@ -604,7 +616,7 @@ export interface AoARIORead {
}: {
name: string;
}): Promise<AoReturnedName | undefined>;
getEpoch(epoch?: EpochInput): Promise<AoEpochData | undefined>;
getEpoch(epoch?: EpochInput): Promise<AoGetEpochResult | undefined>;
getCurrentEpoch(): Promise<AoEpochData>;
getPrescribedObservers(
epoch?: EpochInput,
Expand Down
20 changes: 20 additions & 0 deletions src/utils/arweave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { BlockHeight } from '../types/common.js';
import {
AoEligibleDistribution,
AoEpochData,
AoGetEpochResult,
PaginationParams,
PaginationResult,
} from '../types/io.js';
Expand Down Expand Up @@ -227,3 +228,22 @@ export function sortAndPaginateEpochDataIntoEligibleDistributions(
sortBy,
};
}

export function removeEligibleDistributionsFromEpochData(
epochData?: AoEpochData,
): AoGetEpochResult | undefined {
if (epochData === undefined) {
return undefined;
}
return {
...epochData,
distributions: {
...epochData.distributions,
rewards: {
...epochData.distributions.rewards,
// @ts-expect-error -- remove eligible
eligible: undefined,
},
},
};
}

0 comments on commit 4437eaa

Please sign in to comment.