0.1.0 • Published 3 years ago

@consensolabs/claims-test v0.1.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

Safient Claims

JavaScript SDK to manage and interact with the safe claims on Safient protocol.

Installation

  git clone https://github.com/safient/safient-claims-js.git
  cd safient-claims-js
  npm install

Running Tests

Compile the TS code

  npx tsc

Run the chain on a separate terminal

  npm run chain

Run the tests

  npm run test

Getting started

  npm install safient-claims

Usage

// If not injected web3 provider, create a jsonRpcProvider
const { JsonRpcProvider } = require('@ethersproject/providers');
const provider = new JsonRpcProvider('http://localhost:8545');

// Get chainId from provider
(async () => {
  const providerNetwork = await provider.getNetwork();
  const chainId = providerNetwork.chainId;
})();

Initialization

import { SafientClaims } from 'safient-claims';

const sc = new SafientClaims(provider, chainId);

Arbitrator

sc.arbitrator.getArbitrationFee

SafientMain

sc.safientMain.createSafe
sc.safientMain.createClaim
sc.safientMain.submitEvidence
sc.safientMain.depositSafeFunds
sc.safientMain.recoverSafeFunds
sc.safientMain.setTotalClaimsAllowed
sc.safientMain.getTotalNumberOfSafes
sc.safientMain.getTotalNumberOfClaims
sc.safientMain.getAllSafes
sc.safientMain.getAllClaims
sc.safientMain.getSafeBySafeId
sc.safientMain.getClaimByClaimId
sc.safientMain.getClaimsOnSafeBySafeId
sc.safientMain.getClaimStatus
sc.safientMain.getTotalClaimsAllowed
sc.safientMain.getSafientMainContractBalance

API details

Arbitrator

Get Arbitration Fee

const getArbitrationFee = async () => {
  try {
    const fee = await sc.arbitrator.getArbitrationFee();
    console.log(fee);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Arbitration feenumberArbitration fee in ETH

SafientMain

Create Safe

const createSafe = async (inheritorAddress, metaevidenceURI, value) => {
  try {
    const tx = await sc.safientMain.createSafe(inheritorAddress, metaevidenceURI, value);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
inheritorAddressstringRequired. Address of the beneficiary who can claim to inherit this safe
metaevidenceURIstringRequired. IPFS URI pointing to the metaevidence related to arbitration details
valuestringRequired. Safe maintanence fee in Gwei, minimum arbitration fee required
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Create Claim

const createClaim = async (safeId, evidenceURI) => {
  try {
    const tx = await sc.safientMain.createClaim(safeId, evidenceURI);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdnumberRequired. Id of the safe
evidenceURIstringRequired. IPFS URI pointing to the evidence submitted by the claim creator
signerstringOptional & for test only. Specific signer account for test purpose
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Submit Evidence

const submitEvidence = async (disputeId, evidenceURI) => {
  try {
    const tx = await sc.safientMain.submitEvidence(disputeId, evidenceURI);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
disputeIdnumberRequired. Id of the dispute representing the claim
evidenceURIstringRequired. IPFS URI pointing to the evidence submitted by the claim creator
signerstringOptional & for test only. Specific signer account for test purpose
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Deposit Safe Funds

const depositSafeFunds = async (safeId, value) => {
  try {
    const tx = await sc.safientMain.depositSafeFunds(safeId, value);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdnumberRequired. Id of the safe
valuestringRequired. Funds in Gwei
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Recover Safe Funds

Only safe's current owner can execute this

const recoverSafeFunds = async (safeId) => {
  try {
    const tx = await sc.safientMain.recoverSafeFunds(safeId);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdnumberRequired. Id of the safe
signerstringOptional & for test only. Specific signer account for test purpose
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Set Total Claims Allowed

Only SafientMain contract deployer can execute this

const setTotalClaimsAllowed = async (claimsAllowed) => {
  try {
    const tx = await sc.safientMain.setTotalClaimsAllowed(claimsAllowed);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
claimsAllowednumberRequired. Number of total claims allowed
signerstringOptional & for test only. Specific signer account for test purpose
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Get Total Number Of Safes

const getTotalNumberOfSafes = async () => {
  try {
    const numOfSafes = await sc.safientMain.getTotalNumberOfSafes();
    console.log(numOfSafes);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Total no. of safesnumberTotal number of safes created on SafientMain

Get Total Number Of Claims

const getTotalNumberOfClaims = async () => {
  try {
    const numOfClaims = await sc.safientMain.getTotalNumberOfClaims();
    console.log(numOfClaims);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Total no. of claimsnumberTotal number of claims created on SafientMain

Get All Safes

const getAllSafes = async () => {
  try {
    const safes = await sc.safientMain.getAllSafes();
    console.log(safes);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Array of safesSafe[]Array of all the safes created on SafientMain

Type Safe

PropertyTypeDescription
safeIdBigNumberId of the safe
safeCreatedBystringAddress of the safe creator
safeCurrentOwnerstringAddress of the current safe owner
safeInheritorstringAddress of the safe inheritor (beneficiary)
metaEvidenceIdBigumberId used to uniquely identify a piece of meta-evidence
claimsCountBigumberNumber of claims made on this safe
safeFundsBigumberTotal safe funds in Gwei

Get All Claims

const getAllClaims = async () => {
  try {
    const claims = await sc.safientMain.getAllClaims();
    console.log(claims);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Array of claimsClaim[]Array of all the claims created on SafientMain

Type Claim

PropertyTypeDescription
safeIdBigNumberId of the safe
disputeIdBigNumberId of the dispute representing the claim
claimedBystringAddress of the claim creator
metaEvidenceIdBigNumberId used to uniquely identify a piece of meta-evidence
evidenceGroupIdBigumberId used to identify a group of evidence related to a dispute
statusnumberClaim status represented by 0, 1, 2 or 3
resultstringClaim result represented by Passed, Failed or Refused To Arbitrate

Get Safe By Safe Id

const getSafeBySafeId = async (safeId) => {
  try {
    const safe = await sc.safientMain.getSafeBySafeId(safeId);
    console.log(safe);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdnumberRequired. Id of the safe
ReturnsTypeDescription
SafeSafeSafe containing safe data

Get Claim By Claim Id

const getClaimByClaimId = async (claimId) => {
  try {
    const claim = await sc.safientMain.getClaimByClaimId(claimId);
    console.log(claim);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
claimIdnumberRequired. Id of the claim
ReturnsTypeDescription
ClaimClaimClaim containing claim data

Get All Claims On A Safe By Safe Id

const getClaimsOnSafeBySafeId = async (safeId) => {
  try {
    const claims = await sc.safientMain.getClaimsOnSafeBySafeId(safeId);
    console.log(claims);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdnumberRequired. Id of the safe
ReturnsTypeDescription
Array of claimsClaim[]Array of all the claims on a safe

Get Claim Status

const getClaimStatus = async (claimId) => {
  try {
    const claimStatus = await sc.safientMain.getClaimStatus(safeId);
    console.log(claimStatus);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
claimIdnumberRequired. Id of the claim
ReturnsTypeDescription
claim statusstringClaim status represented by Active, Passed, Failed or Refused To Arbitrate

Get Total No. Of Claims Allowed On A Safe

const getTotalClaimsAllowed = async () => {
  try {
    const claimsAllowed = await sc.safientMain.getTotalClaimsAllowed();
    console.log(claimsAllowed);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
Total no. of claims allowednumberTotal no. of claims allowed on a safe

Get SafientMain Contract Total Balance

const getSafientMainContractBalance = async () => {
  try {
    const balance = await sc.safientMain.getSafientMainContractBalance();
    console.log(balance);
  } catch (e) {
    console.log(e.message);
  }
};
ReturnsTypeDescription
SafientMain contract balancenumberTotal balance of SafientMain contract