Skip to content

Commit

Permalink
update sdk and add txTipConfig params example
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzshia committed Jan 15, 2025
1 parent 7fb0278 commit 2c6e206
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Raydium SDK V2 demo.",
"license": "GPL-3.0",
"dependencies": {
"@raydium-io/raydium-sdk-v2": "0.1.101-alpha",
"@raydium-io/raydium-sdk-v2": "0.1.103-alpha",
"@solana/spl-token": "^0.4.6",
"@solana/web3.js": "^1.95.3",
"@triton-one/yellowstone-grpc": "^1.2.0",
Expand Down
7 changes: 7 additions & 0 deletions src/amm/addLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initSdk, txVersion } from '../config'
import { isValidAmm } from './utils'
import Decimal from 'decimal.js'
import BN from 'bn.js'
import { PublicKey } from '@solana/web3.js'

export const addLiquidity = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -62,6 +63,12 @@ export const addLiquidity = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
17 changes: 12 additions & 5 deletions src/amm/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isValidAmm } from './utils'
import Decimal from 'decimal.js'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'
import { PublicKey } from '@solana/web3.js'

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -82,10 +83,16 @@ export const swap = async () => {
// },

// optional: set up priority fee here
computeBudgetConfig: {
units: 600000,
microLamports: 46591500,
},
// computeBudgetConfig: {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

printSimulateInfo()
Expand All @@ -97,4 +104,4 @@ export const swap = async () => {
}

/** uncomment code below to execute */
swap()
// swap()
7 changes: 7 additions & 0 deletions src/amm/swapBaseOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isValidAmm } from './utils'
import Decimal from 'decimal.js'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'
import { PublicKey } from '@solana/web3.js'

// setLoggerLevel('Raydium_LiquidityV2', LogLevel.Debug) // uncomment to show debug log

Expand Down Expand Up @@ -94,6 +95,12 @@ export const swapBaseOut = async () => {
units: 600000,
microLamports: 465915,
},

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

printSimulateInfo()
Expand Down
7 changes: 7 additions & 0 deletions src/amm/withdrawLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initSdk, txVersion } from '../config'
import BN from 'bn.js'
import Decimal from 'decimal.js'
import { isValidAmm } from './utils'
import { PublicKey } from '@solana/web3.js'

export const withdrawLiquidity = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -50,6 +51,12 @@ export const withdrawLiquidity = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
5 changes: 5 additions & 0 deletions src/clmm/closePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const closePosition = async () => {
poolKeys,
ownerPosition: position,
txVersion,
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
6 changes: 6 additions & 0 deletions src/clmm/createFarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export const createFarm = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
5 changes: 5 additions & 0 deletions src/clmm/decreaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export const decreaseLiquidity = async () => {
// units: 600000,
// microLamports: 46591500,
// },
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
6 changes: 6 additions & 0 deletions src/clmm/increaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export const increaseLiquidity = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
6 changes: 6 additions & 0 deletions src/clmm/lockPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const lockPosition = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

const { txId } = await execute({})
Expand Down
7 changes: 7 additions & 0 deletions src/clmm/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BN from 'bn.js'
import { initSdk, txVersion } from '../config'
import { isValidClmm } from './utils'
import { printSimulateInfo } from '../util'
import { PublicKey } from '@solana/web3.js'

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -78,6 +79,12 @@ export const swap = async () => {
// units: 600000,
// microLamports: 465915,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

printSimulateInfo()
Expand Down
7 changes: 7 additions & 0 deletions src/clmm/swapBaseOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initSdk, txVersion } from '../config'
import { isValidClmm } from './utils'
import { NATIVE_MINT } from '@solana/spl-token'
import Decimal from 'decimal.js'
import { PublicKey } from '@solana/web3.js'

// swapBaseOut means fixed output token amount, calculate needed input token amount
export const swapBaseOut = async () => {
Expand Down Expand Up @@ -93,6 +94,12 @@ export const swapBaseOut = async () => {
units: 600000,
microLamports: 465915,
},

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

const { txId } = await execute({ sendAndConfirm: true })
Expand Down
6 changes: 6 additions & 0 deletions src/cpmm/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export const deposit = async () => {
// units: 600000,
// microLamports: 46591500,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
// const { txId } = await execute({ sendAndConfirm: true })
Expand Down
5 changes: 5 additions & 0 deletions src/cpmm/harvestLockLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const harvestLockLiquidity = async () => {
nftMint: new PublicKey('CgkdQL6eRN1nxG2AmC8NFG5iboXuKtSjT4pShnspomZy'), // locked nft mint
lpFeeAmount: new BN(99999999),
txVersion,
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

const { txId } = await execute({ sendAndConfirm: true })
Expand Down
7 changes: 7 additions & 0 deletions src/cpmm/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BN from 'bn.js'
import { isValidCpmm } from './utils'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'
import { PublicKey } from '@solana/web3.js'

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -62,6 +63,12 @@ export const swap = async () => {
// units: 600000,
// microLamports: 4659150,
// },

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

printSimulateInfo()
Expand Down
7 changes: 7 additions & 0 deletions src/cpmm/swapBaseOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BN from 'bn.js'
import { isValidCpmm } from './utils'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'
import { PublicKey } from '@solana/web3.js'

// swapBaseOut means fixed output token amount, calculate needed input token amount
export const swapBaseOut = async () => {
Expand Down Expand Up @@ -79,6 +80,12 @@ export const swapBaseOut = async () => {
units: 600000,
microLamports: 465915,
},

// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

printSimulateInfo()
Expand Down
5 changes: 5 additions & 0 deletions src/cpmm/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const withdraw = async () => {
// units: 600000,
// microLamports: 46591500,
// },
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
5 changes: 5 additions & 0 deletions src/farm/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const stake = async () => {
// units: 600000,
// microLamports: 46591500,
// },
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
5 changes: 5 additions & 0 deletions src/farm/unstake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const unstake = async () => {
// units: 600000,
// microLamports: 46591500,
// },
// optional: add transfer sol to tip account instruction. e.g sent tip to jito
// txTipConfig: {
// address: new PublicKey('96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5'),
// amount: new BN(10000000), // 0.01 sol
// },
})

// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@raydium-io/[email protected].101-alpha":
version "0.1.101-alpha"
resolved "https://registry.yarnpkg.com/@raydium-io/raydium-sdk-v2/-/raydium-sdk-v2-0.1.101-alpha.tgz#44833d7ba95c34655132b83c205d73aab3d47fc4"
integrity sha512-EN/b8RX1y3gXXugpAmyxpTOaCAvTtxEULzkygbkoy0tkxlP3Jh1FyzU3kXX3WT4q4oDXdunoMDZdlH4G0xQ81A==
"@raydium-io/[email protected].103-alpha":
version "0.1.103-alpha"
resolved "https://registry.yarnpkg.com/@raydium-io/raydium-sdk-v2/-/raydium-sdk-v2-0.1.103-alpha.tgz#78129f1f544772c21565fb9d6d7a7c43bbfa28ad"
integrity sha512-M65ghL755vB6BgOsuj47HlNyf53kZlFscpqwpzVmfiWsaMZuokx3MMQPirci8sSovgnVEpiJAPYdJjY0IiWQNQ==
dependencies:
"@solana/buffer-layout" "^4.0.1"
"@solana/spl-token" "^0.4.8"
Expand Down

0 comments on commit 2c6e206

Please sign in to comment.