From 73ff6f1c585d39ec1c1b5f514a9996b63376f502 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 20 Dec 2023 09:26:04 +0530 Subject: [PATCH 1/5] Improving docs to include information about balance loss check --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca2bced..0bd62b4 100644 --- a/README.md +++ b/README.md @@ -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 +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 @@ -128,6 +128,10 @@ 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`. +> **ⓘ ** +> +> Note that as per current design of bot, there is a check in end to determine whether the bot would loose balance in case it submits the build transaction. This check subtracts for transaction fees, that is, it might happen that bot may loose ADA when submitting the transaction but that would solely be due to transaction fees. If currency is set to ADA, bot may still loose some ADA if the transaction fees is more than found ADA arbitrage. + ## Building and running the Smart Order Router > [!NOTE] @@ -394,7 +398,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. From e8ff85689c04db337ed80803f377f1d701f6816e Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 3 Jan 2024 18:11:11 +0530 Subject: [PATCH 2/5] Improve balance lose check and mention it's details in docs --- README.md | 5 ++++- geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ae0271..49ca462 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,10 @@ using these `20 tokenB` we can get `10 tokenA` from the buy order, earning `2 to > **ⓘ ** > -> Note that as per current design of bot, there is a check in end to determine whether the bot would loose balance in case it submits the build transaction. This check subtracts for transaction fees, that is, it might happen that bot may loose ADA when submitting the transaction but that would solely be due to transaction fees. If currency is set to ADA, bot may still loose some ADA if the transaction fees is more than found ADA arbitrage. +> 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 diff --git a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs index af8be63..c10c1a7 100644 --- a/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs +++ b/geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs @@ -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 @@ -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 ------------------------------------------------------------------------------- From 98b4194630b8107a567a2a640031515819b4fecd Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 8 Jan 2024 18:36:22 +0530 Subject: [PATCH 3/5] Feat #65: Improve balance lose check --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49ca462..cce6df5 100644 --- a/README.md +++ b/README.md @@ -128,9 +128,9 @@ 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`. -> **ⓘ ** +> [!IMPORTANT] > -> Note that there is a check in the end which does the following before submitting any transaction: +> 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. From 7c8b7ebd0cd79719e861c5adeabfe8cdd42d85ca Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 8 Jan 2024 18:40:20 +0530 Subject: [PATCH 4/5] Feat #65: Improve balance lose check --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cce6df5..9b30eaa 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ docker run -it \ And the following commands can be used to start a Kupo backed instance, if you want to use an existing Kupo instance: - > **ⓘ How to run Kupo efficiently?** + > [!TIP] **How to run Kupo efficiently?** > > Firstly, Kupo requires a node running, note that node itself maintains efficient access to information such as current protocol parameters, current set of pool ids, etc. but it doesn't efficiently provide us with UTxOs when say queried by a particular address. Kupo helps in covering this gap and gives us efficient lookup tables to query for UTxOs. For our use case, we are only interested in our own bot's UTxOs, order UTxOs and the required reference scripts / reference inputs. So we'll run Kupo to keep track of only those UTxOs, note that if we instead run Kupo by matching against star (`*`) pattern, then as Kupo does many disk writes, we would quickly burn out our SSDs TBW limit. > From d1161e6267765422fef014c29f0a3f407299bcf8 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 8 Jan 2024 18:41:18 +0530 Subject: [PATCH 5/5] Feat #65: Improve balance lose check --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b30eaa..25a5983 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,9 @@ docker run -it \ And the following commands can be used to start a Kupo backed instance, if you want to use an existing Kupo instance: - > [!TIP] **How to run Kupo efficiently?** + > [!TIP] + > + > **How to run Kupo efficiently?** > > Firstly, Kupo requires a node running, note that node itself maintains efficient access to information such as current protocol parameters, current set of pool ids, etc. but it doesn't efficiently provide us with UTxOs when say queried by a particular address. Kupo helps in covering this gap and gives us efficient lookup tables to query for UTxOs. For our use case, we are only interested in our own bot's UTxOs, order UTxOs and the required reference scripts / reference inputs. So we'll run Kupo to keep track of only those UTxOs, note that if we instead run Kupo by matching against star (`*`) pattern, then as Kupo does many disk writes, we would quickly burn out our SSDs TBW limit. >