diff --git a/packages/paima-sdk/paima-utils-backend/src/cde-access-internals.ts b/packages/paima-sdk/paima-utils-backend/src/cde-access-internals.ts index 2a8358913..5ea1dc2db 100644 --- a/packages/paima-sdk/paima-utils-backend/src/cde-access-internals.ts +++ b/packages/paima-sdk/paima-utils-backend/src/cde-access-internals.ts @@ -12,6 +12,7 @@ import { cdeGenericGetRangeData, cdeErc6551GetOwnedAccounts, cdeErc6551GetOwner, + cdeCardanoPoolGetAddressDelegation, } from '@paima/db'; import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types'; @@ -177,3 +178,15 @@ export async function internalGetAllOwnedErc6551Accounts( ); return results.map(row => row.account_created); } + +export async function internalGetCardanoAddressDelegation( + readonlyDBConn: Pool, + address: string +): Promise { + const results = await cdeCardanoPoolGetAddressDelegation.run({ address }, readonlyDBConn); + if (results.length === 0) { + return null; + } + + return results[0].pool; +} diff --git a/packages/paima-sdk/paima-utils-backend/src/cde-access.ts b/packages/paima-sdk/paima-utils-backend/src/cde-access.ts index d9d41f9df..dc4f3d753 100644 --- a/packages/paima-sdk/paima-utils-backend/src/cde-access.ts +++ b/packages/paima-sdk/paima-utils-backend/src/cde-access.ts @@ -12,6 +12,7 @@ import { internalGetGenericDataBlockheightRange, internalGetErc6551AccountOwner, internalGetAllOwnedErc6551Accounts, + internalGetCardanoAddressDelegation, } from './cde-access-internals'; import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types'; @@ -156,3 +157,13 @@ export async function getAllOwnedErc6551Accounts( if (cdeId === null) return []; return await internalGetAllOwnedErc6551Accounts(readonlyDBConn, cdeId, nft); } + +/** + * Fetch the pool this address is delegating to, if any. + */ +export async function getCardanoAddressDelegation( + readonlyDBConn: Pool, + address: string +): Promise { + return await internalGetCardanoAddressDelegation(readonlyDBConn, address); +}