nolus-protocol / nolus.js

JavaScript SDK for Nolus, written in TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nolus.js


Nolus.js


JavaScript SDK for Nolus, written in TypeScript.

Modules

  • client - Nolus Client service
  • wallet - Nolus Wallet service (Coin, Chain, Wallet, etc.)
  • contracts - Interact with the Nolus Protocol
  • utils - Utils (Currency, Keys, etc.)
  • constants - Nolus network constants

Get started

Installation

yarn add @nolus/nolusjs

OR

npm install @nolus/nolusjs

Usage

client

Set up Nolus client:

NolusClient.setInstance(tendermintRpc);

wallet

Create and set up wallet:

const mnemonic = KeyUtils.generateMnemonic();
  const accountNumbers = [0];
  const path = accountNumbers.map(makeCosmoshubPath)[0];
  const privateKey = await KeyUtils.getPrivateKeyFromMnemonic(mnemonic, path);

 // Set up wallet
  const offlineSigner = await DirectSecp256k1Wallet.fromKey(
    privateKey,
    ChainConstants.BECH32_PREFIX_ACC_ADDR,
  );

const nolusWallet = await nolusOfflineSigner(offlineSigner);
nolusWallet.useAccount();

contracts

Set up instance:

NolusClient.setInstance(tendermintRpc);
const cosm = await NolusClient.getInstance().getCosmWasmClient();

    oracleInstance = new NolusContracts.Oracle(cosm, oracleContractAddress);
    leaserInstance = new NolusContracts.Leaser(cosm, leaserContractAddress);
    leaseInstance = new NolusContracts.Lease(cosm, leaseContractAddress);
    lppInstance = new NolusContracts.Lpp(cosm, lppContractAddress);
    treasuryInstance = new NolusContracts.Treasury(cosm, treasuryContractAddress);

Nolus Protocol interacting:

Lease Quote:

await leaserInstance.leaseQuote(
        '1000', // downpaymentAmount
        'unls' // downpaymentCurrencyTicker
        'OSMO' // wantedLeaseCurrency
      );

Open Lease:

// fee structure example

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

const downpaymentCurrencyToIbc = AssetUtils.makeIBCMinimalDenom('OSMO');

await leaserInstance.openLease(
        borrowerWallet,
        'OSMO' // wantedLeaseCurrency
        fee,
        [{ denom: downpaymentCurrencyToIbc, amount: '1000' }],
      );

Get Leaser contract config:

await leaserInstance.getConfig();

utils and constants

Import and use directly:

ChainConstants.COIN_TYPE;
const privateKey = await KeyUtils.getPrivateKeyFromMnemonic(mnemonic, path);

API Documentation

The auto-generated API documentation - Requires basic TypeScript understanding.

Development

See DEVELOPMENT.md.

Collaboration

Nolus.js uses CosmJS.

About

JavaScript SDK for Nolus, written in TypeScript

License:MIT License


Languages

Language:TypeScript 100.0%