open-index/open-npm huggingface dataset:
npm package: @hodlmarkets/sdk
Description: Solana program SDK for the HODL token launchpad/trading platform
Latest version: 0.1.4

# @hodlmarkets/sdk

TypeScript SDK for the HODL vAMM program on Solana.

Full documentation at [docs.hodl.markets](https://docs.hodl.markets)

## Install

```bash
npm install @hodlmarkets/sdk
```

Peer dependencies:

```bash
npm install @coral-xyz/anchor @solana/web3.js @solana/spl-token bn.js
```

## Buy

```ts
import { Connection } from '@solana/web3.js'
import BN from 'bn.js'
import { HodlClient, calculateBuyAmount, applySlippage } from '@hodlmarkets/sdk'

const connection = new Connection('https://api.mainnet-beta.solana.com')
const client = new HodlClient({ connection })

const pool = await client.fetchPool(mint)

const solAmount = new BN('100000000') // 0.1 SOL
const expectedTokens = calculateBuyAmount(solAmount, pool.vammRealSol, pool.vammTokens, pool.vammK)
const minTokensOut = applySlippage(expectedTokens, 100) // 1% slippage

const tx = await client.buy({ buyer: wallet.publicKey, mint, solAmount, minTokensOut })
tx.sign([wallet])
const sig = await connection.sendRawTransaction(tx.serialize())
```

## Sell

```ts
import { HodlClient, calculateSellAmount, applySlippage, getPoolStatePDA, PROGRAM_ID } from '@hodlmarkets/sdk'

const pool = await client.fetchPool(mint)
const [poolState] = getPoolStatePDA(mint, PROGRAM_ID)
const position = await client.fetchPosition(poolState, wallet.publicKey)

const expectedSol = calculateSellAmount(position.tradableTokens, pool.vammRealSol, pool.vammTokens, pool.vammK)

const tx = await client.sell({
  seller: wallet.publicKey,
  mint,
  tokenAmount: position.tradableTokens,
  minSolOut: applySlippage(expectedSol, 100),
})
tx.sign([wallet])
await connection.sendRawTransaction(tx.serialize())
```

## Create Token

```ts
import { Keypair } from '@solana/web3.js'
import BN from 'bn.js'

const mint = Keypair.generate()

const tx = await client.createToken({
  creator: wallet.publicKey,
  mint: mint.publicKey,
  name: 'My Token',
  symbol: 'MTK',
  uri: 'https://arweave.net/metadata.json',
  poolDescription: 'A community token',
  vestDuration: new BN(60), // 1 minute (only 60 or 1800 allowed)
})
tx.sign([wallet, mint]) // both creator and mint must sign
await connection.sendRawTransaction(tx.serialize())
```

## Claim Accrued Tokens

```ts
const [poolState] = getPoolStatePDA(mint, PROGRAM_ID)
const tx = await client.claimAccrued({ owner: wallet.publicKey, poolState })
tx.sign([wallet])
await connection.sendRawTransaction(tx.serialize())
```

## Events

```ts
// Real-time
const subId = client.subscribeToEvents((event, slot, signature) => {
  if (event.name === 'tokenPurchased') {
    console.log('Buy:', event.data.tokensReceived.toString())
  }
})
await client.unsubscribe(subId)

// Historical
const events = await client.fetchAndParseTransaction(signature)
```

## Error Handling

```ts
import { parseHodlError } from '@hodlmarkets/sdk'

try {
  await connection.sendRawTransaction(tx.serialize())
} catch (err) {
  const hodlErr = parseHodlError(err)
  if (hodlErr) console.error(`HODL error ${hodlErr.code}: ${hodlErr.message}`)
}
```

## License

MIT
npm package: @hodlvalley/sdk
Description: 🛠 An SDK for building applications on top of HODL Valley.
Author: hodlEngineer
Latest version: 1.0.0

# HODL Valley SDK

In-depth documentation on this SDK is available at [uniswap.org](https://uniswap.org/docs/v2/SDK/getting-started/).

This modifies uniswap-sdk's UniswapV2Factory address. The new address for hodlvalley is  `0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac`.

## Running tests

To run the tests, follow these steps. You must have at least node v10 and [yarn](https://yarnpkg.com/) installed.

First clone the repository:

```sh
git clone https://github.com/hodlvalley/hodl-sdk.git
```

Move into the hodl-sdk working directory

```sh
cd hodl-sdk/
```

Install dependencies

```sh
yarn install
```

Run tests

```sh
yarn test
```

You should see output like the following:

```sh
yarn run v1.22.4
$ tsdx test
 PASS  test/constants.test.ts
 PASS  test/pair.test.ts
 PASS  test/fraction.test.ts
 PASS  test/miscellaneous.test.ts
 PASS  test/entities.test.ts
 PASS  test/trade.test.ts

Test Suites: 1 skipped, 6 passed, 6 of 7 total
Tests:       3 skipped, 82 passed, 85 total
Snapshots:   0 total
Time:        5.091s
Ran all test suites.
✨  Done in 6.61s.
```