Skip to content

Commit

Permalink
feat(delegations): add getter for staked and vaulted delegations PE-7093
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Melendez committed Nov 13, 2024
1 parent c48f6ef commit 7182942
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import {
AoArNSNameData,
AoAuctionPriceData,
AoDelegation,
AoEpochData,
AoEpochSettings,
AoGateway,
Expand Down Expand Up @@ -637,6 +638,26 @@ export class IOReadable implements AoIORead {
tags: prunedPriceTags,
});
}

async getDelegations({
address,
params,
}: {
address: WalletAddress;
params?: PaginationParams<AoDelegation>;
}): Promise<PaginationResult<AoDelegation>> {
const allTags = [
{ name: 'Action', value: 'Paginated-Delegations' },
{ name: 'Cursor', value: params?.cursor?.toString() },
{ name: 'Limit', value: params?.limit?.toString() },
{ name: 'Sort-By', value: params?.sortBy },
{ name: 'Sort-Order', value: params?.sortOrder },
{ name: 'Address', value: address },
];
return this.process.read<PaginationResult<AoDelegation>>({
tags: pruneTags(allTags),
});
}
}

export class IOWriteable extends IOReadable implements AoIOWrite {
Expand Down
21 changes: 21 additions & 0 deletions src/types/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ export type AoAuctionPriceData = {
currentPrice: number;
};

export type AoDelegationBase = {
type: 'stake' | 'vault';
gatewayAddress: WalletAddress;
delegationId: string;
};

export type AoVaultDelegation = AoDelegationBase &
AoVaultData & {
type: 'vault';
vaultId: TransactionId;
};

export type AoStakeDelegation = Omit<
AoVaultDelegation,
'endTimestamp' | 'vaultId'
> & {
type: 'stake';
};

export type AoDelegation = AoStakeDelegation | AoVaultDelegation;

// Input types

// TODO: confirm what is required or if all can be optional and defaults will be provided
Expand Down

0 comments on commit 7182942

Please sign in to comment.