0.2.0-alpha.0 • Published 4 days ago

@solworks/sujiko-sdk v0.2.0-alpha.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 days ago

Sujiko v1 Client Library

TypeScript client library for interacting with Sujiko v1.

Installation

Using npm:

npm install @solworks/sujiko-sdk

Using yarn:

yarn add @solworks/sujiko-sdk

Usage

  1. Initialise SDK
import { SDK, Decimal, Side } from "@solworks/sujiko-sdk";
import * as anchor from "@coral-xyz/anchor";
// set anchor provider
const provider = anchor.AnchorProvider.env();
// lazy build sdk
let sdk = await SDK.build({
    connection: provider.connection,
    wallet: provider.wallet
    // devnet: true             // use devnet program id
});
  1. Get markets
// fetch clearing house and markets list
let ch = await sdk.getClearingHouse();
let marketsList = await sdk.getMarketsList();
// pretty format clearing house
let clearingHouse = sdk.prettyFormat(
    ch, 
    marketsList,
    // true                     // excludes buffers
);
console.log(clearingHouse);
  1. Create user if not exists
// update with mint of Sujiko Warrior owned by user
let mint = new PublicKey("...");

// check if user exists
let user = await sdk.getUser(provider.wallet.publicKey);
// create user if not exists
if (!user) {
    await sdk.initializeUser(
        provider.wallet.publicKey,
        mint
    );
}
// get user
user = await sdk.getUser(provider.wallet.publicKey);
// pretty format user
let prettyUser = sdk.prettyFormatUser({ user: user!, filtered: true });
console.log(prettyUser);
  1. Deposit all collateral
// only usdc supported (collateralIndex = 0)
let collateralIndex = 0;

// get token account and balance
let ta = sdk.getTokenAccount(provider.wallet.publicKey, marketsList.collaterals[collateralIndex].mint);
let balance = await sdk.connection.getTokenAccountBalance(ta);

// deposit all
let toDeposit = Decimal.newScaled(balance.value.amount, marketsList.collaterals[collateralIndex].mintScale);
const sig = await sdk.deposit({
    owner: provider.wallet.publicKey,       // owner must = signer
    amount: toDeposit,                      // amount to deposit
    collateralIndex: collateralIndex,       // collateral index
    fromUserTokenAccount: ta,               // from user token account
});
console.log("sig", sig);
  1. Place trade
// place trade in MADSLADS-PERP market for 1 contract long
// NOTE: order is executed asynchronously + takes >=5 slots before being executed
const market = marketsList.markets.find(m => m.name === "MADSLADS-PERP")!;
const size = 1;                             // 1 contract (i.e. 1 MADSLADS-PERP)
const sig = await sdk.createOrder({
    owner: provider.wallet.publicKey,       // owner must = signer
    marketIndex: market.index,              // alternatively use 0 for MADSLADS-PERP
    orderType: OrderType.Market,            // only Market or TriggerMarket supported currently (case sensitive)
    side: Side.Buy,                         // one of Buy or Sell (case sensitive)
    size: Decimal.fromSize(size)            // size of order, do not scale when using fromSize
});
console.log("sig", sig);
0.2.0-alpha.0

4 days ago

0.1.43-dev.12

2 months ago

0.1.43-dev.11

2 months ago

0.1.43-dev.10

2 months ago

0.1.43-dev.8

2 months ago

0.1.43-dev.9

2 months ago

0.1.43-dev.4

2 months ago

0.1.43-dev.5

2 months ago

0.1.43-dev.6

2 months ago

0.1.43-dev.7

2 months ago

0.1.43-dev.2

2 months ago

0.1.43-dev.3

2 months ago

0.1.43-dev.1

2 months ago

0.1.43-dev

2 months ago

0.1.41

3 months ago

0.1.42

3 months ago

0.1.40

3 months ago

0.1.38

3 months ago

0.1.39

3 months ago

0.1.37

3 months ago

0.1.35

3 months ago

0.1.36

3 months ago

0.1.31

3 months ago

0.1.32

3 months ago

0.1.33

3 months ago

0.1.34

3 months ago

0.1.10

7 months ago

0.1.11

7 months ago

0.1.12

7 months ago

0.1.13

7 months ago

0.1.14

7 months ago

0.1.15

7 months ago

0.1.0

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.9

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.6

7 months ago

0.1.5

7 months ago

0.1.30

5 months ago

0.0.9-rc2

9 months ago

0.0.9-rc1

10 months ago

0.1.27

7 months ago

0.0.15

7 months ago

0.1.28

7 months ago

0.0.16

7 months ago

0.1.29

6 months ago

0.1.20

7 months ago

0.1.21

7 months ago

0.1.22

7 months ago

0.0.10

8 months ago

0.1.23

7 months ago

0.0.11

7 months ago

0.1.24

7 months ago

0.0.12

7 months ago

0.1.25

7 months ago

0.0.13

7 months ago

0.1.26

7 months ago

0.0.14

7 months ago

0.0.8-psi.r2

10 months ago

0.0.8-psi.r1

10 months ago

0.0.8-psi.r4

10 months ago

0.0.8-psi.r3

10 months ago

0.0.8-psi.r6

10 months ago

0.0.8-psi.r5

10 months ago

0.1.16

7 months ago

0.1.17

7 months ago

0.1.18

7 months ago

0.1.19

7 months ago

0.0.8-lambda

1 year ago

0.0.8-mu

1 year ago

0.0.8-tau

12 months ago

0.0.8-chi

11 months ago

0.0.8-kappa

1 year ago

0.0.8-iota

1 year ago

0.0.8-zeta

1 year ago

0.0.8-eta

1 year ago

0.0.8-omicron

12 months ago

0.0.8-sigma

12 months ago

0.0.8-nu

1 year ago

0.0.8-psi

11 months ago

0.0.8-theta

1 year ago

0.0.8-upsilon

12 months ago

0.0.8-rho

12 months ago

0.0.8-pi

12 months ago

0.0.8-phi

12 months ago

0.0.8-xi

1 year ago

0.0.8-epsilon

1 year ago

0.0.8-delta

1 year ago

0.0.8-gamma

1 year ago

0.0.8-beta

1 year ago

0.0.8-alpha

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago