@trustless-work/escrow
Version:
<p align="center"> <img src="https://github.com/user-attachments/assets/5b182044-dceb-41f5-acf0-da22dea7c98a" alt="CLR-S (2)"> </p>
647 lines (642 loc) • 16.8 kB
TypeScript
/**
* Milestone
*/
type BaseMilestone = {
/**
* Text describing the function of the milestone.
*/
description: string;
/**
* Milestone status. Ex: Approved, In dispute, etc...
*/
status?: string;
/**
* Evidence of work performed by the service provider.
*/
evidence?: string;
};
/**
* Single Release Milestone
*/
type SingleReleaseMilestone = BaseMilestone & {
/**
* Approved flag, only if the escrow is single-release
*/
approved?: boolean;
};
/**
* Multi Release Milestone
*/
type MultiReleaseMilestone = BaseMilestone & {
/**
* Amount to be transferred upon completion of this milestone
*/
amount: number;
/**
* Address where milestone proceeds will be sent to
*/
receiver: string;
/**
* Flags validating certain milestone life states, only if the escrow is multi-release
*/
flags?: Flags;
};
/**
* Single Release Escrow
*/
type SingleReleaseEscrow = {
/**
* Address of the user signing the contract transaction
*/
signer: string;
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Unique identifier for the escrow
*/
engagementId: string;
/**
* Name of the escrow
*/
title: string;
/**
* Roles that make up the escrow structure
*/
roles: Roles;
/**
* Text describing the function of the escrow
*/
description: string;
/**
* Amount to be transferred upon completion of escrow milestones
*/
amount: number;
/**
* Commission that the platform will receive when the escrow is completed
*/
platformFee: number;
/**
* Amount of the token (XLM, USDC, EURC, etc) in the smart contract.
*/
balance: number;
/**
* Objectives to be completed to define the escrow as completed
*/
milestones: SingleReleaseMilestone[];
/**
* Flags validating certain escrow life states
*/
flags?: Flags;
/**
* Information on the trustline that will manage the movement of funds in escrow
*/
trustline: Trustline;
};
/**
* Multi Release Escrow
*/
type MultiReleaseEscrow = Omit<SingleReleaseEscrow, "milestones" | "flags" | "amount" | "roles"> & {
milestones: MultiReleaseMilestone[];
roles: Omit<Roles, "receiver">;
};
/**
* Trustline
*/
type Trustline = {
/**
* Symbol of the token, example: USDC, EURC, etc...
*/
symbol: string;
/**
* Public address establishing permission to accept and use a specific token.
*/
address: string;
};
/**
* Roles
*/
type Roles = {
/**
* Address of the entity requiring the service.
*/
approver: string;
/**
* Address of the entity providing the service.
*/
serviceProvider: string;
/**
* Address of the entity that owns the escrow
*/
platformAddress: string;
/**
* Address of the user in charge of releasing the escrow funds to the service provider.
*/
releaseSigner: string;
/**
* Address in charge of resolving disputes within the escrow.
*/
disputeResolver: string;
/**
* Address where escrow proceeds will be sent to
*/
receiver: string;
};
/**
* Role
*/
type Role = "approver" | "serviceProvider" | "platformAddress" | "releaseSigner" | "disputeResolver" | "receiver" | "signer";
/**
* Flags
*/
type Flags = {
/**
* Flag indicating that an escrow is in dispute.
*/
disputed?: boolean;
/**
* Flag indicating that escrow funds have already been released.
*/
released?: boolean;
/**
* Flag indicating that a disputed escrow has already been resolved.
*/
resolved?: boolean;
/**
* Flag indicating whether a milestone has been approved by the approver.
*/
approved?: boolean;
};
/**
* The base URL for the Trustless Work API
*/
type baseURL = "https://api.trustlesswork.com" | "https://dev.api.trustlesswork.com";
/**
* Escrow Type
*/
type EscrowType = "single-release" | "multi-release";
/**
* Escrow Status
*/
type SingleReleaseEscrowStatus = "working" | "pendingRelease" | "released" | "resolved" | "inDispute";
/**
* Unique possible statuses for a Trustless Work request
*/
type Status = "SUCCESS" | "FAILED";
/**
* Date
*/
type Date = {
_seconds: number;
_nanoseconds: number;
};
/**
* Escrow's Response like fund, release, change, etc ...
*/
type EscrowRequestResponse = {
/**
* Status of the request
*/
status: Status;
/**
* Unsigned transaction
*/
unsignedTransaction?: string;
};
/**
* Send Transaction Response
*/
type SendTransactionResponse = {
/**
* Status of the request
*/
status: Status;
/**
* Message of the request
*/
message: string;
};
/**
* Initialize Escrow Response
*/
type InitializeSingleReleaseEscrowResponse = EscrowRequestResponse & {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Escrow data
*/
escrow: SingleReleaseEscrow;
/**
* Message of the request
*/
message: string;
};
/**
* Initialize Multi Release Escrow Response
*/
type InitializeMultiReleaseEscrowResponse = InitializeSingleReleaseEscrowResponse & {
/**
* Escrow data
*/
escrow: MultiReleaseEscrow;
};
/**
* Update Escrow Response
*/
type UpdateSingleReleaseEscrowResponse = InitializeSingleReleaseEscrowResponse;
/**
* Update Multi Release Escrow Response
*/
type UpdateMultiReleaseEscrowResponse = InitializeMultiReleaseEscrowResponse;
/**
* Get Balances Response
*/
type GetEscrowBalancesResponse = {
/**
* Address of the escrow
*/
address: string;
/**
* Balance of the escrow
*/
balance: number;
};
/**
* Get Escrows From Indexer Response
*/
type GetEscrowsFromIndexerResponse = {
signer?: string;
contractId?: string;
engagementId: string;
title: string;
roles: Roles | (Omit<Roles, "receiver">);
description: string;
amount: number;
platformFee: number;
balance?: number;
milestones: SingleReleaseMilestone[] | MultiReleaseMilestone[];
flags?: Flags;
trustline: Trustline & {
name: string;
};
isActive?: boolean;
approverFunds?: string;
receiverFunds?: string;
user: string;
createdAt: Date;
updatedAt: Date;
type: EscrowType;
};
/**
* Response for updating escrow from transaction hash
*/
type UpdateFromTxHashResponse = {
/**
* Status of the request
*/
status: "SUCCESS" | "FAILED";
/**
* Message describing the result
*/
message: string;
};
/**
* Documentation: https://docs.trustlesswork.com/trustless-work/developer-resources/quickstart/integration-demo-project/entities
*/
/**
* Single Release Milestone Payload
*/
type SingleReleaseMilestonePayload = {
/**
* Text describing the function of the milestone
*/
description: string;
};
/**
* Multi Release Milestone Payload
*/
type MultiReleaseMilestonePayload = {
/**
* Text describing the function of the milestone
*/
description: string;
/**
* Amount to be transferred upon completion of this milestone
*/
amount: number;
/**
* Address where milestone proceeds will be sent to
*/
receiver: string;
};
/**
* Single Release Initialize Escrow Payload
*/
type InitializeSingleReleaseEscrowPayload = Omit<SingleReleaseEscrow, "contractId" | "balance" | "milestones"> & {
/**
* Objectives to be completed to define the escrow as completed
*/
milestones: SingleReleaseMilestonePayload[];
};
/**
* Multi Release Initialize Escrow Payload
*/
type InitializeMultiReleaseEscrowPayload = Omit<MultiReleaseEscrow, "contractId" | "balance" | "milestones"> & {
/**
* Objectives to be completed to define the escrow as completed
*/
milestones: MultiReleaseMilestonePayload[];
};
/**
* Single Release Update Escrow Payload
*/
type UpdateSingleReleaseEscrowPayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Escrow data
*/
escrow: Omit<SingleReleaseEscrow, "contractId" | "signer" | "balance"> & {
/**
* Whether the escrow is active. This comes from DB, not from the blockchain.
*/
isActive?: boolean;
};
/**
* Address of the user signing the contract transaction
*/
signer: string;
};
/**
* Multi Release Update Escrow Payload
*/
type UpdateMultiReleaseEscrowPayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Escrow data
*/
escrow: Omit<MultiReleaseEscrow, "contractId" | "signer" | "balance"> & {
/**
* Whether the escrow is active. This comes from DB, not from the blockchain.
*/
isActive?: boolean;
};
/**
* Address of the user signing the contract transaction
*/
signer: string;
};
/**
* Change Milestone Status Payload, this can be a single-release or multi-release
*/
type ChangeMilestoneStatusPayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Index of the milestone to be updated
*/
milestoneIndex: string;
/**
* New status of the milestone
*/
newStatus: string;
/**
* New evidence of work performed by the service provider.
*/
newEvidence?: string;
/**
* Address of the entity providing the service.
*/
serviceProvider: string;
};
/**
* Approve Milestone Payload, this can be a single-release or multi-release
*/
type ApproveMilestonePayload = Omit<ChangeMilestoneStatusPayload, "serviceProvider" | "newStatus"> & {
/**
* Address of the entity requiring the service.
*/
approver: string;
};
/**
* Single Release Start Dispute Payload. This starts a dispute for the entire escrow.
*/
type SingleReleaseStartDisputePayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Address of the user signing the contract transaction
*/
signer: string;
};
/**
* Multi Release Start Dispute Payload. This starts a dispute for a specific milestone.
*/
type MultiReleaseStartDisputePayload = SingleReleaseStartDisputePayload & {
/**
* Index of the milestone to be disputed
*/
milestoneIndex: string;
};
/**
* Resolve Dispute Payload
*/
type SingleReleaseResolveDisputePayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Address in charge of resolving disputes within the escrow.
*/
disputeResolver: string;
/**
* Distributions of the escrow amount to the receivers.
*/
distributions: [
{
/**
* Address of the receiver
*/
address: string;
/**
* Amount to be transferred to the receiver. All the amount must be equal to the total amount of the escrow.
*/
amount: number;
}
];
};
/**
* Multi Release Resolve Dispute Payload
*/
type MultiReleaseResolveDisputePayload = SingleReleaseResolveDisputePayload & {
/**
* Index of the milestone to be resolved
*/
milestoneIndex: string;
};
/**
* Withdraw remaining funds
*/
type WithdrawRemainingFundsPayload = SingleReleaseResolveDisputePayload;
/**
* Fund Escrow Payload, this can be a single-release or multi-release
*/
type FundEscrowPayload = {
/**
* Amount to be transferred upon completion of escrow milestones
*/
amount: number;
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Address of the user signing the contract transaction
*/
signer: string;
};
/**
* Get Escrows From Indexer Params
*/
type GetEscrowsFromIndexerParams = {
/**
* Page number. Pagination
*/
page?: number;
/**
* Sorting direction. Sorting
*/
orderDirection?: "asc" | "desc";
/**
* Order by property. Sorting
*/
orderBy?: "createdAt" | "updatedAt" | "amount";
/**
* Created at = start date. Filtering
*/
startDate?: string;
/**
* Created at = end date. Filtering
*/
endDate?: string;
/**
* Max amount. Filtering
*/
maxAmount?: number;
/**
* Min amount. Filtering
*/
minAmount?: number;
/**
* Is active. Filtering
*/
isActive?: boolean;
/**
* Escrow that you are looking for. Filtering
*/
title?: string;
/**
* Engagement ID. Filtering
*/
engagementId?: string;
/**
* Status of the single-release escrow. Filtering
*/
status?: SingleReleaseEscrowStatus;
/**
* Type of the escrow. Filtering
*/
type?: EscrowType;
/**
* If true, the escrows will be validated on the blockchain to ensure data consistency.
* This performs an additional verification step to confirm that the escrow data
* returned from the indexer matches the current state on the blockchain.
* Use this when you need to ensure the most up-to-date and accurate escrow information.
* If you active this param, your request will take longer to complete.
*/
validateOnChain?: boolean;
};
type GetEscrowsFromIndexerBySignerParams = GetEscrowsFromIndexerParams & {
/**
* Address of the user signing the contract transaction.
*/
signer: string;
};
type GetEscrowsFromIndexerByRoleParams = GetEscrowsFromIndexerParams & {
/**
* Role of the user. Required
*/
role: Role;
/**
* Address of the owner of the escrows. If you want to get all escrows from a specific role, you can use this parameter. But with this parameter, you can't use the signer parameter.
*/
roleAddress: string;
};
type GetEscrowFromIndexerByContractIdsParams = {
/**
* IDs (addresses) that identifies the escrow contracts.
*/
contractIds: string[];
/**
* If true, the escrows will be validated on the blockchain to ensure data consistency.
* This performs an additional verification step to confirm that the escrow data
* returned from the indexer matches the current state on the blockchain.
* Use this when you need to ensure the most up-to-date and accurate escrow information.
* If you active this param, your request will take longer to complete.
*/
validateOnChain?: boolean;
};
/**
* Single Release Release Funds Payload
*/
type SingleReleaseReleaseFundsPayload = {
/**
* ID (address) that identifies the escrow contract
*/
contractId: string;
/**
* Address of the user in charge of releasing the escrow funds to the service provider.
*/
releaseSigner: string;
};
/**
* Multi Release Release Funds Payload
*/
type MultiReleaseReleaseFundsPayload = SingleReleaseReleaseFundsPayload & {
/**
* Index of the milestone to be released
*/
milestoneIndex: string;
};
/**
* Get Balance Params
*/
type GetBalanceParams = {
/**
* Addresses of the escrows to get the balance
*/
addresses: string[];
};
/**
* Payload for updating escrow data from a transaction hash.
*/
type UpdateFromTxHashPayload = {
/**
* Transaction hash to be used for the update.
*/
txHash: string;
};
export type { ApproveMilestonePayload as A, UpdateFromTxHashResponse as B, ChangeMilestoneStatusPayload as C, EscrowRequestResponse as E, Flags as F, GetEscrowBalancesResponse as G, InitializeSingleReleaseEscrowResponse as I, MultiReleaseEscrow as M, Roles as R, SingleReleaseEscrow as S, Trustline as T, UpdateSingleReleaseEscrowResponse as U, WithdrawRemainingFundsPayload as W, SingleReleaseMilestone as a, baseURL as b, MultiReleaseMilestone as c, Role as d, SendTransactionResponse as e, InitializeMultiReleaseEscrowResponse as f, UpdateMultiReleaseEscrowResponse as g, GetEscrowsFromIndexerResponse as h, Status as i, EscrowType as j, InitializeSingleReleaseEscrowPayload as k, InitializeMultiReleaseEscrowPayload as l, SingleReleaseStartDisputePayload as m, MultiReleaseStartDisputePayload as n, SingleReleaseResolveDisputePayload as o, MultiReleaseResolveDisputePayload as p, FundEscrowPayload as q, SingleReleaseReleaseFundsPayload as r, MultiReleaseReleaseFundsPayload as s, UpdateSingleReleaseEscrowPayload as t, UpdateMultiReleaseEscrowPayload as u, GetBalanceParams as v, GetEscrowsFromIndexerBySignerParams as w, GetEscrowsFromIndexerByRoleParams as x, GetEscrowFromIndexerByContractIdsParams as y, UpdateFromTxHashPayload as z };