serum-dev-tools/index.html

57 lines
16 KiB
HTML

<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@project-serum/serum-dev-tools</title><meta name="description" content="Documentation for @project-serum/serum-dev-tools"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@project-serum/serum-dev-tools</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@project-serum/serum-dev-tools </h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><div class="tsd-panel tsd-typography">
<a href="#serum-devtools-🛠️" id="serum-devtools-🛠️" style="color: inherit; text-decoration: none;">
<h1>Serum DevTools 🛠️</h1>
</a>
<p>A developer tooling SDK for building on <a href="https://github.com/project-serum/serum-dex/">serum-dex</a>.</p>
<a href="#prerequisites" id="prerequisites" style="color: inherit; text-decoration: none;">
<h2>Prerequisites</h2>
</a>
<p>You will need to use the <code>FileKeypair</code> class that extends the <a href="https://solana-labs.github.io/solana-web3.js/classes/Keypair.html"><code>Keypair</code></a> class from <a href="https://npmjs.com/package/@solana/web3.js"><code>@solana/web3.js</code></a> to provide easy file-based keypair management, which is required for the market making features provided by this package.</p>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">owner</span><span class="hl-1"> = </span><span class="hl-3">FileKeypair</span><span class="hl-1">.</span><span class="hl-4">generate</span><span class="hl-1">(</span><span class="hl-5">&quot;./scripts/keys/owner.json&quot;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">airdropSig</span><span class="hl-1"> = </span><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">connection</span><span class="hl-1">.</span><span class="hl-4">requestAirdrop</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">.</span><span class="hl-3">publicKey</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-7">10</span><span class="hl-1"> * </span><span class="hl-2">LAMPORTS_PER_SOL</span><span class="hl-1">,</span><br/><span class="hl-1">);</span><br/><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">connection</span><span class="hl-1">.</span><span class="hl-4">confirmTransaction</span><span class="hl-1">(</span><span class="hl-3">airdropSig</span><span class="hl-1">);</span>
</code></pre>
<p>You need to have a <a href="https://github.com/project-serum/serum-dex/">serum-dex</a> program deployed on the cluster you wish to interact with.</p>
<p>You can either,</p>
<ul>
<li><p>Use the <a href="https://github.com/project-serum/serum-dev-tools/tree/main/cli">serum-dev-tools CLI</a> to deploy the program.</p>
</li>
<li><p>use the already deployed <code>serum-dex</code> programs, <code>9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin</code> on <strong>mainnet-beta</strong> and <code>DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY</code> on <strong>devnet</strong>.</p>
</li>
</ul>
<a href="#get-started" id="get-started" style="color: inherit; text-decoration: none;">
<h2>Get Started</h2>
</a>
<pre><code><span class="hl-3">yarn</span><span class="hl-1"> </span><span class="hl-3">add</span><span class="hl-1"> @</span><span class="hl-3">project</span><span class="hl-1">-</span><span class="hl-3">serum</span><span class="hl-1">/</span><span class="hl-3">serum</span><span class="hl-1">-</span><span class="hl-3">dev</span><span class="hl-1">-</span><span class="hl-3">tools</span>
</code></pre>
<a href="#initialize-a-dex" id="initialize-a-dex" style="color: inherit; text-decoration: none;">
<h3>Initialize a <code>Dex</code></h3>
</a>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">connection</span><span class="hl-1"> = </span><span class="hl-0">new</span><span class="hl-1"> </span><span class="hl-4">Connection</span><span class="hl-1">(</span><span class="hl-5">&quot;http://localhost:8899&quot;</span><span class="hl-1">, </span><span class="hl-5">&quot;confirmed&quot;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">dexAddress</span><span class="hl-1"> = </span><span class="hl-0">new</span><span class="hl-1"> </span><span class="hl-4">PublicKey</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-5">&quot;7zo7HCQAZPRb4pYiQQ6fLjC8ssN3E8LkavVs8JUA5NMn&quot;</span><span class="hl-1">,</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">dex</span><span class="hl-1"> = </span><span class="hl-0">new</span><span class="hl-1"> </span><span class="hl-4">Dex</span><span class="hl-1">(</span><span class="hl-3">dexAddress</span><span class="hl-1">, </span><span class="hl-3">connection</span><span class="hl-1">);</span>
</code></pre>
<a href="#create-coin-instances-for-your-market" id="create-coin-instances-for-your-market" style="color: inherit; text-decoration: none;">
<h3>Create <code>Coin</code> instances for your <code>Market</code></h3>
</a>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">baseCoin</span><span class="hl-1"> = </span><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">dex</span><span class="hl-1">.</span><span class="hl-4">createCoin</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-5">&quot;SAYA&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-7">9</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">quoteCoin</span><span class="hl-1"> = </span><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">dex</span><span class="hl-1">.</span><span class="hl-4">createCoin</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-5">&quot;SRM&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-7">9</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">,</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-8">// Fund the FileKeypair object to place orders.</span><br/><br/><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">baseCoin</span><span class="hl-1">.</span><span class="hl-4">fundAccount</span><span class="hl-1">(</span><span class="hl-7">1000000</span><span class="hl-1">, </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">, </span><span class="hl-3">connection</span><span class="hl-1">);</span><br/><br/><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">quoteCoin</span><span class="hl-1">.</span><span class="hl-4">fundAccount</span><span class="hl-1">(</span><span class="hl-7">2000000</span><span class="hl-1">, </span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">, </span><span class="hl-3">connection</span><span class="hl-1">);</span>
</code></pre>
<a href="#initialize-a-market" id="initialize-a-market" style="color: inherit; text-decoration: none;">
<h3>Initialize a <code>Market</code></h3>
</a>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">market</span><span class="hl-1"> = </span><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-3">dex</span><span class="hl-1">.</span><span class="hl-4">initDexMarket</span><span class="hl-1">(</span><span class="hl-3">owner</span><span class="hl-1">.</span><span class="hl-3">keypair</span><span class="hl-1">, </span><span class="hl-3">baseCoin</span><span class="hl-1">, </span><span class="hl-3">quoteCoin</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-3">lotSize:</span><span class="hl-1"> </span><span class="hl-7">1e-3</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">tickSize:</span><span class="hl-1"> </span><span class="hl-7">1e-2</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code></pre>
<a href="#run-a-market-maker" id="run-a-market-maker" style="color: inherit; text-decoration: none;">
<h3>Run a Market Maker</h3>
</a>
<pre><code class="language-javascript"><span class="hl-3">dex</span><span class="hl-1">.</span><span class="hl-4">runMarketMaker</span><span class="hl-1">(</span><span class="hl-3">market</span><span class="hl-1">, </span><span class="hl-3">owner</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-3">durationInSecs:</span><span class="hl-1"> </span><span class="hl-7">30</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">orderCount:</span><span class="hl-1"> </span><span class="hl-7">3</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">initialBidSize:</span><span class="hl-1"> </span><span class="hl-7">1000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">baseGeckoSymbol:</span><span class="hl-1"> </span><span class="hl-5">&quot;solana&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">quoteGeckoSymbol:</span><span class="hl-1"> </span><span class="hl-5">&quot;usd&quot;</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code></pre>
<a href="#run-a-crank" id="run-a-crank" style="color: inherit; text-decoration: none;">
<h3>Run a crank</h3>
</a>
<pre><code class="language-javascript"><span class="hl-3">dex</span><span class="hl-1">.</span><span class="hl-4">runCrank</span><span class="hl-1">(</span><span class="hl-3">market</span><span class="hl-1">, </span><span class="hl-3">owner</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-3">durationInSecs:</span><span class="hl-1"> </span><span class="hl-7">20</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">verbose:</span><span class="hl-1"> </span><span class="hl-0">true</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code></pre>
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/Coin.html" class="tsd-kind-icon">Coin</a></li><li class="tsd-kind-class"><a href="classes/Dex.html" class="tsd-kind-icon">Dex</a></li><li class="tsd-kind-class"><a href="classes/DexMarket.html" class="tsd-kind-icon">Dex<wbr/>Market</a></li><li class="tsd-kind-class"><a href="classes/FileKeypair.html" class="tsd-kind-icon">File<wbr/>Keypair</a></li><li class="tsd-kind-interface"><a href="interfaces/MarketAccounts.html" class="tsd-kind-icon">Market<wbr/>Accounts</a></li><li class="tsd-kind-type-alias"><a href="modules.html#CrankOpts" class="tsd-kind-icon">Crank<wbr/>Opts</a></li><li class="tsd-kind-type-alias"><a href="modules.html#MarketMakerOpts" class="tsd-kind-icon">Market<wbr/>Maker<wbr/>Opts</a></li><li class="tsd-kind-type-alias"><a href="modules.html#MarketParams" class="tsd-kind-icon">Market<wbr/>Params</a></li><li class="tsd-kind-type-alias"><a href="modules.html#MessageType" class="tsd-kind-icon">Message<wbr/>Type</a></li><li class="tsd-kind-type-alias"><a href="modules.html#OrderType" class="tsd-kind-icon">Order<wbr/>Type</a></li><li class="tsd-kind-type-alias"><a href="modules.html#SelfTradeBehaviour" class="tsd-kind-icon">Self<wbr/>Trade<wbr/>Behaviour</a></li><li class="tsd-kind-type-alias"><a href="modules.html#TransactionWithSigners" class="tsd-kind-icon">Transaction<wbr/>With<wbr/>Signers</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>