Skip to content

Commit

Permalink
Merge pull request #42 from sanjay-del/delegation-balance
Browse files Browse the repository at this point in the history
Delegation balance
  • Loading branch information
Vardominator authored Mar 31, 2024
2 parents 686ba60 + 5902e3c commit d95c4c2
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
65 changes: 65 additions & 0 deletions src/api/accounts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
TimestampedAccountInfo,
PaginatedAccountReward,
PaginatedAccountUpdate,
PaginatedAccountDelegationHistory,
} from '../type';
import {
AccountAddressesQueryParams,
AccountAssetsQueryParams,
AccountDelegationHistoryQueryParams,
AccountHistoryQueryParams,
AccountRewardsQueryParams,
AccountUpdatesQueryParams,
Expand Down Expand Up @@ -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<string, string>;

// 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,
Expand Down Expand Up @@ -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 (\&#39;stake1...\&#39;)
* @param {AccountDelegationHistoryQueryParams} [queryParams] Query parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
accountDelegationHistory(
stakeAddr: string,
queryParams?: AccountDelegationHistoryQueryParams,
options?: AxiosRequestConfig,
): () => Promise<PaginatedAccountDelegationHistory> {
const localVarAxiosArgs = localVarAxiosParamCreator.accountDelegationHistory(
stakeAddr,
queryParams,
options,
);
return createRequestFunction(localVarAxiosArgs, configuration);
},
/**
* Returns various information regarding a stake account
* @summary Stake account information
Expand Down
18 changes: 18 additions & 0 deletions src/api/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
AccountHistoryQueryParams,
AccountRewardsQueryParams,
AccountUpdatesQueryParams,
AccountDelegationHistoryQueryParams,
} from './type';

/**
Expand Down Expand Up @@ -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 (\&#39;stake1...\&#39;)
* @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
Expand Down
22 changes: 22 additions & 0 deletions src/api/accounts/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
51 changes: 51 additions & 0 deletions src/api/addresses/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PaginatedPaymentCredentialTransaction,
PaginatedUtxoRef,
PaginatedUtxoWithSlot,
AddressBalance,
} from '../type';
import {
TxsByAddressQueryParams,
Expand Down Expand Up @@ -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<string, string>;
const localVarQueryParameter = {} as Record<string, string>;

// 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
Expand Down Expand Up @@ -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<AddressBalance> {
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
Expand Down
12 changes: 12 additions & 0 deletions src/api/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions src/api/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<AccountAction>}
* @memberof PaginatedAccountHistory
*/
data: Array<AccountDelegationHistory>;
/**
*
* @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
Expand Down

0 comments on commit d95c4c2

Please sign in to comment.