UNPKG

@sol-synth-engine/js-client

Version:

JavaScript client for Sol Synth Engine

147 lines (107 loc) 3.45 kB
# Sol Synth Engine JavaScript Client This is the JavaScript client for the Sol Synth Engine program, a synthetic asset protocol on Solana. ## Features - Create and manage synthetic markets - Mint and redeem synthetic assets - Manage underlying tokens and treasuries - Query market and position information - Full TypeScript support ## Installation ```bash npm install @sol-synth-engine/js-client ``` ## Usage ### Initialize Client ```typescript import { SolSynthEngineClient } from "@sol-synth-engine/js-client"; import { Connection, PublicKey, Keypair } from "@solana/web3.js"; // Initialize the client const connection = new Connection("https://api.mainnet-beta.solana.com"); const programId = new PublicKey("YOUR_PROGRAM_ID"); const client = new SolSynthEngineClient(programId, connection); // Create a wallet const wallet = Keypair.generate(); ``` ### Create Market ```typescript const marketName = "btc"; const syntheticMint = new PublicKey("YOUR_SYNTHETIC_MINT"); const oracleSource = new PublicKey("YOUR_ORACLE_SOURCE"); const syntheticOracleSource = new PublicKey("YOUR_SYNTHETIC_ORACLE_SOURCE"); const marketFeeRate = 0.01; const marketAuthority = new PublicKey("YOUR_MARKET_AUTHORITY"); const tx = await client.createMarket( marketName, syntheticMint, oracleSource, syntheticOracleSource, marketFeeRate, marketAuthority, ); ``` ### Mint Synthetic Assets ```typescript const marketName = "btc"; const amount = 1000000; // Amount in smallest unit const underlyingToken = new PublicKey("YOUR_UNDERLYING_TOKEN"); const syntheticToken = new PublicKey("YOUR_SYNTHETIC_TOKEN"); const tx = await client.mint(marketName, amount, underlyingToken, syntheticToken, wallet.publicKey); ``` ### Redeem Synthetic Assets ```typescript const marketName = "btc"; const amount = 1000000; // Amount in smallest unit const syntheticToken = new PublicKey("YOUR_SYNTHETIC_TOKEN"); const underlyingToken = new PublicKey("YOUR_UNDERLYING_TOKEN"); const tx = await client.redeem( marketName, amount, syntheticToken, underlyingToken, wallet.publicKey, ); ``` ### Query Market Information ```typescript // Get market info const marketInfo = await client.getMarketInfo("btc"); // Get position info const positionInfo = await client.getPositionInfo("btc", wallet.publicKey); // Get treasury info const treasuryInfo = await client.getTreasuryInfo("btc", new PublicKey("YOUR_TREASURY_TOKEN")); ``` ## API Reference ### SolSynthEngineClient The main client class for interacting with the Sol Synth Engine program. #### Constructor ```typescript constructor(programId: PublicKey, connection: Connection) ``` #### Methods - `createMarket`: Create a new synthetic market - `mint`: Mint synthetic assets - `redeem`: Redeem synthetic assets - `getMarketInfo`: Get market information - `getPositionInfo`: Get position information - `getTreasuryInfo`: Get treasury information - `addUnderlyingToken`: Add an underlying token to a market - `addTreasury`: Add a treasury to a market ## Development ```bash # Install dependencies npm install # Build the package npm run build # Run tests npm test # Clean build artifacts npm run clean ``` ## Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## License MIT