Skip to content

Commit

Permalink
rebase onto upstream (#28)
Browse files Browse the repository at this point in the history
* add build scripts, add work-around for poor order-book sync between client and server, mm bot rework of basic strategy to make it competitive, relax requirements for POL reserved/locked for fees, get rid of depth chart, other UI cleanup

* fix typos (introduced when removing depth-chart)

* improve order placement (add safety, adjust logs)

* allow to configure profit threshold between 0.1 and 4% (from 2% max allowed previously)

* mm bot improvements, rework previous solution for displaying own order book orders to be complete

* mm bot should make 1-sided placements only, skew mm bot algo to resits (not follow) rapid market price changes

* mm bot adjustments

* mm bot adjustments

* perform Bison mid-gap rate sanity check only when mid-gap rate is available

* work-around for annoying bug that Bison wallet doesn't recover from

* makefile: make a by default

* update fiat rates more frequently

* only check for slippage when we can get mid-gap rate

* better checks for bad prices from fiat oracles

* remove locale artifacts

* better validation for oracle volume

* revert: update fiat rates more frequently (we can't fetch fiat rates more frequently due to aggressive rate limiting)

* disable server-enforced max-fee limit restriction

* add Binance as fiat-rate source, disable other fiat-rate sources for now

* enforce user-configured max-fee-rate value properly

* revert inconsistent change

* improve trade validation (keep it powerful, but not intrusive)

* have pprof on by default

* refuse to use any other rate than wallet-provided

* (refactor) refuse to use any other rate than wallet-provided

* revert last commit since not every wallet is a FeeRater we still have to fall back to other rate-sources occasionally

* update fiat rates more frequently (note, this works with Binance rate source only since other sources have strict rate limits)

* btc: better differentiate between transaction types when identifying unknown transaction

* align btc implementation with zec

* rework slippage warning

* mm bot shouldn't rely on Bison book being present (use oracle/fiat rate only as reference point)

* fix typo in trade-validation code that results into panic

* ui: markets page rework (#25)

* ui: markets page rework (mainly order-form)

* fix rate conversion(s), get rid of swap options views (and rework showVerify), get rid of translations as unnecessary burden

* fix decimal number inputs (getting rid of number in favor of text + additional js validation)

* turn off selection history for order-forms

* handle balance update notes properly

* rework market list

* minor visual adjustments (margins and such)

* add reference fiat rate in orange

* move order-forms under candle chart

* fix scaling with browser zoom

* fix total calculation for buy/sell forms

* order-form: resolve some edge-cases around invalid inputs

* refactor number parsing for rate/qty fields, allow for comma

* rework active orders section to only show active/relevant orders

* order-form: optimize buy/sell buttons

* refactor out unnecessary delay param

* rework slider to make it more vibrant, general order form improvements & bug fixes (element alignment and such)

* markets: shrink header a bit, limit order book-side size to 14 so we don't have to scroll UI

* improve rate/qty fields parsing

* improve slider handling

* markets: adding order to book-side should be smooth

* markets: rework header, rework spot-price display

* minor sell slider fix

* minor markets-header adjustments

* markets: misc adjustments (mostly header)

* order-form default price should be best buy/sell (not mid-gap)

* form-label should not affect cursor

* rework market header (mostly to simplify code involved), format total in/out properly, make candle-chart scaling/zooming smooth (add more zoom-levels)

* get rid of redundant trading limits info, remove what's left of wallet locking in UI, adjust markets header

* fix number formatting all across UI

* introduce a work-around for insanely high server-configured rate-step

* refactor matches table code, swap column order for more clear signal, add asset symbols to clarify what Rate/Size are

* refactor qty parsing (order-form)

* refactor rate/coin formatting, format qty to lot size (in order-book, matches table)

* reverse rate/qty columns in order-book to make qty easier to read

* use precise to-lot formatting where it makes sense

* rework order-book to highlight order relevance (based on quantity and price)

* fix typo/bug with converting floating-point numbers to atomic numbers (which are always integers)

* (when formatting decimals in UI) don't show comma since it's confusing when combined with decimal dot

* candle chart refactoring/adjustments (mostly related to making scrolling smooth, adjusting paddings, and moving price labels to a separate column on the right); plus minor bug fixes unrelated to candle chart

* candle-chart: make scrolling smoother

* fix forms formatting

* candle-chart: fixes & adjustments (proper life-cycle handling)

* variuos adjustments to make things pretty

* re-arrange stats on market header (mostly around bison/fiat price), fix the way candles/market is loaded

* markets: remove order-acceleration functionality since it doesn't belong on this page (we can accelerate on order-view if necessary), add a bunch of missing await calls

* add tooltips for bison/external prices, display external price on the order-book as well

* use defined constant instead of hardcoded value (for colors), make MM overview view background distinct from created bot configurations

* order-form: make use of change handler for price/qty inputs to address some quirks of current implementation

* minor adjustments

* handle edge-case related to user order still showing in UI but no longer being relevant (eg. order in submitting status)

* adjust the way candlesLoaded notification gets handled in UI to make it fully symmetric

* matches table - update Age column to be a timestamp in hh-mm-ss format (for simpler readability) and only show recent (24h in the past) matches; also rework order-book mid-section

* use more compact date-time for display on candle chart (when candle is hovered)

* rework market page UI colors, minor mics adjustments

* update the way order-book looks, add % delta relative to external price

* remove last match data from order-book to keep it clean and simple

* order-book: periodically update price delta(s)

* cut margins for date-time displayed on candle chart (when candle is hovered), adjust profit threshold

* display negative price delta with opposite color to make it clearly visible in UI

* refactor code around recent matches & open orders (called active orders previously); add completed orders views (and extend order filtering API to support the use-case of fetching truly relevant orders); format quantities on open/completed views to lot size; finally, minor adjustments to relevant html/css have been made

* update OrderReader.StatusString func to correspond to what we have in JS

* properly count/display total/locked wallet balances

* fix incorrect fee displayed in UI for user-prompt action to bump fees (also display fiat rate alongside); improve the way stuck EVM transactions are handled so that fee-bumps actually work; respects user-configured MaxFee estimate for redeems

* mm: enforce oracle/fiat price confluence, add USDT-derived oracle markets, bump HTTP response read limit to allow for fetching oracle rates (for certain markets the amount of data to fetch is just higher)

* fix 1d on completed history view, don't show active orders in completed history (these are shown in open orders section)

* make duration labels on Candle chart less distracting (by setting opacity below 1)

* improve the way immediate-match warning works, prevent MM bot from placing immediately matching orders (as a safety precaution)

* mics improvements (mostly adding await & adjusting font sizes), adjust red/green colors on markets page, use Binance-like own order market (orange dot) since it's nice and clean compared to everything else I've tried

* put completed orders section right below open orders section

* instrument a.sh with pprof everywhere

* don't initiate swap if wallet-supported rate is too low when swap needs to happen (it's better than overpaying in fees, or initiating swap and refunding it eventually due to swap tx never being mined)

* use 2x fee cap (wallet configuration setting) for Swap transaction type since it's under sever time limit for trade to execute successfully

* adjust the way wallets handle fees (swap, max cap, etc.)

* filter out inactive orders (open orders section)

* set reasonable default fee cap for ETH and POL wallets

* adjust wallet readiness checks on buy/sell order forms

* increase EVM providers request timeouts so we can better tolerate temporary networking delays (also reducing user notifications spam)

* markets page, cancelling order should happen immediately without additional popup

* use age instead of time column for recent matches (since time is hard to make sense of when matches aren't happening constantly all the time), but format it slightly differently from how it was

* minor fixes & adjustments

* update README to describe how this project is different from upstream, as well as how to build & run it from source code

* increase eth/pol timeouts some more

* add make l - a shortcut for make run

* fix typo in buy/sell order form event handlers

* adjust font size for fiat rate in the header (markets page)

* improve the way order buy/sell forms are initialized (also handling un-synced wallets better)

* wallets: better fit for fee estimates

* core: initialize with retries (tolerating failure to connect to DEX server on startup on the very first try)

* poke notes: remove redundant info

* wallets: make sense of fiat price displayed on wallets view

* slider adjustments to account for some edge cases
  • Loading branch information
norwnd authored Jan 18, 2025
1 parent 333e9f6 commit faf1d78
Show file tree
Hide file tree
Showing 93 changed files with 5,013 additions and 7,806 deletions.
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
all:
make build
make run

run:
./run.sh

l:
make run

build:
./build.sh

server_build:
./build_server.sh

server_run:
./run_server.sh

build_linux:
./build_linux.sh

test:
./run_tests.sh

format:
gofmt -w -s $$(find . -type f -name '*.go' -not -path "./pkg/proto/*" -not -name "*.gen.go" -not -path "*/mock/*")
goimports -w $$(find . -type f -name '*.go' -not -path "./pkg/proto/*" -not -name "*.gen.go" -not -path "*/mock/*")

#comment:
# $GOPATH/bin/commentwrap -fix -docflow_limit=90 /Users/norwnd/crypto-integrations/applications/outgoing-transactions/domain/outgoing_transaction.go
# $GOPATH/bin/commentwrap -fix -docflow_limit=90 TODO

server_deps_up:
docker-compose -f server/docker/deps-compose.yml up -d --build

server_deps_down:
docker-compose -f server/docker/deps-compose.yml down
214 changes: 9 additions & 205 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,210 +1,14 @@
# <img src="docs/images/logo_wide_v2.svg" alt="DCRDEX" width="456">
## Bison Lean is crypto-wallet built around atomic-swaps powered DEX

Check failure on line 1 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

First line in a file should be a top-level heading

README.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## Bison Lean is crypto-wallet..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md041.md

Check failure on line 1 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

First line in a file should be a top-level heading

README.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## Bison Lean is crypto-wallet..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md041.md

[![Build Status](https://github.com/decred/dcrdex/workflows/Build%20and%20Test/badge.svg)](https://github.com/decred/dcrdex/actions)
[![ISC License](https://img.shields.io/badge/license-Blue_Oak-007788.svg)](https://blueoakcouncil.org/license/1.0.0)
[![GoDoc](https://img.shields.io/badge/go.dev-reference-blue.svg?logo=go&logoColor=lightblue)](https://pkg.go.dev/decred.org/dcrdex)
This repository is a fork of [Bison wallet](https://github.com/decred/dcrdex) that prioritizes UX and clean UI.

Check failure on line 3 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Trailing spaces

README.md:3:112 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md

Check failure on line 3 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Trailing spaces

README.md:3:112 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md

## Bison Wallet and DCRDEX development

This is the repository for development of Bison Wallet, DCRDEX, and Tatanka
Mesh.

## What is DCRDEX?

The [Decred Decentralized Exchange (DEX)](https://dex.decred.org/) is a system
that enables trustless exchange of different types of blockchain assets via a
familiar market-based API. DEX is a non-custodial solution for cross-chain
exchange based on atomic swap technology. DEX matches trading parties and
facilitates price discovery and the communication of swap details.

Matching is performed through a familiar exchange interface, with market and
limit orders and an order book. Settlement occurs on-chain. DEX's epoch-based
matching algorithm and rules of community conduct ensure that the order book
action you see is real and not an army of bots.

Trades are performed directly between users through on-chain contracts with no
actual reliance on DEX, though swap details must be reported both as a
courtesy and to prove compliance with trading rules. Trades are settled with
pure 4-transaction atomic swaps and nothing else. Because DEX collects no
trading fees, there's no intermediary token and no fee transactions.

Although trading fees are not collected, DEX does require a one-time
registration fee to be paid on-chain. Atomic swap technology secures all trades,
but client software must still adhere to a set of policies to ensure orderly
settlement of matches. The maximum penalty imposable by DEX is loss of trading
privileges and forfeiture of registration fee.

## What is Bison Wallet

Bison Wallet is a multi-wallet developed in concert with DCRDEX and Tatanka
Mesh. Bison Wallet leverages state-of-the-art blockchain technology to bring
more features and more privacy for your favorite assets. DCRDEX is built-in, as
well as advanced trading features like market-making and arbitrage, directly
from your wallet.

Our goal is to find a balance of convenience and privacy that works for you,
while giving you access to advanced features most wallets ignore. For many
assets, we can cut out the middleman altogether and allow you to interact
directly with the blockchain network. This type of wallet is highly-resilient to
data collection and censorship.

We also focus on bringing advanced, asset-specific features for out wallets.
With Decred, you can use StakeShuffle to further anonymize your funds, or stake
your DCR and earn some block rewards. The Zcash wallet exposes unified addresses
and shielded pools, and operates on a shielded-first principle that makes
privacy effortless. Keep an eye on development here. We are dedicated to
exposing these technologies to the communities that want them.

## What is Tatanka Mesh

Tatanka Mesh (Tatanka, the mesh) is the evolution of DCRDEX. Where DCRDEX relies
on a central server for maintaining order books and policing trades, Tatanka is
a decentralized P2P protocol that enables a network of subscribers to
collectively perform these tasks. Here are the three critical services that
Tatanka Mesh provides.

- Enhance the ability for users to connect and to share data both publicly and privately
- Aggregate reputation data and monitor fidelity bonds. Tatanka can limit
access to users who earn a bad reputation
- Oracle services for fiat exchange rates and blockchain transaction fee rates

The mesh collects no fees for its services. Trades are performed using trustless
atomic swaps that exchange funds directly between wallets.

Going P2P empowers our users to trade directly, enhancing security,
censorship-resistance, privacy. and self-sovereignty.

## Contents

- [Getting Started](#getting-started)
- [Important Stuff to Know](#important-stuff-to-know)
- [Fees](#fees)
- [DEX Specification](#dex-specification)
- [Contribute](#contribute)
- [Source](#source)
![img.png](docs/images/ui_overview.png)

## Getting Started

To trade on DCRDEX, you can use Bison Wallet. There are a few simple options
for obtaining Bison Wallet. The standalone wallet is strongly recommended as
it is the easiest to setup and generally has the most up-to-date downloads. Pick
**just one** method:

1. From version 1.0, installers are available for all major operating systems
2. Download standalone Bison Wallet for your operating system for the
[latest release on GitHub](https://github.com/decred/dcrdex/releases).
3. Use your operating system's package manager. See [OS Packages](#os-packages)
for more info.
4. [Use Decrediton](https://docs.decred.org/wallets/decrediton/decrediton-setup/),
the official graphical Decred wallet, which integrates Bison Wallet, and go
to the DEX tab.
5. Build the standalone client [from source](https://github.com/decred/dcrdex/wiki/Client-Installation-and-Configuration#advanced-client-installation).

See the [Client Installation and Configuration](https://github.com/decred/dcrdex/wiki/Client-Installation-and-Configuration)
page on the wiki for more information and a detailed walk-through of the initial setup.

Almost everyone will just want the client to trade on existing markets, but if
you want to set up a new DEX server and host markets of your choice, see
[Server Installation](https://github.com/decred/dcrdex/wiki/Server-Installation).

## OS Packages

We are in the process of adding the application to various OS package managers:

- Arch Linux ([AUR](https://aur.archlinux.org/packages/dcrdex)). e.g. `$ yay dcrdex`. Accessible to [Arch-based distros](https://wiki.archlinux.org/title/Arch-based_distributions) like Manjaro.
- MacOS. Homebrew cask **coming soon**.
- Windows. `winget` package **coming soon**.
- Debian/Fedora. apt repository **coming soon**.

## Important Stuff to Know

Trades settle on-chain and require block confirmations. Trades do not settle instantly.
In some cases, they may take hours to settle.
**The client software should not be shut down until you are absolutely certain that your trades have settled**.

**The client has to stay connected for the full duration of trade settlement**.
Losses of connectivity of a couple minutes are fine, but don't push it.
A loss of internet connectivity for more than 20 hours during trade settlement has the potential to result in lost funds.
Simply losing your connection to the DEX server does not put funds at risk.
You would have to lose connection to an entire blockchain network.

**There are initially limits on the amount of ordering you can do**.
We'll get these limits displayed somewhere soon, but in the meantime,
start with some smaller orders to build up your reputation. As you complete
orders, your limit will go up.

**If you fail to complete swaps** when your orders are matched, your account
will accumulate strikes that may lead to your account becoming automatically
suspended. These situations are not always intentional (e.g. prolonged loss of
internet access, crashed computer, etc.), so for technical assistance, please
reach out
[on Matrix](https://matrix.to/#/!mlRZqBtfWHrcmgdTWB:decred.org?via=decred.org&via=matrix.org).

## Fees

DEX does not collect any fees on the trades, but since all swap transactions
occur on-chain and are created directly by the users, they will pay network
transaction fees. Transaction fees vary based on how orders are matched. Fee
estimates are shown during order creation, and the realized fees are displayed
on the order details page.

To ensure that on-chain transaction fees do not eat a significant portion of the
order quantity, orders must be specified in increments of a minimum lot size.
To illustrate, if on-chain transaction fees worked out to $5, and a user was able
to place an order to trade $10, they would lose half of their trade to
transaction fees. For chains with single-match fees of $5, if the operator wanted
to limit possible fees to under 1% of the trade, the minimum lot size would need
to be set to about $500.

The scenario with the lowest fees is for an entire order to be consumed by a
single match. If this happens, the user pays the fees for two transactions: one
on the chain of the asset the user is selling and one on the chain of the asset
the user is buying. The worst case is for the order to be filled in multiple
matches each of one lot in amount, potentially requiring as many swaps as lots
in the order.
Check the
[dex specification](https://github.com/decred/dcrdex/blob/master/spec/atomic.mediawiki)
for more details about how atomic swaps work.

## DEX Specification

The [DEX specification](spec/README.mediawiki) details the messaging and trading
protocols required to use the Market API. Not only is the code in
the **decred/dcrdex** repository open-source, but the entire protocol is
open-source. So anyone can, in principle, write their own client or server based
on the specification. Such an endeavor would be ill-advised in these early
stages, while the protocols are undergoing constant change.

## Contribute

**Looking to contribute? We need your help** to make DEX &#35;1.

Nearly all development is done in Go and JavaScript. Work is coordinated
through [the repo issues](https://github.com/decred/dcrdex/issues),
so that's the best place to start.
Before beginning work, chat with us in the
[DEX Development room](https://matrix.to/#/!EzTSRQITaqHuFBDFhM:decred.org?via=decred.org&via=matrix.org&via=zettaport.com).
The pace of development is pretty fast right now, so you'll be expected to keep
your pull requests moving through the review process.

Check out these wiki pages for more information.

- [Getting Started Contributing](../../wiki/Contribution-Guide)
- [Backend Development](../../wiki/Backend-Development)
- [Run **dcrdex** and **bisonw** on simnet](../../wiki/Simnet-Testing). Recommended for development.
- [Run **bisonw** on testnet](../../wiki/Testnet-Testing). Recommended for poking around.
- [Run the test app server](../../wiki/Test-App-Server). Useful for GUI development, or just to try everything out without needing to create wallets or connect to a **dcrdex** server.

## Source

The DEX [specification](spec/README.mediawiki) was drafted following stakeholder
approval of the
[specification proposal](https://proposals.decred.org/proposals/a4f2a91c8589b2e5a955798d6c0f4f77f2eec13b62063c5f4102c21913dcaf32).

The source code for the DEX server and client are being developed according to
the specification. This undertaking was approved via a second DEX
[development proposal](https://proposals.decred.org/proposals/417607aaedff2942ff3701cdb4eff76637eca4ed7f7ba816e5c0bd2e971602e1).

## FAQS

- How can I integrate new assets? To add new assets, follow the instructions [here](https://github.com/decred/dcrdex/blob/master/spec/fundamentals.mediawiki/#adding-new-assets) and see existing implementations [here](https://github.com/decred/dcrdex/tree/master/server/asset).
At the moment we don't distribute pre-built binaries, so the only way to run Bison Lean is to build it from source code:
- `git clone` this repository

Check failure on line 10 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Lists should be surrounded by blank lines

README.md:10 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `git clone` this repository"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md032.md

Check failure on line 10 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown

Lists should be surrounded by blank lines

README.md:10 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `git clone` this repository"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md032.md
- install `Golang` and `Node.js` that will be used to compiling & building this code
- build Bison Lean wallet binary by running `make build`
- run Bison Lean wallet binary by running `make run`
- open `127.0.0.1:3333` URL in browser and you are done!
21 changes: 21 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -e

#!/usr/bin/env bash

pushd client/webserver/site
rm -rf dist
npm clean-install
npm run build
popd

(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on go build -tags lgpl)
#
# Mac-specific issue with older Golang versions (resolved with `codesign`), see discussions
# here for details: https://github.com/golang/go/issues/63997
#(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on go build -tags lgpl && codesign -s - -f ./bisonw)
#
# to specify OS and Architecture
#(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on GOOS=darwin GOARCH=arm64 go build -tags lgpl)
#
# -race build
#(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on go build -race -tags lgpl)
19 changes: 19 additions & 0 deletions build_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -e

#!/usr/bin/env bash

pushd client/webserver/site
npm clean-install
npm run build
popd

#(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on GOOS=linux GOARCH=amd64 go build -tags lgpl)
(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on go build -tags lgpl)
#
# Note, this is -race build, to be used for testing only!
#(cd client/cmd/bisonw/ && CGO_ENABLED=1 GO111MODULE=on go build -race -tags lgpl)
# TODO, previously was CGO_ENABLED=0 ?

# Run Bison binary with:
# - (./client/cmd/bisonw/bisonw --db=/home/t/dcrdex-old-decrediton/db --webaddr=127.0.0.1:5758 --log=trace)
# - (./client/cmd/bisonw/bisonw --db=/home/t/dcrdex-anon/db --webaddr=127.0.0.1:5758 --log=trace)
6 changes: 6 additions & 0 deletions build_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -e

#!/usr/bin/env bash

#(cd server/cmd/dcrdex/ && CGO_ENABLED=0 GO111MODULE=on go build -tags lgpl -race)
(cd server/cmd/dcrdex/ && CGO_ENABLED=0 GO111MODULE=on go build -tags lgpl)
Loading

0 comments on commit faf1d78

Please sign in to comment.