> For the complete documentation index, see [llms.txt](https://docs.kpk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/balance-adapters/sparklend.md).

# SparkLend

Reports an account's per-reserve lending positions in SparkLend.

Reports an account's per-reserve lending positions in SparkLend: a supply or collateral leg (from the aToken balance) and a borrow leg per reserve. It enumerates reserves onchain from the SparkLend Protocol Data Provider.

* **Type:** Plain adapter
* **protocolSubId:** `keccak256("spark-lend")`
* **Source:** `SparkLendBalanceAdapter.sol`

## Positions returned

Up to two legs per SparkLend reserve that is registered on NAVCalculator:

| Leg        | PositionKind | isDebt  | Description                                                |
| ---------- | ------------ | ------- | ---------------------------------------------------------- |
| Supply     | `Supplied`   | `false` | aToken balance when `usageAsCollateralEnabled == false`    |
| Collateral | `Collateral` | `false` | aToken balance when `usageAsCollateralEnabled == true`     |
| Borrow     | `Borrowed`   | `true`  | Variable + legacy stable debt, summed, one leg per reserve |

Legacy stable debt can still persist on this Aave V3 fork, so the borrow leg sums `variableDebt + stableDebt`. Reserves with zero supply and zero debt are skipped.

If the account borrows a reserve whose asset is **unregistered** on NAVCalculator, the adapter reports **nothing at all** rather than collateral without its debt. The borrowed set comes from the user-configuration bitmap, falling back to a full reserve scan when it is unavailable. See [Never report collateral without its debt](https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting.md#how-an-adapter-is-built).

## Balance calculation

<figure><picture><source srcset="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FspTMEf91RskRPUbzwZ30%2Fadapter-sparklend_D.png?alt=media&amp;token=9401fd44-bcf1-4acb-aa40-185b21c08187" media="(prefers-color-scheme: dark)"><img src="https://1699303810-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUsQM4bzcmOPSgkWddkeN%2Fuploads%2FBd7lOziYyllez8lqGJXJ%2Fadapter-sparklend.png?alt=media&amp;token=3350646d-b1d1-4b44-a345-28b8f8337ac7" alt="Flowchart of the SparkLend balance adapter: read calls derive position legs into PositionBalance entries."></picture><figcaption><p>SparkLend adapter: how the underlying balances reported to the NAV Calculator are derived.</p></figcaption></figure>

Per reserve, the adapter reads `getUserReserveData(asset, account)`:

```
supply = currentATokenBalance
debt   = currentVariableDebt + currentStableDebt   // legacy stable folded in
asCollateral = usageAsCollateralEnabled
```

The supply leg is `Collateral` if `asCollateral` is true, else `Supplied`; the borrow leg has `isDebt = true`.

{% hint style="info" %}
`getAdapterBalanceForAsset` and `getAdapterBalances` return a single net `supply − debt` scalar per asset; `getAdapterPositions`, the NAV path, keeps the legs separate.
{% endhint %}

## Identity

* **positionId:** `abi.encode(address pool)`, the SparkLend Pool resolved at construction; the reserve is carried in `balanceAsset`, not the `positionId`
* **positionKind:** `Supplied` · `Collateral` · `Borrowed`

## Constructor

```solidity
constructor(address dataProvider_, address navCalculator_)
```

| Parameter        | Description                                                                                 |
| ---------------- | ------------------------------------------------------------------------------------------- |
| `dataProvider_`  | SparkLend Protocol Data Provider (must be a contract); source of reserves and per-user data |
| `navCalculator_` | NAVCalculator address (must be a contract); source of the asset registry                    |

`POOL` is derived at construction from `dataProvider_.ADDRESSES_PROVIDER().getPool()`.

## Registration

Register with `addBalanceAdapters([adapter])` (MANAGER-gated); remove with `removeBalanceAdapters`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kpk.io/funds/infrastructure/architecture/onchain-accounting/balance-adapters/sparklend.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
