@blockswaplab/k2-sdk

2.0.6 • Public • Published

@blockswaplab/k2-sdk

K2 SDK is a typescript SDk which can be used to interact with the K2 Lending protocol.

Installation

To install the SDK use the command npm i @blockswaplab/k2-sdk

Using the K2 SDK

One of the ways to import and initialise the SDK is:

import { K2 } from "@blockswaplab/k2-sdk";

const provider = new ethers.InfuraProvider(
  "goerli",
  INFURA_PROJECT_ID,
  INFURA_PROJECT_SECRET
);
const signer = new ethers.Wallet(PRIV_KEY, provider);

const sdk = new K2(signer);

For using the fundSplitter sub-class, the SDK instance can be initialised with the fund splitter contract address as follows:

const sdk = new K2(signer, fundSplitterAddress);

The SDK supports both goerli (until it is deprecated) and mainnet, hence the user should choose the network as per the need.

Please note that the SDK is an ethers.js based SDK and hence requires ethers based signer instance. It also returns values in ethers.js supported format. For example, it returns BigInt for the smart contract view functions that might return uint (BigNumber in case of ethers v5).

Also note that K2 SDK v2 uses ethers v6. If you are using K2 SDK v1 which makes use of ethers v5, please create the signer and provider instances in the following way:

const provider = new ethers.providers.InfuraProvider("goerli", {
    projectId: INFURA_PROJECT_ID,
    projectSecret: INFURA_PROJECT_SECRET
});
const signer = new ethers.Wallet(PRIV_KEY, provider);

The SDK exposed following sub-classes:

utils sub-class

The following readme describes all the functions and their parameters exposed by the utils class of the K2 SDK.

add0x function

This function can be used to append 0x towards the start of a string to convert it into a hex string accepted by the contracts. If the input string already contains the 0x, the function will return the string as is.

Input Parameters

data: string which needs to be appended by 0x

Using add0x function

await sdk.utils.add0x(data);

Return Parameter

Returns hex string

remove0x function

This function removes 0x from the beginning of a string. If the input string doesn't contain 0x, it will return the string as is.

Input Parameters

data: string to remove 0x from

Using remove0x function

await sdk.utils.remove0x(data);

Return Parameter

Returns string without 0x in the beginning.

generateLivenessReport function

This function can be used to generate a liveness reports of the software being run.

Input Parameters

middlewareAPI: API endpoint of the middleware

Using generateLivenessReport function

await sdk.utils.generateLivenessReport(middlewareAPI);

Return Parameter

Returns a liveness report. Here's a sample liveness report:

{
  "rpbsSelfAttestation": {
    "signature": {
      "z1Hat": "6404105216342bd57fa13ea8...310b519feb117f9e25087fe584f2",
      "c1Hat": "1e4b7e54b1ba032ef94f2b89...b6ef01c823e20454c1166fb9aa19",
      "s1Hat": "1d4a3c56bf2be321d0a6aac4...7a19ed3082b21c94357e16885278",
      "c2Hat": "16755d115768ef6ebb0c45d...f4b9ffe0126b599d5d486f5574653",
      "s2Hat": "1140c70f8b38105aca1d465...3bbe9f89dbc00da6646c48aa5eaa1",
      "m1Hat": "6404223e9396cce38a9bf6a...48d0df6055de44898ecd0e0004ca4"
    },
    "commonInfo": {
      "numOfValidatorsOnline": "8",
      "numOfValidatorsOffline": "2",
      "totalValidators": "10"
    },
    "publicKey": "630409260df6b583400e97...42db0603ca1fe7766d45ac42f6c0"
  },
  "eventType": "LIVENESS",
  "version": "1",
  "eventData": {
    "numOfValidatorsOnline": "8",
    "numOfValidatorsOffline": "2",
    "totalValidators": "10",
    "proposedSlashing": "0"
  }
}

getMiddlewareInfo function

This function can be used to get the info from the middleware endpoint.

Input Parameters

middlewareAPI: API endpoint of the middleware

Using getMiddlewareInfo function

await sdk.utils.getMiddlewareInfo(middlewareAPI);

Return Parameter

The function returns info related to the middleware API. Here's an example of the info:

{
    "VERSION":"1",
    "CHAIN_ID":"5","SERVICE_PROVIDER_BORROW_ADDRESS":"0xEa0F09A471dCe34d7d3675787B1D68D841FF56D2","K2_LENDING_CONTRACT":"0x7E015fa28e05eD002Ac166D230cD3c3726CC2e7E","K2_REPORTER_REGISTRY":"0x88Cc3B6e96ef8E78b592eaDc135a0DF31991bE20",
    "LIVENESS_ENDPOINT":"https://endpoint.amazonaws.com/goerli/liveness",
    "REPORT_DEADLINE_LENGTH_IN_ETH_BLOCKS":"125"
}

verifyReport function

Once the liveness or the corruption report has been generated, it needs to be verified before submitting it to the reporter registry. To verify the report, verifyReport function should be used.

Input Parameters

middlewareAPI: API endpoint of the middleware
report: Liveness or the corruption report returned by the respective function

Using verifyReport function

await sdk.utils.verifyReport(middlewareAPI, report);

Return Parameter

The function returns a verified report which contains the liveness report along with a signature valid for 20 minutes. Here's how a verified report looks like:

{
  "inputs": {
    "rpbsSelfAttestation": {
      "signature": {
      "z1Hat": "6404105216342bd57fa13ea8...310b519feb117f9e25087fe584f2",
      "c1Hat": "1e4b7e54b1ba032ef94f2b89...b6ef01c823e20454c1166fb9aa19",
      "s1Hat": "1d4a3c56bf2be321d0a6aac4...7a19ed3082b21c94357e16885278",
      "c2Hat": "16755d115768ef6ebb0c45d...f4b9ffe0126b599d5d486f5574653",
      "s2Hat": "1140c70f8b38105aca1d465...3bbe9f89dbc00da6646c48aa5eaa1",
      "m1Hat": "6404223e9396cce38a9bf6a...48d0df6055de44898ecd0e0004ca4"
    },
      "commonInfo": {
        "numOfValidatorsOnline": "8",
        "numOfValidatorsOffline": "2",
        "totalValidators": "10"
      },
      "publicKey": "630409260df6b583400e97...42db0603ca1fe7766d45ac42f6c0"
    },
    "eventType": "LIVENESS",
    "version": "1",
    "eventData": {
      "numOfValidatorsOnline": "8",
      "numOfValidatorsOffline": "2",
      "totalValidators": "10",
      "proposedSlashing": "100000000000000000"
    }
  },
  "signedReport": {
    "slashType": "0",
    "debtor": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
    "block": 9819746,
    "signature": "0x3634303432336464663333323864663263623136393239373137626261356634353366323963396637623832313062343537633436633237363731383938303230386533306432346662636537316531333061366538663364346161333731616461646464653639663834346163316464616365386363663562626632653561633166643a313838333339343262373434633436323232343865323862346465353963613930633639366530623538633336393433666362643566386136383361656461653a306631316464373530393337306632316339393534643063373432313338303632323931323734393961373961386663376633353963643434353439306363353a323631363139626337656338306630613863663333643836643430373062636465313262383138303632653437396236333235623836396438323066343933633a313662383438646230666533303561363366353061346633613661383963613165326531616165626363653630363431623865633931643438323439363335343a363430343136373630313961363065396135336563323766303835363638336433653039396130616331643938376665633165636464383663636536633866643438363232306237373165643464303836343730376334666436386631386363663831333135643533303531373964346237346233363530343933346164306130326163",
    "amount": {
      "type": "BigInt",
      "hex": "0x016345785d8a0000"
    },
    "identifier": 1
  },
  "designatedVerifierSignature": {
    "deadline": 9819746,
    "v": 27,
    "r": "0x3a61148c3a2fdd3a9fe2c6133bbddf579333a630663f0c19dce8ecfb62484392",
    "s": "0x1b4f68b48c177edf8f10f1f382cfb0c73920ecac7ed564e82909d57f119b3a11"
  }
}

verifyEffectiveBalance function

This function can be used to batch verify effective balance of a list of BLS public keys.

Input Parameters

blsPublicKeys: List of BLS public keys in string format
effectiveBalances: List of effective balance in string corresponding to each BLS public key

Using verifyEffectiveBalance function
await sdk.utils.verifyEffectiveBalance(blsPublicKeys, effectiveBalances);
Return Parameter

The function returns a list of verified effective balance report after it has been successfully verified and error otherwise.

// Format of verified effective balance reports
[
report: {
    blsKey: string,
    effectiveBalance: string
  },
  designatedVerifierSignature: {
    v: string,
    r: string,
    s: string
  }
]

readUsingMulticall function

Allows to read batch values from a contract in a single RPC call.

Input Parameters

targetContract: Address of the target contract in string format
allowFailure: Boolean. Set to true to throw error if any one value is rejected by the contract
calldata: List of calldata in string

Using readUsingMulticall function

await sdk.utils.readUsingMulticall(targetContract, allowFailure, calldata);

Return Parameter

Returns a list of response for each call data in the format:

{
  bool success; // True if the call succeeded, false otherwise.
  bytes returnData; // Return data if the call succeeded, or revert data if the call reverted.
}

The result will have to be decoded to correctly get all the values.

/// Example: decode the values from the result after using multicall read method 
/// on the claimableKETHForNodeOperator function.
/// contractInterface: ABI interface of the contract that defines said function, created using ethersjs
const previewValues = multicall.map(({ success, returnData }, i) => {
    if (!success) throw new Error(`Failed to resolve data for calldata[${i}]`);
    return contractInterface.decodeFunctionResult(
      "claimableKETHForNodeOperator",
      returnData
  )[0];
});

getEffectiveBalance function

Get effective balance of a BLS public key from the consensus layer.

Input Parameters

beaconNodeUrl: Beacon node URL string
blsPublicKey: BLS public key in string format to get effective balance of

Using getEffectiveBalance function

await sdk.utils.getEffectiveBalance(beaconNodeUrl, blsPublicKey);

Return Parameter

Effective balance in numbers

generateCorruptionReport function

Generate corruption report from the data received from middleware API endpoint.

Input Parameters

middlewareAPI: API endpoint of the middleware
eventData: event data of the format CorruptionEventDataT
message: string message which needs to be mentioned in the report. Default value: ''
debtorOverride: optional debtor address. Can be left null for the function to fetch debtor address from the middlewareAPI

Using generateCorruptionReport function

await sdk.utils.generateCorruptionReport(middlewareAPI, eventData, message, debtorOverride);

Return Parameter

Returns corruption report of the format:

{
    rpbsSelfAttestation: {
    signature: marshalledSignature,
      commonInfo: commonInfo,
      publicKey: rpbsPublicKey
    },
    eventType: "CORRUPTION",
    version: version,
    eventData: eventData,
    serviceProviderAddress: debtor
}

claimEffectiveBalance function

Claim effective balance for all the BLS public keys delegated by the user.

Input Parameters

beaconNodeUrl: Beacon node URL in string
userAddress: user address in string

Using claimEffectiveBalance function

await sdk.utils.claimEffectiveBalance(beaconNodeUrl, userAddress);

Return Parameter

Transaction hash

getClaimableKETHForNodeOperator function

Preview claimable effective balance for all the BLS public keys delegated by the user.

Input Parameters

userAddress: user address in string

Using getClaimableKETHForNodeOperator function

await sdk.utils.getClaimableKETHForNodeOperator(userAddress);

Return Parameter

List of claimable kETH in Big Numbers

getAllDelegetedBLSPublicKeysForNodeRunner function

Get a list of BLS public keys delegated by a node operator.

Input Parameters

nodeRunnerAddress: Address of the node runner in string

Using getAllDelegetedBLSPublicKeysForNodeRunner function

await sdk.utils.getAllDelegetedBLSPublicKeysForNodeRunner(nodeRunner);

Return Parameter

List of BLS public keys

getAllDelegetedBLSPublicKeys function

List of all the delegated BLS public keys in the K2 protocol.

Using getAllDelegetedBLSPublicKeys function

await sdk.utils.getAllDelegetedBLSPublicKeys();

Return Parameter

List of BLS public keys

contracts sub-class

The SDK also exposes the contractInstance sub-class which provides an instance for contracts used in the K2 lending protocol. These instances can be used to call smart contract functions that may or may not exist in the SDK.

Contract instances exposed by the sub-class

  • k2LendingContract
  • k2LendingDepositor
  • ReporterRegistry
  • nodeOperatorModule
  • rst
  • rstModule
  • k2NativeDelegationRSTIncentives
  • nodeOperatorInclusionList
  • partitionedLinearInterestRateModel
  • pnoRegistry
  • lien
  • fundSplitterFactory
  • fundSplitter

Using the contractInstance class

const k2LendingContractInstance = await sdk.contracts.k2LendingContract();
const k2LendingDepositorInstance = await sdk.contracts.k2LendingDepositor();
const reporterRegistryInstance = await sdk.contracts.reporterRegistry();
const nodeOperatorModuleInstance = await sdk.contracts.nodeOperatorModule();
const rstInstance = await sdk.contracts.rst("INSERT_RST_CONTRACT_ADDRESS");
const rstModuleInstance = await sdk.contracts.rstModule();
const multicallContract = await sdk.contracts.multicallContract();
const k2NativeDelegationRSTIncentivesInstance = await sdk.contracts.k2NativeDelegationRSTIncentives();
const nodeOperatorInclusionListInstance = await sdk.contracts.nodeOperatorInclusionList();
const partitionedLinearInterestRateModelInstance = await sdk.contracts.partitionedLinearInterestRateModel();
const fundSplitterFactory = await sdk.contracts.fundSplitterFactory();
const fundSplitter = await sdk.contracts.fundSplitter(fundSplitterAddress);
const pnoRegistry = await sdk.contracts.pnoRegistry();
const lien = await sdk.contracts.lien();

All the contract instances can be directly accessed without any input parameter.

k2Lending sub-class

The following readme describes all the functions and their parameters exposed by the k2Lending class of the K2 SDK. This class exposes all the important functions from the K2 Lending protocol.

getDebtor function

This function allows anyone to get the debtor related information just by the debtor address.

Input Parameters

debtor: ETH address of the debtor

Using getDebtor function

await sdk.k2Lending.getDebtor(debtor);

Return Parameter

Returns data of a particular debtor.

getBorrowDuration function

Get the borrow duration set by the contract.

Using getBorrowDuration function

await sdk.k2Lending.getBorrowDuration();

Return Parameter

Borrow duration in BigInt.

getDAOAddress function

Get the DAO address associated with the contract.

Using getDAOAddress function

await sdk.k2Lending.getDAOAddress();

Return Parameter

ETH address of the DAO.

getProposerRegistry function

Get the proposer registry ETH address.

Using getProposerRegistry function

await sdk.k2Lending.getProposerRegistry();

Return Parameter

ETH address of the proposer registry.

getNodeOperatorInclusionList function

Get the contract that manages the node operators eligible for native delegation.

Using getNodeOperatorInclusionList function

await sdk.k2Lending.getNodeOperatorInclusionList();

Return Parameter

ETH address of the contract that manages the node operators eligible for native delegation.

deposit function

Deposits KETH into the pool and mints pool shares to the sender.

Input Parameters

amount: amount of kETH to be deposited

Using deposit function

await sdk.k2Lending.deposit(amount);

Return Parameter

Transaction details if the transaction was successful.

depositFor function

Deposit kETH for another ETH address.

Input Parameters

amount: amount of kETH to be deposited
recipient: ETH address to deposit kETH for

Using depositFor function

await sdk.k2Lending.depositFor(amount, recipient);

Return Parameter

Transaction details if the transaction was successful.

withdraw function

Burns shares from the sender and returns the equivalent fraction of remaining KETH liquidity. Optionally, sends all KETH accrued by the lender.

Input Parameters

amount: amount of kETH to be withdrawn
claim: true for claiming accrued kETH

Using withdraw function

await sdk.k2Lending.withdraw(amount, claim);

Return Parameter

Transaction details if the transaction was successful.

claimKETHForLender function

Claims all of the accrued KETH for the lender and sends it to the lender's address.

Input Parameters

lender: ETH address of the lender

Using claimKETHForLender function

await sdk.k2Lending.claimKETHForLender(lender);

Return Parameter

Transaction details if the transaction was successful.

nodeOperatorDeposit function

Deposit node operator in K2 lending protocol.

Input Parameters

blsPublicKey: BLS public key of the validator
payoutRecipient: ETH address of the recipient that would receive payout
blsSignature: BLS Signature associated with the BLS public key
ecdsaSignature: ECDSA signature

Using nodeOperatorDeposit function

await sdk.k2Lending.nodeOperatorDeposit(blsPublicKey, payoutRecipient, blsSignature, ecdsaSignature);

Return Parameter

Transaction details if the transaction was successful.

nodeOperatorWithdraw function

Withdraw node operator from the K2 Lending protocol.

Input Parameters

recipientOverride: The recipient address nodeOperatorAddress: ETH address of the node operator
blsPublicKey: BLS public key string

Using nodeOperatorWithdraw function

await sdk.k2Lending.nodeOperatorWithdraw(recipientOverride, nodeOperatorAddress, blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

nodeOperatorKick function

Kick node operator from the K2 Lending protocol.

Input Parameters

reporterAddress: ETH address of the reporter
blsPublicKey: BLS public key

Using nodeOperatorKick function

await sdk.k2Lending.nodeOperatorKick(reporterAddress, blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

nodeOperatorClaim function

Claim ETH earned for all the BLS public keys associated with a node operator.

Input Parameters

recipientOverride: The recipient address blsPublicKeys: List of BLS public keys to claim for

Using nodeOperatorClaim function

await sdk.k2Lending.nodeOperatorClaim(recipientOverride, blsPublicKeys);

Return Parameter

Transaction details if the transaction was successful.

slash function

Slash KETH from the pool. This function can only be called by a reporter.

Input Parameters

slashType: the slash type (liveness & corruption) debtor: the debtor address amount: the slash amount recipient: the recipient address

Using slash function

await sdk.k2Lending.slash(slashType, debtor, amount, recipient);

Return Parameter

Transaction details if the transaction was successful.

terminate function

Terminate debt position

Input Parameters

debtor: ETH address of the debtor

Using terminate function

await sdk.k2Lending.terminate(debtor);

Return Parameter

Transaction details if the transaction was successful.

liquidate function

Liquidate debt position.

Input Parameters

debtor: ETH address of the debtor

Using liquidate function

await sdk.k2Lending.liquidate(debtor);

Return Parameter

Transaction details if the transaction was successful.

topUpSlashAmount function

Top up kETH if it gets slashed.

Input Parameters

debtor: address of debtor in string format
amount: amount of kETH to topup

Using topUpSlashAmount function

await sdk.k2Lending.topUpSlashAmount(debtor, amount);

Return Parameter

Transaction details if the transaction was successful.

borrow function

Borrows KETH from the pool and records the debt to the debtor's address

Input Parameters

debtPositionType: debt position type
designatedVerifier: The designated verifier of debtor
amount: The debt principal to borrow
maxSlashableAmountPerLiveness: Maximum slashable amount per liveness
maxSlashableAmountPerCorruption: Maximum slashable amount per corruption
rstConfigParams: RST config params of type RSTConfigParamsT

Using borrow function

await sdk.k2Lending.borrow(debtPositionType, designatedVerifier, amount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption, rstConfigParams);

Return Parameter

Transaction details if the transaction was successful.

increaseDebt function

Increase the SBP coverage and borrow a larger amount from K2 protocol which will cancel the old SBP.

Input Parameters

debtPositionType: debt position type
designatedVerifier: The designated verifier of debtor
amount: The debt principal to borrow
maxSlashableAmountPerLiveness: Maximum slashable amount per liveness
maxSlashableAmountPerCorruption: Maximum slashable amount per corruption
resetDuration: If true, resets the duration else keeps the remaining duration of the borrow

Using increaseDebt function

await sdk.k2ending.increaseDebt(debtPositionType, designatedVerifier, amount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption, resetDuration);

Return Parameter

Transaction details if the transaction was successful.

totalSupply function

Returns the ERC-20 token supply for K2 LP.

Using totalSupply function

await sdk.k2Lending.totalSupply();

Return Parameter

Returns the total supply of the token.

getTotalBorrowableAmount function

The total amount that SBP can borrow from the K2 protocol.

Using getTotalBorrowableAmount function

await sdk.k2Lending.getTotalBorrowableAmount();

Return Parameter

Returns the total amount that SBP can borrow from the protocol.

getOutstandingInterest function

Get the outstanding interest that is left for the SBP to pay the lenders.

Input Parameters

debtor: ETH address of the debtor

Using getOutstandingInterest function

await sdk.k2Lending.getOutstandingInterest(debtor);

Return Parameters

Returns the total outstanding interest that is left for the SBP to pay the lenders.

setHookAsDebtorForSBP function

External hook contract. Set to address(0) to disable the hook

Input Parameters

hookAddress: ETH address of the hook contract. Set to address(0) by default

Using setHookAsDebtorForSBP function

await sdk.k2Lending.setHookAsDebtorForSBP(hookAddress);

Return Parameter

Transaction details if the transaction was successful.

claimableKETHForNativelyDelegatedBLSKey function

Preview claimable kETH for a BLS public key delegated by the node operator.

Input Parameters

blsPublicKey: BLS public key in string

Using claimableKETHForNativelyDelegatedBLSKey function

await sdk.k2Lending.claimableKETHForNativelyDelegatedBLSKey(blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

k2LendingDepositor sub-class

The following readme describes all the functions and their parameters exposed by the k2LendingDepositor class of the K2 SDK. This sub-class contains all the important functions from the K2 Lending depositor contract of the K2 Lending protocol.

getKethVaultAddress function

This function can be used to get the kETH vault address registered with the contract.

Using getKethVaultAddress function

await sdk.k2LendingDepositor.getKethVaultAddress();

Return parameters

ETH address of the kETH vault.

deposit function

This function can be used to deposit tokens to the contract.

Input Parameters

tokenAddress: Token address to deposit into the contract
amount: Amount of tokens to be deposited

Using deposit function

await sdk.k2LendingDepositor.deposit(tokenAddress, amount);

Return parameters

Transaction hash if the deposit was successful.

reporterRegistry sub-class

The following readme describes all the functions and their parameters exposed by the reporterRegistry class of the K2 SDK. This sub-class of the SDK exposes all the functions from the reporter registry contract of the K2 Lending protocol.

getk2LendingPool function

This function can be used to get the contract address of the K2 Lending pool.

Using getk2LendingPool function

await sdk.reporterRegistry.getk2LendingPool();

Return Parameter

Returns contract address.

isReporterActive function

Check the contracts if the reporter is active.

Input Parameters

reporter: ETH Address of the reporter

Using isReporterActive function

await sdk.reporterRegistry.isReporterActive(reporter);

Return Parameter

Boolean, true if active, false otherwise.

isReporterRagequitted function

Check the contracts if the reporter has rage quitted or not.

Input Parameters

reporter: ETH address of the reporter

Using isReporterRagequitted function

await sdk.reporterRegistry.isReporterRagequitted(reporter);

Return Parameter

Boolean, true if rage quitted, false otherwise.

isReportUsed function

Check if the reporter has been already used or not.

Input Parameters

reporter: ETH address of the reporter

Using isReportUsed function

await sdk.reporterRegistry.isReportUsed(reporter);

Return Parameter

Boolean, true if already used, false otherwise.

registerReporter function

Register a reporter to the reporter registry contract. The msg.sender will be registered as the reporter.

Using registerReporter function

await sdk.reporterRegistry.registerReporter();

Return Parameter

Transaction details if the transaction is successful.

isReporterOperational function

Check if the reporter is operational and can perform reports. An operational reporter is the one that is active and hasn't rage quitted.

Input Parameters

reporter: ETH address of the reporter

Using isReporterOperational function

await sdk.reporterRegistry.isReporterOperational(reporter);

Return Parameter

Boolean, true if reporter is operational, false otherwise.

batchSubmitReports function

Function to submit multiple verified reports in a single transaction.

Input Parameters

reports: List of verified reports of the following structure:

{
    slashType: SlashType;
    debtor: string;     // Borrower address
    amount: number;     // Amount being slashed
    identifier: number; // Unique ID to avoid double reporting
    block: number;      // Block number
    signature: string;  // Blind signature being reported
};

reportSignatures: List of signatures (designatedVerifierSignature obtained after verifying the reports) of the respective reports. Each signature follows the following structure:

{
    v: number; // version
    r: string; // x coordinate of the curve
    s: string; // y coordinate of the curve
}

Using batchSubmitReports function

await sdk.reporterRegistry.batchSubmitReports(reports, reportSignatures);

Return Parameter

Transaction details if the transaction is successful.

reportTypedHash function

Calculate typed hash of report struct.

Input Parameters

report: verified report of the following structure:

{
    slashType: SlashType;
    debtor: string;     // Borrower address
    amount: number;     // Amount being slashed
    identifier: number; // Unique ID to avoid double reporting
    block: number;      // Block number
    signature: string;  // Blind signature being reported
};

Using reportTypedHash function

await sdk.reporterRegistry.reportTypedHash(report);

Return Parameter

bytes32 hash string

isDebtorReportUsed function

Used to prevent double-reporting but scoped at a debtor level.

Input Parameters

debtorAddress: Address of the debtor in string
reportIdentifier: identifier field (in string) from the report

Using isDebtorReportUsed function

await sdk.reporterRegistry.isDebtorReportUsed(debtorAddress, reportIdentifier);

Return Parameter

Returns true if report is already used, false otherwise.

isValidReport function

Check if report is valid or not.

Input Parameters

report: Verified report obtained from the verifyReport function, of the following structure:

{
    slashType: SlashType;
    debtor: string;     // Borrower address
    amount: number;     // Amount being slashed
    identifier: number; // Unique ID to avoid double reporting
    block: number;      // Block number
    signature: string;  // Blind signature being reported
};

reportSignature: Signature (designatedVerifierSignature obtained after verifying the reports) of the respective report. The signature follows the following structure:

{
    v: number; // version
    r: string; // x coordinate of the curve
    s: string; // y coordinate of the curve
}

Using isValidReport function

await sdk.reporterRegistry.isValidReport(report, reportSignature);

Return Parameter

Returns true if valid, false otherwise.

nodeOperatorModule sub-class

The following readme describes all the functions and their parameters exposed by the nodeOperatorModule class of the K2 SDK. This sub-class contains all the important functions from the K2 Node Operator Module contract of the K2 Lending protocol.

getk2LendingContract function

This function can be used to get the k2 Lending contract address set in the K2 Node operator module contract.

Using getk2LendingContract function

await sdk.nodeOperatorModule.getk2LendingContract();

Return parameters

ETH address of the k2Lending contract.

getReporterRegistryContract function

This function can be used to get the reporter registry contract address set in the K2 Node operator module contract.

Using getReporterRegistryContract function

await sdk.nodeOperatorModule.getReporterRegistryContract();

Return parameters

ETH address of the Reporter registry contract.

batchNodeOperatorKick function

Report multiple BLS keys for kicking from K2 pool.

Input Parameters

blsPublicKeys: List of BLS public keys to kick
effectiveBalances: List of effective balance in string for respective BLS public keys
designatedVerifierSignatures: List of verifier signatures of the format SignatureECDSAT (defined in the K2-SDK) for the respective BLS public keys

Using batchNodeOperatorKick function

await sdk.nodeOperatorModule.batchNodeOperatorKick(blsPublicKeys, effectiveBalances, designatedVerifierSignatures);

Return parameters

Transaction details if the transaction is successful.

nodeOperatorClaim function

Batch node operator claims must come with an effective balance report.

Input Parameters

blsPublicKeys: List of BLS public keys to kick
effectiveBalances: List of effective balance in string for respective BLS public keys
designatedVerifierSignatures: List of verifier signatures of the format SignatureECDSAT (defined in the K2-SDK) for the respective BLS public keys

Using nodeOperatorClaim function

await sdk.nodeOperatorModule.nodeOperatorClaim(blsPublicKeys, effectiveBalances, designatedVerifierSignatures);

Return parameters

Transaction details if the transaction is successful.

isValidEffectiveBalanceReport function

Check whether a kick due to effective balance is valid

Input Parameters

blsPublicKey: BLS public key to kick
effectiveBalance: Effective balance in string for the respective BLS public key
designatedVerifierSignature: Verifier signature of the format SignatureECDSAT (defined in the K2-SDK) for the respective BLS public key

Using isValidEffectiveBalanceReport function

await sdk.nodeOperatorModule.isValidEffectiveBalanceReport(blsPublicKey, effectiveBalance, designatedVerifierSignature);

Return parameters

true if report is valid, false otherwise.

isNewBLSKeyPermitted function

Check whether a BLS public key si permitted or not.

Input Parameters

blsPublicKey: BLS public key

Using isNewBLSKeyPermitted function

await sdk.nodeOperatorModule.isNewBLSKeyPermitted(blsPublicKey);

Return parameters

true if BLS public key is valid, false otherwise.

rst sub-class

The following readme describes all the necessary functions and their parameters exposed by the rst class of the K2 SDK.

getDeployer function

Get address of the RST module factory that deployed the RST.

Input Parameters

rstAddress: Address of RST contract in string

Using getDeployer function

await sdk.rst.getDeployer(rstAddress);

Return Parameter

Returns address of RST deployer

getSBPIndex function

Reference to the unique SBP index in the K2 lending contract where activity can be checked.

Input Parameters

rstAddress: Address of RST contract in string

Using getSBPIndex function

await sdk.rst.getSBPIndex(rstAddress);

Return Parameter

Returns uint256 SBP index in Big Numbers

updateSBPIndex function

For new SBPs created, the deployer uses this method so that the RST points to the new SBP index.

Input Parameters

rstAddress: Address of RST contract in string
newSBPIndex: new SBP index in string

Using updateSBPIndex function

await sdk.rst.updateSBPIndex(rstAddress, newSBPIndex);

Return Parameter

Transaction hash

isActive function

Check if the RST token is active or not.

Input Parameters

rstAddress: Address of RST contract in string

Using isActive function

await sdk.rst.isActive(rstAddress);

Return Parameter

Boolean. true if active, false otherwise.

rstModule sub-class

The following readme describes all the necessary functions and their parameters exposed by the rstModule class of the K2 SDK.

getK2LendingContract function

Get address of the K2 lending contract.

Using getK2LendingContract function

await sdk.rstModule.getK2LendingContract();

Return Parameter

Returns address of K2 Lending contract

getImplementationContract function

Address of the implementation contract that will be cloned (minimal proxy standard).

Using getImplementationContract function

await sdk.rstModule.getImplementationContract();

Return Parameter

Returns address of implementation contract

isRST function

Check if a contract is RST or not.

Input Parameters

contractAddress: Address of contract

Using isRST function

await sdk.rstModule.isRST(contractAddress);

Return Parameter

Returns true if valid RST contract, false otherwise.

sbpToRST function

Get the RST token associated with an SBP(Slashable borrow position) index.

Input Parameters

sbpIndex: SBP index in string

Using sbpToRST function

await sdk.rstModule.sbpToRST(sbpIndex);

Return Parameter

Returns RST token address.

sbpOwnerToRST function

RST address deployed by the debtor (SBP owner).

Input Parameters

debtorAddress: Address of debtor

Using sbpOwnerToRST function

await sdk.rstModule.sbpOwnerToRST(debtorAddress);

Return Parameter

Returns RST token address.

sbpLabel function

Get the label configured by the SBP owner for their SBP index.

Input Parameters

sbpIndex: SBP index in string

Using sbpLabel function

await sdk.rstModule.sbpLabel(sbpIndex);

Return Parameter

Returns SBP label in string.

deployRST function

Deploy RST. RST can only be deployed at the time of creating the SBP.

Input Parameters

debtorAddress: Address of debtor in string
recipientAddress: Address of the account (in string) that will receive 90% of the tokens minted
dao: DAO address in string that will hold back 10% to ensure that it maintains incentives for native delegation
k2Incentives: Address in string
percentageContributionToIncentives: string
amount: Total supply that will be minted where the upper bound is the SBP principle in string
symbol: The RST token symbol used when deploying the ERC20 cloneable token in string

Using deployRST function

await sdk.rstModule.deployRST(debtorAddress, recipientAddress, dao, k2Incentives, percentageContributionToIncentives, amount, symbol);

Return Parameter

Address of RST deployed.

updateRSTLabel function

Updated label of SBP index.

Input Parameters

sbpIndex: SBP index in string
label: new SBP label in string

Using updateRSTLabel function

await sdk.rstModule.updateRSTLabel(sbpIndex, label);

Return Parameter

Transaction hash.

k2NativeDelegationRSTIncentives sub-class

The following readme describes all the functions and their parameters exposed by the k2NativeDelegationRSTIncentives class of the K2 SDK. This sub-class contains all the important functions from the K2 Native Delegation RST Incentives contract of the K2 Lending protocol.

poolLength function

Get the length of the pool.

Using poolLength function

await sdk.k2NativeDelegationRSTIncentives.poolLength();

Return Parameter

Returns the length of the pool.

poolIdByRewardToken function

Get pool ID by the reward token.

Input Parameters

rewardToken: The RST reward token address.

Using poolIdByRewardToken function

await sdk.k2NativeDelegationRSTIncentives.poolIdByRewardToken(rewardToken);

Return Parameter

Return the pool ID for the RST reward token.

getRewardFromLastBlock function

Get the rewards from the last given block.

Input Parameters

poolId: The pool ID for the RST token lastBlock: The last block number

Using getRewardFromLastBlock function

await sdk.k2NativeDelegationRSTIncentives.getRewardFromLastBlock(poolId, lastBlock);

Return Parameter

Returns the rewards received from the last given block.

pendingRewards function

Get the pending rewards of a user.

Input Parameters

poolId: The pool ID for the RST token user: The user's ETH Address

Using pendingRewards function

await sdk.k2NativeDelegationRSTIncentives.pendingRewards(poolId, user);

Return Parameter

Returns the pending rewards of the user.

massUpdatePools function

Update all the pools.

Using massUpdatePools function

await sdk.k2NativeDelegationRSTIncentives.massUpdatePools();

Return Parameter

Transaction details if the transaction was successful.

updatePool function

Update pool for the given pool ID.

Input Parameters

poolId: The pool ID for the pool to be updated.

Using updatePool function

await sdk.k2NativeDelegationRSTIncentives.updatePool(poolId);

Return Parameter

Transaction details if the transaction was successful.

nativeDelegationDeposit function

Farming deposit with native delegation.

Input Parameters

poolId: The pool ID

Using nativeDelegationDeposit function

await sdk.k2NativeDelegationRSTIncentives.nativeDelegationDeposit(poolId);

Return Parameter

Transaction details if the transaction was successful.

deposit function

K2 LP farming deposit function.

Input Parameters

poolId: The pool ID to be withdrawn from amount: The withdraw amount

Using deposit function

await sdk.k2NativeDelegationRSTIncentives.deposit(poolId, amount);

Return Parameter

Transaction details if the transaction was successful.

nativeDelegationWithdraw function

Withdraw all the native delegation from a pool.

Input Parameters

poolId: The pool ID for the pool to be updated.

Using nativeDelegationWithdraw function

await sdk.k2NativeDelegationRSTIncentives.nativeDelegationWithdraw(poolId);

Return Parameter

Transaction details if the transaction was successful.

withdraw function

Withdraw the K2 LP tokens.

Input Parameters

poolId: The pool ID to be withdrawn from amount: The withdraw amount

Using withdraw function

await sdk.k2NativeDelegationRSTIncentives.withdraw(poolId, amount);

Return Parameter

Transaction details if the transaction was successful.

claim function

Claim the pending BSN tokens.

Input Parameters

poolId: The pool ID to claim from

Using claim function

await sdk.k2NativeDelegationRSTIncentives.claim(poolId);

Return Parameter

Transaction details if the transaction was successful.

forceWithdraw function

Force withdraw K2 LP without rewards.

Input Parameters

poolId: The pool ID to withdraw from

Using forceWithdraw function

await sdk.k2NativeDelegationRSTIncentives.forceWithdraw(poolId);

Return Parameter

Transaction details if the transaction was successful.

forceWithdrawNativeDelegation function

Force withdraw K2 LP without rewards for native delegation farmers.

Input Parameters

poolId: The pool ID to withdraw from

Using forceWithdrawNativeDelegation function

await sdk.k2NativeDelegationRSTIncentives.forceWithdrawNativeDelegation(poolId);

Return Parameter

Transaction details if the transaction was successful.

nodeOperatorInclusionList sub-class

The following readme describes all the functions and their parameters exposed by the nodeOperatorInclusionList class of the K2 SDK. This sub-class contains all the important functions from the K2 Node Operator Inclusion List contract of the K2 Lending protocol.

isNewBLSKeyPermitted function

Compare the current counter with the global counter to see if the given bls key is permitted.

Input Parameters

blsPublicKey: BLS public key of the validator

Using isNewBLSKeyPermitted function

await sdk.nodeOperatorInclusionList.isNewBLSKeyPermitted(blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

onBLSKeyRegisteredToK2 function

Notify the inclusion list that a key was added so it can increase its global counter.

Input Parameters

blsPublicKey: BLS public key of the validator

Using onBLSKeyRegisteredToK2 function

await sdk.nodeOperatorInclusionList.onBLSKeyRegisteredToK2(blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

onBLSKeyUnregisteredToK2 function

Notify the inclusion list that a key was removed so it can decrease its global counter.

Input Parameters

blsPublicKey: BLS public key of the validator

Using onBLSKeyUnregisteredToK2 function

await sdk.nodeOperatorInclusionList.onBLSKeyUnregisteredToK2(blsPublicKey);

Return Parameter

Transaction details if the transaction was successful.

partitionedLinearInterestRateModel sub-class

The following readme describes all the functions and their parameters exposed by the partitionedLinearInterestRateModel class of the K2 SDK. This sub-class contains all the important functions from the K2 Partitioned Linear Interest Rate Model contract of the K2 Lending protocol.

getUtilizationRatio function

Get the max utilisation percentage of the pool at 100% utilisation.

Input Parameters

assumedLiquidity: Total liquidity in the pool, including available and borrowed funds borrowedLiquidity: Liquidity borrowed from the pool borrowAmount: Borrow amount

Using getUtilizationRatio function

await sdk.partitionedLinearInterestRateModel.getUtilizationRatio(assumedLiquidity, borrowedLiquidity, borrowAmount);

Return Parameters

Returns the max utilization percentage.

maxSlashableAmountPerLivenessUpper function

Upper bound for the ETH slashing amount that can take place for a given liveness event.

Input Parameters

assumedLiquidity: Total liquidity in the pool, including available and borrowed funds borrowedLiquidity: Liquidity borrowed from the pool borrowAmount: Borrow amount

Using maxSlashableAmountPerLivenessUpper function

await sdk.partitionedLinearInterestRateModel.maxSlashableAmountPerLivenessUpper(assumedLiquidity, borrowedLiquidity, borrowAmount);

Return Parameters

Returns the max ETH slashing amount possible for a given liveness event.

maxSlashableAmountPerCorruptionUpper function

Upper bound for the ETH slashing amount that can take place for a given corruption event.

Input Parameters

assumedLiquidity: Total liquidity in the pool, including available and borrowed funds borrowedLiquidity: Liquidity borrowed from the pool borrowAmount: Borrow amount

Using maxSlashableAmountPerCorruptionUpper function

await sdk.partitionedLinearInterestRateModel.maxSlashableAmountPerCorruptionUpper(assumedLiquidity, borrowedLiquidity, borrowAmount);

Return Parameters

Returns the max ETH slashing amount possible for a given corruption event.

getInterestRate function

Get the current interest rate based on assumed (total) and available liquidity.

Input Parameters

assumedLiquidity: Total liquidity in the pool, including available and borrowed funds borrowedLiquidity: Liquidity borrowed from the pool borrowAmount: Borrow amount maxSlashableAmountPerLiveness: Maximum slashable amount per liveness maxSlashableAmountPerCorruption: Maximum slashable amount per corruption

Using getInterestRate function

await sdk.partitionedLinearInterestRateModel.getInterestRate(assumedLiquidity, borrowedLiquidity, borrowAmount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption);

Return Parameters

Returns the current interest rate in RAY format.

getMaxBorrowableAmount function

Get the expected max borrow amount for SBP using interest.

Input Parameters

interestAmount: The interest amount currentBorrowAmount: Curent debt principal maxSlashableAmountPerLiveness: Maximum slashable amount per liveness maxSlashableAmountPerCorruption: Maximum slashable amount per corruption duration: Borrow duration

Using getMaxBorrowableAmount function

await sdk.partitionedLinearInterestRateModel.getMaxBorrowableAmount(interestAmount, currentBorrowAmount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption, duration);

Return Parameters

Returns the expected max borrow amount using interest.

getExpectedInterest function

Get the expected interest accrued over a duration, assuming interest rate doesn't change after the initial borrow.

Input Parameters

newBorrowAmount: The debt principal to compute interest for currentBorrowAmount: Curent debt principal maxSlashableAmountPerLiveness: Maximum slashable amount per liveness maxSlashableAmountPerCorruption: Maximum slashable amount per corruption duration: Borrow duration

Using getExpectedInterest function

await sdk.partitionedLinearInterestRateModel.getExpectedInterest(newBorrowAmount, currentBorrowAmount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption, duration);

Return Parameters

Returns the expected interest accrued over a duration.

pno sub-class

The following readme describes all the functions and their parameters exposed by the pno class of the K2 SDK. This sub-class contains all the important functions from the PNO registry and Lien contracts of the K2 Lending protocol.

onDelegatedRecipientSet function

Handle the case where delegated recipient is being adjusted to make sure no redelegations remain when lien is in force.

Input Parameters

currentRecipient: Address of the current recipient

Using onDelegatedRecipientSet function

await sdk.pno.onDelegatedRecipientSet(currentRecipient);

Return Parameters

Transaction details if the transaction was successful.

onSBPUpdated function

Poke the PNO registry to allow it to check whether kNetwork is mapped to current SBP.

Input Parameters

debtor: ETH address of the debtor

Using onSBPUpdated function

await sdk.pno.onSBPUpdated(debtor);

Return Parameters

Transaction details if the transaction was successful.

createKNetwork function

SBP owner can call this function to spin up their own kNetwork which will take care of deploying a fund splitter.

Input Parameters

defaultRewardToken: Address of the default reward token

Using createKNetwork function

await sdk.pno.createKNetwork(defaultRewardToken);

Return Parameters

Transaction details if the transaction was successful.

banNodeOperator function

Allows the lien contract to ban a node operator in the event that a PNO has severely violated protocol rules.

Input Parameters

sbpIndexId: SBP index in string
pno: Address of the PNO

Using banNodeOperator function

await sdk.pno.banNodeOperator(sbpIndexId, pno);

Return Parameters

Transaction details if the transaction was successful.

managePNO function

Allows the DAO to manage the global PNO inclusion list.

Input Parameters

pno: Address of the PNO
enabled: Boolean value, true if enabled

Using managePNO function

await sdk.pno.managePNO(pno, enabled);

Return Parameters

Transaction details if the transaction was successful.

removePNO function

Allow a SBP owner to use a PNO from the global inclusion list in their kNetwork.

Input Parameters

pno: Address of the PNO

Using removePNO function

await sdk.pno.removePNO(pno);

Return Parameters

Transaction details if the transaction was successful.

togglePNOGatekeepingForKNetwork function

Allow a kNetwork to enable PNO gatekeeping for their network before and after network creation.

Using togglePNOGatekeepingForKNetwork function

await sdk.pno.togglePNOGatekeepingForKNetwork();

Return Parameters

Transaction details if the transaction was successful.

manageKNetworkInclusionList function

Allow a kNetwork that has gatekeeping enabled to manage inclusion list for the opt in to work.

Input Parameters

PNOs: Array of all PNO addresses enabled: Boolean value, true if enabled

Using manageKNetworkInclusionList function

await sdk.pno.manageKNetworkInclusionList(PNOs, enabled);

Return Parameters

Transaction details if the transaction was successful.

optIntoKNetwork function

Lets the PNO to opt into node running for a kNetwork.

Input Parameters

sbpIndexId: SBP index in string

Using optIntoKNetwork function

await sdk.pno.optIntoKNetwork(sbpIndexId);

Return Parameters

Transaction details if the transaction was successful.

optOutOfKNetwork function

Lets the PNO to opt out of node running for a kNetwork.

Input Parameters

sbpIndexId: SBP index in string

Using optOutOfKNetwork function

await sdk.pno.optOutOfKNetwork(sbpIndexId);

Return Parameters

Transaction details if the transaction was successful.

setPNOFeeRecipient function

Allow PNO to set their fee recipient across all kNetwork payout processing fund splitter contracts.

Input Parameters

feeRecipient: Address of the fee recipient

Using setPNOFeeRecipient function

await sdk.pno.setPNOFeeRecipient(feeRecipient);

Return Parameters

Transaction details if the transaction was successful.

reDelegateToPreferredNodeOperator function

Re-delegate K2 re-staked balance to a PNO using K2 LP balance.

Input Parameters

pno: Address of the PNO
amount: Restaked balance to be re-delegated

Using reDelegateToPreferredNodeOperator function

await sdk.pno.reDelegateToPreferredNodeOperator(pno, amount);

Return Parameters

Transaction details if the transaction was successful.

removeRedelegation function

Remove the re-delegation given to a PNO by a K2 LP balance and obtain K2 LP back.

Input Parameters

pno: Address of the PNO
amount: Re-delegated amount to be obtained back

Using removeRedelegation function

await sdk.pno.removeRedelegation(pno, amount);

Return Parameters

Transaction details if the transaction was successful.

reDelegateToPreferredNodeOperatorFromNativeDelegation function

Re-delegate K2 re-staked balance to a PNO using K2 native delegation balance.

Input Parameters

pno: Address of the PNO
amountToRedelegateInETH: Amount to be re-delegated in ETH

Using reDelegateToPreferredNodeOperatorFromNativeDelegation function

await sdk.pno.reDelegateToPreferredNodeOperatorFromNativeDelegation(pno, amountToRedelegateInETH);

Return Parameters

Transaction details if the transaction was successful.

removeRedelegationFromNativeDelegation function

Remove re-delegation from a PNO that was given from a native delegation K2 balance.

Input Parameters

pno: Address of the PNO
amountToRedelegateInETH: Re-delegated amount to be obtained back

Using removeRedelegationFromNativeDelegation function

await sdk.pno.removeRedelegationFromNativeDelegation(pno, amountToRedelegateInETH);

Return Parameters

Transaction details if the transaction was successful.

totalReDelegationsInETHToPNO function

Query function to get total re-delegations to PNO in ETH.

Input Parameters

user: ETH address of the user
pno: Address of the PNO

Using totalReDelegationsInETHToPNO function

await sdk.pno.totalReDelegationsInETHToPNO(user, pno);

Return Parameters

Returns the total re-delegated amount in bigint.

totalReDelegationsInETHToPNOForTimestamp function

Query function to get total re-delegations to PNO in ETH for the given timestamp.

Input Parameters

user: ETH address of the user
pno: Address of the PNO
timestamp: The timestamp value in string

Using totalReDelegationsInETHToPNOForTimestamp function

await sdk.pno.totalReDelegationsInETHToPNOForTimestamp(user, pno, timestamp);

Return Parameters

Returns the total re-delegated amount in bigint.

isPreferredNodeOperator function

To check if the PNO is eligible to receive liquid re-delegations.

Input Parameters

pno: Address of the PNO

Using isPreferredNodeOperator function

await sdk.pno.isPreferredNodeOperator(pno);

Return Parameters

Returns true if the PNO is eligible, else false.

onWithdraw function

Check if re-delegations have been first removed when trying to burn K2 LP.

Input Parameters

user: ETH address of the user amount: Withdraw amount in string

Using onWithdraw function

await sdk.pno.onWithdraw(user, amount);

Return Parameters

Transaction details if the transaction was successful.

onNodeOperatorWithdraw function

Check the active re-delegations before allowing the node operator to remove their native delegation.

Input Parameters

user: ETH address of the user.

Using onNodeOperatorWithdraw function

await sdk.pno.onNodeOperatorWithdraw(user);

Return Parameters

Transaction details if the transaction was successful.

configureDesignatedVerifierAsKNetwork function

Allow a kNetwork to specify the public key of their PNO designated verifier for slashing.

Input Parameters

designatedVerifier: Address of the PNO designated verifier

Using configureDesignatedVerifierAsKNetwork function

await sdk.pno.configureDesignatedVerifierAsKNetwork(designatedVerifier);

Return Parameters

Transaction details if the transaction was successful.

slashPNO function

Slash the given PNO.

Input Parameters

kNetwork: Address of the kNetwork
reportIdentifier: Nonce for the report
pno: Address of the PNO
amount: The slash amount in string
designatedVerifierSignature: List of verifier signatures of the format SignatureECDSAT (defined in the K2-SDK) for the respective BLS public keys
deadline: Deadline for the validity of the signatures

Using slashPNO function

await sdk.pno.slashPNO(kNetwork, reportIdentifier, pno, amount, designatedVerifierSignature, deadline);

Return Parameters

Transaction details if the transaction was successful.

onSBPUpdatedLien function

Poke the Lien to allow it to check whether kNetwork is mapped to current SBP.

Input Parameters

debtor: ETH address of the debtor

Using onSBPUpdatedLien function

await sdk.pno.onSBPUpdatedLien(debtor);

Return Parameters

Transaction details if the transaction was successful.

isValidReport function

Check if the given report is valid.

Input Parameters

kNetwork: Address of the kNetwork
reportIdentifier: Nonce for the report
pno: Address of the PNO
amount: The slash amount in string
designatedVerifierSignature: List of verifier signatures of the format SignatureECDSAT (defined in the K2-SDK) for the respective BLS public keys
deadline: Deadline for the validity of the signatures

Using isValidReport function

await sdk.pno.isValidReport(kNetwork, reportIdentifier, pno, amount, designatedVerifierSignature, deadline);

Return Parameters

Return true if the report is valid, else false.

reportTypedHash function

Get the typed hash of the given report.

Input Parameters

kNetwork: Address of the kNetwork
reportIdentifier: Nonce for the report
pno: Address of the PNO
amount: The slash amount in string
deadline: Deadline for the validity of the signatures

Using reportTypedHash function

await sdk.pno.reportTypedHash(currentRecipient);

Return Parameters

Returns the 32-byte hash of the report.

fundSplitterFactory sub-class

The following readme describes all the functions and their parameters exposed by the fundSplitterFactory class of the K2 SDK. This sub-class contains all the important functions from the Fund Splitter factory contract of the K2 Lending protocol.

remapFundSplitterIfRequired function

SBP owner will call this function to remap the fund splitter if required.

Using remapFundSplitterIfRequired function

await sdk.fundSplitterFactory.remapFundSplitterIfRequired();

Return Parameters

Transaction hash if the deposit was successful.

deployFundSplitter function

SBP owner will call this function to deploy a fund splitter instance.

Input Parameters

debtor: ETH address of the debtor
defaultRewardToken: Address of the reward token for the fund splitter instance

Using deployFundSplitter function

await sdk.fundSplitterFactory.deployFundSplitter(debtor, defaultRewardToken);

Return Parameters

Returns the address of the deployed fund splitter instance.

fundSplitter sub-class

The following readme describes all the functions and their parameters exposed by the fundSplitter class of the K2 SDK. This sub-class contains all the important functions from the Fund Splitter contract of the K2 Lending protocol.

updateSBPIndex function

Update the SBP index.

Input Parameters

sbpIndex: The SBP index in string

Using updateSBPIndex function

await sdk.fundSplitter.updateSBPIndex(sbpIndex);

Return Parameters

Transaction details if the transaction was successful.

distributeNewRewards function

Distribute the new rewards to the PNOs and redelegators.

Input Parameters

rewardToken: The address of the reward token
rewardAmount: The reward amount in string
PNOs: Array of ETH addresses of the PNOs

Using distributeNewRewards function

await sdk.fundSplitter.distributeNewRewards(rewardToken, rewardAmount, PNOs);

Return Parameters

Transaction details if the transaction was successful.

claimFromRedelegationBucket function

Claim rewards from the redelegation bucket after it has been distributed.

Input Parameters

user: The ETH address of the user
distributionIndex: The distribution index in string
PNOs: Array of ETH addresses of the PNOs

Using claimFromRedelegationBucket function

await sdk.fundSplitter.claimFromRedelegationBucket(user, distributionIndex, PNOs);

Return Parameters

Transaction details if the transaction was successful.

claimFromPNOBucket function

Claim PNO earnings from the PNO bucket after it has been distributed.

Input Parameters

pno: The ETH address of the PNO
rewardTokens: Array of reward token addresses

Using claimFromPNOBucket function

await sdk.fundSplitter.claimFromPNOBucket(pno, rewardTokens);

Return Parameters

Transaction details if the transaction was successful.

onPNOEnabled function

Hook function to track PNOs enabled status.

Input Parameters

pno: The ETH address of the PNO
enabled: Boolean value, true if enabled

Using onPNOEnabled function

await sdk.fundSplitter.onPNOEnabled(pno, enabled);

Return Parameters

Transaction details if the transaction was successful.

pnoHistoricalEarnings function

Get the historical earnings for the given PNO, for the default reward token.

Input Parameters

pno: The ETH address of the PNO

Using pnoHistoricalEarnings function

await sdk.fundSplitter.pnoHistoricalEarnings(pno);

Return Parameters

Returns the historical PNO earnings in bigint.

pnoHistoricalEarningsForRewardToken functions

Get the historical earnings for the given PNO and the given reward token.

Input Parameters

pno: The ETH address of the PNO
rewardToken: Address of the reward token

Using pnoHistoricalEarningsForRewardToken function

await sdk.fundSplitter.pnoHistoricalEarningsForRewardToken(pno, rewardToken);

Return Parameters

Returns the historical PNO earnings in bigint.

isPNOEnabledAt function

Checks if the PNO was enabled at the given snapshot.

Input Parameters

pno: The ETH address of the PNO
snapshotId: The snapshot id in string

Using isPNOEnabledAt function

await sdk.fundSplitter.isPNOEnabledAt(pno, snapshotId);

Return Parameters

Return true if the PNO was enabled, else false.

Readme

Keywords

none

Package Sidebar

Install

npm i @blockswaplab/k2-sdk

Weekly Downloads

15

Version

2.0.6

License

none

Unpacked Size

453 kB

Total Files

60

Last publish

Collaborators

  • blockswapnpm