open-index/open-npm huggingface dataset:
npm package: @preceptlabs/echelon-sdk
Description: The SDK for the Echelon Market
Latest version: 2.1.0

# echelon-sdk

## Quick Start

### Install

Install from npmjs:
```
npm install @preceptlabs/echelon-sdk
```

And make sure you also install the `@aptos-labs/ts-sdk`.

### Get all markets

```typescript
import { EchelonClient } from "@preceptlabs/echelon-sdk";
import { Account, Aptos, AptosConfig } from "@aptos-labs/ts-sdk";

// create the aptos instance
const aptos = new Aptos(
  new AptosConfig({
    network: Network.MAINNET,
    fullnode: "your rpc endpoint",
  })
);

const client = new EchelonClient(aptos, "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba");

// get all markets
const markets = await client.getAllMarkets();
```

Each market has a corresponding coin, to get the coin address:

```typescript
const market = markets[0]; // use the first market as an example
const coin = await client.getMarketCoin(market);
```

### Borrow/Supply/Replay/Withdraw

Borrow, supply, replay, and withdraw are similar. Let's use Borrow as an example.

First, you need to get the amount of coins the user can borrow:

```typescript
const borrowable = await client.getAccountBorrowable(account, market);
```

The user can borrow an amount of coins less than the maximum borrowable. To send the transaction, you can use "@thalalabs/surf" or Aptos wallet adapter. Here is an example using Surf:

```tsx
import { useSubmitTransaction } from '@thalalabs/surf/hooks';

const payload = client.createBorrowPayload(
  "0x1::aptos_coin::AptosCoin",
  // the market address of APT
  "0x761a97787fa8b3ae0cef91ebc2d96e56cc539df5bc88dadabee98ae00363a831",
  "100000000"
);

// in react:
const {submitTransaction} = useSubmitTransaction()

<button onClick={() => submitTransaction(payload)} />
```

## Details

Please refer to the complete API documentation at: [API docs](docs/globals.md)
npm package: @preceptlabs/router-sdk
Description: SDK to get optimal swap routing for ThalaSwap. Currently, we support finding routes of no more than 3 hops.
Latest version: 5.0.1

# Thala Router

SDK to get optimal swap routing for ThalaSwap. Currently, we support finding routes of no more than 3 hops.

## Install

```
$ npm i @preceptlabs/router-sdk
```

## Examples

```
const router = new ThalaswapRouter({
  client: new Aptos(
      new AptosConfig({
        network: "mainnet",
        fullnode: "https://fullnode.mainnet.aptoslabs.com/v1",
      })
    ),
  resourceAddress:
    "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af",
  v2ResourceAddress:
    "0x007730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5",
  v2LensAddress:
    "0x2ee2526b8035890ebf30510aae8891d41116d83d2b5b7d774a3bc73d2b751d61",
  multirouterAddress:
    "0x60955b957956d79bc80b096d3e41bad525dd400d8ce957cdeb05719ed1e4fc26",
  v2RouterAddress: 
    "0xc36ceb6d7b137cea4897d4bc82d8e4d8be5f964c4217dbc96b0ba03cc64070f4",
});
const fromToken = "0x1::aptos_coin::AptosCoin";
const toToken = "0x7fd500c11216f0fe3095d0c4b8aa4d64a4e2e04f83758462f2b127255643615::thl_coin::THL";
const amountIn = 0.1;

const route = await router.getRouteGivenExactInput(
    fromToken,
    toToken,
    amountIn
);

console.log("Route:", route);
console.log("Entry function payload with 0.5% slippage:", router.encodeRoute(route!, 0.5));
```

See `examples.ts` for more details

## Development

This package uses Bun for development and package management.

```
# install dependencies
pnpm install

# test the app
pnpm run test

# build the app, available under dist
pnpm run build
```
npm package: @preceptlabs/thalaswap-math
Description: SDK to calculate swap amounts and pool price.
Latest version: 1.0.1

# thalaswap-math

SDK to calculate swap amounts and pool price.

# install

```
$ npm i @preceptlabs/thalaswap-math
```

# example

```typescript
import {
  calcInGivenOutStable,
  calcInGivenOutWeighted,
  calcOutGivenInStable,
  calcOutGivenInWeighted,
} from "@preceptlabs/thalaswap-math";

// Calculate amount out given amount in:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the input token amount is 10.
console.log(calcOutGivenInStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount in given amount out:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the output token amount is 10.
console.log(calcInGivenOutStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount out given amount in:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the input token amount is 10.
console.log(calcOutGivenInWeighted(100, 20, 200, 30, 10, 0.01));

// Calculate amount out given amount out:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the output token amount is 10.
console.log(calcInGivenOutWeighted(100, 20, 200, 30, 10, 0.01));
```