Using the Aggregator SDK

hippo-sdk:

  • Detailed integration sample code on github

  • 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);
};

Last updated