npm package: @omnibtc/omnibtc-aptos-sdk
Description: OmniSwap SDK for Aptos
Latest version: 0.1.5

# aptos-amm-sdk

`omni-amm-sdk` provides the the following TypeScript interface:
- swap in aptos amm
- add and remove liquid

## USAGE
### Install SDK
```
yarn add @omnibtc/omniswap-aptos-sdk
```
### Query All Support Coins
```
import { App } from '@omnibtc/omniswap-aptos-sdk/generated';
import { AptosAccount, AptosClient, HexString } from 'aptos';
import { CONFIGS } from '@omnibtc/omniswap-aptos-sdk/config';

const netConf = CONFIGS.testnet;
const client = new AptosClient("https://fullnode.testnet.aptoslabs.com/v1");
const app = new App(client);

(async()=>{
    const coinListClient = await CoinListClient.load(app);
    const coinlist = await coinListClient.getCoinInfoList()
    console.log(`JSON.stringify(coinlists)`);
})
```

### Query All LiquidPools
```
import { App } from '@omnibtc/omniswap-aptos-sdk/generated';
import { AptosAccount, AptosClient, HexString } from 'aptos';
import { CONFIGS } from '@omnibtc/omniswap-aptos-sdk/config';

const netConf = CONFIGS.testnet;
const client = new AptosClient("https://fullnode.testnet.aptoslabs.com/v1");
const app = new App(client);

(async()=>{
    const coinListClient = await CoinListClient.load(app);
    const omniProvider = new OmniPoolProvider(app, netConf, coinListClient);
    const poollist = await omniProvider.loadPoolList();
    poollist.forEach(async (pool) => {
      await pool.reloadState(app);
      // calculate quote
      const quote = await pool.getQuote(1, true);
      console.log(`quote: ${JSON.stringify(quote)}`);
    });

})
```
### Add liquidity
```
import { App,Swap } from '@omnibtc/omniswap-aptos-sdk/generated';
import { AptosAccount, AptosClient, HexString } from 'aptos';
import { CONFIGS } from '@omnibtc/omniswap-aptos-sdk/config';
import { parseTypeTagOrThrow, u64, sendPayloadTxAndLog, parseMoveStructTag, StructTag } from '@manahippo/move-to-ts';
const netConf = CONFIGS.testnet;
const client = new AptosClient("https://fullnode.testnet.aptoslabs.com/v1");
const app = new App(client);
const account = new AptosAccount(privateKey.toUint8Array());

(async()=>{
  // X_: 0xd415c5143d4f9752e462ab3476c567fdc0e2f0fb02f779d333e819c0e8624ea8::Coins::USDT
  // Y_: 0x1::aptos_coin::AptosCoin
  const X_ = parseTypeTagOrThrow(X);
  const Y_ = parseTypeTagOrThrow(Y);
  const coin_x_val_ = u64(coin_x_val);
  const coin_x_val_min_ = u64(coin_x_val_min);
  const coin_y_val_ = u64(coin_y_val);
  const coin_y_val_min_ = u64(coin_y_val_min);
  const max_gas_ = parseInt(max_gas);
  const payload = Swap.Interface.buildPayload_add_liquidity(
    coin_x_val_,
    coin_x_val_min_,
    coin_y_val_,
    coin_y_val_min_,
    [X_, Y_]
  );
  await sendPayloadTxAndLog(client, account, payload, { maxGasAmount: max_gas_ });

})

```

## CLI
```
git clone https://github.com/OmniBTC/omniswap-aptos-sdk.git
yarn 
yarn build-cli
```
List commands
```
Usage: yarn cli [options] [command]
Options:
  -c, --config <path>                           path to your aptos config.yml (generated with "aptos init")
  -p, --profile <PROFILE>                       aptos config profile to use (default:"default")
  -h, --help                                    display help for command

Commands:
  interface:add-liquidity <TYPE_X> <TYPE_Y> <coin_x_val> <coin_x_val_min> <coin_y_val> <coin_y_val_min> [max_gas]  Add liquidity to the pool
  interface:initialize-swap <controller> <beneficiary> [max_gas]                                                   Initialize swap (admin-only)
  interface:register-pool <TYPE_X> <TYPE_Y> [max_gas]                                                              Register a new liquidity pool for
                                                                                                                   'X'/'Y' pair
  interface:remove-liquidity <TYPE_X> <TYPE_Y> <lp_val> <min_x_out_val> <min_y_out_val> [max_gas]                  Remove liquidity to the pool
  interface:swap <TYPE_X> <TYPE_Y> <coin_val> <coin_out_min_val> [max_gas]                                         Swap 'X' for 'Y'
  list-pools                                                                                                       List all registered liquidity pools
  help [command]                                                                                                   display help for command
```