5.15.1 • Published 5 months ago

@kamino-finance/klend-sdk v5.15.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Installation

# npm
npm install @kamino-finance/klend-sdk

# yarn
yarn add @kamino-finance/klend-sdk

Kamino Lending Typescript SDK

This is the Kamino Lending Typescript SDK to interact with the Kamino Lend smart contract

Basic usage

Reading data

// There are three levels of data you can request (and cache) about the lending market.
// 1. Initalize market with parameters and metadata
const market = await KaminoMarket.load(
  connection,
  new PublicKey("7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF") // main market address. Defaults to 'Main' market
);
console.log(market.reserves.map((reserve) => reserve.config.loanToValueRatio));

// 2. Refresh reserves
await market.loadReserves();

const usdcReserve = market.getReserve("USDC");
console.log(usdcReserve?.stats.totalDepositsWads.toString());


// Refresh all cached data
market.refreshAll();

const obligation = market.getObligationByWallet("WALLET_PK");
console.log(obligation.stats.borrowLimit);

Perform lending action

const kaminoAction = await KaminoAction.buildDepositTxns(
  kaminoMarket,
  amountBase,
  symbol,
  new VanillaObligation(PROGRAM_ID),
);

const env = await initEnv('mainnet-beta');
await sendTransactionFromAction(env, sendTransaction); // sendTransaction from wallet adapter or custom

Getting a vanilla obligation for a user

  const kaminoMarket = await KaminoMarket.load(env.provider.connection, marketAddress, DEFAULT_RECENT_SLOT_DURATION_MS, programId);

  const obligation = await kaminoMarket!.getUserVanillaObligation(user);

  // to check the reserve is used in the obligation
  const isReservePartOfObligation = kaminoMarket!.isReserveInObligation(obligation, reserve);

Getting a list of user obligations for a specific reserve

  const kaminoMarket = await KaminoMarket.load(env.provider.connection, marketAddress, DEFAULT_RECENT_SLOT_DURATION_MS, programId);

  const obligations = await kaminoMarket!.getAllUserObligationsForReserve(user, reserve);

Getting a list of user obligations for a specific reserve with caching

  1. Fetch all user obligations, this should be cached as it takes longer to fetch
  const kaminoMarket = await KaminoMarket.load(env.provider.connection, marketAddress, DEFAULT_RECENT_SLOT_DURATION_MS, programId); 

  const allUserObligations = await kaminoMarket!.getAllUserObligations(user);
  allUserObligations.forEach(obligation  => {
    if (obligation !== null) {
      for (const deposits of obligation.deposits.keys()) {
        if (deposits.equals(reserve)) {
          finalObligations.push(obligation);
        }
      }
      for (const borrows of obligation.borrows.keys()) {
        if (borrows.equals(reserve)) {
          finalObligations.push(obligation);
        }
      }
    }
  });

CLI

Depositing

yarn cli deposit --url <RPC> --owner ./keypair.json --token USDH --amount 10
yarn cli deposit --url <RPC> --owner ./keypair.json --token SOL --amount 10

Printing all lending markets

The following will print all lending markets' raw account data JSONs:

yarn cli print-all-lending-market-accounts --rpc <RPC>

The output is a stream of consecutive JSON documents, which makes it appropriate for further processing using jq. Use yarn's -s option to skip the yarn version metadata from garbling the JSON output - e.g. the following will print the autodeleverage enabled flag of every market, one per line:

yarn -s cli print-all-lending-market-accounts --rpc <RPC> | jq '.autodeleverageEnabled'

Printing all reserves

The following will print all reserves' raw account data JSONs:

yarn cli print-all-reserve-accounts --rpc <RPC>

The output is a stream of consecutive JSON documents, which makes it appropriate for further processing using jq. Use yarn's -s option to skip the yarn version metadata from garbling the JSON output - e.g. the following will print the last update slot of every reserve, one per line:

yarn -s cli print-all-reserve-accounts --rpc <RPC> | jq '.lastUpdate.slot'

Printing all obligations

The following will print all obligations' raw account data JSONs:

yarn cli print-all-obligation-accounts --rpc <RPC>

The output is a stream of consecutive JSON documents, which makes it appropriate for further processing using jq, with the following gotchas:

  • use yarn's -s option to skip the yarn version metadata from garbling the JSON output,
  • use jq's --stream mode to avoid buffering the entire output.

With this in mind, the following will print the last update slot of every obligation, one per line:

yarn -s cli print-all-obligation-accounts --rpc <RPC> | jq -cn --stream 'fromstream(1|truncate_stream(inputs)) | .lastUpdate.slot'

Codegen

  • Copy the new idl from the kamino-lending program to src/idl.json
  • yarn codegen
5.15.0

6 months ago

5.10.35-beta.1

9 months ago

5.10.35-beta.0

9 months ago

5.8.0

12 months ago

5.10.24-beta.0

10 months ago

5.12.5-beta.0

8 months ago

5.12.5-beta.1

8 months ago

5.10.22-beta.0

10 months ago

5.10.18

10 months ago

5.10.17

10 months ago

5.10.19

10 months ago

5.10.14

10 months ago

5.10.13

10 months ago

5.10.16

10 months ago

5.10.15

10 months ago

5.10.10

10 months ago

5.10.12

10 months ago

5.10.11

10 months ago

5.14.1-beta.0

6 months ago

5.10.29

9 months ago

5.10.28

9 months ago

5.10.25

10 months ago

5.10.24

10 months ago

5.10.27

10 months ago

5.10.26

10 months ago

5.10.21

10 months ago

5.10.20

10 months ago

5.10.23

10 months ago

5.10.22

10 months ago

5.9.0

12 months ago

5.10.25-beta.0

10 months ago

5.10.25-beta.1

10 months ago

5.10.32

9 months ago

5.10.31

9 months ago

5.10.34

9 months ago

5.10.33

9 months ago

5.10.30

9 months ago

5.10.9

10 months ago

5.11.12-beta.0

8 months ago

5.10.8

10 months ago

5.10.7

10 months ago

5.10.6

11 months ago

5.11.18

8 months ago

5.11.15

8 months ago

5.11.14

8 months ago

5.11.17

8 months ago

5.11.16

8 months ago

5.11.11

8 months ago

5.11.10

8 months ago

5.11.13

8 months ago

5.11.12

8 months ago

5.10.5

11 months ago

5.10.4

11 months ago

5.10.3

11 months ago

5.10.2

11 months ago

5.10.1

11 months ago

5.10.0

12 months ago

5.11.2-beta.0

9 months ago

5.11.0-beta.0

10 months ago

5.11.9

8 months ago

5.11.8

8 months ago

5.11.7

8 months ago

5.11.6

8 months ago

5.11.5

9 months ago

5.3.0

1 year ago

5.10.23-beta.0

10 months ago

5.11.4

9 months ago

5.11.3

9 months ago

5.11.2

9 months ago

5.11.1

9 months ago

5.11.0

9 months ago

5.11.3-beta.1

9 months ago

5.11.3-beta.0

9 months ago

5.11.6-beta.0

9 months ago

5.12.8

8 months ago

5.12.7

8 months ago

5.12.6

8 months ago

5.12.5

8 months ago

5.12.4

8 months ago

5.4.3

12 months ago

5.4.2

12 months ago

5.4.1

12 months ago

5.4.0

1 year ago

5.12.7-beta.0

8 months ago

5.12.3

8 months ago

5.12.2

8 months ago

5.12.1

8 months ago

5.12.0

8 months ago

5.14.0-beta.0

7 months ago

5.13.9

7 months ago

5.13.8

7 months ago

5.13.7

7 months ago

5.13.6

7 months ago

5.13.5

7 months ago

5.13.4

8 months ago

5.13.16

6 months ago

5.13.17

6 months ago

5.13.18

6 months ago

5.13.19

6 months ago

5.13.12

7 months ago

5.13.13

7 months ago

5.10.28-beta.1

10 months ago

5.10.26-beta.1

10 months ago

5.13.14

7 months ago

5.10.26-beta.0

10 months ago

5.13.15

7 months ago

5.13.10

7 months ago

5.10.28-beta.0

10 months ago

5.13.11

7 months ago

5.5.1

12 months ago

5.5.0

12 months ago

5.13.2

8 months ago

5.13.1

8 months ago

5.13.0

8 months ago

5.13.18-beta.0

6 months ago

5.2.14

1 year ago

5.13.23

6 months ago

5.2.13

1 year ago

5.13.24

6 months ago

5.2.12

1 year ago

5.13.21-beta.0

6 months ago

5.2.11

1 year ago

5.2.10

1 year ago

5.13.20

6 months ago

5.13.21

6 months ago

5.13.22

6 months ago

5.11.5-beta.0

9 months ago

5.2.9-fix

1 year ago

5.14.5

6 months ago

5.14.4

6 months ago

5.14.3

6 months ago

5.14.2

6 months ago

5.6.0

12 months ago

5.14.1

6 months ago

5.14.0

6 months ago

5.15.1

5 months ago

5.7.0

12 months ago

5.2.9

1 year ago

5.2.8

1 year ago

5.2.7

1 year ago

5.2.6

1 year ago

5.2.5

1 year ago

5.2.4

1 year ago

5.2.3

1 year ago

5.2.2

1 year ago

5.2.1

1 year ago

5.2.0

1 year ago

5.1.11

1 year ago

5.1.10

1 year ago

5.1.5

1 year ago

5.1.9

1 year ago

5.1.8

1 year ago

5.1.7

1 year ago

5.1.6

1 year ago

5.1.4

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.7

1 year ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

5.0.2-fix

1 year ago

4.1.0

1 year ago

3.2.24

1 year ago

3.2.23

1 year ago

3.2.26

1 year ago

3.2.25

1 year ago

3.2.20

1 year ago

3.2.22

1 year ago

3.2.21

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.2.17

1 year ago

3.2.16

1 year ago

3.2.19

1 year ago

3.2.18

1 year ago

2.12.0-SNAPSHOT

1 year ago

2.13.10

1 year ago

2.11.0

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.0.1

1 year ago

3.2.6

1 year ago

3.2.5

1 year ago

3.2.4

1 year ago

2.13.8

1 year ago

3.2.3

1 year ago

2.13.9

1 year ago

2.13.6

1 year ago

2.13.7

1 year ago

2.13.4

1 year ago

2.13.5

1 year ago

3.0.0

1 year ago

2.13.2

1 year ago

2.13.3

1 year ago

2.13.0

1 year ago

2.13.1

1 year ago

2.12.2-kv-beta

1 year ago

2.12.0

1 year ago

2.10.14

2 years ago

2.10.15

1 year ago

2.10.16

1 year ago

3.2.9

1 year ago

2.10.17

1 year ago

3.2.8

1 year ago

2.10.18

1 year ago

3.2.7

1 year ago

2.10.19

1 year ago

3.2.13

1 year ago

3.2.12

1 year ago

3.2.15

1 year ago

3.2.14

1 year ago

3.1.0

1 year ago

3.2.11

1 year ago

2.12.1

1 year ago

3.2.10

1 year ago

2.12.2

1 year ago

2.10.20

1 year ago

2.10.21

1 year ago

2.13.6-kv-beta

1 year ago

2.10.12

2 years ago

2.10.13

2 years ago

2.10.11

2 years ago

2.10.10

2 years ago

2.10.9

2 years ago

2.10.8

2 years ago

2.10.7

2 years ago

2.10.6

2 years ago