npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hippo-sdk-private

v2.0.0-4

Published

Hippo SDK for Aptos

Downloads

42

Readme

hippo-sdk

hippo-sdk provides the following TypeScript interface:

  • Hippo's trade aggregator
  • Hippo Swap
  • Token coinList

Directories

  • src/config: node configuration, allows us to specify which network/fullnode/contract to use.
  • src/generated: TypeScript interface generated using move-to-ts
  • src/aggregator: Hippo aggregator client SDK
  • src/swap: Hippo swap client SDK
  • src/tools: command-line tools for developers
  • src/wallet: Hippo wallet client SDK

Aggregator Usage

These snippets are taken from src/tools/index.ts and demonstrate how you can use the TradeAggregator 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 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.getQuotes(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}`);
  }
};

// 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.getQuotes(inputAmt, xCoinInfo, yCoinInfo);
  if (quotes.length === 0) {
    console.log('No route available');
    return;
  }
  const payload = quotes[0].route.makePayload(inputAmt, 0);
  await sendPayloadTx(client, account, payload as TxnBuilderTypes.TransactionPayloadEntryFunction);
};

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

cli tool

We already deployed the contracts to Aptos devnet (for now, might be wiped out by the time you read this).

To build the cli utility, run:

yarn build-cli

Aggregator CLI

List commands

$ yarn cli agg

aggregator

Options:
  -h, --help                                                        display help for command

Commands:
  list-trading-pools
  list-routes <fromSymbol> <toSymbol>
  list-quotes <fromSymbol> <toSymbol> <inputUiAmt>
  swap <fromSymbol> <toSymbol> <inputUiAmt>
  simulate-swap <fromSymbol> <toSymbol> <inputUiAmt> <minOutUiAmt>
  help [command]                                                    display help for command

List all available pools

$ yarn cli -c .aptos/config.yaml agg list-trading-pools

###########
Pair: BTC - USDC
Dex: Hippo
PoolType: 1

###########
Pair: BTC - USDT
Dex: Hippo
PoolType: 1

###########
Pair: DAI - USDC
Dex: Hippo
PoolType: 3

###########
Pair: USDT - USDC
Dex: Hippo
PoolType: 3

###########
Pair: BTC - USDC
Dex: Econia
PoolType: 1

###########
Pair: BTC - USDC
Dex: Econia
PoolType: 1

Get quotes from multiple routes

$ yarn cli -c .aptos/config.yaml agg list-quotes BTC DAI 0.1

###########
Route: BTC -> USDC -> DAI
Step 0: BTC -> USDC (via Econia)
Step 1: USDC -> DAI (via Hippo)
x-to-y: 0.00009999002515576115
y-to-x: 9999.99738417296
Quote input: 0.1
Quote output: 999.8534694079265
###########
Route: BTC -> USDC -> DAI
Step 0: BTC -> USDC (via Hippo)
Step 1: USDC -> DAI (via Hippo)
x-to-y: 0.00010021089359466275
y-to-x: 10037.091547286866
Quote input: 0.1
Quote output: 987.7686941186852
###########
Route: BTC -> USDT -> USDC -> DAI
Step 0: BTC -> USDT (via Hippo)
Step 1: USDT -> USDC (via Hippo)
Step 2: USDC -> DAI (via Hippo)
x-to-y: 0.00010023109670032361
y-to-x: 10033.061505127245
Quote input: 0.1
Quote output: 987.3274270314756
###########
Route: BTC -> USDC -> DAI
Step 0: BTC -> USDC (via Econia)
Step 1: USDC -> DAI (via Hippo)
x-to-y: 0
y-to-x: 0
Quote input: 0.1
Quote output: 0

Wallet & Faucet CLI

Get airdrop from faucet:

$ yarn cli -c .aptos/config.yaml test wallet-client-faucet BTC 0.1
{
  type: 'user_transaction',
  version: '1904948',
  hash: '0xd2cae8dd0f9a9f930f1cff31734a9caba92529e247d31827f9ef3290f6acccee',
  state_root_hash: '0xcb1cf36930db2e03bac78f6d42ffa4e96cc196805bf48f8c23c113e9b826b47c',
  event_root_hash: '0x32ba5023ca80de4916b23c3bf5adf0c77963e0c8ae6a8f8ac35420677400c4b7',
  gas_used: '158',
  success: true,
  vm_status: 'Executed successfully',
  accumulator_root_hash: '0x4b7dea2a293432e20ea0c8cd766be93fc3fb141c7fed1090d44284c51c462eed',
  changes: [
    {
    ...

Show current balance (only hippo devnet tokens supported)

$ yarn cli -c .aptos/config.yaml test wallet-client
APTOS: 0.00009842
BTC: 0.1

Token Registry

List coins registered in coinList:

$ yarn cli -c .aptos/config.yaml show-token-coinList
########BTC#######
name: Bitcoin
description: Bitcoin
decimals: 8
logo_url: https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E/logo.png
project_url: https://bitcoin.org
type: 0xa61e1e86e9f596e483283727d2739ba24b919012720648c29380f9cd0a96c11a::mock_coin::WBTC
delisted: false

########USDC#######
name: USDC
description: USDC
decimals: 8
logo_url: https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png
project_url: https://www.centre.io/
type: 0xa61e1e86e9f596e483283727d2739ba24b919012720648c29380f9cd0a96c11a::mock_coin::WUSDC
delisted: false

########USDT#######
name: USDT
description: Tether
decimals: 8
logo_url: https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB/logo.svg
project_url: https://tether.to/
type: 0xa61e1e86e9f596e483283727d2739ba24b919012720648c29380f9cd0a96c11a::mock_coin::WUSDT
delisted: false

...

Miscellaneous

You can test the cli with:

yarn cli
yarn run v1.22.11
$ node dist/tools/index.js
Usage: hippo-cli [options] [command]

Hippo SDK cli tool.

Options:
  -c, --config <path>                         path to your aptos config.yml (generated with "aptos init")
  -p, --profile <PROFILE>                     aptos config profile to use (default: "default")
  -h, --help                                  display help for command

Commands:
  mock-deploy
  list-modules
  show-token-coinList
  show-pools
  hit-faucet <coin-name> <raw-amount>
  show-wallet
  swap <from-coin> <to-coin> <raw-amount-in>
  help [command]                              display help for command

You need to provide an aptos config file through -c flag. When the node url contains "devnet" in it, the cli tool automatically picks the deployed devnet contract address.

To get started, try these:

yarn cli -c YOUR_CONFIG_FILE test hippo-client
yarn cli -c YOUR_CONFIG_FILE test wallet-client
yarn cli -c YOUR_CONFIG_FILE test wallet-client-faucet BTC 1.1
yarn cli -c YOUR_CONFIG_FILE test wallet-client-faucet USDC 11000
yarn cli -c YOUR_CONFIG_FILE test add-liquidity BTC USDC 1 10000
yarn cli -c YOUR_CONFIG_FILE test swap BTC USDT 0.1
yarn cli -c YOUR_CONFIG_FILE test remove-liquidity BTC USDC 50
yarn cli -c YOUR_CONFIG_FILE test hippo-client