@manahippo/hippo-sdk
TypeScript icon, indicating that this package has built-in type declarations

7.3.8 • Public • Published

hippo-sdk

hippo-sdk provides the following TypeScript interface:

  • Hippo Dex aggregator

Aggregator Usage

These snippets demonstrate how you can use the TradeAggregatorV2 class to

  1. query coin info
  2. query quotes for a particular pair
  3. perform swap
// compute a list of quotes (ordered by output), for fromSymbol -> toSymbol
const listQuotes = async (fromSymbol: string, toSymbol: string, inputUiAmt: string) => {
  const { client } = getAptosClient();
  const agg = await TradeAggregatorV2.create(client);
  const xCoinInfos = agg.coinListClient.getCoinInfoBySymbol(fromSymbol);
  const yCoinInfos = agg.coinListClient.getCoinInfoBySymbol(toSymbol);
  const inputAmt = parseFloat(inputUiAmt);
  const quotes = await agg.getQuotes(inputAmt, xCoinInfos[0], yCoinInfos[0], {
    split: true,
    considerGasWhenSorting: true,
    allowHighGas: true
  });
  for (const quote of quotes) {
    console.log('###########');
    quote.route.debugPrint();
    console.log(`Quote input: ${quote.quote.inputUiAmt}`);
    console.log(`Quote output: ${quote.quote.outputUiAmt}`);
  }
};

// send a transaction to swap "inputUiAmt" of "fromSymbol" to "toSymbol"
const swap = async (fromSymbol: string, toSymbol: string, inputUiAmt: string) => {
  const { client } = getAptosClient();
  const agg = await TradeAggregatorV2.create(client);
  const xCoinInfos = agg.coinListClient.getCoinInfoBySymbol(fromSymbol);
  const yCoinInfos = agg.coinListClient.getCoinInfoBySymbol(toSymbol);
  const inputAmt = parseFloat(inputUiAmt);
  const quotes = await agg.getQuotes(inputAmt, xCoinInfos[0], yCoinInfos[0], {
    split: true,
    considerGasWhenSorting: true,
    allowHighGas: true
  });
  if (quotes.length === 0) {
    console.log('No route available');
    return;
  }
  const payload = quotes[0].route.makeSwapPayload(inputAmt, 0);
  await sendPayloadTx(client, account, payload as TxnBuilderTypes.TransactionPayloadEntryFunction);
};

You can find more sample code that uses TradeAggregator in src/tools/index.ts.

Aggregator CLI

List commands

$ yarn cli agg2
Usage: hippo-cli agg2 [options] [command]

aggregator v2

Options:
  -h, --help

Commands:
  list-trading-pools
  list-quotes <fromSymbol> <toSymbol> <inputUiAmt>
  list-quotes-split <fromSymbol> <toSymbol> <inputUiAmt>
  list-quotes-direct <fromSymbol> <toSymbol> <inputUiAmt>
  list-quotes-api <fromSymbol> <toSymbol> <inputUiAmt>
  list-quotes-split-api <fromSymbol> <toSymbol> <inputUiAmt>
  list-quotes-with-change <fromSymbol> <toSymbol> <outputUiAmt>
  swap <fromSymbol> <toSymbol> <inputUiAmt> [minOutUiAmt] [routeIdx] [maxGas]
  simulate-swap <fromSymbol> <toSymbol> <inputUiAmt> [minOutUiAmt] [routeIdx] [maxGas]
  swap-with-fees <fromSymbol> <toSymbol> <inputUiAmt> <feeTo> <feeBips> [minOutUiAmt] [routeIdx] [maxGas]
  simulate-swap-with-fees <fromSymbol> <toSymbol> <inputUiAmt> <feeTo> <feeBips> [minOutUiAmt] [routeIdx] [maxGas]
  swap-fixed-out <fromSymbol> <toSymbol> <outputUiAmt> [routeIdx] [maxGas]
  simulate-swap-fixed-out <fromSymbol> <toSymbol> <outputUiAmt> [routeIdx] [maxGas]
  simulate-swap-with-change <fromSymbol> <toSymbol> <outputUiAmt> [maxGas]
  swap-with-change <fromSymbol> <toSymbol> <outputUiAmt> [maxGas]
  split-swap <fromSymbol> <toSymbol> <inputUiAmt> [minOutUiAmt] [routeIdx] [maxGas]
  simulate-split-swap <fromSymbol> <toSymbol> <inputUiAmt> [minOutUiAmt] [routeIdx] [maxGas]
  help [command]          

Get quotes from multiple routes

$ yarn cli -c .aptos/config.yaml agg2 list-quotes zUSDC APT 100

Readme

Keywords

none

Package Sidebar

Install

npm i @manahippo/hippo-sdk

Weekly Downloads

147

Version

7.3.8

License

MIT

Unpacked Size

9.57 MB

Total Files

660

Last publish

Collaborators

  • andy-hippo
  • hippolabs