Polygon (POL)

SDK functions for POL staking on Ethereum protocol

Approve

Approve a contract to spend an amount of ERC-20 POL.

This function is necessary prior to stake POL through a ValidatorShare proxy contract.

Users must first allow the POL StakeManager proxy (sepolia / mainnet) contract to spend the amount that needs to be spent. If no amount is specified, an infinite amount will be approved and this transaction will no longer be required before each staking transaction. That said, this is not recommended for security reasons.

const tx = await k.pol.craftApproveTx('wallet_address', 'stake_manager_proxy_address', 1);

Buy voucher

Buy voucher is the action of exchanging POL against validator shares.

It is done by doing a buyVoucherPOL contract call to a ValidatorShare proxy contract of your desired validator.

Our validator share proxies are : mainnet / sepolia

This function also links your stake to your kiln account id.

The amount to stake is in POL.

const tx = await k.pol.craftBuyVoucherTx('account_id', 'wallet_address', 'validator_share_proxy_address', 1);

Sell voucher

Sell voucher is the action of unbonding your staked POL.

It is done by doing a sellVoucherPOL contract call to a ValidatorShare proxy contract.

Once done, your POL token enter the unbonding period of ~3/4 days (80 checkpoints).

The amount to sell is in POL.

const tx = await k.pol.craftSellVoucherTx('wallet_address', 'validator_share_proxy_address', 1);

Unstake claim tokens

Unstake claim tokens transfers your unbonded tokens to your wallet.

const tx = await k.pol.craftUnstakeClaimTokensTx('wallet_address', 'validator_share_proxy_address');

Withdraw rewards

Withdraw rewards transfers your available rewards to your wallet.

const tx = await k.pol.craftWithdrawRewardsTx('wallet_address', 'validator_share_proxy_address');

Restake rewards

Restake rewards converts your available rewards to staked POL. This is how you can take advantage of auto-compounding by automating this process.

const tx = await k.pol.craftRestakeRewardsTx('wallet_address', 'validator_share_proxy_address');

Sign and broadcast

On POL, you have two options for signing and broadcasting transactions.

Fireblocks contract call

The method is usually preferred as it does not require the Fireblocks raw signing feature and allows you to leverage Fireblocks policies.

For this method to work you will need to whitelist the contract address that you are interacting with. When staking ETH with Kiln, it is interacting with our ValidatorShareProxy contract.

Once the contract is whitelisted in Fireblocks, you should be able to retrieve the destination id associated with it (in the fireblocks URL or via their API). This id needs to be in the Integration configuration object.

Here is an example showing how to sign and broadcast a transaction with a fireblocks vault.

Checkout the setup fireblocks documentation to setup your vault.

import { Integration } from "@kilnfi/sdk/lib/types/integrations";
const fs = require('fs');
const apiSecret = fs.readFileSync(__dirname + '/fireblocks_secret.key', 'utf8');

const vault: Integration = {
      provider: 'fireblocks',
      fireblocksApiKey: 'YOUR_API_USER_KEY', // your fireblocks API user key
      fireblocksSecretKey: apiSecret, // your fireblocks private key (generated with your CSR file and your API user)
      vaultId: 7, // your fireblocks vault id
      fireblocksDestinationId: '07df91b4-7788-4833-a8f4-428facef68cc', // your fireblocks whitelisted destination id
};
const txSigned = await k.pol.signAndBroadcast(vault, tx);

With this method, the transaction is signed and broadcasted through Fireblocks.

Fireblocks raw signing

When using the Fireblocks raw signing feature, you need to make two calls to our SDK, the first to sign the transaction and the second to broadcast it via our API.

Sign a transaction by specifying the integration and the crafted transaction.

Here is an example showing how to sign a transaction with a fireblocks vault.

Checkout the setup fireblocks documentation to setup your vault.

import { Integration } from "@kilnfi/sdk/lib/types/integrations";
const fs = require('fs');
const apiSecret = fs.readFileSync(__dirname + '/fireblocks_secret.key', 'utf8');

const vault: Integration = {
      provider: 'fireblocks',
      fireblocksApiKey: 'YOUR_API_USER_KEY', // your fireblocks API user key
      fireblocksSecretKey: apiSecret, // your fireblocks private key (generated with your CSR file and your API user)
      vaultId: 7 // your fireblocks vault id
};
const txSigned = await k.pol.sign(vault, tx);

Broadcast

Broadcast a signed transaction.

const txHash = await k.pol.broadcast(txSigned);

Get transaction status

Get the transaction status of a broadcasted transaction by providing its transaction hash.

const status = await k.pol.getTxStatus('tx_hash');

Decode transaction

Decode a serialized transaction previously crafted. You can use this to get more information about a transaction prior to broadcast it such as the gas fees used, the function parameters etc.

const decodedTx = await k.pol.decodeTx('tx_serialized');

Last updated