Socket
Socket
Sign inDemoInstall

@manahippo/hippo-sdk

Package Overview
Dependencies
137
Maintainers
2
Versions
322
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @manahippo/hippo-sdk

Hippo SDK for Aptos


Version published
Weekly downloads
185
decreased by-16.67%
Maintainers
2
Install size
40.3 MB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 19 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc