@ankr.com/stakefi-polkadot
v0.0.150
Published
SDK for polkadot & slot auction staking
Downloads
549
Readme
StakeFi Polkadot & Slot Auction Staking
This SDK can be used for polkadot and slot auction staking on StakeFi platform.
To install dependency, run next command:
yarn add @ankr.com/stakefi-polkadot
Since this library depends on Web3, it has ankr.com/stakefi-web3
package inside.
Create SDK
Firstly you need to create SDK instance and store it somewhere in your state. Each SDK instance is assigned to chosen polakdot network, that can be Kusama or Polkadot. If its required to manage both networks at the same time then create two SDK instances.
// create new web3 key provider
const keyProvider = new Web3KeyProvider({
// required chain id for MetaMask
expectedChainId: 5,
});
// create SDK instance
const sdk = new SlotAuctionSdk({
// url to polkadot RPC (network type is strictly depends on polkadot URL)
polkadotUrl: 'wss://westend-rpc.polkadot.io',
// base url to api gateway
baseUrl: 'https://api.dev.stkr.io/',
// don't do status check
crowdloanStatusCheck: false,
});
sdk.initPolkadotProvider();
sdk.initWeb3Provider(keyProvider);
// dispatch it to state somewhere
dispatch(SDK_INIT, {sdk});
HINT: By default slot auction SDK uses always connected Web3 key provider, so its not required to connect it manually, because it asks user to connect MetaMask only when its required for application.
Basic methods
Some methods can be used without connection to polkadot.js
, here is list of such methods:
getAvailableCrowdloans
- list available crowdloansgetCrowdloanById
- get crowdloan by idrequestDepositAddress
- request deposit address for selected crowdloangetCrowdloanBalances
- get claimable and total your crowdloan balances (if you know polkadot address, of course)getClaimableStakingRewards
- get claimable staking rewards in ethereum networkgetClaimMethodsForStakingRewards
- list possible clam methods (ERC20 or PARACHAIN)claimStakingRewards
- claim staking rewards as ERC20 tokens or as PARACHAIN tokencheckCrowdloanStatus
- check crowdloan status check (it can be disabled in config for testing purposes)
Connect to PolkadotJS
Once its required to do connect for lending or staking you need to do connect.
// you can check does it connected already
if (sdk.isConnected()) {
return;
}
// connect to polkadot.js (promise is resolved once user accepted connection or expection is thrown)
await sdk.connect();
Once you're connected to polkadot.js
, next methods are available for you:
depositFundsToCrowdloan
- lend funds to specified crowdloan projectclaimRewardPoolTokens
- claim aDOTp once project is winnercreateRawTokenSignature
- ask user to create raw token signature (internal)createVerifiableTokenSignature
- ask user to create verifiable token sig (internal)
Lend KSM/DOT tokens
To lend KSM/DOT tokens to project just use next snippet (don't forget to specify crowloan to participate).
const stakingAmount = prompt('Enter staking amount: ');
// find crowdloan u're interested of
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_ONGOING');
if (!crowdloan) throw new Error(`There is no availabe ongoing crowdloans`);
// choose one of available polkadot accounts
const [polkadotAccount] = await sdk.getPolkadotAccounts();
// lend funds to crowdloan
await sdk.depositFundsToCrowdloan(polkadotAccount, crowdloan.loanId, new BigNumber(`${stakingAmount}`));
Claim aDOTp tokens
After crowdloan launch you're allowed to claim aDOTp tokens for some project.
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_SUCCEED');
if (!crowdloan) throw new Error(`There is no availabe succeed crowdloans`);
// choose one of available polkadot accounts
const [polkadotAccount] = await sdk.getPolkadotAccounts();
// lend funds to crowdloan
const metaMaskAccount = await sdk.getEthereumAccount();
await sdk.claimRewardPoolTokens(polkadotAccount, crowdloan.loanId, metaMaskAccount);
Claim aDOTp staking rewards
After some period (at least 1 block) of staking aDOTp you can claim your staking rewards.
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_SUCCEED');
if (!crowdloan) throw new Error(`There is no availabe succeed crowdloans`);
// determine available claim methods (optional), it can be ERC20 or PARACHAIN
const claimMethods = await sdk.getClaimMethodsForStakingRewards();
if (!claimMethods.includes('ERC20')) throw new Error(`ERC20 claim method is not available`);
// find some polkadot account
const [polkadotAddress] = await sdk.getPolkadotAccounts();
await sdk.claimStakingRewards(polkadotAddress, crowdloan, 'ERC20');