Skip to content

Commit 2a050e7

Browse files
authored
swap
1 parent dfc55a9 commit 2a050e7

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RPC_URL="https://api.devnet.solana.com"
2+
WALLET_PRIVATE_KEY="43EeRipwq7QZurfASn7CnYuJ14pVaCEv7KWav9vknt1bFR6qspYXC2DbaC2gGydrVx4TFtWfyCFkEaLLLMB2bZoT"

.env.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "MIT",
1111
"dependencies": {
1212
"@coral-xyz/anchor": "^0.29.0",
13+
"@project-serum/anchor": "^0.26.0",
1314
"@raydium-io/raydium-sdk": "^1.3.1-beta.50",
1415
"@solana/spl-token": "^0.4.1",
1516
"bs58": "^5.0.0",

src/index.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { Transaction, VersionedTransaction } from '@solana/web3.js';
33
import 'dotenv/config';
44
import { swapConfig } from './swapConfig'; // Import the configuration
55

6+
////////////ayad//////////
7+
import {
8+
LiquidityPoolKeys,
9+
} from '@raydium-io/raydium-sdk';
10+
import { web3 } from "@project-serum/anchor";
11+
612
/**
713
* Performs a token swap on the Raydium protocol.
814
* Depending on the configuration, it can execute the swap or simulate it.
@@ -21,11 +27,50 @@ const swap = async () => {
2127
await raydiumSwap.loadPoolKeys(swapConfig.liquidityFile);
2228
console.log(`Loaded pool keys`);
2329

30+
31+
32+
/////////ayad/////////////
2433
/**
2534
* Find pool information for the given token pair.
2635
*/
27-
const poolInfo = raydiumSwap.findPoolInfoForTokens(swapConfig.tokenAAddress, swapConfig.tokenBAddress);
28-
console.log('Found pool info');
36+
// const poolInfo = raydiumSwap.findPoolInfoForTokens(swapConfig.tokenAAddress, swapConfig.tokenBAddress);
37+
// console.log('Found pool info');
38+
39+
const poolInfo : LiquidityPoolKeys = {
40+
// "_id":"6641bf8d7fdfe653a776471b",
41+
// id:"2viGyp1hY8PGw7GEPzJvLdPAQpe7zL745oHp1C6a3jcJ",
42+
id: new web3.PublicKey("2viGyp1hY8PGw7GEPzJvLdPAQpe7zL745oHp1C6a3jcJ"),
43+
baseMint: new web3.PublicKey("Duqm5K5U1H8KfsSqwyWwWNWY5TLB9WseqNEAQMhS78hb"),
44+
quoteMint: new web3.PublicKey("So11111111111111111111111111111111111111112"),
45+
lpMint: new web3.PublicKey("89ZKE4aoyfLBe2RuV6jM3JGNhaV18Nxh8eNtjRcndBip"),
46+
baseDecimals:9,
47+
quoteDecimals:9,
48+
lpDecimals:6,
49+
version:4,
50+
programId: new web3.PublicKey("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),
51+
authority: new web3.PublicKey("5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1"),
52+
openOrders: new web3.PublicKey("6Su6Ea97dBxecd5W92KcVvv6SzCurE2BXGgFe9LNGMpE"),
53+
targetOrders: new web3.PublicKey("5hATcCfvhVwAjNExvrg8rRkXmYyksHhVajWLa46iRsmE"),
54+
baseVault: new web3.PublicKey("Em6rHi68trYgBFyJ5261A2nhwuQWfLcirgzZZYoRcrkX"),
55+
quoteVault: new web3.PublicKey("3mEFzHsJyu2Cpjrz6zPmTzP7uoLFj9SbbecGVzzkL1mJ"),
56+
withdrawQueue: new web3.PublicKey("11111111111111111111111111111111"),
57+
lpVault: new web3.PublicKey("11111111111111111111111111111111"),
58+
marketVersion:3,
59+
marketProgramId: new web3.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),
60+
marketId: new web3.PublicKey("BzcDHvKWD4LyW4X1NUEaWLBaNmyiCUKqcd3jXDRhwwAG"),
61+
marketAuthority: new web3.PublicKey("7SdieGqwPJo5rMmSQM9JmntSEMoimM4dQn7NkGbNFcrd"),
62+
marketBaseVault: new web3.PublicKey("6U6U59zmFWrPSzm9sLX7kVkaK78Kz7XJYkrhP1DjF3uF"),
63+
marketQuoteVault: new web3.PublicKey("4YEx21yeUAZxUL9Fs7YU9Gm3u45GWoPFs8vcJiHga2eQ"),
64+
marketBids: new web3.PublicKey("C1nEbACFaHMUiKAUsXVYPWZsuxunJeBkqXHPFr8QgSj9"),
65+
marketAsks: new web3.PublicKey("4DNBdnTw6wmrK4NmdSTTxs1kEz47yjqLGuoqsMeHvkMF"),
66+
marketEventQueue: new web3.PublicKey("4HGvdannxvmAhszVVig9auH6HsqVH17qoavDiNcnm9nj"),
67+
lookupTableAccount: new web3.PublicKey("73mV3Cihr7vMUHeoS2KfQ12gaPur8Zf9BGxmuDtQaG6p"),
68+
// createdAt:"2024-05-13T07:21:49.907Z",
69+
// updatedAt:"2024-05-13T07:21:49.907Z",
70+
// __v:0
71+
}
72+
73+
2974

3075
/**
3176
* Prepare the swap transaction with the given parameters.

src/swapConfig.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
export const swapConfig = {
22
executeSwap: false, // Send tx when true, simulate tx when false
33
useVersionedTransaction: true,
4-
tokenAAmount: 0.01, // Swap 0.01 SOL for USDT in this example
4+
tokenAAmount: 0.5, // Swap 0.01 SOL for USDT in this example
55
tokenAAddress: "So11111111111111111111111111111111111111112", // Token to swap for the other, SOL in this case
6-
tokenBAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC address
6+
// tokenBAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC address
7+
8+
tokenBAddress: "Duqm5K5U1H8KfsSqwyWwWNWY5TLB9WseqNEAQMhS78hb", // SALD address
9+
710
maxLamports: 1500000, // Micro lamports for priority fee
811
direction: "in" as "in" | "out", // Swap direction: 'in' or 'out'
9-
liquidityFile: "https://api.raydium.io/v2/sdk/liquidity/mainnet.json",
12+
// liquidityFile: "https://api.raydium.io/v2/sdk/liquidity/mainnet.json",
13+
14+
liquidityFile: "https://simple-crud-app-backend.onrender.com/v2/sdk/liquidity/mint",
15+
1016
maxRetries: 20,
1117
};

0 commit comments

Comments
 (0)