@stacks/stacking
Version:
Library for Stacking.
410 lines (409 loc) • 14.9 kB
TypeScript
import { ClientOpts, IntegerType, PrivateKey } from '@stacks/common';
import { NetworkClientParam, StacksNetwork } from '@stacks/network';
import { BurnchainRewardListResponse, BurnchainRewardSlotHolderListResponse, BurnchainRewardsTotal } from '@stacks/stacks-blockchain-api-types';
import type { ContractIdString } from '@stacks/transactions';
import { ContractCallOptions, StacksTransactionWire, TxBroadcastResult } from '@stacks/transactions';
import { PoxOperationPeriod } from './constants';
import { Pox4SignatureTopic } from './utils';
export * from './utils';
export interface CycleInfo {
id: number;
min_threshold_ustx: number;
stacked_ustx: number;
is_pox_active: boolean;
}
export interface ContractVersion {
contract_id: string;
activation_burnchain_block_height: number;
first_reward_cycle_id: number;
}
export interface PoxInfo {
contract_id: string;
contract_versions: ContractVersion[];
current_burnchain_block_height?: number;
first_burnchain_block_height: number;
min_amount_ustx: string;
next_reward_cycle_in: number;
prepare_cycle_length: number;
prepare_phase_block_length: number;
reward_cycle_id: number;
reward_cycle_length: number;
reward_phase_block_length: number;
reward_slots: number;
current_cycle: CycleInfo;
next_cycle: CycleInfo & {
min_increment_ustx: number;
prepare_phase_start_block_height: number;
blocks_until_prepare_phase: number;
reward_phase_start_block_height: number;
blocks_until_reward_phase: number;
ustx_until_pox_rejection: number;
};
}
export type PoxOperationInfo = {
period: PoxOperationPeriod;
pox1: {
contract_id: string;
};
pox2: ContractVersion;
pox3: ContractVersion;
pox4: ContractVersion;
current: ContractVersion;
};
export type StackerInfo = {
stacked: false;
} | {
stacked: true;
details: {
first_reward_cycle: number;
lock_period: number;
unlock_height: number;
pox_address: {
version: Uint8Array;
hashbytes: Uint8Array;
};
};
};
export type DelegationInfo = {
delegated: false;
} | {
delegated: true;
details: {
amount_micro_stx: bigint;
delegated_to: string;
pox_address?: {
version: number;
hashbytes: Uint8Array;
};
until_burn_ht?: number;
};
};
export interface RewardSetOptions {
contractId: string;
rewardCyleId: number;
rewardSetIndex: number;
}
export interface RewardSetInfo {
pox_address: {
version: Uint8Array;
hashbytes: Uint8Array;
};
total_ustx: bigint;
}
export interface StackingEligibility {
eligible: boolean;
reason?: string;
}
export interface CanLockStxOptions {
poxAddress: string;
cycles: number;
}
export interface LockStxOptions {
privateKey: string;
cycles: number;
poxAddress: string;
amountMicroStx: IntegerType;
burnBlockHeight: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}
export interface StackExtendOptions {
privateKey: string;
extendCycles: number;
poxAddress: string;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}
export interface StackIncreaseOptions {
privateKey: string;
increaseBy: IntegerType;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}
export interface DelegateStxOptions {
amountMicroStx: IntegerType;
delegateTo: string;
untilBurnBlockHeight?: number;
poxAddress?: string;
privateKey: string;
}
export interface DelegateStackStxOptions {
privateKey: string;
stacker: string;
amountMicroStx: IntegerType;
poxAddress: string;
burnBlockHeight: number;
cycles: number;
}
export interface DelegateStackExtendOptions {
stacker: string;
poxAddress: string;
extendCount: number;
privateKey: string;
}
export interface DelegateStackIncreaseOptions {
stacker: string;
poxAddress: string;
increaseBy: IntegerType;
privateKey: string;
nonce?: IntegerType;
}
export interface StackAggregationCommitOptions {
poxAddress: string;
rewardCycle: number;
privateKey: string;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}
export interface StackAggregationIncreaseOptions {
poxAddress: string;
rewardCycle: number;
rewardIndex: number;
privateKey: string;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}
export declare class StackingClient {
address: string;
network: StacksNetwork;
client: Required<ClientOpts>;
constructor(opts: {
address: string;
} & NetworkClientParam);
get baseUrl(): string;
get fetch(): import("@stacks/common").FetchFn;
getCoreInfo(): Promise<V2CoreInfoResponse>;
getPoxInfo(): Promise<V2PoxInfoResponse>;
getTargetBlockTime(): Promise<number>;
getAccountStatus(): Promise<any>;
getAccountBalance(): Promise<bigint>;
getAccountExtendedBalances(): Promise<ExtendedAccountBalances>;
getAccountBalanceLocked(): Promise<bigint>;
getCycleDuration(): Promise<number>;
getRewardsTotalForBtcAddress(): Promise<BurnchainRewardsTotal | BaseErrorResponse>;
getRewardsForBtcAddress(options?: PaginationOptions): Promise<BurnchainRewardListResponse | BaseErrorResponse>;
getRewardHoldersForBtcAddress(options?: PaginationOptions): Promise<BurnchainRewardSlotHolderListResponse | BaseErrorResponse>;
getRewardSet(options: RewardSetOptions): Promise<RewardSetInfo | undefined>;
getSecondsUntilNextCycle(): Promise<number>;
getSecondsUntilStackingDeadline(): Promise<number>;
getPoxOperationInfo(poxInfo?: V2PoxInfoResponse): Promise<PoxOperationInfo>;
hasMinimumStx(): Promise<boolean>;
canStack({ poxAddress, cycles }: CanLockStxOptions): Promise<StackingEligibility>;
stack({ amountMicroStx, poxAddress, cycles, burnBlockHeight, signerKey, signerSignature, maxAmount, authId, ...txOptions }: LockStxOptions & BaseTxOptions): Promise<TxBroadcastResult>;
stackExtend({ extendCycles, poxAddress, signerKey, signerSignature, maxAmount, authId, ...txOptions }: StackExtendOptions & BaseTxOptions): Promise<TxBroadcastResult>;
stackIncrease({ increaseBy, signerKey, signerSignature, maxAmount, authId, ...txOptions }: StackIncreaseOptions & BaseTxOptions): Promise<TxBroadcastResult>;
delegateStx({ amountMicroStx, delegateTo, untilBurnBlockHeight, poxAddress, ...txOptions }: DelegateStxOptions & BaseTxOptions): Promise<TxBroadcastResult>;
delegateStackStx({ stacker, amountMicroStx, poxAddress, burnBlockHeight, cycles, ...txOptions }: DelegateStackStxOptions & BaseTxOptions): Promise<TxBroadcastResult>;
delegateStackExtend({ stacker, poxAddress, extendCount, ...txOptions }: DelegateStackExtendOptions & BaseTxOptions): Promise<TxBroadcastResult>;
delegateStackIncrease({ stacker, poxAddress, increaseBy, ...txOptions }: DelegateStackIncreaseOptions & BaseTxOptions): Promise<TxBroadcastResult>;
stackAggregationCommit({ poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, ...txOptions }: StackAggregationCommitOptions & BaseTxOptions): Promise<TxBroadcastResult>;
stackAggregationCommitIndexed({ poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, ...txOptions }: StackAggregationCommitOptions & BaseTxOptions): Promise<TxBroadcastResult>;
stackAggregationIncrease({ poxAddress, rewardCycle, rewardIndex, signerKey, signerSignature, maxAmount, authId, ...txOptions }: StackAggregationIncreaseOptions & BaseTxOptions): Promise<TxBroadcastResult>;
revokeDelegateStx(privateKey: string): Promise<TxBroadcastResult>;
revokeDelegateStx(txOptions: BaseTxOptions): Promise<TxBroadcastResult>;
getStackOptions({ amountMicroStx, poxAddress, cycles, contract, burnBlockHeight, signerKey, signerSignature, maxAmount, authId, }: {
cycles: number;
poxAddress: string;
amountMicroStx: IntegerType;
contract: string;
burnBlockHeight: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getStackExtendOptions({ extendCycles, poxAddress, contract, signerKey, signerSignature, maxAmount, authId, }: {
extendCycles: number;
poxAddress: string;
contract: string;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getStackIncreaseOptions({ increaseBy, contract, signerKey, signerSignature, maxAmount, authId, }: {
increaseBy: IntegerType;
contract: string;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getDelegateOptions({ contract, amountMicroStx, delegateTo, untilBurnBlockHeight, poxAddress, }: {
contract: string;
amountMicroStx: IntegerType;
delegateTo: string;
untilBurnBlockHeight?: number;
poxAddress?: string;
}): ContractCallOptions;
getDelegateStackOptions({ contract, stacker, amountMicroStx, poxAddress, burnBlockHeight, cycles, }: {
contract: string;
stacker: string;
amountMicroStx: IntegerType;
poxAddress: string;
burnBlockHeight: number;
cycles: number;
}): ContractCallOptions;
getDelegateStackExtendOptions({ contract, stacker, poxAddress, extendCount, }: {
contract: string;
stacker: string;
poxAddress: string;
extendCount: number;
}): ContractCallOptions;
getDelegateStackIncreaseOptions({ contract, stacker, poxAddress, increaseBy, }: {
contract: string;
stacker: string;
poxAddress: string;
increaseBy: IntegerType;
}): ContractCallOptions;
getStackAggregationCommitOptions({ contract, poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, }: {
contract: string;
poxAddress: string;
rewardCycle: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getStackAggregationIncreaseOptions({ contract, poxAddress, rewardCycle, rewardCycleIndex, signerKey, signerSignature, maxAmount, authId, }: {
contract: string;
poxAddress: string;
rewardCycle: number;
rewardCycleIndex: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getStackAggregationCommitOptionsIndexed({ contract, poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, }: {
contract: string;
poxAddress: string;
rewardCycle: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}): ContractCallOptions;
getRevokeDelegateStxOptions(contract: string): ContractCallOptions;
getStatus(): Promise<StackerInfo>;
getDelegationStatus(): Promise<DelegationInfo>;
verifySignerKeySignature({ topic, poxAddress, rewardCycle, period, signerSignature, signerKey, amount, maxAmount, authId, }: {
topic: string;
poxAddress: string;
rewardCycle: number;
period: number;
signerSignature?: string;
signerKey: string;
amount: IntegerType;
maxAmount: IntegerType;
authId: IntegerType;
}): Promise<boolean>;
getStackingContract(poxOperationInfo?: PoxOperationInfo): Promise<string>;
modifyLockTxFee({ tx, amountMicroStx, }: {
tx: StacksTransactionWire;
amountMicroStx: IntegerType;
}): StacksTransactionWire;
parseContractId(contract: string): string[];
signPoxSignature({ topic, poxAddress, rewardCycle, period, signerPrivateKey, authId, maxAmount, }: {
topic: `${Pox4SignatureTopic}`;
poxAddress: string;
rewardCycle: number;
period: number;
signerPrivateKey: PrivateKey;
maxAmount: IntegerType;
authId: IntegerType;
}): string;
}
export interface V2CoreInfoResponse {
burn_block_height: number;
stable_pox_consensus: string;
}
export interface CycleInfoResponse {
id: number;
min_threshold_ustx: number;
stacked_ustx: number;
is_pox_active: boolean;
}
export interface ContractVersionResponse {
contract_id: ContractIdString;
activation_burnchain_block_height: number;
first_reward_cycle_id: number;
}
export interface V2PoxInfoResponse {
contract_id: string;
contract_versions: ContractVersionResponse[];
current_burnchain_block_height?: number;
first_burnchain_block_height: number;
min_amount_ustx: string;
next_reward_cycle_in: number;
prepare_cycle_length: number;
prepare_phase_block_length: number;
rejection_fraction: number;
rejection_votes_left_required: number;
reward_cycle_id: number;
reward_cycle_length: number;
reward_phase_block_length: number;
reward_slots: number;
current_cycle: CycleInfoResponse;
next_cycle: CycleInfoResponse & {
min_increment_ustx: number;
prepare_phase_start_block_height: number;
blocks_until_prepare_phase: number;
reward_phase_start_block_height: number;
blocks_until_reward_phase: number;
ustx_until_pox_rejection: number;
};
}
export interface V1InfoBlockTimesResponse {
mainnet: {
target_block_time: number;
};
testnet: {
target_block_time: number;
};
}
export interface ExtendedAccountBalancesResponse {
stx: {
balance: string;
total_sent: string;
total_received: string;
locked: string;
lock_tx_id: string;
lock_height: number;
burnchain_lock_height: number;
burnchain_unlock_height: number;
};
fungible_tokens: any;
non_fungible_tokens: any;
}
export interface ExtendedAccountBalances {
stx: {
balance: bigint;
total_sent: bigint;
total_received: bigint;
locked: bigint;
lock_tx_id: string;
lock_height: number;
burnchain_lock_height: number;
burnchain_unlock_height: number;
};
fungible_tokens: any;
non_fungible_tokens: any;
}
export interface PaginationOptions {
limit: number;
offset: number;
}
export interface BaseErrorResponse {
error: string;
}