Skip to content

Commit

Permalink
contract-service - adding endpoints (#221)
Browse files Browse the repository at this point in the history
* adding new endpoints

* longDescription

* omit vendorId

* responses

* PendingTokenLinkDto

* remove TokenLinkPermissionEntry

---------

Co-authored-by: orman <[email protected]>
  • Loading branch information
or109 and orman authored Nov 15, 2023
1 parent ed3127e commit 016eb1b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 12 deletions.
65 changes: 61 additions & 4 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import {
PublicKeyInformation,
DropTransactionResponse,
TokenLink,
TokenLinkPermissionEntry,
IssueTokenRequest,
NFTOwnershipStatus,
NFTOwnershipStatusUpdatedPayload,
Expand Down Expand Up @@ -101,14 +100,23 @@ import {
UsersGroup,
LeanContractTemplateDto,
ContractTemplateDto,
BatchTask, BatchJob, JobCreatedResponse,
BatchTask,
BatchJob,
JobCreatedResponse,
ContractUploadRequest,
ContractDeployResponse,
ContractDeployRequest,
PendingTokenLinkDto,
TAP,
ExchangeAccountsPageFilter,
PagedExchangeResponse,
TAP,
WriteCallFunctionDto,
ReadCallFunctionDto,
WriteCallFunctionResponseDto,
ContractAbiResponseDto,
DeployedContractResponseDto,
LeanDeployedContractResponseDto,
ParameterWithValueList,
} from "./types";
import { AxiosProxyConfig, AxiosResponse } from "axios";
import { PIIEncryption } from "./pii-client";
Expand Down Expand Up @@ -1689,6 +1697,55 @@ export class FireblocksSDK {
return await this.apiClient.issuePostRequest(`/v1/contract-registry/contracts/${contractId}/deploy`, payload);
}

/**
* Get all contracts by blockchain and template
* @param blockchainId
* @param templateId
*/
public async getContractsByFilter(templateId: string, blockchainId?: string): Promise<LeanDeployedContractResponseDto[]> {
const requestFilter = {
templateId,
blockchainId,
};
return await this.apiClient.issueGetRequest(`/v1/contract-service/contract?${queryString.stringify(requestFilter)}`);
}

/**
* Get contract by blockchain and address
* @param blockchainId
* @param templateId
*/
public async getContractByAddress(blockchainId: string, contractAddress: string): Promise<DeployedContractResponseDto> {
return await this.apiClient.issueGetRequest(`/v1/contract-service/contract/${blockchainId}/${contractAddress}`);
}

/**
* Get contract's ABI by blockchain and address
* @param blockchainId
* @param templateId
*/
public async getContractAbi(blockchainId: string, contractAddress: string): Promise<ContractAbiResponseDto> {
return await this.apiClient.issueGetRequest(`/v1/contract-service/contract/${blockchainId}/${contractAddress}/abi`);
}

/**
* Call contract read function
* @param blockchainId
* @param templateId
*/
public async readContractCallFunction(blockchainId: string, contractAddress: string, payload: ReadCallFunctionDto): Promise<ParameterWithValueList> {
return await this.apiClient.issuePostRequest(`/v1/contract-service/contract/${blockchainId}/${contractAddress}/function/read`, payload);
}

/**
* Call contract write function
* @param blockchainId
* @param templateId
*/
public async writeContractCallFunction(blockchainId: string, contractAddress: string, payload: WriteCallFunctionDto): Promise<WriteCallFunctionResponseDto> {
return await this.apiClient.issuePostRequest(`/v1/contract-service/contract/${blockchainId}/${contractAddress}/function/write`, payload);
}

/**
* Issue a new token and link it to the tenant
* @param payload
Expand Down Expand Up @@ -1737,7 +1794,7 @@ export class FireblocksSDK {
/**
* Get all pending tokens linked to the tenant
*/
public async getPendingLinkedTokens(): Promise<TokenLink[]> {
public async getPendingLinkedTokens(): Promise<PendingTokenLinkDto[]> {
return await this.apiClient.issueGetRequest(`/v1/tokenization/tokens/pending`);
}

Expand Down
49 changes: 41 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,6 @@ export interface ContractUploadRequest {
docs?: ContractDoc;
abi?: AbiFunction[];
attributes?: Record<string, string>;
vendorId?: string;
}
interface AbiFunction {
name?: string;
Expand Down Expand Up @@ -1578,6 +1577,7 @@ export interface ContractTemplateDto {
id: string;
name: string;
description: string;
longDescription: string;
compilerOutputMetadata?: object;
abi: AbiFunction[];
attributes?: Record<string, string>;
Expand All @@ -1587,27 +1587,24 @@ export interface ContractTemplateDto {
isPublic: boolean;
}

export interface TokenLinkPermissionEntry {
permission: "MINT" | "BURN";
vaultAccountId: string;
}

export interface LinkedTokenMetadata {
assetId: string;
name?: string;
symbol?: string;
networkProtocol?: string;
totalSupply?: string;
holdersCount?: number;
type?: string;
contractAddress?: string;
issuerAddress?: string;
testnet?: boolean;
blockchain?: string;
decimals?: number;
vaultAccountId?: string;
}
export interface TokenLink {
id: string;
assetId: string;
assetMetadata?: LinkedTokenMetadata;
permissions: TokenLinkPermissionEntry[];
}
export interface PendingTokenLinkDto {
id: number;
Expand All @@ -1618,6 +1615,28 @@ export interface PendingTokenLinkDto {
blockchainId?: string;
}

export interface LeanDeployedContractResponseDto {
contractAddress: string;
blockchainId: string;
contractTemplateId: string;
}

export interface DeployedContractResponseDto extends LeanDeployedContractResponseDto {
id: string;
vaultAccountId?: string;
}

type ContractAbi = AbiFunction[];

export interface ContractAbiResponseDto {
abi: ContractAbi;
implementationAbi?: ContractAbi;
}

export interface WriteCallFunctionResponseDto {
txId: string;
}

export interface IssueTokenRequest {
symbol: string;
name: string;
Expand Down Expand Up @@ -1675,12 +1694,26 @@ interface ParameterWithValue {
description?: string;
value: any;
}
export type ParameterWithValueList = ParameterWithValue[] | ParameterWithValueList[];


interface EVMTokenCreateParamsDto {
contractId: string;
constructorParams?: Array<ParameterWithValue>;
}

export interface ReadCallFunctionDto {
abiFunction: AbiFunction;
}

export interface WriteCallFunctionDto {
vaultAccountId: string;
abiFunction: AbiFunction;
amount?: string;
feeLevel?: FeeLevel;
note?: string;
}

export enum SmartTransfersTicketDirection {
EXCHANGE = "EXCHANGE",
SEND = "SEND",
Expand Down

0 comments on commit 016eb1b

Please sign in to comment.