The AgenticPayContract is a Soroban-based smart contract designed to facilitate secure payments between clients and freelancers using an escrow mechanism. It ensures funds are held securely and only released upon delivery and approval of work.
Represents the current lifecycle state of a project.
Created: Project has been initialized but not yet funded.Funded: Escrow contains the required funds for the project.InProgress: Freelancer has started working on the project.WorkSubmitted: Freelancer has submitted the completion reference (e.g., GitHub repo).Verified: Submitted work has been automatically or manually verified.Completed: Work approved, funds released, and project finalized.Disputed: A party has raised a dispute regarding the work or payment.Cancelled: Project was terminated (e.g., due to deadline expiration or mutual agreement).
Main data structure storing project details.
id: Unique identifier (u64).client: Address of the project creator.freelancer: Address of the assigned freelancer.amount: Target budget for the project (i128).deposited: Current escrow balance (i128).status: Current state of the project (ProjectStatus).github_repo: Reference to the project workspace or submitted repository.description: Project description or scope of work.created_at: Unix timestamp of project creation.deadline: Unix timestamp for the project completion deadline (0 means no deadline).
Helper struct for batch creation of projects.
freelancer: Address of the freelancer to be assigned.amount: Project budget.description: Project description.github_repo: Workspace reference.
Initializes the contract with an administrator address. This address is used for dispute resolution and administrative metadata management.
- Parameters:
admin: The address to be set as the contract administrator.
- Permissions: Requires authorization from the provided
adminaddress. - Returns: None.
create_project(env: Env, client: Address, freelancer: Address, amount: i128, description: String, github_repo: String, deadline: u64) -> u64
Creates a new project and returns its unique ID.
- Parameters:
client: The address of the client creating the project.freelancer: The address of the freelancer assigned to the project.amount: The budget amount for the project.description: A brief description of the project.github_repo: The GitHub repository associated with the project.deadline: Unix timestamp for the project deadline.
- Permissions: Requires authorization from the
clientaddress. - Returns:
u64(The ID of the newly created project).
Creates multiple projects in a single optimized transaction.
- Parameters:
client: The address of the client creating the projects.projects: A vector ofProjectInputstructs.
- Permissions: Requires authorization from the
clientaddress. - Returns:
Vec<u64>(A list of IDs for the newly created projects).
Deposits funds into a project's escrow. If the total deposited matches or exceeds the project amount, the status transitions to Funded.
- Parameters:
project_id: The ID of the project to fund.client: The address of the client funding the project.amount: The amount to deposit.
- Permissions: Requires authorization from the
clientaddress. The project must be inCreatedstatus. - Returns: None.
Submits work for a project, typically by providing a GitHub repository URL.
- Parameters:
project_id: The ID of the project.freelancer: The address of the freelancer submitting the work.github_repo: The URL of the repository containing the work.
- Permissions: Requires authorization from the assigned
freelancer. The project must be inFundedorInProgressstatus. - Returns: None.
Approves the submitted work, releases the escrowed funds to the freelancer, and marks the project as Completed.
- Parameters:
project_id: The ID of the project to approve.client: The address of the client approving the work.
- Permissions: Requires authorization from the project
client. The project must be inWorkSubmittedorVerifiedstatus. - Returns: None.
Raises a dispute on a project, shifting it to the Disputed status for administrative resolution.
- Parameters:
project_id: The ID of the project.caller: The address of the party raising the dispute.
- Permissions: Requires authorization from either the
clientor thefreelancer. - Returns: None.
Resolves an active dispute, either releasing funds to the freelancer or refunding them to the client.
- Parameters:
project_id: The ID of the project.admin: The administrator address.release_to_freelancer: If true, funds are released to the freelancer; otherwise, they are refunded to the client.
- Permissions: Requires authorization from the stored
adminaddress. Project must be inDisputedstatus. - Returns: None.
Checks if a project has passed its deadline. If expired and not in a terminal state, the project is automatically cancelled and funds are marked for refund.
- Parameters:
project_id: The ID of the project to check.
- Returns:
bool(True if the project was automatically cancelled).
Retrieves the details of a specific project.
- Parameters:
project_id: The ID of the project.
- Returns: The
Projectstruct containing project state.
Returns the total number of projects created.
- Returns:
u64.
Stores an arbitrary metadata key-value pair at the contract level.
- Parameters:
admin: The administrator address.key: The metadata key.value: The metadata value.
- Permissions: Requires administrator authorization.
- Returns: None.
Retrieves metadata associated with a specific key.
- Parameters:
key: The metadata key.
- Returns:
Option<String>containing the value if found.
Deletes a metadata entry.
- Parameters:
admin: The administrator address.key: The metadata key.
- Permissions: Requires administrator authorization.
- Returns: None.
Upgrades the contract logic to a new WASM binary while preserving all storage.
- Parameters:
admin: The administrator address.new_wasm_hash: The SHA-256 hash of the new contract WASM.
- Permissions: Requires administrator authorization.
- Returns: None.
Returns the current implementation version of the contract.
- Returns:
u32(Current: 1).
- Creation: Client calls
create_projectto define scope and assignee. - Funding: Client calls
fund_projectto lock funds in escrow. - Submission: Freelancer calls
submit_workwith proof of delivery. - Completion: Client calls
approve_workto release funds.
- Conflict: Either party calls
raise_disputeif expectations are not met. - Mediation: Admin reviews and calls
resolve_disputeto finalize payment or refund.
- Timeout: If the
deadlineis set and passed, any user can triggercheck_deadline. - Cancellation: The contract automatically cancels the project and authorizes a refund if the deadline is missed.