@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / Lender

Interface: Lender

Defined in: packages/sdk/src/lend/lender.ts:81

Write surface for the SomniaLend money market, bound to one signer — built by client.lend.createLender on the owning client.

Details

Every method resolves once the tx is MINED, with its receipt. Amounts are raw underlying-token units. ERC-20 pulls (supply / repay) auto-approve by default; the *Native variants route native SOMI through the WrappedTokenGateway so the caller never touches WSOMI.

Gotchas

Every method THROWS if the mined tx reverted (receipt.status !== "success") — a reverted lend action never resolves as success. The *Native variants need wrappedTokenGateway in the lend addresses. Borrowing is variable-rate only. Position/risk reads live on the lend client (getAccount), not here.

Properties

account

readonly account: `0x${string}`

Defined in: packages/sdk/src/lend/lender.ts:83

The signer address the lender acts as.

Methods

supply()

supply(asset, amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:98

Supply amount of asset to earn interest (and optionally back borrows). Auto-approves the Pool when the allowance is short.

Parameters

asset

`0x${string}`

Underlying ERC-20 to supply (a LendReserve.underlying).

amount

bigint

Raw underlying units.

opts?

LendSupplyOptions

Approval/gas overrides, or supply on behalf of another address.

Returns

Promise<TxResult>

Example

ts
const lender = client.lend.createLender({ privateKey });
await lender.supply(usdso, 1_000n * 10n ** 18n);

withdraw()

withdraw(asset, amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:103

Withdraw supplied asset. Pass maxUint256 as amount to withdraw the full balance including accrued interest. See Lender.supply.

Parameters

asset

`0x${string}`

amount

bigint

opts?

LendWithdrawOptions

Returns

Promise<TxResult>


borrow()

borrow(asset, amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:108

Borrow asset against the account's collateral (variable rate). Reverts on-chain if the health factor would drop below 1. See Lender.supply.

Parameters

asset

`0x${string}`

amount

bigint

opts?
gas?

bigint

Returns

Promise<TxResult>


repay()

repay(asset, amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:114

Repay variable-rate debt in asset. Pass maxUint256 as amount to clear the full debt including accrued interest (requires balance ≥ debt; the contract only pulls what is owed). See Lender.supply.

Parameters

asset

`0x${string}`

amount

bigint

opts?

LendRepayOptions

Returns

Promise<TxResult>


setUseAsCollateral()

setUseAsCollateral(asset, useAsCollateral, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:119

Toggle whether the supplied asset balance backs borrows. Disabling reverts on-chain if it would leave existing debt under-collateralized.

Parameters

asset

`0x${string}`

useAsCollateral

boolean

opts?
gas?

bigint

Returns

Promise<TxResult>


supplyNative()

supplyNative(amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:124

Supply native SOMI (wrapped to WSOMI by the gateway). Sibling of Lender.supply; needs addresses.lend.wrappedTokenGateway.

Parameters

amount

bigint

opts?
onBehalfOf?

`0x${string}`

gas?

bigint

Returns

Promise<TxResult>


withdrawNative()

withdrawNative(amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:130

Withdraw the WSOMI position as native SOMI. maxUint256 withdraws all. Auto-approves the gateway to pull the aWSOMI (an ERC-20 approve on the aToken). Sibling of Lender.withdraw.

Parameters

amount

bigint

opts?

LendWithdrawOptions & object

Returns

Promise<TxResult>


borrowNative()

borrowNative(amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:136

Borrow native SOMI (variable rate) via the gateway. First-use grants the gateway credit delegation on the WSOMI variable-debt token (approveDelegation, cached like approvals). Sibling of Lender.borrow.

Parameters

amount

bigint

opts?
approve?

boolean

gas?

bigint

Returns

Promise<TxResult>


repayNative()

repayNative(amount, opts?): Promise<TxResult>

Defined in: packages/sdk/src/lend/lender.ts:142

Repay WSOMI debt with native SOMI. maxUint256 is not supported for the native path — pass a slight overpayment instead; the gateway refunds the excess. Sibling of Lender.repay.

Parameters

amount

bigint

opts?
onBehalfOf?

`0x${string}`

gas?

bigint

Returns

Promise<TxResult>


clearApprovalCache()

clearApprovalCache(): void

Defined in: packages/sdk/src/lend/lender.ts:148

Drop the lender's in-memory approval/delegation grant cache (mirrors the trader's clearApprovalCache) — needed only if an approval was revoked out-of-band while this lender instance is alive.

Returns

void