project-serum / serum-js

JavaScript client library for interacting with the Project Serum DEX.
82 stars 33 forks source link

What should we put for the market address public key? #1

Closed leonardge closed 3 years ago

leonardge commented 4 years ago

In the README.md it said to put in the public key of the market, I am wondering when should we put in exactly?

I have tried:

  let marketAddress = new PublicKey('9o1FisE366msTQcEvXapyMorTLmvezrxSD8DnM5e5XKw');

According to here

But this doesn't seem to work, it's reporting:

$ node index.js 
(node:15774) ExperimentalWarning: The ESM module loader is experimental.
(node:15774) UnhandledPromiseRejectionWarning: Error: Address not owned by program
    at Function.load (/Users/wge/Documents/serum_exp/node_modules/@project-serum/serum/lib/market.js:53:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async main (file:///Users/wge/Documents/serum_exp/index.js:9:16)
(node:15774) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15774) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
nishadsingh1 commented 4 years ago

Hi @leonardge -- sorry about the delay here.

I believe you're passing in a market that corresponds to an old DEX program version (see DEX_PROGRAM_ID in instructions.js).

You can either:

Here's a market that'll work for (1) in the source's current state (verison 0.6.4, DEX program ID 3v9kjrBLN7Awr9BGC2qmFnWLM1EgMAdNm2rXLQFUcQ2d): 6ibUz1BqSD3f8XP4wEGwoRH4YbYRZ1KDZBeXmrp3KosD on mainnet.

nishadsingh1 commented 4 years ago

9o1FisE366msTQcEvXapyMorTLmvezrxSD8DnM5e5XKw also doesn't seem to be a market address: it's a program address. When using the solana explorer, market addresses will show their owner (corresponding DEX program) like so: https://explorer.solana.com/address/6ibUz1BqSD3f8XP4wEGwoRH4YbYRZ1KDZBeXmrp3KosD

leofisG commented 4 years ago

Hi, @nishadsingh1 thanks for the clarification. I can now get the bids and asks however, should the order have the owner field? Specificially, I am referring to:

// Full orderbook data
for (let order of asks) {
  console.log(
    order.orderId,
    order.owner.toBase58(),   <--- this line
    order.price,
    order.size,
    order.side, // 'buy' or 'sell'
  );
}

It is telling me the owner is undefined when using the market address as you suggested.

leofisG commented 4 years ago

I looked at the code, seems like owner is not part of the Order interface.

leofisG commented 4 years ago

Ah and one more thing, for the following code:

// Placing orders
let owner = new Account('...');
let payer = new PublicKey('...'); // spl-token account
await market.placeOrder(connection, {
  owner,
  payer,
  side: 'buy', // 'buy' or 'sell'
  price: 123.45,
  size: 17.0,
  orderType: 'limit', // 'limit', 'ioc', 'postOnly'
});

why do we need the distinction of owner and payer?

chatbox77 commented 4 years ago

what is the address for mainnet ? let connection = new Connection('https://testnet.solana.com');

leofisG commented 4 years ago

This: https://api.mainnet-beta.solana.com @chatbox77 And you can find the market as followed:

          Z = {
            "MSRM/USDT": {
                address: "H4snTKK9adiU15gP22ErfZYtro3aqR9BTMXiH3AwiUTQ",
                name: "MSRM/USDT"
            },
            "MSRM/USDC": {
                address: "7kgkDyW7dmyMeP8KFXzbcUZz1R2WHsovDZ7n3ihZuNDS",
                name: "MSRM/USDC"
            },
            "BTC/USDT": {
                address: "8AcVjMG2LTbpkjNoyq8RwysokqZunkjy3d5JDzxC6BJa",
                name: "BTC/USDT"
            },
            "BTC/USDC": {
                address: "CAgAeMD7quTdnr6RPa7JySQpjf3irAmefYNdTb6anemq",
                name: "BTC/USDC"
            },
            "ETH/USDT": {
                address: "HfCZdJ1wfsWKfYP2qyWdXTT5PWAGWFctzFjLH48U1Hsd",
                name: "ETH/USDT"
            },
            "ETH/USDC": {
                address: "ASKiV944nKg1W9vsf7hf3fTsjawK6DwLwrnB2LH9n61c",
                name: "ETH/USDC"
            },
            "SRM/USDT": {
                address: "HARFLhSq8nECZk4DVFKvzqXMNMA9a3hjvridGMFizeLa",
                name: "SRM/USDT"
            },
            "SRM/USDC": {
                address: "68J6nkWToik6oM9rTatKSR5ibVSykAtzftBUEAvpRsys",
                name: "SRM/USDC"
            },
            "FTT/USDT": {
                address: "DHDdghmkBhEpReno3tbzBPtsxCt6P3KrMzZvxavTktJt",
                name: "FTT/USDT"
            },
            "FTT/USDC": {
                address: "FZqrBXz7ADGsmDf1TM9YgysPUfvtG8rJiNUrqDpHc9Au",
                name: "FTT/USDC"
            },
            "YFI/USDT": {
                address: "5zu5bTZZvqESAAgFsr12CUMxdQvMrvU9CgvC1GW8vJdf",
                name: "YFI/USDT"
            },
            "YFI/USDC": {
                address: "FJg9FUtbN3fg3YFbMCFiZKjGh5Bn4gtzxZmtxFzmz9kT",
                name: "YFI/USDC"
            },
            "LINK/USDT": {
                address: "F5xschQBMpu1gD2q1babYEAVJHR1buj1YazLiXyQNqSW",
                name: "LINK/USDT"
            },
            "LINK/USDC": {
                address: "7GZ59DMgJ7D6dfoJTpszPayTRyua9jwcaGJXaRMMF1my",
                name: "LINK/USDC"
            }
chatbox77 commented 4 years ago

Hi, @524119574 thanks. I created an account at https://www.sollet.io/

PublicKey is my wallet address. but what is the owner?

// Placing orders let owner = new Account('...'); let payer = new PublicKey('...'); // spl-token account

leofisG commented 4 years ago

I am not super sure about this part. You might find this code helpful.

My current understanding is the owner is your wallet public key.

chatbox77 commented 4 years ago

Hi, @524119574 thanks.

I use my account at https://www.sollet.io/

when i run this // Placing orders let owner = new Account('wallet public key'); let payer = new PublicKey('...'); // spl-token account

I got Error: bad secret key size at Function.nacl.sign.keyPair.fromSecretKey (/root/node_modules/tweetnacl/nacl-fast.js:2320:11) at new Account (/root/node_modules/@solana/web3.js/lib/index.cjs.js:341:61) at file:///root/serum/serum-js/index.js:30:13

Where could i config my own secret key?

nishadsingh1 commented 4 years ago

Hey! new Account(...) actually takes in your privatey key, not your public key. Be very careful handling it, but you can get it from the outfile that solana-keygen new ... creates

armaniferrante commented 3 years ago

This repository has moved to https://github.com/project-serum/serum-ts/tree/master/packages/serum. Please migrate this issue over, if desired.