SDK - Guide for Fixed Staking
This guide provides a detailed walkthrough of integrating FIVA's fixed staking functionality into your platform using our SDK. We'll cover the full implementation process with code examples and best practices.
Getting Started with the SDK
First, install the FIVA SDK in your project:
npm install @fiva/sdk
# or
yarn add @fiva/sdk
# or
pnpm install @fiva/sdkClient Initialization
The first step is to initialize the FIVA client with your wallet connector, TON client, and the SY address for the asset you want to work with:
import { FivaClient } from '@fiva/sdk';
import { Address, TonClient4 } from '@ton/ton';
// Initialize TON client
const tonClient = new TonClient4({
endpoint: 'https://mainnet-v4.tonhubapi.com'
});
// Initialize FIVA client for USDT-EVAA fixed staking
const fivaClient = new FivaClient({
connector, // Your wallet connector
tonClient,
syAddress: Address.parse('EQDi9blCcyT-k8iMpFMYY0t7mHVyiCB50ZsRgyUECJDuGvIl') // USDT-EVAA SY address
});You can find all supported SY addresses at:
You can also check available pools and APYs in the FIVA application: https://app.thefiva.com/fixed-yield
Implementing Core Fixed Staking Functions
Let's implement the three core functions needed for fixed staking:
1. Stake (Fixed Yield)
This function allows users to lock in current rates by swapping their asset for PT tokens:
When presenting this to users, you should frame it as "Fixed Staking" with a guaranteed return at maturity.
2. Unstake Before Maturity
This function allows users to exit their position early:
When presenting this option to users, make it clear that early unstaking will return an amount determined by current market conditions, which may differ from the initially promised fixed rate.
3. Unstake After Maturity
This function allows users to redeem their PT tokens after maturity:
This function should be presented as "Claim" or "Withdraw" after the maturity date is reached.
Understanding Minimum Amount Out and Slippage Protection
Slippage protection is a critical aspect of any on-chain transaction, and it's especially important for fixed staking operations where users expect predictable outcomes.
What is minAmountOut?
minAmountOut?In the SDK functions swapAssetForPt and swapPtForAsset, the minPtOut and minAssetOut parameters represent the minimum amount of tokens the user is willing to accept from the transaction. If the actual output would be less than this minimum (due to price movements or other factors), the transaction will revert.
Implementing Slippage Protection
There are two main approaches to implementing slippage protection:
Fixed Percentage (as shown in examples):
User-Configurable:
Importance of Slippage Protection
Without appropriate slippage protection:
Transactions may execute at unfavorable rates during periods of high volatility
Users may receive significantly less than expected, especially in pools with lower liquidity
Front-running attacks become possible in some scenarios
Important Note: If the transaction would result in receiving less than the specified minAmountOut, the entire transaction will be reverted. This protects users from unexpected outcomes and ensures they always get at least what they specified or nothing at all (allowing them to try again).
Complete Integration Example
Here's a comprehensive example that ties everything together:
Testing Your Integration
Before going live, we recommend testing your integration in our testnet environment:
Use testnet SY addresses from our repository
Test all three functions with small amounts
Verify APY calculations match expected values
Test the full lifecycle including maturity redemption
If you have questions about the integration process or need support, please contact [email protected] or join our community on Telegram.
Last updated