Skip to main content

All methods

Account Info


getBalances()

Retrieves the MATIC and stMATIC balances from the user account

Syntax:

const { matic, stMatic } = await polidoSDK.getBalances(address);

Parameters:

  • address - The address to check balances from

Return value:

type: Promise<{ matic: string, stMatic: string }>


Prices


getMaticPrice()

Retrieves the price of MATIC in USD

Syntax:

const maticPrice = await polidoSDK.getMaticPrice();

Return value: type: Promise<number>


getStMaticPrice()

Retrieves the price of stMATIC in USD

Syntax:

const stMaticPrice = await polidoSDK.getStMaticPrice();

Return value: type: Promise<number>


Staking


getStMaticFromMatic()

Returns the amount of stMATIC received by staking a certain amount of MATIC

Syntax:

const stMatic = await polidoSDK.getStMaticFromMatic('20');

Parameters:

  • amount - The amount of MATIC to convert to stMATIC

Return value:

type: Promise<string>


getMaticFromStMatic()

Returns the amount of MATIC received by un-staking a certain amount of stMATIC

Syntax:

const matic = await polidoSDK.getMaticFromStMatic('20');

Parameters:

  • amount - The amount of stMATIC to convert to MATIC

Return value:

type: Promise<string>


checkAllowance()

Checks if the address has enough unlocked tokens to be able to stake

Syntax:

const allowed = await polidoSDK.checkAllowance({ amount: string, address: string });

Parameters:

  • amount - amount in MATIC to check
  • address - address of user

Return value:

type: Promise<boolean>

value definition: If true, then the user is able to stake that amount of MATIC


unlockTokens()

Approves an amount of MATIC to be used for Staking

Syntax:

type TxStageChangeCallback = (props: {
txStage: TX_STAGE;
code: TX_STAGE_ERROR_CODE;
error?: string;
}) => void;


// With txStage
const { amount } = await polidoSDK.unlockTokens({
amount: '20',
onTxStageChange: txStageChangeCallback,
});

// Without txStage
const { amount } = await polidoSDK.unlockTokens({
amount: '20'
});

Parameters:

  • amount - amount in MATIC to approve
  • setTxStage? - Optional callback for getting information about transaction stage

Return value:

type: Promise<{ amount: string }>

value definition: The amount in MATIC that was approved for staking


stake()

First prepares stake transaction, then signs and confirm it

Syntax:

type TxStageChangeCallback = (props: {
txStage: TX_STAGE;
code: TX_STAGE_ERROR_CODE;
transactionHash?: string;
error?: string;
additionalData?: Record<string, unknown>
}) => void;


// With txStage
const { transactionHash, stAmount } = await polidoSDK.stake({
amount: '20',
referral: '0x...', // Optional address field for assigning a referrer in case there is one
onTxStageChange: txStageChangeCallback,
});

// Without txStage
const { transactionHash, stAmount } = await polidoSDK.stake({
amount: '20',
referral: '0x...', // Optional address field for assigning a referrer in case there is one
});

Parameters:

  • amount - The amount of MATIC to stake
  • referral - Optional address field for assigning a referrer in case there is one
  • setTxStage? - Optional callback for getting information about transaction stage

Return value:

type: Promise<{ transactionHash: string; stAmount: string }>


Withdrawals


requestWithdrawal()

First checks if the account has enough staked to be able to withdraw, then makes the request

Syntax:

type TxStageChangeCallback = (props: {
txStage: TX_STAGE;
code: TX_STAGE_ERROR_CODE;
transactionHash?: string;
error?: string;
additionalData?: Record<string, unknown>
}) => void;


// With txStage
const { transactionHash, amount } = await polidoSDK.requestWithdrawal({
amount: '20',
address: '0x...',
referral: '0x...', // Optional address field for assigning a referrer in case there is one
setTxStage: setTxStageCallback,
});

// Without txStage
const { transactionHash, amount } = await polidoSDK.requestWithdrawal({
amount: '20',
address: '0x...',
referral: '0x...', // Optional address field for assigning a referrer in case there is one
});

Parameters:

  • amount - The amount of stMATIC to withdraw
  • address - The user address
  • referral - Optional address field for assigning a referrer in case there is one
  • setTxStage? - Optional callback for getting information about transaction stage

Return value:

type: Promise<{ transactionHash: string; amount: string }>


fetchTokens()

Fetches the NFT tokens representing the amounts requested to claim. Has information about the un-bonding period

Syntax:

type TokenItem = {
value: string;
amount: BigNumber;
text: string;
available: boolean;
checked: boolean;
}

const { tokens, claimableAmount, pendingAmount, delay } = await polidoSDK.fetchTokens({
address: string
})

Parameters:

  • address - The user address

Return value:

type: Promise<{ tokens: TokenItem[], claimableAmount: string, pendingAmount: string, delay: number }>

value definition: tokens.value - ID of the NFT token

value definition: tokens.amount - Amount in MATIC represented by the NFT token

value definition: tokens.text - Text to display (Example: 20 - Available or 20 - in 80 epochs)

value definition: tokens.available - boolean value representing if the amount is available to claim

value definition: tokens.checked - boolean value helper for the UI

value definition: claimableAmount - Total claimable amount in MATIC

value definition: pendingAmount - Total pending amount in MATIC

value definition: delay - Total number of epochs required to un-bond


claimTokens()

Claims MATIC rewards from tokens that are ready for withdrawal (the un-bonding period has passed)

Syntax:

type TxStageChangeCallback = (props: {
txStage: TX_STAGE;
code: TX_STAGE_ERROR_CODE;
transactionHash?: string;
error?: string;
additionalData?: Record<string, unknown>
}) => void;


// With txStage
const { transactionHash } = await polidoSDK.claimTokens({
tokenIds: string[]
setTxStage: setTxStageCallback,
});

// Without txStage
const { transactionHash } = await polidoSDK.claimTokens({
tokenIds: string[]
});

Parameters:

  • tokenIds - A string[] containing the IDs of the NFT tokens to claim

Return value:

type: Promise<{ transactionHash: string }>


Lido Statistics


getStats()

Fetches stats from the Lido on Polygon API

Syntax:

type LidoPolygonStats = {
price: number;
apr: number;
stakers: number;
totalStaked: {
token: number;
usd: number;
};
totalRewards: {
token: number;
usd: number;
};
}

const stats: LidoPolygonStats = await polidoSDK.getStats();

Return value:

type: Promise<LidoPolygonStats>


Transaction State

OnTxStageChangeCallback

Callback used throughout the PolidoSDK methods that interact with a Signer

enum TX_STAGE {
IDLE = 0,
AWAITING_SIGNING = 1,
AWAITING_BLOCK = 2,
SUCCESS = 3,
ERROR = 4,
}

enum TX_STAGE_ERROR_CODE {
GENERIC_ERROR = 'GENERIC_ERROR',
FAILED_SIGNING = 'FAILED_SIGNING',
FAILED_TRANSACTION = 'FAILED_TRANSACTION',
ALREADY_APPROVED = 'ALREADY_APPROVED',
}

type TxStageChangeCallback = (props: {
txStage: TX_STAGE;
code: TX_STAGE_ERROR_CODE;
transactionHash?: string;
error?: string;
additionalData?: Record<string, unknown>
}) => void;


// Example
const { transactionHash, stAmount } = await polidoSDK.stake({
amount: '20',
onTxStageChange: ({ txStage, code, transactionHash, error, additionalData }) => {
// Called multiple times throughout the lifecycle of the transaction
},
});