npm package: @nemoprotocol/nemo-sdk
Description: Lightweight TypeScript SDK for building NEMO transactions and queries on Sui.
Latest version: 0.6.2

## NEMO Protocol SDK

Lightweight TypeScript SDK for building NEMO transactions and queries on Sui.

### Installation

```bash
pnpm add @nemoprotocol/nemo-sdk
# or
npm i @nemoprotocol/nemo-sdk
# or
yarn add @nemoprotocol/nemo-sdk
```

### Quick Start: Mint LP

Mint LP using the high-level `Market` API. The config is resolved from the public API using a `marketStateId`.

```typescript
import { Transaction } from "@mysten/sui/transactions";
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { Market } from "@nemoprotocol/nemo-sdk";

async function main() {
  // 1) Create tx and resolve Market via API
  const tx = new Transaction();
  const marketStateId = "0x..."; // replace with a real Market state id
  const market = await Market.fromMarketState(tx, marketStateId);

  // 2) Prepare inputs (must be real on-chain objects/ids owned by the sender)
  const syCoin = tx.object("0x...");       // SY coin object to deposit
  const ptAmount = tx.object("0x...");     // PT coin object (paired with SY)
  const pyPosition = tx.object("0x...");   // Your PY position object id

  // 3) Build the mint_lp call on the tx
  const { result: lpCoin } = await market.market.mintLp(
    syCoin,
    ptAmount,
    "950000000",  // min LP amount (base units)
    pyPosition
  );

  // 4) Sign & execute
  const client = new SuiClient({ url: getFullnodeUrl("mainnet") });
  // const keypair = ... // load your Ed25519 keypair
  // const resp = await client.signAndExecuteTransaction({ signer: keypair, transaction: tx });
  // console.log("txDigest:", resp.digest);
}

main().catch(console.error);
```

Notes:
- `mintLp` automatically fetches a price voucher via the Oracle module.
- Prefer manual config? Use `buildMarketConfigFromApi(marketStateId)` and `new Market(tx, config)`.

### Quick Start: Get SY and Mint PY from SY

The flow below shows how to get SY (via SY providers) and then mint PY from SY using `PyManager`.

```typescript
import { Transaction } from "@mysten/sui/transactions";
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { SyManager, PyManager } from "@nemoprotocol/nemo-sdk";

async function main() {
  const tx = new Transaction();
  const marketStateId = "0x..."; // replace with a real Market state id

  // 1) Get SY by depositing underlying via SyManager
  const syManager = await SyManager.fromMarketState(tx, marketStateId);
  const underlyingCoin = tx.object("0xunderlying-coin-object-id");
  const { result: syCoin } = await syManager.depositToSy({
    coin: underlyingCoin,
  });

  // 2) Initialize a new PY position and mint PY from SY
  const py = await PyManager.fromMarketState(tx, marketStateId);
  const { result: pyPosition } = await py.positions.initPyPosition();

  const { result: mintedPy } = await py.yield.mintPy(
    syCoin,
    pyPosition
  );

  // 3) Optional: redeem to SY later
  // const { result: redeemedSy } = await py.yield.redeemPy("100", "100", pyPosition);

  // 4) Sign & execute
  const client = new SuiClient({ url: getFullnodeUrl("mainnet") });
  // const keypair = ...
  // const resp = await client.signAndExecuteTransaction({ signer: keypair, transaction: tx });
}

main().catch(console.error);
```

### Quick Start: SY from Market State ID

You can directly create an `SyManager` from a `marketStateId`. The SDK will resolve the SY provider via the public API and preload it for you.

```typescript
import { Transaction } from "@mysten/sui/transactions";
import { SyManager } from "@nemoprotocol/nemo-sdk";

async function main() {
  const tx = new Transaction();
  const marketStateId = "0x..."; // replace with a real Market state id

  // Create from market state id (preloads provider)
  const sy = await SyManager.fromMarketState(tx, marketStateId);

  // Mint sCoin from underlying
  const underlyingCoin = tx.object("0xunderlying-coin-object-id");
  const { result: sCoin } = await sy.mintSCoin({
    marketStateId,
    coin: underlyingCoin,
    amount: "1000000",
  });

  // Optional: burn back to underlying
  // await sy.burnSCoin({ marketStateId, sCoin, address: "0xyour-address" });
}

main().catch(console.error);
```

### Query Operations: LP Amount Estimations

The `QueryOperations` class provides methods to estimate LP token amounts for various operations. These methods use dry-run transactions to calculate expected outputs without executing actual transactions.

#### Get LP Out for Single SY In

Estimates the LP token amount you would receive when depositing a single SY coin into the market.

```typescript
import { Transaction } from "@mysten/sui/transactions";
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { Market } from "@nemoprotocol/nemo-sdk";

async function main() {
  const tx = new Transaction();
  const marketStateId = "0x..."; // replace with a real Market state id
  const market = await Market.fromMarketState(tx, marketStateId);

  const suiClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
  const sender = "0x..."; // your wallet address

  // Estimate LP output for depositing 1000000 SY tokens (base units)
  const { result } = await market.query.getLpOutForSingleSyIn(
    "1000000", // syAmountIn: amount of SY tokens to deposit
    suiClient,
    sender
  );

  console.log("Estimated LP output:", result.lpOut);
  console.log("SY fee:", result.syFee);
  console.log("SY to reserve:", result.syToReserve);
}

main().catch(console.error);
```

#### Get LP Out from Mint LP

Estimates the LP token amount you would receive when minting LP tokens with both PT and SY coins.

```typescript
import { Transaction } from "@mysten/sui/transactions";
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { Market } from "@nemoprotocol/nemo-sdk";

async function main() {
  const tx = new Transaction();
  const marketStateId = "0x..."; // replace with a real Market state id
  const market = await Market.fromMarketState(tx, marketStateId);

  const suiClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
  const sender = "0x..."; // your wallet address

  // Estimate LP output for minting with 500000 PT and 1000000 SY tokens
  const { result } = await market.query.getLpOutFromMintLp(
    "1000000",  // ptValue: amount of PT tokens
    "2000000", // syValue: amount of SY tokens
    suiClient,
    sender
  );

  console.log("Estimated LP output:", result);
}

main().catch(console.error);
```

### More examples

See the `samples/` directory for runnable scripts:
- `samples/py-manager-basic.ts`
- `samples/py-yield.ts`
- `samples/py-query.ts`
- `samples/py-get-sy-pt.ts` (estimate PT from mintPy and read SY on redeem)
- `samples/market.ts` (Market.mintLp build example)
- `samples/sy-from-market-state.ts` (Create `SyManager` from `marketStateId` and mint/burn sCoin)