Nolus Docs
TypeScript SDK

Examples

Common nolus.js workflows: quote, open, query, manage, repay, close, and lend.

These snippets assume you already have a NolusClient, a nolusWallet, and contract instances as set up in Getting started. Exact method signatures live in the auto-generated API reference.

Quote a margin position

Preview the position the protocol would open, including expected borrow, fees, and resulting position size:

const quote = await leaser.leaseQuote(
  '1000',  // downpayment amount (minor units of the downpayment currency)
  'unls',  // downpayment currency ticker
  'OSMO',  // wanted position currency
);

Open a margin position

import { AssetUtils, ChainConstants } from '@nolus/nolusjs';

const fee = {
  gas: '1000000',
  amount: [
    { amount: '50000', denom: ChainConstants.COIN_MINIMAL_DENOM },
  ],
};

const currencies = await oracle.getCurrencies();
const bankSymbol = AssetUtils.findBankSymbolByTicker(
  currencies,
  downpaymentCurrencyTicker,
);

await leaser.openLease(
  borrowerWallet,
  'OSMO',     // wanted position currency
  fee,
  undefined,  // max_ltd (optional)
  [{ denom: bankSymbol, amount: '1000' }],  // downpayment
);

Read Leaser configuration

const cfg = await leaser.getLeaserConfig();

List a wallet's open positions

const addresses = await leaser.getCurrentOpenLeasesByOwner(walletAddress);
// addresses: string[]  - one Lease contract address per active position

Read a position's status

const status = await lease.getLeaseStatus();

if (status.opening) {
  // Position is still being opened (ICA + DEX swap in flight).
} else if (status.opened) {
  // Active position: debt, interest, current close policy.
  console.log(status.opened);
} else if (status.closing) {
  // Settlement in progress.
} else if (status.closed) {
  // Fully closed.
} else if (status.liquidated) {
  // Fully liquidated.
}

getLeaseStatus returns a LeaseStatus discriminated union; exactly one of the five branches will be populated. Only opened and opening carry debt/interest detail; the rest are terminal markers.

Repay (manual)

Settle outstanding interest and principal using external LPN funds:

const lpn = await lpp.getLPN();  // current LPN ticker for the pool

await lease.repayLease(borrowerWallet, fee, [
  { denom: lpnBankSymbol, amount: '100000000' },  // 100 USDC in minor units
]);

The protocol applies the repayment in order: overdue protocol interest, overdue loan interest, current-period interest, then principal.

Close (market close)

Settle the position from its own holdings without supplying external funds:

await lease.closePositionLease(borrowerWallet, fee);

Pass an Asset for the second argument to partially close:

await lease.closePositionLease(
  borrowerWallet,
  fee,
  { amount: '500000000', ticker: 'OSMO' },  // partial close
);

Set stop-loss / take-profit

await lease.changeClosePolicy(
  borrowerWallet,
  fee,
  850,  // stopLoss: LTV in permille (85%)
  600,  // takeProfit: LTV in permille (60%)
);

Pass null for either parameter to clear that side of the policy.

Deposit into the LPP (lender)

await lpp.deposit(lenderWallet, fee, [
  { denom: lpnBankSymbol, amount: '1000000000' },  // 1000 USDC in minor units
]);

The lender receives nLPN proportional to the current price.

Check lender deposit and pending rewards

const deposit = await lpp.getLenderDeposit(lenderAddress);  // nLPN balance
const rewards = await lpp.getLenderRewards(lenderAddress);  // pending uNLS

Claim NLS rewards

await lpp.claimRewards(lenderWallet, undefined, fee);

The second argument is an optional recipient address. Pass undefined to credit the caller.

Withdraw (burn nLPN)

await lpp.burnDeposit(lenderWallet, '500000000', fee);

The amount is in nLPN minor units. Burns settle at the current nLPN/LPN exchange rate; passing the full nLPN balance also auto-claims any pending NLS rewards.

Read oracle prices

const everything = await oracle.getPrices();   // all supported pairs
const osmo       = await oracle.getBasePrice('OSMO');  // single pair

More

The nolus.js repository is the canonical reference for end-to-end usage. For the complete method surface (every parameter, every response type), see the auto-generated API reference.

On this page