@agreewe/quickwork-sdk
v1.0.1
Published
Quickwork SDK to allow TS applications to interact with the Quickwork Smart Contract
Downloads
6
Readme
Introduction
This package acts as an interaction layer for the Solidity program found in contracts/quickwork.sol. Quickwork allows for tasks to be proposed by a group, and accomplished by an individual or another group. Once the tasks are deemed completed by the proposers, the various parties can sign on each individual deliverable and release the task bounty attached to each.
Installation instructions
First, install this package via the command below.
npm i @agreewe/solana-blockchain-contracts
Initializing Quickwork Contract
Types and enums:
export enum ApprovalType {
ALL = 0, // Requires all in the SignerList to sign on each deliverable to be considered completed
MAJORITY = 1 // Requires > 50% majority in SignerList to sign on each deliverable to be considered completed (e.g. 1/2, 6/11)
}
export interface Deliverable {
task: string; // Task description
approvalType: ApprovalType; // Type of approval as seen above
completed: boolean, // Set to false unless it is already completed from the start
taskBounty: number // USDC amount - Take note of decimals: 2000000 = USDC $2
}
export interface DeploymentArgs {
deliverableList: Deliverable[];
signerList: string[];
receiverAddress: string;
agreementEndDate: number; // unix timestamp
withdrawalAddress: string;
}
If you have not initialized a contract before, refer to the code below.
Only wallet address in the SignerList are able to sign on task to deem it as completed.
Withdrawal address will be the only wallet which can initiate withdrawAll function (only after current date is past the end date of the agreement)
import { deployQuickWorkContract, DeploymentArgs } from 'quickwork-sdk';
import { ethers } from 'ethers';
const deploymentWallet = new ethers.Wallet(PRIVATE_KEY, new ethers.providers.JsonRpcProvider(GOERLI_RPC_URL));
const params: DeploymentArgs = {
deliverableList: [{
task: "Task 1",
approvalType: 0,
completed: false,
taskBounty: 2000000 //in USDC
}, {
task: "Task 2",
approvalType: 1,
completed: false,
taskBounty: 3000000 //in USDC
}],
signerList: [signer1.address, signer2.address, signer3.address],
receiverAddress: signer1.address,
agreementEndDate: 1669934745,
withdrawalAddress: deploymentWallet.address, // Does NOT have to be the deployment wallet address.
}
const deploy = async () => {
const contract = await deployQuickWorkContract(wallet1, params);
return contract.address;
}
const contractAddr = deploy();
Take note that the contract has to be funded with >= USDC than the total USDC required for pay outs.
Initiating Quickwork Instance
const quickworkInstance = new QuickWorkContract(deploymentWallet, contractAddress)
Getting Deliverable Details
const firstTask = quickworkInstance.getDeliverable(deliverableNo)
Signing Deliverable
await quickworkInstance.signDeliverable(deliverableNo)
Check If a Deliverable has been Signed by a Specific Party
await quickworkInstance.isDeliverableApprovedBySigner(deliverableNo, address)
Distribute Task Bounty for Specific Task
This can only be done if the task has been signed by sufficient number of signers and been marked as completed. Task will be automatically marked as completed if the requirements of number of signers are met.
await quickworkInstance.releaseDeliverableSpecificFund(deliverableNo)
Withdraw All
The withdraw all function withdraws all ETH and USDC in the contract to the withdrawalAddr wallet. This can only be done if the current time is past the end date of the agreement. This function can only be called by the withdrawalAddr specified when deploying the Quickwork Smart Contract.
await quickworkInstance.withdrawAll()
There are other functions such as getAgreementEndDate(), isUserAllowedToSign(), isDeliverablePaid(), getTotalSigners(), getReceiverAddress(), getSignerCountOnDeliverable() and more. These functions can be found in src/index.ts