Hippo Labs
  • Hippo Labs
  • move-to-ts
    • Move-to-TypeScript Transpiler
    • App interface
    • Codegen attributes
  • Aggregator SDK
    • Using the Aggregator SDK
    • Adding a new DEX
  • aptos-wallet-adapter
    • aptos-wallet-adapter
Powered by GitBook
On this page
  • Quoting
  • Swapping
  1. Aggregator SDK

Using the Aggregator SDK

PreviousCodegen attributesNextAdding a new DEX

Last updated 2 years ago

hippo-sdk:

  • Detailed integration sample code on

  • npm: @manahippo/hippo-sdk

Quoting

// compute a list of quotes (ordered by output), for fromSymbol -> toSymbol
const aggListQuotes = async (fromSymbol: string, toSymbol: string, inputUiAmt: string) => {
  const { client } = readConfig(program);
  const agg = await TradeAggregator.create(client);
  const xCoinInfo = agg.registryClient.getCoinInfoBySymbol(fromSymbol);
  const yCoinInfo = agg.registryClient.getCoinInfoBySymbol(toSymbol);
  const inputAmt = parseFloat(inputUiAmt);
  const quotes = await agg.getQuotesUptoV3(inputAmt, xCoinInfo, yCoinInfo);
  for (const quote of quotes) {
    console.log('###########');
    quote.route.debugPrint();
    console.log(`Quote input: ${quote.quote.inputUiAmt}`);
    console.log(`Quote output: ${quote.quote.outputUiAmt}`);
  }
};

Swapping

// send a transaction to swap "inputUiAmt" of "fromSymbol" to "toSymbol"
const aggSwap = async (fromSymbol: string, toSymbol: string, inputUiAmt: string) => {
  const { client, account } = readConfig(program);
  const agg = await TradeAggregator.create(client);
  const xCoinInfo = agg.registryClient.getCoinInfoBySymbol(fromSymbol);
  const yCoinInfo = agg.registryClient.getCoinInfoBySymbol(toSymbol);
  const inputAmt = parseFloat(inputUiAmt);
  const quotes = await agg.getQuotesUptoV3(inputAmt, xCoinInfo, yCoinInfo);
  if (quotes.length === 0) {
    console.log('No route available');
    return;
  }
  // first quote also the best quote
  const payload = quotes[0].route.makeSwapPayload(inputAmt, 0);
  await sendPayloadTx(client, account, payload as TxnBuilderTypes.TransactionPayloadEntryFunction);
};
github