Project Serum Rust Monorepo

Overview

serum-dex

Project Serum Rust Monorepo

Build Status Discord Chat License

Website | Discord | Awesome | DEX | TypeScript

Program Deployments

Program Devnet Mainnet Beta
DEX DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin

Note

  • Serum is in active development so all APIs and protocols are subject to change.
  • The code is unaudited. Use at your own risk.

Contributing

Install Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup component add rustfmt

On Linux systems you may need to install additional dependencies. On Ubuntu,

sudo apt-get install -y pkg-config build-essential python3-pip jq

Install Solana

Directions can be found here.

Download the source

git clone https://github.com/project-serum/serum-dex.git

Build, deploy, and test programs

See individual crates for documentation. For example, to build the dex see its README.

Running a local Solana cluster

The easiest way to run a local cluster is to use solana-test-validator.

Directories

  • assert-owner: Solana utility program for checking account ownership.
  • common: Common rust utilities.
  • dex: Serum DEX program and client utility.
  • pool: Serum pool protocol.
  • scripts: Bash scripts for development.
Comments
  • Export MarketState and Slab functions to read bid/ask data on-chain

    Export MarketState and Slab functions to read bid/ask data on-chain

    The serum_dex package has helper functions for reading bid/ask data from the slab tree, but some of them are not public. This PR makes these functions and associated structs and enums public. Not a breaking change.

    Is it useful? Yes. We need these functions in production.

    Edit: more functions from critbit.rs made public.

    opened by secretshardul 6
  • Pubkey seeds

    Pubkey seeds

    hi i want to initialize a market but the function gets many pubkeys that i dont know how to create them

    pub fn initialize_market(
        market: &Pubkey,
        program_id: &Pubkey,
        coin_mint_pk: &Pubkey,
        pc_mint_pk: &Pubkey,
        coin_vault_pk: &Pubkey,
        pc_vault_pk: &Pubkey,
        authority_pk: Option<&Pubkey>,
        prune_authority_pk: Option<&Pubkey>,
        consume_events_authority_pk: Option<&Pubkey>,
        // srm_vault_pk: &Pubkey,
        bids_pk: &Pubkey,
        asks_pk: &Pubkey,
        req_q_pk: &Pubkey,
        event_q_pk: &Pubkey,
        coin_lot_size: u64,
        pc_lot_size: u64,
        vault_signer_nonce: u64,
        pc_dust_threshold: u64,
    )
    

    I need to create them to pass them to this function, spl-associated-token-address has a format for seeds to generate pubkeys. is there any function which could generate these pubkeys?

    opened by saman-pasha 4
  • settle_funds return 0 usdt to my address

    settle_funds return 0 usdt to my address

    sol address:7ewn8oj7MWyhZE5qFux1npzUnuT4XCVvBvYiMHehYvBb usdt address:8pkzuX9GjrgEFuX4JXQeV4hcSjwTba59yC92vSfbz45H fida address:4BCnuuQXHXEMiUVYYA7mw2Jc5AyX5q1FcTRDmvnV9uDR

    i submit an order https://explorer.solana.com/tx/522X9qN66UMbSoLk5Sry9iRcm9zFFoaR1M34qysJSedtCQ5893ofNhxx61uaqnRxj4b8cadfXH4YEM1BV1Bd3WKP , then i've cancelled it twice , not sure why.. https://explorer.solana.com/tx/54GUkmszRxT9g8T9GFL2PZRyi8Z6PDKzmT5STkVVbGcHoQRgRNC6HUeChTuggKDdmFsn1GM6WLHrbx3MeQJVAHfZ and https://explorer.solana.com/tx/46XJr3zDs94tmDNgjXHhQJTYFQfPnjyKKrzrRtYcWYNJ9672zEiv9XxZZsmuHj2h3N1fnNVfMA5po8K1QLe1zhvb

    then not sure what i did there when i've tried to settle_my funds https://explorer.solana.com/tx/2ph3m68QKaxjyyk2SmBQ2m2j6XF7ksYjMiz9hVo9eo5toKhPopQRj8XT6AA8AdPUXBNEo39cy5zf91WHYC8i2WMS

    open_orders_account = market.find_open_orders_accounts_for_owner(owner_address=PublicKey('7ewn8oj7MWyhZE5qFux1npzUnuT4XCVvBvYiMHehYvBb')) but when i do now settle_fundsit sends me 0 usdt back all the time https://explorer.solana.com/tx/36Rca4VQQe7dodh2VTavXRTPJZGQuknhc4wRt4ST2s8GgQijbFJKwmoDsxgBJnHYrutKQzzCuQtuRc41mfPzUSeZ and https://explorer.solana.com/tx/4gJyqXLH7Xr4XcfwsTjgbjDbFBasHhQjaPjBwkxAk8Cd9hU92xqUHgw2sbRGcP3KonCrFu3PFADF6CoE5PYLHFa4 image

    please dm me on dicord cryptoguy100786#0098

    how to get my usdt from of https://explorer.solana.com/address/Dygr7hmVgydf6Cs4CF34EbXbD8xhJJVMXjvYJCR7LqmM ? thanks

    opened by cryptoalert15 4
  • Tokens remain in Vault after SettleFunds is executed

    Tokens remain in Vault after SettleFunds is executed

    I am writing a client (in Rust) to interact with Serum. When testing@devnet it (a simple case when two participants place Asks / Bids orders with an exchange rate of 1:1), I encountered a problem that the Ask side funds (pc token) are not returned to the account even after the SettleFunds instruction has been executed. In this case, the proceeds from the sale of coin tokens pc tokens are stored in the vault. Thus, for payer / wallet # 1 we have the following balance (after order execution and SettleFunds) -1 coin, for payer / wallet # 2: -1 pc, +1 coin.

    P.S> Do you plan to develop a client library for Rust (similar to serum-ts) ?

    Before order placement

    image image

    State after orders execution and SettleFunds

    image

    SettleFunds logs for payer#1

    image

    SettleFunds logs for payer#2

    image

    Vault

    image

    Market Info
    own_address:    7KH444DFaHsnJECWhmLe3VYhqSn8XY2RtxPrsLS92rhS
    coin_mint:      9ZpZqwJfDQzppXkazKBTqNFW1z4rLL9wxbkbhPbWTb3n
    pc_mint:        G5JuS6p1TX7P3dz2DhiQ1L1exERem6Ayn5ZwqXx29dkn
    coin_vault:     8h8yreygpuRiwqhRwzGFNdrNT7P9qx9f9HADyzxZrJvY
    pc_vault:       HiX9rBut3LU5P3GwT2aR8uC1co6gKRjM5UYtcPZHca7j
    req_q:          EXeDheqgB8dQLN7NYrUn6zwm6Cg6Z21LLXxb9xvWRfTR
    event_q:        FR6Gn5HHNG8i4au62ec7hA1RnsBSXS1SMFCiTtKj6qdq
    bids:           5Fm4HGTVeRsttjM3oSPVuyUq5awLdbTT5UtpmCwMghwM
    asks:           CamnzxFGMKCszpUgHsYipHh9YTag3TeXSWtnqvqiDdn8
    coin_lot_size:  100000
    pc_lot_size:    100
    pc_decimal:     9
    coin_decimal:   9
    
    Payers/wallet Info
    wallet #1 addres: BXhe2cKFT6UEF5gLiHCDJnqQVxyKVsjnH95m3AaCDCRc
    wallet #1 pc addres: 3dhhuqUTq2oQxh4Lhz1zyeJoUnip31LWUK6sWvccyptL
    wallet #1 coin addres: 5f9UiFcVPnK1u2k9sHW4Qqx6kesbpBLrVfSBCRujK5h6
    
    wallet #2 addres: 857hQyZViutfWSSUj5HL1oxJP5goBHTvzAMNWCQpg9Z7
    wallet #2 pc addres: 2UiNCsmECibXM4AW7ePGe7zFQkxoAtfGsGWX6jn6iuRU
    wallet #2 coin addres: CSYU2V943K4ZPEvwLRZvPDaFumVjaZ4Sht3UKe3WNy5o
    
    Additional Info

    image

    opened by PraetorP 3
  • Funds lost during SBR/USDC transaction

    Funds lost during SBR/USDC transaction

    Hi there,

    Everything looks fine at transaction level, however at the last step when USDC should be deposited nothing happened.

    https://solscan.io/tx/redacted

    opened by romanzac 3
  • What does `[u64; 4]` mean?

    What does `[u64; 4]` mean?

    Several structs use the type [u64; 4] for what I suspect is the public key. For instance in MarketState and LeafNode.

    pub struct MarketState {
        // 0
        pub account_flags: u64, // Initialized, Market
    
        // 1
        pub own_address: [u64; 4],
    
        // 5
        pub vault_signer_nonce: u64,
        // 6
        pub coin_mint: [u64; 4],
        // 10
        pub pc_mint: [u64; 4],
    
        // 14
        pub coin_vault: [u64; 4],
        
    
    pub struct LeafNode {
        tag: u32,
        owner_slot: u8,
        fee_tier: u8,
        padding: [u8; 2],
        key: u128,
        owner: [u64; 4],
        quantity: u64,
        client_order_id: u64,
    }
    

    My use case is specifically to:

    1. check if a market's coin_mint matches the address of a program account; and to
    2. find public key used for placing a serum order, from owner field in LeafNode.
    opened by secretshardul 3
  • Enable Loading Bids And Asks Via External Packages

    Enable Loading Bids And Asks Via External Packages

    The functions in this PR when made public allow you to calculate orderbook pricing via external crates. This should address the concerns pointed out in https://github.com/project-serum/serum-dex/pull/106#issuecomment-825077598

    edit:

    When I attempted to build the codebase with cargo build after i made the change, Cargo.lock was updated automatically so I included it with the last commit. Let me know if I should remove this.

    opened by bonedaddy 3
  • Mark Various Functions, And Enums Public For On-Chain Price Calculations

    Mark Various Functions, And Enums Public For On-Chain Price Calculations

    Overview

    While attempting to get various bid/ask prices on-chain through CPI I ran into a few different issues due to various functions and enums not being marked as public. As far as I can tell the updated visibilities I have included in this repo are all that is needed to access this information on-chain through other programs.

    opened by bonedaddy 3
  • Forked borsh crate needs to rebase onto v0.8.1

    Forked borsh crate needs to rebase onto v0.8.1

    Hi! I'm an engineer from solana. :)

    To make long story short, could you update your forked borsh crate to be rebased onto borsh-rs v0.8.1?

    We noticed updating serde to v1.0.122 at the solana monorepo would break serum-dex build: https://buildkite.com/solana-labs/solana/builds/38795#a018ae71-7d4c-4dc2-a9a9-fab840bcd3ef/1360-1834. Don't worry. We won't do that soon. This is just maintenance update at our side. :)

    If there is better way for you like bumping solana-program and/or spl, please let us know.

    Details

    Well, there are various crates involved.

    Firstly, solana-program crates use serde. And serde v1.0.122 now depends on syn >= v1.0.60 specifically and it broke build of borsh-rs < v0.8.0: https://github.com/near/borsh-rs/issues/2 (this pr should be in borsh-rs v0.8.0)

    Then, serum-dex uses both solana-program and borsh-rs, which would be unable to build with conflicting versions.

    https://github.com/project-serum/serum-dex/blob/d47058600c3ba8ffe83669ebca1e50c49f780dc5/pool/Cargo.toml#L20

    https://github.com/project-serum/serum-dex/blob/d47058600c3ba8ffe83669ebca1e50c49f780dc5/Cargo.lock#L238-L275

    These changes seems to be introduced by this pr: https://github.com/project-serum/serum-dex/pull/51

    Also, it seems that you're also pinning syn at forked branch: https://github.com/project-serum/borsh/blob/90fcdf51f4c0333002a00a2db7367cc672882dc5/borsh-rs/borsh-derive-internal/Cargo.toml#L17

    by this commit https://github.com/project-serum/borsh/pull/1/commits/884c56711c732d172f5d65374feff1fb796d4841

    It may become unnecessary?

    Also, updated borsh-rs isn't pinning syn it seems: https://github.com/near/borsh-rs/blob/3dddc6d7af2e66bf4f5947c0187a9d1f7dae6888/borsh-schema-derive-internal/Cargo.toml#L16

    So, I'm thinking you can just update borsh-rs to v0.8.1, considering it's not pinning syn version: https://crates.io/crates/borsh-derive-internal/0.8.1

    (A bit odd thing is that it seems spl succeeded to build with syn v1.0.60 and it seems pinning syn isn't working in your repository for some reason...)

    CC: @armaniferrante (mentioning based on relevant commit's author info, nice to meet you!), @mvines (my dependable rust dependency-hell solving expert.)

    opened by ryoqun 3
  • Invalid param: could not find mint

    Invalid param: could not find mint

    I'm working localnet . I have this error.
    failed to get token accounts owned by account acSUiwT9cCe4hfaYNATdodj8iJJ3bvmWZyeTBNQmD8S: Invalid param: could not find mint

    acSUiwT9cCe4hfaYNATdodj8iJJ3bvmWZyeTBNQmD8S = my Solletio solana address

    opened by oznfc 3
  • Lower fees as voted plz

    Lower fees as voted plz

    Special fee tier for stable needs more thinking so this should come later.

    https://dao.projectserum.com/#/proposal/7GxS9nEc4ZiTjgSpTxg7JnsJXfyayoJocSdzAj5PmWR8?programId=AVoAYTs36yB5izAaBkxRG67wL1AMwG3vo41hKtUSb8is

    opened by Arrowana 2
  • Spillover when converting from USDC/USDT to another token

    Spillover when converting from USDC/USDT to another token

    When I try to do a swap on Serum from USDC/USDT to some other token, I’ve noticed that there is some spillover. Here are some transactions that showcase this behavior:

    3YS8Skg4sSX92Fc4PkXXdhfvskoATNoN1r5eLjgYX6245NJg1HwSVzUM6d4AD8LVa6W9fabJZ79vJWsLY8AZ67CE

    Here, I could have received up to 0.17 SOL but only get 0.1 SOL and the rest is returned.

    5oDj65D2UDuxq7d8fmGzuxN7fKheQ6taw3mxjXUzj8dPbc57PGS23vbTELmVxk9dfsg9gYzJ7eys6CLRYVqe29Ni

    Similarly, here I could have received up to 0.35 SOL but only got 0.3 SOL.

    What is the reason for this truncation in the output balance? By the way, this only happens if you exchange the USDC to SOL. If you convert SOL to USDC, you see no such spillover e.g.

    4trewrpt1Ns6smDy7xVS1XEkBC9qqStA6pQabpGnazR93sVYtDvG9o379Ua2A8arh52xQSy7yhexRVxCZ6Q58ntn

    opened by amerfarooq 0
  • Comply with Art. 15 GDPR Right of access by the data subject

    Comply with Art. 15 GDPR Right of access by the data subject

    Please outline and provide tooling to retrieve all filled orders for a certain wallet address and market. All the UIs on the market only display recent data. This becomes a legal issue for traders that have to fulfill tax obligations. As the Serum program is developed, maintained and brought to the blockchain by you guys I expect some responsibility here and comply with minimum standards of any financial application. Sorry to be so blunt but I see enormous activity for launching new partnerships etc. but nothing for the accounting part.

    opened by gitmalong 5
  • adds fix to build errors

    adds fix to build errors

    Upon building dex using the command cargo build-bpf --manifest-path=./Cargo.toml --bpf-out-dir=dist, I get the error

    error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
       --> src/lib.rs:375:20
        |
    375 |     StdoutLock(io::StdoutLock<'a>),
        |                    ^^^^^^^^^^---- help: remove these generics
        |                    |
        |                    expected 0 lifetime arguments
    
    error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
       --> src/lib.rs:376:20
        |
    376 |     StderrLock(io::StderrLock<'a>),
        |                    ^^^^^^^^^^---- help: remove these generics
        |                    |
        |                    expected 0 lifetime arguments
    
    For more information about this error, try `rustc --explain E0107`.
    error: could not compile `termcolor` due to 2 previous errors
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    

    This is fixed by bumping up the solana-program version from 1.6.18 to 1.11

    opened by saad039 0
  • Request to deploy assert-owner program on testnet and devnet

    Request to deploy assert-owner program on testnet and devnet

    Hi, token transfers on devnet and testnet are failing on Phantom and Sollet wallets because they rely on the assert-owner program to be present.

    More info: https://solana.stackexchange.com/questions/359/which-program-is-this-4mnpdku9wfmveezbmt3eipfs5ovvwtjb31pexdjaaxx5

    Could you please deploy the assert-owner program with the same pubkey as mainnet, on devnet and testnet as well?

    Thanks in advance.

    opened by itsfarseen 0
  • `CancelOrderByClientIdV2` API should take `NonZeroU64` and not `u64`.

    `CancelOrderByClientIdV2` API should take `NonZeroU64` and not `u64`.

    The instruction accepts an u64: https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/instruction.rs#L434 despite it being casted to a NonZeroU64 internally: https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/state.rs#L2127

    which means that an order with client id of 0 can not be cancelled (raising an assertion error).

    This is also an issue for the CancelOrdersByClientIds instruction, worst yet it silently filters away the 0 id order: https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/state.rs#L2190-L2194

    Causing confusing errors like insufficient funds.

    opened by tommyip 0
Releases(v0.5.6)
Joystream Monorepo

Joystream This is the main code repository for all Joystream software. In this mono-repo you will find all the software required to run a Joystream ne

Joystream 152 Dec 28, 2022
Subspace Monorepo

Subspace Network Monorepo This is a mono repository for Subspace Network implementation, primarily containing Subspace node/client using Substrate fra

subspace 182 Dec 24, 2022
Monorepo of our ahead-of-time implementation of Secure ECMAScript

Ahead-of-time Secure EcmaScript The monorepo contains a set of packages that helps adopt SES in a pre-compiled way. Security Assumptions This project

Dimension 13 Dec 21, 2022
A monorepo containing all the custom components of the Astria network

A monorepo containing all the custom components of the Astria network, a decentralized system that replaces traditional sequencers, offering a shared, permissionless sequencer network.

Astria 6 Jun 7, 2023
Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

Akhil Sharma 2 Dec 20, 2022
A Rust port of the password primitives used in Django Project.

Rust DjangoHashers A Rust port of the password primitives used in Django Project. Django's django.contrib.auth.models.User class has a few methods to

Ronaldo Ferreira 52 Nov 17, 2022
A prototype project integrating jni rust into Kotlin and using protobuf to make them work together

KotlinRustProto a prototype project integrating jni rust into Kotlin and using protobuf to make them work together How to start add a RPC call in Droi

woo 11 Sep 5, 2022
A Rust port of the password primitives used in Django Project.

Rust DjangoHashers A Rust port of the password primitives used in Django Project. Django's django.contrib.auth.models.User class has a few methods to

Ronaldo Ferreira 52 Nov 17, 2022
A library to help you sew up your Ethereum project with Rust and just like develop in a common backend

SewUp Secondstate EWasm Utility Program, a library helps you sew up your Ethereum project with Rust and just like development in a common backend. The

Second State 48 Dec 18, 2022
Project generator written in Rust :crab:

C.R.S. Create a new project from a template Why another project generator ? It's inspired of cookiecutter (#20). It's written in rust for safety and r

0xMRTT 3 Nov 11, 2022
Rust starter project for building CLI and libraries, with great CI

Using the starter project: find where bumblefoot is and replace it with the name of your project. $ rg bumblefoot This is a dual library and binary pr

Rusty Ferris Club 19 Nov 19, 2022
A template for your next Rust project.

Opinionated Rust Template A template for your next Rust project. To start coding run: cargo generate tomkarw/opinionated-rust-template Only requires j

Tom Karwowski 8 Dec 1, 2022
Initial project for using Rust on the Nintendo 64.

N64 Project Template for Rust This repo is intended to be a starting point for developing software for the Nintendo 64 console using Rust. Only the ba

null 4 Oct 26, 2023
Temporary edit external crates that your project depends on

rhack You want to quickly put a sneaky macro kind of like dbg! into external crates to find out how some internal data structure works? If so rhack is

Ryo Nakao 119 Nov 3, 2022
Source project for the Internet Computer software

The Internet Computer is the world’s first blockchain that runs at web speed and can increase its capacity without bound. Like the Internet (which is composed of many machines adhering to TCP/IP protocol) and blockchain protocols (such as Bitcoin and Ethereum).

DFINITY 1.2k Jan 1, 2023
HyperCube is a free and open source blockchain project for everyone to use.

XPZ Public Chain HyperCube is a free and open source blockchain project for everyone to use. 日本語 简体中文 正體中文 HyperCube Wiki Wha is HyperCube HyperCube i

null 949 Dec 31, 2022
This is the Repo used to learn blockchain development in conjusction with the CyberGen NFT Project.

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

null 1 Nov 3, 2021
Terra Trophies is a copy of Ethereum's POAP project for Terra

Terra Trophies Terra Trophies is a copy of Ethereum's POAP project for Terra. It allows anyone to create digital badges for participants of events, or

larry.{ust,sol,thor} 18 Dec 7, 2022
Secret contract for Anons project.

Snip-721 Protocal by Baedrik template with several edits Minting Limits mint() caps tokens max at 580 mint() will keep count of how many anons each ad

Stake or Die 14 Jul 9, 2022