Amulet SDK provides functionalities for other Dapp to integrate with Amulet protocol.
Github
SDK Library
Amulet SDK can be installed from npm package manager
npm install @amulet.org/sdk
It currently supports the following functions:
Get premium
Buy Cover
Stake and underwrite SOL token
Unstake AUWT token and receive a ticket
Withdraw AMTSOL token with ticket
The full sample code for buying cover using JS code can be found here
Prerequisites
Before using the SDK, you are required to register an API key with Amulet protocol. The API key is required by the SDK to call the getPremium API from our endpoint. The API key can be requested by submitting the form here.
After receiving your API key, add it on Amulet class apiSecret key parameter, as shown below
This function allows SOL token to be staked on Amulet protocol with earning yield from staking and underwriting pool. AUWT token is minted and transferred to user token account as the representative token.
Below is a step-by-step illustration of the JS code:
import { clusterApiUrl, Connection, Keypair } from'@solana/web3.js';import { Amulet, Mode, BN } from'@amulet/sdk';importtype { StakeSolForAuwtParam } from'@amulet/sdk';constamulet=newAmulet({ mode:Mode.Devnet, connection:newConnection(clusterApiUrl('devnet')), apiSecret:process.env.REACT_APP_API_SECRET});constkeypair=Keypair.generate(); // Replace this with the user wallet address constparam:StakeSolForAuwtParam= { staker:keypair.publicKey, stakeAmount:newBN(1e9),};// Stake SOL token and get AUWT tokenconst { transaction } =awaitamulet.stakeSolForAuwt(param);console.log(transaction.signature); // 5wzdPU5zd57o1hJvtg9U4a8xciFazPn8MD5WqyUhGN5AdrrceM1rU9CtaastW7g5e6AbsbLxLHnDpRP8gPNnNKnQ
Unstake AUWT token and receive a ticket
This function allows user to swap AUWT token for amtSOL token without paying unstaking fee by waiting. A ticket receipt account will be created recording the amount to be withdrawn and waiting period. The ticket can only be used to withdraw amtSOL after the stated waiting period.
Below is a step-by-step illustration of the JS code:
import { clusterApiUrl, Connection, Keypair } from'@solana/web3.js';import { Amulet, Mode, BN } from'@amulet/sdk';importtype { RedeemAuwtDelayedParam } from'@amulet/sdk';constamulet=newAmulet({ mode:Mode.Devnet, connection:newConnection(clusterApiUrl('devnet')), apiSecret:process.env.REACT_APP_API_SECRET});constkeypair=Keypair.generate(); // Replace this with the user wallet address constparam:RedeemAuwtDelayedParam= { staker:keypair.publicKey, redeemAmount:newBN(1e9),};// Unstake AUWT token for AMTSOL token with receiving a ticketconst { transaction,ticketAccount } =awaitamulet.redeemAuwtForAmtsolDelayed(param);console.log(transaction.signature);// 5wzdPU5zd57o1hJvtg9U4a8xciFazPn8MD5WqyUhGN5AdrrceM1rU9CtaastW7g5e6AbsbLxLHnDpRP8gPNnNKnQconsole.log(ticketAccount);// DkVm7cLFRYMe98dhQY334PUXQG3ZBEHPs4ph9iiGogcm
Withdraw amtSOL token with a ticket.
This function allows user to withdraw amtSOL with the ticket receipt generated from the AUWT token unstaking function.
Below is a step-by-step illustration of the JS code:
import { clusterApiUrl, Connection, Keypair, PublicKey } from'@solana/web3.js';import { Amulet, Mode } from'@amulet/sdk';importtype { WithdrawTicketAccountParam } from'@amulet/sdk';constamulet=newAmulet({ mode:Mode.Devnet, connection:newConnection(clusterApiUrl('devnet')), apiSecret:process.env.REACT_APP_API_SECRET});constkeypair=Keypair.generate(); // Replace this with the user wallet address // Replace this with the ticket account address from AUWT unstaking eventconstticketAccount=newPublicKey("DkVm7cLFRYMe98dhQY334PUXQG3ZBEHPs4ph9iiGogcm") constparam:WithdrawTicketAccountParam= { staker:keypair.publicKey, ticketAccount: ticketAccount,};// Withdraw AMTSOL token with the ticketconst { transaction } =awaitamulet.withdrawAmtsolTicketAccount(param);console.log(transaction.signature);// 5wzdPU5zd57o1hJvtg9U4a8xciFazPn8MD5WqyUhGN5AdrrceM1rU9CtaastW7g5e6AbsbLxLHnDpRP8gPNnNKnQ