From 8ea6245aeb29b994b0cfec854504760e4cabe6f7 Mon Sep 17 00:00:00 2001 From: Tomer Vilensky Date: Wed, 25 Sep 2019 13:41:01 +0300 Subject: [PATCH] Add additional methods --- src/fireblocks-sdk.ts | 71 ++++++++++++++++++++++++++++++++++--------- src/types.ts | 8 +++++ 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index ac40fafa..48c97a23 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -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 { @@ -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 { 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 { 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 { 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 { + return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`, { description }); + } + /** * Gets all exchange accounts for your tenant. */ @@ -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 { + 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 { + 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). diff --git a/src/types.ts b/src/types.ts index d27975f8..6db7d0bd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -50,6 +50,10 @@ export interface DepositAddressResponse { description?: string; type: string; } +export interface GenerateAddressResponse { + address: string; + tag?: string; +} export interface TransactionArguments { assetId: string; @@ -107,6 +111,10 @@ export interface CancelTransactionResponse { success: boolean; } +export interface OperationSuccessResponse { + success: boolean; +} + export interface TransactionFilter { before?: number; after?: number;