Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.starkfi.io/llms.txt

Use this file to discover all available pages before exploring further.

To move a user’s invested balance from one protocol to another (or to rebuild the operation on the same protocol), create a rebalance operation with the endpoint below. You must execute it through our yield broadcast endpoint — do not broadcast with sendTransaction or a third-party RPC. The user only signs; your backend submits the signed payload to StarkFi.

Building a rebalance operation

PATCH /yield/rebalance
1

Building rebalance operation

Building a rebalance operation
ParameterTypeRequiredDescription
chain_namestringNetwork where the position lives (e.g. solana).
amountstringDecimal amount to move (must be > 0, e.g. "100.00").
walletstringUser’s wallet public key.
assetstringToken symbol (e.g. USDC).
provider_outstringProtocol to withdraw from: jupiter_lend or kamino.
provider_instringProtocol to deposit into: jupiter_lend or kamino.
providerstringWhen both sides are the same protocol, send only this field (withdraw + deposit use the same provider).
Either provider_in and provider_out, or a single provider (same protocol on both legs).
2

Request example (cross-protocol)

curl --request PATCH \
  --url https://api.starkfi.io/yield/rebalance \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api_key>' \
  --data '{
    "chain_name": "solana",
    "wallet": "FmTGYpzX27fDqaiytXUdFVaphC5o68G61Q3uhVM2d8bm",
    "asset": "USDC",
    "amount": "0.01",
    "provider_out": "kamino",
    "provider_in": "jupiter_lend"
  }'
3

Expected response

The API returns the standard envelope. On success, data includes position_out_id, position_in_id, and rebalance (build result: success, message, and details).

Single merged transaction

When instructions fit in one Solana packet, details.mode is single_transaction.
{
  "statusCode": 200,
  "success": true,
  "status": "rebalance_yield_strategy_ok",
  "message": "Yield strategy rebalanced successfully",
  "data": {
    "position_out_id": "<uuid>",
    "position_in_id": "<uuid>",
    "rebalance": {
      "success": true,
      "message": "rebalance_yield_strategy_built",
      "details": {
        "mode": "single_transaction",
        "transaction": "<base64_unsigned_versioned_tx>"
      }
    }
  }
}
4

Signing rebalance transactions

Never broadcast with the wallet’s sendTransaction or an external RPC. Sign only, then submit through StarkFi’s yield broadcast API.
import { Wallet } from "ethers";

const privateKey = "SUA_PRIVATE_KEY_AQUI";
const wallet = new Wallet(privateKey);

const tx = {
  from:                 "0x9b57847b69D0354837F7b723133B9dBCbefb4F9F",
  to:                   "0x23183C87c9c6668edf5974893905AF475c3664c9",
  data:                 "0x40180def000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90000000000000000000000009b57847b69d0354837f7b723133b9dbcbefb4f9f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000009b57847b69d0354837f7b723133b9dbcbefb4f9f0000000000000000000000001e659faad0181ab1a30891d99f69df115db77eef0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000e3220000000000000000000000000000000000000000000000000000000000000706",
  value:                0n,
  chainId:              42161,
  gasLimit:             82499n,
  maxPriorityFeePerGas: 0n,
  maxFeePerGas:         52514800n,
  nonce:                36,
  type:                 2,
};

const signedTx = await wallet.signTransaction(tx);
console.log("Transação assinada:", signedTx);
You can now submit your signed transaction using our broadcast endpoint.