UNPKG

@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>

622 lines (617 loc) 16.2 kB
/** * 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; /** * 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; /** * Field used to identify the recipient's address in transactions through an intermediary account. This value is included as a memo in the transaction and allows the funds to be correctly routed to the wallet of the specified recipient */ receiverMemo?: number; }; /** * Multi Release Escrow */ type MultiReleaseEscrow = Omit<SingleReleaseEscrow, "milestones" | "flags" | "amount"> & { milestones: MultiReleaseMilestone[]; }; /** * Trustline */ type Trustline = { /** * Public address establishing permission to accept and use a specific token. */ address: string; /** * Number of decimals into which the token is divided. */ decimals: number; }; /** * 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; description: string; amount: number; platformFee: number; balance?: number; milestones: SingleReleaseMilestone[] | MultiReleaseMilestone[]; flags?: Flags; trustline: Trustline & { name: string; }; receiverMemo?: number; isActive?: boolean; approverFunds?: string; receiverFunds?: string; user: string; createdAt: Date; updatedAt: Date; type: EscrowType; }; /** * 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; }; /** * 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; /** * New flag value of the milestone */ newFlag: boolean; }; /** * 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; /** * Amount of funds to be returned to the approver based on the global amount. */ approverFunds: number; /** * Amount of funds to be returned to the receiver based on the global amount. */ receiverFunds: number; }; /** * Multi Release Resolve Dispute Payload */ type MultiReleaseResolveDisputePayload = SingleReleaseResolveDisputePayload & { /** * Index of the milestone to be resolved */ milestoneIndex: string; }; /** * 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[]; /** * Address of the user signing the contract transaction. */ signer: 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 = { /** * Address of the user signing the contract transaction */ signer: string; /** * Addresses of the escrows to get the balance */ addresses: string[]; }; export type { ApproveMilestonePayload, ChangeMilestoneStatusPayload, EscrowRequestResponse, EscrowType, Flags, FundEscrowPayload, GetBalanceParams, GetEscrowBalancesResponse, GetEscrowFromIndexerByContractIdsParams, GetEscrowsFromIndexerByRoleParams, GetEscrowsFromIndexerBySignerParams, GetEscrowsFromIndexerResponse, InitializeMultiReleaseEscrowPayload, InitializeMultiReleaseEscrowResponse, InitializeSingleReleaseEscrowPayload, InitializeSingleReleaseEscrowResponse, MultiReleaseEscrow, MultiReleaseMilestone, MultiReleaseReleaseFundsPayload, MultiReleaseResolveDisputePayload, MultiReleaseStartDisputePayload, Role, Roles, SendTransactionResponse, SingleReleaseEscrow, SingleReleaseMilestone, SingleReleaseReleaseFundsPayload, SingleReleaseResolveDisputePayload, SingleReleaseStartDisputePayload, Status, Trustline, UpdateMultiReleaseEscrowPayload, UpdateMultiReleaseEscrowResponse, UpdateSingleReleaseEscrowPayload, UpdateSingleReleaseEscrowResponse, baseURL };