0.0.1 • Published 3 months ago
@synthetic-market-programs/synthetic-market-js v0.0.1
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
npm install @synthetic-market-programs/js-client
Usage
Initialize Client
import { SyntheticMarketClient } from "@synthetic-market-programs/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 SyntheticMarketClient(programId, connection);
// Create a wallet
const wallet = Keypair.generate();
Create Market
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
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
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
// 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
SyntheticMarketClient
The main client class for interacting with the Sol Synth Engine program.
Constructor
constructor(programId: PublicKey, connection: Connection)
Methods
createMarket
: Create a new synthetic marketmint
: Mint synthetic assetsredeem
: Redeem synthetic assetsgetMarketInfo
: Get market informationgetPositionInfo
: Get position informationgetTreasuryInfo
: Get treasury informationaddUnderlyingToken
: Add an underlying token to a marketaddTreasury
: Add a treasury to a market
Development
# Install dependencies
npm install
# Build the package
npm run build
# Run tests
npm test
# Clean build artifacts
npm run clean
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
MIT
0.0.1
3 months ago