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

garnet-market-maker

v0.0.13

Published

Automatic market maker on Stellar Network

Downloads

20

Readme

Garnet

Automatic market maker on Stellar Network

NPM Version Linux Build dependencies Status

Garnet is a market-maker bot for the Stellar network. It automatically creates offers on the market depending on its wallets and on market prices.

Its main goal is not to earn money but to help the expansion and introduction of anchors into Stellar network. It allows anchors to diffuse their assets, and users to send path payments with assets they do not hold. It is made to play the essential role of real market-makers until there are enough players on the network.

This repository shows my original idea to strengthen the network and to show a proof-of-concept implementation. It is not intended to be used on public network for now, but to serve as a starter-kit for an anchor.

The bot is launched with an account seed created specifically for it. It first checks his trustlines and balances. Then it creates passive offers for everything the account holds, with rates defined by an oracle. The Oracle is an independent module that tells the bot prices and amount to sell for a pair of assets.

In this project, there are three different oracles:

  • One very basic, that sells everything it holds for a price of 1:1 (oracles/simple.js)
  • One that fetch current market prices of common currences (USD, EUR, BTC, ...) from public APIs (currently Fixer.io) (oracles/realWorld.js)
  • One that reads prices and amount in a Redis database. (oracles/redis.js)

Use case

When an anchor wants to get into the stellar network, no one holds its assets. There must be market makers that trust this new anchor to allow path payments and trading of its assets. At the very beginning, an anchor can become its own market maker, choose to trust some others anchor's assets, inject its own asset into the bot and get others assets in exchange. The bot will then, lose anchor assets, but gain others. The anchor must invest money into the market, but it will get others currencies claimable on the real world afterwards. At the end, the anchor assets will be flowing on the network and exchanged by Stellar users. To stay fair and not to lose money, the bot must use an oracle that announce correct market prices.

Running demo

You can watch the current balances and offers for on our demo bot running on testnet on Stellar Portal

https://stellar-portal.ngfar.io/?accountId=GDEROTTYIQZSVLECX2DDBZVLSPCRZAMUP5V7JRH2GTNYG3XJ3TAJ3KNG

On this account, you can see that the bot holds EUR, USD, and BTC and has offers with current market prices. If you send it assets, you will see that it is updating his offers. (If you want to receive some assets, send us a message with your public key and we will fund you)

Running

You can run your own bot and test its behaviour on the testnet. You can use tools like Stellar Portal or Stellar Laboratory for managing and monitoring bot accounts.

  • Create a bot account
  • Create some issuer accounts, create trustlines to issuers assets (corresponding to known currencies, EUR, USD...) on the bot account
  • Fund the bot account with one or two assets
  • Watch offers that it has created.

Requirements

  • NodeJS v7+

How to use

The easiest way to run the bot is from command line.

  • Install node dependencies
  • Run npm start with SEEDenvironment variable filled with the bot's secret seed.
$ npm install
$ SEED=SDJEUIJRE npm run bot

Npm Installation:

You can implement your own oracle. This is an example of a bot instance with a simple oracle that sells everything at price 1:1 except Lumens.

You Oracle just have to implement two methods getPrice and getAmount. Please notice that they must return promises, and are implemented as async functions here. Assets are instance of StellarSDK's Asset class.

$ npm install garnet-market-maker
const Bot = require('garnet-market-maker').Bot;

class Oracle {

  async getPrice(assetSelling, assetBuying){ // For example 1:1 price

    return {
      n: 1,
      d: 1
    };

  }
  
  async getAmount(wallet){ // For example bid all ressource

    if(wallet.asset.isNative() ){

      return 0;

    }

    return wallet.balance;

  }
  
}

const SEED = 'yourSeed';
const oracle = new Oracle();
const bot = new Bot(SEED, oracle);

bot.run();

Improvements

This bot is just a proof-of-concept for a market-maker bot to support the stellar network expansion and new anchors introduction. It is not intended to be used on the real public network as the currently implemented oracle is not returning perfectly correct market prices and may lose some money value. It is currently configured to run on testnet.

The plan is to increase robustness and precision of market prices and external oracles integrations. If anchors want to use it, the code can be adapted to connect their own market estimations, contact us for more information.

If you have something interesting to share with us, we're open to issues or PM.