@steerprotocol/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.12.1 • Public • Published

Steer Finance SDK

A TypeScript SDK for interacting with Steer Finance services.

Installation

npm install @steer-finance/sdk viem
# or
yarn add @steer-finance/sdk viem
# or
pnpm add @steer-finance/sdk viem

Usage

import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';
import { SteerClient } from '@steer-finance/sdk';

// Create viem client
const client = createPublicClient({
  chain: mainnet,
  transport: http()
});

// Initialize the Steer client
const steerClient = new SteerClient({
  apiKey: 'your-api-key',
  environment: 'production', // or 'development'
  client: client, // Pass your viem client
});

// Use the client
const response = await steerClient.getData<YourDataType>('endpoint');

Staking Client

The StakingClient provides functionality for interacting with Steer Finance staking pools. It supports both single and dual reward staking pools.

Features

  • Fetch available staking pools
  • Stake and withdraw tokens
  • Claim rewards
  • Check earned rewards and balances
  • Calculate APR for staking pools
  • Support for both single and dual reward pools

Example Usage

// Initialize the staking client
const stakingClient = steerClient.staking;

// Get all staking pools
const pools = await stakingClient.getStakingPools();

// Get pools for a specific chain
const polygonPools = await stakingClient.getStakingPools(137); // Polygon chain ID

// Stake tokens
await stakingClient.stake({
  stakingPool: '0x...', // staking pool address
  amount: 1000000000000000000n // amount in wei
});

// Check earned rewards
const earned = await stakingClient.earned('0x...', '0x...'); // pool address, account address
console.log('Earned rewards:', earned.data);

// Calculate APR
const apr = stakingClient.calculateAPR(
  pool,
  rewardTokenPriceUSD,
  totalStakedUSD
);

Available Methods

  • getStakingPools(chainId?: number, protocol?: string): Fetch available staking pools
  • stake(params: StakeParams): Stake tokens in a pool
  • withdraw(params: WithdrawParams): Withdraw tokens from a pool
  • getReward(params: GetRewardParams): Claim rewards
  • earned(stakingPool: Address, account: Address): Get earned rewards
  • totalSupply(stakingPool: Address): Get total staked tokens
  • balanceOf(stakingPool: Address, account: Address): Get staked balance
  • calculateAPR(pool: StakingPool, rewardTokenPriceUSD: number, totalStakedUSD: number): Calculate current pool APR

Requirements

  • Node.js >= 18.0.0
  • viem >= 2.22.0

Development

  1. Install dependencies:
npm install
  1. Build the package:
npm run build
  1. Run tests:
npm test
  1. Format code:
npm run format
  1. Lint code:
npm run lint

Troubleshooting

CommonJS/ESM Import Issues

If you encounter the following error:

import { SteerClient } from "@steerprotocol/sdk";
         ^^^^^^^^^^^
SyntaxError: Named export 'SteerClient' not found. The requested module '@steerprotocol/sdk' is a CommonJS module...

Add the following to your tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @steerprotocol/sdk

Weekly Downloads

113

Version

1.12.1

License

MIT

Unpacked Size

1.96 MB

Total Files

824

Last publish

Collaborators

  • steerguardian
  • rakeshsteer