Skip to content

Commit

Permalink
add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzshia committed Oct 29, 2024
1 parent 0240bde commit f0374bd
Show file tree
Hide file tree
Showing 33 changed files with 83 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/amm/addLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { initSdk, txVersion } from '../config'
import { isValidAmm } from './utils'
import Decimal from 'decimal.js'
import BN from 'bn.js'

export const addLiquidity = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -53,6 +54,7 @@ export const addLiquidity = async () => {
toToken(poolInfo.mintB),
new Decimal(r.maxAnotherAmount.toExact()).mul(10 ** poolInfo.mintA.decimals).toFixed(0)
),
otherAmountMin: r.minAnotherAmount,
fixedSide: 'a',
txVersion,
// optional: set up priority fee here
Expand All @@ -65,6 +67,7 @@ export const addLiquidity = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('liquidity added:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/amm/createAmmPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const createAmmPool = async () => {
{}
)
)
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/amm/createMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const createMarket = async () => {
})

console.log('create market txIds:', txIds)
process.exit() // if you don't want to end up node execution, comment this line
}

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

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -81,15 +82,18 @@ export const swap = async () => {
// },

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

printSimulateInfo()
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log(`swap successfully in amm pool:`, { txId: `https://explorer.solana.com/tx/${txId}` })

process.exit() // if you don't want to end up node execution, comment this line
}

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

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

Expand Down Expand Up @@ -95,9 +96,12 @@ export const swapBaseOut = async () => {
},
})

printSimulateInfo()
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log(`swap successfully in amm pool:`, { txId: `https://explorer.solana.com/tx/${txId}` })

process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
19 changes: 18 additions & 1 deletion src/amm/withdrawLiquidity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiV3PoolInfoStandardItem, AmmV4Keys, AmmV5Keys } from '@raydium-io/raydium-sdk-v2'
import { initSdk, txVersion } from '../config'
import BN from 'bn.js'
import Decimal from 'decimal.js'
import { isValidAmm } from './utils'

export const withdrawLiquidity = async () => {
Expand All @@ -25,10 +26,25 @@ export const withdrawLiquidity = async () => {

if (!isValidAmm(poolInfo.programId)) throw new Error('target pool is not AMM pool')

const [baseRatio, quoteRatio] = [
new Decimal(poolInfo.mintAmountA).div(poolInfo.lpAmount || 1),
new Decimal(poolInfo.mintAmountB).div(poolInfo.lpAmount || 1),
]

const withdrawAmountDe = new Decimal(withdrawLpAmount.toString())
const [withdrawAmountA, withdrawAmountB] = [
withdrawAmountDe.mul(baseRatio).mul(10 ** (poolInfo?.mintA.decimals || 0)),
withdrawAmountDe.mul(quoteRatio).mul(10 ** (poolInfo?.mintB.decimals || 0)),
]

const lpSlippage = 0.001 // means 0.1%

const { execute } = await raydium.liquidity.removeLiquidity({
poolInfo,
poolKeys,
amountIn: withdrawLpAmount,
lpAmount: withdrawLpAmount,
baseAmountMin: new BN(withdrawAmountA.mul(1 - lpSlippage).toFixed(0)),
quoteAmountMin: new BN(withdrawAmountB.mul(1 - lpSlippage).toFixed(0)),
txVersion,
// optional: set up priority fee here
// computeBudgetConfig: {
Expand All @@ -40,6 +56,7 @@ export const withdrawLiquidity = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('liquidity withdraw:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/closePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const closePosition = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('clmm position closed:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/createFarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const createFarm = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('clmm farm created:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/createPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const createPool = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('clmm pool created:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/createPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const createPosition = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('clmm position opened:', { txId, nft: extInfo.nftMint.toBase58() })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/decreaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const decreaseLiquidity = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('withdraw liquidity from clmm position:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/fetchPositionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const fetchPositionInfo = async () => {
amount: r.amount.toString(),
})),
})
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/harvestAllRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const harvestAllRewards = async () => {

const { txIds } = await execute({ sequentially: true })
console.log('harvested all clmm rewards:', { txIds })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
5 changes: 3 additions & 2 deletions src/clmm/harvestLockedPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export const harvestLockedPosition = async () => {
// },
})

// const { txId } = await execute({})
// console.log('harvested locked position :', { txId: `https://explorer.solana.com/tx/${txId}` })
const { txId } = await execute({})
console.log('harvested locked position :', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/increaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const increaseLiquidity = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('clmm position liquidity increased:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/lockPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const lockPosition = async () => {

const { txId } = await execute({})
console.log('position locked:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
2 changes: 2 additions & 0 deletions src/clmm/setFarmRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export const setFarmRewards = async () => {
const { txId } = await execute({ sendAndConfirm: true })
console.log('edit and add more rewards to clmm farm', { txId })
*/

process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
3 changes: 3 additions & 0 deletions src/clmm/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import BN from 'bn.js'
import { initSdk, txVersion } from '../config'
import { isValidClmm } from './utils'
import { printSimulateInfo } from '../util'

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -79,8 +80,10 @@ export const swap = async () => {
// },
})

printSimulateInfo()
const { txId } = await execute()
console.log('swapped in clmm pool:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/clmm/swapBaseOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const swapBaseOut = async () => {

const { txId } = await execute({ sendAndConfirm: true })
console.log('swapped in clmm pool:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/cpmm/createCpmmPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const createPool = async () => {
{}
),
})
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/cpmm/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const deposit = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('pool deposited', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/cpmm/harvestLockLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const harvestLockLiquidity = async () => {

const { txId } = await execute({ sendAndConfirm: true })
console.log('lp locked', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/cpmm/lockLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const lockLiquidity = async () => {

const { txId } = await execute({ sendAndConfirm: true })
console.log('lp locked', { txId: `https://explorer.solana.com/tx/${txId}`, extInfo })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
3 changes: 3 additions & 0 deletions src/cpmm/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initSdk } from '../config'
import BN from 'bn.js'
import { isValidCpmm } from './utils'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'

export const swap = async () => {
const raydium = await initSdk()
Expand Down Expand Up @@ -63,11 +64,13 @@ export const swap = async () => {
// },
})

printSimulateInfo()
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log(`swapped: ${poolInfo.mintA.symbol} to ${poolInfo.mintB.symbol}:`, {
txId: `https://explorer.solana.com/tx/${txId}`,
})
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
3 changes: 3 additions & 0 deletions src/cpmm/swapBaseOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { initSdk, txVersion } from '../config'
import BN from 'bn.js'
import { isValidCpmm } from './utils'
import { NATIVE_MINT } from '@solana/spl-token'
import { printSimulateInfo } from '../util'

// swapBaseOut means fixed output token amount, calculate needed input token amount
export const swapBaseOut = async () => {
Expand Down Expand Up @@ -80,11 +81,13 @@ export const swapBaseOut = async () => {
},
})

printSimulateInfo()
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log(`swapped: ${poolInfo.mintA.symbol} to ${poolInfo.mintB.symbol}:`, {
txId: `https://explorer.solana.com/tx/${txId}`,
})
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/cpmm/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const withdraw = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('pool withdraw:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/farm/createAmmFarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const createAmmFarm = async () => {
'farm id:',
extInfo.farmId.toBase58()
)
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/farm/editAmmFarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const editAmmFarm = async () => {
const { txId } = await editFarmBuilder.execute({ sendAndConfirm: true })
console.log('amm farm reward edited and added:', { txId })
*/
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/farm/harvest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const harvest = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('farm harvested:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/farm/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const stake = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('farm deposited:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
1 change: 1 addition & 0 deletions src/farm/unstake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const unstake = async () => {
// don't want to wait confirm, set sendAndConfirm to false or don't pass any params to execute
const { txId } = await execute({ sendAndConfirm: true })
console.log('farm staked:', { txId: `https://explorer.solana.com/tx/${txId}` })
process.exit() // if you don't want to end up node execution, comment this line
}

/** uncomment code below to execute */
Expand Down
Loading

0 comments on commit f0374bd

Please sign in to comment.