Skip to content

Commit

Permalink
Merge branch 'main' into 60-sor-update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
4TT1L4 authored Jan 9, 2024
2 parents 22474ca + 921f3d3 commit 2b0362a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ over the multi-asset order book to obtain a list of matches. The matches are the
translated into actual transactions that will be signed and submitted by the bot, if
these are profitable to execute.

Thanks to the open and decentralized design of the protocol, anybody can run a Smart Order
Router instance and collect a share of the fees, thus running a Smart Order Router instance
is not only contributing to the further decentralization of the protocol, but it is also
incentivized financially and might be a very lucrative activity.
Due to the open and decentralized design of the protocol, anybody can run a Smart Order
Router instance and profit from the arbitrage opportunities, thus running a Smart Order
Router instance is not only contributing to the further decentralization of the protocol,
but it is also incentivized financially and it might be a very lucrative activity.

## Crash Course: GeniusYield DEX Orders and the Smart Order Routers

Expand Down Expand Up @@ -150,6 +150,13 @@ Using the previous example we could have two cases:
If we want our earnings to be in `GENS` then the commodity must be `ADA`. So we can buy from the sell order,
`20 ADA` using `8 GENS`, then using these `20 ADA` we can get `10 GENS` from the buy order, earning `2 GENS`.

> [!IMPORTANT]
>
> There is a check in the end which does the following before submitting any transaction:
>
> * In case "currency" is set to ADA for all `scanTokens` then this check guarantees that bot doesn't lose any funds by submitting the built transaction.
> * For other case, since arbitrage isn't guaranteed to be in ADA but as transaction fees must be paid in ADA, this check guarantees that bot doesn't lose any non-ADA token and doesn't lose any ADA besides transaction fees.
## Building and running the Smart Order Router

> [!NOTE]
Expand Down Expand Up @@ -214,6 +221,8 @@ docker run -it \
ghcr.io/geniusyield/smart-order-router:latest
```

And the following commands can be used to start a Kupo backed instance, if you want to use an existing Kupo instance:

``` bash
# SMART ORDER ROUTER INSTANCE USING KUPO (existing Kupo instance)
# ===============================================================
Expand Down Expand Up @@ -449,7 +458,7 @@ Once we compiled and configured the order bot, you can execute the SOR using the

The SOR is equipped with a test suite that employs QuickCheck to perform property-based testing.
By implementing certain properties, we are able to verify various important aspects of the strategies,
like for example, given a matching between sell and buy orders there is always a [positive earning](./geniusyield-orderbot/test/Tests/Prop/Strategies.hs#L167-L177).
like for example, given a matching between sell and buy orders there is always a non-negative earning.
Among others that can be found on [Tests.Prop.Strategies](./geniusyield-orderbot/test/Tests/Prop/Strategies.hs)
module.

Expand Down
5 changes: 4 additions & 1 deletion geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ notLosingTokensCheck netId providers botAddr oapFilter (txBody, matchesToExecute
utxosLovelaceAndFilteredValueAtAddr $ txBodyUTxOs txBody

fees = txBodyFee txBody
lovelaceCheck = inputLovelace - outputLovelace <= fees
lovelaceCheck = if all currencyIsLovelace oapFilter then outputLovelace >= inputLovelace else inputLovelace - outputLovelace <= fees

filteredACCheck =
all (\ac -> valueAssetClass filteredACInput ac
Expand Down Expand Up @@ -351,6 +351,9 @@ notLosingTokensCheck netId providers botAddr oapFilter (txBody, matchesToExecute
second (valueFromList . filter (botAssetFilter . fst) . valueToList) $
valueSplitAda $ utxosValueAtAddr utxos

currencyIsLovelace :: OrderAssetPair -> Bool
currencyIsLovelace oap = currencyAsset oap == GYLovelace

-------------------------------------------------------------------------------
-- Helpers
-------------------------------------------------------------------------------
Expand Down

0 comments on commit 2b0362a

Please sign in to comment.