Hippo SDK for Aptos
npm install @manahippo/hippo-sdkhippo-sdk provides the following TypeScript interface:
- Hippo Dex aggregator
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
``typescriptQuote input: ${quote.quote.inputUiAmt}
// 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 output: ${quote.quote.outputUiAmt}
console.log();
}
};
// 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.
List commands
`
$ yarn cli agg2
Usage: hippo-cli agg2 [options] [command]
aggregator v2
Options:
-h, --help
Commands:
list-trading-pools
list-quotes
list-quotes-split
list-quotes-direct
list-quotes-api
list-quotes-split-api
list-quotes-with-change
swap
simulate-swap
swap-with-fees
simulate-swap-with-fees
swap-fixed-out
simulate-swap-fixed-out
simulate-swap-with-change
swap-with-change
split-swap
simulate-split-swap
help [command]
`
Get quotes from multiple routes
```
$ yarn cli -c .aptos/config.yaml agg2 list-quotes zUSDC APT 100