Skip to content

Commit

Permalink
Add smart transfers routes (#184)
Browse files Browse the repository at this point in the history
Add smart transfers routes
  • Loading branch information
asudimac authored Jul 26, 2023
1 parent 5bba9f9 commit 59cb7d1
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 0 deletions.
132 changes: 132 additions & 0 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ import {
TravelRuleVasp,
TravelRuleVaspFilter,
TravelRuleEncryptionOptions,
SmartTransfersTicketResponse,
SmartTransfersTicketCreatePayload,
SmartTransfersTicketsResponse,
SmartTransfersTicketsFilters,
SmartTransfersTicketTermPayload,
SmartTransfersTicketTermFundPayload,
SmartTransfersTicketTermResponse,
} from "./types";
import { AxiosProxyConfig, AxiosResponse } from "axios";
import { PIIEncryption } from "./pii-client";
Expand Down Expand Up @@ -1542,6 +1549,131 @@ export class FireblocksSDK {
return await this.apiClient.issuePutRequest(`/v1/screening/travel-rule/vasp/update`, vaspInfo);
}

/**
* Creates Smart Transfers ticket
* @param data
* @param requestOptions
*/
public async createSmartTransferTicket(data: SmartTransfersTicketCreatePayload, requestOptions?: RequestOptions): Promise<SmartTransfersTicketResponse> {
return await this.apiClient.issuePostRequest(`/v1/smart-transfers`, data, requestOptions);
}

/**
* Get Smart Transfer tickets
* @param filters
*/
public getSmartTransferTickets(filters: SmartTransfersTicketsFilters): Promise<SmartTransfersTicketsResponse> {
return this.apiClient.issueGetRequest(`/v1/smart-transfers?${queryString.stringify(filters)}`);
}

/**
* Get Smart Transfers ticket by id
* @param ticketId
*/
public getSmartTransferTicket(ticketId: string): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issueGetRequest(`/v1/smart-transfers/${ticketId}`);
}

/**
* Set Smart Transfers ticket expires in
* @param ticketId
* @param expiresIn
*/
public setSmartTransferTicketExpiresIn(ticketId: string, expiresIn: number): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/expires-in`, {expiresIn});
}

/**
* Set Smart Transfer ticket external id
* @param ticketId
* @param externalId
*/
public setSmartTransferTicketExternalId(ticketId: string, externalId: string): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/external-id`, {externalId});
}

/**
* Submit Smart Transfers ticket
* @param ticketId
* @param expiresIn
*/
public submitSmartTransferTicket(ticketId: string, expiresIn: number): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/submit`, {expiresIn});
}

/**
* Fulfill Smart Transfers ticket
* @param ticketId
*/
public fulfillSmartTransferTicket(ticketId: string): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/fulfill`, {});
}

/**
* Cancel Smart Transfers ticket
* @param ticketId
*/
public cancelSmartTransferTicket(ticketId: string): Promise<SmartTransfersTicketResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/cancel`, {});
}

/**
* Create Smart Transfers ticket term
* @param ticketId
* @param data
*/
public createSmartTransferTicketTerm(ticketId: string, data: SmartTransfersTicketTermPayload): Promise<SmartTransfersTicketTermResponse> {
return this.apiClient.issuePostRequest(`/v1/smart-transfers/${ticketId}/terms`, data);
}

/**
* Fet Smart Transfers ticket term
* @param ticketId
* @param termId
*/
public getSmartTransferTicketTerms(ticketId: string, termId: string): Promise<SmartTransfersTicketTermResponse> {
return this.apiClient.issueGetRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}`);
}

/**
* Update Smart Transfers ticket term
* @param ticketId
* @param termId
* @param data
*/
public updateSmartTransferTicketTerms(ticketId: string, termId: string, data: SmartTransfersTicketTermPayload): Promise<SmartTransfersTicketTermResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}`, data);
}

/**
* Fund Smart Transfers ticket term
* @param ticketId
* @param termId
* @param data
*/
public fundSmartTransferTicketTerm(ticketId: string, termId: string, data: SmartTransfersTicketTermFundPayload): Promise<SmartTransfersTicketTermResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}/fund`, data);
}

/**
* Manually fund Smart Transfers ticket term
* @param ticketId
* @param termId
* @param txHash
*/
public manuallyFundSmartTransferTicketTerms(ticketId: string, termId: string, txHash: string): Promise<SmartTransfersTicketTermResponse> {
return this.apiClient.issuePutRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}/manually-fund`, { txHash });
}

/**
* Delete Smart Transfers ticket term
* @param ticketId
* @param termId
*/
public deleteSmartTransferTicketTerms(ticketId: string, termId: string): Promise<void> {
return this.apiClient.issueDeleteRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}`);
}

private getCommaSeparatedList(items: Array<string>): string | undefined {
return items ? items.join(",") : undefined;
}
Expand Down
113 changes: 113 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,116 @@ export interface IssueTokenRequest {
issuerAddress?: string;
decimals: number;
}

export enum SmartTransfersTicketDirection {
EXCHANGE = "EXCHANGE",
SEND = "SEND",
RECEIVE = "RECEIVE",
INTERMEDIATE = "INTERMEDIATE",
}

export enum SmartTransfersTicketStatus {
DRAFT = "DRAFT",
PENDING_APPROVAL = "PENDING_APPROVAL",
OPEN = "OPEN",
IN_SETTLEMENT = "IN_SETTLEMENT",
FULFILLED = "FULFILLED",
EXPIRED = "EXPIRED",
CANCELED = "CANCELED",
}

export enum SmartTransferTicketTermStatus {
CREATED = "CREATED",
FUNDING = "FUNDING",
FUNDING_FAILED = "FUNDING_FAILED",
FUNDED = "FUNDED",
REJECTED = "REJECTED",
}

export interface SmartTransfersTicketTermPayload {
asset: string;
amount: string;
fromNetworkId: string;
toNetworkId: string;
}
export interface SmartTransfersTicketCreatePayload {
createdByNetworkId: string;
type: string;
expiresIn?: number;
terms?: SmartTransfersTicketTermPayload[];
externalId?: string;
note?: string;
submit?: boolean;
}

export interface SmartTransfersTicketTerm {
id: string;
asset: string;
amount: string;
fromNetworkId: string;
fromNetworkIdName?: string;
toNetworkId: string;
toNetworkIdName?: string;
txHash?: string;
fbTxId?: string;
transactionStatus: TransactionStatus;
status: SmartTransferTicketTermStatus;
createdAt: Date;
updatedAt: Date;
}

export interface SmartTransfersTicket {
id: string;
type: string;
direction?: SmartTransfersTicketDirection;
canceledByMe?: boolean;
createdByMe?: boolean;
status: SmartTransfersTicketStatus;
terms: SmartTransfersTicketTerm[];
expiresIn?: number;
expiresAt?: Date;
submittedAt?: Date;
createdAt: Date;
updatedAt: Date;
externalId?: string;
note?: string;
createdByNetworkId: string;
createdByNetworkIdName: string;
}

export interface SmartTransfersTicketTermResponse {
data: SmartTransfersTicketTerm;
}

export interface SmartTransfersTicketResponse {
data: SmartTransfersTicket;
}

export interface SmartTransfersTicketsResponse {
message?: string;
after?: string;
data: SmartTransfersTicket[];
}

export interface SmartTransfersTicketsFilters {
q?: string;
statuses?: SmartTransfersTicketStatus[];
networkId?: string;
externalId?: string;
after?: string;
limit?: number;
createdByMe?: boolean;
expiresAfter?: Date;
expiresBefore?: Date;
type?: string;
}

export interface SmartTransfersTicketTermFundPayload {
asset: string;
amount: string;
networkConnectionId: string;
srcId: string;
srcType: string;
fee?: string;
feeLevel?: FeeLevel;
}

0 comments on commit 59cb7d1

Please sign in to comment.