0.0.1 • Published 3 months ago

@synthetic-market-programs/synthetic-market-js v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

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 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

# 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