@midcontract/protocol
Version:
Crypto payment protocol with escrow
436 lines (432 loc) • 15.7 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
import { Abi, Account, Address, Chain, CustomTransport, EIP1193Provider, Hash, HttpTransport, Transaction, TransactionReceipt } from 'viem';
export type PartialRecord<K extends keyof never, T> = {
[P in K]?: T;
};
export type Environment = "prod" | "beta" | "beta2" | "test";
export type SymbolToken = "USDT" | "USDC" | "MockUSDT" | "MockDAI" | "MockUSDC";
export type DataToken = {
symbol: SymbolToken;
address: Address;
decimals: number;
};
export type TokenList = PartialRecord<SymbolToken, DataToken>;
export type ContractList = {
chainName: ChainNameEnum;
escrow: {
[key: string]: Address | Abi;
};
tokenList: TokenList;
};
declare enum ChainNameEnum {
Localhost = "Localhost",
Sepolia = "Sepolia",
BlastSepolia = "BlastSepolia",
PolygonAmoy = "PolygonAmoy"
}
declare enum DepositStatus {
NONE = 0,
ACTIVE = 1,// The contract is active and ongoing
SUBMITTED = 2,// Work submitted by the contractor but not yet approved
APPROVED = 3,// Work has been approved
COMPLETED = 4,// The final claim has been done
RETURN_REQUESTED = 5,// Client has requested a return of funds
DISPUTED = 6,// A dispute has been raised following a denied return request
RESOLVED = 7,// The dispute has been resolved
REFUND_APPROVED = 8,// Refund has been approved, funds can be withdrawn
CANCELED = 9
}
declare enum FeeConfig {
CLIENT_COVERS_ALL = 0,// Client covers all fees
CLIENT_COVERS_ONLY = 1,// Client pays only for his fee
CONTRACTOR_COVERS_CLAIM = 2,// Client covers only freelancer's claim fee
NO_FEES = 3
}
declare enum RefillType {
PREPAYMENT = 0,// Indicates a refill to the contract's general prepayment pool, which can be used to cover future claims.
WEEK_PAYMENT = 1
}
declare enum DisputeWinner {
NONE = 0,
CLIENT = 1,
CONTRACTOR = 2,
SPLIT = 3
}
declare class Deposit {
readonly contractor: Address;
readonly paymentToken: SymbolToken;
readonly amount: number;
readonly amountToClaim: number;
readonly amountToWithdraw: number;
readonly timeLock: bigint;
readonly contractorData: Hash;
readonly feeConfig: FeeConfig;
readonly status: DepositStatus;
constructor(data: readonly [
Address,
SymbolToken,
number,
number,
number,
bigint,
Hash,
FeeConfig,
DepositStatus
]);
}
export interface ContractInput {
functionName: string;
}
export interface EscrowDepositInput extends ContractInput {
contractor: Address;
tokenAddress: Address;
tokenSymbol: SymbolToken;
amount: number;
timeLock: bigint;
feeConfig: number;
recipientData: Hash;
}
export interface EscrowWithdrawInput extends ContractInput {
depositId: bigint;
}
export type TransactionInput = EscrowDepositInput | EscrowWithdrawInput;
export interface DepositAmount {
totalDepositAmount: number;
feeApplied: number;
}
export interface ClaimableAmount {
claimableAmount: number;
feeDeducted: number;
clientFee: number;
}
export interface DepositInput {
contractId: bigint;
contractorAddress: Address;
token: SymbolToken;
amount: number;
amountToClaim?: number;
amountToWithdraw?: number;
timeLock?: bigint;
recipientData: Hash;
feeConfig: FeeConfig;
status?: DepositStatus;
signature?: Hash;
}
export interface MilestoneDepositInput {
contractorAddress: Address;
token: SymbolToken;
amount: number;
amountToClaim?: number;
amountToWithdraw?: number;
timeLock?: bigint;
recipientData: Hash;
feeConfig: FeeConfig;
status?: DepositStatus;
signature?: Hash;
}
export interface HashMilestonesDepositInput {
contractor: Address;
amount: bigint;
amountToClaim?: bigint;
amountToWithdraw?: bigint;
contractorData: Hash;
feeConfig: FeeConfig;
status?: DepositStatus;
}
export interface HourlyDepositInput {
contractorAddress: Address;
amountToClaim?: number;
amountToWithdraw?: number;
feeConfig: FeeConfig;
}
export interface PreparedEscrowFixedPriceDeposit {
contractId: bigint;
contractor: Address;
paymentToken: Address;
amount: bigint;
amountToClaim: bigint;
amountToWithdraw: bigint;
contractorData: Hash;
feeConfig: number;
status: number;
escrow: Address;
expiration: bigint;
signature: Hash;
}
export interface PreparedEscrowMilestoneDeposit {
depositPayload: {
contractId: bigint;
paymentToken: Address;
milestonesHash: Address;
escrow: Address;
expiration: bigint;
signature: Address;
};
milestonesPayload: {
contractor: Address;
amount: bigint;
amountToClaim: bigint;
amountToWithdraw: bigint;
contractorData: Hash;
feeConfig: FeeConfig;
status: DepositStatus;
}[];
}
export interface PreparedEscrowHourlyDeposit {
contractId: bigint;
contractor: Address;
paymentToken: Address;
prepaymentAmount: bigint;
amountToClaim: bigint;
feeConfig: number;
escrow: Address;
expiration: bigint;
signature: Hash;
}
export interface GetFixedPriceDepositHash {
clientAddress: Address;
contractId: bigint;
contractor: Address;
paymentToken: Address;
amount: bigint;
feeConfig: number;
contractorData: Hash;
expiration: bigint;
}
export interface GetMilestoneDepositHash {
clientAddress: Address;
contractId: bigint;
paymentToken: Address;
milestonesHash: Hash;
expiration: bigint;
}
export interface GetHourlyDepositHash {
clientAddress: Address;
contractId: bigint;
contractor: Address;
paymentToken: Address;
prepaymentAmount: bigint;
amountToClaim: bigint;
feeConfig: number;
expiration: bigint;
}
export interface ApproveInput {
contractId: bigint;
valueApprove?: number;
valueAdditional?: number;
recipient?: Address;
token?: SymbolToken;
}
export interface ApproveInputMilestone {
contractId: bigint;
milestoneId: bigint;
valueApprove: number;
recipient: Address;
token: SymbolToken;
}
export interface ApproveInputHourly {
contractId: bigint;
weekId: bigint;
valueApprove: number;
recipient: Address;
token: SymbolToken;
}
export interface ApproveByAdminInputHourly extends ApproveInputHourly {
initializeNewWeek: boolean;
}
export type TransactionStatus = "pending" | "success" | "reverted";
export interface TransactionData {
transaction: Transaction;
input: TransactionInput;
status: TransactionStatus;
receipt: TransactionReceipt | null;
}
export interface TransactionId {
id: Hash;
status: TransactionStatus;
}
export interface DepositResponse extends TransactionId {
contractId: bigint;
}
export declare enum EscrowType {
FixedPrice = 0,
Milestone = 1,
Hourly = 2
}
export interface AbiFunction {
name: string;
inputs: {
components: {
type: string;
}[];
}[];
}
export interface AbiList {
fixedPriceAbi: readonly object[];
milestoneAbi: readonly object[];
hourlyAbi: readonly object[];
feeManagerAbi: readonly object[];
factoryAbi: readonly object[];
}
export declare class MidcontractProtocol {
private readonly contractList;
private escrow;
private wallet;
private public;
readonly blockExplorer: string;
private readonly factoryEscrow;
private readonly feeManagerEscrow;
fixedPriceAbi: [
];
milestoneAbi: [
];
hourlyAbi: [
];
feeManagerAbi: [
];
factoryAbi: [
];
environment: Environment;
private transactionStorage;
constructor(chain: Chain, transport: HttpTransport, contractList: ContractList, abiList: AbiList, environment: Environment, account?: Account);
static buildByEnvironment(name?: Environment, account?: Account, url?: string): MidcontractProtocol;
/** @deprecated */
changeTransport(transport: CustomTransport, account: Account): void;
changeProvider(provider: EIP1193Provider): Promise<void>;
changeEscrow(escrow: Address): void;
changeAccount(account: Account): void;
escrowDepositAmount(amount: number, feeConfig?: FeeConfig, tokenSymbol?: SymbolToken): Promise<DepositAmount>;
escrowClaimableAmount(amount: number, feeConfig?: FeeConfig, tokenSymbol?: SymbolToken): Promise<ClaimableAmount>;
getCoverageFee(wallet?: Hash, contractId?: bigint): Promise<number>;
getClaimFee(wallet?: Hash, contractId?: bigint): Promise<number>;
getMaxBPS(): Promise<number>;
getDepositList(contractId: bigint): Promise<Deposit>;
getDepositListMilestone(contractId: bigint, milestoneId: bigint): Promise<Deposit>;
getDepositListHourly(contractId: bigint, weekId: bigint): Promise<Deposit>;
currentContractId(): Promise<bigint>;
currentContractIdMilestone(): Promise<bigint>;
currentContractIdHourly(): Promise<bigint>;
get blockNumber(): Promise<number>;
get account(): Account;
private dataToken;
private tokenAllowance;
tokenBalance(account: Address, symbol?: SymbolToken): Promise<number>;
tokenApprove(amount: number, symbol?: SymbolToken): Promise<Hash>;
tokenRequireBalance(owner: Address, amount: number, symbol?: SymbolToken): Promise<void>;
tokenRequireAllowance(owner: Address, amount: number, symbol?: SymbolToken): Promise<void>;
escrowMakeSalt(salt: number): Hash;
private numberToBytes32;
escrowMakeDataHash(contractor: Hash, data: string, salt: Hash): Promise<Hash>;
hashContractorData(data: string, salt: Hash): `0x${string}`;
getTransactionReceipt(hash: Hash, waitReceipt?: boolean): Promise<TransactionReceipt | null>;
prepareEscrowDepositPayload(input: DepositInput): Promise<PreparedEscrowFixedPriceDeposit>;
escrowDeposit(input: PreparedEscrowFixedPriceDeposit, waitReceipt?: boolean): Promise<DepositResponse>;
prepareMilestoneDepositPayload(deposits: MilestoneDepositInput[], tokenSymbol: SymbolToken, escrowContractId: bigint): Promise<PreparedEscrowMilestoneDeposit>;
escrowMilestoneDeposit(input: PreparedEscrowMilestoneDeposit, waitReceipt?: boolean): Promise<DepositResponse>;
prepareEscrowDepositHourlyPayload(tokenSymbol: SymbolToken, prepaymentAmount: number | undefined, escrowContractId: bigint | undefined, deposit: HourlyDepositInput): Promise<PreparedEscrowHourlyDeposit>;
escrowDepositHourly(input: PreparedEscrowHourlyDeposit, waitReceipt?: boolean): Promise<DepositResponse>;
escrowSubmit(contractId: bigint, salt: Hash, data: string, signature: Hash, expiration: number, waitReceipt?: boolean): Promise<TransactionId>;
escrowSubmitMilestone(contractId: bigint, milestoneId: bigint, salt: Hash, data: string, signature: Hash, expiration: number, waitReceipt?: boolean): Promise<TransactionId>;
escrowRefill(contractId: bigint, value: number, waitReceipt?: boolean): Promise<TransactionId>;
escrowRefillMilestone(contractId: bigint, milestoneId: bigint, value: number, waitReceipt?: boolean): Promise<TransactionId>;
escrowRefillHourly(contractId: bigint, weekId: bigint, value: number, refillType: RefillType, waitReceipt?: boolean): Promise<TransactionId>;
escrowApprove(input: ApproveInput, waitReceipt?: boolean): Promise<TransactionId>;
escrowApproveMilestone(input: ApproveInputMilestone, waitReceipt?: boolean): Promise<TransactionId>;
escrowApproveHourly(input: ApproveInputHourly, waitReceipt?: boolean): Promise<TransactionId>;
escrowApproveByAdminHourly(input: ApproveByAdminInputHourly, waitReceipt?: boolean): Promise<TransactionId>;
escrowClaim(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowClaimMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowClaimAllMilestone(contractId: bigint, startMilestoneId: bigint, endMilestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowClaimHourly(contractId: bigint, weekId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowWithdraw(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowWithdrawMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
escrowWithdrawHourly(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
requestReturn(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
requestReturnMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
requestReturnHourly(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
approveReturn(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
approveReturnMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
approveReturnHourly(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
cancelReturn(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
cancelReturnMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
cancelReturnHourly(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
createDispute(contractId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
createDisputeMilestone(contractId: bigint, milestoneId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
createDisputeHourly(contractId: bigint, weekId: bigint, waitReceipt?: boolean): Promise<TransactionId>;
resolveDispute(contractId: bigint, winner: DisputeWinner, clientAmount: number, contractorAmount: number, waitReceipt?: boolean): Promise<TransactionId>;
resolveDisputeMilestone(contractId: bigint, milestoneId: bigint, winner: DisputeWinner, clientAmount: number, contractorAmount: number, waitReceipt?: boolean): Promise<TransactionId>;
resolveDisputeHourly(contractId: bigint, weekId: bigint, winner: DisputeWinner, clientAmount: number, contractorAmount: number, waitReceipt?: boolean): Promise<TransactionId>;
mintMockUSDTTokens(): Promise<TransactionId>;
deployEscrow(): Promise<{
userEscrow: Address;
salt: Hash;
}>;
deployMilestoneEscrow(): Promise<{
userEscrow: Address;
salt: Hash;
}>;
deployHourlyEscrow(): Promise<{
userEscrow: Address;
salt: Hash;
}>;
updateDefaultFees(coverageFee: number, claimFee: number): Promise<void>;
setSpecialFees(accountAddress: Address, coverageFee: number, claimFee: number): Promise<void>;
setContractSpecificFees(accountAddress: Address, contractId: bigint, coverageFee: number, claimFee: number): Promise<void>;
setInstanceFees(accountAddress: Address, coverageFee: number, claimFee: number): Promise<void>;
transactionByHashWait(hash: Hash): Promise<TransactionData>;
transactionByHash(hash: Hash, waitReceipt?: boolean): Promise<TransactionData>;
transactionByHashMilestoneWait(hash: Hash): Promise<TransactionData>;
transactionByHashMilestone(hash: Hash, waitReceipt?: boolean): Promise<TransactionData>;
transactionByHashHourlyWait(hash: Hash): Promise<TransactionData>;
transactionByHashHourly(hash: Hash, waitReceipt?: boolean): Promise<TransactionData>;
transactionParse(data: TransactionData): Promise<{
input: {
args: readonly unknown[];
functionName: string;
};
events: {
eventName: string;
args: readonly unknown[] | Record<string, unknown>;
}[];
}>;
transactionParseMilestone(data: TransactionData): Promise<{
input: {
args: readonly unknown[];
functionName: string;
};
events: {
eventName: string;
args: readonly unknown[] | Record<string, unknown>;
}[];
}>;
transactionParseHourly(data: TransactionData): Promise<{
input: {
args: readonly unknown[];
functionName: string;
};
events: {
eventName: string;
args: readonly unknown[] | Record<string, unknown>;
}[];
}>;
hashMilestones(milestoneInput: HashMilestonesDepositInput[]): Promise<Hash>;
private getFixedPriceDepositHash;
private getMilestoneDepositHash;
private getHourlyDepositHash;
private get tokenList();
parseAmount(tokenAddress: Address, amount: bigint): {
symbol: SymbolToken;
amount: number;
};
private parseLogs;
private parseLogsMilestone;
private parseLogsHourly;
private parseInput;
private parseInputMilestone;
private parseInputHourly;
private send;
private generateRandomNumber;
transactionUrl(transactionHash: Hash): string;
accountUrl(account: Address): string;
}
export {};