@swarm-markets/market-maker-sdk
v1.0.3
Published
Swarm Market Maker SDK - Decentralized OTC trading for RWAs
Maintainers
Readme
@swarm/market-maker-sdk
Swarm Market Maker SDK for peer-to-peer OTC trading on blockchain.
Installation
pnpm add @swarm/market-maker-sdkFeatures
- RPQ Service: Request-for-Quote service for discovering offers
- Smart Contract Integration: Direct interaction with Market Maker contracts
- Token Operations: ERC20 approvals and transfers
- Offer Management: Make, take, and cancel offers
Quick Start
import { MarketMakerClient, Network } from "@swarm/market-maker-sdk";
const client = new MarketMakerClient({
network: Network.POLYGON,
privateKey: "0x...",
rpqApiKey: "your-api-key",
});
await client.initialize();
// Get a quote
const quote = await client.getQuote(
"0xFromToken...",
"0xToToken...",
100 // fromAmount
);
// Execute a trade
const result = await client.trade(
"0xFromToken...",
"0xToToken...",
100 // fromAmount
);
console.log(`Trade executed: ${result.txHash}`);
await client.close();API
MarketMakerClient
Main client for Market Maker operations.
const client = new MarketMakerClient({
network: Network.POLYGON, // Required: Network to trade on
privateKey: "0x...", // Required: Private key for signing
rpqApiKey: "your-api-key", // Required: RPQ Service API key
userEmail: "[email protected]", // Optional: User email
rpcUrl: "https://...", // Optional: Custom RPC URL
});Methods
initialize()- Initialize the clientclose()- Close and cleanup resourcesgetQuote(fromToken, toToken, fromAmount?, toAmount?)- Get a quotetrade(fromToken, toToken, fromAmount?, toAmount?, affiliate?)- Execute a trademakeOffer(params)- Create a new offercancelOffer(offerId)- Cancel an existing offer
RPQClient
Low-level client for RPQ Service API.
import { RPQClient } from "@swarm/market-maker-sdk";
const rpq = new RPQClient("polygon", "api-key");
const offers = await rpq.getOffers("0xBuyAsset", "0xSellAsset");MarketMakerWeb3Client
Low-level client for smart contract interactions.
import { MarketMakerWeb3Client, Network } from "@swarm/market-maker-sdk";
const web3Client = new MarketMakerWeb3Client(
Network.POLYGON,
"0xPrivateKey..."
);
const txHash = await web3Client.takeFixedOffer(
123, // offerId
"0xWithdrawToken", // withdrawal token address
1000000000n // amount in wei
);Supported Networks
- Ethereum (Chain ID: 1)
- Polygon (Chain ID: 137)
- Base (Chain ID: 8453)
- BSC (Chain ID: 56)
License
MIT
