> ## Documentation Index
> Fetch the complete documentation index at: https://docs.restaking.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

## setDelegatedRecipient function

This function can be used by the recipient of LST yield to further delegate claim rights to another recipient in exchange for something else.

### Input Parameters

recipient: ETH address of the new recipient

### Using setDelegatedRecipient function

```javascript theme={null}
await sdk.k2Lending.setDelegatedRecipient(recipient);
```

### Return Parameter

Transaction details if the transaction was successful.

## 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

```javascript theme={null}
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

```javascript theme={null}
await sdk.k2Lending.getBorrowDuration();
```

### Return Parameter

Borrow duration in BigInt.

## getDAOAddress function

Get the DAO address associated with the contract.

### Using getDAOAddress function

```javascript theme={null}
await sdk.k2Lending.getDAOAddress();
```

### Return Parameter

ETH address of the DAO.

## getProposerRegistry function

Get the proposer registry ETH address.

### Using getProposerRegistry function

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
await sdk.k2Lending.nodeOperatorDeposit(
  blsPublicKey,
  payoutRecipient,
  blsSignature,
  ecdsaSignature
);
```

### Return Parameter

Transaction details if the transaction was successful.

## batchNodeOperatorDeposit function

Batch deposit multiple node operators in K2 lending protocol.

### Input Parameters

blsPublicKeys: Array of BLS public keys of the validators\
payoutRecipients: Array of ETH addresses of the recipients that would receive payout\
blsSignatures: Array of BLS Signatures associated with the BLS public keys
ecdsaSignatures: Array of ECDSA signatures

### Using batchNodeOperatorDeposit function

```javascript theme={null}
await sdk.k2Lending.batchNodeOperatorDeposit(
  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

nodeOperatorAddress: ETH address of the node operator\
blsPublicKey: BLS public key string

### Using nodeOperatorWithdraw function

```javascript theme={null}
await sdk.k2Lending.nodeOperatorWithdraw(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

```javascript theme={null}
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

blsPublicKeys: List of BLS public keys to claim for

### Using nodeOperatorClaim function

```javascript theme={null}
await sdk.k2Lending.nodeOperatorClaim(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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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: debtor address in string format\
amount: amount of kETH to topup

### Using topUpSlashAmount function

```javascript theme={null}
await sdk.k2Lending.topUpSlashAmount(debtor, amount);
```

### Return Parameter

Transaction details if the transaction was successful.

## topUpAndTerminate function

Top up kETH if it gets slashed and terminate debt position.

### Input Parameters

amount: amount of kETH to topup

### Using topUpAndTerminate function

```javascript theme={null}
await sdk.k2Lending.topUpAndTerminate(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: config params of type RSTConfigParamsT

### Using borrow function

```javascript theme={null}
await sdk.k2Lending.borrow(
  debtPositionType,
  designatedVerifier,
  amount,
  maxSlashableAmountPerLiveness,
  maxSlashableAmountPerCorruption,
  rstConfigParams
);
```

### Return Parameter

Transaction details if the transaction was successful.

## borrowFor function

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

### Input Parameters

debtor: Address of the debtor
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: config params of type RSTConfigParamsT

### Using borrowFor function

```javascript theme={null}
await sdk.k2Lending.borrowFor(
  debtor,
  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

```javascript theme={null}
await sdk.k2ending.increaseDebt(debtPositionType, designatedVerifier, amount, maxSlashableAmountPerLiveness, maxSlashableAmountPerCorruption, resetDuration);
```

### Return Parameter

Transaction details if the transaction was successful.

## increaseDebtFor function

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

### Input Parameters

debtor: Address of the debtor
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 increaseDebtFor function

```javascript theme={null}
await sdk.k2ending.increaseDebtFor(debtor, 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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
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

```javascript theme={null}
await sdk.k2Lending.claimableKETHForNativelyDelegatedBLSKey(blsPublicKey);
```

### Return Parameter

Transaction details if the transaction was successful.

## getTotalBorrowableAmountWithMaxBorrowRatio function

Get the total borrowable max amount for the given max borrow ratio.

### Input Parameters

debtPositionType: debt position type

### Using getTotalBorrowableAmountWithMaxBorrowRatio function

```javascript theme={null}
await sdk.k2Lending.getTotalBorrowableAmountWithMaxBorrowRatio(debtPositionType);
```

### Return Parameter

Returns the total borrowable amount with max borrow ratio.

## getBorrowedLiquidity function

Get the borrowed liquidity.

### Using getTotalBorrowableAmountWithMaxBorrowRatio function

```javascript theme={null}
await sdk.k2Lending.getBorrowedLiquidity();
```

### Return Parameter

Returns the borrowed liquidity.

## claimableKETH function

Get the kETH claimable by the lender.

### Input Parameters

lender: ETH address of the lender

### Using claimableKETH function

```javascript theme={null}
await sdk.k2Lending.claimableKETH(lender);
```

### Return Parameter

Returns the claimable kETH amount.

## nodeOperatorPayoutRecipientUpdate function

This function can be called by the node operator to update the payout recipient as per ability to change it on the node.

### Input Parameters

newPayoutRecipient: ETH address of the new payout recipient

### Using nodeOperatorPayoutRecipientUpdate function

```javascript theme={null}
await sdk.k2Lending.nodeOperatorPayoutRecipientUpdate(newPayoutRecipient);
```

### Return Parameter

Transaction details if the transaction was successful.

## updateLenderPosition function

Updates the KETH amount pending to the lender, and their last recorded cumulative reward per share.

### Input Parameters

lender: ETH address of the lender

### Using updateLenderPosition function

```javascript theme={null}
await sdk.k2Lending.updateLenderPosition(lender);
```

### Return Parameter

Transaction details if the transaction was successful.

## updateNodeOperatorPosition function

Updates the KETH amount pending to the node operator, and their last recorded cumulative reward per share.

### Input Parameters

nodeOerator: ETH address of the node operator

### Using updateNodeOperatorPosition function

```javascript theme={null}
await sdk.k2Lending.updateNodeOperatorPosition(nodeOerator);
```

### Return Parameter

Transaction details if the transaction was successful.

## updateInterest function

Updates the current cumulative interest index before executing the function the function.

### Using updateInterest function

```javascript theme={null}
await sdk.k2Lending.updateInterest();
```

### Return Parameter

Transaction details if the transaction was successful.
