@xend-finance/web-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Logo

XendFinance SDK

Build applications on-top of the Xend Finance Smart Contract Protocols.

Authors

Installation

Using npm:

npm install @xend-finance/web-sdk

Using yarn:

yarn add @xend-finance/web-sdk

Xend Finance has different saving strategies that helps you save your money in stable currencies;

  • Personal Savings
  • Esusu
  • Cooperative Savings
  • Yield Aggregator(xAuto,xVault)

You can make use of one or all of these strategies

Setup Video

Follow this youtube link for an example of how you can setup this SDK for local development.

Scenario

You can use Xend Finance in as many scenario's you can come up with, but there are 2 examples

  1. Use one general address for all your transactions
  2. Create a new address for each of your users and use for their transactions

Example Personal Flexible Deposit

import XF from '@xend-finance/web-sdk';


const makeDeposit = async () => {
  const { Personal } = await XF(chainId, privateKey, { env:"mainnet" });

  const depositAmount = "100";

  const response = await Personal.flexibleDeposit(depositAmount);

  return response;
}

Example xAuto Deposit

import XF from '@xend-finance/web-sdk';


const makeDeposit = async () => {
  const { xAuto } = await XF(chainId, privateKey, { env:"mainnet" });

  const depositAmount = "100";
  let approval = await xAuto.approve("USDC", depositAmount);

	if (approval && approval.status) {

  const response = await xAuto.deposit("USDC",depositAmount);
  }

  return response;
}

Example xAuto Deposit BNB

import XF from '@xend-finance/web-sdk';


const makeDeposit = async () => {
  const { xAuto } = await XF(chainId, privateKey, { env:"mainnet" });

  const depositAmount = "100";

  const response = await xAuto.depositNative("BNB",depositAmount);

  return response;
}

Withdraw xAuto | xVault

import XF from '@xend-finance/web-sdk';
const withdraw = async () => {
const { xAuto,xVault } = await XF(chainId, privateKey, { env:"mainnet" });

const receiptXauto = await xAuto.withdraw("USDC", totalBUSDAdmount)
const receiptXvault = await xVault.withdraw("BUSD", totalBUSDAdmount)


}

Parameters

These parameters are used to create an instance of any of the saving strategies exported from the SDK

Name Description
chainId Chain ID of the network in use. 56 represents the BSC Mainnet, 1 is for Ethererum Mainnet, 97 is for BSC Testnet
privateKey Private key of address
options Optional

Options

When any of Xend Finance strategy is initialized without options, the SDK defaults to use the addresses for the testnet.

Properties Values Description
env local, testnet, mainnet Required
protocols Array of protocols objects This can only be used when the env is local.
protocolName Used in the case of multiple protocols available

Note: whenever you use the options argument you have to provide value for the env property even if it is "testnet"

Protocol Type

This is the structure of a protocol to be used by the SDK and will be helpful when using the SDK on your local machine with an instance of tools like ganache.

{
  "name":"",
  "code":"",
  "addresses": {
    "PROTOCOL_ADAPTER": "",
    "PROTOCOL_SERVICE": "",
    "GROUPS": "",
    "CYCLES": "",
    "ESUSU_SERVICE": "",
    "ESUSU_STORAGE": "",
    "ESUSU_ADAPTER": "",
    "COOPERATIVE": "",
    "PERSONAL": "",
    "CLIENT_RECORD": "",
    "XEND_TOKEN": "",
    "TOKEN": "",
    "PROTOCOL_CURRENCY": "",
  }
}

Some Available Methods

General

Name Parameters Description
getClientAddress address of account used to initialize SDK
apys will only return values if you are on mainnet

Personal Savings

Name Parameters Description
flexibleDeposit depositAmount
fixedDeposit
fixedInfo
flexibleInfo
withdrawFixed recordId
withdrawFlexible amount
walletBalance

Esusu

Name Parameters Description
create
walletBalance

Cooperative Savings

Name Parameters Description
create
walletBalance

xAuto ,xVault

​​Name Parameters Description
deposit
withdraw

🔗 Social Media Links

gitbook linkedin twitter discord telegram

/@xend-finance/web-sdk/

    Package Sidebar

    Install

    npm i @xend-finance/web-sdk

    Weekly Downloads

    0

    Version

    0.2.2

    License

    MIT

    Unpacked Size

    3.11 MB

    Total Files

    149

    Last publish

    Collaborators

    • ncally