Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #65: Improve balance lose check and mention it's details in docs #66

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ over the multi-asset order book to obtain a list of matches. The matches are the
translated into transactions that will be signed and submitted by the bot.

Due 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 contributiung to the further decentralization of the protocol, but it is also
Router instance and collect the arbitrage opportunities, thus running a Smart Order Router instance
Copy link
Contributor

@4TT1L4 4TT1L4 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collect the arbitrage opportunities,

I think we should change the wording here. One does not "collect" opportunities.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, could you elaborate / suggest the required changes?

is not only contributing to the further decentralization of the protocol, but it is also
incentivized financially.

## Crash Course: GeniusYield DEX Orders and the Smart Order Routers
Expand Down Expand Up @@ -128,6 +128,13 @@ If we want our earnings to be in `tokenA` then the
commodity must be `tokenB`. So we can buy from the sell order, `20 tokenB` using `8 tokenA`, then
using these `20 tokenB` we can get `10 tokenA` from the buy order, earning `2 tokenA`.

> **ⓘ **
sourabhxyz marked this conversation as resolved.
Show resolved Hide resolved
>
> Note that 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 @@ -414,7 +421,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
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
Loading