Scripts to manage DeFindex vaults on the Stellar network: emergency rescue and idle funds rebalancing.
- Node.js (v18+)
- pnpm
- Install dependencies:
pnpm install- Create a
.envfile from the example:
cp .env.example .env- Fill in the environment variables:
| Variable | Required | Description |
|---|---|---|
SIGNER_SECRET |
One of the two | Stellar secret key of the authorized account. Signs and submits the transaction automatically. |
SIGNER_PUBLIC_KEY |
One of the two | Stellar public key of the authorized account. Builds and simulates the transaction, then prints the XDR for signing with an external tool. |
VAULT_ADDRESS |
Yes | Contract address of the DeFindex vault. |
Tip — XDR export mode: If you don't have access to the private key at runtime (e.g. hardware wallet, multisig), set only
SIGNER_PUBLIC_KEY. The script will build and simulate the transaction, then save the fully-assembled XDR to a timestamped file (e.g.rescue_unsigned_2026-02-26_14-30-00.xdr). These files are gitignored. Open the file, copy the contents, and paste them into any Stellar signer (e.g. Stellar Laboratory, Albedo, Freighter, or your hardware wallet tool).
Emergency rescue of funds from a strategy back to the vault. It will protect users funds and will pause the strategy. Funds will stay as IDLE FUNDS.
pnpm rescueThe script will:
- Build an emergency rescue transaction for the specified vault and strategy
- Simulate the transaction to assemble auth entries
- If
SIGNER_SECRETis set: sign and submit the transaction - If only
SIGNER_PUBLIC_KEYis set: print the assembled XDR to stdout
The strategy address to rescue from is hardcoded in src/rescue.ts (Currently USDC_BLEND_YIELDBLOX_STRATEGY). Update it to target a different strategy.
Detects idle funds in a vault and invests them into the configured strategy.
pnpm rebalanceThe script will:
- Fetch total managed funds from the vault (via simulation)
- Identify assets with idle (uninvested) balances
- Build
Investinstructions mapping each idle asset to its configured strategy - If
SIGNER_SECRETis set: sign and submit therebalancetransaction - If only
SIGNER_PUBLIC_KEYis set: print the assembled XDR to stdout
The asset-to-strategy mapping is configured in src/rebalance.ts. By default it maps USDC to the USDC_BLEND_FIXED_STRATEGY strategy on mainnet.
To run rebalance against a testnet vault:
pnpm rebalance:testnetThis reads credentials from .env.test (instead of .env) and uses testnet RPC/network passphrase. The strategy mapping switches to XLM Blend on testnet.
The setup-test-vault script creates a fully configured test environment on Stellar testnet:
pnpm setup-test-vaultThe script will:
- Generate a new random Stellar keypair
- Fund the account via Friendbot (10,000 XLM)
- Create a vault via the DeFindex factory with XLM + Blend strategy
- Deposit 100 XLM as idle funds (not invested)
- Write the credentials to
.env.test
After setup completes, run pnpm rebalance:testnet to test the rebalance flow end-to-end.