SDK for polkadot & slot auction staking
npm install @ankr.com/stakefi-polkadotStakeFi Polkadot & Slot Auction Staking
=======================================
This SDK can be used for polkadot and slot auction staking on StakeFi platform.
To install dependency, run next command:
``bash`
yarn add @ankr.com/stakefi-polkadot
Since this library depends on Web3, it has ankr.com/stakefi-web3 package inside.
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.
`typescript`
// 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.
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 polkadotgetClaimableStakingRewards
address, of course)
- - 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)
Once its required to do connect for lending or staking you need to do connect.
`typescript`
// 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)
To lend KSM/DOT tokens to project just use next snippet (don't forget to specify crowloan to
participate).
`typescriptThere is no availabe ongoing crowdloans
const stakingAmount = prompt('Enter staking amount: ');
// find crowdloan u're interested of
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_ONGOING');
if (!crowdloan) throw new Error();${stakingAmount}
// choose one of available polkadot accounts
const [polkadotAccount] = await sdk.getPolkadotAccounts();
// lend funds to crowdloan
await sdk.depositFundsToCrowdloan(polkadotAccount, crowdloan.loanId, new BigNumber());`
After crowdloan launch you're allowed to claim aDOTp tokens for some project.
`typescriptThere is no availabe succeed crowdloans
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_SUCCEED');
if (!crowdloan) throw new Error();`
// 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);
After some period (at least 1 block) of staking aDOTp you can claim your staking rewards.
`typescriptThere is no availabe succeed crowdloans
const [crowdloan] = sdk.getAvailableCrowdloans('LOAN_STATUS_SUCCEED');
if (!crowdloan) throw new Error();ERC20 claim method is not available
// determine available claim methods (optional), it can be ERC20 or PARACHAIN
const claimMethods = await sdk.getClaimMethodsForStakingRewards();
if (!claimMethods.includes('ERC20')) throw new Error();``
// find some polkadot account
const [polkadotAddress] = await sdk.getPolkadotAccounts();
await sdk.claimStakingRewards(polkadotAddress, crowdloan, 'ERC20');