Client to interact with the Flash program on Solana
npm install flash-sdkautogenerated docs : https://flash-trade.github.io/flash-sdk-docs/
npm : https://www.npmjs.com/package/flash-sdk
npm i flash-sdk / yarn add flash-sdk
`
Flash SDK
Client SDK for interacting with FLASH.TRADE's smart-contractsautogenerated docs : https://flash-trade.github.io/flash-sdk-docs/
npm : https://www.npmjs.com/package/flash-sdk
code : https://github.com/flash-trade/flash-trade-sdk.git
Using the SDK
$3
`
import { AnchorProvider } from "@coral-xyz/anchor";
import { ComputeBudgetProgram , PublicKey, TransactionInstruction } from '@solana/web3.js' const provider : AnchorProvider = AnchorProvider.local(clusterUrl, {
commitment: "confirmed",
preflightCommitment: "confirmed",
skipPreflight: true
});
const perpClient = new PerpetualsClient(provider, programId);
// NOTE: choose the correct POOL_CONFIG based on the pool you want to interact
// flp.1
const POOL_CONFIG = PoolConfig.fromIdsByName('Crypto.1','mainnet-beta')
// flp.2
// const POOL_CONFIG = PoolConfig.fromIdsByName('Virtual.1','mainnet-beta')
// flp.3
// const POOL_CONFIG = PoolConfig.fromIdsByName('Governance.1','mainnet-beta')
// flp.4
// const POOL_CONFIG = PoolConfig.fromIdsByName('Community.1','mainnet-beta')
// flp.5
// const POOL_CONFIG = PoolConfig.fromIdsByName('Community.2','mainnet-beta')
// flp.7
// const POOL_CONFIG = PoolConfig.fromIdsByName('Trump.1','mainnet-beta')
// flp.8
// const POOL_CONFIG = PoolConfig.fromIdsByName('Ore.1','mainnet-beta')
// flp.r
// const POOL_CONFIG = PoolConfig.fromIdsByName('Remora.1','mainnet-beta')
const poolAddress = POOL_CONFIG.poolAddress.toBase58()
const backupOracleData: any = await (await fetch(
https://flash.trade/api/backup-oracle?poolAddress=${poolAddress})).json()
const backUpOracleInstruction = new TransactionInstruction({
keys: backupOracleData.keys,
programId: new PublicKey(backupOracleData.programId),
data: Buffer.from(backupOracleData.data),
})
const USDC_TOKEN = POOL_CONFIG.tokens.find((t) => t.symbol == 'USDC')!
const BTC_TOKEN = POOL_CONFIG.tokens.find((t) => t.symbol == 'BTC')!
const tokenMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
const USDC_TOKEN = POOL_CONFIG.tokens.find((t) => t.mintKey.equals(tokenMint))!
await perpClient.loadAddressLookupTable(POOL_CONFIG)
const payTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
const { instructions : addLiqInstructions, additionalSigners : addLiqAdditionalSigners } = await perpClient.addLiquidityAndStake(
payTokenSymbol,
tokenAmountIn,
minLpAmountOut, // new BN(0)
POOL_CONFIG
)
const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([backUpOracleInstruction, setCULimitIx, ...addLiqInstructions ], {
addLiqAdditionalSigners,
alts: addresslookupTables,
})
const payTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
const { instructions : addCompLiqInstructions, additionalSigners : addCompLiqAdditionalSigners } = await perpClient.addCompoundingLiquidity(
tokenAmountIn,
payTokenSymbol,
minLpAmountOut, // new BN(0)
USDC_TOKEN.mintKey,
POOL_CONFIG
)
const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
const txid = perpClient.sendTransaction([backUpOracleInstruction, setCULimitIx, ...addCompLiqInstructions ], {
addCompLiqAdditionalSigners,
alts: perpClient.addressLookupTables,
})
const recieveTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
const { instructions : removeCompLiqInstructions, additionalSigners : removeCompLiqAdditionalSigners } = await await perpClient.removeCompoundingLiquidity(
lpAmountIn,
minTokenAmountOut, // new BN(0)
recieveTokenSymbol,
USDC_TOKEN.mintKey,
POOL_CONFIG,
true
)
const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([backUpOracleInstruction, setCULimitIx, ...removeCompLiqInstructions ], {
removeCompLiqAdditionalSigners,
alts: addresslookupTables,
})
const recieveTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
const { instructions : removeLiqInstructions, additionalSigners : removeLiqAdditionalSigners } = await await perpClient.removeLiquidity(
recieveTokenSymbol,
lpAmountIn,
minTokenAmountOut, // new BN(0)
POOL_CONFIG
)
const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([backUpOracleInstruction, setCULimitIx, ...removeLiqInstructions ], {
removeLiqAdditionalSigners,
alts: perpClient.addressLookupTables,
})
const { instructions: depositStakeInstructions, additionalSigners: depositStakeAdditionalSigners } =
await perpClient.depositStake(.provider.wallet.publicKey, provider.wallet.publicKey, flpDepositAmount, POOL_CONFIG)
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([...depositStakeInstructions ], {
depositStakeAdditionalSigners,
alts: perpClient.addressLookupTables,
})
const { instructions: unstakeInstantInstructions, additionalSigners : unstakeInstantAdditionalSigners } = await perpClient.unstakeInstant('USDC',flpUnstakeAmount,POOL_CONFIG)
const { instructions: withdrawStakeInstructions } = await perpClient.withdrawStake(POOL_CONFIG, false)
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([...unstakeInstantInstructions, ...withdrawStakeInstructions ], {
unstakeInstantAdditionalSigners,
alts: perpClient.addressLookupTables,
})
const { instructions, additionalSigners } = await perpClient.collectStakeFees('USDC',POOL_CONFIG)
let addresslookupTables: AddressLookupTableAccount[] = (
await flashClient.getOrLoadAddressLookupTable(POOL_CONFIG)
).addressLookupTables
const txid = perpClient.sendTransaction([...instructions ], {
additionalSigners,
alts: perpClient.addressLookupTables,
})
const compoundingLPTokenPrice = await perpClient.getCompoundingLPTokenPrice(POOL_CONFIG.poolAddress, POOL_CONFIG)
`
#### For generating docs run `yarn run doc ``