@valiant-trade/vortex
v1.0.6
Published
Valiant's high-level typescript sdk to interact with Valiant's on-chain Vortex program.
Readme
Valiant Vortex SDK
Valiant Vortex is an open-source concentrated liquidity AMM contract on the Fogo blockchain. This SDK allows developers to interact with the Vortex program on both chains, enabling the creation and management of liquidity pools and positions, as well as performing swaps.
Overview
The Valiant Vortex SDK provides a comprehensive set of tools to interact with the Vortex program on the Fogo blockchain.
Note: This SDK uses Solana kit SDK.
Installation
To install the SDK, use the following command:
npm install @valiant-trade/vortexBasic Usage
1. Wallet Creation
You can generate a file system wallet using the Solana CLI and load it in your program.
import { createKeyPairSignerFromBytes } from "@solana/kit";
import fs from 'fs';
const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
const wallet = await createKeyPairSignerFromBytes(keyPairBytes);2. Configure the Vortex SDK for Your Network
Valiant's Vortex SDK supports Fogo testnet currently. To select a network, use the setVortexConfig function. This ensures compatibility with the network you’re deploying on.
Example: Setting the SDK Configuration to Solana Devnet.
import { setVortexConfig } from '@valiant-trade/vortex';
await setVortexConfig('fogoTestnet');Available networks are:
- fogoTestnet
ℹ️ The setVortexConfig function accepts either one of Valiant's default network keys or a custom Address. This allows you to specify a custom configuration if needed.
3. Create the Swap Instructions
After configuring the SDK, you can perform a swap. Here is an example of how to perform a token swap using the Vortex SDK:
import { swapInstructions } from '@valiant-trade/vortex';
const poolAddress = "POOL_ADDRESS";
const mintAddress = "TOKEN_MINT";
const amount = 1_000_000n;
const slippageTolerance = 100; // 100 bps = 1%
const { instructions, quote } = await swapInstructions(
devnetRpc,
{
inputAmount: amount,
mint: mintAddress
},
poolAddress,
wallet,
slippageTolerance,
wallet
);4. Putting it all together
import { swapInstructions, setVortexConfig } from '@valiant-trade/vortex';
import { devnet } from "@solana/kit";
import { createSolanaRpc } from '@solana/rpc';
// Setup RPC connection to Fogo testnet
const devnetRpc = createSolanaRpc(devnet('https://testnet.fogo.io'));
// Set Vortex configuration for Fogo testnet
await setVortexConfig('fogoTestnet');
// Load wallet
const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
const wallet = await createKeyPairSignerFromBytes(keyPairBytes);
// Request airdrop for testing
await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
// Swap configuration
const poolAddress = address("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt");
const mintAddress = address("So11111111111111111111111111111111111111112");
const amount = 1_000_000n; // 0.001 WFOGO (FOGO has 9 decimals)
const slippageTolerance = 100; // 100bps = 1%
// Get swap instructions and quote
const { instructions, quote } = await swapInstructions(
devnetRpc,
{
inputAmount: amount,
mint: mintAddress
},
poolAddress,
wallet,
slippageTolerance,
wallet
);
