Skip to content

Commit

Permalink
Add additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer Vilensky committed Sep 25, 2019
1 parent f98944a commit 8ea6245
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
71 changes: 56 additions & 15 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiClient } from "./api-client";
import { ApiTokenProvider } from "./api-token-provider";
import { IAuthProvider } from "./iauth-provider";
import { VaultAccountResponse, CreateTransactionResponse, TransactionArguments, AssetResponse,
ExchangeResponse, TransactionResponse, TransactionFilter, CancelTransactionResponse, WalletContainerResponse, WalletAssetResponse, DepositAddressResponse } from "./types";
ExchangeResponse, TransactionResponse, TransactionFilter, CancelTransactionResponse, WalletContainerResponse, WalletAssetResponse, DepositAddressResponse, GenerateAddressResponse, OperationSuccessResponse } from "./types";
import queryString from "query-string";

export class FireblocksSDK {
Expand Down Expand Up @@ -41,32 +41,41 @@ export class FireblocksSDK {
return await this.apiClient.issueGetRequest("/v1/vault/accounts");
}

/**
* Gets a single vault account.
* @param vaultAccountId The vault account ID.
*/
/**
* Gets a single vault account.
* @param vaultAccountId The vault account ID.
*/
public async getVaultAccount(vaultAccountId: string): Promise<VaultAccountResponse> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}`);
}

/**
* Gets a single vault account asset.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset to get.
*/
/**
* Gets a single vault account asset.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset to get.
*/
public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise<AssetResponse> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`);
}

/**
* Gets deposit addresses for an asset in a vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset for which to get the deposit address.
*/
/**
* Gets deposit addresses for an asset in a vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset for which to get the deposit address.
*/
public async getDepositAddresses(vaultAccountId: string, assetId: string): Promise<DepositAddressResponse[]> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`);
}

/**
* Generates a new address for an asset in a vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset for which to get the deposit address.
*/
public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string): Promise<GenerateAddressResponse> {
return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`, { description });
}

/**
* Gets all exchange accounts for your tenant.
*/
Expand All @@ -82,6 +91,38 @@ export class FireblocksSDK {
return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}`);
}

/**
* Transfer from a main exchange account to a subaccount.
* @param exchangeAccountId The exchange ID in Fireblocks.
* @param subaccountId The ID of the subaccount in the exchange.
* @param assetId The asset to transfer.
* @param amount The amount to transfer.
*/
public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number): Promise<OperationSuccessResponse> {
const body = {
subaccountId,
amount
};

return await this.apiClient.issuePostRequest(`/v1/exchange_accounts/${exchangeAccountId}/${assetId}/transfer_to_subaccount`, body);
}

/**
* Transfer from a subaccount to a main exchange account.
* @param exchangeAccountId The exchange ID in Fireblocks.
* @param subaccountId The ID of the subaccount in the exchange.
* @param assetId The asset to transfer.
* @param amount The amount to transfer.
*/
public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number): Promise<OperationSuccessResponse> {
const body = {
subaccountId,
amount
};

return await this.apiClient.issuePostRequest(`/v1/exchange_accounts/${exchangeAccountId}/${assetId}/transfer_from_subaccount`, body);
}

/**
* Gets a list of transactions matching the given filter.
* @param filter.before Only gets transactions created before a given timestamp (in seconds).
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface DepositAddressResponse {
description?: string;
type: string;
}
export interface GenerateAddressResponse {
address: string;
tag?: string;
}

export interface TransactionArguments {
assetId: string;
Expand Down Expand Up @@ -107,6 +111,10 @@ export interface CancelTransactionResponse {
success: boolean;
}

export interface OperationSuccessResponse {
success: boolean;
}

export interface TransactionFilter {
before?: number;
after?: number;
Expand Down

0 comments on commit 8ea6245

Please sign in to comment.