Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
/ nolus.js Public archive
forked from nolus-protocol/nolus.js

JavaScript SDK for Nolus, written in TypeScript

License

Notifications You must be signed in to change notification settings

alexandermake/nolus.js

 
 

Repository files navigation

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(NODE_ENDPOINT);
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);

Development

See DEVELOPMENT.md.

References

Nolus.js uses CosmJS.

About

JavaScript SDK for Nolus, written in TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%