Unagii Docs
  • Introduction
  • Unagii Vaults
    • Overview
    • Understanding Vaults
    • Strategies
    • Architecture
    • Smart Contracts
    • Security
    • F.A.Q
    • Vault Integration
  • Unagii Stake
    • Overview
    • Ethereum
      • Kyber
      • Skale
    • Tendermint
      • Band
      • Cosmos
      • Kava
      • Persistence
      • Terra
      • Agoric
      • Akash
      • Archway
      • Shentu
      • Kujira
      • Osmosis
      • Passage
      • Quicksilver
      • Celestia
      • dYdX
    • Others
      • Sui
      • Solana
    • Security
    • F.A.Q
    • Stake Integration
      • Kyber
      • Skale
      • Tendermint Ecosystem
      • Sui
      • Solana
    • Page
  • DeFi
    • What is DeFi?
    • What are the risks in DeFi?
    • What are Stablecoins?
      • How to earn yield on Stablecoins?
        • What are Lending Pools?
        • What are Liquidity Pools?
  • Unagii Account
Powered by GitBook
On this page
  • Get Chain Total Staked and Staked Ratio
  • Get SOL Balances
  • Get Delegations
  • Build Stake Transaction
  • Build Deactivate Transaction
  • Build Withdraw Transaction

Was this helpful?

  1. Unagii Stake
  2. Stake Integration

Solana

If you require assistance or need additional information to integrate Unagii Stake, reach out to us at support@unagii.com.

Get Chain Total Staked and Staked Ratio

GET https://app.unagii.com/api/v1/noneth/sui/total_staked

Response
{
  "success": true,
  "error_code": 0,
  "result": {
    "totalStaked": "376976660.102478139",
    "stakedRatio": "0.81094003086521619911",
    "swuStaked": "61262.62476851",
    "commission": 0.05
  }
}

Get SOL Balances

const  web3 = require('@solana/web3.js');
const connection = new web3.Connection(SOLANA_ENDPOINT
);
const nativeBalance = await connection.getBalance(
  new web3.PublicKey(WALLET_ADDRESS)
);
const result = {
  balance: nativeBalance / web3.LAMPORTS_PER_SOL,
};

Get Delegations

const connection = new web3.Connection(SOLANA_ENDPOINT);
const res = await connection.getParsedProgramAccounts(web3.StakeProgram.programId, {
  commitment: 'confirmed',
  filters: [
    {
      memcmp: {
        offset: 44,
        bytes: WALLET_ADDRESS,
      },
    },
  ],
});

Build Stake Transaction

const connection = new web3.Connection(SOLANA_ENDPOINT);
const fromPubkey = new web3.PublicKey(WALLET_ADDRESS);
const votePubkey = new web3.PublicKey(VALIDATOR_ADDRESS);
const newStakeAccount = web3.Keypair.generate();
const stakePubkey = newStakeAccount.publicKey;
const transaction = new web3.Transaction().add(
  web3.StakeProgram.createAccount({
    fromPubkey,
    stakePubkey,
    authorized: new web3.Authorized(fromPubkey, fromPubkey),
    lamports: payload.amount * web3.LAMPORTS_PER_SOL,
    lockup: new web3.Lockup(0, 0, fromPubkey),
  }),
  web3.StakeProgram.delegate({
    stakePubkey,
    authorizedPubkey: fromPubkey,
    votePubkey: votePubkey,
  })
);
transaction.feePayer = fromPubkey;
transaction.recentBlockhash = (
  await connection.getLatestBlockhash()
).blockhash;
transaction.sign(newStakeAccount);

Build Deactivate Transaction

const connection = new web3.Connection(SOLANA_ENDPOINT);
const fromPubkey = new web3.PublicKey(WALLET_ADDRESS);
const stakePubkey = new web3.PublicKey(STAKER_ACCOUNT);
const transaction = new web3.Transaction().add(
  web3.StakeProgram.deactivate({
    stakePubkey,
    authorizedPubkey: fromPubkey,
  })
);
transaction.feePayer = fromPubkey;
transaction.recentBlockhash = (
  await connection.getLatestBlockhash()
).blockhash;

Build Withdraw Transaction

const connection = new web3.Connection(SOLANA_ENDPOINT);
const fromPubkey = new web3.PublicKey(WALLET_ADDRESS);
const stakePubkey = new web3.PublicKey(STAKER_ACCOUNT);
const transaction = new web3.Transaction().add(
  web3.StakeProgram.withdraw({
    stakePubkey,
    authorizedPubkey: fromPubkey,
    toPubkey: fromPubkey,
    lamports: payload.amount * web3.LAMPORTS_PER_SOL,
  })
);
transaction.feePayer = fromPubkey;
transaction.recentBlockhash = (
  await connection.getLatestBlockhash()
).blockhash;
PreviousSuiNextPage

Last updated 9 months ago

Was this helpful?