From d0d78500b79191707e59d3cf6f01ded1d64e071d Mon Sep 17 00:00:00 2001 From: sanjay-del Date: Tue, 26 Mar 2024 06:50:53 +0545 Subject: [PATCH 1/4] Supporting types for delegation history and address cred balance --- src/api/accounts/type.ts | 22 ++++++++++++ src/api/type.ts | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/api/accounts/type.ts b/src/api/accounts/type.ts index e2b9d09..df29ef8 100644 --- a/src/api/accounts/type.ts +++ b/src/api/accounts/type.ts @@ -114,3 +114,25 @@ export interface AccountUpdatesQueryParams { */ cursor?: string | null; } + +/** + * Query parameters for accountDelegationHistory. + * @export + * @interface AccountDelegationHistoryQueryParams + * + */ +export interface AccountDelegationHistoryQueryParams { + /** + * The max number of results per page. + * @type {number | null} + * @memberof AccountDelegationHistoryQueryParams + */ + count?: number | null; + + /** + * Pagination cursor string, use the cursor included in a page of results to fetch the next page. + * @type {string | null} + * @memberof AccountDelegationHistoryQueryParams + */ + cursor?: string | null; +} diff --git a/src/api/type.ts b/src/api/type.ts index 16e0eba..c1e1cd0 100644 --- a/src/api/type.ts +++ b/src/api/type.ts @@ -15,6 +15,33 @@ export const AccountAction = { export type AccountAction = (typeof AccountAction)[keyof typeof AccountAction]; +/** + * Per-epoch information about a stake account + * @export + * @interface AccountDelegationHistory + */ +export interface AccountDelegationHistory { + /** + * Epoch number in which the delegation becomes active + * @type {number} + * @memberof AccountDelegationHistory + */ + active_epoch_no: number; + /** + * Bech32 encoded pool ID the account was delegated to + * @type {string} + * @memberof AccountDelegationHistory + */ + pool_id: string; + + /** + * Absolute slot of the block which contained the transactio + * @type {number} + * @memberof AccountDelegationHistory + */ + slot: number; +} + /** * Per-epoch information about a stake account * @export @@ -233,6 +260,25 @@ export interface AddressInfo { staking_cred?: StakingCredential | null; } +/** + * Current Balance by payment credential + * @export + * @interface AddressBalance + */ +export interface AddressBalance { + /** + * + * @type {object} + * @memberof AddressBalance + */ + assets: object; + /** + * + * @type {string} + * @memberof AddressBalance + */ + lovelace: object; +} /** * Transaction which involved a specific address * @export @@ -1394,6 +1440,32 @@ export interface PaginatedAccountHistory { */ next_cursor?: string | null; } + +/** + * A paginated response. Pass in the `next_cursor` in a subsequent request as the `cursor` query parameter to fetch the next page of results. + * @export + * @interface PaginatedAccountDelegationHistory + */ +export interface PaginatedAccountDelegationHistory { + /** + * Endpoint response data + * @type {Array} + * @memberof PaginatedAccountHistory + */ + data: Array; + /** + * + * @type {LastUpdated} + * @memberof PaginatedAccountDelegationHistory + */ + last_updated: LastUpdated; + /** + * Pagination cursor + * @type {string} + * @memberof PaginatedAccountDelegationHistory + */ + next_cursor?: string | null; +} /** * A paginated response. Pass in the `next_cursor` in a subsequent request as the `cursor` query parameter to fetch the next page of results. * @export From 2b41f2f3f19c298607f88088746253b861733c78 Mon Sep 17 00:00:00 2001 From: sanjay-del Date: Tue, 26 Mar 2024 07:49:03 +0545 Subject: [PATCH 2/4] Added helper function for account delegation history and cred balance --- src/api/accounts/helpers.ts | 65 ++++++++++++++++++++++++++++++++++++ src/api/addresses/helpers.ts | 51 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/src/api/accounts/helpers.ts b/src/api/accounts/helpers.ts index 17e2b33..c30308d 100644 --- a/src/api/accounts/helpers.ts +++ b/src/api/accounts/helpers.ts @@ -17,10 +17,12 @@ import { TimestampedAccountInfo, PaginatedAccountReward, PaginatedAccountUpdate, + PaginatedAccountDelegationHistory, } from '../type'; import { AccountAddressesQueryParams, AccountAssetsQueryParams, + AccountDelegationHistoryQueryParams, AccountHistoryQueryParams, AccountRewardsQueryParams, AccountUpdatesQueryParams, @@ -275,6 +277,48 @@ export const AccountsApiAxiosParamCreator = (configuration: Configuration) => ({ ...options.headers, }; + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Returns list of delegation actions relating to a stake account + * @summary Stake account delegation history + * @param {string} stakeAddr Bech32 encoded stake/reward address (\'stake1...\') + * @param {AccountDelegationHistoryQueryParams} [localVarQueryParameter] Query parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + accountDelegationHistory: ( + stakeAddr: string, + localVarQueryParameter: AccountDelegationHistoryQueryParams = {}, + options: AxiosRequestConfig = {}, + ): RequestArgs => { + // verify required parameter 'stakeAddr' is not null or undefined + assertParamExists('accountDelegationHistory', 'stakeAddr', stakeAddr); + const localVarPath = `/accounts/{stake_addr}/delegations`.replace( + `{${'stake_addr'}}`, + encodeURIComponent(String(stakeAddr)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + const { baseOptions } = configuration; + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options }; + const localVarHeaderParameter = {} as Record; + + // authentication api-key required + setApiKeyToObject(localVarHeaderParameter, 'api-key', configuration); + + setSearchParams(localVarUrlObj, localVarQueryParameter); + const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + return { url: toPathString(localVarUrlObj), options: localVarRequestOptions, @@ -337,6 +381,27 @@ export const AccountsApiFp = (configuration: Configuration) => { const localVarAxiosArgs = localVarAxiosParamCreator.accountHistory(stakeAddr, queryParams, options); return createRequestFunction(localVarAxiosArgs, configuration); }, + + /** + * Returns list of delegation actions relating to a stake account + * @summary Stake account history + * @param {string} stakeAddr Bech32 encoded stake/reward address (\'stake1...\') + * @param {AccountDelegationHistoryQueryParams} [queryParams] Query parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + accountDelegationHistory( + stakeAddr: string, + queryParams?: AccountDelegationHistoryQueryParams, + options?: AxiosRequestConfig, + ): () => Promise { + const localVarAxiosArgs = localVarAxiosParamCreator.accountDelegationHistory( + stakeAddr, + queryParams, + options, + ); + return createRequestFunction(localVarAxiosArgs, configuration); + }, /** * Returns various information regarding a stake account * @summary Stake account information diff --git a/src/api/addresses/helpers.ts b/src/api/addresses/helpers.ts index 993368a..47e3451 100644 --- a/src/api/addresses/helpers.ts +++ b/src/api/addresses/helpers.ts @@ -18,6 +18,7 @@ import { PaginatedPaymentCredentialTransaction, PaginatedUtxoRef, PaginatedUtxoWithSlot, + AddressBalance, } from '../type'; import { TxsByAddressQueryParams, @@ -71,6 +72,45 @@ export const AddressesApiAxiosParamCreator = (configuration: Configuration) => ( options: localVarRequestOptions, }; }, + + /** + * Return total amount of assets, including ADA, in UTxOs controlled by a specific payment credential + * @summary Address Balance + * @param {string} credential Payment credential in bech32 format + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + addressBalance: (credential: string, options: AxiosRequestConfig = {}): RequestArgs => { + // verify required parameter 'credential' is not null or undefined + assertParamExists('addressBalance', 'address', credential); + const localVarPath = `/addresses/cred/{credential}/balance`.replace( + `{${'credential'}}`, + encodeURIComponent(String(credential)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + const { baseOptions } = configuration; + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options }; + const localVarHeaderParameter = {} as Record; + const localVarQueryParameter = {} as Record; + + // authentication api-key required + setApiKeyToObject(localVarHeaderParameter, 'api-key', configuration); + + setSearchParams(localVarUrlObj, localVarQueryParameter); + const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * Returns the number of transactions in which the address spent or received some funds. Specifically, the number of transactions where: the address controlled at least one of the transaction inputs and/or receives one of the outputs AND the transaction is phase-2 valid, OR, the address controlled at least one of the collateral inputs and/or receives the collateral return output AND the transaction is phase-2 invalid. [Read more](https://docs.cardano.org/plutus/collateral-mechanism/). * @summary Address transaction count @@ -427,6 +467,17 @@ export const AddressesApiFp = (configuration: Configuration) => { const localVarAxiosArgs = localVarAxiosParamCreator.decodeAddress(address, options); return createRequestFunction(localVarAxiosArgs, configuration); }, + /** + * Return total amount of assets, including ADA, in UTxOs controlled by a specific payment credential + * @summary Address Balance + * @param {string} credential Payment credential in bech32 format + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + addressBalance(credential: string, options?: AxiosRequestConfig): () => Promise { + const localVarAxiosArgs = localVarAxiosParamCreator.addressBalance(credential, options); + return createRequestFunction(localVarAxiosArgs, configuration); + }, /** * Returns the number of transactions in which the address spent or received some funds. Specifically, the number of transactions where: the address controlled at least one of the transaction inputs and/or receives one of the outputs AND the transaction is phase-2 valid, OR, the address controlled at least one of the collateral inputs and/or receives the collateral return output AND the transaction is phase-2 invalid. [Read more](https://docs.cardano.org/plutus/collateral-mechanism/). * @summary Address transaction count From 10d09efef23eddbc9c22525b3d903407b7e9ded4 Mon Sep 17 00:00:00 2001 From: sanjay-del Date: Tue, 26 Mar 2024 07:50:00 +0545 Subject: [PATCH 3/4] Added sdk functions for account delegation history and account credential balance --- src/api/accounts/index.ts | 18 ++++++++++++++++++ src/api/addresses/index.ts | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/api/accounts/index.ts b/src/api/accounts/index.ts index 2211993..4c1a15b 100644 --- a/src/api/accounts/index.ts +++ b/src/api/accounts/index.ts @@ -7,6 +7,7 @@ import { AccountHistoryQueryParams, AccountRewardsQueryParams, AccountUpdatesQueryParams, + AccountDelegationHistoryQueryParams, } from './type'; /** @@ -59,6 +60,23 @@ export class AccountsApi extends BaseAPI { return AccountsApiFp(this.configuration).accountHistory(stakeAddr, queryParams, options)(); } + /** + * * Returns list of delegation actions relating to a stake account + * @summary Stake account history + * @param {string} stakeAddr Bech32 encoded stake/reward address (\'stake1...\') + * @param {AccountDelegationHistoryQueryParams} [queryParams] Query parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AccountsApi + */ + public accountDelegationHistory( + stakeAddr: string, + queryParams?: AccountDelegationHistoryQueryParams, + options?: AxiosRequestConfig, + ) { + return AccountsApiFp(this.configuration).accountDelegationHistory(stakeAddr, queryParams, options)(); + } + /** * Returns various information regarding a stake account * @summary Stake account information diff --git a/src/api/addresses/index.ts b/src/api/addresses/index.ts index 4e0a5bb..f93b708 100644 --- a/src/api/addresses/index.ts +++ b/src/api/addresses/index.ts @@ -28,6 +28,18 @@ export class AddressesApi extends BaseAPI { return AddressesApiFp(this.configuration).decodeAddress(address, options)(); } + /** + * Return total amount of assets, including ADA, in UTxOs controlled by a specific payment credential + * @summary Address Balance + * @param {string} credential Payment credential in bech32 format + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public addressBalance(credential: string, options?: AxiosRequestConfig) { + return AddressesApiFp(this.configuration).addressBalance(credential, options)(); + } + /** * Returns the number of transactions in which the address spent or received some funds. Specifically, the number of transactions where: the address controlled at least one of the transaction inputs and/or receives one of the outputs AND the transaction is phase-2 valid, OR, the address controlled at least one of the collateral inputs and/or receives the collateral return output AND the transaction is phase-2 invalid. [Read more](https://docs.cardano.org/plutus/collateral-mechanism/). * @summary Address transaction count From 5902e3c3569f95168fa25c8aa2fc1f5c3c5c1052 Mon Sep 17 00:00:00 2001 From: sanjay-del Date: Sun, 31 Mar 2024 19:58:43 +0545 Subject: [PATCH 4/4] Package json version upgrade --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 39855ed..30337f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maestro-org/typescript-sdk", - "version": "1.5.2", + "version": "1.5.4", "description": "TypeScript SDK for the Maestro Dapp Platform", "main": "dist/index.js", "module": "dist/index.mjs",