-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from fireblocks/staking-sdk
Staking sdk
- Loading branch information
Showing
5 changed files
with
484 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./staking-api-client"; | ||
export * from "./staking-sdk"; | ||
export * from "./types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
ChainInfo, | ||
CheckTermsOfServiceResponseDto, | ||
DelegationSummaryDto, | ||
DelegationSummaryDtoByVault, | ||
ExecuteActionResponse, StakeRequestDto, | ||
StakingAction, | ||
StakingChain, | ||
StakingPosition, | ||
StakingValidator, UnstakeRequestDto, WithdrawRequestDto, | ||
} from "./types"; | ||
import { StakingSDK } from "./staking-sdk"; | ||
import { ApiClient } from "../api-client"; | ||
|
||
const STAKING_BASE_PATH = "/v1/staking"; | ||
|
||
export class StakingApiClient implements StakingSDK { | ||
constructor(private readonly apiClient: ApiClient) {} | ||
public async getChains(): Promise<string[]> { | ||
return await this.apiClient.issueGetRequest(`${STAKING_BASE_PATH}/chains`); | ||
} | ||
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 executeAction( | ||
actionId: StakingAction, | ||
chainDescriptor: StakingChain, | ||
body: StakeRequestDto | UnstakeRequestDto | WithdrawRequestDto, | ||
): Promise<ExecuteActionResponse> { | ||
return await this.apiClient.issuePostRequest( | ||
`${STAKING_BASE_PATH}/chains/${chainDescriptor}/${actionId}`, | ||
body, | ||
); | ||
} | ||
public async getPositions(chainDescriptor?: StakingChain): Promise<StakingPosition[]> { | ||
const url = `${STAKING_BASE_PATH}/positions${chainDescriptor ? `?chainDescriptor=${chainDescriptor}` : ""}`; | ||
return await this.apiClient.issueGetRequest(url); | ||
} | ||
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 approveProviderTermsOfService(validatorProviderId: string): Promise<CheckTermsOfServiceResponseDto> { | ||
return await this.apiClient.issuePostRequest(`${STAKING_BASE_PATH}/providers/approveTermsOfService`, { | ||
validatorProviderId, | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
ChainInfo, CheckTermsOfServiceResponseDto, | ||
DelegationSummaryDto, | ||
DelegationSummaryDtoByVault, | ||
ExecuteActionResponse, | ||
StakingAction, | ||
StakingChain, StakingPosition, StakingValidator | ||
} from "./types"; | ||
|
||
export interface StakingSDK { | ||
/** | ||
* Get all staking chains | ||
*/ | ||
getChains(): Promise<string[]>; | ||
|
||
/** | ||
* Get chain info | ||
*/ | ||
getChainInfo(chainDescriptor: StakingChain): Promise<ChainInfo>; | ||
|
||
/** | ||
* Get staking positions summary | ||
*/ | ||
getPositionsSummary(): Promise<DelegationSummaryDto | DelegationSummaryDtoByVault>; | ||
|
||
/** | ||
* Execute staking action on a chain | ||
*/ | ||
executeAction(actionId: StakingAction, chainDescriptor: StakingChain, body: any): Promise<ExecuteActionResponse>; | ||
|
||
/** | ||
* Get all staking positions, optionally filtered by chain | ||
*/ | ||
getPositions(chainDescriptor?: StakingChain): Promise<StakingPosition[]>; | ||
/** | ||
* Get a staking position by id | ||
*/ | ||
getPosition(positionId?: string): Promise<StakingPosition[]>; | ||
|
||
/** | ||
* Get all staking validators, filtered by chain | ||
*/ | ||
getValidatorsByChain(chainDescriptor: StakingChain): Promise<StakingValidator[]>; | ||
|
||
/** | ||
* Approve staking provider terms of service | ||
*/ | ||
approveProviderTermsOfService(validatorProviderId: string): Promise<CheckTermsOfServiceResponseDto>; | ||
} |
Oops, something went wrong.