0.1.7 • Published 3 years ago

@safient/claims v0.1.7

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

Safient Claims SDK

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

Installation

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

Running Tests

Create an .env file in the root dtrectory with INFURA_API_KEY

Terminal 1

  npm run chain

Terminal 2

  npm run deploy
  npm run tests

Getting started

  npm i @safient/claims

Usage

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

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

Initialization

import { SafientClaims } from '@safient/claims';

const sc = new SafientClaims(signer, chainId);

Arbitrator

sc.arbitrator.getArbitrationFee

SafientMain

sc.safientMain.createSafe
sc.safientMain.syncSafe
sc.safientMain.createClaim
sc.safientMain.submitEvidence
sc.safientMain.depositFunds
sc.safientMain.withdrawFunds
sc.safientMain.getTotalNumberOfSafes
sc.safientMain.getTotalNumberOfClaims
sc.safientMain.getSafeBySafeId
sc.safientMain.getClaimByClaimId
sc.safientMain.getClaimStatus
sc.safientMain.getContractBalance
sc.safientMain.guardianProof

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 (beneficiaryAddress, safeIdOnThreadDB, claimType, signalingPeriod, metaevidenceURI, value) => {
  try {
    const tx = await sc.safientMain.createSafe(
      beneficiaryAddress,
      safeIdOnThreadDB,
      claimType,
      signalingPeriod,
      metaevidenceURI,
      value
    );
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
beneficiaryAddressstringRequired. Address of the beneficiary who can claim to inherit this safe
safeIdOnThreadDBstringRequired. Safe Id on threadDB
claimTypestringRequired. Type of claim the inheritor has go through
signalingPeriodstringNumber of days within which the safe creator is willing to send a signal
metaevidenceURIstringIPFS 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

Sync Safe

const syncSafe = async (creatorAddress, safeIdOnThreadDB, claimType, signalingPeriod, metaevidenceURI, value) => {
  try {
    const tx = await sc.safientMain.syncSafe(
      creatorAddress,
      safeIdOnThreadDB,
      claimType,
      signalingPeriod,
      metaevidenceURI,
      value
    );
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
creatorAddressstringRequired. Address of the creator who created the safe offchain
safeIdOnThreadDBstringRequired. Safe Id on threadDB
claimTypestringRequired. Type of claim the inheritor has go through
signalingPeriodstringNumber of days within which the safe creator is willing to send a signal
metaevidenceURIstringIPFS 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 (safeIdOnThreadDB, evidenceURI) => {
  try {
    const tx = await sc.safientMain.createClaim(safeIdOnThreadDB, evidenceURI);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
evidenceURIstringIPFS URI pointing to the evidence submitted by the claim creator
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
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Deposit Safe Funds

const depositFunds = async (safeIdOnThreadDB, value) => {
  try {
    const tx = await sc.safientMain.depositFunds(safeIdOnThreadDB, value);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
valuestringRequired. Funds in Gwei
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Retrieve Safe Funds

Only safe's current owner can execute this

const withdrawFunds = async (safeIdOnThreadDB) => {
  try {
    const tx = await sc.safientMain.withdrawFunds(safeIdOnThreadDB);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
ReturnsTypeDescription
Transaction ResponseobjectIncludes all properties of a transaction

Send signal

Only safe's current owner can execute this

const sendSignal = async (safeIdOnThreadDB) => {
  try {
    const tx = await sc.safientMain.sendSignal(safeIdOnThreadDB);
    console.log(tx);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
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 Safe By Safe Id

const getSafeBySafeId = async (safeIdOnThreadDB) => {
  try {
    const safe = await sc.safientMain.getSafeBySafeId(safeIdOnThreadDB);
    console.log(safe);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
ReturnsTypeDescription
SafeSafeSafe containing safe data

Type Safe

PropertyTypeDescription
safeIdstringSafe Id on threadDB
safeCreatedBystringAddress of the safe creator
safeCurrentOwnerstringAddress of the current safe owner
safeBeneficiarystringAddress of the safe beneficiary
signalingPeriodBigumberNumber of days before which signal should be given
endSignalTimeBigumberEnd timestamp before which signal should be given
latestSignalTimeBigumberTimestamp at which signal is given
metaEvidenceIdBigumberId used to uniquely identify a piece of meta-evidence
claimsCountBigumberNumber of claims made on this safe
safeFundsBigumberTotal safe funds in Gwei

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

Type Claim

PropertyTypeDescription
claimTypeBigNumberType of claim 0 - SignalBased, 1 - ArbitrationBased
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
statusBigNumberClaim status represented by 0, 1, 2 or 3
resultstringClaim result represented by Passed, Failed or Refused To Arbitrate

Get Claim Status

const getClaimStatus = async (safeIdOnThreadDB, claimId) => {
  try {
    const claimStatus = await sc.safientMain.getClaimStatus(claimId);
    console.log(claimStatus);
  } catch (e) {
    console.log(e.message);
  }
};
ParameterTypeDescription
safeIdOnThreadDBstringRequired. Safe Id on threadDB
claimIdnumberRequired. Id of the claim
ReturnsTypeDescription
claim statusnumberClaim status represented by 0 - Active, 1 - Passed, 2 - Failed or 3 - Refused To Arbitrate

Get SafientMain Contract Total Balance

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

Guardian proof

const guardianProof = async (message, signature, guardianProof, secrets, safeIdOnThreadDB) => {
  try {
    const result = await sc.safientMain.guardianProof(message, signature, guardianProof, secrets, safeIdOnThreadDB);
    console.log(result);
  } catch (e) {
    console.log(e.message);
  }
};

Type RecoveryProof

PropertyTypeDescription
secretstringSecret
addressstringGuardian address
ParameterTypeDescription
messagestringRequired. Message generated during safe creation, also signed by the safe creator
signaturebytesRequired. Signature of the message signed by the creator
guardianProofRecoveryProofRequired. Object containing guardian address and his secret
secretsstring[]Required. Array of all the secrets of all the guardians, for cross verification
safeIdOnThreadDBstringRequired. Id of the safe on threadDB
ReturnsTypeDescription
Guardian proof resultbooleanGuardian proof is true or false