Search code examples
blockchainsolana

Finding all obligations in spl-token-lending program


If an Obligation becomes unhealthy, it can be liquidated by calling LiquidateObligation instruction, however, I cannot liquidate it if I don't know it exists, and the process of finding them is still unclear to me.

What is the expected way for me to find all currently "working" Obligations?


Solution

  • The only way to get all of the Obligation accounts is to use the getProgramAccounts RPC endpoint with a filter, which fetches every account owned by the lending program that has a certain size. Since an Obligation has a size of 916 according to the code: https://github.com/solana-labs/solana-program-library/blob/9123a80a6a5b5f8a378a56c4501f99df7debda55/token-lending/program/src/state/obligation.rs#L329, you can do:

    curl YOUR_RPC_ENDPOINT_HERE -X POST -H "Content-Type: application/json" -d '
      {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "getProgramAccounts",
        "params": [
          "LENDING_PROGRAM_PUBKEY_IN_BASE_58",
          {
            "filters": [
              {
                "dataSize": 916
              }
            ]
          }
        ]
      }
    '
    

    This was adapated from https://docs.solana.com/developing/clients/jsonrpc-api#example-35