Skip to content

Commit

Permalink
Rebase serum-js
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Nov 15, 2020
1 parent b6c49b8 commit ff6688a
Show file tree
Hide file tree
Showing 108 changed files with 5,378 additions and 10,435 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"rules": {
"no-constant-condition": ["error", { "checkLoops": false }],
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-empty-function": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off"
}
Expand Down
20 changes: 4 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# dependencies
node_modules

# builds
build
dist
lib
.rpt2_cache

# misc
node_modules/
build/
dist/
lib/
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
*~
.idea

npm-debug.log*
yarn-debug.log*
yarn-error.log*
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- 12
- 10
node_js: 12
dist: bionic
cache: yarn
before_script:
- yarn build
File renamed without changes.
159 changes: 74 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,87 @@
[![npm (scoped)](https://img.shields.io/npm/v/@project-serum/serum)](https://www.npmjs.com/package/@project-serum/serum)
[![Build Status](https://travis-ci.com/project-serum/serum-js.svg?branch=master)](https://travis-ci.com/project-serum/serum-js)
<div align="center">
<img height="170" src="http://github.com/project-serum/awesome-serum/blob/master/logo-serum.png?raw=true" />

<h1>serum-ts</h1>

<p>
<strong>Project Serum Monorepo</strong>
</p>

<p>
<a href="https://travis-ci.com/project-serum/serum-ts"><img alt="Build Status" src="https://travis-ci.com/project-serum/serum-ts.svg?branch=master" /></a>
<a href="https://discord.com/channels/739225212658122886"><img alt="Discord Chat" src="https://img.shields.io/discord/739225212658122886?color=blueviolet" /></a>
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="License" src="https://img.shields.io/github/license/project-serum/serum-dex?color=blue" /></a>
</p>

<h4>
<a href="https://projectserum.com/">Website</a>
<span> | </span>
<a href="https://serum-academy.com/en/">Academy</a>
<span> | </span>
<a href="https://github.com/project-serum/awesome-serum">Awesome</a>
<span> | </span>
<a href="https://dex.projectserum.com/#/">DEX</a>
<span> | </span>
<a href="https://github.com/project-serum/serum-dex">Rust</a>
</h4>
</div>

## Packages

| Package | Version | Description |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| [`@project-serum/borsh`](/packages/borsh) | [![npm](https://img.shields.io/npm/v/@project-serum/borsh.svg)](https://www.npmjs.com/package/@project-serum/borsh) | Borsh serialization primitives |
| [`@project-serum/common`](/packages/common) | [![npm](https://img.shields.io/npm/v/@project-serum/common.svg)](https://www.npmjs.com/package/@project-serum/common) | Common utilities |
| [`@project-serum/serum`](/packages/serum) | [![npm](https://img.shields.io/npm/v/@project-serum/tokens.svg)](https://www.npmjs.com/package/@project-serum/tserum) | Library for interacting with the Serum DEX |
| [`@project-serum/lockup`](/packages/lockup) | [![npm](https://img.shields.io/npm/v/@project-serum/lockup.svg)](https://www.npmjs.com/package/@project-serum/lockup) | Client for interacting with the Lockup Program |
| [`@project-serum/pool`](/packages/pool) | [![npm](https://img.shields.io/npm/v/@project-serum/pool.svg)](https://www.npmjs.com/package/@project-serum/pool) | Client for interacting with Pools |
| [`@project-serum/registry`](/packages/registry) | [![npm](https://img.shields.io/npm/v/@project-serum/registry.svg)](https://www.npmjs.com/package/@project-serum/registry) | Client for interacting with the Registry Program |
| [`@project-serum/swap`](/packages/swap) | [![npm](https://img.shields.io/npm/v/@project-serum/swap.svg)](https://www.npmjs.com/package/@project-serum/swap) | Client for interacting witht the Swap Program |
| [`@project-serum/tokens`](/packages/tokens) | [![npm](https://img.shields.io/npm/v/@project-serum/tokens.svg)](https://www.npmjs.com/package/@project-serum/tokens) | Solana token addresses |

## Contributing

### Installing

To get started first install the required build tools:

# Serum JS Client Library
```
npm install -g lerna
npm install -g yarn
```

JavaScript client library for interacting with the Project Serum DEX.
Then bootstrap the workspace:

## Installation
```
yarn
```

Using npm:
### Building

To build the workspace:

```
npm install @solana/web3.js @project-serum/serum
yarn build
```

Using yarn:
### Testing

To run all tests:

```
yarn add @solana/web3.js @project-serum/serum
yarn test
```

## Usage

```js
import { Account, Connection, PublicKey } from '@solana/web3.js';
import { Market } from '@project-serum/serum';

let connection = new Connection('https://testnet.solana.com');
let marketAddress = new PublicKey('...');
let market = await Market.load(connection, marketAddress);

// Fetching orderbooks
let bids = await market.loadBids(connection);
let asks = await market.loadAsks(connection);
// L2 orderbook data
for (let [price, size] of bids.getL2(20)) {
console.log(price, size);
}
// Full orderbook data
for (let order of asks) {
console.log(
order.orderId,
order.price,
order.size,
order.side, // 'buy' or 'sell'
);
}

// 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'
});

// Retrieving open orders by owner
let myOrders = await market.loadOrdersForOwner(connection, owner.publicKey);

// Cancelling orders
for (let order of myOrders) {
await market.cancelOrder(connection, owner, order);
}

// Retrieving fills
for (let fill of await market.loadFills(connection)) {
console.log(
fill.orderId,
fill.price,
fill.size,
fill.side,
);
}

// Settle funds
for (let openOrders of await market.findOpenOrdersAccountsForOwner(
connection,
owner.publicKey,
)) {
if (openOrders.baseTokenFree > 0 || openOrders.quoteTokenFree > 0) {
// spl-token accounts to which to send the proceeds from trades
let baseTokenAccount = new PublicKey('...');
let quoteTokenAccount = new PublicKey('...');

await market.settleFunds(
connection,
owner,
openOrders,
baseTokenAccount,
quoteTokenAccount,
);
}
}
### Linting

To lint:

```
yarn lint
```

To apply lint fixes:

```
yarn lint:fix
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions migrate/.editorconfig

This file was deleted.

10 changes: 0 additions & 10 deletions migrate/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions migrate/.travis.yml

This file was deleted.

86 changes: 0 additions & 86 deletions migrate/README.md

This file was deleted.

Loading

0 comments on commit ff6688a

Please sign in to comment.