npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@allianceblock/lmaas-sdk

v2.2.3

Published

## ⚙️ Install dependencies

Downloads

222

Readme

DeFi Terminal SDK

Getting started

Installing

You can either use npm or yarn to install the package:

$ npm i @allianceblock/lmaas-sdk

or

$ yarn add @allianceblock/lmaas-sdk

Creating a new instance

To create a new instance of the SDK, you'll need to provide a ConfigWrapper object that downloads the off chain config of the tenant's campaign's you want to interact with.

Each client of the DeFi Terminal has a tenant ID (if you are not sure what your tenant ID is, usually the project's name, always in lowercase. It can be found in their DeFi Terminal's URL (for example https://allianceblock.defiterm.io - here we know it's "allianceblock"). The SDK is meant to be integrated per project, so you'll have to provide the Tenant ID on initialization. We use the "allianceblock" tenant ID for demonstration purposes as it contains a sufficient amount of campaigns to interact with.

You can assume that the API endpoint will always remain the same over time; there is only a difference between development, staging, and production environments, where this endpoint is the production environment.

When you have the ConfigWrapper set up, you need to call its loadConfig method to actually call the API to get the data.

Ultimately, to get an instance of the SDK, you create a new StakerSDK object and pass on the Web3 provider (for example injected by MetaMask), the chainId (1 for ethereum) and the ConfigWrapper's configuration data that can be accessed through the config.config property.

const configWrapper = new ConfigWrapper('https://api.defiterm.io', 'allianceblock');
await newConfigWrapper.loadConfig();

const sdk = new StakerSDK(provider, chainId, configWrapper.config.config);

:factory: CICD information

CICD is done into the GitHub Actions scripts.
Access to packages into other repositories of this organization (see list here) is done through GITHUB_TOKEN with additionnal authorizations into the packages settings (use "Add Repository" in "Manage Actions access").

Usage

Retrieving campaigns

When retrieving a list of campaigns, you'll need to reuse the ConfigWrapper instance. This is because campaign data is stored off chain and needs to be obtained first before it can be interacted with on chain (through the instance of StakerSDK).

Liquidity Mining campaigns

// get all Liquidity Mining campaigns
const lmCampaigns = configWrapper.getLmCampaigns(stakerSdk.getProtocolByChainId(chainId));

// or a subset of Liquidity Mining campaigns through an optional filter
// here we only show campaigns from the v2.0 campaign contracts
const lmCampaignsFiltered = configWrapper.getLmCampaigns(
  stakerSdk.getProtocolByChainId(chainId),
  item => item.campaign.version === '2.0',
);

// get data that can be used typically inside of a component
// through the getCardData method
// the signer (wallet/account) per campaign needs to be set per campaign
const lmCampaignDataPrep = lmCampaigns.map(campaign =>
  sdk.campaignWrapper.getCardDataCommon(signer, campaign),
);

// resolve promises from all campaigns
const lmCampaignData = await Promise.all(lmCampaignDataPrep);

Staking campaigns

// the code for retrieving staking campaigns is the same
// just use another method to call from the configWrapper:
const stakingCampaigns = configWrapper.getStakingCampaigns(stakerSdk.getProtocolByChainId(chainId));

interacting with the campaigns

Approving tokens

// liquidity mining
const tx = await sdk.dexWrapper.approveToken(
  signer,
  campaign.campaign.campaignAddress,
  campaign.campaign.liquidityPoolAddress,
);

// staking
const tx = await sdk.soloStakerWrapper.approveToken(signer, campaign);

Stake

// liquidity mining
const tx = await sdk.campaignWrapper.stake(
  signer,
  campaign,
  amountTokens, // the token's decimals will be taken care of by the SDK, but this needs to be a string!
);

// staking
const tx = await sdk.soloStakerWrapper.stake(signer, campaign, amountTokens);

Useful properties of a campaign

campaign.campaign.campaignAddress; // the smart contract address of a campaign
campaign.totalStaked; // total staked in the campaign
campaign.apy.toFixed(2); // current APY of the campaign
campaign.userStakedAmount; // how much the connected wallet staked in this campaign
campaign.campaign.version; // the smart contract version of the campaign (either 1.0 or 2.0)

Note: this README will be expanded continiously to contain more information on how to use the SDK properly

Need any support or have any questions? Join our Discord at our #development channel!