diff --git a/README.md b/README.md index 9fa8711..5712cea 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,7 @@ $ cargo run --bin sample -- -r $YOUR_DEVNET_RPC_ENDPOINT ## TypeScript ```TypeScript -import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token"; -import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js"; +import { Connection, Keypair, Transaction } from "@solana/web3.js"; import base58 from "bs58"; import * as Phoenix from "@ellipsis-labs/phoenix-sdk"; @@ -27,28 +26,36 @@ async function simpleSwap() { // DO NOT USE THIS KEYPAIR IN PRODUCTION const trader = Keypair.fromSecretKey( base58.decode( - "2PKwbVQ1YMFEexCmUDyxy8cuwb69VWcvoeodZCLegqof84DJSTiEd89Ak3so9CiHycZwynesTt1JUDFAPFWEzvVs" - ) + "2PKwbVQ1YMFEexCmUDyxy8cuwb69VWcvoeodZCLegqof84DJSTiEd89Ak3so9CiHycZwynesTt1JUDFAPFWEzvVs", + ), ); // Create a Phoenix client and select a market const phoenix = await Phoenix.Client.create(connection); - const marketConfig = phoenix.marketConfigs.find((market) => market.name === "SOL/USDC"); + + const marketConfig = Array.from(phoenix.marketConfigs.values()).find( + (market) => market.name === "SOL/USDC", + ); if (!marketConfig) { throw new Error("Market config not found"); } + const marketState = phoenix.marketStates.get(marketConfig.marketId); if (!marketState) { throw new Error("Market state not found"); } - // Submit a market order buying 100 USDC worth of SOL - const tx = marketState.getSwapTransaction({ + // Build an order packet for a market swap + const orderPacket = marketState.getSwapOrderPacket({ side: Phoenix.Side.Bid, inAmount: 100, - trader: trader.publicKey, }); + // Submit a market order buying 100 USDC worth of SOL + const tx = new Transaction().add( + marketState.createSwapInstruction(orderPacket, trader.publicKey), + ); + const txId = await connection.sendTransaction(tx, [trader]); console.log("Transaction ID: ", txId); }