Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staking-sdk: update staking sdk #222

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import {
DelegationSummaryDto,
DelegationSummaryDtoByVault,
ExecuteActionResponse, StakeRequestDto, StakingAction,
StakingChain, StakingPosition, StakingValidator, UnstakeRequestDto, WithdrawRequestDto
StakingChain, StakingPosition, StakingProvider, UnstakeRequestDto, WithdrawRequestDto
} from "./staking";

export * from "./types";
Expand Down Expand Up @@ -220,8 +220,14 @@ export class FireblocksSDK {
/**
* Get staking positions summary
*/
public async getStakingPositionsSummary(byVault?: boolean): Promise<DelegationSummaryDto | DelegationSummaryDtoByVault> {
return await this.stakingApiClient.getPositionsSummary(byVault);
public async getStakingPositionsSummary(): Promise<DelegationSummaryDto> {
return await this.stakingApiClient.getPositionsSummary();
}
/**
* Get staking positions summary by vault
*/
public async getStakingPositionsSummaryByVault(): Promise<DelegationSummaryDtoByVault> {
return await this.stakingApiClient.getPositionsSummaryByVault();
}
/**
* Execute staking action on a chain
Expand All @@ -242,16 +248,16 @@ export class FireblocksSDK {
return await this.stakingApiClient.getPosition(positionId);
}
/**
* Get all staking validators, filtered by chain
* Get all staking providers
*/
public async getStakingValidatorsByChain(chainDescriptor: StakingChain): Promise<StakingValidator[]> {
return await this.stakingApiClient.getValidatorsByChain(chainDescriptor);
public async getStakingProviders(): Promise<StakingProvider[]> {
return await this.stakingApiClient.getProviders();
}
/**
* Approve staking provider terms of service
*/
public async approveStakingProviderTermsOfService(validatorProviderId: string): Promise<CheckTermsOfServiceResponseDto> {
return await this.stakingApiClient.approveProviderTermsOfService(validatorProviderId);
public async approveStakingProviderTermsOfService(providerId: string): Promise<CheckTermsOfServiceResponseDto> {
return await this.stakingApiClient.approveProviderTermsOfService(providerId);
}
/**
* Gets all assets that are currently supported by Fireblocks
Expand Down
21 changes: 11 additions & 10 deletions src/staking/staking-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
ExecuteActionResponse, StakeRequestDto,
StakingAction,
StakingChain,
StakingPosition,
StakingValidator, UnstakeRequestDto, WithdrawRequestDto,
StakingPosition, StakingProvider,
UnstakeRequestDto, WithdrawRequestDto,
} from "./types";
import { StakingSDK } from "./staking-sdk";
import { ApiClient } from "../api-client";
Expand All @@ -22,8 +22,11 @@ export class StakingApiClient implements StakingSDK {
public async getChainInfo(chainDescriptor: StakingChain): Promise<ChainInfo> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/chains/${chainDescriptor}/chainInfo`);
}
public async getPositionsSummary(byVault?: boolean): Promise<DelegationSummaryDto | DelegationSummaryDtoByVault> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/positions/summary${byVault ? "?byVault=true" : "?byVault=false"}`);
public async getPositionsSummary(): Promise<DelegationSummaryDto> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/positions/summary`);
}
public async getPositionsSummaryByVault(): Promise<DelegationSummaryDtoByVault> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/positions/summary/vaults`);
}
public async executeAction(
actionId: StakingAction,
Expand All @@ -42,13 +45,11 @@ export class StakingApiClient implements StakingSDK {
public async getPosition(positionId: string): Promise<StakingPosition[]> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/positions/${positionId}`);
}
public async getValidatorsByChain(chainDescriptor: StakingChain): Promise<StakingValidator[]> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/validators/${chainDescriptor}`);
public async getProviders(): Promise<StakingProvider[]> {
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/providers`);
}
public async approveProviderTermsOfService(validatorProviderId: string): Promise<CheckTermsOfServiceResponseDto> {
return await this.apiClient.issuePostRequest(`${STAKING_BASE_PATH}/providers/approveTermsOfService`, {
validatorProviderId,
});
public async approveProviderTermsOfService(providerId: string): Promise<CheckTermsOfServiceResponseDto> {
return await this.apiClient.issuePostRequest(`${STAKING_BASE_PATH}/providers/${providerId}/approveTermsOfService`, {});
}
}

15 changes: 10 additions & 5 deletions src/staking/staking-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DelegationSummaryDtoByVault,
ExecuteActionResponse,
StakingAction,
StakingChain, StakingPosition, StakingValidator
StakingChain, StakingPosition, StakingProvider,
} from "./types";

export interface StakingSDK {
Expand All @@ -21,7 +21,12 @@ export interface StakingSDK {
/**
* Get staking positions summary
*/
getPositionsSummary(): Promise<DelegationSummaryDto | DelegationSummaryDtoByVault>;
getPositionsSummary(): Promise<DelegationSummaryDto>;

/**
* Get staking positions summary by vault
*/
getPositionsSummaryByVault(): Promise<DelegationSummaryDtoByVault>;

/**
* Execute staking action on a chain
Expand All @@ -38,12 +43,12 @@ export interface StakingSDK {
getPosition(positionId?: string): Promise<StakingPosition[]>;

/**
* Get all staking validators, filtered by chain
* Get all staking providers
*/
getValidatorsByChain(chainDescriptor: StakingChain): Promise<StakingValidator[]>;
getProviders(): Promise<StakingProvider[]>;

/**
* Approve staking provider terms of service
*/
approveProviderTermsOfService(validatorProviderId: string): Promise<CheckTermsOfServiceResponseDto>;
approveProviderTermsOfService(providerId: string): Promise<CheckTermsOfServiceResponseDto>;
}
75 changes: 30 additions & 45 deletions src/staking/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum PositionState {
export enum PositionStatus {
"error" = "error",

"activating" = "activating",
Expand All @@ -15,7 +15,7 @@ interface ISolanaBlockchainData {
/**
* The stake account address matching the stakeAccountId
*/
stakeAccountAddress: string;
stakeAccountAddress?: string;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -30,9 +30,9 @@ interface RelatedTransactionDto {
txId: string;

/**
* Is the transaction successful or not
* Is the transaction completed or not
*/
isSuccessful: boolean;
completed: boolean;
}

export interface StakingPosition {
Expand All @@ -41,6 +41,11 @@ export interface StakingPosition {
*/
id: string;

/**
* The unique identifier of the staking provider
*/
providerId: string;

/**
* The source vault account to stake from.
*/
Expand Down Expand Up @@ -76,9 +81,9 @@ export interface StakingPosition {
dateCreated: string;

/**
* The current state.
* The current status.
*/
state: PositionState;
status: PositionStatus;

/**
* An array of transaction objects related to this position.
Expand All @@ -90,20 +95,20 @@ export interface StakingPosition {
/**
* Indicates whether there is an ongoing action for this position (true if ongoing, false if not).
*/
ongoingRequest?: boolean;
inProgress: boolean;

/**
* The transaction ID of the ongoing request
*/
onGoingRequestTxId?: string;
inProgressTxId?: string;

/**
* Additional fields per blockchain - can be empty or missing if not initialized or no additional info exists.
* The type depends on the chainDescriptor value.
* For Solana (SOL), stake account address.
* For Ethereum (ETH), an empty object is returned as no specific data is available.
*/
blockchainPositionInfo?: TBlockchainPositionInfo;
blockchainPositionInfo: TBlockchainPositionInfo;

/**
* The destination address of the staking transaction.
Expand All @@ -116,52 +121,37 @@ export interface StakingPosition {
availableActions: string[];
}

export interface StakingValidator {
export interface ValidatorDto {
/**
* Blockchain descriptor for the validator
* The protocol identifier (e.g. "ETH"/"SOL") of the validator
*/
chainDescriptor: string;

/**
* The ID of the provider
*/
providerId: number;

/**
* The ID of the validator
*/
validatorId: number;

/**
* The destination address of the staking transaction
*/
validatorAddress: string;

/**
* Percentage fee charged by the validator
* The service fee as a percentage out of the earned rewards
*/
feePercent: number;

}
export interface StakingProvider {
/**
* Name of the validator
* The ID of the provider
*/
validatorName: string;

id: string;
/**
* Name of the provider
*/
providerName: string;

/**
* An array of objects that includes chain descriptors and the corresponding fee percentages for validators supported by the provider
*/
validators: ValidatorDto[];
/**
* URL to the validator's icon
*/
iconUrl: string;

/**
* URL to the terms of service
*/
termsOfServiceUrl: string;

/**
* Indicates whether the terms of service are approved"
*/
Expand Down Expand Up @@ -190,12 +180,7 @@ export enum StakingChain {
/**
* Check terms of service response
*/
export interface CheckTermsOfServiceResponseDto {
/**
* True if the terms and services were previously approved
*/
isPreviouslyApproved: boolean;
}
export interface CheckTermsOfServiceResponseDto {}

export interface ChainInfo {
chainId: string;
Expand All @@ -218,9 +203,9 @@ export interface DelegationSummaryDto {
active: AmountAndChainDescriptor[];

/**
* An array of objects containing chain descriptors and associated amounts, representing inActive positions.
* An array of objects containing chain descriptors and associated amounts, representing inactive positions.
*/
inActive: AmountAndChainDescriptor[];
inactive: AmountAndChainDescriptor[];

/**
* An array of objects containing chain descriptors and associated amounts, representing rewards positions.
Expand Down Expand Up @@ -249,9 +234,9 @@ export interface StakeRequestDto {
vaultAccountId: string;

/**
* The destination validator address id. The blockchain is used implicitly (it's associated with the address)
* The ID of the provider
*/
validatorAddressId: string;
providerId: string;

/**
* Amount of tokens to stake
Expand Down
Loading