diff --git a/src/common/io.ts b/src/common/io.ts index 24b31c68..f2fd1b4d 100644 --- a/src/common/io.ts +++ b/src/common/io.ts @@ -42,6 +42,7 @@ import { import { AoArNSNameData, AoAuctionPriceData, + AoDelegation, AoEpochData, AoEpochSettings, AoGateway, @@ -637,6 +638,26 @@ export class IOReadable implements AoIORead { tags: prunedPriceTags, }); } + + async getDelegations({ + address, + params, + }: { + address: WalletAddress; + params?: PaginationParams; + }): Promise> { + 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>({ + tags: pruneTags(allTags), + }); + } } export class IOWriteable extends IOReadable implements AoIOWrite { diff --git a/src/types/io.ts b/src/types/io.ts index 055b49e4..32eeda0c 100644 --- a/src/types/io.ts +++ b/src/types/io.ts @@ -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