0.0.14 • Published 8 months ago

omxjs v0.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

OMX typescript api

Typescript client for interacting with OMX contracts.

ReadTheDocs license npm npm

Installation

Requirements

npm i omxjs

Examples

Simple example of creating a position with the client:

import { OmxCwRouterClient, OmxCwVaultClient } from "omxjs";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";

// replace with the addresses of the contracts on your chain
const vaultAddress = "osmo1...";
const routerAddress = "osmo1...";
const osmoAddress = "osmo1...";

const ownAddress = "osmo1a..."; // replace with your address
const cwClient: SigningCosmWasmClient = ...; // create a client for the chain with signer you prefer

const vaultClient = new OmxCwVaultClient(cwClient, ownAddress, vaultAddress);
const routerClient = new OmxCwRouterClient(cwClient, ownAddress, routerAddress);

// In real world this should be the price from the oracle with 18 decimals precision
const priceInUsd = BigInt(1e18);

const amountIn = BigInt(100e6); // 100 uosmo
const leverage = 3n; // 3x leverage

// Add router to the vault
await vaultClient.addRouter({ router: routerAddress });

// Create position
await routerClient.increasePositionOsmo({
    collateral: {
        token: osmoAddress,
    },
    indexToken: osmoAddress,
    isLong: true,
    price: priceInUsd.toString(),
    minOut: "0",
    sizeDelta: (priceInUsd * leverage).toString(),
}, "auto", "", [{ denom: "uosmo", amount: amountIn.toString()}]);

// Check the position
const position = await vaultClient.position({
    account: ownAddress,
    indexToken: osmoAddress,
    collateralToken: osmoAddress,
    isLong: true,
});

console.log("position", position);

Code generation

Requirements

Generate code

npm i
# generate code for specific tag
npm run code-gen v0.0.12
0.0.12

8 months ago

0.0.13

8 months ago

0.0.14

8 months ago

0.0.11

8 months ago

0.0.10

9 months ago

0.0.7

10 months ago

0.0.5

10 months ago

0.0.3

10 months ago

0.0.2

11 months ago

0.0.1

11 months ago