Giter Site home page Giter Site logo

raydium-sdk-v1-demo's Introduction

RAYDIUM SDK V1 demo

About the project

This project is for RAYDIUM SDK demonstration

Getting Started

Installation

yarn install

this will install the dependencies for running the demo script

Prerequisites

Modify config.ts.template to fit your configuration, and rename it to config.ts

  • <YOUR_WALLET_SECRET_KEY>: replace to your own one
  • <YOUR_RPC_URL>: replace to your prefer one

Usage

  • yarn clean clean up the old scripts (you don't need this for the very first time)
  • yarn build build the scripts
  • yarn start js/src/<SCRIPT_NAME> run the specific demo script
  • yarn ammv3-market 2QdhepnKRTLjjSqPL1PtKNwqrUkoLee5Gqs8bvZhRdMv 10 20 run ammv3 market maker, arguments 0: poolId, 1: create position deviation, 2: close position deviation, remember to replace rpc url and secret key in code and uncomment closePositionTx and createPositionTx code part

image

you can simply combine the command to run a demo, e.g

yarn clean && yarn build && yarn start js/src/stakeFarm.js

raydium-sdk-v1-demo's People

Contributors

cruzshia avatar edsolater avatar jack77121 avatar rudy5348 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

raydium-sdk-v1-demo's Issues

Is there an issue with the Raydium API?

Thanks!

After two weeks trying to make the smallest things to work following Raydium SDK's examples your code was a time-saver. Thanks again.

Creating a new market fails

When I try to run utilsCreateMarket script in order to create a market id for a token, it fails every time with this error:
sdkerror

The transaction partially succeeds by creating 2 accounts and initializing them but then fails at second set of instructions at ins2
27 02 2024_16 13 48_REC

Please fix

Create Pool Tx not Found on Solana Devnet Explorer

I successfully created a pool on devnet (ammCreatePool.js) and got the AMM ID and txid which I can't find on Solana Explorer Devnet. How can I find this pool?

AMM_ID: 7hF4rzcuq2WRgrGo6Lc2oDE645pJPXW9vaTSEPuxv9F8

Txid: 638v99dxHYvjmdstydR8PVNKU3ecmocH6Nn1hjxoC34ffFMXRotPjfJCPs4etHsve2PT9UWBwwDJGqk4huQKKz8V

Where is the ammV3MarketMaker file?

I am trying to run the demo.

yarn ammv3-market 2QdhepnKRTLjjSqPL1PtKNwqrUkoLee5Gqs8bvZhRdMv 10 20

It seems this ammV3MarketMaker folder is missing.

Why swapRoute.ts soooooo slow?

When I run swapRoute.ts in nodejs, it might cost 2 minutes, and I check the code, most time spent at those code:

const sPool: ApiPoolInfo = await formatAmmKeysToApi(PROGRAMIDS.AmmV4.toString(), true)

any suggestion?

also I get this error sometimes:

Error: 500 Internal Server Error: {"jsonrpc":"2.0","id":"7b40fc89-75f4-482f-8e78-8a5cd8cb6797","error":{"code":-32603,"message":"Internal server error"}}

I use the alchemy RPC node:

const RPC_MAINET = 'https://solana-mainnet.g.alchemy.com/v2/UZlhPRTS....';

Error when create pool on devnet

Here is the logs:

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1000078
    at Connection.sendEncodedTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9560:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20)
    at async Connection.sendTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9482:14) {
  logs: [
    'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 invoke [1]',
    'Program log: initialize2: InitializeInstruction2 { nonce: 252, open_time: 1705661603, init_pc_amount: 100000000000, init_coin_amount: 100000000000 }',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: SyncNative',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3045 of 182570 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeMint',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2920 of 154835 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeAccount',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4501 of 140334 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeAccount',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4501 of 124242 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj invoke [2]',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj consumed 1357 of 94689 compute units',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj failed: custom program error: 0x1000078',
    'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 consumed 106668 of 200000 compute units',
    'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 failed: custom program error: 0x1000078'
  ]
    }

And also createMarket method:

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 5: custom program error: 0x1000694
    at Connection.sendEncodedTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9560:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20)
    at async Connection.sendTransaction (/home/ubuntu/raydium/demo-raydium/node_modules/@solana/web3.js/lib/index.cjs.js:9482:14) {
  logs: [
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj invoke [1]',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj consumed 4811 of 1199250 compute units',
    'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj failed: custom program error: 0x1000694'
  ]
}

@rudy5348 Could you please check? Thank you!

subNewAmmPool runs without receiving events

I wanted to monitor new AmmPool created in real time. As mentioned here I wanted to use the subNewAmmPool.ts script for that. I cloned the repo and followed readme. stakeFarm.js runs with no problems. When a start subNewAmmPool by running: start js/src/subNewAmmPool.js the script runs for couple of minutes without logging anything and then throws an error. Probably just timing out because of inactivity. I checked and the scripts seem to open connection and subscribing without errors. But there are no results in minutes. As I understand it there should be multiple AmmPool created per minute on Raydium as it is the last step of listing a token to trade. What do I understand or do wrong?

Running swapOnlyAMM throw error

when i running swapOnlyAMM.ts, throw error

Uncaught RangeError RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 20. Received 44

Running swapRoute throw error

Hello! When I try to call the function Clmm.fetchMultiplePoolInfos, it returns this error. Help me understand what's going on

image image

bad secret key size

Hey when i want to use a script i get "bad secret key size"
but i pasted the right secret key in the config.ts
it looked like this "[185,123,156,123,...,]"

What am i doing wrong?

swaponlyamm suggestion

First suggestion is to have it to export swaponlyamm

export async function swapOnlyAmm(input: TestTxInputInfo)

This will allow users to make their own files and connect them to the sdk without making changes, hence they can update them without problem.

update how to use to handle errors.

swapOnlyAmm({
  outputToken,
  targetPool,
  inputTokenAmount,
  slippage,
  walletTokenAccounts,
  wallet: wallet,
}).then(({ txids }) => {
  /** continue with txids */
  console.log(`https://solscan.io/tx/${txids}`)
}).catch((error) => {
  // Handle the error
  console.error('An error occurred:', error);
});

Unable create pool on devnet

  1. Change the PROGRAMIDS in config.ts
- export const PROGRAMIDS = MAINNET_PROGRAM_ID;
+ export const PROGRAMIDS = DEVNET_PROGRAM_ID;

Also

- marketProgramId: MAINNET_PROGRAM_ID.OPENBOOK_MARKET,
+ marketProgramId: PROGRAMIDS.OPENBOOK_MARKET,
  1. Change baseToken and quoteToken as needed
  2. Run the script, and get the error below,
/home/user/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5921
      throw new SendTransactionError(
            ^
SendTransactionError: failed to send transaction: invalid transaction: Transaction loads an address table account that doesn't exist
    at Connection.sendEncodedTransaction (/home/user/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5921:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/home/user/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5880:20)
    at async Connection.sendTransaction (/home/user/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5829:14) {
  logs: undefined

Have try the option { skipPreflight: true } said in #7. no luck.


And the market-related public keys on devnet,

  • programId: PublicKey(HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8)
  • marketProgramId: PublicKey(EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj)
  • marketId: PublicKey(DRzjx9azfcxkdnCDQ5aZ43EyEmbwFMjVu3ST5QwuH5Ty)
  • marketAuthority: PublicKey(G8Vsxm9rCG26AhXxAT4PfDggRmMvY9cf7oQFwSLz3phe)
  • lookupTableAccount: PublicKey(11111111111111111111111111111111)
  • configId: PublicKey(8QN9yfKqWDoKjvZmqFsgCzAqwZBQuzVVnC388dN5RCPo)

The error occurs when invoking ammCreatePool.ts

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: custom program error: 0x1000078
at Connection.sendEncodedTransaction (/Users/aurora/project/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5921:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Connection.sendRawTransaction (/Users/aurora/project/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5880:20)
at async Connection.sendTransaction (/Users/aurora/project/raydium-sdk-V1-demo/node_modules/@solana/web3.js/src/connection.ts:5829:14) {
logs: [
'Program 11111111111111111111111111111111 invoke [1]',
'Program 11111111111111111111111111111111 success',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
'Program log: Instruction: InitializeAccount',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3443 of 799850 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 invoke [1]',
'Program log: initialize2: InitializeInstruction2 { nonce: 252, open_time: 1713880941, init_pc_amount: 0, init_coin_amount: 0 }',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
'Program log: Instruction: SyncNative',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3045 of 779233 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
'Program log: Instruction: InitializeMint',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2920 of 744020 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
'Program log: Instruction: InitializeAccount',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4501 of 726518 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
'Program log: Instruction: InitializeAccount',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3445 of 710416 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program 11111111111111111111111111111111 invoke [2]',
'Program 11111111111111111111111111111111 success',
'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj invoke [2]',
'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj consumed 1357 of 684916 compute units',
'Program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj failed: custom program error: 0x1000078',
'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 consumed 112848 of 796407 compute units',
'Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 failed: custom program error: 0x1000078'
]
}

staked list

hello i need to know how i can show staked tokens and amount of staked

Bad secret key size

throw new Error('bad secret key size')
I know this issue has been already answered but I need further help. My private key has 88 characters and has both numbers and letter which doesn't seem to be the case in the last post(idk I don't understand this, I just need to somehow paste the key for it to work)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.