Giter Club home page Giter Club logo

bot's Introduction

LNp2pBot

chat MIT license

LNp2pBot

Telegram bot that allows people to trade using lightning network with other people on telegram, this is an open source project and anyone can create issues, submit a PR, fork it, modify it or create their own bot with the code.

Try it out!

Wherever you are you can start using the bot, just need to have a telegram account with a username and /start the bot.


LNp2pBot is being developed on nodejs and connects with an LND node, we wanted that the telegram bot be able to receive lightning payments without being custodial, after some thinking we decided to use hold invoices for it, the bot only settle seller invoices when each party is ok with it and right after that moment the bot pays the buyer's invoice.

Creating a sell order

  1. Alice tells to the bot that she wants to sell 5000 sats for n fiat amount.
  2. The bot publishes a sell order of 5000 sats on the bot channel.
  3. Bob accepts the order for 5000 sats sending a new lightning invoice to the bot.
  4. The bot send to alice a hold-invoice, Alice has to pay a hold-invoice of 5000 sats to the bot, this invoice is "pending", the money is not accepted or rejected by the bot at that moment.
  5. After the bot detects that Alice paid the invoice, the bot puts Alicia in contact with Bob.
  6. Bob sends the fiat money to Alice and tells to the bot that the fiat money was sent to Alice.
  7. When Alice confirmed that she received the money, the bot settles Alice's initial invoice and pays Bob's invoice.
  8. If Alice does not confirm the operation that she received the payment in certain amount of time (initially we set this in two hours but this can be changed), the bot will send all the information to one admin and the admin will solve the issue, before the time expires Bob will be notified that Alice is not responding and Bob can start a dispute.

Creating a buy order

  1. Alice wants to buy 5000 sats.
  2. Alice publishes a buy order of 5000 sats with n fiat amount, Alice does not have satoshis, but she has fiat.
  3. The bot shows the order in the public group.
  4. Bob takes the order, the bot sends him a hold-invoice for 5000.
  5. Bob pays the invoice.
  6. The bot tells Alice that Bob has already made the payment, Alice now have to send an invoice to the bot to receive her satoshis. She can now send the fiat to Bob, after she sent the money she tells to the bot that the fiat was sent.
  7. When Bob confirms that he received the fiat, the bot settles Bob's invoice and pays Alice's invoice.
  8. If Bob does not confirm the operation that he received the payment in certain amount of time (initially we set this in two hours but this can be changed), the bot will send all the information to one admin and the admin will solve the issue, before the time expires Alice will be notified that Bob is not responding and Alice can start a dispute.

Cooperative cancel

After a user creates a new order and before another user take it, the user can cancel the order, but in some cases users may need to cancel the order, it shouldn't be unilateral.

Only if both parties cancel cooperatively the order is canceled and seller's funds are returned.

If users have a disagreement on canceling or don't want to go forward they can start a dispute.

Disputes

Both parties can start a dispute at any moment, after a dispute is started a human (aka "solver") will be notified with all the information, this solver will contact both parties to evaluate the situation and take a decision.

After a user starts a dispute, both parties will have increased by 1 their own dispute field in database. If during a dispute it is proven that there is a malicious user, the solver can ban that user, and they will no longer be able to use the bot anymore.

Incentive to release funds

A seller that didn't release funds to the buyer can't open or take another order from the bot and probably will be involved in a dispute from the buyer damaging his/her reputation

Communities

Anyone who already has or creates a Telegram group can include the bot inside to facilitate buying and selling bitcoin among its members. The group administrator will earn a commission for transactions conducted within their community, and they can also offer discounts on the fees that the bot charges within their community.

Financial Support

LNp2pBot is an open source project. We are not a company, we don't do ICOs or dark business, we are just people that wants bring solutions to the people using the best open source money in the world. Our work depends on the financial collaboration of the users.

To financially support further development of LNp2pBot, please consider support our project sending bitcoin to lightning address [email protected].

Installation

You will need to create an .env file on the root dir, you can use a sample env file called .env.sample on the root dir, an easy way of doing this is just to copy the sample file to .env.

cp .env-sample .env

MongoDB

You will need to have mongo installed and fill the mongo variables on the .env file, those that stats with DB_.

Telegram

You will need a telegram bot api key (BOT_TOKEN), find out more about it here.

Tor service or another proxy

You can route the bot API via Tor service or another proxy if you specify 'SOCKS_PROXY_HOST' parameter in .env. For Ubuntu see this

Lightning Network

You will need a lightning network node, for this bot we use LND.

There are two methods to connect with an LND node:

Method 1: Setting Variables in the .env File

To connect with an LND node we need to set 3 variables in the .env file,

  1. LND_CERT_BASE64: LND node TLS certificate on base64 format, you can get it with base64 -w0 ~/.lnd/tls.cert on the LND node.

  2. LND_MACAROON_BASE64: Macaroon file on base64 format, the macaroon file contains permission for doing actions on the LND node, you can get it with base64 -w0 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon.

  3. LND_GRPC_HOST: IP address or domain name from the LND node and the port separated by colon (:), example: 192.168.0.2:10009.

Method 2: Copying Files to the Project Root

Instead of setting the LND_MACAROON_BASE64 and LND_CERT_BASE64 variables in the .env file, you can simply copy the admin.macaroon and tls.cert files to the root of the project.

Please note that you will still need to define the LND_GRPC_HOST in the .env file as in Method 1, step 3.

Please choose one of these two methods for your setup.

To install just run:

$ git clone https://github.com/lnp2pbot/bot.git lnp2pbot
$ cd lnp2pbot
$ npm install

Here we have a detailed guide for installation and first steps using the bot.

Running it

$ npm start

Testing

$ npm test

Documentation

You can find documentation in English, Spanish, Portuguese, French and Persian

Contribute

See contributing guide.

bot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bot's Issues

Add cancel button after user take an order

If the user touch the cancel button the order status should change to 'CANCELED' and a new order should be created with the same values but in 'PENDING' status and should be published on the bot channel.

cancel

Ban users with N disputes

We need to add a new env var MAX_DISPUTES to .env file with the max number of disputes to ban users and also code the logic for banning users with many diputes.

help command to the bot

User enter: /help
Response:
/start
/sell <monto_en_sats> <monto_en_fiat> <codigo_fiat> <método_de_pago>
/buy <monto_en_sats> <monto_en_fiat> <codigo_fiat> <método_de_pago> <lightning_invoice>
/cancel <order_id> -- cancel an order
/dispute <order_id> -- start a dispute
/release <order_id> -- release satoshis


For more information on each command type /help <command>.

Allow to create fiat orders without indicate sats amount

Currently when a user creates an order he needs to indicate the sats amount and the fiat amount, this order is published on a channel, the problem come when an order is not taken instantly and the bitcoin price goes up or down, the order creator needs to manually cancel it and create a new one with the corrected price.

We can allow users to create an order just with the fiat amount and let the bot calculate the BTC price using an API

I propose to use the api from this site which have the free market fiat currencies rate.

https://yadio.io/api.html

Example:
VES: https://api.yadio.io/rate/VES
ARS: https://api.yadio.io/rate/ARS
MXN: https://api.yadio.io/rate/MXN

Trade was not completed after seller released the sats

Trade 611eeea65a192872bb657f07 was not completed after seller released the sats. The bot sent me this message:

El vendedor ha liberado los satoshis pero no he podido pagar tu invoice, en unos minutos intentaré pagarla nuevamente, asegúrate que tu nodo/wallet esté online

Tell to buyer Fiat amount and Fiat code

In order to have clear messages to the users the bot should say the exact fiat amount and fiat currency on the message to the buyer when the buyer must send the fiat money to the seller

Allow users to use their own channels to publish offers

We are receiving request from users to create channels by country, we can do that easily but probably in the future we will receive request for channels by cities, or comunities and so on, instead of create new channels in a centralize way, I think a better idea is to allow users to create their own channels without asking permission.

The idea is, if a user is admin of the group A, that user can link that group to channel B, when the bot receive new orders sent from the group A the bot will publish them to the channel B.

Change buy workflow

Some wallets generate invoices with an expiration time of 60 minutes, to avoid working with expired invoices when buying we should stop asking for an invoice when the user create the buy order and only ask for an invoice when the order is taken by a seller

Also we need to set the order expiration time (after buyer took it, status=WAITING_PAYMENT) to be the same to the buyer invoice expiration minus 10 minutes, to do this in an easy way we can set an expiration time when create the hold invoice and cancel the order on jobs/cancel_orders.js

Send message to seller after /cooperativecancel

cuando cancelas una orden con cooperative, que en el mensaje de confirmacion te diga "has recibido un reembolso lightning, no es necesario hacer nada mas", no es evidente que rechaza el pago en esos casos

Add reputation system

We need a way of show a better user reputation, this reputation is displayed when a user A creates a new order, and helps user B to know how A is using the bot.

The current reputation only shows how many successful trades did user A.

The new reputation should be a new index from 1 to 5, calculated using the successful trades and volume in sats.

If users A and B traded successfully they will have a positive impact on the index but if the next trades between themselves will add less positive points to the index.

Things to have in consideration, currently a user can create an order and the same user can take that order, we need to eliminate this option

Users response time

We need to calculate the average time between for buyer/seller

We need to show this number when the bot publishes the order and when other user take it

Buyer response time:

Time from when the order becomes ACTIVE (when the bot puts them in touch) until the buyer does the /fiatsent (status FIAT_SENT)

Seller response time:

Time from buyer executes /fiatsent to seller executes /release (status PAID_HOLD_INVOICE)

Add command to list currently supported fiat currencies price

The bot supports all fiat currencies but we only have a limited number of fiat currencies with we know the current price using an external API, we should let know to users which are those currencies.

The fiat data is on /util/fiat.json and the ones that have price: true are the ones we can work with the price, por example, when the user create an order with 0 amount on sats.

Order cancel after expiration time

If the seller does not confirm the operation that received the fiat in certain amount of time (ORDER_EXPIRATION_WINDOW), the bot cancels the hold-invoice and closes the order, before the time expires the buyer will be notified by the bot that the seller is not responding and the buyer can start a dispute.

Add a new env var ORDER_EXPIRATION_WINDOW, and a script that will be run by a cronjob.

Multilang

ESP/ENG to messages

A command to select lang

Change the message that seller receive when order Is taken

Vendedor crea una order, cambiar este mensaje que recibe cuando alguien la toma

"Por favor paga esta factura para comenzar la venta, esta factura expira en 10 minutos"

por

"Alguien quiere comprarte sats por fiat amount Fiat code, Por favor paga esta factura para comenzar la venta, esta factura expira en 10 minutos"

Add new order status = ADDING_INVOICE

We use this status to know when a buyer is about to add an invoice, if the user don't do it in a period of Time the order will expire.

Also a user with this status can't take any other order.

Change behavior on commands that receive <order_id>

Some commands receive a order id as parameter, for example /release <order_id>, in order have a better UX we need to change those commands to work without the param if the user have only one active order.

If the user have more than one order that can be released, the response from the bot should be show the orders (type, id, sats amount, fiat amount, fiat code) and ask which is the one the user needs to release.

Do the same with commands /fiatsent, /cancel, /dispute, /cancel,

Add /cooperativecancel command

After a user creates a new order and before another user take it, the user can cancel the order, but in some cases users can agree on cancel the order, it shouldn't be unilateral.

Add a command /cooperativecancel to cancel cooperatively, only if both execute this command the order is canceled and the seller sats are returned.

If users have a disagreement on canceling or going forward the can open a dispute.

/setinvoice updates pending_payments

setinvoice command should check if there is a pending payment record for that order on pending_payments collection with paid=false and then update that buyer payment request field

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.