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
const lmCampaigns = configWrapper.getLmCampaigns(stakerSdk.getProtocolByChainId(chainId));
const lmCampaignsFiltered = configWrapper.getLmCampaigns(
stakerSdk.getProtocolByChainId(chainId),
item => item.campaign.version === '2.0',
);
const lmCampaignDataPrep = lmCampaigns.map(campaign =>
sdk.campaignWrapper.getCardDataCommon(signer, campaign),
);
const lmCampaignData = await Promise.all(lmCampaignDataPrep);
Staking campaigns
const stakingCampaigns = configWrapper.getStakingCampaigns(stakerSdk.getProtocolByChainId(chainId));
interacting with the campaigns
Approving tokens
const tx = await sdk.dexWrapper.approveToken(
signer,
campaign.campaign.campaignAddress,
campaign.campaign.liquidityPoolAddress,
);
const tx = await sdk.soloStakerWrapper.approveToken(signer, campaign);
Stake
const tx = await sdk.campaignWrapper.stake(
signer,
campaign,
amountTokens,
);
const tx = await sdk.soloStakerWrapper.stake(signer, campaign, amountTokens);
Useful properties of a campaign
campaign.campaign.campaignAddress;
campaign.totalStaked;
campaign.apy.toFixed(2);
campaign.userStakedAmount;
campaign.campaign.version;
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!