Deposit and withdraw
How to deposit the pool currency into a Nolus lending pool, read the value of an nLPN pool share, and withdraw principal and interest with burn.
Lending takes two messages to a pool, deposit to put the pool currency in
and burn to take it out. Between the two, the lender's nLPN balance stays the
same while its price in the pool currency rises with the interest that
positions pay. Deposits have no lock-up, so the only limit on a withdrawal is
the pool's idle balance.
The commands on this page use two shell variables. $LPP holds the pool
address, which Find and query a pool
shows how to resolve, and $USDC_DENOM holds the bank denom of the pool currency, which
the protocol oracle's {"currencies":{}} query returns as bank_symbol. The
following commands look up that denom for the SOLANA-METIS-USDC protocol:
ADMIN=nolus1gurgpv8savnfw66lckwzn4zk7fp394lpe667dhu7aw48u40lj6jsqxf8nd
ORACLE=$(nolusd q wasm contract-state smart $ADMIN '{"protocol":"SOLANA-METIS-USDC"}' -o json \
| jq -r .data.contracts.oracle)
USDC_DENOM=$(nolusd q wasm contract-state smart $ORACLE '{"currencies":{}}' -o json \
| jq -r '.data[] | select(.ticker=="USDC") | .bank_symbol')ADMIN is the address of the platform admin contract, which returns the
protocol's oracle address, and the jq filter picks the currency whose ticker
is USDC from the oracle's answer.
Deposit
A deposit is the deposit message, which takes no arguments:
{ "deposit": [] }To deposit, execute the message on the pool with the pool currency attached as funds:
nolusd tx wasm execute $LPP '{"deposit":[]}' \
--amount 100000000$USDC_DENOM \
--from <key> --gas auto --gas-adjustment 1.3 --gas-prices 0.025unlsReplace <key> with the name or address of the signing key in your nolusd
keyring, and set --amount to the deposit in the smallest unit of the pool
currency.
When the deposit arrives, the pool reads the current nLPN price and credits
the lender with deposit / price nLPN. In an empty pool the price is 1, so
1 LPN mints 1 nLPN, and the deposited funds then become available to new
positions.
A deposit that exceeds the pool's deposit capacity is rejected, so check the
capacity first with {"deposit_capacity":[]}, which returns null when
deposits are uncapped.
Balance and value
The value of a lender's pool share comes from two pool queries, one for the nLPN balance and one for the nLPN price:
nolusd q wasm contract-state smart $LPP '{"balance":{"address":"<account>"}}' -o json
# {"data":{"amount":"99726512"}}
nolusd q wasm contract-state smart $LPP '{"price":[]}' -o json
# {"data":{"amount":{"amount":"109260066737"},"amount_quote":{"amount":"109552893059"}}}Replace <account> with the lender's Nolus account. The balance is in nLPN,
and the price is a pair of amounts, amount in nLPN and amount_quote in the
pool currency, from which the lender's value in the pool currency follows:
value = nLPN balance x amount_quote / amountIn the example the price is about 1.0027, so 99.73 nLPN is worth about 100 USDC, and the price keeps rising as positions pay loan interest into the pool.
Withdraw
A withdrawal is the burn message, which names the amount of nLPN to burn:
{ "burn": { "amount": { "amount": "50000000" } } }The amount is in nLPN, and burning the whole balance takes the lender out of
the pool entirely. The following command sends the message, with <key>
replaced by the signing key as for a deposit:
nolusd tx wasm execute $LPP '{"burn":{"amount":{"amount":"50000000"}}}' \
--from <key> --gas auto --gas-adjustment 1.3 --gas-prices 0.025unlsThe pool computes the payout as the nLPN burned times the current price, so every withdrawal, partial or full, includes the interest earned on the burned share. It then removes the nLPN from the lender's balance and sends the payout to the account. A full withdrawal also pays out any pending NLS rewards, while a partial withdrawal leaves the rest of the balance earning.
A withdrawal fails with NoLiquidity when the payout is larger than the
pool's idle funds, which happens when most of the pool is lent out. In that
case, read the idle balance from the balance field of {"lpp_balance":[]}
and withdraw a smaller amount, or wait for positions to repay.
To withdraw a given payout, burn the payout divided by the price, which is
nLPN = LPN x amount / amount_quote.
Interest is only part of what a lender earns, because the pool also shares out NLS rewards, which accrue apart from the nLPN price. NLS rewards shows how they are distributed and how to claim them.
Lending
How Nolus lending pools work, how lenders earn the fixed-rate interest Spot Margin positions pay, and how to find and query each pool on chain.
NLS rewards
How the Nolus treasury distributes NLS rewards to lending pools by total pool value, how each lender's share accrues, and how to query and claim it.